/* ADAS Scenario Viewer. Same design tokens and components as the Developer Console
   (developer-platform.html); dark while <html> has .svh-dark (scripts/theme.js). */
:root {
  --c-bg: #ffffff; --c-bg2: #f5f5f7; --c-bg3: #ebebf0; --c-bg-hover: rgba(23, 26, 32, 0.045);
  --c-border: rgba(23, 26, 32, 0.09); --c-border-strong: rgba(23, 26, 32, 0.18);
  --c-text: #171a20; --c-text2: #5f6672; --c-text3: #8a919e;
  --c-accent: #2563eb; --c-accent-hover: #1d4ed8; --c-accent-soft: rgba(37, 99, 235, 0.10); --c-navy: #1E1A4D;
  --c-success: #15803d; --c-success-soft: rgba(21, 128, 61, 0.12); --c-danger: #dc2626; --c-danger-soft: rgba(220, 38, 38, 0.10);
  --c-warn: #b45309; --c-warn-soft: rgba(180, 83, 9, 0.12); --c-code-bg: #171a20; --c-code-text: #e5e7eb;
  --header-h: 48px; --sidebar-w: 15rem; --inspector-w: 19rem; --radius: 8px; --radius-lg: 12px;
  --shadow-card: 0 1px 2px rgba(23, 26, 32, 0.05), 0 10px 30px -18px rgba(23, 26, 32, 0.25);
  --shadow-pop: 0 10px 38px -10px rgba(22, 23, 24, 0.35), 0 10px 20px -15px rgba(22, 23, 24, 0.2);
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --scene-bg: #0d1117;
}
html.svh-dark {
  --c-bg: #0f1115; --c-bg2: #15181d; --c-bg3: #1b1e25; --c-bg-hover: rgba(255, 255, 255, 0.05);
  --c-border: rgba(255, 255, 255, 0.08); --c-border-strong: rgba(255, 255, 255, 0.18);
  --c-text: #f3f4f6; --c-text2: #9aa3b2; --c-text3: #6f7785;
  --c-accent: #3b82f6; --c-accent-hover: #60a5fa; --c-accent-soft: rgba(96, 165, 250, 0.14);
  --c-success: #4ade80; --c-success-soft: rgba(74, 222, 128, 0.14); --c-danger: #f87171; --c-danger-soft: rgba(248, 113, 113, 0.14);
  --c-warn: #fbbf24; --c-warn-soft: rgba(251, 191, 36, 0.14); --c-code-bg: #0b0d11; --c-code-text: #e5e7eb;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4), 0 10px 30px -18px rgba(0, 0, 0, 0.7);
  --shadow-pop: 0 10px 38px -10px rgba(0, 0, 0, 0.7), 0 10px 20px -15px rgba(0, 0, 0, 0.5);
}
html, body { height: 100%; margin: 0; }
body { background: var(--c-bg2); color: var(--c-text); font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { flex-shrink: 0; }
.ico { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; border-radius: 4px; }
::-webkit-scrollbar { width: 8px; height: 8px; } ::-webkit-scrollbar-thumb { background: var(--c-border-strong); border-radius: 4px; }

/* shell: sidebar | main | inspector */
.viewer { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--inspector-w); height: 100svh; width: 100%; overflow: hidden; }
#sidebar, #inspector { display: flex; flex-direction: column; min-height: 0; background: var(--c-bg2); overflow-y: auto; }
#sidebar { border-right: 1px solid var(--c-border); }
#inspector { border-left: 1px solid var(--c-border); }
.sb-head { height: var(--header-h); flex: 0 0 auto; border-bottom: 1px solid var(--c-border); display: flex; align-items: center; gap: 8px; padding: 0 12px; font-weight: 600; }
.avatar { width: 30px; height: 30px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.sb-section { padding: 10px 12px 6px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--c-text3); }
.sb-item { display: flex; align-items: center; gap: 8px; min-height: 34px; padding: 4px 7px; margin: 0 7px; border-radius: 6px; color: var(--c-text); width: calc(100% - 14px); text-align: left; }
.sb-item .ico { color: var(--c-text2); }
.sb-item:hover { background: var(--c-bg3); }
.sb-item.active { background: var(--c-bg3); font-weight: 500; }
.sb-item .lbl { flex: 1; min-width: 0; }
.sb-item .sub { display: block; font-size: 11.5px; color: var(--c-text3); font-weight: 400; }
.layer { display: flex; align-items: center; gap: 8px; padding: 5px 14px; font-size: 13px; cursor: pointer; }
.layer input { accent-color: var(--c-accent); }
.layer .sw { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.sb-bottom { margin-top: auto; padding: 10px 7px; border-top: 1px solid var(--c-border); }

main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--c-bg); }
.hdr { height: var(--header-h); flex: 0 0 auto; display: flex; align-items: stretch; border-bottom: 1px solid var(--c-border); min-width: 0; }
.hdr-btn { height: 100%; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; color: var(--c-text); }
.hdr-btn:hover { background: var(--c-bg2); }
.hdr-btn .ico { color: var(--c-text2); }
.crumbs { display: flex; align-items: center; min-width: 0; flex: 1; padding: 0 16px; gap: 8px; font-weight: 500; white-space: nowrap; overflow: hidden; }
.crumbs .muted { color: var(--c-text2); font-weight: 400; }
.tabs { display: flex; align-items: stretch; border-left: 1px solid var(--c-border); }
.tab { display: inline-flex; align-items: center; padding: 0 14px; color: var(--c-text2); position: relative; white-space: nowrap; }
.tab:hover { color: var(--c-text); background: var(--c-bg2); }
.tab.active { color: var(--c-text); }
.tab.active::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; background: var(--c-accent); border-radius: 2px 2px 0 0; }
.hdr-right { margin-left: auto; display: flex; align-items: stretch; border-left: 1px solid var(--c-border); }

#stage { position: relative; flex: 1; min-height: 0; background: var(--scene-bg); overflow: hidden; }
#stage canvas.gl { display: block; width: 100%; height: 100%; }
#overlay2d { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl3d { position: absolute; transform: translate(-50%, -100%); font-size: 11px; font-family: SFMono-Regular, ui-monospace, Menlo, monospace; color: #fff; background: rgba(13, 17, 23, .72); border: 1px solid rgba(255,255,255,.18); border-radius: 4px; padding: 1px 5px; white-space: nowrap; }
.lbl3d.sel { border-color: #fbbf24; color: #fde68a; }
.stage-note { position: absolute; left: 12px; top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }
.stage-hint { position: absolute; right: 12px; bottom: 10px; font-size: 11.5px; color: rgba(255,255,255,.65); }
.stage-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: rgba(255,255,255,.7); font-size: 14px; }

.timeline { flex: 0 0 auto; border-top: 1px solid var(--c-border); padding: 8px 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.timeline input[type=range] { flex: 1; min-width: 160px; accent-color: var(--c-accent); }
.tl-track { position: relative; flex: 1; min-width: 160px; display: flex; align-items: center; height: 24px; }
.tl-track input { width: 100%; margin: 0; }
.tl-marks { position: absolute; left: 0; right: 0; top: 18px; height: 6px; pointer-events: none; }
.tl-mark { position: absolute; width: 2px; height: 6px; background: var(--c-warn); transform: translateX(-1px); }
.tl-time { font-family: SFMono-Regular, ui-monospace, Menlo, monospace; font-size: 12.5px; min-width: 112px; text-align: center; }
.perf { flex: 0 0 auto; border-top: 1px solid var(--c-border); background: var(--c-bg2); display: flex; flex-wrap: wrap; gap: 0; font-size: 12px; }
.perf div { padding: 6px 12px; border-right: 1px solid var(--c-border); color: var(--c-text2); white-space: nowrap; }
.perf b { color: var(--c-text); font-weight: 600; font-family: SFMono-Regular, ui-monospace, Menlo, monospace; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 6px; font-weight: 500; font-size: 13px; white-space: nowrap; box-shadow: inset 0 0 0 1px var(--c-border-strong); background: var(--c-bg); color: var(--c-text); }
.btn:hover { background: var(--c-bg2); }
.btn.primary { background: var(--c-accent); color: #fff; box-shadow: none; }
.btn.primary:hover { background: var(--c-accent-hover); }
.btn.sm { height: 26px; padding: 0 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.seg { display: inline-flex; background: var(--c-bg3); border-radius: 6px; padding: 2px; }
.seg button { padding: 4px 10px; border-radius: 4px; font-size: 12.5px; color: var(--c-text2); }
.seg button.active { background: var(--c-bg); color: var(--c-text); box-shadow: var(--shadow-card); }
.badge { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 500; background: var(--c-bg3); color: var(--c-text2); white-space: nowrap; }
.badge.ok { background: var(--c-success-soft); color: var(--c-success); }
.badge.warn { background: var(--c-warn-soft); color: var(--c-warn); }
.badge.err { background: var(--c-danger-soft); color: var(--c-danger); }
.badge.blue { background: var(--c-accent-soft); color: var(--c-accent); }
.badge .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
.card { background: var(--c-bg); border: 1px solid var(--c-border); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); margin: 10px 12px 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--c-border); font-size: 13px; font-weight: 600; }
.card-body { padding: 10px 12px; font-size: 12.5px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; }
.kv dt { color: var(--c-text2); } .kv dd { margin: 0; font-family: SFMono-Regular, ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; }
.muted { color: var(--c-text2); } .tiny { font-size: 12px; color: var(--c-text3); } .mono { font-family: SFMono-Regular, ui-monospace, Menlo, monospace; font-size: 12.5px; }
.notice { display: flex; gap: 8px; padding: 8px 10px; border-radius: var(--radius); background: var(--c-warn-soft); color: var(--c-text); font-size: 12.5px; align-items: flex-start; margin: 10px 12px 0; }
.notice .ico { color: var(--c-warn); margin-top: 1px; }
.empty { padding: 20px 12px; text-align: center; color: var(--c-text2); font-size: 12.5px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 11.5px; color: var(--c-text2); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; background: var(--sw); }

@media (max-width: 1100px) {
  .viewer { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  #inspector { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--c-border); max-height: 40vh; }
  .viewer { grid-template-rows: minmax(0, 1fr) auto; }
}
@media (max-width: 767px) {
  .viewer { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto; height: auto; min-height: 100svh; }
  #sidebar { border-right: 0; border-bottom: 1px solid var(--c-border); max-height: 36vh; }
  #stage { min-height: 48vh; }
  .tabs .tab { padding: 0 9px; }
}
