/* beams-replay UI — research-tool aesthetic, dark slate + amber accents.
   Type scale: 11/12/13/15. Spacing scale: 4/8/12/16/24/32. */

:root {
    --bg:          #0a0e14;
    --panel:       #0f141c;
    --panel-2:     #161c26;
    --panel-3:     #1d2533;
    --line:        #2a3548;
    --line-soft:   #1c2433;
    --line-strong: #3d4a63;
    --text:        #d4dde8;
    --text-dim:    #a4afc1;
    --muted:       #6c7a90;
    --muted-faint: #4a5366;
    --cyan:        #7cc8de;
    --cyan-dim:    #4d8ea3;
    --amber:       #e8b75a;
    --track:       #f3bf4f;
    --green:       #5fdc8f;
    --red:         #ff6b5e;
    --magenta:     #c987c5;
    --accent:      #88ccdd;
    --selection:   rgba(124, 200, 222, 0.18);

    --r-sm:        2px;
    --r-md:        4px;
    --shadow-md:   0 1px 3px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
::selection { background: var(--selection); }

html, body { height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font: 13px/1.5 ui-sans-serif, system-ui, -apple-system, "Inter", "Segoe UI", sans-serif;
    font-feature-settings: "ss01", "ss02", "cv11";
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}
.mono { font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace; }
code, kbd, samp, .num { font-family: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace; }
.num { font-variant-numeric: tabular-nums; }

a { color: var(--cyan); text-decoration: none; transition: color .12s; }
a:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

button, input, select, textarea { font: inherit; color: inherit; }
button {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line);
    padding: 5px 10px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: border-color .12s, color .12s, background .12s;
}
button:hover  { border-color: var(--cyan); color: var(--cyan); }
button:active { background: var(--panel-3); }
button:disabled { color: var(--muted-faint); cursor: not-allowed; }
button.primary { background: var(--cyan-dim); border-color: var(--cyan); color: #06141a; font-weight: 600; }
button.primary:hover { background: var(--cyan); color: #06141a; }

select, input[type="text"], input[type="number"], input[type="search"], input[type="datetime-local"], textarea {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 5px 8px;
    transition: border-color .12s, background .12s;
    font-size: 12px;
}
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 24px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%237cc8de' stroke-width='1.4' stroke-linecap='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 9px 6px;
    cursor: pointer;
    line-height: 1.2;
}
select:hover { border-color: var(--line-strong); }
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--cyan); }
select option { background: var(--panel); color: var(--text); }
input[type="checkbox"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 12px; height: 12px;
    border: 1px solid var(--line);
    border-radius: 2px;
    background: var(--bg);
    cursor: pointer;
    vertical-align: -1px;
    transition: border-color .12s, background .12s;
}
input[type="checkbox"]:hover { border-color: var(--line-strong); }
input[type="checkbox"]:checked {
    background: var(--cyan-dim);
    border-color: var(--cyan);
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M2 6l3 3 5-6' fill='none' stroke='%23061418' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 11px 11px;
}

/* ----- shell ----- */
#app {
    height: 100vh;
    display: grid;
    grid-template-rows: 36px minmax(0, 1fr);
    background: var(--bg);
}

#topbar {
    background: linear-gradient(180deg, var(--panel) 0%, var(--bg) 100%);
    border-bottom: 1px solid var(--line-soft);
    padding: 0 16px;
    display: flex;
    gap: 14px;
    align-items: center;
    font-size: 11px;
    letter-spacing: 0.04em;
    user-select: none;
}
#topbar .brand {
    color: var(--text);
    font-weight: 700;
    letter-spacing: 0.06em;
}
#topbar .brand::before {
    content: "▸";
    color: var(--amber);
    margin-right: 6px;
}
#topbar .crumb {
    color: var(--muted);
    text-transform: lowercase;
    letter-spacing: 0.02em;
}
#topbar .crumb a { color: var(--text-dim); border-bottom: 1px dashed transparent; padding-bottom: 1px; }
#topbar .crumb a:hover { color: var(--cyan); border-bottom-color: var(--cyan-dim); text-decoration: none; }
#topbar .sep { color: var(--muted-faint); }
#topbar .spacer { flex: 1; }
#topbar .meta {
    color: var(--muted);
    font-family: ui-monospace, monospace;
    font-size: 11px;
}
#topbar .nav-link {
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 4px 8px;
    border-radius: var(--r-sm);
}
#topbar .nav-link:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }

/* ----- main scroll area ----- */
#main { padding: 16px; min-height: 0; overflow: auto; }
#main.flush { padding: 0; }

/* ----- panels ----- */
.panel {
    background: var(--panel);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-md);
}
.panel + .panel { margin-top: 12px; }
.panel-h {
    padding: 8px 12px;
    border-bottom: 1px solid var(--line-soft);
    background: var(--panel-2);
    border-top-left-radius: var(--r-md);
    border-top-right-radius: var(--r-md);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
}
.panel-h .accent { color: var(--cyan); }
.panel-h .spacer { flex: 1; }
.panel-h .hint   { color: var(--muted); text-transform: none; letter-spacing: 0; font-size: 11px; }
.panel-b { padding: 12px; }
.panel-b.tight { padding: 0; }

/* ----- key-value lists ----- */
.kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 16px;
    font-family: ui-monospace, monospace;
    font-size: 11.5px;
}
.kv dt { color: var(--muted); white-space: nowrap; }
.kv dd { color: var(--text); word-break: break-word; }

/* ----- tables ----- */
table.data {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    font-family: ui-monospace, monospace;
    font-size: 11.5px;
}
table.data th, table.data td {
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid var(--line-soft);
}
table.data th {
    color: var(--muted);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.06em;
    font-weight: 500;
    background: var(--panel-2);
    position: sticky;
    top: 0;
    z-index: 2;
}
table.data tbody tr:hover { background: var(--panel-2); }
table.data tbody tr.selected { background: var(--selection); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .pri { color: var(--text); }

/* ----- pills ----- */
.pill {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 10px;
    font-family: ui-monospace, monospace;
    letter-spacing: 0.04em;
    border: 1px solid transparent;
    line-height: 1.5;
}
.pill.ok      { background: rgba( 95,220,143, 0.10); color: var(--green);   border-color: rgba(95,220,143,0.25); }
.pill.failed  { background: rgba(255,107, 94, 0.12); color: var(--red);     border-color: rgba(255,107,94,0.30); }
.pill.skipped { background: rgba(108,122,144, 0.12); color: var(--muted);   border-color: rgba(108,122,144,0.25); }
.pill.warn    { background: rgba(232,183, 90, 0.12); color: var(--amber);   border-color: rgba(232,183,90,0.30); }
.pill.info    { background: rgba(124,200,222, 0.10); color: var(--cyan);    border-color: rgba(124,200,222,0.25); }

/* ----- skeleton + spinner ----- */
.skeleton {
    background: linear-gradient(90deg, var(--panel-2) 0%, var(--panel-3) 50%, var(--panel-2) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: var(--r-sm);
    color: transparent;
    user-select: none;
}
@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.spin { display: inline-block; width: 10px; height: 10px; border: 1.5px solid var(--cyan-dim);
        border-top-color: var(--cyan); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- index page (runs list) ----- */
.index-h {
    display: flex; align-items: baseline; gap: 16px; margin-bottom: 12px;
}
.index-h h1 { font-size: 15px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.index-h .sub { color: var(--muted); font-size: 12px; }

.runs-grid { display: grid; gap: 8px; }
.run-card {
    background: var(--panel);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-md);
    padding: 10px 14px;
    display: grid;
    grid-template-columns: 1.3fr 1fr 1.2fr auto;
    gap: 12px;
    align-items: center;
    transition: border-color .12s, transform .08s;
}
.run-card:hover  { border-color: var(--line-strong); transform: translateY(-1px); }
.run-card .id    { font-family: ui-monospace, monospace; font-size: 12.5px; color: var(--text); }
.run-card .id a  { color: var(--text); }
.run-card .id a:hover { color: var(--cyan); }
.run-card .ts    { font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); }
.run-card .stats { font-family: ui-monospace, monospace; font-size: 11px; color: var(--text-dim); display:flex; gap: 12px; }
.run-card .stats .n { color: var(--text); }
.run-card .pills { display: flex; gap: 6px; }

/* ----- run detail page ----- */
.run-grid {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 12px;
}
.actions a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--panel-2);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-sm);
    color: var(--text);
    margin-bottom: 6px;
    transition: border-color .12s, background .12s;
}
.actions a::after { content: "→"; color: var(--muted); transition: color .12s, transform .12s; }
.actions a:hover { border-color: var(--cyan); text-decoration: none; background: var(--panel-3); }
.actions a:hover::after { color: var(--cyan); transform: translateX(2px); }
.actions a.disabled { opacity: 0.4; pointer-events: none; }

.stage-row {
    display: grid;
    grid-template-columns: 60px 1fr 60px;
    gap: 10px;
    align-items: center;
    font-family: ui-monospace, monospace;
    font-size: 11.5px;
    padding: 4px 0;
    border-bottom: 1px solid var(--line-soft);
}
.stage-row:last-child { border-bottom: none; }
.stage-row .name { color: var(--text); }
.stage-row .t    { color: var(--muted); text-align: right; }
.stage-row .err  { color: var(--red); font-size: 10.5px; grid-column: 1 / -1; padding-left: 70px; }

/* ----- recording page ----- */
.recording-grid {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr) 320px;
    grid-template-rows: minmax(280px, 1fr) minmax(180px, 0.6fr) minmax(220px, 0.7fr);
    gap: 8px;
    height: calc(100vh - 36px);
    padding: 8px;
}
.cell { background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r-md);
        display: flex; flex-direction: column; min-height: 0; min-width: 0; overflow: hidden; }
.cell-h { padding: 6px 10px; background: var(--panel-2); border-bottom: 1px solid var(--line-soft);
          font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim);
          display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.cell-h .accent { color: var(--cyan); }
.cell-h .spacer { flex: 1; }
.cell-b { flex: 1 1 auto; min-height: 0; min-width: 0; position: relative; overflow: hidden; }
.cell-b.scroll { overflow: auto; }
.cell-b.padded { padding: 10px; }

.cell.cell-meta   { grid-column: 1; grid-row: 1; }
.cell.cell-map    { grid-column: 2; grid-row: 1; }
.cell.cell-list   { grid-column: 3; grid-row: 1 / span 3; }
.cell.cell-imu    { grid-column: 1 / span 2; grid-row: 2; }
.cell.cell-chans  { grid-column: 1 / span 2; grid-row: 3; }

#leaflet-map { width: 100%; height: 100%; background: #0a0e14; }
.leaflet-container { background: #0a0e14 !important; }
.leaflet-tile-pane { filter: invert(0.92) hue-rotate(180deg) brightness(0.85) contrast(0.95); }
.leaflet-control-attribution { font-size: 10px !important; background: rgba(15,20,28,0.85) !important;
                                color: var(--muted-faint) !important; }
.leaflet-control-attribution a { color: var(--cyan-dim) !important; }
.leaflet-control-zoom a { background: var(--panel) !important; color: var(--cyan) !important;
                          border-color: var(--line-strong) !important; }

/* ----- BTR page ----- */
.layout-sidebar {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 8px;
    height: calc(100vh - 36px);
    padding: 8px;
}
.sidebar {
    background: var(--panel);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-md);
    padding: 10px;
    overflow: auto;
    display: flex; flex-direction: column; gap: 8px;
}
.sidebar h3 {
    font-size: 10.5px;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.08em;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--line-soft);
    padding-bottom: 3px;
}
.sidebar select, .sidebar input { width: 100%; }
.sidebar button { width: 100%; }

/* canvas wrappers */
.canvas-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}
.canvas-wrap canvas { display: block; }

#hover {
    position: absolute;
    pointer-events: none;
    background: rgba(15, 20, 28, 0.95);
    color: var(--text);
    padding: 5px 8px;
    font-family: ui-monospace, monospace;
    font-size: 11px;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-sm);
    z-index: 100;
    white-space: nowrap;
    box-shadow: var(--shadow-md);
}

#audio-bar {
    background: var(--panel);
    border: 1px solid var(--line-soft);
    border-radius: var(--r-sm);
    padding: 8px;
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11.5px;
}
#audio-bar audio { flex: 1; height: 28px; }

/* ----- waveform & traces ----- */
.chans { display: flex; flex-direction: column; height: 100%; }
.chan-row {
    display: grid;
    grid-template-columns: 50px 1fr 80px;
    gap: 8px;
    align-items: center;
    flex: 1 1 25%;
    min-height: 0;
    border-bottom: 1px solid var(--line-soft);
    padding: 4px 8px;
}
.chan-row:last-child { border-bottom: none; }
.chan-label { font-family: ui-monospace, monospace; font-size: 11px; color: var(--cyan); }
.chan-canvas { width: 100%; height: 100%; min-width: 0; }
.chan-controls button { padding: 2px 6px; font-size: 10px; }

/* ----- upload dropzone ----- */
.dropzone {
    border: 1.5px dashed var(--line-strong);
    border-radius: var(--r-md);
    padding: 14px;
    text-align: center;
    color: var(--muted);
    transition: border-color .12s, color .12s, background .12s;
    cursor: pointer;
}
.dropzone.drag { border-color: var(--cyan); color: var(--cyan); background: var(--panel-2); }
.dropzone .hint { font-size: 11px; }
.dropzone input { display: none; }

/* ----- empty + error states ----- */
.state {
    padding: 20px;
    text-align: center;
    color: var(--muted);
    font-size: 12px;
}
.state .icon { font-size: 16px; opacity: 0.5; display: block; margin-bottom: 6px; }
.state.err { color: var(--red); }

/* ----- utility ----- */
.hide { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 6px; }
.gap-4  { gap: 4px; }
.gap-12 { gap: 12px; }
.text-muted   { color: var(--muted); }
.text-dim     { color: var(--text-dim); }
.text-accent  { color: var(--cyan); }
.text-amber   { color: var(--amber); }
.text-green   { color: var(--green); }
.text-red     { color: var(--red); }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; }
.mb-8 { margin-bottom: 8px; }
.fs-11 { font-size: 11px; } .fs-12 { font-size: 12px; }

/* legacy bits the older pages still reference */
.panels { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 12px; }
.kv-flex { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
table.kv { border-collapse: collapse; font-family: ui-monospace, monospace; font-size: 11.5px; width: 100%; }
table.kv th, table.kv td { border-bottom: 1px solid var(--line-soft); padding: 6px 8px; text-align: left; }
table.kv th { background: var(--panel-2); color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; font-size: 10px; }
table.runs { border-collapse: collapse; font-family: ui-monospace, monospace; font-size: 11.5px; width: 100%; }
table.runs th, table.runs td { border-bottom: 1px solid var(--line-soft); padding: 6px 10px; text-align: left; }
table.runs th { background: var(--panel-2); color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 10px; }
table.runs tr:hover { background: var(--panel-2); }
