:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #1e293b;
  --ink-2: #475569;
  --ink-3: #64748b;
  --line: #d9e0e7;
  --line-2: #e8edf2;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4f2;
  --danger: #b91c1c;
  --warn-bg: #fff7e6;
  --warn-line: #f59e0b;
  --warn-ink: #92400e;
  --ok: #15803d;
  --ok-ink: #ffffff;
  --sym-on: #dc2626;
  --band: #dbeafe;
  --band-ink: #1e40af;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 8px rgba(15, 23, 42, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1419; --surface: #171d24; --surface-2: #1c232b;
    --ink: #e6ebf0; --ink-2: #b4bfca; --ink-3: #8d99a6;
    --line: #2d3742; --line-2: #242d37;
    --accent: #2bb3a3; --accent-ink: #06201d; --accent-soft: #123330;
    --danger: #f87171; --warn-bg: #3a2c0f; --warn-line: #d99a2b; --warn-ink: #f5c56b;
    --ok: #22c55e; --ok-ink: #052e14;
    --sym-on: #ef4444; --band: #1e3350; --band-ink: #9cc3ff;
    --shadow: none; color-scheme: dark;
  }
}
/* disease themes: <html data-disease> is set by js/config.js, the home page cards carry it themselves */
[data-disease="dengue"] { --accent: #d03441; --accent-ink: #ffffff; --accent-soft: #fef3f4; --top-bg: #d03441; --top-ink: #ffffff; }
[data-disease="zika"] { --accent: #cb2f87; --accent-ink: #ffffff; --accent-soft: #fef5fa; --top-bg: #cb2f87; --top-ink: #ffffff; }
[data-disease="chik"] { --accent: #0276b8; --accent-ink: #ffffff; --accent-soft: #f2fafe; --top-bg: #0276b8; --top-ink: #ffffff; }
@media (prefers-color-scheme: dark) {
  /* the accent is too bright to fill a whole top bar on a dark page, so the bar has its own deeper shade */
  :root:not([data-theme="light"])[data-disease="dengue"], :root:not([data-theme="light"]) [data-disease="dengue"] { --accent: #f58a93; --accent-ink: #2b0609; --accent-soft: #3f1d22; --top-bg: #8f2a35; }
  :root:not([data-theme="light"])[data-disease="zika"], :root:not([data-theme="light"]) [data-disease="zika"] { --accent: #f68bc6; --accent-ink: #2d0619; --accent-soft: #401b32; --top-bg: #8c2a66; }
  :root:not([data-theme="light"])[data-disease="chik"], :root:not([data-theme="light"]) [data-disease="chik"] { --accent: #6cc9f5; --accent-ink: #04222f; --accent-soft: #133645; --top-bg: #1f6a92; }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 "Sarabun", "Leelawadee UI", "Tahoma", system-ui, sans-serif;
  background: var(--bg); color: var(--ink);
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--ink-3); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 7px 14px; cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
/* case header: history (blue), cancel edits (amber), done editing (green) */
.btn.info { background: var(--band); border-color: color-mix(in srgb, var(--band-ink) 30%, transparent); color: var(--band-ink); }
.btn.info:hover { border-color: var(--band-ink); }
.btn.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); }
.btn.warn:hover { filter: brightness(.97); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: var(--ok-ink); }
.btn.ok:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn.danger.solid:hover { background: #b91c1c; border-color: #b91c1c; }
.btn.lg { padding: 9px 18px; font-size: 16px; font-weight: 600; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.has { border-color: var(--accent); color: var(--accent); }
.btn.has::after { content: " ●"; font-size: 9px; vertical-align: 2px; }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--ink-3); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--line-2); color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.top-left { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; min-width: 0; }
.disease-nav { width: auto; max-width: 100%; }
/* top bar in the disease colour: its text takes the bar's ink, its controls stay on solid surface */
:root[data-disease] .topbar { background: var(--top-bg); color: var(--top-ink); border-bottom-color: transparent; }
:root[data-disease] .topbar :is(.brand span, .brand span b, .home-link .back, .brand .page-link, .who) { color: inherit; }
:root[data-disease] .topbar :is(.btn, .btn.ghost, .disease-nav) { background: var(--surface); border-color: transparent; color: var(--ink); }
:root[data-disease] .topbar .btn.primary { color: var(--accent); font-weight: 700; }
:root[data-disease] .topbar .btn:hover { filter: brightness(.95); }
:root[data-disease] .topbar :focus-visible { outline-color: var(--top-ink); }
.brand i { font-style: normal; }
/* img/mosquito.svg as a mask, so it takes the colour of the title beside it */
.brand-ico { display: inline-block; width: 1.25em; height: 1.25em; margin-right: 6px; vertical-align: -0.25em; background: currentColor; -webkit-mask: url(../img/mosquito.svg) center / contain no-repeat; mask: url(../img/mosquito.svg) center / contain no-repeat; }
.disease-home { max-width: 760px; margin: 0 auto; padding: 40px 20px; }
.disease-home h1 { margin: 0 0 16px; font-size: 22px; }
.disease-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.disease-card { display: grid; gap: 4px; padding: 24px 20px; background: var(--surface); border: 1px solid var(--line); border-top: 4px solid var(--accent); border-radius: var(--radius); box-shadow: var(--shadow); color: inherit; text-decoration: none; }
.disease-card:hover, .disease-card:focus-visible { border-color: var(--accent); background: var(--accent-soft); }
.disease-card strong { font-size: 18px; color: var(--accent); }
.disease-card span { font-size: 14px; color: var(--ink-3); }
.app-version { position: fixed; right: 16px; bottom: 12px; font-size: 12px; color: var(--ink-3); pointer-events: none; user-select: none; }
@media print { .app-version { display: none; } }
.other-apps-head { margin: 32px 0 12px; font-size: 16px; color: var(--ink-3); font-weight: 600; }
.disease-card.other-app { --accent: #0f766e; --accent-soft: rgba(15, 118, 110, .08); }   /* the factory app's teal */
.disease-card.other-app.zika-baby { --accent: #db2777; --accent-soft: rgba(219, 39, 119, .08); }   /* pink */
/* a field caption with a round "!" after it; hover or focus shows data-tip */
.cap-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.info-tip { position: relative; flex: none; display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid var(--warn-line); color: var(--warn-ink); background: var(--warn-bg); font-size: 11px; font-weight: 700; line-height: 1; cursor: help; }
.info-tip::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); right: 0; z-index: 20; width: max-content; max-width: 240px;
  padding: 6px 10px; border-radius: 6px; background: var(--ink, #1f2937); color: var(--surface, #fff); font-size: 12.5px; font-weight: 500; white-space: normal;
  box-shadow: var(--shadow); opacity: 0; visibility: hidden; transition: opacity .12s; pointer-events: none; }
.info-tip:hover::after, .info-tip:focus-visible::after { opacity: 1; visibility: visible; }
.brand { display: flex; flex-direction: column; line-height: 1.25; }
.brand strong { font-size: 17px; }
.brand span { color: var(--ink-3); font-size: 13px; }
.home-link { color: inherit; text-decoration: none; }
.home-link .back { font-style: normal; color: var(--accent); font-weight: 600; margin-right: 6px; }
.home-link:hover strong, .home-link:hover .back { text-decoration: underline; text-underline-offset: 3px; }
.brand .page-link { color: var(--accent); font-weight: 600; text-decoration: underline dashed; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.brand .page-link:hover { text-decoration-style: solid; }
.brand span b { color: var(--ink-2); }

/* ---------- page สถิติ (stats.html, js/stats.js) ---------- */
.stats-page {
  --viz-1: var(--accent); --viz-grid: #e8edf2; --viz-base: #c3cbd4;
  --viz-c1: #eb8a1d; --viz-c2: #8b5cf6; --viz-c3: #2a78d6; --viz-c4: #1baf7a; --viz-none: #a3adb8;
  --viz-ok: #14b8a6; --viz-late: #dc2626;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .stats-page { --viz-grid: #242d37; --viz-base: #3a4652;
  --viz-c1: #f39a33; --viz-c2: #a07cf8; --viz-c3: #3987e5; --viz-c4: #2bc48c; --viz-none: #66727f; --viz-ok: #2dd4bf; --viz-late: #ef4444; } }
:root[data-theme="dark"] .stats-page { --viz-grid: #242d37; --viz-base: #3a4652;
  --viz-c1: #f39a33; --viz-c2: #a07cf8; --viz-c3: #3987e5; --viz-c4: #2bc48c; --viz-none: #66727f; --viz-ok: #2dd4bf; --viz-late: #ef4444; }
.stats { max-width: 1280px; margin: 0 auto; padding: 16px 20px 40px; }
.st-filters { display: flex; flex-wrap: wrap; align-items: end; gap: 12px 16px; margin-bottom: 16px; }
.st-filters label { display: grid; gap: 4px; min-width: 160px; }
.st-filters .hint { padding-bottom: 9px; }
.st-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.st-tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 2px; box-shadow: var(--shadow); }
.st-tile .st-k { font-size: 13px; color: var(--ink-2); }
.st-tile b { font-size: 30px; font-weight: 600; line-height: 1.2; color: var(--ink); }
.st-tile small { font-size: 12px; color: var(--ink-3); }
.st-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.st-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.st-card.wide { grid-column: 1 / -1; }
.st-card h3 { margin: 0; font-size: 15px; }
.st-sub { margin: 2px 0 0; font-size: 12px; color: var(--ink-3); }
.st-card > :is(.st-hbars, svg) { margin-top: 12px; }
.st-hbars { display: grid; gap: 6px; }
.st-hrow { display: grid; grid-template-columns: minmax(90px, 34%) 1fr 36px; align-items: center; gap: 8px; font-size: 13px; border-radius: 6px; padding: 1px 4px; }
.st-hrow:hover, .st-hrow:focus-visible { background: var(--surface-2); outline: none; }
.st-hl { color: var(--ink-2); overflow-wrap: anywhere; }
.st-ht { height: 16px; }
.st-ht i { display: block; height: 100%; background: var(--viz-1); border-radius: 0 4px 4px 0; }
.st-hrow:hover .st-ht i, .st-hrow:focus-visible .st-ht i { filter: brightness(1.12); }
.st-hv { text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.st-cols { width: 100%; height: auto; display: block; overflow: visible; }
.st-cols .grid { stroke: var(--viz-grid); stroke-width: 1; }
.st-cols .base { stroke: var(--viz-base); stroke-width: 1; }
.st-cols .tick { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.st-cols .cap { fill: var(--ink); font-size: 12px; font-weight: 600; }
.st-cols .mark { fill: var(--viz-1); }
.st-cols .seg { stroke: var(--surface); stroke-width: 1; }
.st-cols .hit { fill: transparent; }
.st-col { outline: none; }
.st-col:hover .hit, .st-col:focus-visible .hit { fill: var(--surface-2); }
.st-col:hover :is(.mark, .seg), .st-col:focus-visible :is(.mark, .seg) { filter: brightness(1.12); }
.st-table { margin-top: 10px; font-size: 13px; }
.st-table summary { cursor: pointer; color: var(--ink-3); }
.st-table table { border-collapse: collapse; margin-top: 6px; min-width: 200px; }
.st-table th, .st-table td { border-bottom: 1px solid var(--line-2); padding: 3px 10px 3px 0; text-align: left; }
.st-table td:last-child, .st-table th:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.st-tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; box-shadow: var(--shadow); display: grid; font-size: 12px; }
.st-tip b { font-size: 14px; color: var(--ink); }
.st-tip span { color: var(--ink-3); white-space: pre-line; }
.st-legend { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--ink-2); }
.st-legend li { display: flex; align-items: center; gap: 6px; }
.st-legend i { width: 10px; height: 10px; border-radius: 3px; }
.st-more > summary { cursor: pointer; list-style: none; }
.st-more > summary::-webkit-details-marker { display: none; }
.st-more > summary .st-hl::before { content: "▸ "; color: var(--ink-3); }
.st-more[open] > summary .st-hl::before { content: "▾ "; }
.st-more-l { list-style: none; margin: 4px 0 6px; padding: 0 4px 0 18px; display: grid; gap: 3px; font-size: 13px; color: var(--ink-2); }
.st-more-l li { display: grid; grid-template-columns: 1fr auto; gap: 8px; overflow-wrap: anywhere; }
.st-more-l b { font-weight: 400; color: var(--ink); font-variant-numeric: tabular-nums; }
.st-pie-b { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-top: 12px; }
.st-pie-b svg { width: 120px; height: 120px; flex: none; }
/* HI / CI: one pie each, side by side under the bars */
.st-pie-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 20px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.st-pie-pair .st-pie-b { margin-top: 6px; }
.st-pie-pair .st-pie-b svg { width: 96px; height: 96px; }
.st-pie-h { font-size: 14px; color: var(--ink); }
.st-slice { stroke: var(--surface); stroke-width: 2; outline: none; }
.st-slice:hover, .st-slice:focus-visible { filter: brightness(1.12); }
.st-pie-l { list-style: none; margin: 0; padding: 0; flex: 1 1 160px; min-width: 0; display: grid; gap: 4px; font-size: 13px; color: var(--ink-2); }
.st-pie-l li { display: grid; grid-template-columns: 10px 1fr auto; align-items: baseline; gap: 8px; }
.st-pie-l i { width: 10px; height: 10px; border-radius: 3px; }
.st-pie-l span { overflow-wrap: anywhere; }
.st-pie-l b { font-weight: 400; color: var(--ink); font-variant-numeric: tabular-nums; }
/* save as image (saveImage() in stats.js): the caption only shows in the image, the buttons never do */
.st-save { margin-left: auto; }
.st-card { position: relative; }
.st-card h3 { padding-right: 40px; }
.st-img { position: absolute; top: 8px; right: 8px; width: 32px; height: 30px; border: 1px solid var(--accent); border-radius: 6px;
  background: var(--accent); color: var(--accent-ink); font-size: 16px; font-weight: 600; cursor: pointer; }
.st-img:hover, .st-img:focus-visible { filter: brightness(1.08); outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px; }
.st-cap { display: none; margin-bottom: 12px; font-size: 14px; color: var(--ink-2); }
.st-cap b { color: var(--ink); font-size: 16px; }
.st-exporting .st-cap { display: block; }
.st-exporting #stBody { padding: 16px; }
/* tabbed card (tabs() in stats.js): tabs sit on the card's top edge */
.st-group { display: grid; grid-template-rows: auto 1fr; min-width: 0; }
.st-group > .st-card { border-top-left-radius: 0; }
.st-tabbar { display: flex; flex-wrap: wrap; gap: 4px; }
.st-tabbar button { font: inherit; font-size: 13px; padding: 5px 12px; border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0;
  background: var(--surface-2); color: var(--ink-2); cursor: pointer; margin-bottom: -1px; position: relative; }
.st-tabbar button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 600; z-index: 1; }
.st-tabbar button:focus-visible { outline: 2px solid var(--viz-1); outline-offset: -2px; }
/* split bar (splitBars() in stats.js) */
.st-stack { display: flex; }
.st-stack i { border-radius: 0; outline: none; }
.st-stack i + i { box-shadow: inset 2px 0 0 var(--surface); }
.st-stack i:last-child { border-radius: 0 4px 4px 0; }
@media (max-width: 800px) { .st-grid { grid-template-columns: 1fr; } .stats { padding: 12px 16px 32px; } .st-filters label { min-width: 0; flex: 1 1 140px; } }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.layout { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 62px); }
.sidebar { border-right: 1px solid var(--line); background: var(--surface-2); padding: 14px; }
/* sidebar scrolls on its own, independent of the main content */
@media (min-width: 801px) {
  .sidebar {
    position: sticky; top: var(--topbar-h, 62px); align-self: start;
    height: calc(100vh - var(--topbar-h, 62px)); overflow-y: auto; overscroll-behavior: contain;
  }
}
.sidebar input[type=search] { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.case-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 6px; }
.case-list button {
  width: 100%; text-align: left; border: 1px solid transparent; background: transparent; border-radius: 8px;
  padding: 8px 10px; cursor: pointer; display: grid; grid-template-columns: 1fr; column-gap: 8px;
}
.case-list button:hover { background: var(--surface); border-color: var(--line); }
.case-list button.active { background: var(--surface); border-color: var(--accent); box-shadow: var(--shadow); }
.case-list .who { font-weight: 600; }
.case-list .where, .case-list .when { font-size: 13px; color: var(--ink-3); }
.case-list .none { color: var(--ink-3); padding: 8px; }
.case-list .editing { grid-column: 2; font-size: 12px; font-weight: 600; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { padding: 20px 24px 60px; min-width: 0; }
.empty { max-width: 520px; margin: 80px auto; text-align: center; color: var(--ink-2); }
.row-gap { display: flex; gap: 8px; justify-content: center; }

/* case title, actions and tabs stay pinned under the top bar while scrolling */
.editor-head {
  position: sticky; top: var(--topbar-h, 62px); z-index: 6;
  margin: -20px -24px 18px; padding: 14px 24px 0; background: var(--bg);
  box-shadow: 0 1px 0 var(--line), 0 6px 12px -10px rgba(15, 23, 42, .25);
}
.case-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.case-head h2 { margin: 0; font-size: 22px; }
.head-actions { margin-left: auto; display: flex; gap: 8px; }
.mode-badge { font-size: 12px; font-weight: 600; color: var(--ink-3); background: var(--line-2); border-radius: 99px; padding: 2px 10px; }
.mode-badge.locked { color: var(--ink); background: var(--warn-bg); box-shadow: inset 0 0 0 1px var(--warn-line); }
.save-state { font-size: 13px; color: var(--accent); }
.save-state.err { color: var(--danger); }
.case-meta { font-size: 13px; color: var(--ink-3); }
.case-meta .stale { color: #b45309; font-weight: 600; background: #fef3c7; border-radius: 99px; padding: 1px 8px; margin-left: 4px; }
.who { align-self: center; font-size: 13px; color: var(--ink-3); }
.who.logout { text-decoration: underline; text-underline-offset: 2px; }
.case-list .none.err { color: var(--danger); }

.tabs { display: flex; gap: 6px; min-height: 46px; padding-bottom: 8px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 1px solid var(--line); background: var(--surface); padding: 8px 16px; cursor: pointer; color: var(--ink-2);
  border-radius: 8px; font-weight: 600; white-space: nowrap; transition: background .15s, color .15s, border-color .15s;
}
.tabs button:hover { color: var(--ink); border-color: var(--ink-3); background: var(--accent-soft); }
.tabs button.active {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
  box-shadow: 0 2px 6px -2px rgba(15, 118, 110, .5);
}

/* ---------- form ---------- */
fieldset {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
  padding: 14px 18px 18px; margin: 0 0 16px; box-shadow: var(--shadow);
}
legend { font-weight: 700; padding: 0 6px; }
legend small, label small { font-weight: 400; color: var(--ink-3); }
.cap { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 16px; }
.grid + .grid { margin-top: 12px; }
.grid.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid.g6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
/* Zika's and chikungunya's first row also has อายุ (วัน) */
/* and their Case classification names are long */
@media (min-width: 801px) {
  .grid.g5.age-row { grid-template-columns: repeat(6, minmax(0, 1fr)); }   /* every disease now has อายุ (วัน) */
  .grid.ud-row { grid-template-columns: 1fr 2fr 2fr; }
  .grid.ud-row:has(> [data-cc][hidden]) { grid-template-columns: 1fr 1fr; }   /* Zika preg/baby: only แพ้ยา */
  :root:is([data-disease="zika"], [data-disease="chik"]) .grid.g5 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  :root:is([data-disease="zika"], [data-disease="chik"]) .cc-field { grid-column: span 3; }
}
@media (max-width: 800px) { :root:is([data-disease="zika"], [data-disease="chik"]) .cc-field { grid-column: 1 / -1; } }
.form-sub { margin: 14px 0 8px; font-size: 13px; font-weight: 600; }
.ga { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.ga input { flex: 1; min-width: 0; }
.span4 { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; background: var(--surface);
  font-size: 15px; min-width: 0; width: 100%;
}
input:disabled { background: var(--line-2); color: var(--ink-3); }
input.invalid { border-color: var(--danger); }
output {
  display: flex; align-items: center; gap: 6px; min-height: 38px; padding: 7px 9px;
  border-radius: 7px; background: var(--accent-soft); color: var(--ink); font-size: 15px; font-weight: 600;
}
.pill { font-size: 12px; font-weight: 600; background: var(--surface); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; }

.symptoms { display: grid; gap: 10px; }
.sym-group { display: grid; grid-template-columns: 140px 1fr; gap: 12px; align-items: start; }
.sym-group + .sym-group { padding-top: 10px; border-top: 1px dashed var(--line-2); }
.symptoms + .sym-group { margin-top: 10px; }
.other-symp { display: grid; gap: 8px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-row .sym { width: auto; padding: 4px 12px; font-size: 13px; }
.chip-groups { display: grid; gap: 8px; }
.chip-group { display: grid; grid-template-columns: 130px 1fr; gap: 8px; align-items: start; }
.chip-head { font-size: 12px; color: var(--ink-3); padding-top: 5px; }
@media (max-width: 640px) { .chip-group { grid-template-columns: 1fr; gap: 4px; } }
.ud-chips { margin-top: 8px; }
.sym-head { font-size: 13px; font-weight: 600; color: var(--ink-2); padding-top: 7px; }
/* 4 per row, with a little extra space between the 2nd and 3rd box */
.sym-grid { display: grid; grid-template-columns: 1fr 1fr 10px 1fr 1fr; gap: 8px; }
.sym-grid .sym:nth-child(4n+1) { grid-column: 1; }
.sym-grid .sym:nth-child(4n+2) { grid-column: 2; }
.sym-grid .sym:nth-child(4n+3) { grid-column: 4; }
.sym-grid .sym:nth-child(4n+4) { grid-column: 5; }
.sym-group textarea { resize: vertical; }
.risk { margin: 0; padding-left: 22px; }
.risk-checks { display: grid; gap: 8px; }
.sym { white-space: nowrap; }
.sym {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 99px;
  padding: 6px 14px; cursor: pointer; font-weight: 500;
}
.sym:hover { border-color: var(--ink-3); }
.sym[aria-pressed="true"] { background: var(--sym-on); border-color: var(--sym-on); color: #fff; }
/* a fixed-size check box in both states, so toggling never changes the button width */
.sym::before {
  content: ""; flex: none; width: 14px; height: 14px; border-radius: 4px;
  border: 1.5px solid var(--ink-3); background: var(--surface) center / 10px no-repeat;
}
.sym[aria-pressed="true"]::before {
  border-color: #fff; background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 6.5l2.5 2.5L10 3.5' fill='none' stroke='%23dc2626' stroke-width='2'/%3E%3C/svg%3E");
}
.sym:disabled { cursor: default; }

/* ---------- timeline editor ---------- */
.strip-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px 8px; box-shadow: var(--shadow); }
.strip svg { width: 100%; height: auto; display: block; }
.strip .axis { stroke: var(--ink-3); stroke-width: 1.5; }
.strip .tick { stroke: var(--ink-3); }
.strip .stem { stroke: var(--line); stroke-width: 1.5; }
.strip .tick-d { font-size: 12px; font-weight: 700; fill: var(--ink-2); text-anchor: middle; }
.strip .tick-t { font-size: 11px; fill: var(--ink-3); text-anchor: middle; }
.strip .mk text { font-size: 11px; font-weight: 700; fill: #fff; text-anchor: middle; pointer-events: none; }
.strip .mk circle { stroke: var(--surface); stroke-width: 2; }
.strip .mk { cursor: pointer; transform-box: fill-box; transform-origin: center; transition: transform .15s ease, filter .15s ease; outline: none; }
.strip .mk:hover, .strip .mk:focus-visible { transform: scale(1.35); filter: drop-shadow(0 2px 4px rgba(0,0,0,.3)); }

/* hover card for strip markers */
.tip {
  position: fixed; z-index: 50; max-width: 320px; pointer-events: none;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .18); padding: 10px 12px; font-size: 13px;
  opacity: 0; transform: translateY(6px); transition: opacity .15s ease, transform .15s ease;
}
.tip.below { transform: translateY(-6px); }
.tip.show { opacity: 1; transform: none; }
.tip-h { display: flex; align-items: center; gap: 6px; }
.tip-h i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.tip-h span { margin-left: auto; font-weight: 700; font-size: 12px; background: var(--line-2); border-radius: 4px; padding: 0 6px; }
.tip-d { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.tip p { margin: 6px 0 0; line-height: 1.45; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--accent); } to { box-shadow: 0 0 0 3px transparent; } }
.flash { animation: flash 1.4s ease-out; }
.strip .band { fill: var(--band); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); padding: 6px 0 2px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.legend i.band-key { border-radius: 2px; width: 18px; background: var(--band); }

.tl-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 16px 0 10px; }
.tl-add { display: flex; justify-content: flex-start; margin-top: 10px; }
.hint { font-size: 13px; color: var(--ink-3); }

.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.events .none { padding: 24px; text-align: center; color: var(--ink-3); border: 1px dashed var(--line); border-radius: var(--radius); }
.ev {
  display: grid; grid-template-columns: 22px 26px 250px 1fr auto; gap: 10px; align-items: start;
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--c);
  border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow);
}
.ev.warn { background: var(--warn-bg); border-color: var(--warn-line); border-left-color: var(--c); }
.ev .drag { cursor: grab; color: var(--ink-3); font-weight: 700; letter-spacing: -3px; padding-top: 7px; user-select: none; text-align: center; }
.ev .idx {
  width: 24px; height: 24px; border-radius: 50%; background: var(--c); color: #fff; font-size: 12px; font-weight: 700;
  display: grid; place-items: center; margin-top: 6px;
}
.ev-when { display: grid; grid-template-columns: 136px 62px 1fr; gap: 6px; align-items: center; }
.ev-when .dfield input.dtext { padding: 7px 28px 7px 6px; }
.ev-when .time24 { text-align: center; padding: 7px 4px; font-variant-numeric: tabular-nums; }
.ev-when select { grid-column: 1 / -1; }
.ev-when .day { font-weight: 700; color: var(--ink-2); font-size: 13px; text-align: center; }
input.invalid { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.ev textarea { resize: vertical; min-height: 40px; overflow: hidden; }
.ev select { font-weight: 600; }
.ev-actions { display: flex; gap: 4px; align-items: center; padding-top: 3px; }
.ghost-row { opacity: .4; }

/* ---------- dialog ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(860px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.hist-body { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; padding-top: 14px; }
.hist-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; align-content: start; max-height: 60vh; overflow: auto; }
.hist-list button { width: 100%; text-align: left; display: grid; gap: 2px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); cursor: pointer; font-size: 13px; }
.hist-list button span { color: var(--ink-3); overflow-wrap: anywhere; }
.hist-list button .pill { justify-self: start; color: var(--accent); }
.hist-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.hist-tags:empty { display: none; }
.hist-list button .pill.print { color: var(--ink-2); }
.hist-list button.active { border-color: var(--accent); background: var(--accent-soft); }
.hist-view h4 { margin-top: 0; }
.hist-text { white-space: pre-wrap; font: inherit; font-size: 13px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; max-height: 40vh; overflow: auto; }
@media (max-width: 640px) { .hist-body { grid-template-columns: 1fr; } .hist-list { max-height: 30vh; } }
.dlg-head, .dlg-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; }
.dlg-head { border-bottom: 1px solid var(--line); }
.dlg-head h3 { margin: 0; font-size: 16px; flex: 1; }
.dlg-foot { border-top: 1px solid var(--line); justify-content: flex-end; }
.dlg-foot .spacer { flex: 1; }
/* import-from-PDF review */
.pdf-dlg .dlg-head h3 small { display: block; font-size: 12px; font-weight: 400; color: var(--ink-3); overflow-wrap: anywhere; }
.pdf-dlg .facts { font-size: 13px; }
.pdf-notes { margin: 8px 0 0; padding: 8px 12px 8px 28px; background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 8px; font-size: 13px; }
.pdf-tl { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.pdf-tl li { border-left: 4px solid var(--c); padding: 2px 0 2px 10px; }
.pdf-tl .tag { font-size: 12px; font-weight: 600; color: var(--c); }
.pdf-raw { margin-top: 16px; }
.pdf-raw summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.pdf-raw pre {
  margin: 8px 0 0; max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-family: inherit; font-size: 12px; line-height: 1.5;
}
.bp { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4px; }
.bp b { color: var(--ink-3); }

/* autocomplete dropdown */
.ac-wrap { position: relative; }
.ac {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 20; margin: 4px 0 0; padding: 4px;
  list-style: none; max-height: 260px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 28px rgba(15, 23, 42, .18);
}
.ac li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 8px; border-radius: 6px; cursor: pointer; color: var(--ink); font-size: 14px; }
.ac li small { color: var(--ink-3); font-size: 12px; white-space: nowrap; text-align: right; }
.ac li:hover, .ac li.hi { background: var(--accent-soft); }
.ac li[data-t="รพ.เอกชน"] small { color: #9333ea; }

/* read mode: fields keep their outline but can't be changed, editing controls hidden */
.readonly .edit-only, dialog.readonly .edit-only { display: none !important; }
.readonly .ev .drag { visibility: hidden; }
.readonly .ev [data-act="del"] { display: none; }
.readonly input:disabled, .readonly select:disabled, .readonly textarea:disabled,
dialog.readonly input:disabled, dialog.readonly select:disabled, dialog.readonly textarea:disabled {
  background: transparent; border-color: var(--line); color: var(--ink); opacity: 1;
  -webkit-text-fill-color: var(--ink); appearance: none; -webkit-appearance: none; resize: none; cursor: default;
}
.readonly input:disabled::placeholder, .readonly textarea:disabled::placeholder,
dialog.readonly input:disabled::placeholder, dialog.readonly textarea:disabled::placeholder { color: transparent; -webkit-text-fill-color: transparent; }
.readonly input.is-empty:disabled, .readonly select.is-empty:disabled { -webkit-text-fill-color: var(--ink-3); color: var(--ink-3); }
.readonly .dfield .dpick { display: none; }
.readonly .dfield input.dtext:disabled { padding-right: 9px; }
.readonly #caseForm input:disabled, .readonly #caseForm select:disabled { font-weight: 600; }
.readonly .sym[aria-pressed="false"] { opacity: .45; }
.readonly .ev select:disabled { font-weight: 700; color: var(--c); -webkit-text-fill-color: var(--c); }
.dlg-body { padding: 8px 18px 16px; max-height: 70vh; overflow: auto; }
.dlg-body h4 { margin: 16px 0 8px; font-size: 14px; color: var(--accent); }
.preview { margin-top: 16px; background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; }
.preview span { font-size: 12px; font-weight: 700; color: var(--ink-3); }
.preview p { margin: 4px 0 0; }

/* ---------- report ---------- */
.report-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.report {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 32px; max-width: 980px; box-shadow: var(--shadow);
}
.report h1 { font-size: 20px; margin: 0 0 8px; }
.report h2 { font-size: 16px; margin: 22px 0 10px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.report .lead { margin: 0 0 14px; font-size: 16px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 18px; margin: 0; font-size: 14px; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; font-weight: 500; }
.tl { list-style: none; margin: 14px 0 0; padding: 0; }
.tl li { position: relative; padding: 0 0 12px 22px; border-left: 2px solid var(--line); margin-left: 6px; break-inside: avoid; }
.tl li::before {
  content: ""; position: absolute; left: -7px; top: 5px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--c); border: 2px solid var(--surface);
}
.tl li:last-child { border-left-color: transparent; }
.tl-when { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tl .day { font-size: 12px; font-weight: 700; color: var(--ink-2); background: var(--line-2); border-radius: 4px; padding: 0 6px; }
.tl .tag { font-size: 12px; color: var(--c); font-weight: 600; }
.tl p { margin: 2px 0 0; font-size: .9em; line-height: 1.5; }   /* event text a step below the date line, on screen and in print */
.report h3 { font-size: 14px; margin: 16px 0 6px; }
.report .src { font-size: 12px; color: var(--ink-3); }
.cl-sum-wrap { overflow-x: auto; }
.cl-sum { width: 100%; border-collapse: collapse; font-size: 13px; }
.cl-sum th, .cl-sum td { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; text-align: left; }
.cl-sum thead th { background: var(--accent-soft); font-weight: 700; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.cl-sum tbody th { width: 24%; font-weight: 400; }
.cl-sum tbody th b { display: block; }
.cl-sum tbody th small { display: block; color: var(--ink-3); font-size: 12px; line-height: 1.4; }
.cl-sum td:nth-child(3) { width: 20%; }
.cl-sum td:nth-child(4) { width: 18%; }
.cl-sum tr { break-inside: avoid; }
.sign { margin: 32px 48px 0 auto; width: max-content; max-width: 100%; text-align: center; font-size: 14px; break-inside: avoid; }
.sign p { margin: 4px 0; }
.cl-author { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-top: 12px; border-top: 1px dashed var(--line-2); }
.cl-author .hint { grid-column: 1 / -1; margin: 0; }
@media (max-width: 640px) { .cl-author { grid-template-columns: 1fr; } }
.printed { margin-top: 20px; font-size: 12px; color: var(--ink-3); text-align: right; }

/* ---------- checklist tab ---------- */
.cl-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.cl-table { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.cl-row { display: grid; grid-template-columns: 110px 200px minmax(0, 1fr) 230px 170px; border-top: 1px solid var(--line); }
.cl-row.cont { border-top-style: dashed; border-top-color: var(--line-2); }
.cl-row > div { padding: 10px 12px; min-width: 0; }
.cl-row > div + div { border-left: 1px solid var(--line-2); }
.cl-head { border-top: 0; background: var(--accent-soft); font-weight: 700; font-size: 13px; }
.cl-topic { font-weight: 700; }
.cl-issue { font-size: 13px; color: var(--ink-2); background: var(--surface-2); }
.cl-list { margin: 0; padding-left: 16px; }
.cl-list li + li { margin-top: 2px; }
.cl-detail { display: grid; gap: 8px; align-content: start; }
.cl-detail textarea, .cl-note textarea { resize: vertical; font-size: 14px; }
.cl-note textarea { height: 100%; min-height: 72px; }
@media (min-width: 1451px) {
  .cl-row > .cl-note, .cl-head > div:last-child, .cl-row > .cl-checkcol, .cl-head > div:nth-child(4) { padding-left: 6px; padding-right: 6px; }
}
.cl-auto { background: var(--accent-soft); border-radius: 7px; padding: 8px 10px; font-size: 14px; line-height: 1.55; }
.cl-tools { display: flex; justify-content: flex-end; }
label.inline { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; font-size: 13px; }
label.inline input { width: auto; }
label.inline input.cl-count { width: 90px; }
/* dd/mm/yyyy (พ.ศ.) date box from js/datefield.js; the real <input type=date> is kept hidden underneath */
.dfield { position: relative; display: block; width: 100%; min-width: 0; }
label.inline .dfield { width: 150px; flex: none; }
.dfield input.dtext { width: 100%; padding-right: 32px; font-variant-numeric: tabular-nums; }
.dfield .dpick {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%); border: 0; background: none;
  padding: 2px 4px; font-size: 14px; line-height: 1; cursor: pointer; opacity: .7;
}
.dfield .dpick:hover { opacity: 1; }
.dfield .dpick:disabled { display: none; }
.dfield input[type=date] {
  position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; padding: 0; border: 0;
  opacity: 0; pointer-events: none;
}
/* calendar popup from the 📅 button (พ.ศ. years) */
.dcal {
  position: fixed; z-index: 1000; width: 288px; padding: 10px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(15, 23, 42, .18); font-size: 14px;
}
.dcal button { border: 0; background: none; color: inherit; font: inherit; cursor: pointer; border-radius: 6px; }
.dcal-head { display: grid; grid-template-columns: 30px 1fr 84px 30px; gap: 6px; align-items: center; margin-bottom: 8px; }
.dcal-head button { height: 32px; font-size: 20px; line-height: 1; }
.dcal-head button:hover, .dcal-foot button:hover { background: var(--line-2); }
.dcal-head select { width: 100%; padding: 5px 6px; font-size: 14px; }
.dcal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.dcal-grid b { font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 4px 0; }
.dcal-grid button { height: 34px; font-variant-numeric: tabular-nums; }
.dcal-grid button:hover { background: var(--line-2); }
.dcal button:focus-visible { outline: 2px solid var(--sym-on); outline-offset: 1px; }
.dcal button:focus:not(:focus-visible) { outline: none; }
.dcal-grid .sun { color: var(--danger); }
.dcal-grid .today { box-shadow: inset 0 0 0 1px var(--sym-on); font-weight: 700; }
.dcal-grid button.sel { background: var(--sym-on); color: #fff; font-weight: 700; }
.dcal-foot { display: flex; justify-content: space-between; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line-2); }
.dcal-foot button { padding: 5px 10px; font-size: 13px; color: var(--ink-2); }
/* both survey lines share one grid (date | HI | CI | note) so their boxes line up;
   the note column is as wide as the widest note and empty when nothing is over the standard */
.cl-hici { display: grid; grid-template-columns: minmax(0, 124px) minmax(0, 1fr) minmax(0, 1fr) auto; gap: 6px 10px; align-items: center; }
.cl-hici-row { display: contents; }
.cl-over { grid-column: 4; max-width: 8.5em; font-size: 12px; font-weight: 600; line-height: 1.25; color: var(--danger); }
.cl-hici-row .dfield { grid-column: 1; width: 100%; }
.cl-hici-row .dfield input.dtext { padding: 6px 26px 6px 4px; }
.cl-hici-row label.inline { min-width: 0; gap: 4px; }
.cl-hici-row label.inline input { flex: 1 1 auto; width: 0; min-width: 48px; padding: 6px 4px; font-size: 14px; font-variant-numeric: tabular-nums; text-align: right; -moz-appearance: textfield; }
.cl-hici-row input[type=number]::-webkit-inner-spin-button, .cl-hici-row input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.cl-check { display: grid; gap: 4px; font-size: 13px; }
.cl-radio { display: flex; flex-direction: row; align-items: flex-start; gap: 6px; color: var(--ink); font-weight: 400; cursor: pointer; }
.cl-radio input { flex: none; width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); }
/* read mode: no radio dots, the chosen option is ticked and highlighted, the rest dimmed */
.readonly .cl-radio { cursor: default; color: var(--ink-3); }
.readonly .cl-radio input { display: none; }
.readonly .cl-radio span { display: flex; align-items: flex-start; }
.readonly .cl-radio span::before {
  content: ""; display: inline-block; width: 14px; height: 14px; margin: 3px 6px 0 0; flex: none;
  border: 1.5px solid var(--line); border-radius: 4px;
}
.readonly .cl-radio:has(input:checked) { color: var(--ink); font-weight: 700; }
.readonly .cl-radio:has(input:checked) span::before {
  border-color: var(--accent); background: var(--accent) center / 10px no-repeat;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2 6.5l2.5 2.5L10 3.5' fill='none' stroke='white' stroke-width='2'/%3E%3C/svg%3E");
}
.readonly .cl-check .cl-chk-note:disabled { margin-left: 20px; font-weight: 600; color: var(--ink); -webkit-text-fill-color: var(--ink); }
.cl-chk-note { margin: 0 0 4px 22px; width: calc(100% - 22px); font-size: 13px; padding: 4px 8px; }
.cl-mode { margin-bottom: 2px; }
.auto-badge { display: inline-block; font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); border-radius: 99px; padding: 1px 8px; }
.linkbtn { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; text-decoration: underline; }
.cl-tick { font-size: 13px; color: var(--ink-3); }
.cl-tick.on { color: var(--ink); font-weight: 600; }
.cl-dates { display: grid; gap: 6px; justify-items: start; }
.cl-date-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.cl-date-row select { width: auto; }
/* narrower date, so วันที่ดำเนินการ and ครอบคลุมรัศมี 100 เมตร fit on one line */
.cl-date-row label.inline .dfield { width: 128px; }
.cl-date-row .dfield input.dtext { padding: 7px 28px 7px 8px; }
/* two short lines, no taller than the select beside it */
.cl-cov span, .cl-two { font-size: 12px; line-height: 1.25; }
/* ตามกำหนด / เลยกำหนด beside Day 1's วันที่ดำเนินการ (CFG.ctrlTiming) */
.cl-timing { font-style: normal; font-weight: 600; font-size: 12px; border-radius: 99px; padding: 1px 8px; }
.cl-timing:empty { display: none; }
.cl-timing.ok { color: #0b7a70; background: color-mix(in srgb, #14b8a6 18%, transparent); }
.cl-timing.late { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .cl-timing.ok { color: #5eead4; } }
:root[data-theme="dark"] .cl-timing.ok { color: #5eead4; }
.cl-plan { display: grid; gap: 4px; font-size: 13px; padding-top: 4px; }
.cl-plan-opts { display: flex; gap: 14px; align-items: center; }
.cl-plan-opts input[type=text] { flex: 1; }
.cl-next { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; }
.cl-print { display: none; }
.readonly .cl-tools, .readonly .cl-mode .linkbtn { display: none; }
@media (max-width: 1450px) {
  .cl-row { grid-template-columns: 110px minmax(0, 1.4fr) minmax(0, 1fr); }
  .cl-head { display: none; }
  .cl-topic { grid-row: span 2; }
  .cl-issue { grid-column: 2 / -1; }
  .cl-detail { grid-column: 2; }
  .cl-checkcol { grid-column: 3; }
  .cl-note { grid-column: 2 / -1; border-left: 0 !important; }
  .cl-row > div + div { border-left: 1px solid var(--line-2); }
  .cl-detail::before, .cl-checkcol::before, .cl-note::before { display: block; font-size: 11px; font-weight: 700; color: var(--ink-3); margin-bottom: 4px; }
  .cl-detail::before { content: "รายละเอียดการสอบสวนโรค"; }
  .cl-checkcol::before { content: "รายการตรวจสอบ"; }
  .cl-note::before { content: "ข้อสังเกต/ข้อเสนอแนะสำหรับพื้นที่"; }
}

/* ---------- toasts & confirm dialog ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 10px; justify-items: end; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; max-width: min(420px, calc(100vw - 40px));
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 10px; padding: 12px 16px; box-shadow: 0 10px 30px rgba(15, 23, 42, .18);
  opacity: 0; transform: translateY(12px); transition: opacity .25s ease, transform .25s ease;
}
.toast.show { opacity: 1; transform: none; }
.toast.err { border-left-color: #dc2626; }
.toast-ic {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: #fff; background: var(--accent);
}
.toast.err .toast-ic { background: #dc2626; }
dialog.otp-dlg { width: min(420px, calc(100vw - 32px)); padding: 0; border-radius: 16px; }
.otp-msg { font-size: 14px; color: var(--ink-2); line-height: 1.55; }
.otp-box { text-align: center; }
.otp-ts { display: flex; justify-content: center; min-height: 65px; }
.otp-ts[hidden] { display: none; }
.otp-input { width: 100%; max-width: 220px; text-align: center; font-family: ui-monospace, Consolas, monospace; font-size: 28px; letter-spacing: 10px; padding: 8px; }
.otp-timer { margin: 8px 0 0; }
.otp-err { margin: 10px 0 0; color: var(--danger); font-size: 14px; min-height: 1em; }
dialog.confirm { width: min(440px, calc(100vw - 32px)); padding: 0; border-radius: 16px; animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: none; } }
.confirm-body { display: flex; gap: 14px; padding: 22px 22px 12px; }
.confirm-body h3 { margin: 2px 0 6px; font-size: 17px; }
.confirm-body p { margin: 0; color: var(--ink-2); font-size: 14px; line-height: 1.55; white-space: pre-line; }
.confirm-ic {
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  font-size: 20px; font-weight: 700; color: var(--accent); background: var(--accent-soft);
}
.confirm-ic.danger { color: #dc2626; background: color-mix(in srgb, #dc2626 14%, var(--surface)); }
.confirm-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px 18px; }

/* a number field was clamped to its limit (HI/CI 0–100, Neutrophil/Lymphocyte 0–100, Albumin 0–10): shake only, no lasting red border */
@keyframes limit { 0%, 100% { transform: none; } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
input.limit { animation: limit .25s ease 2; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .ev { grid-template-columns: 22px 26px 250px 1fr; }
  .ev-actions { grid-column: 3 / -1; justify-content: flex-end; }
}
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .case-list { max-height: 180px; overflow: auto; }
  main { padding: 16px; }
  .editor-head { margin: -16px -16px 16px; padding: 10px 16px 0; }
  .grid, .grid.g5, .grid.g6, .grid.g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ev { grid-template-columns: 22px 1fr auto; }
  .ev .idx { display: none; }
  .ev-when, .ev textarea { grid-column: 2 / -1; }
  .sym-group { grid-template-columns: 1fr; gap: 6px; }
  .sym-grid { grid-template-columns: 1fr 1fr; }
  .sym-grid .sym:nth-child(n) { grid-column: auto; }
  .ev-actions { grid-column: 2 / -1; grid-row: auto; justify-content: flex-end; }
  .report { padding: 18px 16px; }
}

/* ---------- evidence files ---------- */
.attach.drop { outline: 2px dashed var(--accent); outline-offset: 2px; background: var(--accent-soft); }
.att-add { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.att-empty { margin: 0; }
.att-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.att { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; align-items: start; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--surface-2); }
.att-type { width: 44px; height: 44px; border-radius: 6px; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); }
.att-type.pdf { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.att-body { display: grid; gap: 4px; min-width: 0; }
.att-name { border: 0; background: none; padding: 0; cursor: pointer; text-align: left; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-name { display: block; text-decoration: none; }
span.att-name { cursor: default; color: var(--ink-3); }
a.att-name:hover { color: var(--accent); text-decoration: underline; }
.att-missing { color: var(--danger); font-weight: 600; }
.att-body small { color: var(--ink-3); font-size: 12px; }
.att-body small em { color: var(--danger); font-style: normal; }
.att-meta { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.att-meta select, .att-meta input { font-size: 13px; padding: 5px 7px; }
.att-files { margin: 8px 0 0; padding-left: 18px; font-size: 13px; }

/* ---------- print: always prints the report ---------- */
@media print {
  /* printing outside the app's print buttons (Ctrl+P): only this notice is printed */
  body.print-blocked > * { display: none !important; }
  body.print-blocked::before { content: "กรุณาพิมพ์ผ่านปุ่ม “พิมพ์” ในโปรแกรม"; display: block; padding: 40px; font-size: 18px; }
  :root { --bg: #fff; --surface: #fff; --ink: #000; --ink-2: #222; --ink-3: #555; --line: #bbb; --line-2: #eee; --band: #dbeafe; --band-ink: #1e40af; }
  @page { size: A4; margin: 14mm; }
  body { background: #fff; font-size: 13px; }
  .topbar, .sidebar, .editor-head, .tabs, .case-head, .report-actions, .toasts, #empty, [data-panel]:not([data-panel="report"]), .att-report, .facts .np, .report h1 .np { display: none !important; }
  .layout { display: block; }
  main { padding: 0; }
  [data-panel="report"] { display: block !important; }
  .report { border: 0; box-shadow: none; padding: 0; max-width: none; }
  body.print-checklist [data-panel="report"] { display: none !important; }
  body.print-checklist [data-panel="checklist"] { display: block !important; }
  body.print-checklist [data-panel="checklist"] > :not(#checklistPrint) { display: none !important; }
  body.print-checklist .cl-print { display: block; page: checklist; font-size: 11px; }
  @page checklist { size: A4 landscape; margin: 10mm; }
  .cl-print h1 { font-size: 15px; margin: 0 0 4px; }
  .cl-print h2 { font-size: 13px; margin: 12px 0 4px; }
  /* ผลการดำเนินงาน in the report: body 1px smaller than the header row */
  .cl-sum tbody th, .cl-sum td { font-size: 12px; }
  .cl-sum tbody th small { font-size: 11px; }
  /* สิ่งที่จะดำเนินการต่อไป moves to the next page rather than split */
  .keep { break-inside: avoid; }
  .cl-print table { width: 100%; border-collapse: collapse; }
  .cl-print th, .cl-print td { border: 1px solid #888; padding: 4px 6px; vertical-align: top; text-align: left; }
  .cl-print th { background: #eef4f3; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .cl-print td:nth-child(1) { width: 11%; font-weight: 700; }
  .cl-print td:nth-child(2) { width: 22%; }
  .cl-print td:nth-child(4) { width: 20%; }
  .cl-print td:nth-child(5) { width: 15%; }
  .cl-print tr { break-inside: avoid; }
  .cl-print .src { font-size: 10px; color: #555; }
  .tl li::before, .strip circle, .legend i { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .strip rect { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- rights (lib/access.js): the case page knows the role after the first load (data-role on <html>) ---------- */
/* until then, and for viewers, nothing that edits is shown; delete is for the disease's admins only */
:root:not([data-role="editor"]):not([data-role="admin"]) .need-editor { display: none !important; }
:root:not([data-role="admin"]) .need-admin { display: none !important; }
.disease-card.no-access { opacity: .5; pointer-events: none; }
.disease-card.no-access span::after { content: ' · ไม่มีสิทธิ์'; }
.admin-link { align-self: center; font-size: 13px; color: var(--ink-3); text-decoration: none; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; }
.admin-link:hover { color: #c2410c; border-color: #c2410c; }
.admin-link[hidden] { display: none; }

/* ---------- admin.html ---------- */
.admin { max-width: 1400px; margin: 0 auto; padding: 16px 16px 40px; }
.ad-msg { margin: 0 0 12px; padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); border: 1px solid var(--accent); }
.ad-msg.bad { background: var(--warn-bg); border-color: var(--danger); color: var(--danger); }
.ad-lock { max-width: 460px; margin: 48px auto; padding: 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.ad-lock h1 { font-size: 20px; margin: 0 0 8px; }
.ad-lock p { color: var(--ink-2); margin: 0 0 16px; }
.ad-lock-f { display: flex; gap: 8px; }
.ad-lock-f input { flex: 1; font-size: 22px; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.ad-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 8px; }
.ad-tabs { flex-wrap: wrap; }
.ad-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 0 var(--radius) var(--radius) var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.ad-panel > .hint { margin: 0 0 10px; }
.ad-add { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.ad-add input { flex: 1 1 200px; min-width: 0; }
.ad-add select { flex: 0 1 auto; }
.ad-search { width: 100%; max-width: 360px; margin-bottom: 10px; }
.ad-tw { overflow-x: auto; }
.ad-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.ad-table th { text-align: left; font-weight: 600; color: var(--ink-2); padding: 8px; border-bottom: 2px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
.ad-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.ad-table td.c, .ad-table th.c { text-align: center; }
.ad-table td b, .ad-table td small { display: block; }
.ad-table td small { color: var(--ink-3); font-size: 12px; }
.ad-table td input:not([type="checkbox"]) { width: 100%; min-width: 140px; margin-top: 2px; padding: 3px 6px; font-size: 13px; }
.ad-table td select { max-width: 220px; padding: 3px 6px; font-size: 13px; }
.ad-table tr.off td:first-child b { text-decoration: line-through; color: var(--ink-3); }
.ad-table tr.bad td, .ad-table td.bad, .ad-table .bad { color: var(--danger); }
.ad-table code { font-size: 11.5px; color: var(--ink-3); overflow-wrap: anywhere; }
.ad-policy td:first-child { width: 45%; }
#policy h3 { margin: 18px 0 2px; font-size: 16px; }
#policy h3:first-child { margin-top: 0; }
.ad-hi { color: var(--warn-ink); font-weight: 700; }
.warn-t { color: var(--warn-ink); }
