/* ============================================================
   System font, CSS custom properties, base reset
   ============================================================ */
:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #d0d4da;
  --border-subtle: #e8eaed;
  --text: #1a1c1e;
  --text-muted: #6b7280;
  --text-small: #8f95a0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-fg: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;

  --radius: 8px;
  --radius-sm: 4px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.10);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button { font-family: inherit; }

/* ============================================================
   Login page
   ============================================================ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 360px;
}

.login-card h1 { font-size: 1.3rem; font-weight: 600; margin-bottom: 0.25rem; }
.login-card .subtitle { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 1.75rem; }

.login-card label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.login-card .field-group { margin-bottom: 1.25rem; }

.login-card input[type="password"] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
  background: var(--bg);
}
.login-card input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.login-error {
  background: #fee2e2;
  color: var(--danger);
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  margin-bottom: 1rem;
  display: none;
}
.login-error.visible { display: block; }

/* ============================================================
   Shared button styles
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  line-height: 1.4;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
  text-decoration: none;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }

/* ============================================================
   App layout — top bar
   ============================================================ */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}
.topbar-title { font-weight: 600; font-size: 1.05rem; white-space: nowrap; }
.topbar-title span { color: var(--accent); }

.search-box {
  flex: 1;
  max-width: 420px;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  background: var(--bg);
}
.search-box:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.topbar-spacer { flex: 1; }

/* ============================================================
   Status strip
   ============================================================ */
.status-strip {
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  color: var(--text-muted);
}
.status-strip-summary {
  padding: 0.5rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: inherit;
  color: inherit;
  font-family: inherit;
}
.status-strip-summary:hover { background: var(--bg); }
.status-strip-detail {
  padding: 0 1.5rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.status-strip[data-open="false"] .status-strip-detail { display: none; }
.status-strip-errors { color: var(--danger); }
.status-strip-caret { transition: transform 0.12s; display: inline-block; }
.status-strip[data-open="true"] .status-strip-caret { transform: rotate(90deg); }

/* ============================================================
   Main layout — chip rail + content
   ============================================================ */
.layout {
  display: flex;
  align-items: flex-start;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  gap: 1.5rem;
}

.chip-rail {
  flex: 0 0 240px;
  position: sticky;
  top: 72px;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
}
.chip-rail h2 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-small); margin: 0.75rem 0 0.35rem; }
.chip-rail h2:first-child { margin-top: 0; }

.topic-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-size: 0.85rem;
  text-align: left;
  color: var(--text);
  width: 100%;
  font-family: inherit;
}
.topic-chip:hover { background: var(--surface); border-color: var(--border-subtle); }
.topic-chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.topic-chip[aria-pressed="true"] .chip-count { color: var(--accent-fg); opacity: 0.85; }
.chip-count { color: var(--text-small); font-variant-numeric: tabular-nums; }

.content-col { flex: 1; min-width: 0; }

.section-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}
.section-header h1 { font-size: 1.05rem; font-weight: 600; }
.result-count { color: var(--text-muted); font-size: 0.85rem; }
.clear-filter-btn { margin-left: auto; }

/* ============================================================
   Video card grid
   ============================================================ */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.9rem;
}

.video-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: box-shadow 0.12s, border-color 0.12s;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: left;
  font-family: inherit;
  width: 100%;
}
.video-card:hover { box-shadow: var(--shadow); border-color: var(--border); }

.video-card-name { font-weight: 600; font-size: 0.92rem; line-height: 1.35; word-break: break-word; }
.video-card-meta { color: var(--text-muted); font-size: 0.78rem; display: flex; align-items: center; gap: 0.4rem; }

.video-card-topics { display: flex; flex-direction: column; gap: 0.3rem; }
.video-card-topic-row { display: flex; align-items: baseline; gap: 0.4rem; font-size: 0.8rem; flex-wrap: wrap; }
.video-card-topic-label { font-weight: 500; }
.video-card-topic-ranges { color: var(--text-muted); font-variant-numeric: tabular-nums; }

.confidence-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.confidence-dot.high { background: var(--success); }
.confidence-dot.medium { background: var(--warn); }
.confidence-dot.low { background: var(--danger); }

.video-card-footer { margin-top: auto; display: flex; justify-content: flex-end; }

/* ============================================================
   Empty state
   ============================================================ */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}
.empty-state p { max-width: 420px; margin: 0 auto; }

/* ============================================================
   Detail modal
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 22, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 1rem;
  z-index: 100;
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.3rem 0.8rem;
  border-bottom: 1px solid var(--border-subtle);
}
.modal-title { font-size: 1.05rem; font-weight: 600; line-height: 1.35; }
.modal-close-btn { font-size: 1rem; }

.modal-body { padding: 1.1rem 1.3rem 1.4rem; display: flex; flex-direction: column; gap: 1rem; }
.modal-summary { color: var(--text); font-size: 0.88rem; line-height: 1.55; }
.modal-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }

.modal-topic { border-top: 1px solid var(--border-subtle); padding-top: 0.6rem; }
.modal-topic:first-of-type { border-top: none; padding-top: 0; }
.modal-topic-header { display: flex; align-items: center; gap: 0.45rem; font-size: 0.88rem; font-weight: 600; margin-bottom: 0.3rem; }
.modal-topic-ranges { display: flex; flex-direction: column; gap: 0.15rem; color: var(--text-muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }

.copy-feedback { font-size: 0.8rem; color: var(--success); }

/* ============================================================
   Misc
   ============================================================ */
.muted { color: var(--text-muted); }
.loading-note { color: var(--text-muted); font-size: 0.85rem; padding: 1rem 0; }
.error-note { color: var(--danger); font-size: 0.85rem; padding: 1rem 0; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .chip-rail { position: static; flex: 1 1 auto; max-height: none; width: 100%; }
}
