:root {
  --ink: #1d2433;
  --muted: #667085;
  --line: #d0d5dd;
  --soft: #f4f6fa;
  --accent: #2f5bd3;
  --accent-soft: #e8eefc;
  --up: #15803d;
  --down: #b42318;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: #eef1f6;
}
h1 { font-size: 20px; margin: 0 0 2px; }
h2 { font-size: 15px; margin: 18px 0 8px; padding-bottom: 4px; border-bottom: 2px solid var(--ink); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand img { width: 44px; height: 44px; object-fit: contain; }
.brand > span { display: flex; flex-direction: column; }
.clinic-banner {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid var(--line);
}
.clinic-banner img { width: 76px; height: 76px; object-fit: contain; }
.clinic-name { font-size: 18px; font-weight: 700; letter-spacing: 0.2px; }
nav { display: flex; flex-wrap: wrap; gap: 4px; }
nav a { padding: 6px 12px; border-radius: 6px; color: var(--ink); text-decoration: none; }
nav a.active, nav a:hover { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }

.actions {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 12px; padding: 10px 12px; background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
button, .button-like {
  font: inherit; padding: 7px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; cursor: pointer; color: var(--ink);
}
label.button-like { display: inline-flex; flex-direction: row; margin: 0; font-size: 14px; color: var(--ink); }
button:hover, .button-like:hover { background: var(--soft); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--down); }
.live { margin-left: auto; font-weight: 600; }

.sheet, .block {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 18px 20px; margin-bottom: 12px;
}
.sheet .block { border: 0; padding: 0; margin: 0; }
.title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.form-meta { font-size: 11px; color: var(--muted); }

.grid-fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 14px; margin-top: 12px; }
.grid-fields .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; margin-top: 6px; }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
input[type=text], input[type=date], input:not([type]), select, textarea {
  font: inherit; color: var(--ink); padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%;
}
textarea { resize: vertical; min-height: 38px; }
.calc { color: var(--ink); font-weight: 600; min-height: 32px; padding: 6px 0; }
.print-line { display: none; }

.scale-key { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 12px; padding: 8px 10px; background: var(--soft); border-radius: 6px; font-size: 12px; }
.note { font-size: 12px; color: var(--muted); margin: -2px 0 8px; font-style: italic; }

table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid var(--line); padding: 6px 8px; vertical-align: top; text-align: left; }
th { background: var(--soft); font-size: 12px; font-weight: 600; }
td.num { text-align: center; font-weight: 700; width: 34px; }
col.c-num { width: 34px; }
col.c-item { width: 40%; }
col.c-score { width: 270px; }
.level-row .pills { flex-wrap: nowrap; }
col.c-link { width: 170px; }
col.c-gas { width: 190px; }
.mtitle { font-weight: 600; }
.observe { font-size: 12px; color: var(--muted); }
.ex { font-size: 12px; margin-top: 3px; padding: 3px 6px; background: var(--accent-soft); border-radius: 4px; }
.domain-total { font-size: 12px; text-align: right; padding: 4px 2px; color: var(--muted); }

.pills { display: flex; flex-wrap: wrap; gap: 4px; }
.pill { display: inline-flex; margin: 0; cursor: pointer; }
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill span {
  min-width: 28px; height: 28px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid #98a2b3; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--ink); background: #fff;
}
.pill:hover span { border-color: var(--accent); }
.pill input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.level-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.mini-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); width: 38px; flex: 0 0 38px; }
.level-row .pill span { min-width: 26px; height: 26px; font-size: 11px; }
.lvl .pill span { border-style: dashed; }
.lvl .pill input:checked + span { background: #fff; color: var(--accent); border: 2px solid var(--accent); }
.adapt { font-size: 12px; color: #b54708; margin-top: 3px; }
.adapt:empty { display: none; }
label.check-label span { display: flex; gap: 6px; align-items: flex-start; color: var(--ink); padding-top: 18px; }
.print-only { display: none; }
input[type=number] { font: inherit; color: var(--ink); padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; width: 100%; }
col.c-tool { width: 24%; }
col.c-std-notes { width: 160px; }
col.c-date { width: 130px; }
col.c-score-in { width: 110px; }
.std-interp { font-weight: 600; }
.band-list { margin-top: 2px; }
table.bank td, table.bank th { font-size: 11px; padding: 4px 5px; }
table.bank td:nth-child(2) { width: 110px; }
.ics td.ics-opt { text-align: center; width: 70px; }
.ics th:not(:first-child) { text-align: center; }
.flags .c-check, th.c-check { width: 34px; text-align: center; }
.flags input[type=checkbox] { width: 18px; height: 18px; }

.summary .bar-col { width: 160px; }
.bar { height: 8px; background: var(--soft); border-radius: 4px; overflow: hidden; margin-top: 3px; }
.bar span { display: block; height: 100%; background: var(--accent); }
.total-row td { font-weight: 700; background: #fafbfc; }
.up { color: var(--up); font-weight: 700; }
.down { color: var(--down); font-weight: 700; }
.records .row-actions { display: flex; gap: 6px; align-items: center; white-space: nowrap; }

.attribution, .disclaimer { font-size: 11px; color: var(--muted); margin-top: 10px; }
.disclaimer { padding: 8px 10px; border-left: 3px solid #f79009; background: #fffaeb; color: #6b4a00; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; margin: 2px; }
.guide ol li, .guide ul li { margin-bottom: 4px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 50;
}
.error { color: var(--down); }

h3 { font-size: 13px; margin: 14px 0 6px; }
.test-chooser {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px;
  margin: 14px 0 0; padding: 10px 12px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent-soft);
}
.test-chooser label.inline, .blank-tests label.inline { margin: 0; color: var(--ink); font-size: 13px; gap: 5px; }
.blank-tests { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.std-test .scale-key { margin-bottom: 8px; }
.copyright { color: #6b4a00; }
.ep-on { background: var(--accent); color: #fff; border-radius: 4px; padding: 0 6px; }
table.cdc th.c-resp, table.cdc td.c-resp { width: 150px; }
table.cdc tr.sub td { background: var(--soft); font-weight: 700; font-size: 12px; }
.howto { font-weight: 600; margin: 8px 0; }
.reels-row { padding: 8px 0; border-top: 1px solid var(--line); }
.reels-head { margin-bottom: 6px; }
.reels-pills .pills { flex-wrap: wrap; gap: 4px; }
.reels-pills .pill span { min-width: 44px; font-size: 11px; }
.reels-out { margin-top: 6px; font-weight: 600; min-height: 1em; }
.reels-cla { font-size: 15px; padding: 8px 10px; background: var(--accent-soft); border-radius: 6px; }
.reel4-opt { margin-top: 8px; }
.reel4-opt summary { cursor: pointer; color: var(--accent); }
.reel-fields { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); margin-top: 6px; }
col.c-dim { width: 120px; }
col.c-la, col.c-items { width: 130px; }
col.c-calc { width: 170px; }
.part-title { margin-top: 22px; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
img { max-width: 100%; }
.m-only { display: none; font-style: normal; font-weight: 500; }
input[type=date] { min-height: 36px; -webkit-appearance: none; appearance: none; }

@media screen and (max-width: 760px) {
  body { font-size: 15px; }
  main { padding: 8px; }

  .topbar { position: static; padding: 8px 10px; gap: 6px; }
  .brand img { width: 36px; height: 36px; }
  .brand strong { font-size: 14px; }
  .brand .muted { font-size: 12px; }
  nav { width: 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav a { white-space: nowrap; flex: 0 0 auto; padding: 8px 12px; background: var(--soft); }

  .actions {
    position: sticky; top: 0; z-index: 9; padding: 8px; gap: 6px;
    box-shadow: 0 2px 6px rgba(16, 24, 40, 0.06);
  }
  .actions button, .actions .button-like { flex: 1 1 0; min-width: 0; padding: 8px 6px; font-size: 13px; line-height: 1.2; }
  .actions .live { flex-basis: 100%; margin: -2px 0 0; text-align: center; font-size: 12px; }
  .actions > .muted.small { flex-basis: 100%; }
  .actions label.inline { flex-basis: 100%; }

  .sheet, .block { padding: 12px; border-radius: 6px; }
  .clinic-banner img { width: 52px; height: 52px; }
  .clinic-name { font-size: 15px; }
  h1 { font-size: 18px; }
  .title-row { flex-wrap: wrap; }
  .grid-fields { grid-template-columns: 1fr 1fr; gap: 6px 10px; }
  .grid-fields .wide { grid-column: 1 / -1; }

  /* iOS zooms into inputs below 16px */
  input[type=text], input[type=date], input:not([type]), select, textarea { font-size: 16px; padding: 8px; }

  .pill span { min-width: 36px; height: 36px; font-size: 14px; }
  .pills { gap: 6px; }

  table.markers, table.markers tbody { display: block; }
  table.markers colgroup, table.markers thead { display: none; }
  table.markers tr {
    display: grid; grid-template-columns: 30px 1fr; border: 1px solid var(--line); border-radius: 6px;
    margin-bottom: 8px; padding: 6px 4px;
  }
  table.markers td { border: 0; padding: 4px; }
  table.markers td.score-cell, table.markers td:last-child { grid-column: 2; }

  table.ics, table.ics tbody, table.ics tr { display: block; }
  table.ics thead { display: none; }
  table.ics tr { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; padding: 6px; }
  table.ics td { display: inline-block; border: 0; padding: 2px; width: auto; }
  table.ics td:first-child { display: block; font-weight: 600; margin-bottom: 4px; }
  table.ics td.ics-opt { width: auto; }
  table.ics .pill span { padding: 0 10px; }
  .m-only { display: inline; }

  table.goals, table.goals tbody, table.goals tr, table.goals td { display: block; }
  table.goals colgroup, table.goals thead { display: none; }
  table.goals tr { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; padding: 6px; }
  table.goals td { border: 0; padding: 4px; }
  table.goals td.num::before { content: "Goal "; }
  table.goals td.num { width: auto; text-align: left; }
  table.goals td[data-label]::before, table.records td[data-label]::before {
    content: attr(data-label); display: block; font-size: 12px; color: var(--muted);
  }

  .level-row .pill span { min-width: 32px; height: 32px; font-size: 13px; }
  .mini-label { width: 40px; flex-basis: 40px; }
  label.check-label span { padding-top: 0; }
  input[type=number] { font-size: 16px; padding: 8px; }

  table.std, table.std tbody, table.std tr, table.std td { display: block; }
  table.std colgroup, table.std thead { display: none; }
  table.std tr { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; padding: 6px; }
  table.std td { border: 0; padding: 4px; }
  table.std td[data-label]:not(:first-child)::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); }

  table.bank { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.bank td, table.bank th { min-width: 150px; }
  table.bank td:first-child, table.bank th:first-child { min-width: 30px; }

  table.records, table.records tbody, table.records tr { display: block; }
  table.records thead { display: none; }
  table.records tr { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; padding: 6px; display: grid; grid-template-columns: 1fr 1fr; }
  table.records td { border: 0; padding: 4px; }
  table.records td:first-child, table.records td.row-actions { grid-column: 1 / -1; }
  table.records td.row-actions { flex-wrap: wrap; }
  table.records td.row-actions > * { flex: 1 1 auto; text-align: center; padding: 8px; }

  table.summary { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  table.summary td:first-child { white-space: normal; min-width: 150px; }
  .summary .bar-col { display: none; }

  table.flags, table.flags tbody { display: block; }
  table.flags thead { display: none; }
  table.flags tr { display: grid; grid-template-columns: 34px 1fr; border-bottom: 1px solid var(--line); padding: 4px 0; }
  table.flags td { border: 0; padding: 4px; }
  table.flags td:last-child { grid-column: 2; font-size: 12px; color: var(--muted); padding-top: 0; }
  table.flags td:last-child::before { content: "Refer: "; font-weight: 600; }
  .flags input[type=checkbox] { width: 22px; height: 22px; }
  .scale-key { font-size: 12px; }
  .toast { left: 10px; right: 10px; transform: none; text-align: center; }

  .test-chooser label.inline, .blank-tests label.inline { flex-basis: auto; font-size: 14px; }
  .std-test > label.inline { flex-wrap: wrap; }
  .std-test > label.inline select { flex: 1 1 100%; }
  table.cdc, table.cdc tbody { display: block; }
  table.cdc thead { display: none; }
  table.cdc tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 2px; }
  table.cdc td { display: block; border: 0; padding: 2px 4px; }
  table.cdc td.c-resp { width: auto; padding-top: 4px; }
  .reels-pills .pill span { min-width: 52px; height: 36px; font-size: 13px; }
  .reel-fields { grid-template-columns: 1fr 1fr; }
  table.dlat, table.dlat tbody, table.dlat tr, table.dlat td { display: block; }
  table.dlat colgroup, table.dlat thead { display: none; }
  table.dlat tr { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; padding: 6px; }
  table.dlat td { border: 0; padding: 4px; }
  table.dlat td[data-label]:not(:first-child)::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); }
}

@media screen and (max-width: 380px) {
  .grid-fields { grid-template-columns: 1fr; }
  .pill span { min-width: 34px; height: 34px; }
}

/* ---------- print ---------- */
@page { size: A4; margin: 11mm 10mm; }
@media print {
  body { background: #fff; font-size: 10.5px; }
  .no-print, .topbar, .actions { display: none !important; }
  main { max-width: none; padding: 0; }
  .sheet, .block { border: 0; padding: 0; margin: 0 0 6px; border-radius: 0; }
  h1 { font-size: 15px; }
  .clinic-banner { padding-bottom: 6px; margin-bottom: 6px; }
  .clinic-banner img { width: 60px; height: 60px; }
  .clinic-name { font-size: 15px; }
  h2 { font-size: 12px; margin: 10px 0 5px; break-after: avoid; }
  th, td { padding: 3px 5px; }
  tr, .domain-total { break-inside: avoid; }
  .page-break { break-before: page; }
  .grid-fields { grid-template-columns: repeat(3, 1fr); gap: 2px 12px; margin-top: 6px; }
  label { font-size: 9.5px; color: #333; margin-top: 3px; }
  input[type=text], input[type=date], input:not([type]), select, textarea {
    border: 0; border-bottom: 1px solid #777; border-radius: 0; padding: 2px 0; background: transparent;
    -webkit-appearance: none; appearance: none; font-size: 10.5px;
  }
  input[type=date]::-webkit-calendar-picker-indicator { display: none; }
  select { color: #000; }
  textarea { resize: none; overflow: hidden; border: 0; min-height: 30px;
    background-image: repeating-linear-gradient(to bottom, transparent 0 14px, #aaa 14px 15px); line-height: 15px; }
  .print-line { display: block; border-bottom: 1px solid #777; height: 16px; }
  .print-line.sig { height: 24px; }
  .sheet:not(.blank) .print-line { display: none; }
  .blank .calc { display: none; }
  .blank select { color: transparent; }
  .ex { background: #eef2fb; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .scale-key { padding: 4px 6px; margin-top: 6px; font-size: 9.5px; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  ::placeholder { color: transparent; }
  .print-only { display: block; }
  input[type=number] { border: 0; border-bottom: 1px solid #777; border-radius: 0; padding: 2px 0; -moz-appearance: textfield; appearance: textfield; font-size: 10.5px; }
  input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
  .level-row { margin-bottom: 2px; gap: 3px; }
  .mini-label { font-size: 8px; width: 28px; flex-basis: 28px; }
  .level-row .pill span { min-width: 17px; height: 17px; font-size: 8.5px; }
  .lvl .pill span { border-style: dashed; }
  .lvl .pill input:checked + span { background: #fff !important; color: #000 !important; border: 1.5px solid #000; }
  label.check-label span { padding-top: 10px; font-size: 9.5px; }
  table.std td, table.std th { padding: 3px 5px; font-size: 9.5px; }
  .std .band-list { font-size: 8.5px; }
  table.bank td, table.bank th { font-size: 8.5px; padding: 2px 3px; }
  table.bank tr { break-inside: avoid; }
  table.summary { break-inside: avoid; }
  col.c-item { width: 42%; }
  col.c-score { width: 158px; }
  .pills { flex-wrap: nowrap; gap: 3px; }
  .pill span { min-width: 19px; height: 19px; font-size: 9px; border-width: 1px; padding: 0 3px; }
  .observe, .ex { font-size: 9.5px; }
  .ex { margin-top: 2px; padding: 1px 4px; }
  table.markers td { padding: 2px 4px; }
  table.markers textarea { min-height: 28px; }
  .pill input:checked + span { background: #000 !important; color: #fff !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .domain-total { font-size: 9.5px; }
  .blank .domain-total::before { content: "Domain total: ______ / ______   Items scored: ____   N/O: ____"; }
  .disclaimer { background: none; border-left: 2px solid #999; color: #333; }
  .bar { print-color-adjust: exact; -webkit-print-color-adjust: exact; }

  h3 { font-size: 11px; margin: 8px 0 4px; break-after: avoid; }
  .copyright { color: #333; }
  .ep-on { background: none; color: inherit; padding: 0; }
  table.cdc td { font-size: 10px; }
  table.cdc th.c-resp, table.cdc td.c-resp { width: 92px; }
  table.cdc tr.sub td { print-color-adjust: exact; -webkit-print-color-adjust: exact; font-size: 10px; }
  .howto { margin: 4px 0; }
  .reels-row { padding: 4px 0; }
  .reels-sec { break-inside: avoid; }
  .reels-pills .pills { flex-wrap: nowrap; gap: 2px; }
  .reels-pills .pill span { min-width: 0; height: 18px; font-size: 8px; padding: 0 3px; letter-spacing: -0.2px; }
  .reels-out { font-size: 10.5px; margin-top: 4px; }
  .reels-cla { font-size: 11px; padding: 4px 6px; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .reel-fields { grid-template-columns: repeat(4, 1fr); }
  table.dlat td, table.dlat th { font-size: 9.5px; }
}
