:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --surface-3: #e6e4dd;
  --border: #dedcd4;
  --text: #1c1d1f;
  --muted: #6b6c70;
  --faint: #9a9a9d;
  --accent: #1f6f5c;
  --accent-soft: #dcefe8;
  --accent-ink: #ffffff;
  --danger: #b4372c;
  --danger-soft: #f8e1de;
  --warn: #9a6400;
  --warn-soft: #fbefd6;
  --ins: #d9f0e1;
  --ins-ink: #145c34;
  --del: #fbe0dc;
  --del-ink: #8f2a20;
  --mark: #fff0a8;
  --now: #eef6f2;
  --s1: #2b6cb0; --s2: #b7472a; --s3: #2f855a; --s4: #805ad5;
  --s5: #b7791f; --s6: #c53f7a; --s7: #2c7a7b; --s8: #5a6472;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 16px rgb(0 0 0 / 0.04);
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151618; --surface: #1c1d20; --surface-2: #232428; --surface-3: #2c2d32; --border: #33353a;
    --text: #ececea; --muted: #a2a3a8; --faint: #74757b; --accent: #5fc4a6; --accent-soft: #1d3a32;
    --accent-ink: #0d1f1a; --danger: #f07b6f; --danger-soft: #3d201d; --warn: #e8b350; --warn-soft: #3a2e17;
    --ins: #173a26; --ins-ink: #8fe0ad; --del: #44221f; --del-ink: #f5a59c; --mark: #5b4e12; --now: #1f2a27;
    --s1: #78a9e8; --s2: #ee8d73; --s3: #73c995; --s4: #b39cf0; --s5: #e3b459; --s6: #ec88b4; --s7: #6cc8c9; --s8: #a3acb8;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #151618; --surface: #1c1d20; --surface-2: #232428; --surface-3: #2c2d32; --border: #33353a;
  --text: #ececea; --muted: #a2a3a8; --faint: #74757b; --accent: #5fc4a6; --accent-soft: #1d3a32;
  --accent-ink: #0d1f1a; --danger: #f07b6f; --danger-soft: #3d201d; --warn: #e8b350; --warn-soft: #3a2e17;
  --ins: #173a26; --ins-ink: #8fe0ad; --del: #44221f; --del-ink: #f5a59c; --mark: #5b4e12; --now: #1f2a27;
  --s1: #78a9e8; --s2: #ee8d73; --s3: #73c995; --s4: #b39cf0; --s5: #e3b459; --s6: #ec88b4; --s7: #6cc8c9; --s8: #a3acb8;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text); font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
code, pre { font-family: var(--mono); font-size: 0.86em; }
code { background: var(--surface-2); padding: 0.1em 0.35em; border-radius: 5px; }
pre { background: var(--surface-2); padding: 12px 14px; border-radius: 10px; overflow-x: auto; white-space: pre; margin: 8px 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; height: 100dvh; }
.sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--surface); min-height: 0; }
.main { overflow-y: auto; min-width: 0; }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .app[data-view="list"] .main { display: none; }
  .app:not([data-view="list"]) .sidebar { display: none; }
  .sidebar { border-right: 0; }
}

.brand-bar { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px 18px; padding-top: max(14px, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; color: var(--text); letter-spacing: -0.01em; }
.brand.big { font-size: 22px; justify-content: center; margin-bottom: 4px; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: var(--accent) url("icon.svg") center / cover; display: inline-block; }
.brand-actions { display: flex; gap: 2px; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.search-wrap { position: relative; margin: 4px 14px 10px; }
.search-wrap svg { position: absolute; left: 11px; top: 50%; translate: 0 -50%; color: var(--faint); width: 18px; height: 18px; }
.search-wrap input { width: 100%; padding: 10px 12px 10px 36px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); outline: none; }
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.upload-progress { margin: 0 14px 10px; font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }

/* ---------- list ---------- */
.list { overflow-y: auto; flex: 1; padding: 0 8px 24px; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
.list-group { font-size: 12px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; padding: 14px 10px 6px; }
.item { display: block; padding: 10px 10px 11px; border-radius: 10px; color: var(--text); margin-bottom: 1px; }
.item:hover { background: var(--surface-2); }
.item.active { background: var(--accent-soft); }
.item-title { font-weight: 560; line-height: 1.3; display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.item-title span:first-child { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.item-meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.item-summary { font-size: 13px; color: var(--muted); margin-top: 4px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hit-snippet { font-size: 13.5px; margin-top: 4px; color: var(--text); }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.empty { color: var(--muted); padding: 28px 14px; text-align: center; font-size: 14px; }
.empty.big { padding: 18vh 24px; }
.empty h2 { color: var(--text); font-size: 18px; margin: 0 0 6px; font-weight: 600; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; border-radius: 999px; padding: 1px 8px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.queued, .badge.transcribing, .badge.summarizing { background: var(--warn-soft); color: var(--warn); }
.badge.error { background: var(--danger-soft); color: var(--danger); }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }
.icon-btn.busy { color: var(--accent); cursor: progress; }
.icon-btn.busy svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { rotate: 360deg; } }

/* ---------- detail ---------- */
.detail { max-width: 860px; margin: 0 auto; padding: 18px 28px 80px; padding-bottom: max(80px, env(safe-area-inset-bottom)); }
@media (max-width: 820px) { .detail { padding: 10px 16px 80px; padding-top: max(10px, env(safe-area-inset-top)); } }
.back { display: none; align-items: center; gap: 4px; color: var(--accent); font-weight: 500; padding: 6px 0; margin-bottom: 4px; }
@media (max-width: 820px) { .back { display: inline-flex; } }
.title-input { font-size: 26px; font-weight: 680; letter-spacing: -0.02em; line-height: 1.2; width: 100%; border: 0; background: transparent; padding: 4px 0; border-radius: 6px; outline: none; resize: none; field-sizing: content; }
.title-input:hover { background: var(--surface-2); }
.title-input:focus { background: var(--surface); box-shadow: 0 0 0 2px var(--accent-soft); }
@media (max-width: 820px) { .title-input { font-size: 22px; } }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; color: var(--muted); font-size: 13.5px; margin: 4px 0 14px; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; background: var(--surface-2); color: var(--muted); padding: 1px 8px; border-radius: 999px; }
.error-box { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 12px; margin: 0 0 14px; font-size: 14px; }
.info-box { background: var(--surface-2); color: var(--muted); border-radius: 10px; padding: 10px 12px; margin: 0 0 14px; font-size: 14px; }

.player { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0 10px; margin: 0 -2px; }
.player audio { width: 100%; height: 40px; display: block; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 6px 0 18px; overflow-x: auto; scrollbar-width: none; }
.tab { border: 0; background: none; padding: 9px 12px; color: var(--muted); font-weight: 550; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab .count { font-size: 11.5px; color: var(--faint); margin-left: 4px; font-weight: 500; }

.section { margin: 0 0 24px; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--faint); margin: 0 0 8px; font-weight: 650; }
.section p { margin: 0 0 8px; }
.section ul { margin: 0; padding-left: 20px; }
.section li { margin: 3px 0; }
.summary-text { font-size: 16px; line-height: 1.6; }
.actions-list { list-style: none; padding: 0 !important; }
.actions-list li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); margin: 6px 0; }
.actions-list .box { width: 16px; height: 16px; border: 1.6px solid var(--faint); border-radius: 4px; flex: none; margin-top: 3px; }
.actions-list .who { color: var(--muted); font-size: 13px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.speakers { display: grid; gap: 8px; }
.speaker-row { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.speaker-row input { border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 6px 9px; min-width: 0; width: 100%; }
.speaker-row input:focus { outline: none; border-color: var(--accent); }
.speaker-share { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.suggest { border: 1px dashed var(--accent); color: var(--accent); background: none; border-radius: 999px; font-size: 12px; padding: 1px 8px; cursor: pointer; margin-left: 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13.5px; }
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--s8)); }

/* transcript */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1; min-width: 140px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 10px; }
.toggle { display: inline-flex; gap: 6px; align-items: center; font-size: 13.5px; color: var(--muted); cursor: pointer; user-select: none; }
.seg { display: grid; grid-template-columns: 52px 1fr; gap: 4px 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; scroll-margin: 90px; }
.seg:hover { background: var(--surface-2); }
.seg.now { background: var(--now); box-shadow: inset 3px 0 0 var(--accent); }
.seg .ts { font-family: var(--mono); font-size: 12px; color: var(--faint); padding-top: 3px; font-variant-numeric: tabular-nums; }
.seg .who { grid-column: 2; font-size: 13px; }
.seg .txt { grid-column: 2; line-height: 1.55; }
.seg.cont .who { display: none; }
.seg.dim { opacity: 0.35; }

/* compare */
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.metric .v { font-size: 24px; font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.metric .l { font-size: 12.5px; color: var(--muted); }
.diff { line-height: 1.9; font-size: 15px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.diff ins, .diff del { text-decoration: none; border-radius: 4px; padding: 1px 3px; cursor: pointer; }
.diff ins { background: var(--ins); color: var(--ins-ink); }
.diff del { background: var(--del); color: var(--del-ink); text-decoration: line-through; text-decoration-thickness: 1px; }
.diff .gap { color: var(--faint); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin: 8px 0 10px; flex-wrap: wrap; }
.legend ins, .legend del { text-decoration: none; padding: 0 4px; border-radius: 4px; }
.legend ins { background: var(--ins); color: var(--ins-ink); }
.legend del { background: var(--del); color: var(--del-ink); }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--faint); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }

/* buttons + forms */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 9px; cursor: pointer; font-weight: 550; font-size: 14px; color: var(--text); }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
select { border: 1px solid var(--border); background: var(--surface); border-radius: 9px; padding: 6px 8px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); font-size: 14px; }
.copy-row { display: flex; gap: 8px; align-items: center; margin: 6px 0 12px; }
.copy-row pre { flex: 1; min-width: 0; margin: 0; }
td.nowrap { white-space: nowrap; }
.copy-row .btn { flex: none; padding: 5px 10px; font-size: 13px; }

/* login + toast */
.login { border: 0; border-radius: 16px; padding: 28px; width: min(400px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgb(0 0 0 / 0.25); }
.login::backdrop { background: var(--bg); }
.login form { display: grid; gap: 12px; text-align: center; }
.login p { margin: 0; color: var(--muted); font-size: 14px; }
.login input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); }
.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); translate: -50% 0; background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; z-index: 50; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgb(0 0 0 / 0.2); }

/* judging differences */
.diff .sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.diff .v-ours, .diff .v-reference, .diff .v-neither { opacity: 0.55; }
.diff .v-ours::after, .diff .v-reference::after, .diff .v-neither::after { font-size: 0.75em; margin-left: 2px; }
.diff ins.v-ours::after, .diff del.v-reference::after { content: " ✓"; }
.diff .v-neither::after { content: " ✗"; }
.judge { position: sticky; bottom: 0; margin-top: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; box-shadow: 0 -4px 20px rgb(0 0 0 / 0.08); display: grid; gap: 8px;
  padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.judge-words { display: flex; gap: 14px; flex-wrap: wrap; align-items: baseline; }
.judge ins, .judge del { text-decoration: none; border-radius: 4px; padding: 1px 4px; }
.judge ins { background: var(--ins); color: var(--ins-ink); }
.judge del { background: var(--del); color: var(--del-ink); }

/* ---------- note actions: copy, share, delete ---------- */
.detail-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.detail-top .back { margin-bottom: 0; }
.detail-actions { display: flex; gap: 2px; margin-left: auto; }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- swipe a row left to delete ---------- */
.swipe-row { position: relative; border-radius: 10px; margin-bottom: 1px; overflow: hidden; }
.swipe-row .item { position: relative; z-index: 1; margin-bottom: 0; background: var(--surface); touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-user-drag: none; transition: transform 0.22s ease; }
.swipe-row .item:hover { background: var(--surface-2); }
.swipe-row .item.active { background: var(--accent-soft); }
.swipe-row.dragging .item { transition: none; }
.swipe-actions { position: absolute; top: 0; right: 0; bottom: 0; display: flex; visibility: hidden; }
.swipe-row.dragging .swipe-actions, .swipe-row.open .swipe-actions { visibility: visible; }
.swipe-actions button { width: 80px; border: 0; color: var(--bg); font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; }
.swipe-rename { background: var(--muted); }
.swipe-delete { background: var(--danger); }

/* toast with an Undo button */
.toast { display: flex; align-items: center; gap: 16px; }
.toast-action { background: none; border: 0; padding: 0; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* rename box */
.rename::backdrop { background: rgb(0 0 0 / 0.4); }
.rename form { text-align: left; }
.rename h3 { margin: 0; font-size: 17px; }
.rename input { font-size: 16px; } /* 16px keeps iPhone from zooming in */
.rename .btn-row { justify-content: flex-end; }
.chip-btn { border: 0; background: none; padding: 0; color: inherit; font-family: inherit; line-height: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.chip-btn:hover { filter: brightness(0.95); text-decoration: underline; text-underline-offset: 2px; }
