:root {
  --ink: #14213d;
  --ink-2: #44506a;
  --muted: #6b7489;
  --line: #e3e7ee;
  --bg: #f5f7fa;
  --card: #ffffff;
  --brand: #0f766e;
  --brand-2: #115e59;
  --brand-soft: #e6f4f2;
  --danger: #b42318;
  --warn-bg: #fff7e6;
  --warn-line: #f5c26b;
  --ok: #067647;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 33, 61, .06), 0 4px 16px rgba(20, 33, 61, .05);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; font-size: 15px; line-height: 1.5; }
h1 { font-size: 1.6rem; margin: 0 0 .15rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0; }
a { color: var(--brand-2); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9em; }
.muted, .sub { color: var(--muted); }
.sub { font-size: .85rem; }
.fineprint { color: var(--muted); font-size: .78rem; margin: .75rem 0 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.banner { background: #fff1d6; color: #7a4b00; text-align: center; font-size: .82rem; font-weight: 600; padding: .4rem 1rem; border-bottom: 1px solid var(--warn-line); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: .75rem 1.5rem; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; color: var(--ink); text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, var(--brand), #14b8a6); position: relative; display: inline-block; }
.brand-mark::after { content: ""; position: absolute; inset: 6px 9px; background: #fff; border-radius: 3px; }
.brand-mark.lg { width: 34px; height: 34px; }
.brand-mark.lg::after { inset: 9px 14px; }
.topnav { display: flex; align-items: center; gap: 1rem; }
.who { color: var(--ink-2); font-size: .9rem; }

.view { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 1rem; }
.back { display: inline-block; margin-bottom: .75rem; text-decoration: none; font-size: .9rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: .75rem; margin-bottom: .9rem; flex-wrap: wrap; }
.card-head h2 { margin-right: auto; }
.grid-2 { display: grid; grid-template-columns: 1.1fr 1fr; gap: 1rem; }
.review { display: grid; grid-template-columns: 1fr 1.15fr; gap: 1rem; align-items: start; }
.span-2 { grid-column: 1 / -1; }
@media (max-width: 900px) { .grid-2, .review { grid-template-columns: 1fr; } }

.btn { font: inherit; font-weight: 600; border-radius: 9px; border: 1px solid transparent; padding: .55rem 1rem; cursor: pointer; display: inline-flex; align-items: center; gap: .5rem; transition: background .15s, box-shadow .15s; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn:focus-visible, .row-link:focus-visible, textarea:focus-visible, input:focus-visible { outline: 3px solid #99d5cf; outline-offset: 2px; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; margin-top: 1rem; }
.link { color: var(--brand-2); text-decoration: underline; cursor: pointer; font-size: .9rem; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
.table td { padding: .8rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.row-link { cursor: pointer; }
.row-link:hover { background: var(--brand-soft); }
.table-dense td { padding: .5rem 1rem; font-size: .88rem; }

.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: .15rem .55rem; border-radius: 999px; }
.badge-draft { background: #fff1d6; color: #7a4b00; }
.badge-approved { background: #dcfae6; color: var(--ok); }
.badge-muted { background: #eef1f5; color: var(--muted); }

.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: min(400px, 100%); display: flex; flex-direction: column; padding: 2rem; }
.login-brand { display: flex; align-items: center; gap: .75rem; margin-bottom: .25rem; }
.login-brand h1 { font-size: 1.3rem; margin: 0; }
label { font-size: .85rem; font-weight: 600; margin: .9rem 0 .3rem; }
input[type=email], input[type=password] { font: inherit; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 9px; }
.form-error { color: var(--danger); min-height: 1.2em; margin: .5rem 0 0; font-size: .88rem; }

.patient-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1rem; }
.reason { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .9rem; display: flex; flex-direction: column; }
.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: 0; }

.recorder { display: flex; flex-direction: column; align-items: center; text-align: center; gap: .6rem; }
.recorder h2 { align-self: flex-start; }
.rec-time { font-size: 2.6rem; font-weight: 600; letter-spacing: .02em; margin-top: .5rem; }
.meter { width: 70%; height: 8px; background: #eef1f5; border-radius: 99px; overflow: hidden; }
.meter-fill { height: 100%; width: 0; background: linear-gradient(90deg, #14b8a6, var(--brand)); transition: width .08s; }
.rec-status { min-height: 2.6em; max-width: 34ch; margin: .2rem 0; }
.rec-status.err { color: var(--danger); }
.rec-actions { display: flex; gap: .75rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #fff; }
.recording { border-color: #f4a9a3; box-shadow: 0 0 0 4px rgba(180, 35, 24, .08), var(--shadow); }
.recording .rec-time { color: var(--danger); }
.busy .rec-status::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: .5rem; border: 2px solid var(--brand); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

.transcript { max-height: 64vh; overflow: auto; display: flex; flex-direction: column; gap: .6rem; padding-right: .25rem; }
.turn { border-left: 3px solid var(--line); padding: .15rem 0 .15rem .75rem; }
.turn p { margin: .15rem 0 0; }
.turn-meta { display: flex; gap: .5rem; align-items: center; }
.who-chip { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: .1rem .45rem; border-radius: 5px; background: #eef1f5; color: var(--ink-2); }
.turn-clinician { border-left-color: var(--brand); }
.turn-clinician .who-chip { background: var(--brand-soft); color: var(--brand-2); }
.turn-patient { border-left-color: #8b9bb4; }

.flags { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 10px; padding: .7rem .9rem; margin-bottom: .9rem; font-size: .9rem; }
.flags ul { margin: .35rem 0 0; padding-left: 1.1rem; }
textarea.note { width: 100%; min-height: 46vh; font: .92rem/1.55 ui-monospace, "SF Mono", Menlo, Consolas, monospace; padding: .9rem; border: 1px solid var(--line); border-radius: 10px; resize: vertical; color: var(--ink); background: #fff; }
textarea.note[readonly] { background: #fafbfc; }
textarea.letter { min-height: 34vh; font-family: inherit; font-size: .95rem; }
.actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: .9rem; flex-wrap: wrap; }

.act { font-size: .78rem; font-weight: 600; padding: .1rem .45rem; border-radius: 5px; background: #eef1f5; }
.act-approve, .act-record { background: #dcfae6; color: var(--ok); }
.act-login { background: var(--brand-soft); color: var(--brand-2); }
.act-pipeline { background: #fee4e2; color: var(--danger); }
.act-export { background: #ece8ff; color: #4a3aa8; }

.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: .65rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); font-size: .9rem; z-index: 20; }
.toast-err { background: var(--danger); }

.print-area { display: none; }
@media print {
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block; font: 11pt/1.5 Georgia, serif; color: #000; }
  .print-area h1 { font-size: 14pt; }
  .print-area pre { white-space: pre-wrap; font: inherit; }
}
