/* RodmanTranscribe */
:root {
  --accent: #4f46e5;
  --accent-2: #6366f1;
  --accent-dark: #4338ca;
  --bg: #f5f6fb;
  --panel: #ffffff;
  --line: #e3e5ef;
  --text: #1e2030;
  --muted: #6b7090;
  --ok: #16a34a;
  --warn: #b45309;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 22, 60, 0.08), 0 8px 24px rgba(20, 22, 60, 0.05);
}
* { box-sizing: border-box; }
/* Several elements (`.recording-bar`, `.find-bar`, `.banner`, `.status`) set
   `display: flex` and were also marked with the HTML `hidden` attribute as
   their initial state. CSS `display` wins over the UA `[hidden] {display:none}`
   rule, so they were actually visible on first paint — the recording bar
   would show "Stop" before the user had clicked Record. Force-restore the
   semantic of the attribute so `el.hidden = true` always hides. */
[hidden] { display: none !important; }
/* `overflow-x: clip` on html+body stops iOS Safari from auto-shrinking
   the layout when any descendant briefly reports an intrinsic width
   wider than the viewport (the cause of the "starts zoomed in" bug
   on first paint). Prefer `clip` over `hidden` so the body doesn't
   become a scroll container. */
html, body { margin: 0; height: 100%; overflow-x: clip; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}
button { font: inherit; color: inherit; cursor: pointer; }
select, input { font: inherit; color: inherit; }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding:
    max(14px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    calc(60px + env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

.rodmanoffice-back {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 8px;
  background: #fff; border: 1px solid var(--line); color: var(--muted);
  text-decoration: none; font-size: 12px; font-weight: 600;
}
.rodmanoffice-back:hover { border-color: var(--accent); color: var(--accent); }

.topbar { display: flex; align-items: center; margin: 14px 0 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { line-height: 0; }
.brand-title { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.brand-sub { font-size: 12px; color: var(--muted); }

.banner {
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
  display: flex; align-items: center; gap: 12px;
}
.banner-warn { background: #fff7ed; border: 1px solid #fed7aa; color: #9a3412; }
.banner-ok { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }

/* Diagnostics panel */
.debug-panel {
  margin-top: 16px; background: #0b1020; color: #cdd3f0;
  border: 1px solid #1d2542; border-radius: var(--radius); overflow: hidden;
}
.debug-head {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: #0f1530; border-bottom: 1px solid #1d2542;
  font-size: 13px;
}
.debug-head .muted { color: #8893c0; }
.debug-actions { margin-left: auto; display: flex; gap: 6px; }
.debug-lines {
  margin: 0; padding: 8px 12px; list-style: none; max-height: 320px; overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
}
.debug-lines li { padding: 1px 0; }
.debug-lines .t { color: #6b73a0; }
.debug-lines .stage { color: #7ee787; }
.debug-lines .info  { color: #9db2ff; }
.debug-lines .warn  { color: #ffd479; }
.debug-lines .err   { color: #ff8a8a; font-weight: 600; }
.banner span { font-size: 13px; }
.banner-text { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.banner-warn .btn { white-space: nowrap; }

.layout {
  display: grid; gap: 16px;
  grid-template-columns: 1fr 1fr;
  grid-template-areas: "source settings" "transcript transcript";
}
.panel-source     { grid-area: source; }
.panel-settings   { grid-area: settings; }
.transcript-panel { grid-area: transcript; }
@media (max-width: 820px) {
  /* On mobile, the natural flow is "pick a file → watch the transcript →
     tweak settings if needed". Settings goes last so the user lands on
     the source picker, not a wall of options. */
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas: "source" "transcript" "settings";
  }
}

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
  /* Grid items default to min-content min-width — without this the
     widest descendant (e.g. a long <select> option label) widens the
     whole track and the page reports an intrinsic width > viewport. */
  min-width: 0;
}
.panel-title { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 15px; }
.step {
  display: inline-grid; place-items: center; width: 22px; height: 22px;
  border-radius: 50%; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
}

/* Source / dropzone */
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 26px 16px; text-align: center; transition: border-color .15s, background .15s;
}
.drop.has-source { display: none; }
.drop-icon { font-size: 34px; }
.drop-headline { font-weight: 700; margin: 8px 0 2px; }
.drop-sub { color: var(--muted); margin: 4px 0; }
.drop-actions { display: flex; gap: 8px; justify-content: center; margin: 8px 0; }
.drop-formats { font-size: 11px; color: var(--muted); margin: 6px 0 0; }

.recording-bar {
  display: flex; align-items: center; gap: 10px; margin-top: 12px;
  padding: 10px 12px; border-radius: 8px; background: #fef2f2; border: 1px solid #fecaca;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; margin-left: auto; font-weight: 700; }
@keyframes pulse { 50% { opacity: 0.3; } }

.source-info { display: flex; flex-direction: column; gap: 10px; }
.source-meta { display: flex; align-items: center; gap: 10px; }
.source-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-dur { color: var(--muted); font-variant-numeric: tabular-nums; }
.source-meta .btn-ghost { margin-left: auto; }
.waveform { width: 100%; height: 64px; background: #fafaff; border-radius: 8px; cursor: pointer; }
audio { width: 100%; }

/* Settings */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.field select, .field input {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  /* Long <option> labels (e.g. "English · large-v3-q5_0 · max quality
     — 1.08 GB") otherwise stretch the select to its intrinsic content
     width on iOS Safari, which then triggers fit-to-content zoom on
     first paint. */
  max-width: 100%; min-width: 0;
}
.field-inline { flex-direction: row; align-items: center; justify-content: space-between; }
.field-inline input { width: 80px; }
.field-note { font-size: 12px; color: var(--muted); margin: -6px 0 12px; }
.field-note .ok, .ok { color: var(--ok); font-weight: 600; }
.field-note .warn, .warn { color: var(--warn); font-weight: 600; }
.checks { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; }

.btn {
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font-weight: 600; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-run { width: 100%; padding: 11px; font-size: 15px; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f1f1f8; border-color: transparent; color: var(--text); }
.btn-tiny { padding: 5px 10px; font-size: 12px; }
.btn-stop { margin-left: auto; background: var(--danger); border-color: var(--danger); color: #fff; }

.status { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.status-row { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 8px; }
.stages {
  list-style: none; padding: 8px 10px; margin: 4px 0 0;
  font-size: 12px; line-height: 1.6; color: var(--muted);
  background: #fafaff; border: 1px solid var(--line); border-radius: 8px;
  font-variant-numeric: tabular-nums;
}
.stages li { display: grid; grid-template-columns: 18px 1fr auto; align-items: baseline; gap: 6px; }
.stages li.done    { color: var(--ok); }
.stages li.active  { color: var(--accent); font-weight: 600; }
.stages li.pending { opacity: 0.55; }
.stages li.failed  { color: var(--danger); }
.stages .ico { display: inline-block; text-align: center; }
.stages .elapsed { color: var(--muted); font-weight: 400; }
.status-label { font-size: 12px; color: var(--muted); }
.bar { height: 8px; background: #eceefb; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.status-detail { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Transcript */
.transcript-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.transcript-toolbar .panel-title { margin: 0; }
.toolbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.export-select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.find-bar { display: flex; gap: 6px; margin-bottom: 8px; }
.find-bar input { flex: 1; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; }

.transcript {
  min-height: 240px; max-height: 56vh; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; background: #fff; line-height: 1.75;
}
.transcript:empty::before { content: attr(data-placeholder); color: var(--muted); }
.transcript.hide-ts .seg-ts { display: none; }
.seg { border-radius: 4px; }
.seg.active { background: #eef0ff; box-shadow: 0 0 0 2px #dfe2ff; }
.seg-ts {
  font-variant-numeric: tabular-nums; font-size: 11px; color: var(--accent);
  background: #eef0ff; border: none; border-radius: 4px; padding: 0 5px; margin-right: 4px;
}
.seg-ts:hover { background: var(--accent); color: #fff; }
.seg-text { }

/* Per-token confidence tinting. Off by default — only visible when the
   user flips the "Confidence" toggle (which adds .show-conf on .transcript). */
.tok { transition: background 0.15s; padding: 0 1px; border-radius: 2px; }
.transcript.show-conf .tok.conf-mid    { background: #fef3c7; } /* amber-100 */
.transcript.show-conf .tok.conf-low    { background: #fed7aa; } /* orange-200 */
.transcript.show-conf .tok.conf-vlow   { background: #fecaca; } /* red-200 */
.transcript.show-conf .seg-text.conf-mid    { background: #fef3c7; }
.transcript.show-conf .seg-text.conf-low    { background: #fed7aa; }
.transcript.show-conf .seg-text.conf-vlow   { background: #fecaca; }

.seg.proofread { background: #ecfdf5; box-shadow: 0 0 0 2px #d1fae5; }

.error { color: var(--danger); font-weight: 600; }
.rtf { margin-top: 8px; font-size: 12px; color: var(--muted); }
.report {
  margin-top: 8px; padding: 8px 12px; font-size: 12px;
  background: #f5f3ff; border: 1px solid #ddd6fe; color: #5b21b6;
  border-radius: 8px;
}

/* Custom dictionary modal rows */
.dict-rows { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 10px; }
.dict-row { display: grid; grid-template-columns: 1fr 16px 1fr auto auto; align-items: center; gap: 6px; }
.dict-row input[type="text"] { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.dict-row .check { font-size: 12px; color: var(--muted); }
#openDictBtn { margin-bottom: 10px; }
.modal-card footer { display: flex; align-items: center; gap: 10px; }
.modal-card footer .muted { margin-right: auto; }

/* Storage modal */
.modal { position: fixed; inset: 0; background: rgba(20, 22, 60, 0.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: var(--radius); width: min(460px, 92vw); box-shadow: var(--shadow); overflow: hidden; }
.modal-card header { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-card header h3 { margin: 0; font-size: 15px; }
.modal-card header .icon-btn { margin-left: auto; background: none; border: none; font-size: 16px; color: var(--muted); }
.modal-body { padding: 8px 16px; max-height: 60vh; overflow-y: auto; }
.modal-card footer { padding: 12px 16px; border-top: 1px solid var(--line); }
.muted { color: var(--muted); font-size: 12px; }
.storage-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.storage-row:last-child { border-bottom: none; }
.storage-row > div:first-child { flex: 1; }
.storage-name { font-weight: 600; }
.storage-sub { font-size: 12px; color: var(--muted); }

/* Shared drop overlay (lib/ui/dropzone.js) */
.drop-overlay {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(79, 70, 229, 0.12); z-index: 9000; pointer-events: none;
}
.drop-overlay.is-active { display: flex; }
.drop-overlay-card {
  border: 3px dashed var(--accent); border-radius: 14px; padding: 28px 44px;
  background: #fff; box-shadow: var(--shadow); text-align: center;
}
.drop-overlay-icon { font-size: 38px; color: var(--accent); line-height: 1; margin-bottom: 8px; }
.drop-overlay-title { font-size: 18px; font-weight: 700; }
.drop-overlay-sub { font-size: 12px; color: var(--muted); }

/* Panel-title row (Source heading + Recent button) */
.panel-title-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.panel-title-row .panel-title { margin: 0; flex: 1; }
.panel-title-row .btn-tiny { margin-left: auto; }

/* Cancel-state run button */
.btn-danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }

/* Hardware hint */
#hardwareHint .link {
  background: none; border: none; padding: 0; margin: 0;
  color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit;
}

/* Summary + chapters */
.summary {
  margin: 8px 0 10px; padding: 10px 12px; font-size: 13px;
  background: #ecfeff; border: 1px solid #a5f3fc; color: #155e75;
  border-radius: 8px;
}
.summary-tldr { line-height: 1.5; margin-bottom: 6px; }
.summary-chapters { margin: 0; padding-left: 18px; }
.summary-chapters li { margin: 2px 0; }
button.chapter {
  background: #cffafe; border: 1px solid #a5f3fc; border-radius: 4px;
  padding: 0 5px; font-variant-numeric: tabular-nums; font-size: 11px; cursor: pointer;
}
button.chapter:hover { background: #a5f3fc; }

/* Speaking-density histogram */
.density {
  display: block; width: 100%; height: 36px; margin-top: 8px;
  background: #fafaff; border-radius: 8px; cursor: pointer;
}

/* Live captions overlay */
.captions-overlay {
  position: fixed; left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom, 0) + 16px);
  margin: 0 auto; max-width: 880px; width: calc(100% - 32px);
  background: rgba(15, 17, 35, 0.92); color: #fff;
  padding: 14px 18px; border-radius: 12px; text-align: center;
  font-size: 18px; line-height: 1.35; pointer-events: none; z-index: 200;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
}
@media (max-width: 600px) { .captions-overlay { font-size: 16px; padding: 10px 14px; } }

/* Recent transcripts */
.recent-row {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.recent-row:last-child { border-bottom: none; }
.recent-info { flex: 1; min-width: 0; }
.recent-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-meta { font-size: 12px; color: var(--muted); }
.recent-sentence { font-size: 13px; color: var(--text); margin-top: 4px; line-height: 1.4; }
.recent-actions { display: flex; flex-direction: column; gap: 4px; }

/* iOS / mobile polish — bigger tap targets, looser spacing */
@media (max-width: 820px) {
  .btn { min-height: 40px; }
  .btn-tiny { min-height: 36px; padding: 7px 10px; }
  .toolbar-actions { gap: 8px; }
  .modal-card { width: min(560px, 96vw); }
  .modal-body { padding: 12px 16px; }
  /* 16 px is the iOS Safari threshold below which focusing a form
     control auto-zooms the page. The desktop default is 14 px (set
     via `select, input { font: inherit }`); we only bump on mobile. */
  .field select, .field input, .field-inline input,
  .find-bar input, .find-bar select, #proofreadKey, #translateLang,
  .export-select, .dict-row input[type="text"] {
    font-size: 16px;
  }
}
