:root {
  --bg: #0f1115;
  --panel: #161a22;
  --panel-soft: #1b2030;
  --border: #232936;
  --fg: #e6e8ec;
  --muted: #8a93a6;
  --accent: #4cc9f0;
  --ok: #4ade80;
  --warn: #ffb703;
  --err: #ef4444;

  /* ETRI-AVSR system metric palette */
  --cpu:  #4cc9f0;
  --ram:  #80ed99;
  --gpu:  #ffb703;
  --vram: #ef476f;

  /* indicator strip palette */
  --ind-ratio:   #06d6a0;
  --ind-fps:     #4cc9f0;
  --ind-bitrate: #ffd166;
  --ind-latency: #ef476f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
}

/* ------------------------------------------------------------------ */
/* Header                                                              */
/* ------------------------------------------------------------------ */

.top-bar {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex; align-items: center; gap: 12px;
}
.brand h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: 0.02em; }

.controls { display: flex; align-items: center; gap: 8px; }

.file-picker {
  cursor: pointer;
  padding: 7px 12px;
  background: var(--accent); color: #0a0d12;
  border-radius: 6px; font-weight: 600; font-size: 13px;
}
.file-picker input { display: none; }
button {
  padding: 7px 12px;
  background: var(--panel-soft); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; font-size: 13px;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #0a0d12; border-color: var(--accent); font-weight: 600; }
.btn-secondary { background: transparent; }

.conn-state {
  color: var(--muted);
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
  font-size: 12px;
}
.conn-state.connected { color: var(--ok); border-color: rgba(74,222,128,.4); }
.conn-state.error     { color: var(--err); border-color: rgba(239,68,68,.4); }

/* ------------------------------------------------------------------ */
/* System metric cards (ETRI-AVSR style)                               */
/* ------------------------------------------------------------------ */

.sys-cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  margin-left: auto;
}

.sys-card {
  position: relative;
  min-height: 48px;
  padding: 6px 12px;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.sys-card-bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 0%;
  background: var(--bar-color, rgba(255,255,255,.08));
  transition: width .35s ease;
  z-index: 0;
}
.sys-card-spark {
  position: absolute; right: 8px; top: 6px;
  width: 56px; height: 14px;
  z-index: 1;
}
.sys-card-text {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 8px; row-gap: 0;
  align-items: baseline;
  min-width: 0;
}
.sys-label {
  grid-row: 1; grid-column: 1;
  color: var(--muted); font-size: 10px;
  text-transform: uppercase; letter-spacing: .05em;
}
.sys-value {
  grid-row: 1; grid-column: 3;
  font-size: 18px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0,0,0,.7);
}
.sys-meta {
  grid-row: 2; grid-column: 1 / span 3;
  font-size: 11px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0; padding-right: 60px; /* leave room for sparkline */
}

.sys-cpu  { --bar-color: rgba(76, 201, 240, .18); }
.sys-ram  { --bar-color: rgba(128, 237, 153, .18); }
.sys-gpu  { --bar-color: rgba(255, 183, 3,  .18); }
.sys-vram { --bar-color: rgba(239, 71, 111, .18); }
.sys-cpu  .sys-value { color: var(--cpu);  }
.sys-ram  .sys-value { color: var(--ram);  }
.sys-gpu  .sys-value { color: var(--gpu);  }
.sys-vram .sys-value { color: var(--vram); }
.sys-cpu  .sparkline-line { stroke: var(--cpu);  }
.sys-ram  .sparkline-line { stroke: var(--ram);  }
.sys-gpu  .sparkline-line { stroke: var(--gpu);  }
.sys-vram .sparkline-line { stroke: var(--vram); }

/* ------------------------------------------------------------------ */
/* Indicator strip                                                     */
/* ------------------------------------------------------------------ */

.indicator-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}
.ind-card {
  position: relative;
  min-height: 56px;
  padding: 6px 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-color, var(--accent));
  border-radius: 8px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: baseline;
  overflow: hidden;
}
.ind-ratio   { --accent-color: var(--ind-ratio);   }
.ind-fps     { --accent-color: var(--ind-fps);     }
.ind-bitrate { --accent-color: var(--ind-bitrate); }
.ind-latency { --accent-color: var(--ind-latency); }

.ind-label {
  grid-row: 1; grid-column: 1;
  color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em;
}
.ind-value {
  grid-row: 1; grid-column: 3;
  font-size: 22px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-color, var(--accent));
}
.ind-meta {
  grid-row: 2; grid-column: 1 / span 3;
  color: var(--muted); font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.ind-card .sparkline {
  grid-row: 2; grid-column: 1 / span 3;
  width: 100%; height: 18px;
  margin-top: 14px;
  align-self: end;
}
.sparkline { width: 100%; height: 16px; }
.sparkline-line {
  fill: none; stroke: var(--accent-color, var(--accent));
  stroke-width: 1.4; vector-effect: non-scaling-stroke;
}

/* ------------------------------------------------------------------ */
/* Video grid                                                          */
/* ------------------------------------------------------------------ */

.video-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 14px;
  padding: 14px 18px;
}
.video-column {
  display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.video-pane {
  position: relative;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
}
.pane-input { aspect-ratio: auto; min-height: 360px; }
.video-pane video,
.video-pane iframe {
  width: 100%; height: 100%;
  object-fit: contain;
  background: #000; border: 0; display: block;
}
.video-pane iframe[hidden],
.video-pane video[hidden] { display: none !important; }
.video-caption {
  position: absolute; bottom: 8px; right: 8px;
  padding: 4px 10px;
  background: rgba(0,0,0,.6);
  border-radius: 6px;
  font-size: 11px; color: #d4dae3;
  letter-spacing: .02em;
}
.video-warning {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(0,0,0,.85);
  color: var(--warn);
  font-size: 13px; text-align: center; line-height: 1.5;
  z-index: 2;
}
.video-warning[hidden] { display: none !important; }

/* ------------------------------------------------------------------ */
/* Modal (YouTube URL)                                                 */
/* ------------------------------------------------------------------ */

.modal { position: fixed; inset: 0; z-index: 1000;
         display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none !important; }
.modal-backdrop { position: absolute; inset: 0;
                  background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
.modal-dialog {
  position: relative; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 22px; min-width: 420px; max-width: 92vw;
  display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.modal-title { margin: 0; font-size: 16px; font-weight: 600; }
.modal-dialog input[type="url"] {
  width: 100%; padding: 9px 12px;
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px;
}
.modal-dialog input[type="url"]:focus { outline: none; border-color: var(--accent); }
.modal-error { color: var(--err); font-size: 12px; margin-top: -4px; }
.modal-error[hidden] { display: none !important; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

@media (max-width: 1280px) {
  .top-bar { grid-template-columns: 1fr; }
  .sys-cards { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 1080px) {
  .video-grid { grid-template-columns: 1fr; }
  .pane-input { min-height: 320px; }
}
@media (max-width: 720px) {
  .sys-cards, .indicator-strip { grid-template-columns: repeat(2, 1fr); }
}

/* ------------------------------------------------------------------ */
/* Module-toggle panel (post-processors / inference)                   */
/* ------------------------------------------------------------------ */

.config-strip { padding: 8px 16px 0; }
.config-panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px;
}
.config-panel summary {
  cursor: pointer; user-select: none; font-weight: 600;
  font-size: 13px; padding: 4px 0;
}
.config-warn { color: var(--warn, #f6c177); font-size: 11px; margin-left: 8px; }
.config-body {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 16px; padding: 8px 0 4px;
}
.config-group h3 {
  margin: 0 0 6px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
}
.config-list { display: flex; flex-direction: column; gap: 4px; }
.config-row {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
  padding: 2px 0; cursor: pointer;
}
.config-row input[type="number"] {
  width: 56px; padding: 2px 6px; background: var(--bg);
  color: var(--fg); border: 1px solid var(--border); border-radius: 4px;
}
.config-row.experimental { color: var(--warn, #f6c177); }
.config-row.experimental::after { content: " (experimental)"; opacity: .8; }

.det-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.pane-recon { position: relative; }

@media (max-width: 1080px) {
  .config-body { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .config-body { grid-template-columns: 1fr; }
}
