/* =========================================
   Madrid CityBrain - Ontology Viewer
   ========================================= */

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border-color: rgba(148, 163, 184, 0.15);
  --glass-bg: rgba(30, 41, 59, 0.7);
  --glass-border: rgba(148, 163, 184, 0.1);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);

  --color-territorial: #3B82F6;
  --color-medio-ambiente: #10B981;
  --color-mobiliario: #F59E0B;
  --color-urbanismo: #8B5CF6;
  --color-transporte: #EF4444;
  --color-incidencias: #F97316;
  --color-servicios: #06B6D4;
  --color-turismo: #EC4899;
  --color-comercio: #84CC16;
  --color-infraestructura: #6366F1;
  --color-google-places: #14B8A6;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

/* ---- HEADER ---- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.9));
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(16px);
  z-index: 100;
  position: relative;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--color-territorial), var(--color-medio-ambiente));
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 16px;
  color: white;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 400;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  background: rgba(88, 166, 255, 0.12);
  border: 1px solid rgba(88, 166, 255, 0.35);
  border-radius: 8px;
  text-decoration: none;
  transition: all 0.15s ease;
}

.header-btn:hover {
  background: rgba(88, 166, 255, 0.2);
  border-color: rgba(88, 166, 255, 0.55);
  transform: translateY(-1px);
}

.node-map-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-left: 6px;
  padding: 0;
  font-size: 12px;
  line-height: 1;
  background: rgba(88, 166, 255, 0.1);
  border: 1px solid rgba(88, 166, 255, 0.25);
  border-radius: 4px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s ease;
}

.node-map-btn:hover {
  background: rgba(88, 166, 255, 0.25);
  border-color: rgba(88, 166, 255, 0.5);
  transform: scale(1.1);
}

.step-counter {
  font-size: 14px;
  color: var(--text-secondary);
}

.step-counter .current {
  font-weight: 700;
  font-size: 20px;
  color: var(--text-primary);
}

.step-counter .total {
  font-weight: 400;
}

/* ---- TIMELINE ---- */
.timeline {
  display: flex;
  align-items: center;
  padding: 12px 24px;
  background: rgba(15, 23, 42, 0.8);
  border-bottom: 1px solid var(--border-color);
  gap: 0;
  position: relative;
  z-index: 90;
}

.timeline-track {
  display: flex;
  align-items: center;
  flex: 1;
  position: relative;
}

.timeline-bar {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--bg-tertiary);
  transform: translateY(-50%);
  border-radius: 2px;
}

.timeline-progress {
  position: absolute;
  top: 50%;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-territorial), var(--color-google-places));
  transform: translateY(-50%);
  border-radius: 2px;
  transition: width 0.5s ease;
}

.timeline-point {
  position: relative;
  z-index: 2;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--bg-tertiary);
  background: var(--bg-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.timeline-point:hover {
  transform: scale(1.2);
  border-color: var(--text-secondary);
}

.timeline-point.active {
  border-color: currentColor;
  color: white;
  box-shadow: 0 0 16px rgba(var(--glow-rgb), 0.4);
  transform: scale(1.15);
}

.timeline-point.completed {
  border-color: currentColor;
  opacity: 0.7;
}

.timeline-point.completed::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.timeline-point.timeline-real {
  box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.4);
}

.timeline-point.timeline-real::before {
  content: '';
  position: absolute;
  top: -4px;
  right: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
  border: 1.5px solid var(--bg-primary);
  z-index: 3;
}

.timeline-spacer {
  flex: 1;
}

.timeline-label {
  position: absolute;
  top: 34px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--text-muted);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.timeline-point:hover .timeline-label,
.timeline-point.active .timeline-label {
  opacity: 1;
  color: var(--text-secondary);
}

/* ---- MAIN LAYOUT ---- */
.main-container {
  display: flex;
  height: calc(100vh - 110px);
  position: relative;
}

/* ---- GRAPH PANEL ---- */
.graph-panel {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#cy {
  width: 100%;
  height: 100%;
  background: transparent;
}

.graph-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(circle at 30% 40%, rgba(59, 130, 246, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 70% 60%, rgba(16, 185, 129, 0.03) 0%, transparent 50%),
    var(--bg-primary);
  z-index: 0;
}

/* ---- SIDE PANEL ---- */
.side-panel {
  width: 380px;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--glass-border);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  z-index: 10;
  transition: transform 0.3s ease;
}

.side-panel::-webkit-scrollbar {
  width: 4px;
}

.side-panel::-webkit-scrollbar-track {
  background: transparent;
}

.side-panel::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 2px;
}

/* ---- STEP INFO ---- */
.step-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

/* ---- STATUS BADGES ---- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  margin-bottom: 12px;
}

.status-badge.status-real {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-badge.status-real::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 6px rgba(52, 211, 153, 0.6);
}

.status-badge.status-estimated {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-muted);
  border: 1px solid rgba(148, 163, 184, 0.15);
}

.status-badge.status-estimated::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  opacity: 0.5;
}

.step-title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.step-description {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

/* ---- STATS GRID ---- */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  transition: all 0.3s ease;
}

.stat-value-real {
  color: #34d399 !important;
}

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* ---- SECTIONS ---- */
.section {
  margin-bottom: 20px;
}

.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}

/* Node list */
.node-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.node-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.node-item:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateX(2px);
}

.node-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.node-label {
  font-size: 13px;
  font-weight: 600;
  flex: 1;
}

.node-count {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.node-count-real {
  color: #34d399;
  font-weight: 700;
}

.node-item-review {
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.08), rgba(251, 191, 36, 0));
  border-left: 2px solid rgba(251, 191, 36, 0.55);
}

/* Edge list */
.edge-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.edge-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 4px 0;
}

.edge-arrow {
  color: var(--text-muted);
  font-size: 10px;
}

.edge-label {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 10px;
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 6px;
  border-radius: 3px;
}

.edge-cardinality {
  font-size: 9px;
  font-weight: 600;
  color: #a78bfa;
  background: rgba(167, 139, 250, 0.1);
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.3px;
}

.edge-count {
  color: var(--text-muted);
  font-size: 10px;
  margin-left: auto;
}

.edge-count-real {
  color: #34d399;
  font-weight: 700;
}

.edge-item-review {
  background: linear-gradient(90deg, rgba(251, 191, 36, 0.08), rgba(251, 191, 36, 0));
  border-left: 2px solid rgba(251, 191, 36, 0.55);
  padding-left: 6px;
  border-radius: 3px;
}

.edge-review-badge {
  font-size: 8.5px;
  font-weight: 700;
  color: #fbbf24;
  background: rgba(251, 191, 36, 0.14);
  border: 1px solid rgba(251, 191, 36, 0.4);
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  box-shadow: 0 0 6px rgba(251, 191, 36, 0.15);
}

/* Source list */
.source-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.source-item {
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
}

.source-name {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
}

.source-type {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.source-datasets {
  font-size: 10px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.source-datasets code {
  background: rgba(255, 255, 255, 0.05);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
}

/* ---- NODE DETAIL POPUP ---- */
.node-detail {
  display: none;
  position: absolute;
  top: 20px;
  left: 20px;
  width: 320px;
  background: var(--glass-bg);
  backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 16px;
  z-index: 50;
  box-shadow: var(--shadow);
}

.node-detail.visible {
  display: block;
  animation: fadeIn 0.2s ease;
}

.node-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.node-detail-title {
  font-size: 16px;
  font-weight: 700;
}

.node-detail-close {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.node-detail-close:hover {
  background: rgba(255, 255, 255, 0.1);
}

.node-detail-count {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 4px;
}

.node-detail-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.node-detail-real {
  color: #34d399;
  font-weight: 600;
}

.property-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.property-tag {
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  font-family: 'JetBrains Mono', monospace;
}

/* ---- FOOTER NAV ---- */
.footer-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px 0 0;
  border-top: 1px solid var(--border-color);
  margin-top: 12px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  transition: all 0.2s ease;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--text-secondary);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.nav-btn.primary {
  border-color: transparent;
  color: white;
}

.keyboard-hint {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}

.kbd {
  display: inline-block;
  padding: 2px 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 10px;
  font-family: monospace;
}

/* ---- CUMULATIVE STATS BAR ---- */
.cumulative-bar {
  display: flex;
  gap: 16px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  margin-bottom: 16px;
}

.cumulative-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.cumulative-label {
  color: var(--text-muted);
}

.cumulative-value {
  font-weight: 700;
  color: var(--text-primary);
}

/* ---- ANIMATIONS ---- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.8); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes countUp {
  from { opacity: 0.5; }
  to   { opacity: 1; }
}

.animate-in {
  animation: fadeIn 0.4s ease forwards;
}

/* ---- LOADING ---- */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.5s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bg-tertiary);
  border-top-color: var(--color-territorial);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ---- RESPONSIVE ---- */
@media (max-width: 1024px) {
  .side-panel {
    width: 320px;
  }
}

@media (max-width: 768px) {
  .side-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    max-width: 380px;
    transform: translateX(100%);
  }

  .side-panel.open {
    transform: translateX(0);
  }

  .timeline-label {
    display: none;
  }
}
