/* ============================================================
   Video Intelligence — design tokens
   Palette moved off the old flat blue (#4f7cff on navy) to a
   warm amber accent on neutral charcoal, with teal reserved
   exclusively for evidence/citation affordances so "this is
   clickable proof" reads as its own visual language.
   ============================================================ */
:root {
  --bg:         #0a0b0d;
  --surface:    #131519;
  --surface-2:  #1a1d23;
  --surface-3:  #22262e;
  --border:     #2a2f38;
  --border-soft:#1f242b;

  --text:       #e9eaed;
  --text-dim:   #939aa6;
  --text-faint: #6b7280;

  --accent:     #e0a03c;
  --accent-hi:  #f0b455;
  --accent-dim: rgba(224, 160, 60, 0.12);

  --teal:       #4fd1c5;
  --teal-dim:   rgba(79, 209, 197, 0.12);
  --green:      #4ade80;
  --red:        #f87171;
  --red-dim:    rgba(248, 113, 113, 0.12);

  --radius:   10px;
  --radius-sm: 7px;
  --shadow:   0 6px 24px rgba(0, 0, 0, 0.45);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

/* The UA's [hidden]{display:none} lives in the user-agent origin, so ANY author
   rule that sets display (.auth-view{display:grid}, .app-view{display:flex},
   .card-body{...}) silently beats it and the "hidden" element renders anyway.
   Without this, the login page and the app shell were both visible, stacked. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
.muted { color: var(--text-dim); }
.small { font-size: 12px; }

/* ============================ buttons ============================ */
.btn {
  font: inherit; font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--surface-3);
  color: var(--text);
  cursor: pointer;
  transition: background .13s ease, border-color .13s ease, opacity .13s ease;
  white-space: nowrap;
}
.btn:hover { background: #2b3039; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #1a1204; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hi); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; border-color: var(--border); color: var(--red); }
.btn-danger:hover { background: var(--red-dim); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { display: block; width: 100%; text-align: center; }

/* ============================ inputs ============================ */
input[type="text"], input[type="email"], input[type="password"],
input:not([type]), select, textarea, .file-input {
  font: inherit;
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color .13s ease, box-shadow .13s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
textarea { min-height: 76px; resize: vertical; }
select.select { cursor: pointer; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; font-weight: 500; }
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; }

/* ============================ auth page ============================ */
.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(224,160,60,.10), transparent 70%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 30px;
  box-shadow: var(--shadow);
}
.auth-brand { display: flex; gap: 13px; align-items: flex-start; margin-bottom: 24px; }
.auth-logo { color: var(--accent); font-size: 26px; line-height: 1; }
.auth-brand h1 { font-size: 19px; }
.auth-brand p { font-size: 12.5px; color: var(--text-dim); margin-top: 3px; }

.auth-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--radius-sm); margin-bottom: 20px; }
.auth-tab {
  flex: 1; font: inherit; font-size: 13px; padding: 7px; cursor: pointer;
  background: transparent; border: none; color: var(--text-dim); border-radius: 5px;
}
.auth-tab.active { background: var(--surface-3); color: var(--text); font-weight: 500; }

.auth-status { font-size: 12.5px; margin-top: 12px; min-height: 18px; text-align: center; }
.auth-status.error { color: var(--red); }
.auth-status.ok { color: var(--green); }
.auth-foot { margin-top: 22px; font-size: 11.5px; color: var(--text-faint); text-align: center; }

/* ============================ app shell ============================ */
.app-view { display: flex; min-height: 100vh; }

.sidebar {
  width: 218px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 12px;
  position: sticky; top: 0; height: 100vh;
}
.side-brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 600; font-size: 14.5px; padding: 0 8px 18px;
}
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  font: inherit; font-size: 13.5px; text-align: left;
  padding: 9px 11px; border-radius: var(--radius-sm);
  background: transparent; border: none; color: var(--text-dim); cursor: pointer;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent-hi); font-weight: 500; }
.nav-ico { width: 15px; text-align: center; opacity: .85; }

.side-foot { margin-top: auto; border-top: 1px solid var(--border-soft); padding-top: 12px; }
.side-user { font-size: 11.5px; color: var(--text-faint); padding: 0 8px 8px; word-break: break-all; }

.main { flex: 1; min-width: 0; padding: 24px 28px 48px; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
}
.page-head h2 { font-size: 21px; }
.page-head p { font-size: 13px; margin-top: 2px; }
.page-head .select { width: auto; min-width: 220px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px);} to { opacity: 1; transform: none; } }

/* ============================ cards ============================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--border-soft);
  background: var(--surface-2);
}
.card-head h3 { font-size: 13.5px; }
.card-body { padding: 16px; }

.empty { color: var(--text-faint); font-size: 13px; padding: 16px; text-align: center; }
.empty.tall { padding: 46px 16px; }

.notice {
  padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px;
  background: var(--accent-dim); color: var(--accent-hi);
  border: 1px solid rgba(224,160,60,.25); margin-bottom: 16px;
}
.notice.danger { background: var(--red-dim); color: var(--red); border-color: rgba(248,113,113,.25); }

/* ============================ library ============================ */
.library-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.list-card { margin-bottom: 0; }

.video-list { list-style: none; margin: 0; padding: 6px; max-height: 560px; overflow-y: auto; }
.video-list li {
  padding: 10px 11px; border-radius: var(--radius-sm); cursor: pointer;
  display: flex; flex-direction: column; gap: 6px;
  border: 1px solid transparent; transition: background .12s, border-color .12s;
}
.video-list li:hover { background: var(--surface-2); }
.video-list li.selected { background: var(--accent-dim); border-color: rgba(224,160,60,.3); }
.vl-name { font-size: 13px; font-weight: 500; word-break: break-all; line-height: 1.3; }
.vl-row { display: flex; align-items: center; gap: 8px; }

.status-badge {
  font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 20px;
  text-transform: uppercase; letter-spacing: .03em;
  background: var(--surface-3); color: var(--text-dim);
}
.status-indexed { background: rgba(74,222,128,.14); color: var(--green); }
.status-processing, .status-queued, .status-uploaded { background: var(--accent-dim); color: var(--accent-hi); }
.status-failed { background: var(--red-dim); color: var(--red); }

.mini-progress { flex: 1; height: 3px; background: var(--surface-3); border-radius: 2px; overflow: hidden; }
.mini-progress > div { height: 100%; background: var(--accent); transition: width .4s ease; }

.detail-card { margin-bottom: 0; }
.detail-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--border-soft); background: var(--surface-2);
}
.detail-head h3 { font-size: 13.5px; word-break: break-all; }

/* --- the player: constrained so a vertical 720x1280 clip cannot
       take over the page the way it did before --- */
.player-shell {
  height: 300px;
  background: #000;
  display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--border-soft);
}
.player-shell video {
  max-height: 100%; max-width: 100%;
  height: 100%; width: auto;
  display: block; outline: none;
}
.player-meta {
  padding: 8px 16px; font-size: 11.5px; color: var(--text-faint);
  font-family: var(--mono); border-bottom: 1px solid var(--border-soft);
}
.summary { padding: 14px 16px; font-size: 13px; color: var(--text-dim); border-bottom: 1px solid var(--border-soft); }
.summary b { color: var(--text); font-weight: 600; }

.subtabs { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--border-soft); }
.subtab {
  font: inherit; font-size: 12.5px; padding: 7px 13px; cursor: pointer;
  background: transparent; border: none; color: var(--text-dim);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subtab:hover { color: var(--text); }
.subtab.active { color: var(--accent-hi); border-bottom-color: var(--accent); font-weight: 500; }
.subpanel { display: none; }
.subpanel.active { display: block; }

.table-scroll { max-height: 340px; overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); font-weight: 600;
  padding: 9px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.data-table td { padding: 9px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--surface-2); }
.ts-cell { font-family: var(--mono); font-size: 11.5px; color: var(--teal); white-space: nowrap; }

.keyframe-gallery {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px; padding: 14px; max-height: 380px; overflow-y: auto;
}
.keyframe-card {
  background: var(--surface-2); border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm); overflow: hidden; cursor: pointer;
  transition: border-color .12s, transform .12s;
}
.keyframe-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.keyframe-card img { width: 100%; height: 88px; object-fit: cover; display: block; background: #000; }
.keyframe-ts { font-family: var(--mono); font-size: 10.5px; color: var(--teal); padding: 5px 7px 0; }
.keyframe-caption {
  font-size: 11px; color: var(--text-dim); padding: 2px 7px 7px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* ============================ chat ============================ */
.chat-card { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 420px; margin-bottom: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 16px; }

.chat-msg { max-width: 760px; }
.chat-msg.user { align-self: flex-end; }
.chat-msg.user .bubble {
  background: var(--accent-dim); border: 1px solid rgba(224,160,60,.25);
  padding: 9px 14px; border-radius: 14px 14px 3px 14px; color: var(--text);
}
.chat-msg.assistant .bubble { padding: 0; }
.msg-role {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); font-weight: 600; margin-bottom: 6px;
}
/* narrated answers read as prose, so give them book-ish rhythm */
.prose { font-size: 14px; line-height: 1.72; color: var(--text); }
.prose p { margin: 0 0 11px; }
.prose p:last-child { margin-bottom: 0; }

.stream-caret {
  display: inline-block; width: 7px; height: 15px; margin-left: 2px;
  background: var(--accent); vertical-align: text-bottom;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

.thinking { display: flex; gap: 4px; align-items: center; padding: 3px 0; }
.thinking i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-faint);
  display: inline-block; animation: bounce 1.2s infinite;
}
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,60%,100% { opacity:.25; transform: translateY(0);} 30% { opacity:1; transform: translateY(-3px);} }

.chat-meta { margin-top: 9px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.confidence-pill {
  font-size: 11px; padding: 2px 9px; border-radius: 20px;
  background: rgba(74,222,128,.13); color: var(--green); font-weight: 600;
}
.confidence-pill.mid { background: var(--accent-dim); color: var(--accent-hi); }
.confidence-pill.low { background: var(--red-dim); color: var(--red); }
.warn-pill { font-size: 11px; color: var(--red); }

.evidence-block { margin-top: 10px; border-top: 1px solid var(--border-soft); padding-top: 9px; }
.evidence-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-faint); font-weight: 600; margin-bottom: 6px;
}
.evidence-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.evidence-chip {
  display: flex; gap: 8px; align-items: baseline;
  padding: 6px 9px; border-radius: var(--radius-sm); cursor: pointer;
  background: var(--surface-2); font-size: 12px; color: var(--text-dim);
  transition: background .12s, color .12s;
}
.evidence-chip:hover { background: var(--teal-dim); color: var(--text); }
.evidence-chip .ts { font-family: var(--mono); font-size: 11px; color: var(--teal); flex-shrink: 0; }
.evidence-source-tag {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .04em;
  padding: 1px 6px; border-radius: 3px; background: var(--surface-3);
  color: var(--text-faint); flex-shrink: 0; font-weight: 600;
}
.evidence-snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* inline [video_id @ mm:ss] citations, rewritten into clickable pills */
.cite {
  font-family: var(--mono); font-size: 11px; cursor: pointer;
  color: var(--teal); background: var(--teal-dim);
  padding: 1px 6px; border-radius: 4px; white-space: nowrap;
  border: 1px solid rgba(79,209,197,.22);
}
.cite:hover { background: rgba(79,209,197,.25); }

.chat-input-row { display: flex; gap: 9px; padding: 13px; border-top: 1px solid var(--border-soft); background: var(--surface-2); }
.chat-input-row input { flex: 1; }

/* ============================ compare ============================ */
.compare-picker { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 16px; }
.compare-picker .field { margin-bottom: 0; min-width: 190px; }
.vs { color: var(--text-faint); font-size: 12px; padding-bottom: 10px; font-weight: 600; }

.compare-split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.split-col { margin-bottom: 16px; }
.split-head-a { border-left: 3px solid var(--accent); }
.split-head-b { border-left: 3px solid var(--teal); }
.split-section { padding: 14px 16px; }
.split-section h4 { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); margin-bottom: 8px; }

.bullets { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; font-size: 13px; }
.bullets.pad { padding: 14px 16px; }
.bullets li { padding-left: 14px; position: relative; color: var(--text-dim); line-height: 1.5; }
.bullets li::before { content: "▸"; position: absolute; left: 0; color: var(--accent); }
.bullets li.none { padding-left: 0; color: var(--text-faint); font-style: italic; }
.bullets li.none::before { content: ""; }

.diff-table td:first-child { font-weight: 500; color: var(--text); width: 160px; }
.diff-table .col-a { border-left: 2px solid rgba(224,160,60,.3); }
.diff-table .col-b { border-left: 2px solid rgba(79,209,197,.3); }
.diff-table td.cell-a { border-left: 2px solid rgba(224,160,60,.3); color: var(--text-dim); }
.diff-table td.cell-b { border-left: 2px solid rgba(79,209,197,.3); color: var(--text-dim); }

/* ============================ report ============================ */
.report-grid { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 16px; align-items: start; }
.checklist { display: flex; flex-direction: column; gap: 6px; max-height: 170px; overflow-y: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; }
.checklist label { display: flex; gap: 8px; align-items: center; font-size: 12.5px; cursor: pointer; color: var(--text-dim); }
.checklist input { width: auto; }
.file-input { padding: 7px; font-size: 12px; }

.spinner-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-dim); margin-bottom: 12px; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress { height: 3px; background: var(--surface-3); border-radius: 2px; overflow: hidden; }
.progress-bar.indeterminate { height: 100%; width: 40%; background: var(--accent); animation: slide 1.3s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

.ready-badge { color: var(--green); font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.dl-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ============================ responsive ============================ */
@media (max-width: 1100px) {
  .library-grid, .report-grid, .compare-split { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .app-view { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; gap: 10px; padding: 10px; overflow-x: auto; }
  .side-brand { padding: 0 6px 0 4px; }
  .side-nav { flex-direction: row; }
  .side-foot { margin-top: 0; border-top: none; padding-top: 0; margin-left: auto; }
  .side-user { display: none; }
  .main { padding: 16px; }
  .player-shell { height: 230px; }
}
