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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #0d1117;
  color: #c9d1d9;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Title Bar ── */
#title-bar {
  position: sticky; top: 0; z-index: 101;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  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-main {
  font-size: 34px; font-weight: 800;
  color: #58a6ff; letter-spacing: -0.5px; line-height: 1;
}
#title-main .title-dashboard {
  font-weight: 700; color: #58a6ff;
  font-size: 34px; margin-left: 10px;
}
#title-full {
  font-size: 13px; color: #8b949e;
  font-style: italic; letter-spacing: 0.1px;
}

/* ── Top Bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
}
.topbar h1 { font-size: 17px; font-weight: 600; color: #58a6ff; }
.controls { display: flex; gap: 14px; align-items: flex-end; }
.controls label { font-size: 11px; color: #8b949e; text-transform: uppercase; letter-spacing: 0.5px; }
.controls select {
  background: #21262d; color: #c9d1d9;
  border: 1px solid #30363d; border-radius: 6px;
  padding: 5px 10px; font-size: 13px; cursor: pointer; display: block;
}
.controls select:hover { border-color: #58a6ff; }

/* ── Slider Bar ── */
.slider-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 20px;
  background: #161b22; border-bottom: 1px solid #30363d;
}
.slider-bar label { font-size: 12px; color: #8b949e; white-space: nowrap; }

/* Slider track */
input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: #30363d;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; background: #30363d; border-radius: 3px;
}
/* Fill left portion of track in blue */
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  background: #58a6ff;
  border-radius: 50%;
  border: 2px solid #161b22;
  cursor: pointer;
  margin-top: -6px;
  box-shadow: 0 0 0 2px #30363d;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  background: #58a6ff; border-radius: 50%;
  border: 2px solid #161b22; cursor: pointer;
}
input[type="range"]::-moz-range-track {
  height: 6px; background: #30363d; border-radius: 3px;
}
.slider-value {
  font-size: 13px; font-weight: 600; color: #58a6ff;
  min-width: 110px; text-align: right;
}

/* ── Panel Grid ── */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 20px;
}
.grid-2col { grid-template-rows: 520px; }
#analysis-section .grid { grid-template-rows: 520px 420px; }

/* ── Pattern Tables ── */
.pat-table { width:100%; border-collapse:collapse; font-size:11px; }
.pat-table th {
  color:#8b949e; font-weight:600; text-align:left;
  padding:5px 8px; border-bottom:1px solid #30363d;
  position:sticky; top:0; background:#161b22; z-index:1;
}
.pat-table td { padding:4px 8px; border-bottom:1px solid #21262d; }
.pat-table tr:hover td { background:#1c2128; }
.pat-arrow { color:#58a6ff; font-weight:700; text-align:center; }
.pat-pct {
  text-align:right; font-weight:600;
  min-width:48px;
}
.pat-count { text-align:right; color:#8b949e; min-width:40px; }
.pat-bar-wrap { width:80px; padding:0 6px; }
.pat-bar-bg { background:#21262d; border-radius:3px; height:8px; }
.pat-bar-fill { background:#58a6ff; border-radius:3px; height:8px; }
.pat-no-data { color:#8b949e; padding:24px; text-align:center; font-size:13px; }

/* ── Individual Panel ── */
.panel {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-header {
  padding: 8px 14px;
  font-size: 12px; font-weight: 600; color: #c9d1d9;
  border-bottom: 1px solid #30363d;
  background: #1c2128;
  flex-shrink: 0;
}
.panel-body {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}

/* ── Play button ── */
#btn-play {
  background: #21262d; color: #58a6ff;
  border: 1px solid #30363d; border-radius: 6px;
  padding: 4px 12px; font-size: 15px; cursor: pointer;
  line-height: 1; flex-shrink: 0;
}
#btn-play:hover { border-color: #58a6ff; background: #1c2128; }

/* ── Loading Overlay ── */
.loading {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(13, 17, 23, 0.75);
  display: none;
  align-items: center; justify-content: center;
  font-size: 14px; color: #58a6ff;
  z-index: 10;
}
.loading.active { display: flex; }

/* ── Grafana links ── */
.grafana-link {
  text-align: center; padding: 8px;
  font-size: 12px; color: #8b949e;
}
.grafana-link a { color: #58a6ff; text-decoration: none; }
.grafana-link a:hover { text-decoration: underline; }

/* ── Detailed Analysis Toggle ── */
#btn-analysis {
  background: #21262d; color: #c9d1d9;
  border: 1px solid #30363d; border-radius: 6px;
  padding: 5px 14px; font-size: 12px; cursor: pointer;
  font-weight: 600; letter-spacing: 0.3px; transition: all 0.2s;
}
#btn-analysis:hover { border-color: #58a6ff; color: #58a6ff; }
#btn-analysis.active { background: #1f4e8c; border-color: #58a6ff; color: #58a6ff; }

/* ── Story Row (always visible) ── */
#story-section { display: block; padding: 10px 20px 0; }

/* ── Analysis Section (hidden until toggled) ── */
#analysis-section { display: none; }
#analysis-section.visible { display: block; }

.story-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  height: 380px;
}

/* ── Scenario Canvas ── */
#scenario-svg { width: 100%; height: 100%; }

.user-node { cursor: pointer; transition: opacity 0.2s; }
.user-node:hover circle { stroke-width: 3; }
.user-node.selected circle { stroke-width: 4; filter: drop-shadow(0 0 6px currentColor); }
.user-node.dimmed { opacity: 0.35; }

.signal-ring {
  fill: none; stroke-width: 1; opacity: 0.15;
  animation: pulse-ring 2s ease-out infinite;
}
@keyframes pulse-ring {
  0%   { r: 28px; opacity: 0.2; }
  100% { r: 52px; opacity: 0; }
}

.link-line { stroke-width: 1.5; stroke-dasharray: 5 4; opacity: 0.5;
  animation: dash-flow 1.2s linear infinite; }
.link-line.poor { stroke: #f85149; animation-duration: 2.4s; }
.link-line.degraded { stroke: #e3b341; }
.link-line.good { stroke: #3fb950; }
@keyframes dash-flow { to { stroke-dashoffset: -18; } }

/* ── Application Panel ── */
#app-panel .panel-body { padding: 12px; overflow: hidden; }

.app-placeholder {
  display: flex; align-items: center; justify-content: center;
  height: 100%; color: #484f58; font-size: 13px; text-align: center;
}

.quality-banner {
  border-radius: 6px; padding: 5px 12px; font-size: 12px; font-weight: 700;
  text-align: center; letter-spacing: 0.4px; margin-bottom: 10px;
}
.quality-banner.good    { background: #1a3a1e; color: #3fb950; border: 1px solid #3fb950; }
.quality-banner.degraded{ background: #3a2e10; color: #e3b341; border: 1px solid #e3b341; }
.quality-banner.poor    { background: #3a1414; color: #f85149; border: 1px solid #f85149; }

/* Video app */
.video-wrap {
  position: relative; border-radius: 6px; overflow: hidden;
  background: #000; aspect-ratio: 16/9; width: 100%;
}
.video-screen {
  width: 100%; height: 100%;
  background: linear-gradient(135deg, #1a2a4a 0%, #0d1f3c 50%, #1a2a4a 100%);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: #58a6ff; transition: filter 0.8s ease;
}
.video-screen.blurred-1 { filter: blur(2px); }
.video-screen.blurred-2 { filter: blur(5px) brightness(0.7); }
.video-screen.blurred-3 { filter: blur(10px) brightness(0.5); }
.video-buffering {
  position: absolute; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #8b949e; flex-direction: column; gap: 8px;
}
.spinner {
  width: 28px; height: 28px; border: 3px solid #30363d;
  border-top-color: #58a6ff; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.video-stats {
  display: flex; justify-content: space-between;
  font-size: 11px; color: #8b949e; margin-top: 6px; padding: 0 2px;
}

/* Robot app */
.robot-wrap { display: flex; flex-direction: column; gap: 8px; height: 100%; }
.robot-header {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; font-weight: 700; color: #c9d1d9;
}
.robot-icon { font-size: 24px; }
.robot-terminal {
  flex: 1; background: #0d1117; border: 1px solid #30363d; border-radius: 6px;
  padding: 8px 10px; font-family: monospace; font-size: 11px; overflow: hidden;
  color: #3fb950; display: flex; flex-direction: column; gap: 3px;
}
.robot-terminal .cmd { color: #c9d1d9; }
.robot-terminal .ok  { color: #3fb950; }
.robot-terminal .err { color: #f85149; }
.robot-terminal .warn{ color: #e3b341; }
.latency-row {
  display: flex; align-items: center; justify-content: space-between;
  background: #161b22; border-radius: 6px; padding: 6px 10px; font-size: 12px;
}
.latency-val { font-size: 20px; font-weight: 700; font-family: monospace; }
.latency-val.good    { color: #3fb950; }
.latency-val.degraded{ color: #e3b341; }
.latency-val.poor    { color: #f85149; }

/* Drone app */
.drone-wrap { display: flex; flex-direction: column; gap: 8px; height: 100%; }
.drone-hud {
  flex: 1; background: #0a0f1a; border: 1px solid #1f4e8c;
  border-radius: 8px; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.drone-crosshair { color: #1f78b4; font-size: 38px; position: relative; z-index: 2; }
.drone-ring {
  position: absolute; border-radius: 50%; border: 1px solid #1f78b4;
  opacity: 0.3; animation: drone-ring 2s ease-in-out infinite;
}
.drone-ring:nth-child(1) { width: 70px; height: 70px; animation-delay: 0s; }
.drone-ring:nth-child(2) { width: 110px; height: 110px; animation-delay: 0.5s; }
.drone-ring:nth-child(3) { width: 150px; height: 150px; animation-delay: 1s; }
@keyframes drone-ring {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50%       { opacity: 0.1; transform: scale(1.05); }
}
.drone-overlay {
  position: absolute; inset: 0; background: rgba(248,81,73,0.18);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #f85149; letter-spacing: 1px;
  z-index: 3; animation: flicker 0.4s ease-in-out infinite alternate;
}
@keyframes flicker { from { opacity: 1; } to { opacity: 0.5; } }
.drone-stats {
  display: flex; justify-content: space-between;
  font-size: 11px; color: #8b949e; padding: 0 2px;
}
.drone-stat-val { font-weight: 700; font-family: monospace; }
.drone-stat-val.good    { color: #3fb950; }
.drone-stat-val.degraded{ color: #e3b341; }
.drone-stat-val.poor    { color: #f85149; }

/* ── Explanation Panel ── */
#explain-panel .panel-body {
  padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
}
.expl-slice-badge {
  display: inline-block; border-radius: 4px; padding: 2px 8px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.5px; margin-right: 6px;
}
.expl-section { display: flex; flex-direction: column; gap: 6px; }
.expl-title { font-size: 11px; font-weight: 700; color: #8b949e; text-transform: uppercase; letter-spacing: 0.5px; }
.expl-body { font-size: 12px; color: #c9d1d9; line-height: 1.6; }
.expl-decision {
  background: #1c2128; border-left: 3px solid #58a6ff;
  border-radius: 0 4px 4px 0; padding: 6px 10px;
  font-size: 11px; font-family: monospace; color: #79c0ff;
}
.expl-impact {
  background: #161b22; border-radius: 6px; padding: 8px 10px;
  font-size: 12px; color: #c9d1d9; line-height: 1.6;
}
.expl-divider { border: none; border-top: 1px solid #30363d; margin: 2px 0; }
.expl-empty { color: #484f58; font-size: 13px; text-align: center; padding: 20px; }
