/* Data-entry screens. (The printed form uses annex-e.css and never changes.) */
:root {
  --ink: #0f172a; --ink-2: #334155; --muted: #64748b; --line: #e2e8f0; --line-2: #cbd5e1;
  --bg: #f5f7fa; --card: #fff; --soft: #f8fafc; --ro: #f1f5f9;
  --primary: #0f766e; --primary-hover: #0d5f59; --primary-soft: #e6f4f2;
  --warn: #b45309; --danger: #b91c1c; --focus: #2563eb; --focus-soft: #eff6ff;
  --radius: 10px; --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .04);
}
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 14px; }
body { margin: 0; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; font-weight: 650; letter-spacing: -.01em; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; font-weight: 650; margin: 0 0 .6rem; }
h3 { font-size: .95rem; font-weight: 600; margin: .3rem 0; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.strong { font-weight: 600; }

.dev-banner { background: #b91c1c; color: #fff; text-align: center; font-size: .85rem; font-weight: 600; padding: .3rem 1rem; }

/* ── Top bar ──────────────────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center;
  gap: .4rem 1.5rem; padding: .55rem 1.5rem; }
.brand { font-weight: 700; color: var(--ink); letter-spacing: -.01em; display: flex; align-items: center; gap: .5rem; }
.brand::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--primary); }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; flex-wrap: wrap; gap: .15rem; flex: 1; }
.topbar nav a { color: var(--ink-2); padding: .3rem .65rem; border-radius: 7px; font-weight: 500; }
.topbar nav a:hover { background: var(--soft); text-decoration: none; }
.topbar nav a.active { background: var(--primary-soft); color: var(--primary); }
.who { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.who a { color: var(--ink); font-weight: 600; }
.who form { margin: 0; }
.subnav { background: var(--card); border-bottom: 1px solid var(--line); padding: .4rem 1.5rem;
  display: flex; flex-wrap: wrap; gap: .15rem; font-size: .9rem; }
.subnav a { color: var(--ink-2); padding: .25rem .6rem; border-radius: 6px; }
.subnav a:hover { background: var(--soft); text-decoration: none; }
.subnav a.active { background: var(--primary-soft); color: var(--primary); }

main { max-width: 1080px; margin: 0 auto; padding: 1.4rem 1.25rem 6rem; }
main.narrow { max-width: 420px; padding-top: 3rem; }

/* ── Building blocks ──────────────────────────────────── */
.card, .queue { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: .75rem; }
.stack label, .field label, .field .label { display: flex; flex-direction: column; gap: .3rem; font-weight: 500;
  font-size: .9rem; color: var(--ink-2); }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }

input[type=text], input[type=search], input[type=password], input[type=date], input[type=number],
input:not([type]), input[type=file], select, textarea {
  font: inherit; color: inherit; width: 100%; padding: .45rem .65rem; border: 1px solid var(--line-2);
  border-radius: 7px; background: #fff; min-height: 2.25rem; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
button:focus-visible, a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
input:disabled, select:disabled, textarea:disabled { background: var(--ro); color: var(--ink-2); }
input[type=checkbox] { width: 1.05rem; height: 1.05rem; min-height: 0; margin: 0; accent-color: var(--primary); }
fieldset { border: none; padding: 0; margin: 0; }
legend { padding: 0; margin-bottom: .3rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; font: inherit;
  font-weight: 500; font-size: .93rem; padding: .42rem .9rem; border-radius: 8px; border: 1px solid var(--line-2);
  background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--soft); border-color: #94a3b8; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-warn { background: #fff7ed; border-color: #fdba74; color: var(--warn); }
.btn-warn:hover { background: #ffedd5; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-small { padding: .2rem .55rem; font-size: .85rem; border-radius: 6px; }
.btn-big { padding: .55rem 1.1rem; }
.who .btn { padding: .25rem .65rem; font-size: .85rem; }

.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; font-size: .93rem; }
.flash-ok { background: #f0fdf4; border-color: #bbf7d0; color: #14532d; }
.flash-info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: #7f1d1d; }
.callout { background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: .7rem .9rem; margin-bottom: 1rem; font-size: .93rem; }
.callout-info { background: #eff6ff; border-color: #bfdbfe; }
.callout ul { margin: .3rem 0; padding-left: 1.2rem; }

.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .12rem .5rem; border-radius: 99px;
  vertical-align: middle; letter-spacing: .01em; }
.badge-needs_doctor { background: #fef3c7; color: #92400e; }
.badge-done { background: #dcfce7; color: #166534; }
.badge-sample { background: #ede9fe; color: #5b21b6; }
.badge-returned { background: #fee2e2; color: #991b1b; }
.badge-deleted { background: #334155; color: #fff; }
.count { display: inline-block; min-width: 1.5rem; text-align: center; background: var(--soft); color: var(--ink-2);
  border: 1px solid var(--line); border-radius: 99px; font-size: .78rem; font-weight: 600; padding: 0 .45rem;
  margin-left: .35rem; vertical-align: middle; }

/* ── Home, search, lists ──────────────────────────────── */
.searchbar { display: flex; gap: .5rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.searchbar input { flex: 1; min-width: 12rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters label { display: flex; flex-direction: column; font-weight: 500; font-size: .85rem; color: var(--ink-2); gap: .25rem; }
.filters input, .filters select { width: auto; }
.inline-form { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; margin-top: .5rem; }
.inline-form label { display: flex; flex-direction: column; font-weight: 500; font-size: .85rem; color: var(--ink-2); gap: .25rem; }
.inline-form input { width: auto; }
.queue h2 { display: flex; align-items: center; }
.queue > p.muted { margin: -.35rem 0 .6rem; font-size: .9rem; }
.empty { color: var(--muted); margin: .3rem 0; font-size: .93rem; }
table.list { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.list th, table.list td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list thead th { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.list tbody tr:last-child td { border-bottom: none; }
table.list tbody tr:hover td { background: var(--soft); }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn { margin-left: .25rem; }
.pager { display: flex; gap: 1rem; align-items: center; margin-top: 1rem; }
.history td { vertical-align: top; }
.history .old { color: #991b1b; text-decoration: line-through; text-decoration-color: rgba(153, 27, 27, .4); }
.history .new { color: #166534; }

/* ── Record: header and the form-shaped sheet ─────────── */
.record-head, .sheet, .sheet-width { max-width: 880px; margin-left: auto; margin-right: auto; }
.record-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.record-head h1 { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.head-actions { display: flex; gap: .4rem; }
.record-form > .callout { max-width: 880px; margin-left: auto; margin-right: auto; }

.sheet-page { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  padding: 1.4rem 1.75rem 1.6rem; margin-bottom: 1rem; }
.sheet-title { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding-bottom: .75rem; margin-bottom: .4rem; border-bottom: 1px solid var(--line); }
.sheet-title strong { font-weight: 650; }
.sheet-title span { color: var(--muted); margin-left: .5rem; font-size: .9rem; }
.sheet-title .page-no { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.sheet-section { display: flex; align-items: baseline; gap: .75rem; margin: 1.15rem 0 .45rem; }
.sheet-section h2 { font-size: .98rem; margin: 0; }
.lock { font-size: .78rem; color: var(--muted); background: var(--ro); border-radius: 99px; padding: .08rem .55rem; }

.sheet-table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed;
  border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.sheet-table > tr > *, .sheet-table > tbody > tr > *, .sheet-table > thead > tr > * {
  border-bottom: 1px solid var(--line); }
.sheet-table > tr:last-child > *, .sheet-table > tbody > tr:last-child > * { border-bottom: none; }
.sheet-table > tbody > tr > th[scope=row] { width: 35%; text-align: left; font-weight: 500; font-size: .9rem; color: var(--ink-2);
  background: var(--soft); padding: .45rem .75rem; border-right: 1px solid var(--line); vertical-align: middle; }
.sheet-table th label { cursor: pointer; }
.sheet-table td { padding: 0; vertical-align: middle; }
.sheet-table td + td { border-left: 1px solid var(--line); }

/* inputs sit flush inside the cells, like writing on the form */
.sheet-table input[type=text], .sheet-table input[type=date], .sheet-table select {
  border: none; border-radius: 0; background: transparent; min-height: 2.3rem; padding: .4rem .75rem; }
.sheet-table input[type=text]:focus, .sheet-table input[type=date]:focus, .sheet-table select:focus {
  box-shadow: inset 0 0 0 2px var(--focus); background: var(--focus-soft); }
.sheet-table input:disabled, .sheet-table select:disabled { background: transparent; color: var(--ink-2); -webkit-text-fill-color: var(--ink-2); opacity: 1; }
.sheet-table tr.ro td, .sheet-table.ro-all td { background: var(--ro); }
.sheet-table input::placeholder { color: #94a3b8; }

.age-sex { display: flex; align-items: center; }
.age-sex .age { display: flex; align-items: baseline; gap: .4rem; padding: 0 .75rem; min-width: 9rem;
  border-right: 1px solid var(--line); align-self: stretch; align-items: center; }
.age-sex .age small { color: var(--muted); font-size: .78rem; }
.age-sex select { flex: 1; }
td.referred { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem 1rem; padding: .45rem .75rem; }
td.referred .check { display: inline-flex; align-items: center; gap: .4rem; font-size: .93rem; }
td.referred .check-text { width: 11rem; }
td.referred .check-text input { border: none; border-bottom: 1px solid var(--line-2); min-height: 1.9rem; padding: .2rem .3rem; }
td.stacked input + input { border-top: 1px solid var(--line); }

td.nest { padding: 0; }
.inner-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.inner-table th, .inner-table td { border-bottom: 1px solid var(--line); }
.inner-table tbody tr:last-child > * { border-bottom: none; }
.inner-table td, .inner-table thead th + th { border-left: 1px solid var(--line); }
.inner-table thead th { font-size: .78rem; font-weight: 500; color: var(--muted); padding: .28rem .4rem; text-align: center;
  background: var(--soft); }
.inner-table thead th:first-child { width: 24%; }
.inner-table th[scope=row] { font-size: .85rem; font-weight: 500; color: var(--ink-2); text-align: left; padding: .3rem .6rem;
  background: #fff; }
.inner-table input[type=text] { text-align: center; padding: .35rem .3rem; min-height: 2.1rem; }
tr.ro .inner-table th[scope=row] { background: transparent; }

.sheet-table.single td, .sheet-table.grid-2 td { padding: 0; }
.sheet-table.followup col.fu-label { width: 28%; }
.sheet-table.followup thead th { font-size: .8rem; font-weight: 500; color: var(--muted); background: var(--soft);
  padding: .35rem .6rem; text-align: center; }
.sheet-table.followup thead th + th { border-left: 1px solid var(--line); }
.sheet-table.followup > tbody > tr > th[scope=row] { width: auto; font-size: .85rem; }

.accomplished { margin: 1.4rem 0 .6rem; display: flex; flex-direction: column; gap: .2rem; max-width: 22rem; }
.accomplished > label { font-size: .9rem; font-weight: 500; color: var(--ink-2); }
.accomplished .sign-line input { border: none; border-bottom: 1px solid var(--ink-2); border-radius: 0; padding: .35rem .2rem;
  background: transparent; }
.accomplished .sign-line input:focus { box-shadow: none; border-bottom: 2px solid var(--focus); }
.accomplished.ro .sign-line input { background: transparent; }
.accomplished small { color: var(--muted); font-size: .8rem; }

.actionbar { position: sticky; bottom: 0; z-index: 10; margin-top: .5rem; padding: .7rem 0;
  background: linear-gradient(to top, var(--bg) 70%, rgba(245, 247, 250, 0)); }
.actionbar-inner { max-width: 880px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .55rem .6rem;
  box-shadow: 0 4px 16px rgba(15, 23, 42, .08); }
.danger-zone { border-color: #fecaca; }
.danger-zone form { margin-bottom: .8rem; }

/* ── Suggestion lists, account checkboxes, idle warning ─ */
.suggest-list { display: flex; flex-wrap: wrap; gap: .35rem; margin: .4rem 0 .8rem; }
.chip { display: inline-flex; align-items: center; gap: .2rem; background: var(--soft); border: 1px solid var(--line);
  border-radius: 99px; padding: .1rem .15rem .1rem .65rem; font-size: .9rem; }
.chip form { margin: 0; }
.chip button { border: none; background: none; cursor: pointer; font-size: 1rem; color: var(--muted); padding: 0 .35rem; line-height: 1; }
.chip button:hover { color: var(--danger); }
.checks { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1rem; }
.check { flex-direction: row !important; align-items: center; gap: .4rem !important; font-weight: 400 !important; color: var(--ink) !important; }
.idle-warning { position: fixed; inset: 0; background: rgba(15, 23, 42, .4); display: flex; align-items: center;
  justify-content: center; z-index: 100; }
.idle-warning[hidden] { display: none; }
.idle-box { background: #fff; border-radius: 12px; padding: 1.3rem 1.5rem; max-width: 24rem; text-align: center;
  box-shadow: 0 10px 30px rgba(15, 23, 42, .2); }

/* ── Narrow screens (phones) ──────────────────────────── */
@media (max-width: 700px) {
  main { padding: 1rem .75rem 6rem; }
  .topbar { padding: .5rem .75rem; }
  .sheet-page { padding: 1rem .9rem 1.1rem; border-radius: 10px; }
  .sheet-table > tbody > tr > th[scope=row] { width: 40%; }
  .sheet-table.followup col.fu-label { width: 34%; }
  td.referred .check-text { width: 100%; }
  .age-sex .age { min-width: 6.5rem; }
  .inner-table thead th:first-child { width: 28%; }
  .inner-table th[scope=row] { padding: .3rem .35rem; }
  table.list thead { display: none; }
  table.list td { display: block; border: none; padding: .1rem .3rem; }
  table.list tr { display: block; border-bottom: 1px solid var(--line); padding: .45rem 0; }
  td.actions { text-align: left; }
}
@media (max-width: 480px) {
  .sheet-table:not(.followup):not(.grid-2) > tbody > tr > th[scope=row],
  .sheet-table:not(.followup):not(.grid-2) > tbody > tr > td { display: block; width: 100%; }
  .sheet-table:not(.followup):not(.grid-2) > tbody > tr > th[scope=row] { border-right: none; border-bottom: none; padding-bottom: .1rem; }
}
@media print {
  .topbar, .subnav, .actionbar, .dev-banner, .head-actions { display: none !important; }
}
