:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --ink: #142321;
  --ink-2: #4b5d5a;
  --ink-3: #7a8a87;
  --line: #d9e1df;
  --brand: #0f5c58;
  --brand-ink: #ffffff;
  --brand-soft: #e1efed;
  --rec: #c62f2f;
  --rec-soft: #fbe6e6;
  --warn: #8a5a00;
  --warn-soft: #fff4dc;
  --warn-line: #f0d48c;
  --ok: #1d7a3d;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20,35,33,.06), 0 4px 16px rgba(20,35,33,.05);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1514;
    --surface: #162120;
    --surface-2: #1d2a29;
    --ink: #e6efed;
    --ink-2: #a9bbb8;
    --ink-3: #7f918e;
    --line: #2a3a38;
    --brand: #4fb3a9;
    --brand-ink: #062320;
    --brand-soft: #18322f;
    --rec: #ef5b5b;
    --rec-soft: #3a1c1c;
    --warn: #f1c46b;
    --warn-soft: #2e2512;
    --warn-line: #5b4920;
    --ok: #5cc982;
    --danger: #ff7b6e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px 16px; text-align: center; color: var(--ink-3); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
.topbar .logo { white-space: nowrap; font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.topbar .logo svg { width: 22px; height: 22px; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 38vw; }
.nav { display: flex; gap: 4px; }
.nav button {
  background: transparent; border: 0; color: inherit; padding: 6px 10px; border-radius: 8px;
  font-size: 14px; cursor: pointer; opacity: .85;
}
.nav button[aria-current="page"], .nav button:hover { background: rgba(255,255,255,.16); opacity: 1; }

main { max-width: 860px; margin: 0 auto; padding: 16px; display: grid; gap: 14px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.card h2 { margin: 0 0 10px; font-size: 15px; font-weight: 650; color: var(--ink-2); text-transform: uppercase; letter-spacing: .5px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--ink-3); font-size: 13px; }
.small { font-size: 13px; }

/* ---------- privacy banner ---------- */
.privacy {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--brand-soft); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font-size: 13.5px; color: var(--ink-2);
}
.privacy b { color: var(--ink); }

/* ---------- segmented control ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; border: 1px solid var(--line); }
.seg button {
  border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--ink-2);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

/* ---------- inputs & buttons ---------- */
input[type=text], input[type=password], select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
textarea { resize: vertical; min-height: 64px; line-height: 1.45; }
label.field { display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 550; font-size: 14.5px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.big { padding: 13px 18px; font-size: 16px; width: 100%; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn svg { width: 16px; height: 16px; }

/* ---------- recorder ---------- */
.recorder { display: grid; justify-items: center; gap: 10px; padding: 8px 0 4px; }
.recbtn {
  width: 112px; height: 112px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--rec); color: #fff; display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(198,47,47,.35); transition: transform .12s ease;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.recbtn:active { transform: scale(.96); }
.recbtn svg { width: 42px; height: 42px; }
.recbtn.recording { animation: pulse 1.6s ease-in-out infinite; }
.recbtn.recording .ic-mic { display: none; }
.recbtn:not(.recording) .ic-stop { display: none; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(198,47,47,.45); } 50% { box-shadow: 0 0 0 16px rgba(198,47,47,0); } }
@media (prefers-reduced-motion: reduce) { .recbtn.recording { animation: none; outline: 4px solid var(--rec-soft); } }
.rec-status { font-size: 14px; color: var(--ink-2); min-height: 21px; text-align: center; }
.rec-status.warning { color: var(--warn); font-weight: 600; }
.rec-timer { font: 600 22px var(--mono); font-variant-numeric: tabular-nums; }
.meter { width: 180px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.meter > i { display: block; height: 100%; width: 0; background: var(--rec); transition: width .08s linear; }
.queue { width: 100%; display: grid; gap: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.qitem { display: flex; gap: 8px; align-items: center; font-size: 13px; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); }
.qitem:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.qitem.err { background: var(--rec-soft); color: var(--danger); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- alerts ---------- */
.alert { border-radius: 10px; padding: 10px 12px; font-size: 13.5px; border: 1px solid var(--warn-line); background: var(--warn-soft); color: var(--warn); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.alert.err { border-color: var(--danger); background: var(--rec-soft); color: var(--danger); }

/* ---------- result ---------- */
.draft-badge { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .6px; padding: 2px 8px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-line); }
.section { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.section-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.section-head h3 { margin: 0; font-size: 16px; flex: 1; }
.section-head h3 .letter { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--brand); color: var(--brand-ink); font-size: 14px; margin-right: 8px; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; margin-bottom: 8px; }
.item label { grid-column: 1 / -1; font-size: 12.5px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.item textarea { min-height: 42px; padding: 8px 10px; font-size: 15px; }
.item .btn { align-self: start; }
.empty-items { font-size: 13px; color: var(--ink-3); margin: 0 0 6px; }
details.more summary { cursor: pointer; font-size: 13px; color: var(--ink-3); margin-bottom: 8px; }

.ttv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-bottom: 10px; }
.ttv-cell { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--surface-2); }
.ttv-cell .k { font-size: 11.5px; color: var(--ink-3); font-weight: 650; text-transform: uppercase; }
.ttv-cell .v { font: 600 17px var(--mono); font-variant-numeric: tabular-nums; }
.ttv-cell.abn { border-color: var(--warn-line); background: var(--warn-soft); }
.ttv-cell.abn .v { color: var(--warn); }
.ttv-cell.bad { border-color: var(--danger); background: var(--rec-soft); }
.ttv-cell.bad .v { color: var(--danger); }
.ttv-cell .flag { font-size: 11px; color: inherit; }

/* ---------- list ---------- */
.list { display: grid; gap: 8px; }
.li { display: flex; gap: 10px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; }
.li:hover { background: var(--surface-2); }
.li .title { font-weight: 600; }
.pill { font-size: 11.5px; padding: 2px 8px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); font-weight: 600; white-space: nowrap; }
@media (prefers-color-scheme: dark) { .pill { color: var(--brand); } }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--ink-3); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.table-wrap { overflow-x: auto; }
.audit-detail { font-family: var(--mono); font-size: 12px; color: var(--ink-3); word-break: break-all; }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth { width: 100%; max-width: 380px; display: grid; gap: 12px; }
.auth .brand { display: flex; gap: 10px; align-items: center; font-size: 20px; font-weight: 700; color: var(--brand); }
.auth .brand svg { width: 34px; height: 34px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 50; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.sticky-actions { position: sticky; bottom: 0; padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }

@media (max-width: 560px) {
  main { padding: 12px; gap: 12px; }
  .card { padding: 14px; }
  .topbar .who { display: none; }
  .nav button { padding: 6px 8px; font-size: 13px; }
}
main > * { min-width: 0; }
.section-head h3 .letter { width: auto; min-width: 26px; padding: 0 6px; }
.ttv-cell input.v { border: 0; background: transparent; padding: 0; width: 100%; font: 600 17px var(--mono); color: inherit; }
.ttv-cell .unit { font-weight: 500; text-transform: none; opacity: .8; }
.preview-text { white-space: pre-wrap; font: 12.5px/1.45 var(--mono); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; overflow-x: auto; }
details.preview { margin-top: 4px; }
