:root {
    --bg: #0f1117; --surface: #1a1d27; --surface2: #242836;
    --border: #2e3344; --text: #e4e6f0; --text-dim: #8b8fa3;
    --critical: #ff4757; --critical-bg: rgba(255,71,87,0.12);
    --warning: #ffa502; --warning-bg: rgba(255,165,2,0.12);
    --caution: #2ed573; --caution-bg: rgba(46,213,115,0.12);
    --safe: #747d8c; --safe-bg: rgba(116,125,140,0.12);
    --accent: #5352ed;
}
* { margin:0; padding:0; box-sizing:border-box; }
body { background:var(--bg); color:var(--text); font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif; line-height:1.6; }
a { color:var(--accent); text-decoration:none; }
a:hover { text-decoration:underline; }
.container { max-width:1000px; margin:0 auto; padding:12px 16px; }
h1 { font-size:1.5rem; font-weight:700; margin-bottom:4px; }
h1 { font-size:1.2rem; margin:12px 0 4px; }
h2 { font-size:1.1rem; font-weight:600; margin:32px 0 16px; border-bottom:1px solid var(--border); padding-bottom:8px; }
h3 { font-size:0.9rem; font-weight:600; margin:12px 0 6px; }
.subtitle { color:var(--text-dim); font-size:0.8rem; margin-bottom:12px; }

/* Nav */
.nav { display:flex; gap:8px; margin-bottom:24px; flex-wrap:wrap; }
.nav a { padding:6px 16px; border-radius:8px; background:var(--surface); border:1px solid var(--border); font-size:0.85rem; }
.nav a.active { background:var(--accent); border-color:var(--accent); color:white; }

/* Score ring */
.score-hero { display:flex; flex-direction:column; align-items:center; }
.score-ring { position:relative; width:100%; aspect-ratio:1; }
.score-ring svg { width:100%; height:100%; transform:rotate(-90deg); }
.score-ring circle { fill:none; stroke-width:10; }
.score-ring .bg { stroke:var(--surface2); }
.score-ring .fg { stroke-linecap:round; transition:stroke-dashoffset 0.6s ease; }
.score-value { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; }
.score-number { font-size:clamp(2rem, 6vw, 3.5rem); font-weight:800; line-height:1; }
.score-unit { font-size:clamp(0.6rem, 1.5vw, 0.8rem); color:var(--text-dim); margin-top:1px; }
.score-grade { display:inline-block; margin-top:4px; font-size:clamp(0.8rem, 2vw, 1rem); font-weight:700; color:var(--text); }

/* Sub-metric pills */
.sub-metrics { display:flex; gap:12px; justify-content:center; margin:12px 0 32px; flex-wrap:wrap; }
.sub-metric { background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:14px 20px; min-width:140px; text-align:center; }
.sub-metric-label { font-size:0.75rem; color:var(--text-dim); margin-bottom:4px; }
.sub-metric-rate { font-size:1.4rem; font-weight:700; line-height:1.2; }
.sub-metric-unit { font-size:0.7rem; color:var(--text-dim); }
.sub-metric-grade { display:inline-block; margin-top:6px; padding:2px 10px; border-radius:10px; font-size:0.75rem; font-weight:700; }

/* Charts */
.chart-row { display:grid; grid-template-columns:1fr 1fr; gap:16px; margin:16px 0; }
.chart-box { background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:12px 14px; }
.chart-title { font-size:0.8rem; color:var(--text-dim); margin-bottom:8px; }
.chart-box canvas { width:100%!important; }
#replayCanvas, #summaryCanvas { width:100%; height:auto; aspect-ratio:1; }

/* Tables */
.event-table { width:100%; border-collapse:collapse; font-size:0.85rem; }
.event-table th { text-align:left; padding:8px 12px; color:var(--text-dim); font-weight:500; border-bottom:1px solid var(--border); font-size:0.8rem; }
.event-table td { padding:8px 12px; border-bottom:1px solid var(--border); }
.event-table tr:hover { background:var(--surface2); }
.event-table tr.replay-trigger { cursor:pointer; }
.badge { display:inline-block; padding:2px 8px; border-radius:4px; font-size:0.75rem; font-weight:600; }
.badge.critical { background:var(--critical-bg); color:var(--critical); }
.badge.warning { background:var(--warning-bg); color:var(--warning); }
.badge.caution { background:var(--caution-bg); color:var(--caution); }
.badge.safe { background:var(--safe-bg); color:var(--safe); }
.cat-badge { display:inline-block; padding:2px 8px; border-radius:4px; font-size:0.7rem; font-weight:600; }
.cat-badge.collision { background:rgba(255,71,87,0.15); color:#ff6b81; border:1px solid rgba(255,71,87,0.3); }
.cat-badge.proximity { background:rgba(255,165,2,0.12); color:#ffc048; border:1px solid rgba(255,165,2,0.2); }
.score-section { display:flex; gap:3%; align-items:stretch; margin:8px 0; }
.score-main-ring { flex:0 0 28%; }
.score-right-col { flex:1; display:flex; flex-direction:column; justify-content:center; gap:8px; min-width:0; }
.score-info { display:flex; align-items:center; gap:8px; font-size:clamp(0.7rem, 1.5vw, 0.85rem); flex-wrap:wrap; }
.score-device-name { font-weight:600; color:var(--text); }
.score-device-hours { color:var(--text-dim); margin-right:auto; }
.score-date-bar { display:flex; align-items:center; gap:4px; flex-shrink:0; }
.score-date-btn { background:none; border:1px solid var(--border); border-radius:6px; color:var(--text-dim); width:24px; height:24px; display:flex; align-items:center; justify-content:center; cursor:pointer; font-size:0.75rem; transition:all 0.2s; flex-shrink:0; }
.score-date-btn:hover { background:var(--surface2); color:var(--text); }
.score-date-text { font-size:clamp(0.7rem, 1.5vw, 0.85rem); color:var(--text); font-weight:500; }
.score-badges { display:flex; gap:2%; }
.replay-commentary { padding:8px 12px; background:var(--surface); border:1px solid var(--border); border-radius:8px; font-size:0.8rem; color:var(--text-dim); line-height:1.5; min-height:40px; white-space:pre-wrap; outline:none; max-width:400px; margin:8px auto; }
.summary-layout { display:flex; gap:12px; align-items:stretch; }
.summary-left { flex:0 0 auto; max-width:280px; }
.summary-right { flex:1; min-width:0; display:flex; align-items:center; }
.summary-deduction { position:absolute; top:8px; left:10px; font-size:1rem; font-weight:700; color:#ff4757; }
.summary-index { position:absolute; top:8px; right:10px; font-size:0.75rem; color:var(--text-dim); font-weight:600; }
.summary-meta-line { font-size:0.7rem; color:var(--text-dim); text-align:center; margin-top:4px; line-height:1.4; }
.summary-commentary { width:100%; padding:12px 16px; font-size:0.95rem; color:#e8e8e8; line-height:1.7; background:transparent; border:none; outline:none; white-space:pre-wrap; resize:none; }
.summary-commentary:focus { color:#fff; }
.summary-commentary:empty:before { content:attr(placeholder); color:var(--text-dim); opacity:0.5; }
@media (max-width:520px) {
    .summary-layout { flex-direction:column; }
    .summary-left { max-width:100%; }
    .summary-commentary { min-height:80px; }
}
.evt-gallery { position:relative; }
.evt-grid { display:grid; grid-template-columns:1fr 1fr 1fr 1fr; gap:6px; min-height:120px; }
.evt-card { background:var(--surface); border:1px solid var(--border); border-radius:8px; padding:8px 10px; cursor:pointer; transition:all 0.15s; display:flex; flex-direction:column; gap:3px; }
.evt-card:hover { background:var(--surface2); border-color:var(--accent); }
.evt-card .ec-time { font-size:0.72rem; color:var(--text-dim); }
.evt-card .ec-sev { margin:2px 0; }
.evt-card .ec-dur { font-size:0.68rem; color:var(--text-dim); }
.evt-page-nav { display:flex; justify-content:center; align-items:center; gap:12px; margin-top:8px; }
.evt-page-btn { background:var(--surface); border:1px solid var(--border); border-radius:6px; color:var(--text-dim); width:28px; height:28px; display:flex; align-items:center; justify-content:center; cursor:pointer; font-size:0.8rem; transition:all 0.2s; }
.evt-page-btn:hover { background:var(--surface2); color:var(--text); }
.evt-page-btn:disabled { opacity:0.3; cursor:default; }
.evt-page-info { font-size:0.72rem; color:var(--text-dim); }
@media (max-width:520px) { .evt-grid { grid-template-columns:1fr 1fr; } }
.tag-gallery { display:flex; flex-wrap:wrap; gap:8px; }
.tag-card { background:var(--surface); border:1px solid var(--border); border-radius:8px; padding:10px 14px; min-width:100px; }
.tag-id { font-weight:600; font-size:0.85rem; margin-bottom:2px; }
.tag-time { font-size:0.72rem; color:var(--text-dim); }
.tag-score { font-size:0.8rem; font-weight:600; margin-top:4px; }
.tag-events { font-weight:400; font-size:0.68rem; }
.replay-commentary:focus { border-color:#5352ed; color:var(--text); }
.uwb-fov-bar { display:flex; align-items:center; gap:6px; margin-top:4px; padding:4px 8px; background:var(--surface2); border-radius:6px; font-size:clamp(0.6rem, 1.3vw, 0.75rem); }
.uwb-fov-icon { font-size:clamp(0.7rem, 1.4vw, 0.85rem); }
.uwb-fov-label { color:var(--text); font-weight:600; white-space:nowrap; }
.uwb-fov-detail { color:var(--text-dim); white-space:nowrap; }
.eval-item { flex:1; display:flex; flex-direction:column; align-items:center; gap:4px; padding:4px 0; border-radius:8px; cursor:pointer; transition:background 0.2s; min-width:0; }
.eval-item:hover { background:var(--surface2); }
.eval-label { font-size:clamp(0.6rem, 1.4vw, 0.75rem); font-weight:600; white-space:nowrap; color:var(--text); }
.eval-ring { position:relative; width:90%; aspect-ratio:1; }
.eval-ring svg { width:100%; height:100%; }
.eval-ring-text { position:absolute; inset:0; display:flex; flex-direction:column; align-items:center; justify-content:center; }
.eval-ring-grade { font-size:clamp(0.55rem, 1.8vw, 0.8rem); font-weight:700; line-height:1; }
.eval-ring-counts { font-size:clamp(0.38rem, 1.1vw, 0.52rem); color:var(--text-dim); margin-top:2px; line-height:1.3; text-align:center; }
.summary-carousel { margin:4px 0; }
.summary-overlay { position:absolute; top:12px; left:12px; right:12px; pointer-events:none; display:flex; justify-content:space-between; align-items:flex-start; }
.summary-overlay .so-left { font-size:0.8rem; color:rgba(255,255,255,0.85); background:rgba(0,0,0,0.5); padding:4px 10px; border-radius:6px; backdrop-filter:blur(4px); }
.summary-overlay .so-right { font-size:0.75rem; color:rgba(255,255,255,0.7); background:rgba(0,0,0,0.4); padding:3px 8px; border-radius:6px; }
.summary-progress { position:absolute; bottom:0; left:0; height:3px; background:#5352ed; border-radius:0 0 8px 8px; transition:width 0.1s linear; }
.summary-dots { display:inline-flex; gap:6px; }
.summary-dots .dot { width:8px; height:8px; border-radius:50%; background:rgba(255,255,255,0.2); display:inline-block; transition:background 0.2s; }
.summary-dots .dot.active { background:#5352ed; }
.detail-toggle-btn { background:var(--surface); color:var(--text-dim); border:1px solid var(--border); padding:8px 24px; border-radius:8px; cursor:pointer; font-size:0.8rem; transition:all 0.2s; }
.detail-toggle-btn:hover { background:var(--surface2); color:var(--text); }

/* Detail tabs */
.detail-tabs { display:flex; gap:0; margin:20px 0 0; border-bottom:2px solid var(--border); }
.detail-tab { flex:1; padding:12px 8px; text-align:center; cursor:pointer; font-size:0.85rem; font-weight:500; color:var(--text-dim); background:transparent; border:none; border-bottom:2px solid transparent; margin-bottom:-2px; transition:all 0.2s; }
.detail-tab:hover { color:var(--text); background:var(--surface); }
.detail-tab.active { color:var(--text); border-bottom-color:var(--accent); }
.detail-tab .tab-count { display:block; font-size:1.1rem; font-weight:700; margin-top:2px; }
.detail-tab-panel { display:none; padding-top:16px; }
.detail-tab-panel.active { display:block; }

/* Heatmap */
.heatmap { overflow-x:auto; }
.heatmap table { border-collapse:collapse; font-size:0.75rem; width:100%; }
.heatmap td, .heatmap th { padding:4px 6px; text-align:center; min-width:36px; }
.heatmap th { color:var(--text-dim); font-weight:normal; }

/* Day section */
.day-section { background:var(--surface); border:1px solid var(--border); border-radius:12px; margin:12px 0; overflow:hidden; }
.day-header { padding:14px 20px; cursor:pointer; display:flex; justify-content:space-between; align-items:center; }
.day-header:hover { background:var(--surface2); }
.day-body { padding:0 20px 20px; display:none; }
.day-section.open .day-body { display:block; }
.day-score { font-size:1.5rem; font-weight:700; }
.day-meta { display:flex; gap:16px; font-size:0.85rem; color:var(--text-dim); }
.day-badges { display:flex; gap:6px; flex-wrap:wrap; }
.day-sub-metrics { display:flex; gap:8px; margin:8px 0; }
.day-sub-pill { padding:3px 10px; border-radius:6px; font-size:0.75rem; font-weight:600; }

/* Timeline */
.timeline { position:relative; height:32px; background:var(--bg); border-radius:6px; margin:8px 0; overflow:hidden; }
.timeline-mark { position:absolute; height:100%; min-width:2px; border-radius:2px; opacity:0.7; }
.timeline-labels { display:flex; justify-content:space-between; font-size:0.7rem; color:var(--text-dim); }

/* Replay */
.replay-panel { background:var(--surface); border:1px solid var(--border); border-radius:12px; margin:16px 0; overflow:hidden; }
.replay-header { padding:12px 20px; display:flex; justify-content:space-between; align-items:center; border-bottom:1px solid var(--border); }
.replay-status { padding:8px 20px; font-size:0.85rem; display:flex; justify-content:space-between; align-items:center; border-bottom:1px solid var(--border); }
.replay-canvas-wrap { max-width:400px; margin:8px auto; position:relative; }
.replay-canvas-wrap canvas { display:block; }
.replay-controls { padding:12px 20px; display:flex; gap:12px; align-items:center; border-top:1px solid var(--border); }
.replay-controls button { background:var(--accent); color:white; border:none; padding:6px 16px; border-radius:6px; cursor:pointer; font-size:0.85rem; }
.replay-controls button:hover { opacity:0.85; }
.replay-controls input[type=range] { flex:1; }

/* Device card */
.device-card { background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:20px; margin:12px 0; display:flex; justify-content:space-between; align-items:center; cursor:pointer; transition:border-color 0.2s; }
.device-card:hover { border-color:var(--accent); }

/* Info row */
.info-row { display:flex; gap:20px; margin:16px 0; flex-wrap:wrap; font-size:0.85rem; color:var(--text-dim); }

.footer { text-align:center; padding:40px 0; color:var(--text-dim); font-size:0.8rem; }
@media (max-width:768px) {
    .chart-row { grid-template-columns:1fr; }
    .sub-metrics { flex-direction:column; align-items:center; }
    .replay-canvas-wrap { width:100%; height:auto; aspect-ratio:1; }
    .score-main-ring { flex:0 0 25%; }
}
@media (max-width:420px) {
    .score-section { flex-direction:column; align-items:center; gap:8px; }
    .score-main-ring { flex:none; width:40%; }
    .score-right-col { width:100%; }
    .score-info { justify-content:center; flex-wrap:wrap; }
    .score-device-hours { margin-right:0; }
    .eval-item { gap:2px; }
    .eval-ring { width:80%; }
    .eval-label { font-size:clamp(0.55rem, 3vw, 0.7rem); }
    .uwb-fov-bar { flex-wrap:wrap; justify-content:center; text-align:center; }
}
/* Summary section */
.summary-fit { display:flex; flex-direction:column; min-height:0; }
.summary-fit .chart-box { flex-shrink:1; min-height:0; }
.summary-fit .chart-box canvas { max-height:20vh; }
.summary-fit .summary-carousel { flex-shrink:1; min-height:0; }
.summary-fit .replay-canvas-wrap { max-width:min(400px, 42vh); }

/* SPA-specific */
.loading { text-align:center; padding:40px; color:var(--text-dim); }
.back-link { cursor:pointer; color:var(--accent); font-size:0.85rem; margin-bottom:12px; display:inline-block; }
.back-link:hover { text-decoration:underline; }
