/* SwasthSetu - single stylesheet. Light, clinical, prints to A4. */
:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --ink: #17202c;
  --ink-2: #3c4757;
  --muted: #667085;
  --line: #e2e7ef;
  --line-2: #cfd6e1;
  --navy: #1f3b73;
  --navy-2: #2c4f94;
  --navy-soft: #eef2fa;
  --saffron: #ff9933;
  --green: #138808;
  --crit: #b42318; --crit-bg: #fef3f2; --crit-line: #fecdca;
  --warn: #b54708; --warn-bg: #fffaeb; --warn-line: #fedf89;
  --info: #175cd3; --info-bg: #eff8ff; --info-line: #b2ddff;
  --ok: #067647; --ok-bg: #ecfdf3; --ok-line: #abefc6;
  --ai: #5b3fc4; --ai-bg: #f6f3ff; --ai-line: #d9d0fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 var(--font); color: var(--ink); background: var(--bg);
  min-height: 100vh; display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
main { flex: 1; width: 100%; max-width: 1440px; margin: 0 auto; padding: 16px 20px 32px; outline: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
p { margin: 0; }
a { color: var(--navy-2); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--navy-2); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--navy); color: #fff; padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* ---------- chrome ---------- */
.tricolor { display: flex; height: 4px; }
.tricolor i { flex: 1; }
.tricolor i:nth-child(1) { background: var(--saffron); }
.tricolor i:nth-child(2) { background: #fff; }
.tricolor i:nth-child(3) { background: var(--green); }

.topbar { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-in { max-width: 1440px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex-shrink: 0; }
.brand img { width: 32px; height: 32px; }
.brand b { font-size: 16px; display: block; letter-spacing: -.01em; }
.brand small { display: block; font-size: 11px; color: var(--muted); margin-top: -2px; }
.nav { display: flex; gap: 2px; }
.nav a { padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--ink-2); font-weight: 550; font-size: 13px; }
.nav a:hover { background: var(--panel-2); }
.nav a.active { background: var(--navy-soft); color: var(--navy); }
.topsearch { flex: 1; max-width: 460px; position: relative; }
.topsearch input { width: 100%; padding: 8px 12px 8px 34px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel-2); }
.topsearch input:focus { background: #fff; }
.topsearch svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.userchip { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.userchip .who { text-align: right; line-height: 1.2; }
.userchip .who small { display: block; color: var(--muted); font-size: 11px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--navy-soft); color: var(--navy); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.aimode { font-size: 11px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--ai-line); background: var(--ai-bg); color: var(--ai); font-weight: 600; white-space: nowrap; }

.footer { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 20px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); background: var(--panel); }

/* ---------- primitives ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 8px; padding: 12px 14px 0; }
.card-h h2 { flex: 1; }
.card-b { padding: 10px 14px 14px; }
.card + .card { margin-top: 12px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line-2); background: #fff; cursor: pointer; font-weight: 550; font-size: 13px; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn-danger:hover { background: #912018; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 16px; padding: 4px 8px; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; border: 1px solid var(--line); background: var(--panel-2); color: var(--ink-2); white-space: nowrap; }
.chip.crit { background: var(--crit-bg); border-color: var(--crit-line); color: var(--crit); }
.chip.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.chip.info { background: var(--info-bg); border-color: var(--info-line); color: var(--info); }
.chip.ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.chip.ai { background: var(--ai-bg); border-color: var(--ai-line); color: var(--ai); }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 3px 10px; font-size: 12px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--navy); color: #fff; }

label.field { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); }
label.field > input, label.field > select, label.field > textarea, .input {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: 8px; background: #fff; font-weight: 400; font-size: 14px;
}
textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.banner { padding: 10px 14px; border-radius: var(--radius); border: 1px solid; display: flex; gap: 10px; align-items: flex-start; }
.banner.crit { background: var(--crit-bg); border-color: var(--crit-line); color: var(--crit); }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-line); color: #7a2e0e; }
.banner.info { background: var(--info-bg); border-color: var(--info-line); color: #194185; }
.banner.ok { background: var(--ok-bg); border-color: var(--ok-line); color: #085d3a; }
.banner b { font-weight: 700; }

table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-weight: 600; font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
table.t td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tr:last-child td { border-bottom: 0; }
.empty-state { padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }

.skeleton { background: linear-gradient(90deg, #eef1f5 25%, #f6f8fa 50%, #eef1f5 75%); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 6px; height: 12px; margin: 8px 0; }
@keyframes sk { to { background-position: -200% 0; } }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 90vw; }
.toast.err { background: var(--crit); }

/* ---------- drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.drawer::before { content: ""; position: absolute; inset: 0; background: rgba(16, 24, 40, .35); opacity: 0; transition: opacity .15s; }
.drawer-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(560px, 100vw); background: var(--panel); box-shadow: -8px 0 24px rgba(16,24,40,.12); transform: translateX(100%); transition: transform .18s ease-out; display: flex; flex-direction: column; }
.drawer.open { pointer-events: auto; }
.drawer.open::before { opacity: 1; }
.drawer.open .drawer-panel { transform: none; }
.drawer-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { flex: 1; }
.drawer-body { padding: 16px; overflow: auto; flex: 1; }

/* ---------- login ---------- */
.login-wrap { display: grid; grid-template-columns: 1.1fr 1fr; gap: 28px; max-width: 1080px; margin: 24px auto; align-items: start; }
.hero h1 { font-size: 30px; letter-spacing: -.02em; margin: 6px 0 10px; }
.hero h1 em { font-style: normal; color: var(--navy-2); }
.hero .lede { color: var(--ink-2); font-size: 15px; max-width: 520px; }
.points { list-style: none; padding: 0; margin: 20px 0 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.points li { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.points b { display: block; font-size: 13px; }
.points small { color: var(--muted); font-size: 12px; }
.acct { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px 12px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; }
.acct:hover { border-color: var(--navy-2); background: var(--navy-soft); }
.acct + .acct { margin-top: 6px; }
.acct .meta { flex: 1; line-height: 1.3; }
.acct .meta small { display: block; color: var(--muted); font-size: 12px; }
.role-tag { font-size: 10.5px; text-transform: uppercase; font-weight: 700; letter-spacing: .05em; color: var(--navy); background: var(--navy-soft); padding: 2px 6px; border-radius: 4px; }

/* ---------- home ---------- */
.home-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.bigsearch { display: flex; gap: 8px; }
.bigsearch input { flex: 1; padding: 11px 14px; font-size: 15px; border: 1px solid var(--line-2); border-radius: 10px; }
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { border-top: 1px solid var(--line); }
.plist li:first-child { border-top: 0; }
.prow { display: flex; align-items: center; gap: 12px; padding: 10px 4px; text-decoration: none; color: inherit; cursor: pointer; width: 100%; border: 0; background: none; text-align: left; }
.prow:hover { background: var(--panel-2); }
.prow .meta { flex: 1; min-width: 0; }
.prow .meta b { display: block; }
.prow .meta small { color: var(--muted); font-size: 12px; }
.scenario { display: block; padding: 12px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; color: inherit; background: var(--panel); }
.scenario:hover { border-color: var(--navy-2); }
.scenario + .scenario { margin-top: 8px; }
.scenario b { display: block; font-size: 13px; }
.scenario small { color: var(--muted); font-size: 12px; }
.scenario .num { float: left; width: 22px; height: 22px; border-radius: 50%; background: var(--navy); color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; margin-right: 10px; }

/* ---------- patient: one-screen summary ---------- */
.phead { display: flex; gap: 16px; align-items: flex-start; padding: 14px 16px; }
.phead .avatar { width: 46px; height: 46px; font-size: 16px; }
.phead .who { flex: 1; min-width: 0; }
.phead h1 { font-size: 20px; }
.phead .facts { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 4px; font-size: 12.5px; color: var(--ink-2); }
.phead .facts span b { font-weight: 600; color: var(--muted); font-weight: 500; margin-right: 3px; }
.phead .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.alertbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 16px; border-top: 1px solid var(--line); background: var(--panel-2); border-radius: 0 0 var(--radius) var(--radius); font-size: 13px; }
.alertbar .allergy { color: var(--crit); font-weight: 700; }
.alertbar .allergy.none { color: var(--muted); font-weight: 500; }
.emergency-strip { background: var(--crit); color: #fff; padding: 8px 16px; font-weight: 600; font-size: 13px; display: flex; gap: 12px; align-items: center; border-radius: var(--radius) var(--radius) 0 0; }

.sgrid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) minmax(0, .95fr); gap: 12px; margin-top: 12px; align-items: start; }
.sgrid > .col > .card + .card { margin-top: 12px; }

.ai-card { border-color: var(--ai-line); }
.ai-card .card-h h2::before { content: "✦ "; color: var(--ai); }
.ai-list { list-style: none; margin: 0; padding: 0; }
.ai-list li { padding: 6px 0 6px 14px; position: relative; border-bottom: 1px dashed var(--line); }
.ai-list li:last-child { border-bottom: 0; }
.ai-list li::before { content: ""; position: absolute; left: 2px; top: 13px; width: 5px; height: 5px; border-radius: 50%; background: var(--ai); }
.ai-list li.flagged::before { background: var(--warn); }
.ai-foot { margin-top: 8px; font-size: 11.5px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.cite { display: inline-block; font-size: 10.5px; padding: 0 5px; margin-left: 3px; border-radius: 4px; background: var(--navy-soft); color: var(--navy); border: 0; cursor: pointer; vertical-align: 1px; line-height: 17px; }
.cite:hover { background: var(--navy); color: #fff; }
.linkish { border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; text-decoration: underline dotted var(--line-2); text-underline-offset: 3px; }
.linkish:hover { color: var(--navy-2); text-decoration-color: var(--navy-2); }

.flag { display: flex; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.flag:last-child { border-bottom: 0; }
.flag .sev { width: 4px; border-radius: 2px; flex-shrink: 0; }
.flag.crit .sev { background: var(--crit); }
.flag.warn .sev { background: var(--warn); }
.flag.info .sev { background: var(--info); }
.flag b { display: block; font-size: 13px; font-weight: 600; }
.flag small { color: var(--ink-2); font-size: 12px; display: block; }
.flag .cat { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }

.med { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.med:last-child { border-bottom: 0; }
.med .name { font-weight: 600; }
.med .sub { grid-column: 1 / -1; font-size: 11.5px; color: var(--muted); }

.trend { display: grid; grid-template-columns: 1fr 96px auto; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.trend:last-child { border-bottom: 0; }
.trend .val { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.trend .val.high, .trend .val.low { color: var(--crit); }
.trend small { display: block; color: var(--muted); font-size: 11px; }
.spark { width: 96px; height: 26px; display: block; }
.spark .line { fill: none; stroke: var(--navy-2); stroke-width: 1.6; }
.spark .band { fill: var(--ok-bg); }
.spark .dot { fill: var(--navy-2); }
.spark .dot.abn { fill: var(--crit); }

.visit { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.visit:last-child { border-bottom: 0; }
.visit .top { display: flex; gap: 6px; align-items: baseline; }
.visit .date { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.visit .fac { color: var(--ink-2); flex: 1; min-width: 0; }
.visit .dx { color: var(--muted); font-size: 12px; }

.ask { display: flex; gap: 8px; }
.ask input { flex: 1; }
.suggest { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.suggest button { border: 1px solid var(--line-2); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; cursor: pointer; color: var(--ink-2); }
.suggest button:hover { border-color: var(--navy-2); color: var(--navy); }
.answer { margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: var(--ai-bg); border: 1px solid var(--ai-line); font-size: 13px; }
.answer.nf { background: var(--panel-2); border-color: var(--line); color: var(--ink-2); }
.answer .q { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }

/* ---------- source drawer / history ---------- */
.src-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.result-flag-high, .result-flag-low { color: var(--crit); font-weight: 700; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 12px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--navy); border-bottom-color: var(--navy); }
.tl { list-style: none; padding: 0; margin: 0; position: relative; }
.tl > li { position: relative; padding: 0 0 14px 22px; }
.tl > li::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: -6px; width: 2px; background: var(--line); }
.tl > li:last-child::before { display: none; }
.tl > li::after { content: ""; position: absolute; left: 1px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 2px solid var(--navy-2); }
.tl > li.paper::after { border-color: var(--saffron); }
.tl > li.hl > .card { outline: 2px solid var(--ai); }
.tl .card { padding: 10px 12px; }
.tl .sub { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 12.5px; }

/* ---------- gate (no access) ---------- */
.gate { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; align-items: start; margin-top: 12px; }
.notice { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.notice h4 { font-size: 14px; margin-bottom: 6px; }
.notice ul { margin: 0; padding-left: 18px; font-size: 13px; }
.notice li + li { margin-top: 3px; }
.phone { width: 260px; max-width: 100%; margin: 0 auto; border: 10px solid #1d2939; border-radius: 28px; background: #f2f4f7; padding: 14px 10px; min-height: 240px; }
.phone .bar { text-align: center; font-size: 11px; color: var(--muted); margin-bottom: 8px; }
.sms { background: #fff; border-radius: 12px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow); }
.sms + .sms { margin-top: 6px; }
.sms time { display: block; font-size: 10px; color: var(--muted); margin-top: 3px; }
.otp { font-size: 22px; letter-spacing: .4em; text-align: center; font-family: var(--mono); }

/* ---------- documents ---------- */
.docgrid { display: grid; grid-template-columns: 1fr 1.2fr; gap: 16px; align-items: start; }
.docimg { width: 100%; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.lowconf { background: var(--warn-bg) !important; border-color: var(--warn-line) !important; }
.xtable input { width: 100%; padding: 4px 6px; border: 1px solid var(--line); border-radius: 5px; font-size: 13px; }
.conf { font-size: 11px; font-variant-numeric: tabular-nums; }

/* ---------- admin ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile b { display: block; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tile span { font-size: 12px; color: var(--muted); }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: grid; grid-template-columns: 200px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.checklist li:last-child { border-bottom: 0; }
.checklist b { font-weight: 650; }
.checklist b::before { content: "✓ "; color: var(--ok); }
pre.payload { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px; font-size: 11.5px; overflow: auto; max-height: 60vh; white-space: pre-wrap; word-break: break-word; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .sgrid { grid-template-columns: 1fr 1fr; }
  .sgrid > .col:first-child { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  main { padding: 12px 16px 24px; }
  .topbar-in { flex-wrap: wrap; padding: 8px 16px; gap: 10px; }
  .topsearch { order: 5; flex-basis: 100%; max-width: none; }
  .userchip .who { display: none; }
  .login-wrap, .home-grid, .gate, .docgrid, .sgrid, .grid2 { grid-template-columns: 1fr; }
  .points { grid-template-columns: 1fr; }
  .phead { flex-wrap: wrap; }
  .phead .actions { justify-content: flex-start; width: 100%; }
  .checklist li { grid-template-columns: 1fr; gap: 2px; }
  .nav a { padding: 6px 8px; }
}

/* ---------- print: one-page A4 summary ---------- */
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 11px; }
  .topbar, .footer, .tricolor, .no-print, .drawer, .toast, .ask-card, .phead .actions, .cite { display: none !important; }
  main { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  .sgrid { grid-template-columns: 1.3fr 1fr; gap: 8px; }
  .sgrid > .col:first-child { grid-column: auto; }
  .print-only { display: block !important; }
}
.print-only { display: none; }

/* ---------- single-tab layout: AI card + colour-coded collapsible sections ---------- */
.p360 { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 14px; margin-top: 12px; align-items: start; }
.ai-card { position: sticky; top: 76px; }
.ai-tabs button { padding: 4px 10px; }

/* "Needs attention": one line per item, colour by severity, expands for detail */
.attention { margin-top: 12px; }
.attention h3 { margin-bottom: 6px; }
.att-note { text-transform: none; letter-spacing: 0; font-weight: 500; }
.att { border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px; background: var(--panel); margin-bottom: 6px; }
.att.crit { border-left-color: var(--crit); background: var(--crit-bg); }
.att.warn { border-left-color: var(--warn); }
.att.info { border-left-color: var(--line-2); background: var(--panel-2); }
.att > summary { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; list-style: none; font-size: 13.5px; }
.att > summary::-webkit-details-marker { display: none; }
.att > summary b { flex: 1; font-weight: 600; }
.att-cat { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; min-width: 86px; }
.att.crit .att-cat { color: var(--crit); }
.att.warn .att-cat { color: var(--warn); }
.att.info .att-cat { color: var(--muted); }
.att > p { padding: 0 12px 8px 108px; font-size: 13px; color: var(--ink-2); }
.att > p + p { padding-top: 0; }

/* sections: each has its own accent colour, icon, count and a one-line preview when closed */
.sec { --c: var(--navy-2); --c-bg: var(--navy-soft); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 10px; border-left: 4px solid var(--c); }
.sec-visits { --c: #175cd3; --c-bg: #eff8ff; }
.sec-meds { --c: #6941c6; --c-bg: #f4f3ff; }
.sec-reports { --c: #0e9384; --c-bg: #f0fdf9; }
.sec-pharmacy { --c: #3e4784; --c-bg: #eef0f8; }
.sec-family { --c: #c11574; --c-bg: #fdf2fa; }
.sec > summary { min-width: 0; display: flex; align-items: center; gap: 12px; padding: 11px 14px; cursor: pointer; list-style: none; border-radius: var(--radius); }
.sec > summary::-webkit-details-marker { display: none; }
.sec > summary:hover { background: var(--panel-2); }
.sec[open] > summary { border-bottom: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; }
.sec-badge { width: 34px; height: 34px; border-radius: 9px; background: var(--c-bg); color: var(--c); display: grid; place-items: center; flex-shrink: 0; }
.sec-ico { width: 19px; height: 19px; }
.sec-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sec-name { display: flex; align-items: center; gap: 8px; }
.sec-name b { font-size: 14.5px; font-weight: 650; }
.sec-count { font-size: 11.5px; font-weight: 700; color: var(--c); background: var(--c-bg); padding: 0 7px; border-radius: 999px; }
.sec-preview { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.sec[open] .sec-preview { display: none; }
.sec-chev { width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); transition: transform .15s; flex-shrink: 0; margin-right: 4px; }
details[open] > summary .sec-chev { transform: rotate(45deg); }
.sec-body { padding: 8px 14px 12px; }
.sub-h { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--c); margin: 14px 0 4px; font-weight: 700; }

.tl-row { display: grid; grid-template-columns: 92px 1fr; gap: 10px; width: 100%; text-align: left; padding: 7px 4px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; font: inherit; color: inherit; font-size: 13px; }
.tl-row:last-of-type { border-bottom: 0; }
button.tl-row:hover { background: var(--c-bg, var(--panel-2)); }
.tl-row.static { cursor: default; }
.tl-row .date { font-weight: 650; font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.tl-row .what small { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; }
.tl-row .abn { color: var(--crit); }
.tl-row .nd { color: var(--warn); font-weight: 600; }
.tl-row .linked { color: var(--ok); }
.more-link { display: inline-block; margin-top: 6px; }

@media (max-width: 1100px) {
  .p360 { grid-template-columns: minmax(0, 1fr); }
  .ai-card { position: static; }
}
@media (max-width: 640px) {
  .att > p { padding-left: 12px; }
  .att-cat { min-width: 0; }
  .tl-row { grid-template-columns: 1fr; gap: 0; }
}
@media print {
  .p360 { grid-template-columns: minmax(0, 1fr); }
  .ai-card { position: static; }
  .sec-chev, .sec-preview { display: none !important; }
  .sec, .att { break-inside: avoid; box-shadow: none; }
}

/* ---------- doctor's one-screen view: tiles open popups ---------- */
.onescreen { display: flex; flex-direction: column; gap: 12px; }
.onescreen-main { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 14px; }
.onescreen .ai-card { position: static; display: flex; flex-direction: column; min-height: 0; }
.ai-scroll { flex: 1; min-height: 0; overflow: auto; padding: 8px 14px 10px; }
.ai-ask { padding: 10px 14px 12px; border-top: 1px solid var(--line); }
.ai-ask .suggest { margin-top: 6px; }
.tiles-col { display: flex; flex-direction: column; gap: 10px; min-height: 0; }

.tile-sec { flex: 1; min-height: 66px; display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 10px 16px; background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--c); border-radius: var(--radius);
  box-shadow: var(--shadow); cursor: pointer; font: inherit; color: inherit; transition: background .12s, transform .12s; }
.tile-sec:hover { background: var(--c-bg); }
.tile-sec:active { transform: scale(.995); }
.tile-sec .sec-badge { width: 40px; height: 40px; }
.tile-sec .sec-ico { width: 21px; height: 21px; }
.tile-sec .sec-preview { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-sec .sec-chev { transform: rotate(-45deg); }
.tile-sec .chip { margin-left: 2px; }
.sec-attention { --c: var(--warn); --c-bg: var(--warn-bg); }
.sec-source { --c: var(--navy-2); --c-bg: var(--navy-soft); }

/* severity chips in the header bar; click opens "Needs attention" */
.att-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; justify-content: flex-end; }
.att-chip { border: 1px solid; border-radius: 999px; padding: 2px 10px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  max-width: 300px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-chip.crit { background: var(--crit); border-color: var(--crit); color: #fff; }
.att-chip.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.att-chip.info { background: #fff; border-color: var(--line-2); color: var(--muted); }
.att-chip:hover { filter: brightness(.96); }

/* popup */
.modal { width: min(760px, calc(100vw - 32px)); max-height: min(82vh, 780px); padding: 0; border: 0;
  border-top: 5px solid var(--c); border-radius: 14px; box-shadow: 0 24px 64px rgba(16, 24, 40, .28); color: var(--ink); background: var(--panel); }
.modal[open] { display: flex; flex-direction: column; }
.modal::backdrop { background: rgba(16, 24, 40, .45); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head .sec-badge { width: 38px; height: 38px; }
.modal-titles { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.modal-titles h2 { font-size: 16px; }
.modal-body { padding: 12px 18px 18px; overflow: auto; }
.modal .back { margin: -4px 0 8px -6px; }
.att-item { border-left: 4px solid var(--line-2); background: var(--panel-2); border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; }
.att-item.crit { border-left-color: var(--crit); background: var(--crit-bg); }
.att-item.warn { border-left-color: var(--warn); background: var(--warn-bg); }
.att-item b { display: block; font-size: 14px; margin: 1px 0 2px; }
.att-item p { font-size: 13px; color: var(--ink-2); }
.att-item.crit .att-cat { color: var(--crit); } .att-item.warn .att-cat { color: var(--warn); } .att-item.info .att-cat { color: var(--muted); }

/* desktop: the whole view fits the window; only the AI card scrolls internally */
@media (min-width: 1100px) and (min-height: 640px) {
  .onescreen { height: calc(100dvh - 158px); }
  .onescreen-main { flex: 1; min-height: 0; }
}
@media (max-width: 1099px) {
  .onescreen-main { grid-template-columns: minmax(0, 1fr); }
  .ai-scroll { max-height: 60vh; }
  .att-chips { margin-left: 0; justify-content: flex-start; width: 100%; }
}
@media print {
  .onescreen { height: auto; }
  .tiles-col, .att-chips, .ai-ask { display: none !important; }
  .ai-scroll { overflow: visible; }
  .print-sec { margin-top: 14px; break-inside: avoid; }
  .print-sec h2 { font-size: 14px; border-bottom: 1px solid #999; padding-bottom: 3px; margin-bottom: 6px; }
}

/* labelled trend rows in the reports popup */
.trend2 { display: grid; grid-template-columns: 150px minmax(0, 1fr) 140px; gap: 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.trend2 .t-name { display: flex; flex-direction: column; font-size: 13.5px; font-weight: 600; }
.trend2 small { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; }
.trend2 .t-now { text-align: right; }
.trend2 .t-val { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.trend2 .t-val small { display: inline; font-size: 11.5px; font-weight: 500; }
.trend2 .t-val.abn { color: var(--crit); }
.tchart { width: 100%; max-width: 340px; height: auto; display: block; margin: 0 auto; overflow: visible; }
.tchart .band { fill: var(--ok-bg); stroke: var(--ok-line); stroke-width: .6; }
.tchart .axis { stroke: var(--line-2); stroke-width: 1; }
.tchart .line { fill: none; stroke: var(--c, var(--navy-2)); stroke-width: 1.8; }
.tchart circle { fill: var(--c, var(--navy-2)); stroke: #fff; stroke-width: 1.2; }
.tchart .abn circle { fill: var(--crit); }
.tchart text { font: 600 9.5px var(--font); fill: var(--ink-2); }
.tchart .abn text.v { fill: var(--crit); }
.tchart text.d { font-weight: 500; fill: var(--muted); }
@media (max-width: 640px) {
  .trend2 { grid-template-columns: 1fr auto; }
  .trend2 .tchart { grid-column: 1 / -1; grid-row: 2; }
}

/* ---------- view switcher (Dashboard / Summary report / Timeline) ---------- */
.view-switch button { padding: 6px 12px; font-size: 12.5px; }
.view-switch { margin-right: 6px; }

/* ---------- view 2: summary report (document) ---------- */
.report-wrap { flex: 1; min-height: 0; overflow: auto; }
.report { max-width: 980px; margin: 0 auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 28px 26px; }
.rp-head { display: flex; align-items: flex-start; gap: 10px; border-bottom: 2px solid var(--navy); padding-bottom: 10px; margin-bottom: 4px; }
.rp-head h2 { font-size: 19px; color: var(--navy); }
.rp-h { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; font-size: 13px; color: var(--navy); text-transform: uppercase; letter-spacing: .04em; }
.rp-h .rp-n { flex-shrink: 0; width: 20px; height: 20px; border-radius: 50%; background: var(--navy); color: #fff; font-size: 11px; display: grid; place-items: center; letter-spacing: 0; }
.report p { font-size: 13.5px; }
.rp-alerts { list-style: none; padding: 0; margin: 0; }
.rp-alerts li { padding: 6px 10px; border-left: 4px solid var(--line-2); background: var(--panel-2); border-radius: 6px; margin-bottom: 5px; font-size: 13px; }
.rp-alerts li.crit { border-left-color: var(--crit); background: var(--crit-bg); }
.rp-alerts li.warn { border-left-color: var(--warn); background: var(--warn-bg); }
.rp-alerts li.none { color: var(--muted); }
.rp-ai { margin: 0; padding-left: 20px; font-size: 13.5px; }
.rp-ai li { margin-bottom: 4px; }
.rp-t { font-size: 12.5px; }
.rp-t td.abn, .rp-t td .abn { color: var(--crit); }
.rp-t .nd, .tl-row .nd { color: var(--warn); font-weight: 600; }
.rp-foot { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 10px; }
.rp-sign { margin-top: 26px; display: flex; justify-content: flex-end; }
.rp-sign span { border-top: 1px solid var(--ink-2); padding-top: 4px; font-size: 12px; color: var(--muted); min-width: 280px; text-align: center; }

/* ---------- view 3: timeline ---------- */
.tl-card { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tl-head { padding: 12px 16px 8px; border-bottom: 1px solid var(--line); }
.jstrip { width: 100%; height: auto; display: block; margin: 6px 0 2px; }
.jstrip .axis { stroke: var(--line-2); stroke-width: 2; }
.jstrip .tick { stroke: var(--line-2); stroke-width: 1; }
.jstrip text { font: 600 11px var(--font); fill: var(--muted); }
.jstrip circle { cursor: pointer; stroke: #fff; stroke-width: 2; }
.jstrip circle:hover { stroke-width: 3; }
.jlegend { display: flex; flex-wrap: wrap; gap: 6px; }
.jlegend button { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line-2); background: #fff; border-radius: 999px; padding: 2px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.jlegend button.on { border-color: var(--navy); background: var(--navy-soft); color: var(--navy); font-weight: 600; }
.jlegend .dot { width: 9px; height: 9px; border-radius: 50%; }
.jlist { list-style: none; margin: 0; padding: 4px 16px 16px; flex: 1; min-height: 0; overflow: auto; }
.jy { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .06em; padding: 12px 0 4px 104px; }
.jv { display: grid; grid-template-columns: 92px 1fr; gap: 12px; position: relative; }
.jv::before { content: ""; position: absolute; left: 98px; top: 0; bottom: 0; width: 2px; background: var(--line); }
.jv-date { font-size: 12.5px; font-weight: 650; color: var(--ink-2); padding-top: 10px; text-align: right; font-variant-numeric: tabular-nums; }
.jv-body { margin: 5px 0 5px 14px; padding: 8px 12px; border: 1px solid var(--line); border-left: 4px solid var(--tc); border-radius: 8px; background: var(--panel); position: relative; transition: box-shadow .3s; }
.jv-body::before { content: ""; position: absolute; left: -22px; top: 12px; width: 12px; height: 12px; border-radius: 50%; background: var(--tc); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line-2); }
.jv.flash .jv-body { box-shadow: 0 0 0 3px var(--tc); }
.jv-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; }
.jv-type { font-size: 11px; font-weight: 700; color: var(--tc); text-transform: uppercase; letter-spacing: .04em; }
.jv-what { font-size: 13px; margin-top: 1px; }
.jv-links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.jl { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel-2); border-radius: 6px; padding: 2px 8px 2px 2px; font: inherit; font-size: 12px; color: var(--ink-2); cursor: pointer; max-width: 100%; text-align: left; }
.jl i { font-style: normal; font-size: 10px; font-weight: 700; padding: 2px 5px; border-radius: 4px; background: #fff; border: 1px solid var(--line); color: var(--muted); }
.jl.rx i { color: #6941c6; } .jl.rep i { color: #0e9384; } .jl.ph i { color: #3e4784; }
.jl.abn { border-color: var(--crit-line); background: var(--crit-bg); color: var(--crit); }
.jl.none { cursor: default; color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.jl:hover:not(.none) { border-color: var(--navy-2); }

@media (max-width: 1099px) {
  .view-switch { order: -1; width: 100%; margin-bottom: 4px; }
  .report { padding: 14px; }
  .jv { grid-template-columns: 1fr; gap: 0; }
  .jv::before, .jv-body::before { display: none; }
  .jv-date { text-align: left; padding: 6px 0 0; }
  .jv-body { margin-left: 0; }
  .jy { padding-left: 0; }
}
@media print {
  .report-wrap, .jlist { overflow: visible; }
  .report { border: 0; box-shadow: none; padding: 0; }
  .view-switch, .jlegend, .jstrip { display: none !important; }
}

/* summary report: earlier results as dated pills */
.rp-series { display: flex; flex-wrap: wrap; gap: 5px; }
.rp-pt { display: inline-flex; flex-direction: column; align-items: center; min-width: 50px; padding: 3px 8px 2px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); line-height: 1.25; }
.rp-pt b { font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--ink); }
.rp-pt small { font-size: 10.5px; color: var(--muted); }
.rp-pt.abn { background: var(--crit-bg); border-color: var(--crit-line); }
.rp-pt.abn b { color: var(--crit); }
@media print { .rp-pt { border-color: #bbb; } }

/* copy of the report handed to the PDF renderer: fixed A4-friendly width, no shadows */
.report-pdf { width: 700px; max-width: none; border: 0; box-shadow: none; padding: 0; }
/* Devanagari: letter-spacing and upper-casing break conjuncts */
.report[lang=hi] .rp-h, .report[lang=hi] .rp-t th { letter-spacing: 0; text-transform: none; }

/* AIKosh: district context and verified-facility marker */
.district-note { border: 1px solid var(--info-line); background: linear-gradient(180deg, var(--info-bg), #fff); border-radius: 10px; padding: 10px 14px 12px; margin: 4px 0 12px; }
.dn-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.dn-head b { font-size: 13px; color: var(--info); }
.dn-head small { font-size: 11px; color: var(--muted); }
.dn-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dn-stat { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; gap: 1px; }
.dn-val { font-size: 24px; font-weight: 750; color: var(--ink); letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.dn-lbl { font-size: 12.5px; color: var(--ink-2); }
.dn-stat > small { font-size: 11px; color: var(--muted); }
.dn-me { margin-top: 6px; font-size: 11.5px; padding: 3px 8px; border-radius: 6px; align-self: flex-start; }
.dn-me.in { background: var(--crit-bg); color: var(--crit); border: 1px solid var(--crit-line); }
.dn-me.out { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok-line); }
.report .district-note { margin-top: 10px; }
@media (max-width: 640px) { .dn-stats { grid-template-columns: 1fr; } }

/* lab results as chips */
.rchips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.rchip { display: inline-flex; align-items: baseline; gap: 3px; padding: 1px 7px; border-radius: 5px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rchip i { font-style: normal; color: var(--muted); }
.rchip small { font-size: 10.5px; color: var(--muted); }
.rchip b { font-size: 11px; }
.rchip.abn { background: var(--crit-bg); border-color: var(--crit-line); color: var(--crit); font-weight: 600; }
.rchip.abn i, .rchip.abn small { color: #b4231899; }
.verified { font-size: 10.5px; font-weight: 600; color: var(--ok); background: var(--ok-bg); border: 1px solid var(--ok-line); border-radius: 999px; padding: 0 6px; }
