:root {
  --bg: #0f1117;
  --panel: #181b24;
  --panel-2: #1f2330;
  --border: #2a2f3d;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #6d8cff;
  --accent-2: #8a6dff;
  --good: #36c08a;
  --bad: #ff6b6b;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1b2030, var(--bg));
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 17, 23, 0.6);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 30px; }
.topbar h1 { font-size: 18px; margin: 0; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

/* Tab bar */
.tabs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  padding: 0 28px;
  max-width: 1200px;
  margin: 0 auto;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 14px 16px;
  cursor: pointer;
  border-radius: 0;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.layout {
  padding: 24px 28px 60px;
  max-width: 1200px;
  margin: 0 auto;
}
/* Enforce the `hidden` attribute everywhere — author `display` rules (e.g. the
   cropper's flex) would otherwise override the UA [hidden] { display:none }. */
[hidden] { display: none !important; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.search-input { padding: 8px 12px; font-size: 13px; min-width: 220px; }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.muted { color: var(--muted); font-weight: 400; opacity: 0.8; }
.settings-heading { margin: 8px 0 2px; font-size: 14px; color: var(--text); }
.settings-block { display: flex; flex-direction: column; gap: 20px; max-width: 520px; }
.restore-row { display: flex; align-items: flex-end; gap: 12px; }
.restore-row .field { flex: 1; }
/* Give the file picker and Restore button the same height so they line up. */
.restore-row .file-control {
  min-height: 44px;
  padding-top: 0;
  padding-bottom: 0;
  box-sizing: border-box;
}
.restore-row button[type="submit"] {
  min-height: 44px;
  box-sizing: border-box;
  padding: 0 20px;
  font-size: 14px;
}

/* Guide / how-to tab */
.guide { line-height: 1.6; }
.guide .hint { margin-bottom: 18px; }
.guide-heading {
  margin: 28px 0 6px;
  font-size: 15px;
  color: var(--text);
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.guide-p { color: var(--muted); font-size: 14px; margin: 0 0 12px; }
.guide-p a, .guide .hint a { vertical-align: baseline; }
.guide-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  list-style: none;
  margin: 0 0 8px;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
}
.guide-quickstart {
  margin: 8px 0 4px;
  padding: 4px 18px 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.guide-quickstart .quickstart-heading {
  border-top: none;
  padding-top: 14px;
  margin-bottom: 4px;
}
.quickstart-list { margin: 0; padding-left: 20px; color: var(--text); font-size: 14px; }
.quickstart-list li { margin: 6px 0; }
.guide-list { margin: 4px 0 6px; padding-left: 22px; color: var(--text); font-size: 14px; }
.guide-list li { margin: 8px 0; }
.guide-list ul { margin: 6px 0; padding-left: 20px; color: var(--muted); }
.guide-list strong { color: var(--text); }
.guide code {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
  font-family: ui-monospace, monospace;
  font-size: 12.5px;
  color: var(--accent);
}
.guide .badge { margin: 0 2px; }
.guide-note {
  margin: 12px 0 4px;
  padding: 10px 14px;
  background: rgba(109, 140, 255, 0.08);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
}
.guide-note strong { color: var(--accent); }

.stack { display: flex; flex-direction: column; gap: 12px; }
/* align-items: end bottom-aligns the inputs even when one label wraps to two
   lines (e.g. "Device (local only)"), keeping the fields level. */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: end; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }

input, select, textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 140, 255, 0.18);
}
textarea { resize: vertical; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label:first-child { font-size: 13px; color: var(--muted); }

/* Radio group (transcript source) — reset the generic bordered input look. */
.radio-group { border: 0; margin: 0; padding: 0; }
.radio-group legend { font-size: 13px; color: var(--muted); padding: 0; margin-bottom: 8px; }
.radio-group .radio {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.radio-group .radio + .radio { margin-top: 6px; }
.radio-group input[type="radio"] {
  width: auto;
  padding: 0;
  margin: 0;
  border-radius: 50%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Custom file picker — the native input is hidden but stays keyboard-focusable. */
.file-native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
.file-control {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  background: var(--panel-2);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.file-control:hover { border-color: var(--accent); background: #232838; }
.file-control.has-file { border-style: solid; }
.file-native:focus-visible + .file-control {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(109, 140, 255, 0.18);
}
.file-btn {
  background: rgba(109, 140, 255, 0.16);
  color: var(--accent);
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.file-name {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-control.has-file .file-name { color: var(--text); }

/* Inline transcript editor (Samples table → Edit text) */
.transcript-edit { display: flex; flex-direction: column; gap: 8px; min-width: 220px; }
.edit-text-area { width: 100%; box-sizing: border-box; }
.edit-actions { display: flex; gap: 12px; }

/* Audio cropper */
.cropper {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}
.crop-head { display: flex; align-items: baseline; justify-content: space-between; }
.crop-title { font-size: 13px; font-weight: 600; }
.crop-hint { font-size: 12px; color: var(--muted); }
.wave {
  width: 100%;
  height: 96px;
  display: block;
  border-radius: 8px;
  background: #12151e;
  cursor: ew-resize;
  touch-action: none;
}
.crop-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 13px;
  color: var(--muted);
}
.crop-stats strong { color: var(--text); }
.crop-controls { display: flex; align-items: center; gap: 14px; }

.advanced summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.advanced[open] { padding-top: 6px; }

/* "How was this generated" disclosure in the Generated audio table. */
.gen-meta { margin-top: 6px; }
.gen-meta summary { cursor: pointer; color: var(--accent); font-size: 12px; }
.gen-meta[open] { margin-top: 8px; }
.gen-text-label {
  margin-top: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.gen-text {
  margin: 4px 0 10px;
  padding: 8px 10px;
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
}
.gen-opts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px 14px;
  margin: 0;
}
.gen-opts div { display: flex; flex-direction: column; gap: 1px; }
.gen-opts dt { font-size: 11px; color: var(--muted); }
.gen-opts dd { margin: 0; font-size: 13px; color: var(--text); word-break: break-word; }

button { cursor: pointer; font-family: inherit; }
.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
}
.primary-btn:disabled { opacity: 0.55; cursor: progress; }
.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 13px;
  text-decoration: none;
}
.ghost-btn:hover:not(:disabled) { border-color: var(--accent); }
.ghost-btn:disabled, .link-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.link-btn {
  background: none; border: none; color: var(--accent);
  padding: 0; font-size: 13px;
}
.link-btn.danger { color: var(--bad); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th { color: var(--muted); font-weight: 600; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
th.sortable.active { color: var(--accent); }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
/* Keep the actions cell a table-cell so it vertically centers with the rest of
   the row (a flex td drops out of table layout and sticks to the top). */
td.actions { white-space: nowrap; }
td.actions > * { vertical-align: middle; }
td.actions > * + * { margin-left: 12px; }
.transcript-details { max-width: 360px; }
.transcript-details summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.transcript-details .gen-text { margin: 8px 0 0; }
.empty { color: var(--muted); text-align: center; padding: 24px; }
/* Small "generated/transcribed in Xs" caption under table cells. */
.metric { color: var(--muted); font-size: 12px; margin-top: 4px; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 5px;
}
.badge.ok { background: rgba(54, 192, 138, 0.16); color: var(--good); }
.badge.no { background: rgba(255, 107, 107, 0.14); color: var(--bad); }
.badge.lang { background: rgba(109, 140, 255, 0.16); color: var(--accent); font-family: ui-monospace, monospace; }

audio { height: 34px; max-width: 230px; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  z-index: 50;
}
.toast.ok { border-color: var(--good); }
.toast.err { border-color: var(--bad); }
.toast.pending { border-color: var(--accent); }
.toast.pending { display: flex; align-items: center; gap: 10px; }

/* Spinner used in the pending toast and table loading rows. */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: none;
  vertical-align: -2px;
}
.empty.loading { display: flex; align-items: center; justify-content: center; gap: 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Global busy lock: while a background op runs, dim + block the locked regions
   (they are also set `inert` in JS, which disables pointer/keyboard/focus). */
body.busy { cursor: progress; }
body.busy [inert] { opacity: 0.55; transition: opacity 0.15s; pointer-events: none; }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}

@media (max-width: 760px) {
  .topbar { padding: 14px 16px; flex-wrap: wrap; gap: 12px; }
  .topbar h1 { font-size: 16px; }
  .subtitle { font-size: 12px; }
  .logo { font-size: 26px; }

  .layout { grid-template-columns: 1fr; gap: 16px; padding: 16px 16px 48px; }
  .card { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }

  /* Inputs are easier to tap and never overflow the viewport. */
  input, select, textarea { font-size: 16px; width: 100%; }
  .primary-btn { padding: 13px 16px; }

  /* Turn each table row into a stacked card with header labels. */
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel-2);
    padding: 8px 14px;
    margin-bottom: 12px;
  }
  tbody tr:hover { background: var(--panel-2); }
  td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 9px 0;
    border: none;
    border-bottom: 1px solid var(--border);
  }
  td:last-child { border-bottom: none; }
  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
    flex: 0 0 auto;
  }
  /* Cells with wide content stack the label above and go full width. */
  td[data-label="Reference"],
  td[data-label="Play"],
  td[data-label="Transcript"],
  td.actions {
    flex-direction: column;
    align-items: stretch;
  }
  td[data-label="Transcript"] .transcript-details { max-width: none; }
  td.actions { gap: 10px; }
  td.actions > * + * { margin-left: 0; }
  td.actions .link-btn, td.actions a.link-btn {
    padding: 6px 0;
    font-size: 14px;
    text-align: left;
  }
  audio { max-width: 100%; width: 100%; }
  .empty { text-align: center; }
  .empty::before { content: ""; }
}

/* ---- Header actions & session --------------------------------------- */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-badge {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Login page ------------------------------------------------------ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
}
.login-brand {
  margin-bottom: 20px;
}
.login-brand h1 { font-size: 18px; margin: 0; }
.login-error {
  margin: 0;
  color: var(--bad);
  font-size: 14px;
}

/* ---- Disabled feature options --------------------------------------- */
/* A transcript source turned off server-side (see /api/config). */
.radio.disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.radio.disabled span { cursor: not-allowed; }

