/* PocketScribe — mobile-first clinical UI */
:root {
  --teal: #0f766e;
  --teal-dark: #115e59;
  --teal-soft: #e4f5f2;
  --bg: #f7f9f9;
  --card: #ffffff;
  --ink: #1a2b30;
  --muted: #617276;
  --line: #e2e9e8;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --ok: #15803d;
  --ok-soft: #e5f6ea;
  --warn: #b45309;
  --warn-soft: #fdf1d8;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(23, 39, 43, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--teal); }

.view { max-width: 720px; margin: 0 auto; padding: 16px 14px calc(76px + env(safe-area-inset-bottom)); }

.banner {
  position: sticky; top: 0; z-index: 40;
  background: var(--warn-soft); color: var(--warn);
  padding: 8px 14px; font-size: 13px; text-align: center;
  border-bottom: 1px solid #f3d9a4;
}

/* ---------- tab bar ---------- */
.tabbar[hidden] { display: none !important; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tabbar a {
  flex: 1; text-align: center; text-decoration: none; color: var(--muted);
  font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 0;
}
.tabbar a.active { color: var(--teal); font-weight: 600; }
.tabbar svg { width: 22px; height: 22px; }

/* ---------- generic ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card h2 { margin: 0 0 4px; font-size: 15px; }
.card h3 { margin: 18px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px;
  border: 1px solid var(--teal); background: var(--teal); color: #fff;
  font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none;
  width: 100%;
}
.btn svg { width: 20px; height: 20px; }
.btn.secondary { background: var(--card); color: var(--teal); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.small { width: auto; min-height: 36px; padding: 6px 12px; font-size: 13px; border-radius: 9px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; font-family: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--teal); outline-offset: -1px; }
textarea { resize: vertical; min-height: 74px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.ocr-hit { border-color: var(--teal); background: var(--teal-soft); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; }
.badge.draft { background: var(--warn-soft); color: var(--warn); }
.badge.signed { background: var(--ok-soft); color: var(--ok); }
.badge.ai { background: #e0e7ff; color: #4338ca; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 82dvh; display: flex; flex-direction: column; justify-content: center; }
.brand { text-align: center; margin-bottom: 22px; }
.brand .logo { width: 74px; height: 74px; border-radius: 18px; margin: 0 auto 10px; background: var(--teal); color: #fff; display: flex; align-items: center; justify-content: center; }
.brand .logo svg { width: 40px; height: 40px; }
.brand h1 { font-size: 24px; margin: 0; }
.brand p { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.tabs { display: flex; margin-bottom: 16px; background: #e6efee; border-radius: 12px; padding: 4px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.active { background: var(--card); color: var(--teal); box-shadow: var(--shadow); }

/* ---------- home ---------- */
.greet { margin: 4px 2px 14px; }
.greet h2 { margin: 0; font-size: 20px; }
.greet p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.bignew {
  display: flex; align-items: center; gap: 14px; width: 100%;
  background: var(--teal); color: #fff; border: 0; border-radius: var(--radius);
  padding: 18px; font-size: 17px; font-weight: 700; cursor: pointer;
}
.bignew svg { width: 28px; height: 28px; }
.bignew small { display: block; font-weight: 400; font-size: 12px; opacity: .85; }
.statrow { display: flex; gap: 10px; margin: 14px 0; }
.stat { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.stat b { display: block; font-size: 20px; color: var(--teal); }
.stat span { font-size: 11px; color: var(--muted); }

/* ---------- lists ---------- */
.noteitem { display: flex; align-items: center; gap: 12px; padding: 13px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.noteitem:last-child { border-bottom: 0; }
.noteitem .avatar { width: 40px; height: 40px; border-radius: 12px; background: var(--teal-soft); color: var(--teal-dark); font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0; }
.noteitem .mid { flex: 1; min-width: 0; }
.noteitem .t { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.noteitem .s { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.searchrow { display: flex; gap: 8px; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 5px 12px; font-size: 12px; cursor: pointer; color: var(--muted); }
.chip.active { background: var(--teal); border-color: var(--teal); color: #fff; }

/* ---------- wizard ---------- */
.steps { display: flex; gap: 6px; margin: 2px 0 14px; }
.stepchip {
  flex: 1; border: 1px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 99px; padding: 6px 4px; font-size: 11.5px; font-weight: 600; cursor: pointer; text-align: center;
}
.stepchip.on { background: var(--teal-soft); border-color: var(--teal-soft); color: var(--teal-dark); }
.stepchip.cur { background: var(--teal); border-color: var(--teal); color: #fff; }
.wizhead { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.wizhead h2 { margin: 0; font-size: 18px; flex: 1; }
.iconbtn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; display: inline-flex; }
.iconbtn svg { width: 22px; height: 22px; }

.scanbtn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px; border: 1.5px dashed var(--teal); border-radius: 12px; background: var(--teal-soft); color: var(--teal-dark); font-weight: 600; font-size: 14px; cursor: pointer; margin-bottom: 14px; }
.scanbtn svg { width: 22px; height: 22px; }
.scanbtn.busy { opacity: .6; pointer-events: none; }

/* camera sheet */
.sheet { position: fixed; inset: 0; z-index: 60; background: rgba(8, 20, 19, .92); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 18px; }
.sheet video { width: 100%; max-width: 560px; border-radius: 14px; background: #000; }
.sheet canvas { width: 100%; max-width: 560px; border-radius: 14px; }
.sheet .row { display: flex; gap: 10px; margin-top: 14px; width: 100%; max-width: 560px; }
.sheet p { color: #c8e5e1; font-size: 13px; text-align: center; margin: 10px 0 0; }

/* dictation */
.micstage { text-align: center; padding: 18px 0 8px; }
.micbtn { width: 108px; height: 108px; border-radius: 50%; border: 0; background: var(--teal); color: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: transform .12s ease; }
.micbtn svg { width: 46px; height: 46px; }
.micbtn.rec { background: var(--danger); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(185, 28, 28, .45); } 70% { box-shadow: 0 0 0 22px rgba(185, 28, 28, 0); } 100% { box-shadow: 0 0 0 0 rgba(185, 28, 28, 0); } }
.micstage .state { margin: 12px 0 2px; font-weight: 700; font-size: 15px; }
.micstage .hint { color: var(--muted); font-size: 12px; }
.rec-timer { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
#dict-interim { color: var(--teal-dark); font-style: italic; font-weight: 600; min-height: 44px; font-size: 15px; line-height: 1.4; margin: 10px 2px 0; padding: 8px 10px; background: var(--teal-soft); border-radius: 10px; }

/* coding */
.codebox { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.codelist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.codepill { display: inline-flex; align-items: center; gap: 6px; background: var(--teal-soft); color: var(--teal-dark); border-radius: 99px; padding: 4px 6px 4px 11px; font-size: 12px; font-weight: 600; }
.codepill.cpt { background: #ede9fe; color: #5b21b6; }
.codepill button { border: 0; background: rgba(0,0,0,.12); color: inherit; width: 17px; height: 17px; border-radius: 50%; cursor: pointer; font-size: 11px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.sugg { border: 0; background: #fff; border: 1px dashed var(--teal); color: var(--teal-dark); border-radius: 99px; padding: 4px 11px; font-size: 12px; cursor: pointer; }
.emresult { background: var(--teal-soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 8px; }
.emresult b { color: var(--teal-dark); }

/* note view */
.notehead { display: flex; align-items: flex-start; gap: 10px; }
.notehead h2 { margin: 0; font-size: 18px; flex: 1; }
.notesection { margin-bottom: 4px; }
.notesection h3 { border-bottom: 1px solid var(--line); padding-bottom: 3px; }
.notesection .body { white-space: pre-wrap; font-size: 14px; line-height: 1.55; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { width: auto; flex: 1 1 40%; min-height: 42px; font-size: 13px; padding: 8px 10px; }
details.transcript summary { cursor: pointer; font-weight: 600; color: var(--muted); font-size: 13px; }
details.transcript .body { white-space: pre-wrap; font-size: 13px; color: var(--muted); max-height: 300px; overflow: auto; }

/* signature */
.sigpad { border: 1.5px dashed var(--line); border-radius: 12px; background: #fff; touch-action: none; width: 100%; display: block; }
.sigline { font-family: "Brush Script MT", "Segoe Script", cursive; font-size: 30px; color: #102a2e; }
.attn { font-size: 12px; color: var(--muted); }

/* toast */
.toast {
  position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: #17272b; color: #fff; padding: 10px 18px; border-radius: 99px; font-size: 13px; z-index: 80;
  max-width: 86vw; text-align: center; box-shadow: var(--shadow);
}
.toast.err { background: var(--danger); }

/* audit table */
.audit { width: 100%; border-collapse: collapse; font-size: 12px; }
.audit th, .audit td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.audit th { color: var(--muted); font-weight: 600; }

/* treatment plan + verification */
.planprob { border-bottom: 1px solid var(--line); padding: 8px 0 4px; }
.planprob:last-of-type { border-bottom: 0; }
.planprob h3 { margin: 6px 0 4px; }
.planrows { display: flex; flex-direction: column; gap: 5px; }
.planrow { font-size: 13px; line-height: 1.45; padding-left: 6px; }
.planwarn { background: var(--warn-soft); color: var(--warn); border-radius: 9px; padding: 8px 10px; font-size: 12.5px; margin-top: 8px; }
.checkrow { display: flex; align-items: baseline; gap: 8px; font-size: 12.5px; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.checkrow:last-child { border-bottom: 0; }
.checkpass { color: var(--muted); }
.chipstatus { flex-shrink: 0; font-size: 10px; font-weight: 800; border-radius: 99px; padding: 2px 8px; letter-spacing: .4px; }
.chipstatus.ok { background: var(--ok-soft); color: var(--ok); }
.chipstatus.warn { background: var(--warn-soft); color: var(--warn); }
.chipstatus.fail { background: var(--danger-soft); color: var(--danger); }
.verline { border-radius: 10px; padding: 9px 12px; font-size: 12.5px; font-weight: 600; }
.verline.verok { background: var(--ok-soft); color: var(--ok); }
.verline.verwarn { background: var(--warn-soft); color: var(--warn); }
.verline.verbad { background: var(--danger-soft); color: var(--danger); }
.refrow { display: grid; grid-template-columns: 1.1fr 1fr .8fr auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.refrow input { padding: 8px 10px; font-size: 13px; }

/* live dictation feedback */
.recbadge { color: #ef4444; font-weight: 800; font-size: 12px; margin-left: 10px; letter-spacing: .5px; animation: recblink 1.3s infinite; }
@keyframes recblink { 50% { opacity: .3; } }
.wordcount, .engstatus { font-size: 12.5px; color: var(--muted); font-weight: 600; }
#micmeter { width: 160px; height: 26px; display: block; margin: 0 auto; }
.liverow { display: flex; gap: 9px; align-items: flex-start; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.liverow:last-child { border-bottom: 0; }
.liverow .livetext { flex: 1; font-size: 13px; line-height: 1.45; }
.liverow .livetext b { font-weight: 700; }
.liverow.sev-flag .livetext b { color: var(--danger); }
.liverow .iconbtn { flex-shrink: 0; color: var(--muted); font-size: 18px; }

.noscript { padding: 40px; text-align: center; font-size: 16px; }

/* ---------- print ---------- */
#printArea { display: none; }
@media print {
  body * { visibility: hidden; }
  #printArea, #printArea * { visibility: visible; }
  #printArea { display: block; position: absolute; inset: 0; background: #fff; padding: 28px 34px; }
  .view, .tabbar, .toast, .banner { display: none !important; }
}
