@font-face { font-family: "Atkinson"; src: url("/static/fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Atkinson"; src: url("/static/fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  --ink: #16223a; --muted: #5b6780; --canvas: #f2f5fa; --surface: #ffffff; --line: #dce3ee; --soft: #eaf0fa;
  --blue: #1d5fd1; --blue-ink: #0f3f94; --green: #1f8a55; --amber: #c9760a; --red: #c23a3a; --violet: #6e46bd;
  --red-bg: #fbeceb; --green-bg: #e6f4ec; --amber-bg: #fdf1df; --violet-bg: #f0eafb; --blue-bg: #e8effc;
  --r-lg: 16px; --r-md: 10px;
  --font: "Atkinson", "Segoe UI", system-ui, -apple-system, sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
}
*, *::before, *::after { box-sizing: inherit; }
html, body { margin: 0; background: var(--canvas); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.hidden { display: none !important; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand svg { width: 38px; height: 38px; flex: none; }
.brand b { display: block; font-size: 1.05rem; }
.brand span { font-size: .82rem; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-md); color: var(--ink); text-decoration: none; font-weight: 700; }
.nav a svg { width: 20px; height: 20px; flex: none; }
.nav a:hover { background: var(--soft); }
.nav a[aria-current="page"] { background: var(--blue-bg); color: var(--blue-ink); }
.side .who { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); font-size: .9rem; }
.side .who button { margin-top: 6px; }
.main { padding: 22px 26px 60px; max-width: 1480px; width: 100%; }
.bottom-nav { display: none; }

/* ---------- common blocks */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 20px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.stack > * + * { margin-top: 16px; }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 16px; border-radius: var(--r-md); font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); min-height: 42px; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-ink); }
.btn.danger { color: var(--red); }
.btn.link { border: 0; background: none; padding: 6px 4px; color: var(--blue); min-height: 0; }
.btn[disabled] { opacity: .55; cursor: progress; }
.icon-btn { border: 0; background: none; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--soft); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; display: block; }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: .82rem; font-weight: 700; white-space: nowrap; }
.pill.high { background: var(--red-bg); color: var(--red); }
.pill.ok { background: var(--green-bg); color: var(--green); }
.pill.warn { background: var(--amber-bg); color: var(--amber); }
.pill.neutral { background: var(--soft); color: var(--muted); }
.pill.check { background: var(--violet-bg); color: var(--violet); }

/* ---------- dashboard */
.patient { display: grid; grid-template-columns: auto 1fr auto auto; gap: 20px; align-items: center; }
.avatar { width: 58px; height: 58px; border-radius: 50%; background: var(--blue-bg); display: grid; place-items: center; color: var(--blue); }
.avatar svg { width: 30px; height: 30px; }
.patient .facts { display: flex; gap: 14px; color: var(--muted); font-size: .95rem; flex-wrap: wrap; }
.conditions { background: var(--blue-bg); border-radius: var(--r-md); padding: 10px 14px; max-width: 380px; }
.conditions b, .goal b { display: block; font-size: .9rem; color: var(--blue-ink); margin-bottom: 2px; }
.goal { background: var(--green-bg); border-radius: var(--r-md); padding: 10px 14px; max-width: 360px; font-size: .92rem; }
.goal b { color: var(--green); }

.rangebar { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.rangebar span { padding: 0 8px; font-weight: 700; white-space: nowrap; }
.rangebar input[type=date] { border: 0; background: transparent; padding: 4px; }

.cards { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat { display: grid; grid-template-columns: 42px 1fr; gap: 12px; align-items: start; }
.stat .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; }
.stat .ic svg { width: 22px; height: 22px; }
.stat .label { font-size: .9rem; color: var(--muted); }
.stat .value { font-size: 1.8rem; font-weight: 700; line-height: 1.1; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.stat .value small { font-size: 1rem; font-weight: 400; }
.stat .foot { font-size: .82rem; color: var(--muted); }
.completeness { display: flex; gap: 22px; flex-wrap: wrap; font-size: .92rem; color: var(--muted); }
.completeness b { color: var(--ink); }

.two { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); align-items: start; }
.charts { grid-template-columns: 1fr 1fr; }
.chart-wrap { position: relative; height: 200px; }
.chart-wrap.tall { height: 280px; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: .92rem; }
.legend { display: flex; gap: 14px; font-size: .84rem; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

.table-wrap { overflow-x: auto; margin: 12px -20px -18px; }
table.data { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
table.data th { background: var(--soft); text-align: center; font-size: .82rem; color: var(--muted); padding: 8px 10px; font-weight: 700; line-height: 1.2; }
table.data td { border-top: 1px solid var(--line); padding: 9px 10px; text-align: center; white-space: nowrap; }
table.data td.left, table.data th.left { text-align: left; }
table.data td.notes { white-space: normal; max-width: 220px; text-align: left; font-size: .9rem; }
table.data tr.flag-alert td:first-child { box-shadow: inset 4px 0 var(--red); }
table.data tr.flag-check td:first-child { box-shadow: inset 4px 0 var(--violet); }
table.data tr.flag-review td:first-child { box-shadow: inset 4px 0 var(--amber); }
td .hi { color: var(--red); font-weight: 700; }
td .chk { color: var(--violet); font-weight: 700; text-decoration: underline dotted; }
.empty { padding: 26px; text-align: center; color: var(--muted); }

.flags li { margin: 6px 0; display: flex; gap: 10px; align-items: baseline; }
.flags ul { list-style: none; padding: 0; margin: 8px 0 0; }
.flags .date { min-width: 58px; font-weight: 700; font-size: .9rem; }

/* ---------- report */
.report h2 { margin-bottom: 8px; }
.report .section { border-radius: var(--r-md); padding: 14px 18px; }
.report .section.findings { background: var(--red-bg); }
.report .section.recs { background: var(--green-bg); }
.report .section.dq { background: var(--violet-bg); }
.report .section.doctor { background: var(--amber-bg); }
.report .section.review { background: var(--soft); }
.report ul { margin: 6px 0 0; padding-left: 20px; }
.report li { margin: 4px 0; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; }
.dot.review { background: var(--red); } .dot.attention { background: var(--amber); } .dot.info { background: #8b95a8; }
.report ul.plain { list-style: none; padding-left: 0; }
.report-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.disclaimer { font-size: .84rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; }
.source { font-size: .84rem; }
.report-list li { list-style: none; border-top: 1px solid var(--line); padding: 14px 0; }
.report-list { padding: 0; margin: 0; }
.report-list p { margin: 4px 0 0; color: var(--muted); max-width: 80ch; }

/* ---------- forms */
.form { max-width: 760px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label, .field .lab { font-weight: 700; font-size: .95rem; }
.field .hint { font-size: .84rem; color: var(--muted); }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], select, textarea {
  border: 1.5px solid var(--line); border-radius: var(--r-md); padding: 10px 12px; background: #fff; min-height: 46px; width: 100%; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px var(--blue-bg); }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fields-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* The one bold element: large BP entry pairs */
.bp-block { border: 1.5px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px; background: #fff; }
.bp-block .lab { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 8px; }
.bp-block .lab i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.bp-pair { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.bp-pair input { font-size: 2rem; font-weight: 700; text-align: center; min-height: 64px; padding: 6px; font-variant-numeric: tabular-nums; }
.bp-pair .slash { font-size: 2rem; color: var(--muted); }
.bp-pair .cap { grid-column: span 3; display: grid; grid-template-columns: 1fr auto 1fr; font-size: .8rem; color: var(--muted); text-align: center; gap: 8px; }
.bp-pair .cap span:nth-child(2) { visibility: hidden; }
.bp-note { font-size: .88rem; margin-top: 8px; color: var(--violet); min-height: 1.2em; }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.seg label { padding: 10px 16px; cursor: pointer; font-weight: 700; border-right: 1px solid var(--line); }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: var(--blue-ink); }
.seg label:has(input:checked) { background: var(--blue-bg); color: var(--blue-ink); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--blue); outline-offset: -3px; }
.check { display: flex; gap: 10px; align-items: center; font-weight: 700; }
.check input { width: 22px; height: 22px; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }
.sticky-save { position: sticky; bottom: 0; background: linear-gradient(to top, var(--canvas) 70%, transparent); padding: 14px 0 calc(8px + env(safe-area-inset-bottom, 0px)); }
.error { color: var(--red); font-weight: 700; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .panel { width: 100%; max-width: 400px; padding: 28px; }
.login .brand { padding: 0 0 18px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 700; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 50; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.spinner { width: 18px; height: 18px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---------- responsive */
@media (max-width: 1250px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .two { grid-template-columns: 1fr; }
  .patient { grid-template-columns: auto 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .main { padding: 14px 14px 96px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); z-index: 20; }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px; font-size: .78rem; font-weight: 700; color: var(--muted); text-decoration: none; }
  .bottom-nav a svg { width: 22px; height: 22px; }
  .bottom-nav a[aria-current="page"] { color: var(--blue); }
  .cards { grid-template-columns: 1fr 1fr; }
  .charts { grid-template-columns: 1fr; }
  .patient { grid-template-columns: 1fr; gap: 12px; }
  .patient .avatar { display: none; }
  .conditions, .goal { max-width: none; }
  .fields-3 { grid-template-columns: 1fr 1fr; }
  .sticky-save { bottom: calc(62px + env(safe-area-inset-bottom, 0px)); }
  .stat { grid-template-columns: 1fr; gap: 6px; padding: 14px; }
  .stat .ic { width: 34px; height: 34px; border-radius: 10px; }
  .stat .ic svg { width: 18px; height: 18px; }
  .stat .value { font-size: 1.5rem; }
  .completeness { gap: 6px 16px; }
  table.data.responsive thead { display: none; }
  table.data.responsive tr { display: grid; grid-template-columns: 1fr 1fr; padding: 10px 14px; border-top: 1px solid var(--line); gap: 2px 12px; }
  table.data.responsive td { border: 0; padding: 3px 0; text-align: left; white-space: normal; }
  table.data.responsive td::before { content: attr(data-label); display: block; font-size: .76rem; color: var(--muted); }
  table.data.responsive td.date { grid-column: span 2; font-weight: 700; font-size: 1.05rem; }
  table.data.responsive td.date::before { display: none; }
  table.data.responsive td.notes, table.data.responsive td.actions { grid-column: span 2; max-width: none; }
  table.data.responsive td.empty-cell { display: none; }
  table.data.responsive tr.flag-alert td:first-child, table.data.responsive tr.flag-check td:first-child, table.data.responsive tr.flag-review td:first-child { box-shadow: none; }
  table.data.responsive tr.flag-alert { box-shadow: inset 4px 0 var(--red); }
  table.data.responsive tr.flag-check { box-shadow: inset 4px 0 var(--violet); }
  table.data.responsive tr.flag-review { box-shadow: inset 4px 0 var(--amber); }
}
@media (max-width: 460px) {
  .fields-2 { grid-template-columns: 1fr; }
  .rangebar { width: 100%; justify-content: space-between; }
}

/* ---------- print (Download PDF) */
@media print {
  @page { size: A4; margin: 14mm; }
  html, body { background: #fff; font-size: 11pt; }
  .side, .bottom-nav, .no-print, #toast { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; max-width: none; }
  .panel { border: 0; padding: 0; }
  .report .section { break-inside: avoid; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.data th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .table-wrap { margin: 8px 0; overflow: visible; }
  .chart-wrap { height: 200px; break-inside: avoid; }
}
