/* ══════════════════════════════════════════════════════════════════════════════
   SIA Dashboard — CSS
   Dark GitHub-night palette, matching ai-ran-symbxrl/monitoring.
   ══════════════════════════════════════════════════════════════════════════════ */

:root {
  --bg-0:       #0d1117;
  --bg-1:       #161b22;
  --bg-2:       #21262d;
  --bg-3:       #30363d;
  --border:     #30363d;
  --text-muted: #8b949e;
  --text:       #c9d1d9;
  --text-bright: #e6edf3;
  --accent:     #58a6ff;
  --accent-dim: #1f6feb;
  --green:      #3fb950;
  --orange:     #d29922;
  --red:        #f85149;
  --purple:     #bc8cff;
  --cyan:       #39d353;

  /* KPI palette: tx_brate, tx_pkts, dl_buffer */
  --kpi-0: #58a6ff;
  --kpi-1: #3fb950;
  --kpi-2: #d29922;

  /* Slice palette: eMBB, mMTC, URLLC */
  --slice-0: #58a6ff;
  --slice-1: #3fb950;
  --slice-2: #bc8cff;

  --radius: 6px;
  --panel-pad: 16px;
  --topbar-h: 54px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg-0); color: var(--text); font-family: var(--font); font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 3px; }

/* ── Title bar ─────────────────────────────────────────────────────────────── */
#title-bar {
  position: sticky; top: 0; z-index: 101;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 28px;
  padding: 14px 24px;
}

#title-logos {
  display: flex; align-items: center; gap: 20px; flex-shrink: 0;
}
.inst-logo {
  height: 62px; width: auto;
  object-fit: contain; object-position: center;
  filter: brightness(1.05);
}
.inst-logo.logo-imdea { height: 52px; }

#title-text {
  display: flex; flex-direction: column; gap: 4px;
}
#title-sia {
  font-size: 34px; font-weight: 800;
  color: var(--accent); letter-spacing: -0.5px; line-height: 1;
}
#title-sia .title-dashboard {
  font-weight: 700; color: var(--accent);
  font-size: 34px; margin-left: 10px;
}
#title-full {
  font-size: 13px; color: var(--text-muted);
  font-style: italic; letter-spacing: 0.1px;
}

/* ── Topbar ────────────────────────────────────────────────────────────────── */
#topbar {
  position: sticky; top: 97px; z-index: 100;
  height: var(--topbar-h);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
}

#topbar .logo {
  font-weight: 700; font-size: 18px; color: var(--text-bright);
  letter-spacing: -0.3px; white-space: nowrap;
}
#topbar .logo span { color: var(--accent); }

#topbar .sep { width: 1px; height: 28px; background: var(--border); flex-shrink: 0; }

#topbar select {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 5px 10px; font-size: 13px; outline: none;
}
#topbar select:hover { border-color: var(--accent-dim); }
#topbar select:focus { border-color: var(--accent); }

#topbar label { color: var(--text-muted); font-size: 12px; }

/* Slider */
#slider-wrap {
  display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0;
}
#t-slider {
  flex: 1; min-width: 80px; max-width: 360px;
  accent-color: var(--accent);
}
#t-display {
  color: var(--text-bright); font-variant-numeric: tabular-nums;
  font-size: 13px; min-width: 60px;
}

/* Play/Pause */
#play-btn {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); padding: 5px 12px;
  font-size: 13px;
}
#play-btn:hover { border-color: var(--accent-dim); color: var(--accent); }
#play-btn.playing { border-color: var(--green); color: var(--green); }

/* Mode toggle */
#mode-toggle {
  margin-left: auto; display: flex; gap: 4px;
}
.mode-btn {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-muted);
  padding: 5px 12px; font-size: 12px;
}
.mode-btn.active {
  background: var(--accent-dim); border-color: var(--accent); color: var(--text-bright);
}

/* ── Main layout ───────────────────────────────────────────────────────────── */
#main {
  max-width: 1600px; margin: 0 auto;
  padding: 18px 20px;
  display: flex; flex-direction: column; gap: 16px;
}

/* ── Panel card ────────────────────────────────────────────────────────────── */
.panel {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--panel-pad);
  position: relative;
}

.panel-title {
  font-size: 12px; font-weight: 600; letter-spacing: 0.5px;
  color: var(--text-muted); text-transform: uppercase;
  margin-bottom: 12px;
}
.panel-title .badge {
  display: inline-block; margin-left: 8px; padding: 1px 6px;
  border-radius: 10px; background: var(--bg-3); color: var(--text-muted);
  font-size: 10px; font-weight: 500; vertical-align: middle;
}

/* Panel row grid */
.panel-row {
  display: grid; gap: 16px;
}
.panel-row-3 { grid-template-columns: repeat(3, 1fr); }
.panel-row-2 { grid-template-columns: repeat(2, 1fr); }
.panel-row-4 { grid-template-columns: repeat(4, 1fr); }

/* ── Hero row ──────────────────────────────────────────────────────────────── */
#hero-row {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 16px;
}

/* KG vis container */
#kg-vis {
  width: 100%; height: 320px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* KG legend */
.kg-leg-item {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text-muted);
}
.kg-leg-dot {
  width: 10px; height: 10px; border-radius: 50%;
  display: inline-block;
}

/* Story grid — vertical stack in side panel */
#story-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
}
#panel-story {
  display: flex;
  flex-direction: column;
}

/* ── Stat cards ────────────────────────────────────────────────────────────── */
.stat-row {
  display: flex; gap: 12px; flex-wrap: wrap;
}
.stat-card {
  flex: 1; min-width: 100px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
  text-align: center;
}
.stat-card .val {
  font-size: 22px; font-weight: 700; color: var(--text-bright);
  font-variant-numeric: tabular-nums;
}
.stat-card .lbl {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
}

/* ── KPI forecast strip ────────────────────────────────────────────────────── */
#forecast-strip {
  height: 200px;
}

/* ── Symbolic explanation panel ────────────────────────────────────────────── */
#symbolic-panel {
  display: flex; flex-direction: column; gap: 10px;
}
.sym-slice-block {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
}
.sym-slice-name {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px;
}
.sym-kpi-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 4px;
}
.sym-kpi-name { font-size: 11px; color: var(--text-muted); width: 72px; flex-shrink: 0; }
.sym-token {
  font-family: var(--font-mono); font-size: 12px;
  padding: 2px 8px; border-radius: 4px;
  background: var(--bg-3); color: var(--text-bright);
  white-space: nowrap;
}
.sym-token.pred-inc  { background: #1c2d3c; color: var(--accent); border-left: 2px solid var(--accent); }
.sym-token.pred-dec  { background: #2d1c1c; color: var(--red);    border-left: 2px solid var(--red); }
.sym-token.pred-const { background: var(--bg-3); color: var(--text-muted); }
.sym-action {
  font-family: var(--font-mono); font-size: 12px;
  background: var(--bg-3); color: var(--green);
  padding: 2px 8px; border-radius: 4px;
}
.sym-refined {
  font-size: 11px; color: var(--orange);
  margin-left: 8px;
}

/* ── IS panel ──────────────────────────────────────────────────────────────── */
#is-panel {
  height: 240px;
}

/* ── KG panel ──────────────────────────────────────────────────────────────── */
#kg-panel {
  height: 380px;
  position: relative;
}
#kg-controls {
  display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap;
}
#kg-controls select, #kg-controls button {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  padding: 4px 10px; font-size: 12px;
}
#kg-vis {
  width: 100%; height: 300px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Detailed analysis section ─────────────────────────────────────────────── */
#details-toggle-wrap {
  text-align: center;
}
#details-toggle {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); padding: 7px 24px;
  font-size: 13px;
}
#details-toggle:hover { border-color: var(--accent-dim); color: var(--accent); }

#details-section { display: none; }
#details-section.open { display: block; }

/* ── MI / refinement panels ────────────────────────────────────────────────── */
#mi-chart { height: 220px; }
#refinement-timeline { height: 220px; }
#is-bimodal { height: 220px; }
#consistency-chart { height: 220px; }
#heatmap-chart { height: 220px; }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.sia-table {
  width: 100%; border-collapse: collapse; font-size: 12px;
}
.sia-table th {
  background: var(--bg-2); color: var(--text-muted);
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
  padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border);
  font-size: 11px;
}
.sia-table td {
  padding: 5px 10px; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.sia-table tr:last-child td { border-bottom: none; }
.sia-table tr:hover td { background: var(--bg-2); }
.sia-table .mono { font-family: var(--font-mono); }
.sia-table .num  { text-align: right; font-variant-numeric: tabular-nums; }
.bar-cell { width: 60px; }
.bar-cell .bar-bg {
  background: var(--bg-3); border-radius: 2px; height: 6px; width: 100%;
}
.bar-cell .bar-fill {
  background: var(--accent); border-radius: 2px; height: 6px;
}

/* ── Perf footer ───────────────────────────────────────────────────────────── */
#perf-footer {
  display: flex; gap: 16px; justify-content: center;
  padding: 10px 0 4px;
  font-size: 11px; color: var(--text-muted);
}
#perf-footer .perf-chip {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 14px;
}
#perf-footer .perf-chip strong { color: var(--green); }

/* ── Story mode ────────────────────────────────────────────────────────────── */
#story-panel {
  display: flex; flex-direction: column; gap: 10px;
}
.story-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
}
.story-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--text-muted); margin-bottom: 6px;
}
.story-text {
  font-size: 13px; color: var(--text-bright); line-height: 1.5;
}
.story-text .highlight { color: var(--accent); font-weight: 500; }
.story-text .gain      { color: var(--green); font-weight: 600; }
.story-text .warn      { color: var(--orange); }

/* ── Loading indicator ─────────────────────────────────────────────────────── */
.loading {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: var(--text-muted); font-size: 13px; gap: 8px;
}
.loading::before {
  content: "";
  width: 16px; height: 16px;
  border: 2px solid var(--bg-3); border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tooltips ──────────────────────────────────────────────────────────────── */
[title] { cursor: help; }

/* ── Live mode (P6) ─────────────────────────────────────────────────────────── */

/* Blinking LIVE badge in topbar */
.live-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 12px;
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid var(--red);
  color: var(--red); font-size: 12px; font-weight: 700;
  letter-spacing: 0.5px;
  animation: live-pulse 1.6s ease-in-out infinite;
  white-space: nowrap;
}
.live-badge::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--red);
  animation: live-dot 1.6s ease-in-out infinite;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}
@keyframes live-dot {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(0.6); }
}

/* Live feed panel — scrolling event table */
#live-feed-panel { display: none; }
#live-feed-panel.active { display: block; }

#live-feed-table {
  max-height: 220px; overflow-y: auto;
  font-size: 12px;
}
#live-feed-table table { width: 100%; border-collapse: collapse; }
#live-feed-table th {
  text-align: left; padding: 4px 8px;
  color: var(--text-muted); font-weight: 600; font-size: 11px;
  border-bottom: 1px solid var(--border); position: sticky; top: 0;
  background: var(--bg-1); white-space: nowrap;
}
#live-feed-table td {
  padding: 3px 8px; border-bottom: 1px solid var(--bg-2);
  white-space: nowrap; overflow: hidden; max-width: 200px;
  text-overflow: ellipsis;
}
.live-row-new {
  animation: live-row-flash 0.8s ease-out forwards;
}
@keyframes live-row-flash {
  from { background: rgba(63, 185, 80, 0.18); }
  to   { background: transparent; }
}
.live-refine-badge {
  background: rgba(210, 153, 34, 0.2); border: 1px solid var(--orange);
  color: var(--orange); font-size: 10px; padding: 1px 5px; border-radius: 8px;
}
.live-status-conn  { color: var(--green); }
.live-status-disc  { color: var(--text-muted); }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  #hero-row { grid-template-columns: 1fr 1fr; }
  #panel-forecast { grid-column: 1/3 !important; }
  .panel-row-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  #hero-row { grid-template-columns: 1fr; }
  #panel-forecast, #panel-story { grid-column: 1/2 !important; }
  #story-grid { flex-direction: row; }
  .panel-row-3, .panel-row-2, .panel-row-4 { grid-template-columns: 1fr; }
}
