:root {
  color-scheme: light;
  --ink: #202521;
  --ink-soft: #3f4741;
  --muted: #6d756f;
  --soft: #939a94;
  --line: #dfe1db;
  --line-strong: #c9cdc5;
  --paper: #fffefa;
  --canvas: #f5f3ee;
  --canvas-deep: #ebece6;
  --surface-tint: #f1f4ef;
  --health: #315d4a;
  --health-deep: #244839;
  --health-soft: #e4eee8;
  --warning: #a3682b;
  --warning-soft: #f6eadb;
  --danger: #a04b43;
  --danger-soft: #f6e8e5;
  --radius: 20px;
  --radius-small: 12px;
  --shadow: 0 1px 2px rgba(31, 37, 33, .025), 0 10px 30px rgba(31, 37, 33, .04);
  --shadow-raised: 0 2px 4px rgba(31, 37, 33, .04), 0 18px 44px rgba(31, 37, 33, .07);
  --sidebar-width: 232px;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 78% -12%, rgba(49, 93, 74, .065), transparent 30rem),
    var(--canvas);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.58;
  letter-spacing: -.006em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
::selection { color: var(--ink); background: #d9e7df; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
button, summary, label, input, select, textarea { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid rgba(49, 93, 74, .24);
  outline-offset: 2px;
}
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { color: var(--ink); text-wrap: balance; }
h1 { margin-bottom: 10px; font-size: clamp(2.35rem, 4.5vw, 3.55rem); font-weight: 760; line-height: 1.02; letter-spacing: -.055em; }
h2 { margin: 0; font-size: 1.12rem; font-weight: 720; line-height: 1.32; letter-spacing: -.025em; }
h3 { margin-bottom: 16px; font-size: 1rem; font-weight: 700; }
.is-hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; z-index: 100; left: 16px; top: -80px; padding: 10px 14px;
  color: #fff; background: var(--ink); border-radius: 10px; text-decoration: none;
}
.skip-link:focus { top: 16px; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; z-index: 20; inset: 0 auto 0 0; width: var(--sidebar-width);
  display: flex; flex-direction: column; padding: 30px 18px 22px;
  color: #f4f5f1;
  background:
    radial-gradient(circle at 20% 0, rgba(129, 168, 148, .16), transparent 18rem),
    #202923;
  border-right: 1px solid rgba(255, 255, 255, .06);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 0 8px; }
.brand-mark {
  display: grid; place-items: center; flex: 0 0 auto; width: 38px; height: 38px;
  color: var(--health-deep); background: #f3f1ea; border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(32, 37, 33, .08);
}
.brand-mark svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.brand-mark.large { width: 54px; height: 54px; margin: 0 auto 24px; border-radius: 17px; }
.brand-mark.large svg { width: 31px; height: 31px; }
.brand strong, .brand span { display: block; }
.brand strong { color: inherit; font-size: 1.02rem; font-weight: 750; line-height: 1.2; letter-spacing: -.025em; }
.brand span { margin-top: 3px; color: #9faba4; font-size: .75rem; }
.primary-nav { display: grid; gap: 7px; margin-top: 52px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 11px;
  border: 1px solid transparent; border-radius: 13px; color: #b8c3bc; background: transparent;
  cursor: pointer; font-weight: 650; text-align: left; transition: color .16s ease, background-color .16s ease, border-color .16s ease;
}
.nav-item:hover { color: #fff; background: rgba(255, 255, 255, .065); }
.nav-item.is-active { color: #fff; background: rgba(255, 255, 255, .11); border-color: rgba(255, 255, 255, .08); }
.nav-icon { display: grid; place-items: center; width: 28px; height: 28px; flex: 0 0 auto; }
.nav-icon svg { width: 21px; height: 21px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-foot {
  display: flex; align-items: center; gap: 9px; margin-top: auto; padding: 17px 8px 0;
  color: #9faba4; border-top: 1px solid rgba(255, 255, 255, .1); font-size: .74rem;
}
.privacy-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: #70a78c; box-shadow: 0 0 0 4px rgba(112, 167, 140, .13); }
.text-button { margin-left: auto; padding: 4px; border: 0; color: inherit; background: transparent; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.mobile-header, .bottom-nav { display: none; }

.main-content { min-height: 100vh; margin-left: var(--sidebar-width); padding: 52px clamp(30px, 4.5vw, 76px) 88px; }
#appContent { width: min(100%, 1220px); margin: 0 auto; }
.page { display: none; }
.page.is-active { display: block; animation: page-in .22s ease-out; }
@keyframes page-in { from { opacity: .25; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.page-heading {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 36px;
  margin-bottom: 30px; padding-bottom: 26px; border-bottom: 1px solid var(--line-strong);
}
.page-heading > div:first-child { max-width: 740px; min-width: 0; }
.page-heading p:not(.eyebrow) { max-width: 680px; margin: 0; color: var(--muted); font-size: .98rem; text-wrap: pretty; }
.eyebrow {
  display: inline-flex; align-items: center; min-height: 25px; margin-bottom: 13px; padding: 3px 9px;
  color: var(--health); background: var(--health-soft); border-radius: 999px;
  font-size: .68rem; font-weight: 780; letter-spacing: .08em;
}
.muted { color: var(--muted); }

.date-control { min-width: 214px; }
.date-control span, .field > span { display: block; margin-bottom: 7px; color: var(--ink-soft); font-size: .78rem; font-weight: 680; }
.date-control input { width: 100%; font-variant-numeric: tabular-nums; }
input, select, textarea {
  width: 100%; min-width: 0; border: 1px solid var(--line-strong); border-radius: var(--radius-small);
  color: var(--ink); background: rgba(255, 254, 250, .96);
  transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
}
input, select { min-height: 47px; padding: 9px 12px; }
textarea { min-height: 84px; padding: 11px 12px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #aab0a8; background: #fff; }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--health); background: #fff; box-shadow: 0 0 0 4px rgba(49, 93, 74, .09); outline-offset: 0; }
input::placeholder, textarea::placeholder { color: #a2a8a2; }
.field small, legend small { color: var(--soft); font-size: .71rem; font-weight: 520; }
.field.full { grid-column: 1 / -1; }
.field-grid { display: grid; gap: 16px; }
.field-grid.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid.three-columns { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid.compact { gap: 14px; }
.field-note { margin: 12px 0 0; color: var(--muted); font-size: .77rem; text-wrap: pretty; }

.section-grid { display: grid; gap: 15px; }
.section-grid.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.record-card, .chart-card, .archive-section, .export-card, .module-cluster {
  min-width: 0; background: var(--paper); border: 1px solid rgba(201, 205, 197, .78);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.record-card, .chart-card, .archive-section, .export-card { padding: clamp(21px, 2.4vw, 29px); }
.today-progress {
  display: grid; grid-template-columns: auto minmax(180px, 260px) minmax(220px, 1fr); align-items: center; gap: 20px;
  margin: -7px 0 18px; padding: 14px 3px 15px; border-bottom: 1px solid var(--line);
}
.today-progress > div:first-child { display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
.today-progress span, .today-progress p { color: var(--muted); font-size: .75rem; }
.today-progress strong { color: var(--ink); font-size: .9rem; font-variant-numeric: tabular-nums; }
.today-progress p { margin: 0; text-align: right; }
.progress-track { height: 5px; overflow: hidden; background: #e0e3dc; border-radius: 999px; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--health); border-radius: inherit; transition: width .35s ease; }
.progress-track .progress-step-1 { width: 20%; }
.progress-track .progress-step-2 { width: 40%; }
.progress-track .progress-step-3 { width: 60%; }
.progress-track .progress-step-4 { width: 80%; }
.progress-track .progress-step-5 { width: 100%; }
.daily-dashboard { display: grid; gap: 15px; }
.program-card {
  display: grid; grid-template-columns: minmax(260px, 1.25fr) minmax(390px, 1fr) auto;
  align-items: center; gap: 26px; margin-bottom: 18px; padding: clamp(22px, 2.8vw, 32px);
  color: #eef3ef; background:
    radial-gradient(circle at 92% 0, rgba(122, 171, 145, .18), transparent 19rem),
    #202923;
  border: 1px solid rgba(255, 255, 255, .06); border-radius: 22px;
  box-shadow: 0 18px 48px rgba(31, 37, 33, .14);
}
.program-card-main { min-width: 0; }
.program-state {
  display: inline-flex; margin-bottom: 12px; padding: 4px 9px; color: #d9ece1;
  background: rgba(112, 167, 140, .18); border: 1px solid rgba(153, 197, 174, .16);
  border-radius: 999px; font-size: .68rem; font-weight: 760;
}
.program-card-main strong { display: block; color: #fff; font-size: clamp(1.25rem, 2vw, 1.7rem); letter-spacing: -.035em; }
.program-card-main p { margin: 7px 0 0; color: #afbbb3; font-size: .77rem; text-wrap: pretty; }
.program-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0; }
.program-metrics div { min-width: 0; padding: 2px 18px; border-left: 1px solid rgba(255, 255, 255, .1); }
.program-metrics dt { color: #8f9c94; font-size: .65rem; }
.program-metrics dd { margin: 5px 0 0; color: #f5f6f3; font-size: .82rem; font-weight: 680; font-variant-numeric: tabular-nums; }
.program-card .primary-button { min-width: 150px; color: var(--ink); background: #f7f5ef; border-color: #f7f5ef; box-shadow: none; }
.program-card .primary-button:hover { background: #fff; border-color: #fff; }
.card-intro { margin: -10px 0 20px; color: var(--muted); font-size: .77rem; text-wrap: pretty; }
.fact-card { position: relative; overflow: hidden; }
.fact-card.needs-attention { border-color: rgba(163, 104, 43, .28); box-shadow: var(--shadow-raised); }
.fact-card.needs-attention::before {
  content: ''; position: absolute; inset: 20px auto 20px 0; width: 3px; border-radius: 0 4px 4px 0;
  background: var(--warning); animation: awaiting-rail 2.9s ease-in-out infinite;
}
.fact-count { flex: 0 0 auto; padding: 5px 9px; color: var(--muted); background: var(--surface-tint); border-radius: 999px; font-size: .69rem; font-weight: 720; white-space: nowrap; }
.fact-form { display: grid; gap: 16px; }
.fact-form > .field { margin-bottom: 0; }
.fact-form > .primary-button { justify-self: end; min-width: 142px; }
.fact-list { display: grid; gap: 7px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.fact-row { padding: 11px 12px; background: var(--surface-tint); border: 1px solid #e4e7e0; border-radius: 11px; }
.fact-row.warning { background: var(--warning-soft); border-color: rgba(163, 104, 43, .14); }
.fact-row-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.fact-row-heading span { color: var(--muted); font-size: .69rem; font-variant-numeric: tabular-nums; }
.fact-row-heading strong { color: var(--ink); font-size: .83rem; text-align: right; }
.fact-row p { margin: 4px 0 0; color: var(--muted); font-size: .7rem; white-space: pre-wrap; }
.fact-empty { margin: 0; color: var(--soft); font-size: .72rem; }
.nutrition-cluster { grid-column: 1 / -1; }
.module-card { position: relative; overflow: hidden; transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease; }
.module-card::before {
  content: ''; position: absolute; z-index: 1; top: 20px; bottom: 20px; left: 0; width: 3px;
  border-radius: 0 4px 4px 0; background: var(--warning); opacity: 0; transform: scaleY(.4); transform-origin: center;
}
.module-card-wide { grid-column: 1 / -1; }
.module-cluster { padding: clamp(21px, 2.4vw, 29px); }
.body-module-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.module-subcard { padding: 20px; background: #f7f7f3; border-color: transparent; box-shadow: none; }
.module-subcard .card-heading { margin-bottom: 18px; }
.module-card.is-pending { border-color: rgba(163, 104, 43, .26); box-shadow: var(--shadow-raised); }
.module-card.is-pending::before { opacity: .7; animation: awaiting-rail 2.9s ease-in-out infinite; }
.module-card.module-order-0::before { animation-delay: 0s; }
.module-card.module-order-1::before { animation-delay: .15s; }
.module-card.module-order-2::before { animation-delay: .3s; }
.module-card.module-order-3::before { animation-delay: .45s; }
.module-card.module-order-4::before { animation-delay: .6s; }
@keyframes awaiting-rail { 0%, 100% { opacity: .32; transform: scaleY(.38); } 50% { opacity: .95; transform: scaleY(1); } }
.module-card.is-complete { background: #f8faf7; border-color: #d6dfd9; box-shadow: none; }
.module-card.is-complete::before { opacity: 1; background: var(--health); transform: scaleY(1); }
.module-card.is-editing { border-color: var(--health); box-shadow: 0 0 0 4px rgba(49, 93, 74, .08); }
.module-status {
  display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto; padding: 5px 9px;
  color: var(--warning); background: var(--warning-soft); border-radius: 999px;
  font-size: .69rem; font-weight: 760; white-space: nowrap;
}
.module-status i { position: relative; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.module-card.is-pending .module-status i::after {
  content: ''; position: absolute; inset: -4px; border: 1px solid currentColor; border-radius: 50%;
  animation: pending-ring 1.8s ease-out infinite;
}
@keyframes pending-ring { from { opacity: .7; transform: scale(.55); } to { opacity: 0; transform: scale(1.7); } }
.module-card.is-complete .module-status { color: var(--health); background: var(--health-soft); }
.module-heading-meta { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.module-summary {
  margin: 1px 0 0; padding: 13px 15px; color: #365344; background: var(--health-soft);
  border: 1px solid rgba(49, 93, 74, .08); border-radius: 12px; font-size: .82rem; line-height: 1.65;
}
.module-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line);
}
.module-actions > span { max-width: 68%; color: var(--muted); font-size: .75rem; text-wrap: pretty; }
.module-actions > div { display: flex; gap: 8px; flex: 0 0 auto; }
.module-actions .primary-button, .module-actions .secondary-button { min-width: 116px; }
.inline-duration { display: inline-block; margin-left: 7px; padding: 2px 8px; color: var(--health); background: var(--health-soft); border-radius: 999px; font-weight: 750; }
.card-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.card-heading > div { display: flex; align-items: center; gap: 10px; min-width: 0; }
.step-number { color: var(--soft); font-size: .66rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .1em; }
.optional-label { color: var(--soft); font-size: .69rem; text-align: right; }
.duration-chip { padding: 5px 9px; color: var(--health); background: var(--health-soft); border-radius: 20px; font-size: .7rem; font-weight: 750; white-space: nowrap; }

fieldset { min-width: 0; padding: 0; border: 0; }
.choice-group { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.choice-pill { position: relative; }
.choice-pill input { position: absolute; opacity: 0; pointer-events: none; }
.choice-pill span {
  display: block; min-width: 76px; padding: 9px 14px; border: 1px solid var(--line-strong);
  border-radius: 999px; background: #fffefa; cursor: pointer; font-size: .84rem; font-weight: 650; text-align: center;
  transition: border-color .16s ease, background-color .16s ease, color .16s ease, transform .16s ease;
}
.choice-pill:hover span { border-color: #9fa69f; }
.choice-pill input:focus-visible + span { outline: 3px solid rgba(49, 93, 74, .24); outline-offset: 2px; }
.choice-pill input:checked + span { color: #fff; background: var(--health); border-color: var(--health); }
.choice-pill.warning input:checked + span { color: #fff; background: var(--warning); border-color: var(--warning); }
.checklist-label { margin: 0 0 8px; color: var(--ink-soft); font-size: .78rem; font-weight: 680; }
.symptom-list { display: flex; flex-wrap: wrap; gap: 9px 16px; margin-bottom: 18px; }
.symptom-list label { display: flex; align-items: center; gap: 7px; min-height: 30px; color: var(--muted); font-size: .82rem; cursor: pointer; }
.symptom-list input { width: 17px; min-height: 17px; accent-color: var(--health); }
.symptom-list:not(.positive-list) input { accent-color: var(--warning); }
.split-number-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.split-number-fields label { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.split-number-fields label > span { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.quality-scale { margin-top: 18px; }
.quality-scale legend { margin-bottom: 10px; color: var(--ink-soft); font-size: .78rem; font-weight: 680; }
.quality-scale > div { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; }
.quality-scale label { position: relative; }
.quality-scale input { position: absolute; opacity: 0; }
.quality-scale span { display: grid; place-items: center; height: 39px; border: 1px solid var(--line-strong); border-radius: 10px; background: #fffefa; cursor: pointer; font-size: .8rem; font-weight: 700; }
.quality-scale input:checked + span { color: #fff; background: var(--health); border-color: var(--health); }
.quality-scale input:focus-visible + span { outline: 3px solid rgba(49, 93, 74, .24); outline-offset: 2px; }

.save-bar {
  position: sticky; z-index: 8; bottom: 20px; display: flex; align-items: center; justify-content: space-between;
  gap: 20px; width: min(760px, 100%); margin: 24px auto 0; padding: 14px 16px 14px 20px;
  color: #fff; background: rgba(32, 41, 35, .96); border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 16px; box-shadow: 0 16px 44px rgba(31, 37, 33, .22); backdrop-filter: blur(12px);
}
.save-bar strong, .save-bar span { display: block; }
.save-bar strong { font-size: .84rem; }
.save-bar span { margin-top: 2px; color: #b8c1bb; font-size: .69rem; }
.primary-button, .secondary-button {
  min-height: 45px; padding: 10px 17px; border-radius: 12px; cursor: pointer; font-weight: 720;
  transition: transform .14s ease, background-color .16s ease, border-color .16s ease, box-shadow .16s ease;
}
.primary-button { color: #fff; background: var(--health); border: 1px solid var(--health); box-shadow: 0 5px 14px rgba(49, 93, 74, .13); }
.primary-button:hover { background: var(--health-deep); border-color: var(--health-deep); box-shadow: 0 7px 18px rgba(49, 93, 74, .18); }
.secondary-button { color: var(--ink); background: #fffefa; border: 1px solid var(--line-strong); }
.secondary-button:hover { background: var(--surface-tint); border-color: #abb1aa; }
.primary-button:active, .secondary-button:active { transform: translateY(1px); }
.primary-button:disabled, .secondary-button:disabled { opacity: .54; cursor: wait; box-shadow: none; }
.save-bar .primary-button { color: var(--ink); background: #fff; border-color: #fff; white-space: nowrap; }
.full-button { width: 100%; }

.segmented-control { display: flex; padding: 4px; background: #e6e8e2; border: 1px solid #dde0d9; border-radius: 13px; }
.segmented-control button { min-width: 56px; padding: 8px 11px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; cursor: pointer; font-size: .79rem; font-weight: 680; }
.segmented-control button:hover { color: var(--ink); }
.segmented-control button.is-active { color: #fff; background: var(--ink); box-shadow: 0 2px 7px rgba(31, 37, 33, .18); }
.summary-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; margin-bottom: 18px;
  overflow: hidden; background: var(--paper); border: 1px solid rgba(201, 205, 197, .78); border-radius: 18px; box-shadow: var(--shadow);
}
.summary-item { min-width: 0; padding: 17px 19px; background: transparent; border: 0; border-right: 1px solid var(--line); }
.summary-item:last-child { border-right: 0; }
.summary-item span, .summary-item strong { display: block; }
.summary-item span { color: var(--muted); font-size: .7rem; }
.summary-item strong { margin-top: 5px; font-size: 1.25rem; font-weight: 730; font-variant-numeric: tabular-nums; letter-spacing: -.035em; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.chart { min-height: 240px; overflow: hidden; }
.chart-empty, .empty-state { display: grid; place-items: center; min-height: 188px; padding: 24px; color: var(--muted); background: var(--surface-tint); border: 1px dashed var(--line-strong); border-radius: 13px; text-align: center; font-size: .82rem; }
.life-chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid-line { stroke: #e7e8e3; stroke-width: 1; }
.chart-axis-label { fill: #858d87; font-size: 10px; }
.chart-line { fill: none; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { stroke: #fffefa; stroke-width: 2; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 13px; margin-top: 10px; color: var(--muted); font-size: .71rem; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 3px; border-radius: 3px; }
.chart-legend i.swatch-health { background: var(--health); }
.chart-legend i.swatch-neutral { background: #7a827d; }
.chart-legend i.swatch-warning { background: var(--warning); }
.chart-legend i.swatch-soft { background: var(--soft); }
.diet-timeline { display: grid; gap: 8px; min-height: 240px; align-content: start; }
.diet-row { display: grid; grid-template-columns: 92px 1fr; align-items: center; gap: 12px; font-size: .77rem; }
.diet-row time { color: var(--muted); font-variant-numeric: tabular-nums; }
.diet-state { padding: 7px 10px; border-left: 3px solid var(--line-strong); background: var(--surface-tint); border-radius: 0 8px 8px 0; }
.diet-state.controlled { border-color: var(--health); background: var(--health-soft); }
.diet-state.off_plan { border-color: var(--warning); background: var(--warning-soft); }
.context-timeline { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; align-content: start; min-height: 120px; }
.context-timeline > .fact-empty { grid-column: 1 / -1; display: grid; place-items: center; min-height: 120px; padding: 20px; background: var(--surface-tint); border: 1px dashed var(--line-strong); border-radius: 12px; text-align: center; }

.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin: 42px 0 18px; padding-top: 30px; border-top: 1px solid var(--line-strong); }
.section-heading p:not(.eyebrow) { max-width: 720px; margin: 7px 0 0; color: var(--muted); font-size: .84rem; text-wrap: pretty; }
.medical-trends-section { margin-top: 46px; }
.medical-trends-section > .section-heading { margin-top: 0; }
.chart-card-wide { grid-column: 1 / -1; }
.lab-chart-heading { gap: 18px; }
.compact-select select { min-height: 39px; padding: 6px 34px 6px 10px; font-size: .75rem; }
.medical-chart-grid .chart { min-height: 270px; }
.session-strip, .metric-detail-strip { display: flex; gap: 9px; margin-top: 12px; overflow-x: auto; padding: 0 0 5px; scrollbar-width: thin; }
.session-chip, .metric-point { flex: 0 0 auto; min-width: 166px; padding: 11px 12px; color: var(--muted); background: var(--surface-tint); border: 1px solid #e4e6df; border-radius: 11px; font-size: .69rem; }
.session-chip strong, .metric-point strong { display: block; margin-top: 3px; color: var(--ink); font-size: .84rem; font-variant-numeric: tabular-nums; }
.session-chip small, .metric-point small { display: block; margin-top: 4px; color: var(--soft); }

.archive-actions { display: grid; gap: 9px; margin-bottom: 18px; }
.action-panel { overflow: hidden; background: var(--paper); border: 1px solid var(--line); border-radius: 14px; transition: border-color .16s ease, box-shadow .16s ease; }
.action-panel:hover { border-color: #c7cbc3; }
.action-panel[open] { border-color: #bfc9c1; box-shadow: var(--shadow); }
.action-panel summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; padding: 17px 20px; cursor: pointer; list-style: none; }
.action-panel summary::-webkit-details-marker { display: none; }
.action-panel summary::after { content: '+'; margin-left: auto; color: var(--muted); font-size: 1.25rem; line-height: 1; transition: transform .16s ease; }
.action-panel[open] summary::after { content: '−'; transform: rotate(180deg); }
.action-panel summary span { font-weight: 720; }
.action-panel summary small { color: var(--muted); font-size: .74rem; }
.panel-form { padding: 20px; border-top: 1px solid var(--line); }
.panel-form .primary-button, .panel-form > .secondary-button { margin-top: 18px; }
.file-field input { padding: 7px; }
.form-message { min-height: 1.4em; margin: 12px 0 0 10px; color: var(--muted); font-size: .78rem; }
.form-message.error { color: var(--danger); }
.form-message.success { color: var(--health); }
.dual-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dual-form-grid .sub-form + .sub-form { border-left: 1px solid var(--line); }
.sub-form { display: grid; align-content: start; gap: 12px; }
.sub-form h3 { margin: 0; }
.archive-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.archive-primary-grid { display: grid; gap: 15px; margin-bottom: 18px; }
.archive-section.wide { grid-column: 1 / -1; }
.comparison-heading { align-items: flex-start; gap: 18px; }
.comparison-controls { display: flex; align-items: center; gap: 8px; }
.comparison-controls .compact-search { width: 170px; }
.comparison-controls input { min-height: 39px; padding: 6px 10px; font-size: .75rem; }
.section-note { margin: -8px 0 18px; color: var(--muted); font-size: .74rem; text-wrap: pretty; }
.comparison-container { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 13px; scrollbar-width: thin; }
.comparison-table { width: 100%; min-width: 720px; border-collapse: separate; border-spacing: 0; font-size: .72rem; font-variant-numeric: tabular-nums; }
.comparison-table th, .comparison-table td { min-width: 150px; padding: 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.comparison-table th:last-child, .comparison-table td:last-child { border-right: 0; }
.comparison-table tbody tr:last-child td { border-bottom: 0; }
.comparison-table tbody tr:hover td { background-color: #fafaf6; }
.comparison-table thead th { color: var(--muted); background: #f1f3ee; font-weight: 680; }
.comparison-table th:first-child, .comparison-table td:first-child { position: sticky; z-index: 2; left: 0; min-width: 190px; max-width: 220px; background: #fffefa; box-shadow: 1px 0 0 var(--line); }
.comparison-table thead th:first-child { z-index: 3; background: #f1f3ee; }
.comparison-metric strong, .comparison-value strong { display: block; color: var(--ink); font-size: .81rem; }
.comparison-metric small, .comparison-value small { display: block; margin-top: 4px; color: var(--muted); line-height: 1.45; }
.comparison-value.is-empty { color: var(--soft); }
.comparison-value.flag-high, .comparison-value.flag-low, .comparison-value.flag-abnormal { background: var(--warning-soft); }
.comparison-empty { min-height: 150px; }
.cgm-session-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 9px; }
.cgm-session-card { padding: 14px; background: var(--surface-tint); border: 1px solid #e4e7e0; border-radius: 12px; }
.cgm-session-card time, .cgm-session-card small { display: block; color: var(--muted); font-size: .69rem; }
.cgm-session-card strong { display: block; margin: 6px 0 3px; font-size: 1rem; font-variant-numeric: tabular-nums; }
.cgm-session-card .quality-note { margin-top: 8px; color: var(--warning); }
.archive-tools-heading { margin-top: 36px; }
.archive-source-heading { margin-top: 40px; }
.record-list { display: grid; gap: 9px; }
#documentList.record-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.record-item { min-width: 0; padding: 14px; background: var(--surface-tint); border: 1px solid #e4e7e0; border-radius: 12px; }
.record-item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.record-item strong { display: block; min-width: 0; overflow-wrap: anywhere; font-size: .86rem; }
.record-item p { margin: 5px 0 0; color: var(--muted); font-size: .74rem; overflow-wrap: anywhere; }
.record-item a { flex: 0 0 auto; color: var(--health); font-size: .73rem; font-weight: 720; text-decoration: none; }
.record-item a:hover { text-decoration: underline; text-underline-offset: 3px; }
.source-tag, .status-tag { display: inline-block; margin: 7px 5px 0 0; padding: 3px 7px; border-radius: 999px; background: #e0e3dd; color: #555d57; font-size: .63rem; }
.status-tag.current { color: var(--health); background: var(--health-soft); }
.lab-table-wrap { margin-top: 10px; overflow-x: auto; }
.lab-table { width: 100%; min-width: 420px; border-collapse: collapse; font-size: .71rem; font-variant-numeric: tabular-nums; }
.lab-table th, .lab-table td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.lab-table th { color: var(--muted); font-weight: 650; }
.flag-high, .flag-low, .flag-abnormal { color: var(--warning); font-weight: 750; }
.timeline-list { position: relative; display: grid; gap: 0; padding-left: 18px; }
.timeline-list::before { content: ''; position: absolute; left: 4px; top: 9px; bottom: 9px; width: 1px; background: var(--line-strong); }
.timeline-item { position: relative; padding: 0 0 20px 16px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before { content: ''; position: absolute; left: -18px; top: 7px; width: 7px; height: 7px; border: 2px solid #fffefa; border-radius: 50%; background: var(--health); box-shadow: 0 0 0 1px var(--health); }
.timeline-item time { color: var(--muted); font-size: .69rem; font-variant-numeric: tabular-nums; }
.timeline-item strong { display: block; margin-top: 2px; font-size: .86rem; }
.timeline-item p { margin: 4px 0 0; color: var(--muted); font-size: .74rem; white-space: pre-wrap; }

.export-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.export-card { display: flex; flex-direction: column; }
.export-card.consultation-card { background: linear-gradient(150deg, #fffefa 55%, #eef4ef); }
.export-card > p:not(.eyebrow) { color: var(--muted); font-size: .85rem; text-wrap: pretty; }
.export-icon { display: grid; place-items: center; width: 46px; height: 46px; margin-bottom: 23px; border-radius: 14px; color: var(--health); background: var(--health-soft); font-size: .7rem; font-weight: 820; letter-spacing: .04em; }
.export-icon.dark { color: #fff; background: var(--ink); }
.range-choice-list { display: grid; gap: 8px; margin: 14px 0 18px; }
.range-choice-list legend { margin-bottom: 10px; font-size: .77rem; font-weight: 720; }
.range-choice-list label { position: relative; }
.range-choice-list input { position: absolute; opacity: 0; }
.range-choice-list label > span { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 254, 250, .72); cursor: pointer; transition: border-color .16s ease, background-color .16s ease, box-shadow .16s ease; }
.range-choice-list label > span:hover { border-color: #afb5ad; }
.range-choice-list strong, .range-choice-list small { display: block; }
.range-choice-list strong { font-size: .8rem; }
.range-choice-list small { color: var(--muted); font-size: .67rem; text-align: right; }
.range-choice-list input:focus-visible + span { outline: 3px solid rgba(49, 93, 74, .24); outline-offset: 2px; }
.range-choice-list input:checked + span { border-color: var(--health); box-shadow: inset 3px 0 0 var(--health); background: var(--health-soft); }
.warning-box { display: flex; flex-direction: column; gap: 3px; margin: 18px 0; padding: 14px; color: var(--warning); background: var(--warning-soft); border: 1px solid rgba(163, 104, 43, .1); border-radius: 12px; }
.warning-box strong { font-size: .79rem; }
.warning-box span { font-size: .71rem; }
.backup-list { margin: 0 0 24px; padding-left: 20px; color: var(--muted); font-size: .78rem; }
.backup-list li + li { margin-top: 7px; }
.backup-card .full-button { margin-top: auto; }
.privacy-note { display: flex; align-items: flex-start; gap: 14px; margin-top: 15px; padding: 17px 19px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255, 254, 250, .55); }
.privacy-note .privacy-dot { margin-top: 7px; }
.privacy-note strong { font-size: .83rem; }
.privacy-note p { margin: 3px 0 0; color: var(--muted); font-size: .74rem; }

.login-screen { min-height: calc(100vh - 110px); display: grid; place-items: center; }
.login-card { width: min(100%, 420px); padding: 39px; text-align: center; background: rgba(255, 254, 250, .92); border: 1px solid rgba(201, 205, 197, .85); border-radius: 24px; box-shadow: var(--shadow-raised); backdrop-filter: blur(14px); }
.login-card h1 { font-size: 2.1rem; }
.login-card .field { margin: 24px 0 14px; text-align: left; }
.toast {
  position: fixed; z-index: 80; left: 50%; bottom: -90px; max-width: min(520px, calc(100vw - 32px));
  padding: 12px 16px; transform: translateX(-50%); color: #fff; background: var(--ink);
  border-radius: 12px; box-shadow: 0 12px 34px rgba(31, 37, 33, .24); opacity: 0;
  transition: bottom .25s ease, opacity .25s ease; font-size: .8rem; text-align: center;
}
.toast.is-visible { bottom: 24px; opacity: 1; }
.toast.error { background: var(--danger); }

@media (max-width: 1100px) {
  .section-grid.two-columns, .chart-grid { grid-template-columns: 1fr; }
  .body-module-grid { grid-template-columns: 1fr; }
  .program-card { grid-template-columns: 1fr; gap: 20px; }
  .program-metrics div:first-child { border-left: 0; padding-left: 0; }
  .program-card .primary-button { justify-self: start; }
}

@media (max-width: 960px) {
  .sidebar { display: none; }
  .mobile-header {
    position: sticky; z-index: 18; top: 0; display: flex; align-items: center; justify-content: space-between;
    min-height: calc(62px + env(safe-area-inset-top)); padding: calc(10px + env(safe-area-inset-top)) 20px 10px;
    background: rgba(245, 243, 238, .9); border-bottom: 1px solid rgba(201, 205, 197, .75); backdrop-filter: blur(18px);
  }
  .brand-mobile { padding: 0; color: var(--ink); }
  .brand-mobile .brand-mark { width: 34px; height: 34px; border-radius: 11px; color: #f4f5f1; background: var(--ink); }
  .brand-mobile .brand-mark svg { width: 21px; height: 21px; }
  .brand-mobile span { color: var(--muted); }
  .local-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; color: var(--health); background: var(--health-soft); border-radius: 999px; font-size: .67rem; font-weight: 720; }
  .local-badge i { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
  .main-content { margin-left: 0; padding: 35px 24px calc(100px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    position: fixed; z-index: 30; inset: auto 0 0; display: grid; grid-template-columns: repeat(4, 1fr);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); background: rgba(255, 254, 250, .94);
    border-top: 1px solid rgba(201, 205, 197, .85); box-shadow: 0 -10px 28px rgba(31, 37, 33, .035); backdrop-filter: blur(18px);
  }
  .bottom-nav .nav-item { position: relative; display: flex; flex-direction: column; gap: 2px; min-height: 56px; padding: 5px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-size: .67rem; }
  .bottom-nav .nav-item:hover { color: var(--health); background: transparent; }
  .bottom-nav .nav-item.is-active { color: var(--health); background: transparent; }
  .bottom-nav .nav-icon { width: 30px; height: 30px; border-radius: 10px; transition: background-color .16s ease; }
  .bottom-nav .nav-item.is-active .nav-icon { background: var(--health-soft); }
  .bottom-nav .nav-icon svg { width: 19px; height: 19px; }
  .toast.is-visible { bottom: calc(82px + env(safe-area-inset-bottom)); }
}

@media (max-width: 720px) {
  .main-content { padding: 27px 16px calc(96px + env(safe-area-inset-bottom)); }
  .page-heading { align-items: stretch; flex-direction: column; gap: 19px; margin-bottom: 20px; padding-bottom: 21px; }
  .page-heading h1 { font-size: 2.35rem; }
  .page-heading p:not(.eyebrow) { font-size: .91rem; }
  .date-control { min-width: 0; }
  .page-heading .secondary-button { align-self: flex-start; }
  .field-grid.two-columns, .field-grid.three-columns, .archive-grid, .export-grid, .dual-form-grid { grid-template-columns: 1fr; }
  .context-timeline { grid-template-columns: 1fr; }
  .dual-form-grid .sub-form + .sub-form { border-left: 0; border-top: 1px solid var(--line); }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-item { padding: 15px 17px; }
  .summary-item:nth-child(2n) { border-right: 0; }
  .summary-item:nth-child(n + 3) { border-top: 1px solid var(--line); }
  .record-card, .chart-card, .archive-section, .export-card, .module-cluster { padding: 20px 17px; border-radius: 17px; }
  .program-card { padding: 22px 19px; border-radius: 18px; }
  .program-metrics { grid-template-columns: 1fr; gap: 0; }
  .program-metrics div, .program-metrics div:first-child { padding: 10px 0; border-left: 0; border-top: 1px solid rgba(255, 255, 255, .1); }
  .program-metrics div:first-child { border-top: 0; }
  .module-subcard { padding: 17px 15px; border-radius: 14px; }
  .today-progress { grid-template-columns: auto 1fr; gap: 10px 16px; margin-top: -3px; padding-inline: 2px; }
  .today-progress p { grid-column: 1 / -1; text-align: left; }
  .module-actions { align-items: stretch; flex-direction: column; gap: 12px; }
  .module-actions > span { max-width: none; }
  .module-actions > div { justify-content: flex-end; }
  .fact-form > .primary-button { width: 100%; justify-self: stretch; }
  .fact-row-heading { align-items: flex-start; flex-direction: column; gap: 3px; }
  .fact-row-heading strong { text-align: left; }
  .card-heading { margin-bottom: 18px; }
  .choice-group.three .choice-pill { flex: 1 1 30%; }
  .choice-group.three .choice-pill span { min-width: 0; padding-inline: 8px; }
  .save-bar { bottom: calc(74px + env(safe-area-inset-bottom)); padding: 12px; }
  .save-bar > div { min-width: 0; }
  .save-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .segmented-control { width: 100%; overflow-x: auto; }
  .segmented-control button { flex: 1; }
  .archive-section.wide, .chart-card-wide { grid-column: auto; }
  .comparison-heading { align-items: stretch; flex-direction: column; }
  .comparison-controls { align-items: stretch; }
  .comparison-controls > label { flex: 1; min-width: 0; }
  .comparison-controls .compact-search { width: auto; }
  .comparison-table th:first-child, .comparison-table td:first-child { min-width: 156px; max-width: 170px; }
  .section-heading { align-items: stretch; }
  .medical-chart-grid .chart { min-height: 200px; }
  .lab-chart-heading { align-items: stretch; flex-direction: column; }
  .lab-chart-heading .compact-select { width: 100%; }
  #documentList.record-list { grid-template-columns: 1fr; }
  .login-card { padding: 30px 21px; }
}

@media (max-width: 420px) {
  .mobile-header { padding-inline: 14px; }
  .brand-mobile span { display: none; }
  .summary-item { padding: 14px; }
  .summary-item strong { font-size: 1.08rem; }
  .module-actions > div { display: grid; grid-template-columns: 1fr; }
  .module-actions .primary-button, .module-actions .secondary-button { width: 100%; }
  .save-bar { align-items: center; flex-direction: row; gap: 8px; padding: 10px; }
  .save-bar > div { flex: 1; }
  .save-bar span { display: none; }
  .save-bar .primary-button { width: auto; min-width: 150px; padding-inline: 12px; }
  .diet-row { grid-template-columns: 78px 1fr; }
  .comparison-controls { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition-duration: .01ms !important; }
}
