:root {
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  color: #142f41;
  background: #f8f6f0;
  font-synthesis: none;
  color-scheme: light;
  --ink: #142f41;
  --muted: #4e6470;
  --navy: #173b58;
  --teal: #23675e;
  --line: #e0e5e3;
  --paper: #fffefa;
  --soft: #e8f1ed;
  --radius: 22px;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
a { color: var(--navy); }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .38; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #257c71; outline-offset: 3px; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: clamp(2.65rem, 7vw, 4.3rem); line-height: 1.04; letter-spacing: -.07em; font-weight: 750; }
h2 { font-size: 1.23rem; letter-spacing: -.023em; }
h3 { font-size: 1.09rem; }
p { line-height: 1.52; }
svg { flex: none; vertical-align: middle; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}

.masthead { border-bottom: 1px solid #e5e5dd; background: #fbfaf6; }
.masthead-inner, .shell { width: min(100% - 44px, 960px); margin-inline: auto; }
.masthead-inner { display: flex; align-items: center; justify-content: space-between; min-height: 74px; gap: 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 750; font-size: 1.08rem; white-space: nowrap; letter-spacing: -.027em; }
.brand img { display: block; border-radius: 11px; }
.local-label { display: inline-flex; align-items: center; gap: 8px; color: #365b54; font-size: .875rem; text-align: right; }
.local-label::before { content: ''; display: block; width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: #4b8575; }
.shell { padding-block: 56px calc(118px + env(safe-area-inset-bottom)); }
.view-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 26px; }
.date-line { color: var(--teal); font-weight: 670; font-size: .95rem; margin-bottom: 7px; }
.date-line::first-letter { text-transform: uppercase; }
.today-grid { display: grid; grid-template-columns: minmax(0, 2.15fr) minmax(0, 1fr); gap: 16px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); min-width: 0; box-shadow: 0 2px 4px #1c382a04; }
.card-title { display: flex; align-items: center; gap: 13px; }
.card-title p { color: var(--muted); margin-top: 3px; }
.symbol {
  width: 43px; height: 43px; border-radius: 13px; flex: 0 0 auto;
  display: inline-grid; place-items: center; color: var(--teal); background: var(--soft);
}
.capture { padding: 22px 24px; background: #f0f5f0; border-color: #dce8df; }
.capture-actions { display: grid; gap: 9px; margin-top: 17px; }
.today-grid .capture-actions { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); margin: 0 0 8px; }
.today-grid .capture-actions > :only-child { grid-column: 1 / -1; }
.pinned-buttons, .preset-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.pinned-buttons:empty { display: none; }
.preset-list { margin-block: 4px 10px; }
.check-field { display: flex; align-items: center; gap: 8px; align-self: center; min-height: 44px; font-weight: 650; cursor: pointer; }
.check-field input[type="checkbox"] { width: 20px; min-height: 20px; margin: 0; flex: 0 0 20px; accent-color: var(--teal); }
.primary, .secondary, .text-button, .icon-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 9px 15px; border: 1px solid transparent; border-radius: 12px;
  font-weight: 670; text-decoration: none; text-align: center; line-height: 1.27;
}
.primary { background: var(--navy); color: white; }
.secondary { background: #fffefa; border-color: #d4dfdc; color: var(--navy); }
.text-button { color: var(--teal); background: transparent; padding-inline: 4px; }
.text-button:hover { text-decoration: underline; }
.icon-button { padding: 0; width: 45px; flex: 0 0 45px; background: var(--paper); border-color: #dfe3dd; color: var(--ink); }
.quick { min-height: 67px; gap: 13px; text-align: left; justify-content: flex-start; padding-inline: 14px; }
.quick-mark { background: #ffffff20; border-radius: 50%; width: 34px; height: 34px; display: grid; place-items: center; flex: 0 0 auto; }
.quick small { display: block; margin-top: 3px; font-size: .875rem; color: #dfecea; font-weight: 500; }
.day-controls { display: flex; gap: 6px; }
.pick-date { position: relative; }
.pick-date:focus-within { outline: 3px solid #257c71; outline-offset: 3px; }
.pick-date input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.pick-date input::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; padding: 0; cursor: pointer; }

.day-summary { padding: 23px; display: flex; gap: 13px; flex-direction: column; align-items: flex-start; background: #fffefa; }
.day-summary strong { font-size: 3.4rem; font-weight: 750; line-height: 1.1; letter-spacing: -.055em; }
.day-summary p { color: var(--muted); }
.day-summary .summary-label { color: var(--ink); font-size: .9rem; font-weight: 700; }
.today-grid .day-summary { grid-column: 1 / -1; flex-direction: row; align-items: center; }
.today-grid .day-summary > div { display: grid; grid-template-columns: auto auto; align-items: center; column-gap: 12px; }
.today-grid .day-summary strong { grid-area: 1 / 1 / 3 / 2; font-size: 2.2rem; }
.journal { grid-column: 1 / -1; padding: 23px 24px 12px; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-title > span { color: var(--muted); font-size: .875rem; }
.empty { display: flex; align-items: center; gap: 12px; padding: 19px 0; color: var(--muted); }
.empty .symbol { width: 37px; height: 37px; color: #657c83; background: #f0f3f2; }
.empty p { font-size: .94rem; }
.journal-footer, .chart-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 10px; border-top: 1px solid var(--line); padding-top: 4px; }
.timeline { list-style: none; margin: 10px 0 0; padding: 0; }
.timeline li + li { border-top: 1px solid var(--line); }
.entry { border: 0; width: 100%; display: flex; align-items: center; text-align: left; gap: 12px; padding: 12px 1px; color: var(--ink); background: transparent; min-height: 57px; }
.entry:hover { background: #f4f7f2; }
.entry time { font-weight: 710; font-variant-numeric: tabular-nums; font-size: .95rem; color: var(--teal); padding-right: 10px; border-right: 1px solid var(--line); }
.entry-name { flex: 1; }
.entry-name strong { display: block; }
.entry-name small { color: var(--muted); font-size: .875rem; line-height: 1.4; }
.edit-mark { color: #4f6974; }

.tabbar {
  position: fixed; bottom: 17px; left: 50%; transform: translateX(-50%); z-index: 2;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; padding: 5px;
  width: min(calc(100% - 38px), 416px); border-radius: 18px; background: #fffefa;
  border: 1px solid #dce5df; box-shadow: 0 6px 24px #173b5816;
}
.tabbar:empty { display: none; }
.tabbar a { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; border-radius: 12px; text-decoration: none; color: var(--muted); font-size: .9rem; font-weight: 670; }
.tabbar a[aria-current] { color: #194f48; background: #e4efe8; }

.chart-card, .observations, .settings-card { padding: 22px 24px; }
.chart { display: grid; grid-template-columns: 28px minmax(0, 1fr); margin-top: 22px; }
.chart-scroll { overflow-x: auto; padding: 10px 0 8px; direction: rtl; }
.axis { height: 152px; display: flex; flex-direction: column; justify-content: space-between; color: var(--muted); font-size: .78rem; }
.plot { position: relative; height: 134px; display: grid; grid-template-columns: repeat(var(--days), minmax(36px, 1fr)); min-width: calc(36px * var(--days)); margin-bottom: 22px; direction: ltr; }
.grid-lines { position: absolute; inset: 0; border-bottom: 1px solid #becacb; background: repeating-linear-gradient(to bottom, #dfe7e6 0 1px, transparent 1px 25%); }
.baseline-band { position: absolute; inset-inline: 0; bottom: var(--position); height: max(2px, var(--size)); background: #deebe0; border-block: 1px dashed #77a18b; }
.plot-day { z-index: 1; position: relative; display: grid; justify-items: center; padding: 0; border: 0; background: transparent; color: var(--muted); }
.plot-day:hover, .plot-day:focus-visible { background: #28675c14; }
.plot-bar { position: absolute; bottom: 0; width: min(57%, 30px); background: #2b6c63; height: var(--height); border-radius: 4px 4px 0 0; }
.plot-bar.zero { height: 8px; width: 8px; border-radius: 50%; background: white; border: 2px solid #286e61; bottom: -3px; }
.plot-bar.missing { height: 0; width: 9px; background: none; border-top: 2px dashed #5f737b; }
.plot-bar.open { background: repeating-linear-gradient(135deg, #fff6e8 0 4px, #d99753 4px 6px); border: 1px solid #aa6529; }
.plot-bar.open-zero { height: 8px; width: 8px; transform: rotate(45deg); border-radius: 1px; bottom: -3px; }
.plot-label { position: absolute; top: calc(100% + 6px); font-size: .72rem; white-space: nowrap; }
.legend { margin: 7px 0 18px; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 7px 15px; color: var(--muted); font-size: .85rem; }
.legend li { display: flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; }
.legend-confirmed { background: #2b6c63; border-radius: 2px; }
.legend-open { background: repeating-linear-gradient(135deg, #fff6e8 0 3px, #c87c32 3px 4px); border: 1px solid #aa6529; border-radius: 2px; }
.legend-zero { border: 2px solid #286e61; border-radius: 50%; }
.legend-missing { border-bottom: 2px dashed #5f737b; transform: translateY(-4px); }
.legend-baseline { background: #deebe0; border: 1px dashed #77a18b; }
.chart-footer { padding-top: 8px; color: var(--muted); }
.observations { margin-top: 16px; }
.observations p { margin-top: 10px; }
.observations button { margin-top: 4px; }
.alert-card, .urgent-card { margin: 0 0 12px; }
.today-grid .alert-card, .today-grid .urgent-card { grid-column: 1 / -1; margin: 0; }
.alert-card.watch { border-color: #e8d3a8; background: #fff9ec; }
.alert-card.contact { border-color: #ddb6a5; background: #fff3eb; }
.alert-reasons { margin: 10px 0 0; padding-left: 19px; }
.alert-reasons li + li { margin-top: 9px; }
.alert-reasons p { margin-top: 2px; }
.alert-entries { display: flex; flex-wrap: wrap; gap: 0 12px; }
.alert-entries .text-button { text-align: left; }
.alert-card .source-links { display: block; color: var(--muted); }
.alert-card .source-links a { padding: 0; }
.urgent-card { background: #fbf0e9; border-color: #ead2c5; }
.urgent-card h2 { color: #873a27; }
.urgent-card p { margin: 4px 0 9px; }
.medication-summary { padding: 14px 16px; }
.medication-summary > p, .dose-time { color: var(--muted); }
.dose-summary-list, .dose-list { padding: 0; margin: 5px 0 0; list-style: none; }
.dose-summary-list li, .dose-list li, .schedule-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 10px; padding: 8px 0; }
.dose-summary-list li + li, .dose-list li + li, .schedule-row { border-top: 1px solid var(--line); }
.dose-summary-list li:last-child { padding-bottom: 0; }
.dose-summary-list small { display: block; color: var(--muted); }
.dose-list li { padding: 13px 0; }
.medication-summary, .dose-list, .schedule-row { overflow-wrap: anywhere; }
.dose-status { color: var(--muted); font-weight: 670; }
.dose-status.taken { color: var(--teal); }
.dose-status.unsure { color: #873a27; }
.dose-guidance { flex-basis: 100%; margin: 6px 0 2px; color: #873a27; }
.med-schedules { margin-top: 12px; }
.slot-fields { gap: 0 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.slot-fields .field { margin-bottom: 0; }
.slot-fields .text-button { grid-column: 1 / -1; justify-self: start; }
.more-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.settings-card .card-title { margin-bottom: 15px; align-items: flex-start; }
.button-row { display: flex; flex-wrap: wrap; gap: 8px; }
.file-button { position: relative; cursor: pointer; }
.file-button:focus-within { outline: 3px solid #257c71; outline-offset: 3px; }
.file-button input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }

.toast {
  position: fixed; z-index: 4; bottom: calc(86px + env(safe-area-inset-bottom)); left: 50%;
  transform: translateX(-50%); width: min(calc(100% - 38px), 416px);
  display: flex; align-items: center; gap: 8px; padding: 5px 8px 5px 14px; border-radius: 13px;
  background: #183748; color: white; box-shadow: 0 4px 16px #142f4130;
}
.toast > span { flex: 1; }
.toast-action, .toast-close { border: 0; background: transparent; color: #fff; min-height: 44px; }
.toast-action { padding: 7px 10px; border-radius: 8px; color: #b8f0da; font-weight: 750; }
.toast-close { font-size: 1.45rem; width: 32px; flex-basis: 32px; }

dialog {
  width: min(100% - 28px, 580px); max-width: none; max-height: min(91dvh, 880px); padding: 20px 24px 24px;
  border: 1px solid #dce4dc; border-radius: 22px; background: var(--paper); color: var(--ink); box-shadow: 0 12px 60px #1a303947;
}
dialog.wide { width: min(100% - 28px, 770px); }
dialog::backdrop { background: #0e293b72; }
dialog p + p { margin-top: 10px; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 13px; }
.panel-heading h2 { font-size: clamp(1.28rem, 4vw, 1.65rem); }
.panel-heading h2:focus { outline: none; }
form p:not(.form-error) { margin-bottom: 13px; }
.field { display: grid; gap: 6px; min-width: 0; margin-bottom: 12px; font-weight: 650; }
input:not([type=radio], [type=file]), select, textarea { min-height: 44px; border-radius: 9px; border: 1px solid #cdd9d7; padding: 8px 10px; color: var(--ink); background: #fff; min-width: 0; }
input[type="datetime-local"], input[type="date"] { max-width: 100%; }
select { cursor: pointer; }
textarea { resize: vertical; }
.field-row { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
fieldset { padding: 0; border: 0; margin: 0 0 12px; min-width: 0; }
legend { padding: 0 0 6px; font-weight: 670; }
.choices { display: flex; flex-wrap: wrap; gap: 5px; }
.choices label { position: relative; min-width: 0; }
.choices input { position: absolute; opacity: 0; }
.choices span { display: grid; place-items: center; padding: 7px 10px; min-height: 44px; height: 100%; text-align: center; border-radius: 9px; border: 1px solid #d2ddda; background: #fff; cursor: pointer; font-size: .92rem; line-height: 1.2; }
.choices input:checked + span { color: #134d44; background: #dfeee5; border-color: #5f9380; box-shadow: inset 0 0 0 1px #5f9380; font-weight: 720; }
.choices input:focus-visible + span { outline: 3px solid #257c71; outline-offset: 2px; }
.choices-kind label { flex: 1; }
.symptom-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
.symptom-fields label { flex: 1 1 auto; }
.symptom-fields .choices span { padding-inline: 6px; }
.form-error { color: #993a26; margin-bottom: 9px; }
.form-error:empty { display: none; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.panel-actions .primary { flex: 1; }
.danger { color: #993a26; }
.danger-fill { background: #8c382a; }
.advice { border: 1px solid var(--line); background: #f1f6f2; padding: 15px; border-radius: 14px; margin: 0 0 10px; }
.advice h3 { margin-bottom: 5px; }
.advice .button-row, .advice > .secondary { margin-top: 9px; }
.urgent-advice { background: #fbf0e9; border-color: #ead2c5; }
.urgent-advice h3 { color: #873a27; }
.plan-copy { white-space: pre-wrap; overflow-wrap: anywhere; }
.source-links { display: flex; gap: 5px 15px; flex-wrap: wrap; font-size: .875rem; }
.source-links a { padding-block: 9px; }
.report-preview { border: 1px solid var(--line); border-radius: 13px; padding: 16px; overflow-wrap: anywhere; }
.report-preview > h3 { font-size: 1.25rem; }
.report-preview > p { margin-top: 4px; color: var(--muted); }
.report-preview h4 { margin-bottom: 7px; }
.report-preview .report-note { margin: 6px 0 15px; font-size: .85rem; }
.report-totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.report-totals div { display: flex; flex-direction: column-reverse; justify-content: flex-end; background: #ecf2ed; border-radius: 7px; padding: 8px; }
.report-totals dt { font-size: .82rem; }
.report-totals dd { font-size: 1.2rem; font-weight: 700; margin: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; text-align: left; }
th { background: var(--navy); color: #fff; }
th, td { padding: 6px; border-bottom: 1px solid var(--line); }
tbody tr:nth-child(even) { background: #f1f6f3; }

.prototype-launcher { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 18px; }
.prototype-launcher [aria-pressed="true"] { background: #e4efe8; border-color: #6f9a89; }
.prototype-grid { max-width: 570px; margin: 0 auto; }
.prototype-shell .view-heading { align-items: flex-start; }
.prototype-shell .day-summary { flex-direction: row; margin-bottom: 12px; }
.prototype-shell .capture { margin-bottom: 12px; }
.prototype-shell .journal > .primary, .prototype-choice { width: 100%; margin-top: 8px; }
.prototype-shell .journal > .primary { position: sticky; bottom: 12px; }
.prototype-choice-list { display: grid; gap: 0; }
.prototype-result { margin: 10px 0; padding: 12px 14px; border-radius: 10px; background: #dfeee5; color: #154d43; }

@media (hover: hover) {
  .primary:hover { background: #255272; }
  .secondary:hover, .icon-button:hover { background: #eff4ed; }
}

@media (max-width: 640px) {
  .masthead-inner, .shell { width: calc(100% - 32px); }
  .masthead-inner { min-height: 62px; }
  .shell { padding-top: 24px; }
  .view-heading { margin-bottom: 16px; }
  .today-grid, .more-grid { grid-template-columns: 1fr; gap: 11px; }
  .capture, .journal, .chart-card, .observations, .settings-card { padding: 16px; }
  .capture-actions { margin-top: 12px; }
  .day-summary { padding: 12px 16px; flex-direction: row; align-items: center; }
  .day-summary > div { display: grid; grid-template-columns: auto auto; align-items: center; column-gap: 9px; }
  .day-summary strong { grid-area: 1 / 1 / 3 / 2; font-size: 2.12rem; }
  .day-summary p:last-child { font-size: .88rem; }
  .empty { padding-block: 14px; }
  .tabbar { bottom: max(10px, env(safe-area-inset-bottom)); }
  .tabbar a { flex-direction: column; gap: 2px; min-height: 49px; }
  dialog, dialog.wide { width: 100%; max-height: 94dvh; margin: auto 0 0; border-radius: 20px 20px 0 0; padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) and (min-height: 560px) {
  .shell:has(.today-grid) { padding-bottom: calc(200px + env(safe-area-inset-bottom)); }
  .today-grid .capture-actions {
    position: fixed; z-index: 2; inset-inline: 16px; bottom: calc(78px + env(safe-area-inset-bottom));
    margin: 0; padding: 6px; background: #f0f5f0; border: 1px solid #dce8df; border-radius: 16px;
    box-shadow: 0 6px 24px #173b581a; gap: 5px;
  }
  .today-grid .capture-actions > button { min-height: 55px; padding: 7px 8px; gap: 6px; }
  .today-grid .capture-actions .quick-mark { width: 26px; height: 26px; }
  .today-grid .capture-actions .quick small { font-size: .74rem; }
  body:has(.today-grid) .toast { bottom: calc(162px + env(safe-area-inset-bottom)); }
}

@media (max-width: 390px) {
  .local-label { font-size: .79rem; }
  .symptom-fields { grid-template-columns: 1fr; }
  .day-controls { gap: 4px; }
  .prototype-shell h1 { font-size: 2.35rem; }
  .today-grid .capture-actions .quick-mark { display: none; }
}
