:root {
  color-scheme: light;
  --page: #f5f4f0;
  --surface: #fff;
  --surface-2: #eeede8;
  --ink: #171816;
  --ink-2: #5e5f5a;
  --line: #d9d8d2;
  --primary: #185f55;
  --primary-ink: #fff;
  --primary-soft: #e2f0ec;
  --danger: #d03b3b;
  --danger-soft: #fbe8e7;
  --warn-soft: #fff4d7;
  --shadow: 0 8px 30px rgba(30, 35, 30, .08);
  --chart-grid: #e1e0d9;
  --chart-text: #5e5f5a;
  --chart-target: rgba(12, 163, 12, .08);
  --chart-sys: #2a78d6;
  --chart-dia: #eb6834;
  --chart-hr: #4a3aa7;
  --chart-bg-bed: #1baf7a;
  --chart-event: #898781;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #111210;
    --surface: #1c1e1b;
    --surface-2: #282a26;
    --ink: #f4f5f0;
    --ink-2: #b8bab2;
    --line: #383a35;
    --primary: #66c5b3;
    --primary-ink: #092b25;
    --primary-soft: #173d36;
    --danger: #d03b3b;
    --danger-soft: #482326;
    --warn-soft: #3b321b;
    --shadow: none;
    --chart-grid: #2c2c2a;
    --chart-text: #c3c2b7;
    --chart-target: rgba(12, 163, 12, .14);
    --chart-sys: #3987e5;
    --chart-dia: #d95926;
    --chart-hr: #9085e9;
    --chart-bg-bed: #46c99b;
    --chart-event: #aaa89f;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #111210;
  --surface: #1c1e1b;
  --surface-2: #282a26;
  --ink: #f4f5f0;
  --ink-2: #b8bab2;
  --line: #383a35;
  --primary: #66c5b3;
  --primary-ink: #092b25;
  --primary-soft: #173d36;
  --danger: #d03b3b;
  --danger-soft: #482326;
  --warn-soft: #3b321b;
  --shadow: none;
  --chart-grid: #2c2c2a;
  --chart-text: #c3c2b7;
  --chart-target: rgba(12, 163, 12, .14);
  --chart-sys: #3987e5;
  --chart-dia: #d95926;
  --chart-hr: #9085e9;
  --chart-bg-bed: #46c99b;
  --chart-event: #aaa89f;
}

* { box-sizing: border-box; }
html { background: var(--page); }
body { margin: 0; min-height: 100dvh; background: var(--page); color: var(--ink); font-size: 17px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 5px; font-size: 30px; line-height: 1.14; letter-spacing: -.02em; }
h2 { margin-bottom: 12px; font-size: 21px; }
h3 { margin-bottom: 8px; font-size: 17px; }
small, .caption { color: var(--ink-2); font-size: 15px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }

#app { min-height: 100dvh; }
.app-shell { width: min(100%, 520px); min-height: 100dvh; margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) 18px calc(96px + env(safe-area-inset-bottom)); }
.app-shell.family-shell { padding-bottom: calc(28px + env(safe-area-inset-bottom)); }
.page-header { display: flex; align-items: center; justify-content: space-between; min-height: 48px; margin-bottom: 18px; gap: 12px; }
.page-title { margin: 0; font-size: 21px; text-align: center; flex: 1; }
.record-header select { width: auto; min-width: 130px; max-width: 220px; }
.icon-button { display: inline-grid; place-items: center; flex: 0 0 44px; min-width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow); font-size: 22px; }
.icon-button.placeholder { visibility: hidden; }
.avatar-button { font-size: 24px; }
.heading-block { margin: 8px 0 22px; }
.heading-block p { margin: 0; color: var(--ink-2); }

.card { margin-bottom: 12px; padding: 18px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: var(--shadow); }
.card.compact { padding: 14px 16px; }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.card-header h2, .card-header h3 { margin: 0; }
.stack { display: grid; gap: 12px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--ink-2); }
.divider { height: 1px; margin: 18px 0; background: var(--line); }

.button { display: inline-flex; min-height: 56px; align-items: center; justify-content: center; gap: 9px; width: 100%; padding: 12px 18px; border: 1px solid transparent; border-radius: 16px; background: var(--primary); color: var(--primary-ink); font-weight: 760; text-align: center; }
.button.secondary { border-color: var(--line); background: var(--surface); color: var(--ink); }
.button.ghost { min-height: 44px; border-color: transparent; background: transparent; color: var(--primary); }
.button.danger { background: var(--danger); color: #fff; }
.button:disabled { cursor: not-allowed; opacity: .42; }
.big-action { min-height: 72px; font-size: 20px; }
.text-link { display: inline-flex; min-height: 44px; align-items: center; color: var(--primary); font-weight: 700; }
.button-row { display: flex; gap: 10px; }
.button-row > * { flex: 1; }

.tab-bar { position: fixed; z-index: 30; left: 50%; bottom: 0; display: grid; grid-template-columns: repeat(5, 1fr); width: min(100%, 520px); min-height: 72px; padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); transform: translateX(-50%); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(18px); }
.tab-bar a { display: grid; min-width: 44px; min-height: 54px; place-content: center; place-items: center; border-radius: 14px; color: var(--ink-2); }
.tab-bar a > span { font-size: 22px; line-height: 1; }
.tab-bar a small { font-size: 14px; color: inherit; }
.tab-bar a.active { background: var(--primary-soft); color: var(--primary); font-weight: 750; }

.status-chip { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 15px; font-weight: 750; }
.status-ok { color: #0ca30c; }
.status-warn, .status-low { color: #fab219; }
.status-high { color: #ec835a; }
.status-critical { color: #d03b3b; }
.status-none { color: #898781; }
.critical-card { margin-bottom: 12px; padding: 16px; border: 2px solid var(--danger); border-radius: 18px; background: var(--danger-soft); color: var(--ink); }
.critical-card strong { color: var(--danger); }
.critical-card p { margin: 5px 0 0; }
.undo-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; padding: 13px 14px; border-radius: 16px; background: var(--ink); color: var(--page); }
.undo-bar button { min-width: 64px; min-height: 44px; border: 0; border-radius: 12px; background: var(--surface); color: var(--ink); font-weight: 750; }

.check-list { display: grid; gap: 9px; margin: 0; padding: 0; list-style: none; }
.check-list li { display: flex; align-items: center; gap: 9px; }
.check-list .done { color: var(--primary); }
.completion { font-weight: 760; color: var(--primary); }
.today-records { margin-top: 24px; }
.record-row { display: flex; min-height: 58px; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.record-row:last-child { border-bottom: 0; }
.record-row span { display: grid; }
.record-row small { margin-top: 2px; }
.record-row-value { justify-items: end; text-align: right; }

.field { display: grid; gap: 7px; }
.field > label, .field > .label { font-weight: 700; }
input, select, textarea { width: 100%; min-height: 52px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 13px; outline: 0; background: var(--surface); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { min-height: 78px; resize: vertical; }
.number-pair { display: grid; grid-template-columns: 1fr 22px 1fr; align-items: end; gap: 8px; }
.number-input { min-height: 64px; padding: 8px 10px; text-align: center; font-size: 34px; font-weight: 720; }
.number-pair .slash { padding-bottom: 20px; color: var(--ink-2); text-align: center; font-size: 25px; }
.unit { color: var(--ink-2); font-size: 15px; text-align: center; }
.single-measure { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.single-measure .number-input { max-width: 220px; }
.choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.choice-grid.four { grid-template-columns: repeat(4, 1fr); }
.choice { min-height: 48px; padding: 8px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); font-weight: 650; }
.choice.selected, .choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.sticky-save { position: sticky; z-index: 10; bottom: calc(10px + env(safe-area-inset-bottom)); margin-top: 20px; padding-top: 8px; background: linear-gradient(transparent, var(--page) 18%); }
.confirm-box { margin-top: 12px; padding: 15px; border: 1px solid #d39c22; border-radius: 16px; background: var(--warn-soft); }
.confirm-box p { margin-bottom: 12px; }
.time-display { display: flex; min-height: 44px; align-items: center; justify-content: space-between; gap: 10px; }
.time-display button { min-width: 88px; min-height: 44px; border: 0; background: transparent; color: var(--primary); font-weight: 700; }

.success-screen { display: grid; min-height: calc(100dvh - 48px); place-content: center; text-align: center; }
.success-mark { font-size: 80px; line-height: 1; color: #0ca30c; }
.success-value { margin: 18px 0 4px; font-size: 48px; font-weight: 760; line-height: 1; }
.success-screen .button { margin-top: 22px; min-width: 220px; }
.success-screen .button-row .button { min-width: 0; }
.success-screen .critical-card { max-width: 420px; margin-top: 20px; text-align: left; }

.member-card { display: block; }
.member-card .latest-values { display: flex; flex-wrap: wrap; gap: 7px 14px; margin: 12px 0 8px; font-size: 18px; font-weight: 680; }
.member-card .latest-values small { display: block; flex-basis: 100%; }
.member-card .completion-line { color: var(--ink-2); font-size: 15px; }
.member-card .status-secondary { opacity: .62; }
.member-card .card-trend { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 10px 0; padding: 10px 12px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); }
.member-card .card-trend span { font-size: 17px; font-weight: 800; }
.avatar-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.avatar-choice { min-height: 96px; padding: 10px 4px; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); font-weight: 700; }
.avatar-choice span { display: block; font-size: 30px; }
.avatar-choice.selected { border: 3px solid var(--primary); background: var(--primary-soft); }
.metric-card .value { margin: 4px 0; font-size: 27px; font-weight: 760; }
.target-copy { margin: 13px 2px 22px; color: var(--ink-2); }
.target-copy strong { color: var(--ink); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 12px 0 22px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.segmented a, .segmented button { display: grid; min-height: 44px; place-items: center; border: 0; border-radius: 11px; background: transparent; font-weight: 700; }
.segmented .active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

.chart-section { margin: 24px 0; }
.chart-card { position: relative; min-height: 220px; overflow: visible; padding: 8px 4px 0; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.chart-card svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-empty { display: grid; min-height: 205px; place-content: center; padding: 20px; color: var(--ink-2); text-align: center; }
.chart-tooltip { position: absolute; z-index: 12; width: max-content; max-width: 180px; padding: 8px 10px; border-radius: 10px; background: var(--ink); color: var(--page); font-size: 13px; line-height: 1.35; box-shadow: var(--shadow); pointer-events: none; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 0 4px 8px; color: var(--ink-2); font-size: 15px; }
.legend-line { display: inline-block; width: 18px; height: 3px; margin: 0 5px 3px 0; border-radius: 2px; }
.legend-shape { display: inline-block; min-width: 16px; margin-right: 3px; font-weight: 900; }
.summary-stat { display: grid; gap: 7px; margin-bottom: 16px; }
.insight-list { display: grid; gap: 8px; margin: 0; padding-left: 22px; }
.insight-list .attention { color: var(--danger); }
.disclaimer { margin: 15px 0 0; padding-top: 14px; border-top: 1px solid var(--line); color: var(--ink-2); font-size: 15px; }

.empty-state { display: grid; min-height: 150px; place-content: center; place-items: center; color: var(--ink-2); text-align: center; }
.empty-state span { font-size: 38px; }
.empty-state p { margin: 8px 0 0; }
.settings-list { display: grid; }
.settings-row { display: flex; min-height: 60px; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); }
.settings-row:last-child { border-bottom: 0; }
.settings-row select { width: auto; min-width: 130px; }
.radio-stack { display: grid; gap: 8px; }
.radio-row { display: flex; min-height: 48px; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 13px; }
.radio-row input { width: 22px; min-height: 22px; }
.range-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.range-grid input { text-align: center; }
.checkbox-row { display: flex; min-height: 44px; align-items: center; gap: 9px; }
.checkbox-row input { width: 22px; min-height: 22px; }

.report-controls { margin-bottom: 16px; }
.report-sheet { padding: 22px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: #111; box-shadow: var(--shadow); }
.report-sheet .chart-card { min-height: 150px; border-color: #ddd; background: #fff; }
.report-sheet .chart-card svg { max-height: 160px; }
.report-sheet .report-header { display: flex; justify-content: space-between; gap: 12px; padding-bottom: 10px; border-bottom: 2px solid #222; }
.report-sheet .report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 14px 0; }
.report-sheet h2 { margin-bottom: 5px; }
.report-sheet p { margin-bottom: 5px; }
.report-sheet small { color: #555; }
.report-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 12px; padding-top: 9px; border-top: 1px solid #ddd; font-size: 13px; color: #555; }

@media (max-width: 390px) {
  .app-shell { padding-left: 14px; padding-right: 14px; }
  .choice-grid.four { grid-template-columns: repeat(2, 1fr); }
  .report-sheet { padding: 16px; }
  .report-sheet .report-grid { grid-template-columns: 1fr; }
}
