/* 가족 건강기록 — 디자인 토큰 + 컴포넌트. 수치 가독성과 입력 편의를 장식보다 우선한다. */
:root {
  --bg: #FBF7F1;
  --surface: #FFFFFF;
  --surface-2: #F4EDE3;
  --ink: #2A2522;
  --ink-2: #5A5048;
  --muted: #766B62;
  --line: #E4D9CB;
  --field-line: #8F8479;
  --primary: #3B312B;
  --on-primary: #FFFFFF;
  --clay: #A83F32;
  --clay-soft: #F8E6E1;
  --teal: #1A6E68;
  --teal-soft: #DCEFEC;
  --danger: #B3261E;
  --danger-soft: #FCE8E6;
  --warn-soft: #FFF1CF;
  --warn-ink: #6B4A00;
  --ok: #25704A;
  --ok-soft: #E1F2E7;
  --focus: #1F5FBF;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 14px rgba(60, 40, 20, .06);
  --radius: 18px;
  --radius-sm: 12px;
  --gutter: 16px;
  --touch: 48px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --accent: var(--primary);
  --accent-soft: var(--surface-2);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1D1916; --surface: #28231F; --surface-2: #332D28; --ink: #F4EDE5; --ink-2: #D2C7BC;
    --muted: #B3A79B; --line: #433B35; --field-line: #7A6E64; --primary: #F4EDE5; --on-primary: #1D1916;
    --clay: #F08A78; --clay-soft: #46282A; --teal: #5CC4BB; --teal-soft: #1E3A38;
    --danger: #FF9C92; --danger-soft: #472624; --warn-soft: #473A17; --warn-ink: #F6D98B;
    --ok: #7FD3A0; --ok-soft: #1F3A2A; --focus: #8DB8FF;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
.accent-clay { --accent: var(--clay); --accent-soft: var(--clay-soft); }
.accent-teal { --accent: var(--teal); --accent-soft: var(--teal-soft); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  word-break: keep-all; overflow-wrap: break-word;
  margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.5 var(--font);
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
ul { margin: 8px 0 0; padding-left: 20px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.noscript, .boot { padding: 40px 16px; text-align: center; }
.boot { display: flex; justify-content: center; padding-top: 30vh; }

.app { min-height: 100vh; min-height: 100dvh; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--bg);
  padding: calc(var(--safe-top) + 8px) calc(var(--gutter) + var(--safe-right)) 8px calc(var(--gutter) + var(--safe-left));
  display: flex; align-items: center; gap: 8px; min-height: calc(var(--safe-top) + 60px);
  border-bottom: 1px solid transparent;
}
.topbar h1 { font-size: 22px; font-weight: 800; letter-spacing: -.02em; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .brand { display: flex; align-items: center; gap: 8px; }
.main { flex: 1; padding: 4px calc(var(--gutter) + var(--safe-right)) 28px calc(var(--gutter) + var(--safe-left)); display: flex; flex-direction: column; gap: 16px; }
.main.has-actionbar { padding-bottom: calc(110px + var(--safe-bottom)); }

.icon { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn {
  width: var(--touch); height: var(--touch); border-radius: 50%; border: 0; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink);
}
.icon-btn:active { background: var(--surface-2); }

/* 버튼 */
.btn {
  min-height: var(--touch); padding: 0 20px; border-radius: 14px; border: 1.5px solid transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; font-size: 17px;
  background: var(--accent); color: #fff; text-decoration: none; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: #fff; }
.accent-neutral .btn.primary, .btn.neutral { background: var(--primary); color: var(--on-primary); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.tonal { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: transparent; color: var(--ink-2); }
.btn.block { width: 100%; }
.btn.lg { min-height: 56px; font-size: 18px; border-radius: 16px; }
.btn.sm { min-height: 44px; padding: 0 14px; font-size: 15px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; pointer-events: none; }
.btn:active { filter: brightness(.94); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #1D1916; } }

/* 카드 */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; border: 1px solid var(--line); }
.card.tap { display: block; width: 100%; text-align: left; cursor: pointer; }
.card.person { border-left: 6px solid var(--accent); }
.card h2, .section-title { font-size: 15px; font-weight: 700; color: var(--ink-2); letter-spacing: 0; }
.section-title { margin: 4px 2px 0; display: flex; justify-content: space-between; align-items: center; }
.person-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; min-height: 48px; text-decoration: none; color: inherit; }
.person-badge {
  width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.person-name { font-size: 19px; font-weight: 800; }
.person-sub { font-size: 14px; color: var(--muted); }
.chev { margin-left: auto; color: var(--muted); }

/* 수치 */
.big { font-size: 46px; line-height: 1.05; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.big .sep { color: var(--muted); font-weight: 600; margin: 0 2px; }
.unit { font-size: 16px; font-weight: 600; color: var(--ink-2); margin-left: 4px; letter-spacing: 0; }
.mid { font-size: 30px; line-height: 1.1; font-weight: 800; font-variant-numeric: tabular-nums; }
.meta { font-size: 14px; color: var(--muted); }
.meta strong { color: var(--ink-2); font-weight: 700; }
.value-row { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 14px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pair > div { background: var(--bg); border-radius: var(--radius-sm); padding: 12px; min-width: 0; }
.pair .label { font-size: 14px; font-weight: 700; color: var(--ink-2); }
.change { white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; font-weight: 700; font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.stale { display: inline-block; background: var(--surface-2); color: var(--ink-2); border-radius: 999px; font-size: 13px; font-weight: 700; padding: 2px 10px; }
.stale.old { background: var(--warn-soft); color: var(--warn-ink); }
.empty-note { color: var(--muted); font-size: 16px; padding: 4px 0 2px; }
.card-actions { display: flex; gap: 8px; margin-top: 14px; }
.card-actions .btn { flex: 1; }

/* 세그먼트 / 칩 */
.segmented { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; }
.segmented button {
  flex: 1; min-height: 44px; border: 0; border-radius: 11px; background: transparent; font-weight: 700; font-size: 15px;
  color: var(--ink-2); display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 6px; white-space: nowrap;
}
.segmented button[aria-pressed="true"], .segmented button[aria-selected="true"] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.segmented.person-switch button[aria-pressed="true"] { color: var(--accent); }
.seg-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); display: inline-block; }
.seg-dot.clay { background: var(--clay); } .seg-dot.teal { background: var(--teal); }
.lower { display: flex; flex-direction: column; gap: 16px; }
.legend .ink { color: var(--ink-2); stroke: none; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface);
  font-weight: 700; color: var(--ink-2);
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"]::before { content: "✓ "; }

/* 액션바 (엄지 영역) */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: linear-gradient(to top, var(--bg) 78%, transparent);
  padding: 12px calc(var(--gutter) + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(var(--gutter) + var(--safe-left));
}
.actionbar .inner { max-width: 560px; margin: 0 auto; display: flex; gap: 10px; }
.actionbar .btn { flex: 1; min-width: 0; padding: 0 12px; }
.ab-label { max-width: 560px; margin: 0 auto 8px; font-size: 14px; font-weight: 800; color: var(--accent); display: flex; align-items: center; gap: 6px; }
.actionbar .btn.photo { flex: 1.15; }
.sticky-save { position: sticky; bottom: 0; z-index: 25; margin: 8px calc(-1 * var(--gutter)) 0; padding: 12px var(--gutter) calc(12px + var(--safe-bottom)); background: linear-gradient(to top, var(--bg) 80%, transparent); }

/* 폼 */
.form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font-weight: 700; font-size: 16px; }
.field .opt { color: var(--muted); font-weight: 500; font-size: 14px; margin-left: 4px; }
.input-wrap { display: flex; align-items: center; background: var(--surface); border: 1.5px solid var(--field-line); border-radius: 14px; min-height: 56px; padding: 0 14px; gap: 8px; }
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-wrap input { flex: 1; min-width: 0; border: 0; background: transparent; outline: 0; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; padding: 10px 0; scroll-margin-bottom: 140px; }
.input-wrap input::placeholder { color: var(--muted); font-weight: 500; opacity: 1; }
.input-wrap .suffix { font-size: 17px; font-weight: 700; color: var(--ink-2); flex: none; }
.input-wrap.plain input { font-size: 18px; font-weight: 600; }
.field.invalid .input-wrap { border-color: var(--danger); background: var(--danger-soft); }
.field.review .input-wrap { border-color: #C98A00; background: var(--warn-soft); }
.field-msg { font-size: 14px; font-weight: 600; display: flex; gap: 6px; align-items: flex-start; }
.field-msg.err { color: var(--danger); }
.field-msg.warn { color: var(--warn-ink); }
.field-msg .icon { width: 18px; height: 18px; margin-top: 2px; }
.field-hint { font-size: 14px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 10px; }
.input-wrap.plain input { width: 100%; min-width: 0; }
.row2 > .field { min-width: 0; }
textarea.memo { width: 100%; min-height: 84px; border-radius: 14px; border: 1.5px solid var(--field-line); background: var(--surface); padding: 12px 14px; font-size: 17px; resize: vertical; scroll-margin-bottom: 140px; }
textarea.memo:focus { border-color: var(--accent); outline: 0; box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; align-items: center; gap: 12px; min-height: 48px; font-weight: 700; }
.check input { width: 26px; height: 26px; accent-color: var(--accent); flex: none; }

/* 알림/배너 */
.notice { border-radius: var(--radius-sm); padding: 12px 14px; font-size: 15px; display: flex; gap: 10px; align-items: flex-start; background: var(--surface-2); color: var(--ink-2); }
.notice .icon { width: 20px; height: 20px; margin-top: 2px; }
.notice.warn { background: var(--warn-soft); color: var(--warn-ink); }
.notice.err { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice b { font-weight: 800; }
.notice .stack { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.notice .links { display: flex; gap: 8px; flex-wrap: wrap; }
.offline-banner { position: sticky; top: calc(var(--safe-top) + 60px); z-index: 19; margin: 0 var(--gutter); }

.toast-host { position: fixed; left: 0; right: 0; bottom: calc(96px + var(--safe-bottom)); z-index: 60; display: flex; justify-content: center; pointer-events: none; padding: 0 16px; }
.toast { background: var(--primary); color: var(--on-primary); padding: 12px 18px; border-radius: 999px; font-weight: 700; font-size: 16px; box-shadow: var(--shadow); max-width: 100%; display: flex; gap: 8px; align-items: center; }
.toast.err { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .toast.err { background: #B3261E; } }

/* 다이얼로그 */
.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(20, 14, 10, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 22px 20px calc(20px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; max-height: 90vh; overflow: auto; }
.sheet h2 { font-size: 20px; color: var(--ink); }
.sheet p { color: var(--ink-2); }
.sheet ul { margin: 0; padding-left: 20px; color: var(--ink-2); }
.sheet .btns { display: flex; flex-direction: column; gap: 10px; }
@media (min-width: 600px) { .overlay { align-items: center; } .sheet { border-radius: 22px; } }
.photo-view { background: #000; padding: 0; align-items: center; }
.photo-view img { max-width: 100%; max-height: 92vh; display: block; margin: auto; }
.photo-view .close { position: absolute; top: calc(var(--safe-top) + 10px); right: 10px; background: rgba(0,0,0,.55); color: #fff; }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn .spinner { width: 20px; height: 20px; border-width: 3px; border-color: rgba(255,255,255,.4); border-top-color: #fff; }
.center { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; padding: 28px 8px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: var(--radius); min-height: 120px; }
@keyframes sh { to { background-position: -200% 0; } }

/* 목록 */
.day-group { display: flex; flex-direction: column; gap: 8px; }
.day-head { font-size: 15px; font-weight: 800; color: var(--ink-2); display: flex; justify-content: space-between; padding: 8px 2px 0; }
.rec { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); text-align: left; }
.rec:active { background: var(--surface-2); }
.rec .when { font-size: 14px; font-weight: 700; color: var(--ink-2); min-width: 62px; font-variant-numeric: tabular-nums; }
.rec .vals { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; flex: 1; min-width: 0; }
.rec .vals small { font-size: 14px; font-weight: 600; color: var(--ink-2); margin-left: 3px; }
.rec .sub { display: block; font-size: 14px; font-weight: 500; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); margin-right: 4px; }
.tag .icon { width: 13px; height: 13px; }

/* 통계/차트 */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.stat.wide { margin-top: 12px; }
@media (max-width: 400px) { .row2 { grid-template-columns: 1fr; } }
.tag.warn { background: var(--warn-soft); color: var(--warn-ink); margin-left: 8px; }
.install-line { display: flex; align-items: center; gap: 10px; }
.install-line .txt { flex: 1; font-weight: 700; font-size: 15px; }
.stat { background: var(--bg); border-radius: var(--radius-sm); padding: 12px; }
.stat .label { font-size: 14px; font-weight: 700; color: var(--ink-2); }
.stat .mid .unit { font-size: 14px; }
.chart-wrap { margin-top: 10px; }
.chart { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--muted); stroke-width: 1; }
.chart text { font-family: var(--font); fill: var(--muted); font-size: 13px; }
.chart .ylab { font-size: 12.5px; }
.chart .line { fill: none; stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .mk { stroke: var(--surface); stroke-width: 1.5; }
.chart .sel { fill: none; stroke: var(--ink); stroke-width: 2; }
.chart .guide { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.s1 { stroke: var(--clay); color: var(--clay); } .s1.mk { fill: var(--clay); }
.s2 { stroke: var(--ink-2); color: var(--ink-2); } .s2.mk { fill: var(--ink-2); }
.s3 { stroke: var(--teal); color: var(--teal); } .s3.mk { fill: var(--teal); }
.s4 { stroke: #8C5E00; color: #8C5E00; } .s4.mk { fill: #8C5E00; }
@media (prefers-color-scheme: dark) { .s4 { stroke: #E9B94A; color: #E9B94A; } .s4.mk { fill: #E9B94A; } }
.s3.s1b, .accent-teal .s1 { stroke: var(--teal); color: var(--teal); } .accent-teal .s1.mk { fill: var(--teal); }
.dash { stroke-dasharray: 6 4; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: 14px; font-weight: 700; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend svg { width: 28px; height: 14px; }
.legend path, .legend line { stroke-width: 2.5; fill: none; }
.legend .mk { stroke-width: 0; }
.readout { min-height: 46px; margin-top: 8px; padding: 10px 12px; background: var(--bg); border-radius: var(--radius-sm); font-size: 15px; color: var(--ink-2); }
.readout b { color: var(--ink); font-variant-numeric: tabular-nums; }
.caption { font-size: 13.5px; color: var(--muted); margin-top: 6px; }

/* 로그인 */
.login { padding-top: calc(var(--safe-top) + 40px); gap: 20px; }
.login .logo { width: 84px; height: 84px; border-radius: 22px; margin: 0 auto; display: block; }
.login h1 { text-align: center; font-size: 28px; font-weight: 800; }
.login .lead { text-align: center; color: var(--ink-2); }

.steps { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 12px; counter-reset: s; }
.steps li { counter-increment: s; display: flex; gap: 12px; align-items: flex-start; }
.steps li::before { content: counter(s); flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: var(--on-primary); font-weight: 800; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; margin-top: 1px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--ink-2); } .kv .v { font-weight: 700; text-align: right; }
.cand { display: flex; flex-direction: column; gap: 14px; }
.cand.off { opacity: .6; }
.cand-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.preview-thumb { width: 72px; height: 72px; border-radius: 12px; object-fit: cover; border: 1px solid var(--line); background: var(--surface-2); }
.photo-box { display: flex; gap: 12px; align-items: center; }
.photo-box .info { flex: 1; min-width: 0; }
.pick-grid { display: grid; gap: 12px; }
.pick { min-height: 88px; border-radius: var(--radius); border: 1.5px dashed var(--accent); background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 19px; font-weight: 800; }
.pick .icon { width: 30px; height: 30px; }
.check.small { min-height: 44px; font-size: 15px; font-weight: 600; color: var(--ink-2); }
.check.small input { width: 22px; height: 22px; }
.input-wrap.dim { opacity: .45; background: var(--surface-2); }
.rec .when.unk { color: var(--muted); font-weight: 600; }
.cand.collapsed .cand-body { display: none; }
.cand-sum { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: -6px; }
.cand.collapsed { gap: 8px; padding: 12px 16px; }
.hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; } }
