:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #1c2330; --muted: #6b7482; --line: #e2e5ea;
  --accent: #1f6feb; --accent-soft: #e3edff; --visual: #b35c00; --visual-soft: #fff1e0;
  --warn: #c62828; --hit: #fff3a8; --kw: #dbe8ff; --seg-a: #eef1f5; --seg-b: #e4e8ee;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b; --panel: #1a1f27; --ink: #e6e9ee; --muted: #8b95a3; --line: #2b323d;
    --accent: #5b9dff; --accent-soft: #1e2d45; --visual: #f0a04b; --visual-soft: #3a2a17;
    --warn: #ff7b7b; --hit: #5a4d00; --kw: #22375a; --seg-a: #232a34; --seg-b: #2a323e;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* top bar */
.top { display: flex; gap: 12px; align-items: center; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 650; white-space: nowrap; }
.logo { color: var(--accent); }
.tag { font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 4px; }
.submit { display: flex; gap: 8px; flex: 1; min-width: 260px; align-items: flex-start; }
.submit textarea { flex: 1; min-width: 0; resize: none; line-height: 1.4; max-height: 9.5em; overflow-y: auto; }
textarea, input[type=search], select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
select { max-width: 220px; }
.recent { position: relative; }
.recent-menu { position: absolute; right: 0; top: calc(100% + 6px); width: min(440px, calc(100vw - 32px)); max-height: 60vh; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 6px; z-index: 10; }
.recent-item { display: flex; align-items: center; gap: 6px; border-radius: 6px; }
.recent-item:hover, .recent-item.current { background: var(--accent-soft); }
.recent-item .open { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; padding: 6px 8px; }
.recent-item .open span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item .open small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-item .badge { font-size: 11px; font-weight: 600; border-radius: 4px; padding: 0 5px; margin-right: 4px; background: var(--accent-soft); color: var(--accent); }
.recent-item .badge.failed { background: var(--visual-soft); color: var(--warn); }
#recent-btn { white-space: nowrap; }
.account { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
#who { font-size: 13px; }
.account form { margin: 0; }

/* login page */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: min(340px, 100%); display: flex; flex-direction: column; gap: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.login .brand { font-size: 18px; margin-bottom: 4px; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login input { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 15px; color: var(--ink); }
.login-error { margin: 0; color: var(--warn); font-size: 14px; }

/* job header: title and how long each step took */
.job-head { margin-bottom: 10px; min-width: 0; }
#job-title { display: block; font-weight: 650; font-size: 17px; line-height: 1.3; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
#job-title:hover { text-decoration: underline; }
#job-meta { margin-top: 2px; }
.recent-item .del { border: 0; background: transparent; padding: 6px 9px; color: var(--muted); }
.recent-item .del:hover { color: var(--warn); background: var(--visual-soft); }
.recent-menu .muted { padding: 8px; display: block; }
button { cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; text-decoration: none; color: inherit; font-size: 14px; }

/* empty state */
.empty { max-width: 720px; margin: 48px auto; padding: 0 16px; }
.empty h1 { font-size: 24px; margin-bottom: 8px; }
.empty p, .steps { color: var(--muted); }
.steps li { margin: 8px 0; }

/* layout */
.app { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 16px; padding: 16px; max-width: 1500px; margin: 0 auto; }
@media (max-width: 900px) { .app { grid-template-columns: 1fr; } }
.left, .right { min-width: 0; }
.right { display: flex; flex-direction: column; max-height: calc(100vh - 90px); position: sticky; top: 72px; }
@media (max-width: 900px) { .right { max-height: none; position: static; } }

video { width: 100%; aspect-ratio: 16 / 9; background: #000; border-radius: var(--radius); display: block; }
.status { display: flex; gap: 10px; align-items: center; padding: 10px 12px; margin-bottom: 10px; border-radius: var(--radius); background: var(--accent-soft); }
.status.error { background: var(--visual-soft); color: var(--warn); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--accent); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
.status.error .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* timeline */
.timeline { position: relative; height: 44px; margin-top: 10px; border-radius: 8px; overflow: hidden; cursor: pointer; background: var(--seg-a); }
.tl-segs, .tl-marks { position: absolute; inset: 0; }
.tl-seg { position: absolute; top: 0; bottom: 0; border-right: 1px solid var(--line); font-size: 11px; color: var(--muted); padding: 3px 5px; overflow: hidden; white-space: nowrap; }
.tl-seg.alt { background: var(--seg-b); }
.tl-labels { position: absolute; inset: 0; pointer-events: none; }
.tl-label { position: absolute; top: 0; height: 17px; padding: 2px 0 0 4px; font-size: 11px; line-height: 1; color: var(--muted); border-left: 1px solid var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.timeline.dragging { cursor: grabbing; }
.tl-seg.active { box-shadow: inset 0 -3px 0 var(--accent); }
.tl-mark { position: absolute; bottom: 4px; width: 3px; height: 16px; border-radius: 2px; background: var(--accent); opacity: .8; pointer-events: none; }
.tl-mark.visual { height: 4px; bottom: 22px; background: var(--visual); opacity: .55; width: auto; }
.tl-mark.hl { opacity: 1; box-shadow: 0 0 0 2px var(--panel); height: 26px; z-index: 2; }
.tl-mark.visual.hl { height: 6px; }
.tl-mark.low { background: var(--muted); }
.tl-head { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); left: 0; pointer-events: none; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin: 6px 2px 0; align-items: center; }
.legend #tl-time { margin-left: auto; font-variant-numeric: tabular-nums; }
.zoom { display: inline-flex; align-items: center; gap: 2px; margin-left: auto; }
.zoom + #tl-time { margin-left: 12px; }
.zoom button { padding: 0 8px; font-size: 13px; line-height: 20px; border-radius: 6px; }
.zoom #z-label { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; }
@media (max-width: 600px) { .legend { flex-wrap: wrap; gap: 6px 12px; } }

/* overview: the whole video, shown only when the timeline is zoomed in */
.overview { position: relative; height: 16px; margin-top: 10px; border-radius: 5px; background: var(--seg-a); cursor: pointer; overflow: hidden; }
.ov-marks { position: absolute; inset: 0; }
.ov-mark { position: absolute; top: 3px; bottom: 3px; width: 1px; background: var(--accent); opacity: .7; pointer-events: none; }
.ov-mark.visual { top: 0; bottom: auto; height: 3px; width: auto; background: var(--visual); opacity: .6; }
.ov-win { position: absolute; top: 0; bottom: 0; border: 2px solid var(--accent); border-radius: 5px; background: rgba(31,111,235,.10); pointer-events: none; min-width: 6px; }
.ov-head { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); pointer-events: none; }
.overview:not([hidden]) + .timeline { margin-top: 4px; }
.tick { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.tick.spoken { background: var(--accent); } .tick.visual { background: var(--visual); }

.now { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
@media (max-width: 600px) { .now { grid-template-columns: 1fr; } }
.now > div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.now h4 { margin: 0 0 4px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.now p { margin: 0; font-size: 14px; max-height: 7.5em; overflow: auto; }

/* controls */
.controls { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 18px; margin-top: 12px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.ctl label { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.ctl output { color: var(--ink); font-variant-numeric: tabular-nums; }
.ctl input[type=range] { width: 100%; accent-color: var(--accent); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; border-radius: 0; padding: 6px 8px; font-size: 13px; background: transparent; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.controls.busy .seg, .controls.busy #kw { opacity: .6; }
.ctl.actions { display: flex; gap: 8px; align-items: end; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { border: 0; background: transparent; border-radius: 0; padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tab { overflow: auto; flex: 1; min-height: 0; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card-h { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.summary { margin: 0; white-space: pre-line; }
.summary.loading { color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--kw); border: 1px solid transparent; font-size: 14px; cursor: pointer; }
.chip:hover, .chip.hl { border-color: var(--accent); }
.chip.visual { background: var(--visual-soft); border: 1px dashed var(--visual); }
.chip.visual:hover, .chip.visual.hl { border-style: solid; }
.chip.low { opacity: .55; }
.chip.low::after { content: "?"; color: var(--warn); font-weight: 700; }
.chip.none { cursor: default; opacity: .5; }
.chip .n { font-size: 11px; color: var(--muted); }
.chip .tr { font-size: 12px; color: var(--muted); font-style: italic; }
.chip.demo { cursor: default; font-size: 13px; padding: 1px 8px; }

/* transcript */
.search { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; position: sticky; top: 0; background: var(--bg); padding-bottom: 4px; z-index: 1; }
.search input { flex: 1; min-width: 0; }
.follow { font-size: 13px; color: var(--muted); display: block; margin-bottom: 8px; }
.transcript .seg-line { display: grid; grid-template-columns: 48px 1fr; gap: 8px; padding: 6px 4px; border-radius: 6px; }
.transcript .seg-line.active { background: var(--accent-soft); }
.ts { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; cursor: pointer; padding-top: 2px; }
.w { cursor: pointer; border-radius: 3px; }
.w:hover { text-decoration: underline; }
.w.kw { background: var(--kw); }
.w.low { color: var(--muted); text-decoration: underline dotted var(--warn); }
.w.hit { background: var(--hit); }
.w.hit.cur { outline: 2px solid var(--accent); }
.w.now { background: var(--accent); color: #fff; }

.captions .cap { display: grid; grid-template-columns: 90px 1fr; gap: 10px; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); margin-bottom: 8px; cursor: pointer; }
.captions .cap.active { border-color: var(--accent); background: var(--accent-soft); }
.captions .cap p { margin: 0; font-size: 14px; }
#fuse-state { margin-left: auto; }
.ghost.small { padding: 2px 8px; font-size: 13px; }
.ghost:disabled { opacity: .5; cursor: default; }
