:root{
  --bg:#F2F5F4;--surface:#FFFFFF;--surface-2:#EAF0EE;--fg:#13201D;--muted:#56635F;--line:#D8E1DE;
  --accent:#0B6E66;--accent-hover:#085851;--accent-ink:#FFFFFF;--accent-soft:#DFEFEB;
  --ok:#1A7349;--ok-soft:#E0F1E7;--warn:#935300;--warn-soft:#FAEAD2;--bad:#B42318;--bad-soft:#F8E2DF;
  --holiday:#73398A;--holiday-soft:#F0E4F4;
  --side-bg:#0E2B28;--side-fg:#F1F7F5;--side-muted:#A6BDB8;--side-active:#1C514B;--side-line:#24433F;
  --shadow:0 1px 2px rgba(16,40,36,.06),0 4px 16px rgba(16,40,36,.05);
  --th-size:.8rem;                      /* table column headings and group heading rows share this size */
  --r-sm:7px;--r-md:11px;--r-lg:14px;
}
@media (prefers-color-scheme:dark){:root{
  --bg:#0E1615;--surface:#15201E;--surface-2:#1B2926;--fg:#E3ECE9;--muted:#9DADA8;--line:#2A3B38;
  --accent:#55BDAE;--accent-hover:#74CDBF;--accent-ink:#04201C;--accent-soft:#173A35;
  --ok:#6FC898;--ok-soft:#173326;--warn:#E6AC5E;--warn-soft:#382813;--bad:#F4877B;--bad-soft:#3C1E1B;
  --holiday:#CFA2E0;--holiday-soft:#31223A;
  --side-bg:#0A1211;--side-fg:#E3ECE9;--side-muted:#8FA29D;--side-active:#183A36;--side-line:#1D2F2C;--shadow:none;
}}
*{box-sizing:border-box}
a,button,.pill,.checkcard,tr.clickrow{-webkit-tap-highlight-color:transparent}
html,body{margin:0}
body{background:var(--bg);color:var(--fg);font:14.5px/1.55 "IBM Plex Sans Thai","Noto Sans Thai","Leelawadee UI",Tahoma,system-ui,sans-serif}
h1{font-size:1.65rem;font-weight:700;margin:.15rem 0 .4rem;line-height:1.25}
h2{font-size:1.08rem;font-weight:700;margin:0}
h3{font-size:.95rem;font-weight:600;margin:0}
.eyebrow{font-size:.78rem;font-weight:600;letter-spacing:.06em;color:var(--muted)}
.muted{color:var(--muted)}
.mono{font-variant-numeric:tabular-nums}
svg.i{width:18px;height:18px;stroke:currentColor;fill:none;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;flex:none}
:focus-visible{outline:3px solid var(--accent);outline-offset:2px}

/* layout */
.shell{display:flex;flex-wrap:wrap;min-height:100vh}
.side{flex:1 1 236px;max-width:236px;background:var(--side-bg);color:var(--side-fg);display:flex;flex-direction:column;padding:18px 12px;position:sticky;top:0;height:100vh}
.main{flex:999 1 560px;min-width:0;padding:30px clamp(16px,3.5vw,44px) 60px}
.brand{display:flex;gap:10px;align-items:center;padding:4px 8px 18px}
.brand .logo{width:36px;height:36px;border-radius:10px;background:var(--side-active);display:grid;place-items:center}
.brand b{display:block;font-size:1rem}.brand small{color:var(--side-muted);font-size:.78rem}
.nav{display:flex;flex-direction:column;gap:4px}
.nav a{display:flex;align-items:center;gap:10px;padding:9px 12px;border-radius:9px;color:var(--side-fg);text-decoration:none;font-weight:500;min-height:40px}
@media (hover:hover){.nav a:hover{background:var(--side-line)}}
.nav a[aria-current=page]{background:var(--side-active);font-weight:600}
.nav a .lock{margin-left:auto;color:var(--side-muted)}
.side .who{margin-top:auto;border-top:1px solid var(--side-line);padding:14px 8px 0;font-size:.82rem;color:var(--side-muted)}
.side .who b{display:block;color:var(--side-fg);font-size:.95rem}
.side .who button{margin-top:10px}
@media (max-width:860px){
  .shell{display:block}
  .side{max-width:none;height:auto;position:static;padding:10px 12px;flex-direction:column}
  .brand{padding-bottom:8px}
  .nav{flex-direction:row;overflow-x:auto;padding-bottom:4px}
  .nav a{white-space:nowrap}
  .side .who{margin-top:8px;border-top:0;padding:6px 8px 0;display:flex;gap:10px;align-items:center;flex-wrap:wrap}
  .side .who button{margin:0 0 0 auto}
}

/* cards, forms, buttons */
.card{background:var(--surface);border:1px solid var(--line);border-radius:var(--r-lg);padding:20px;box-shadow:var(--shadow);margin-bottom:22px}
.card-head{display:flex;justify-content:space-between;align-items:center;gap:12px;flex-wrap:wrap;margin-bottom:12px}
.btn{white-space:nowrap;font:inherit;font-weight:600;border-radius:9px;border:1px solid transparent;padding:8px 16px;min-height:40px;cursor:pointer;display:inline-flex;align-items:center;gap:8px;background:var(--accent);color:var(--accent-ink)}
@media (hover:hover){.btn:hover{background:var(--accent-hover)}}
.btn.ghost{background:transparent;color:var(--fg);border-color:var(--line)}
@media (hover:hover){.btn.ghost:hover{background:var(--surface-2)}}
.btn.danger{background:var(--bad-soft);color:var(--bad);border-color:var(--bad)}
.btn.sm{min-height:34px;padding:4px 12px;font-size:.88rem}
.btn:disabled{opacity:.5;cursor:not-allowed}
label.f,div.f{display:block;font-size:.84rem;font-weight:600;color:var(--muted);margin-bottom:12px}
input[type=text],input[type=password],select{font:inherit;width:100%;min-height:40px;padding:7px 11px;border:1px solid var(--line);border-radius:9px;background:var(--surface);color:var(--fg);margin-top:4px}
select.inline{width:auto;margin:0;min-height:36px}
.tabs{display:flex;gap:8px;flex-wrap:wrap;margin:14px 0 22px}
.tab{font:inherit;font-weight:600;padding:8px 16px;border-radius:999px;border:1px solid var(--line);background:var(--surface);color:var(--fg);cursor:pointer;min-height:40px}
.tab[aria-selected=true]{background:var(--accent);color:var(--accent-ink);border-color:var(--accent)}
.chip{display:inline-block;padding:2px 10px;border-radius:999px;font-size:.78rem;font-weight:600;background:var(--surface-2);color:var(--muted)}
.chip.ok{background:var(--ok-soft);color:var(--ok)}.chip.warn{background:var(--warn-soft);color:var(--warn)}
.chip.holiday{background:var(--holiday-soft);color:var(--holiday)}.chip.accent{background:var(--accent-soft);color:var(--accent)}

/* tables */
.tablewrap{overflow-x:auto;position:relative;border:1px solid var(--line);border-radius:var(--r-md)}
table{border-collapse:collapse;width:100%;font-size:.88rem}
th{background:var(--surface-2);font-size:var(--th-size);text-align:left;padding:9px 12px;white-space:nowrap}
td{padding:10px 12px;border-top:1px solid var(--line);vertical-align:middle}
th.c,td.c{text-align:center}
tr.me td{background:var(--accent-soft)}
input[type=checkbox]{width:18px;height:18px;accent-color:var(--accent)}

/* notices */
.lock-note{display:flex;gap:14px;background:var(--surface-2);border:1px solid var(--line);border-radius:var(--r-md);padding:20px;max-width:640px}
.lock-note svg.i{width:28px;height:28px;color:var(--muted)}
.banner{display:flex;gap:12px;align-items:center;flex-wrap:wrap;background:var(--holiday-soft);color:var(--holiday);border:1px solid var(--holiday);border-radius:var(--r-md);padding:10px 14px;margin-bottom:20px;font-weight:600}
.banner .btn{margin-left:auto}
.error{color:var(--bad);font-weight:600;font-size:.92rem}
#toast{position:fixed;left:50%;bottom:24px;transform:translateX(-50%);background:var(--fg);color:var(--bg);padding:10px 18px;border-radius:999px;font-weight:600;opacity:0;pointer-events:none;transition:opacity .2s;z-index:50;max-width:90vw}
#toast.show{opacity:1}
#toast.bad{background:var(--bad);color:#fff}
dialog{border:1px solid var(--line);border-radius:var(--r-lg);background:var(--surface);color:var(--fg);padding:22px;max-width:min(440px,92vw);width:100%}
dialog::backdrop{background:rgba(0,0,0,.45)}
.dlg-actions{display:flex;gap:10px;justify-content:flex-end;align-items:center;flex-wrap:wrap;margin-top:8px}

/* login */
.login{min-height:100vh;min-height:100dvh;display:grid;place-items:center;padding:20px}
.login .card{width:100%;max-width:420px;padding:30px 28px 26px;margin:0}
/* brand block on the light login card (the sidebar/header brand styles are dark and must not leak in, also on phones) */
.login .card .brand{flex-direction:column;text-align:center;gap:10px;padding:2px 0 22px;margin:0;background:none;color:var(--fg)}
.login .card .brand .logo{width:58px;height:58px;border-radius:17px;background:var(--accent);color:var(--accent-ink)}
.login .card .brand .logo svg{width:28px;height:28px}
.login .card .brand b{font-size:1.3rem}
.login .card .brand small{color:var(--muted);font-size:.88rem}
.login .card form .btn[type=submit]{min-width:128px}
@media (max-width:520px){
  .login{padding:16px;align-content:start;padding-top:12vh}
  .login .card{padding:26px 20px 22px}
  .login .card form .dlg-actions{flex-direction:column-reverse;align-items:stretch;gap:10px}
  .login .card form .btn[type=submit]{width:100%;min-height:46px;justify-content:center}
  .login .card form .error{text-align:center}
}

/* role matrix */
.perm-group td{background:var(--surface-2);font-weight:700;font-size:var(--th-size)}
/* role matrix: the permission names (first column) stay put while the role columns slide; group headings stay pinned too */
table.matrix th:first-child,table.matrix td:first-child{position:sticky;left:0;z-index:1;background:var(--surface);min-width:132px;max-width:170px;white-space:normal;box-shadow:2px 0 0 var(--line)}
table.matrix thead th:first-child{background:var(--surface-2);z-index:3}
table.matrix tr.perm-group td{position:static;box-shadow:none;background:var(--surface-2);min-width:0;max-width:none;overflow:visible}
table.matrix .gtext{position:sticky;left:12px;display:inline-block;white-space:nowrap}
.addrole{display:flex;gap:8px;align-items:center;flex-wrap:wrap;min-width:0;max-width:100%}
.addrole input{flex:1 1 180px;min-width:0;width:auto !important}
.addrole .btn{flex:none}
/* group heading rows in the Master staff list: same size as the column headings and pinned to the left while the table slides sideways */
.grouprow td{position:static !important;overflow:visible !important;font-size:var(--th-size)}      /* same size as the column headings (th) */
.grouprow .gtext{position:sticky;left:12px;display:inline-block;white-space:nowrap}
.role-head{display:flex;flex-direction:column;gap:6px;align-items:center;min-width:120px}
.role-head .row{display:flex;gap:4px}

/* master data */
.pillbox{display:flex;gap:8px;flex-wrap:wrap;margin-top:6px;font-weight:400}
.pill{font:inherit;touch-action:manipulation;font-weight:500;padding:6px 14px;border-radius:999px;border:1px solid var(--line);background:var(--surface);color:var(--fg);cursor:pointer;min-height:36px}
.pill[aria-pressed=true]{background:var(--accent-soft);border-color:var(--accent);color:var(--accent);font-weight:600}
.fgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:0 12px}
button.x{all:unset;cursor:pointer;width:22px;height:22px;display:grid;place-items:center;border-radius:50%;font-weight:700}
@media (hover:hover){button.x:hover{background:var(--surface)}}button.x:focus-visible{outline:3px solid var(--accent)}
td.mono,td .chip{white-space:nowrap}

/* daily records */
.byline{margin-top:12px;font-size:.84rem;color:var(--muted)}.byline b{color:var(--fg)}
.tabcount{margin-left:8px;font-size:.78rem;opacity:.85}
.checkgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:8px}
.checkcard{display:flex;align-items:center;gap:10px;padding:9px 12px;border:1px solid var(--line);border-radius:9px;background:var(--surface);cursor:pointer;min-height:42px}
.checkcard.on{background:var(--accent-soft);border-color:var(--accent)}
.fgrid.wide{grid-template-columns:repeat(auto-fill,minmax(170px,1fr))}
td.num,th.num{text-align:right}.roundrow td{background:var(--surface-2);font-weight:700;font-size:.8rem}
.split{display:grid;grid-template-columns:minmax(0,5fr) minmax(0,6fr);gap:22px;align-items:start}
@media (max-width:980px){.split{grid-template-columns:minmax(0,1fr)}}
textarea{font:inherit;width:100%;padding:8px 11px;border:1px solid var(--line);border-radius:9px;background:var(--surface);color:var(--fg);margin-top:4px}
input[type=date],input[type=month]{font:inherit;min-height:40px;padding:6px 10px;border:1px solid var(--line);border-radius:9px;background:var(--surface);color:var(--fg)}
fieldset:disabled .pill{cursor:not-allowed;opacity:.6}

/* history */
.statgrid{display:grid;grid-template-columns:repeat(auto-fit,minmax(145px,1fr));gap:16px;margin:18px 0 22px}
.statgrid .card{margin:0;padding:16px}
.statnum{font-size:1.9rem;font-weight:600;line-height:1.2;margin:4px 0;word-break:break-word}
tr.clickrow{cursor:pointer}@media (hover:hover){tr.clickrow:hover td{background:var(--accent-soft)}}

/* dashboard */
.unit{font-size:.95rem;font-weight:600;color:var(--muted)}
.chartwrap{width:100%;overflow:hidden}svg.chart{width:100%;height:auto;display:block}
svg.chart .tick{font:11px "IBM Plex Sans Thai","Noto Sans Thai",sans-serif;font-variant-numeric:tabular-nums;fill:var(--muted)}svg.chart .tick.today{fill:var(--fg);font-weight:700}
.legend{display:flex;gap:18px;flex-wrap:wrap;margin-top:8px;font-size:.84rem;color:var(--muted)}
.legend i{display:inline-block;width:10px;height:10px;border-radius:3px;margin-right:6px}
.rightrow{display:grid;grid-template-columns:70px 1fr 90px;gap:12px;align-items:center;margin-bottom:10px;font-size:.9rem}
.rightrow .bar{background:var(--surface-2);height:10px;border-radius:999px;overflow:hidden}.rightrow .bar div{height:100%;background:var(--accent);border-radius:999px}
.rightrow .mono{text-align:right;font-size:.84rem}

.previewbox{background:var(--accent-soft);color:var(--accent);border-radius:var(--r-md);padding:12px 16px;margin-top:6px;line-height:1.8}
.previewbox b{color:var(--fg)}
a.btn{text-decoration:none}

.pwlink{display:block;margin-top:6px;color:var(--side-fg);font-size:.84rem}
pre.json{margin:4px 0 8px;padding:8px 10px;background:var(--surface-2);border-radius:8px;font:12px/1.5 "IBM Plex Sans Thai","Noto Sans Thai",sans-serif;white-space:pre-wrap;word-break:break-word;max-width:420px;max-height:220px;overflow:auto}
details summary{cursor:pointer;color:var(--accent);font-weight:600}
label.f input[type=date],label.f input[type=month]{display:block;margin-top:4px}

/* registry table: roomy single-line rows, slide sideways inside the frame; names / numbers stay pinned on the left */
.tablewrap::-webkit-scrollbar{height:10px}
.tablewrap::-webkit-scrollbar-thumb{background:var(--line);border-radius:999px}
.tablewrap::-webkit-scrollbar-track{background:transparent}
table.registry td,table.registry th{white-space:nowrap}
table.registry th.num,table.registry td.num{text-align:right}
table.registry td.notecell{white-space:normal;min-width:160px;max-width:260px}
table.registry thead th:nth-child(-n+4),table.registry tbody tr:not(.roundrow) td:nth-child(-n+4){position:sticky;z-index:1}
table.registry thead th:nth-child(-n+4){background:var(--surface-2);z-index:2}
table.registry tbody tr:not(.roundrow) td:nth-child(-n+4){background:var(--surface)}
table.registry th:nth-child(1),table.registry td:nth-child(1){left:0;min-width:84px}
table.registry th:nth-child(2),table.registry td:nth-child(2){left:84px;min-width:84px}
table.registry th:nth-child(3),table.registry td:nth-child(3){left:168px;min-width:84px}
table.registry th:nth-child(4),table.registry td:nth-child(4){left:252px;min-width:200px}
table.registry thead th:nth-child(4),table.registry tbody tr:not(.roundrow) td:nth-child(4){box-shadow:2px 0 0 var(--line)}
table.registry .actcol{position:sticky;right:0;z-index:1;box-shadow:-2px 0 0 var(--line)}
table.registry thead th.actcol{background:var(--surface-2);z-index:2}
table.registry tbody tr:not(.roundrow) td.actcol{background:var(--surface)}
.scrollhint{margin-top:8px;font-size:.8rem;color:var(--muted);text-align:right}
@media (max-width:700px){table.registry th:nth-child(4),table.registry td:nth-child(4){min-width:150px}
  table.registry thead th:nth-child(-n+3),table.registry tbody tr:not(.roundrow) td:nth-child(-n+3){position:static}
  table.registry th:nth-child(4),table.registry td:nth-child(4){left:0}}

/* registry data cells: same size as the column headers, regular weight; small action buttons */
table.registry td{font-size:.8rem;font-weight:400}
table.registry td b,table.registry td .mono{font-weight:400}
table.registry .chip{font-size:.72rem;font-weight:500;padding:1px 8px}
.btn.tiny{min-height:26px;padding:1px 9px;font-size:.75rem;font-weight:500;border-radius:6px;gap:4px}

/* every table: one font, one size (same as the header), regular weight for data; small buttons and chips */
td{font-size:.8rem;font-weight:400}
td b,td strong{font-weight:400}
td .btn.btn{font-size:.75rem;font-weight:500;min-height:28px;padding:2px 10px;border-radius:7px}
td .chip{font-size:.72rem;font-weight:500}
td select{font-size:.8rem}

/* round heading rows: bold, and the label stays pinned on the left while the table slides sideways */
table.registry tr.roundrow td{font-weight:700;background:var(--surface-2)}
table.registry tr.roundrow .rtoggle{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;gap:8px;cursor:pointer;font:inherit;font-weight:700;color:var(--fg);padding:6px 8px;margin:-6px -8px;border-radius:8px;min-height:32px}
@media (hover:hover){table.registry tr.roundrow .rtoggle:hover{background:var(--accent-soft)}}
table.registry tr.roundrow .rtoggle:focus-visible{outline:3px solid var(--accent);outline-offset:1px}
.rtoggle .chev{display:inline-block;transition:transform .15s;font-size:1.15rem;line-height:1;transform:rotate(90deg)}
.rtoggle[aria-expanded=false] .chev{transform:rotate(0)}
.rtoggle .rcount{font-weight:400;color:var(--muted);font-size:.78rem}
table.registry tr.roundrow td:first-child{position:sticky;left:0;z-index:1;white-space:nowrap}

.thaidate{display:inline-flex;gap:6px;flex-wrap:wrap}
div.f .thaidate,label.f .thaidate{display:flex;margin-top:4px}
.filtergroup{display:inline-flex;gap:8px;align-items:center;flex-wrap:nowrap;color:var(--muted);font-size:.84rem}
.filtergroup .thaidate{flex-wrap:nowrap}

/* audit log: readable change lines */
td.sumcell{min-width:260px;white-space:normal}
.chgbox{margin-top:6px;padding:6px 10px;background:var(--surface-2);border-radius:8px}
.chg{font-size:.78rem;line-height:1.6;color:var(--fg)}.chglabel{color:var(--muted)}
.chgold{color:var(--muted);text-decoration:line-through;text-decoration-color:var(--line)}
.chg b{font-weight:600}
.badtxt{color:var(--warn);font-weight:600}

/* patient history search */
.suggest{display:flex;flex-direction:column;max-width:420px;margin-top:6px}
.suggestitem{font:inherit;text-align:left;padding:9px 12px;border:0;border-bottom:1px solid var(--line);background:var(--surface);color:var(--fg);cursor:pointer}
@media (hover:hover){.suggestitem:hover{background:var(--accent-soft)}}
.suggestitem:focus-visible{background:var(--accent-soft)}
table.patient-visits td.nw,table.patient-visits td{white-space:nowrap}
table.patient-visits td.notecell{white-space:normal;min-width:160px;max-width:260px}
table.patient-visits th{white-space:nowrap}
table.patient-visits th.num,table.patient-visits td.num{text-align:right}
.statnum.sm{font-size:1.15rem;line-height:1.5;margin:8px 0}

/* ================= phones and tablets ================= */
@media (max-width:860px),(pointer:coarse){
  input[type=text],input[type=password],input[type=date],select,textarea{font-size:16px;min-height:44px}   /* 16px stops iPhones zooming the page when a field is focused */
  select.inline,td select{font-size:16px;min-height:44px}
  .btn{min-height:44px}.btn.sm{min-height:44px;padding:6px 16px}
  td .btn.btn,.btn.tiny{min-height:38px;padding:4px 14px;font-size:.82rem}
  .tab{min-height:44px}.pill{min-height:42px;padding:8px 16px}
  .checkcard{min-height:48px}
  input[type=checkbox]{width:22px;height:22px}
}
@media (max-width:860px){
  /* header: brand, who + sign-out, then a navigation bar that stays pinned while the page scrolls */
  .shell{display:flex;flex-direction:column;flex-wrap:nowrap;min-height:100vh}
  .side{display:contents}
  .brand{order:0;background:var(--side-bg);color:var(--side-fg);margin:0;padding:12px 16px 2px}
  .side .who{order:1;margin:0;border:0;background:var(--side-bg);display:flex;flex-wrap:wrap;gap:2px 12px;align-items:center;padding:2px 16px 8px;font-size:.82rem}
  .side .who>span:first-child{display:none}
  .side .who b{display:inline;font-size:.9rem}
  .side .who .pwlink{display:inline;margin:0}
  .side .who>span:nth-of-type(2){display:none}                       /* the role name: shown on the users page */
  .side .who button{margin:0 0 0 auto;width:44px;min-width:44px;padding:0;justify-content:center}
  .side .who button .lbl{display:none}
  .nav{order:2;position:sticky;top:0;z-index:30;background:var(--side-bg);padding:4px 10px 8px;box-shadow:0 2px 6px rgba(0,0,0,.25);overflow-x:auto;-webkit-overflow-scrolling:touch}
  .nav a{min-height:44px;padding:8px 14px;white-space:nowrap}
  .main{order:3;flex:1;padding:16px 14px 72px}
  h1{font-size:1.45rem}
  dialog{width:calc(100vw - 24px);max-width:none;max-height:calc(100vh - 24px);overflow:auto;padding:16px;margin:auto}
  #toast{bottom:calc(16px + env(safe-area-inset-bottom,0px));max-width:calc(100vw - 32px);text-align:center}
}
@media (max-width:700px){
  /* date / month navigation: selects on one full-width row, the three buttons under them */
  .datenav{display:grid !important;grid-template-columns:1fr 1fr 1fr;gap:8px;width:100%}
  .datenav .thaidate{grid-row:1;grid-column:1/-1;display:grid;grid-template-columns:.7fr 1.35fr 1.35fr;gap:6px;flex-wrap:nowrap}
  .datenav .thaidate select{width:100%;min-width:0}
  .datenav .dn-prev{grid-row:2;grid-column:1}.datenav .dn-today{grid-row:2;grid-column:2}.datenav .dn-next{grid-row:2;grid-column:3}
  .datenav .dn-prev,.datenav .dn-next,.datenav .dn-today{justify-content:center}
  .datenav .dn-prev,.datenav .dn-next{font-size:1.6rem;font-weight:700;line-height:1}
  .monthnav{grid-template-columns:1fr 1fr}
  .monthnav>span{grid-row:1;grid-column:1/-1;display:grid !important;grid-template-columns:1.5fr 1fr;gap:6px}
  .monthnav>span select{width:100%;min-width:0}
  .monthnav .dn-prev{grid-row:2;grid-column:1}.monthnav .dn-next{grid-row:2;grid-column:2}
  .filtergroup{flex-wrap:wrap}
  /* tables slide sideways; their first column (the name / the date) stays in view */
  .tablewrap table:not(.registry):not(.matrix) th:first-child,.tablewrap table:not(.registry):not(.matrix) td:first-child{position:sticky;left:0;z-index:1;background:var(--surface);white-space:nowrap;max-width:50vw;overflow:hidden;text-overflow:ellipsis;box-shadow:1px 0 0 var(--line)}
  .tablewrap table:not(.registry):not(.matrix) th:first-child{background:var(--surface-2);z-index:2}
  .tablewrap table tr.me td:first-child{background:var(--accent-soft)}
  .statgrid{grid-template-columns:repeat(2,minmax(0,1fr));gap:10px}
  .statnum{font-size:1.6rem}
  .card{padding:16px}
}

/* ---- phones: the registry becomes a list of cards (one per patient) instead of a 14-column table ---- */
@media (max-width:700px){
  .registrywrap{border:0;overflow:visible}
  .scrollhint{display:none}
  table.registry,table.registry tbody,table.registry tr,table.registry td{display:block;width:auto}
  table.registry thead{display:none}
  table.registry td,table.registry td.num{position:static !important;box-shadow:none !important;min-width:0 !important;max-width:none !important;padding:0;border:0;background:none !important;text-align:left !important;white-space:normal}
  table.registry tr.roundrow{margin:14px 0 8px;background:none}
  table.registry tr.roundrow td{padding:2px 4px;font-size:.95rem;font-weight:700;background:none !important}
  table.registry tr.roundrow td:nth-child(2){display:none}
  table.registry tr.roundrow .rtoggle{min-height:44px;margin:-8px -8px;padding:8px}
  table.registry tr:not(.roundrow){display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px 10px;background:var(--surface);border:1px solid var(--line);border-radius:12px;padding:12px;margin:0 0 10px}
  table.registry td[data-l]::before{content:attr(data-l);display:block;font-size:.68rem;color:var(--muted);font-family:inherit}
  table.registry td{font-size:.9rem}
  table.registry td:empty{display:none}
  table.registry td.pname{grid-column:1/-1;order:-2;font-size:1.02rem;padding-bottom:4px;border-bottom:1px solid var(--line);margin-bottom:2px}
  table.registry td.pname b{font-weight:600}
  table.registry td.hd{order:-1;font-size:1.05rem;font-weight:500}
  table.registry td[data-l="อายุ"]{order:1}table.registry td[data-l="สิทธิ"]{order:2}table.registry td[data-l="EPO"]{order:3}
  table.registry td[data-l="อาการแทรกซ้อน"]{order:7}table.registry td[data-l="หมายเหตุ"]{order:8}table.registry td[data-l="ผู้ลงทะเบียน"]{order:9}
  table.registry td[data-l="AVF"]{order:4}table.registry td[data-l="SET"]{order:5}table.registry td[data-l="Glucose"]{order:6}
  table.registry td.wide{grid-column:1/-1}
  table.registry td.notecell{max-width:none}
  table.registry td.actcol{order:10}
  table.registry td.actcol>div{justify-content:flex-end}
  table.registry td.muted{font-size:.78rem}
}
@media (max-width:700px){
  .split .tablewrap td:nth-child(2){min-width:150px;white-space:normal}
  #daily-root form.card{scroll-margin-top:72px}                       /* keep the pinned navigation bar from covering the top of the form */
}
[hidden]{display:none!important}

/* guidance text: one quiet hint per section; a coloured callout only where a mistake costs something; longer explanations fold away */
.hint{font-size:.84rem;color:var(--muted);margin:10px 0 0;line-height:1.55}
.hint a{color:var(--accent)}
.callout{font-size:.84rem;line-height:1.55;padding:8px 12px;border-radius:8px;border-left:3px solid var(--warn);background:var(--warn-soft);margin:12px 0 0}
details.help{margin:10px 0 0;font-size:.84rem;color:var(--muted)}
details.help>summary{cursor:pointer;font-weight:600;list-style:none;display:inline-flex;gap:6px;align-items:center;min-height:32px;padding:2px 0}
details.help>summary::-webkit-details-marker{display:none}
details.help>summary::before{content:"›";display:inline-block;transition:transform .15s;font-size:1.1rem;line-height:1}
details.help[open]>summary::before{transform:rotate(90deg)}
details.help>div{margin:2px 0 0;line-height:1.6}
details.help ul{margin:4px 0 0;padding-left:20px}details.help li{margin:3px 0}
.login .hints{margin-top:18px}
.login .hint{text-align:center;margin:0}
.login .hint+.hint{margin-top:4px}

/* blood pressure: two small boxes with a slash between */
.bpbox{display:flex;align-items:center;gap:8px;margin-top:4px}
.bpbox input{margin:0;min-width:0;flex:1}
