/* Vayosmitham — field-first clinical UI.
   Type: Atkinson Hyperlegible (designed for low vision readers) + Manjari for Malayalam.
   One bold element: the full-screen "Show to patient" card. Everything else stays quiet. */
:root {
  --ink: #18272b;
  --ink-2: #4b5d61;
  --ink-3: #75878b;
  --paper: #f3f6f5;
  --surface: #ffffff;
  --line: #d6e0de;
  --line-2: #e7eeec;
  --green: #0c5f56;          /* areca-leaf green: primary actions */
  --green-2: #0a4d46;
  --green-tint: #e2f0ed;
  --gold: #e5a21b;           /* marigold: highlights, the smile */
  --gold-tint: #fdf2d8;
  --red: #b8322a;            /* urgent only */
  --red-tint: #fbe7e5;
  --amber: #9a5b00;
  --amber-tint: #fff1d6;
  --blue: #2b5c8a;
  --blue-tint: #e5eef7;
  --radius-s: 6px;
  --radius-m: 10px;
  --radius-l: 18px;
  --tap: 52px;
  --font: 'Atkinson Hyperlegible', 'Manjari', 'Noto Sans Malayalam', system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 17px; line-height: 1.5; color: var(--ink); background: var(--paper); }
:lang(ml), .ml { font-family: 'Manjari', 'Noto Sans Malayalam', var(--font); line-height: 1.65; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0 0 .75em; }
a { color: var(--green); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--ink-2); }
.small { font-size: .88rem; }
.tiny { font-size: .78rem; color: var(--ink-3); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- app frame ---------- */
.top { position: sticky; top: 0; z-index: 20; background: var(--green); color: #fff; }
.top-in { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.brand svg { width: 30px; height: 30px; }
.top .who { margin-left: auto; font-size: .85rem; opacity: .9; text-align: right; line-height: 1.25; }
.top button.icon { background: transparent; border: 0; color: #fff; padding: 8px; border-radius: 8px; cursor: pointer; }
.offline-bar { background: var(--amber-tint); color: var(--amber); text-align: center; font-size: .88rem; padding: 6px 12px; }
.demo-bar { background: var(--gold-tint); color: #6b4a00; text-align: center; font-size: .8rem; padding: 4px 12px; }
main { max-width: 1200px; margin: 0 auto; padding: 16px 16px 96px; }
.narrow { max-width: 640px; margin: 0 auto; }

.side-layout { display: grid; grid-template-columns: 220px 1fr; gap: 24px; }
.side-nav { position: sticky; top: 72px; align-self: start; display: flex; flex-direction: column; gap: 2px; }
.side-nav a { padding: 10px 12px; border-radius: var(--radius-s); text-decoration: none; color: var(--ink); }
.side-nav a.on { background: var(--green-tint); color: var(--green-2); font-weight: 700; }
@media (max-width: 860px) { .side-layout { grid-template-columns: 1fr; } .side-nav { position: static; flex-direction: row; overflow-x: auto; } .side-nav a { white-space: nowrap; } }

.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
.bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; text-decoration: none; color: var(--ink-2); font-size: .78rem; border-radius: 8px; position: relative; }
.bottom-nav a svg { width: 24px; height: 24px; }
.bottom-nav a.on { color: var(--green); font-weight: 700; }
.bottom-nav .dot { position: absolute; top: 2px; right: calc(50% - 20px); background: var(--red); color: #fff; font-size: .7rem; border-radius: 999px; min-width: 18px; padding: 0 5px; line-height: 18px; text-align: center; }

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px; }
.panel + .panel { margin-top: 16px; }
.panel h2:first-child, .panel h3:first-child { margin-top: 0; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 24px 0 8px; }
.section-title h2 { margin: 0; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line-2); }
.list a.item, .list .item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; text-decoration: none; color: inherit; min-height: var(--tap); }
.list a.item:hover { background: var(--paper); }
.item .title { font-weight: 700; }
.empty { padding: 20px 16px; color: var(--ink-2); text-align: center; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--ink); font-weight: 700; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-2); }
.btn.danger { color: var(--red); border-color: #e7b8b3; }
.btn.big { min-height: var(--tap); font-size: 1.05rem; width: 100%; }
.btn.link { border: 0; background: none; color: var(--green); padding: 6px 4px; min-height: 0; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 20px; height: 20px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

label.field { display: block; }
label.field > span.lbl, .lbl { display: block; font-weight: 700; margin-bottom: 4px; }
.hint { display: block; font-size: .85rem; color: var(--ink-2); margin-top: 2px; }
input[type=text], input[type=tel], input[type=number], input[type=date], input[type=password], input[type=url], input[type=email], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; }
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green); outline: 2px solid var(--green-tint); }
.pin-input { letter-spacing: .5em; font-size: 1.4rem; text-align: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 560px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; min-height: 48px; border: 1px solid var(--line); border-radius: var(--radius-s);
  background: #fff; cursor: pointer; user-select: none; }
.choice input { width: 20px; height: 20px; accent-color: var(--green); margin: 0; }
.choice.on { border-color: var(--green); background: var(--green-tint); font-weight: 700; }
.choice.block { display: flex; width: 100%; align-items: flex-start; }
.choice.block .t { display: block; font-weight: 700; }
.choice.block .d { display: block; font-weight: 400; color: var(--ink-2); font-size: .92rem; }

/* OHAT 0/1/2 picker */
.scale { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 640px) { .scale { grid-template-columns: 1fr; } }
.scale button { text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff; cursor: pointer; min-height: var(--tap); }
.scale button .n { display: inline-block; width: 26px; height: 26px; border-radius: 50%; text-align: center; line-height: 26px; font-weight: 700; margin-right: 8px; background: var(--line-2); }
.scale button.on { border-width: 2px; }
.scale button.l0.on { border-color: var(--green); background: var(--green-tint); }
.scale button.l1.on { border-color: var(--amber); background: var(--amber-tint); }
.scale button.l2.on { border-color: var(--red); background: var(--red-tint); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 46px; height: 28px; background: var(--line); border-radius: 999px; position: relative; cursor: pointer; transition: background .15s; margin: 0; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--green); }
.switch input:checked::after { left: 21px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.chip.urgent { background: var(--red); color: #fff; }
.chip.routine { background: var(--green-tint); color: var(--green-2); }
.chip.warn { background: var(--amber-tint); color: var(--amber); }
.chip.info { background: var(--blue-tint); color: var(--blue); }
.chip.gold { background: var(--gold-tint); color: #6b4a00; }

.callout { border-radius: var(--radius-m); padding: 14px 16px; border: 1px solid; }
.callout.urgent { background: var(--red-tint); border-color: #eab4ae; }
.callout.urgent h3 { color: var(--red); }
.callout.warn { background: var(--amber-tint); border-color: #f0d49c; }
.callout.info { background: var(--blue-tint); border-color: #c4d6ea; }
.callout.ok { background: var(--green-tint); border-color: #b8dad3; }

/* ---------- wizard ---------- */
.steps { display: flex; gap: 4px; margin: 4px 0 16px; }
.steps span { flex: 1; height: 6px; border-radius: 3px; background: var(--line); }
.steps span.done { background: var(--green); }
.steps span.cur { background: var(--gold); }
.wizard-foot { position: sticky; bottom: 64px; background: linear-gradient(transparent, var(--paper) 30%); padding: 16px 0 8px; display: flex; gap: 10px; }
.wizard-foot .btn { flex: 1; }

/* ---------- translation pair ---------- */
.tx-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tx-pair.single { grid-template-columns: 1fr; }
@media (max-width: 720px) { .tx-pair { grid-template-columns: 1fr; } }
.tx-box { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 12px; background: #fff; white-space: pre-wrap; }
.tx-box.machine { background: var(--blue-tint); border-color: #c4d6ea; }
.tx-box .tx-label { display: block; font-size: .75rem; font-weight: 700; color: var(--ink-3); margin-bottom: 4px; white-space: normal; }
.tx-box.machine .tx-label { color: var(--blue); }

/* ---------- photos ---------- */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photo-slot { border: 2px dashed var(--line); border-radius: var(--radius-m); background: #fff; min-height: 150px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 8px; gap: 6px; cursor: pointer; position: relative; overflow: hidden; }
.photo-slot.has { border-style: solid; padding: 0; }
.photo-slot img { width: 100%; height: 150px; object-fit: cover; display: block; }
.photo-slot .cap { font-size: .8rem; padding: 4px 6px; }
.photo-slot .bad { position: absolute; top: 6px; left: 6px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.thumbs button { padding: 0; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; background: #000; cursor: zoom-in; }
.thumbs img { width: 100%; height: 110px; object-fit: cover; display: block; }
.thumbs .cap { display: block; background: #fff; font-size: .75rem; padding: 2px 6px; text-align: left; }
.lightbox { position: fixed; inset: 0; background: rgba(5,15,15,.92); z-index: 100; display: flex; flex-direction: column; }
.lightbox img { flex: 1; min-height: 0; object-fit: contain; width: 100%; }
.lightbox .bar { display: flex; justify-content: space-between; align-items: center; color: #fff; padding: 10px 16px; }
.lightbox .bar button { background: rgba(255,255,255,.15); color: #fff; border: 0; padding: 10px 16px; border-radius: 8px; cursor: pointer; font-weight: 700; }

/* ---------- dentist workspace ---------- */
.workspace { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.workspace .opinion-col { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; }
@media (max-width: 980px) { .workspace { grid-template-columns: 1fr; } .workspace .opinion-col { position: static; max-height: none; } }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 700; }
table.t { width: 100%; border-collapse: collapse; background: #fff; }
table.t th, table.t td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.t th { font-size: .85rem; color: var(--ink-2); font-weight: 700; background: var(--paper); }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-m); }
.score-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.s0 { background: var(--green); } .s1 { background: var(--gold); } .s2 { background: var(--red); }
.timer { font-variant-numeric: tabular-nums; }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 14px 16px; }
.kpi .v { font-size: 1.9rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--ink-2); font-size: .9rem; }
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(110px, 180px) 1fr 56px; gap: 10px; align-items: center; font-size: .92rem; }
.bar-track { height: 14px; background: var(--line-2); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--green); }
.bar-fill.red { background: var(--red); } .bar-fill.gold { background: var(--gold); }
.cols-2 > .panel + .panel, .grid-2 > .panel + .panel { margin-top: 0; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .cols-2 { grid-template-columns: 1fr; } }

/* ---------- show to patient (the one bold moment) ---------- */
.patient-view { position: fixed; inset: 0; z-index: 90; background: #fffdf6; overflow: auto; }
.patient-view .pv-in { max-width: 760px; margin: 0 auto; padding: 24px 20px 120px; }
.patient-view .pv-smile { display: block; width: 92px; height: 46px; margin: 8px 0 12px; }
.patient-view h1 { font-size: 2rem; color: var(--green-2); }
.patient-view .pv-text { font-size: 1.45rem; line-height: 1.7; }
.patient-view .pv-text p { margin-bottom: 1em; }
.patient-view .pv-block { border-left: 6px solid var(--gold); padding: 4px 0 4px 18px; margin: 20px 0; }
.patient-view .pv-block h2 { font-size: 1.15rem; color: var(--ink-2); margin-bottom: 6px; }
.patient-view .pv-close { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); }
.patient-view .pv-refer { background: var(--green); color: #fff; border-radius: var(--radius-l); padding: 18px 20px; font-size: 1.25rem; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--green); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: var(--radius-l); padding: 28px 24px; }
.login-mark { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-mark svg { width: 56px; height: 56px; }
.login-mark .name { font-size: 1.5rem; font-weight: 700; color: var(--green-2); line-height: 1.1; }
.login-mark .sub { font-size: .85rem; color: var(--ink-2); }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--radius-m);
  z-index: 200; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.25); }
.toast.err { background: var(--red); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; margin: 32px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.video-frame { position: relative; padding-top: 56.25%; background: #000; border-radius: var(--radius-m); overflow: hidden; }
.video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* ---------- printable report (A4) ---------- */
.report-page { background: #fff; max-width: 210mm; margin: 0 auto; padding: 14mm 14mm; border: 1px solid var(--line); font-size: 11pt; line-height: 1.45; }
.report-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--green); padding-bottom: 8px; margin-bottom: 12px; }
.report-head .org { font-weight: 700; color: var(--green-2); font-size: 14pt; }
.report-page h2 { font-size: 12pt; color: var(--green-2); margin: 14px 0 4px; }
.report-page .kv { font-size: 10.5pt; }
.report-page .box { border: 1px solid var(--line); padding: 8px 10px; border-radius: 4px; white-space: pre-wrap; }
.report-page .qr { width: 96px; height: 96px; }
.report-foot { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 8px; font-size: 9pt; color: var(--ink-2); }
.no-print {}
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .top, .bottom-nav, .no-print, .offline-bar, .demo-bar { display: none !important; }
  main { padding: 0; max-width: none; }
  .report-page { border: 0; max-width: none; }
}

.notice { font-size: 1rem; max-height: 60vh; overflow: auto; }
.notice h3 { margin: 14px 0 4px; color: var(--green-2); }
.notice h3:first-child { margin-top: 0; }
.notice p { margin: 0 0 4px; }

/* language picker on the sign-in page */
.lang-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.lang-pick button { flex: 1 1 auto; min-height: 40px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer; font-size: .95rem; }
.lang-pick button.on { background: var(--green); border-color: var(--green); color: #fff; font-weight: 700; }
