:root {
  --teal-950: #063f3f;
  --teal-800: #0b5c5b;
  --teal-700: #08706d;
  --teal-100: #dcefed;
  --coral: #f47663;
  --coral-soft: #fff0ed;
  --ink: #173332;
  --muted: #637b79;
  --line: #dce6e4;
  --surface: #ffffff;
  --canvas: #f4f7f6;
  --good: #21865f;
  --bad: #c74747;
  --warning: #b37714;
  --shadow: 0 12px 32px rgba(12, 65, 63, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at top right, #e3f2f0 0, transparent 31rem), var(--canvas); }
button, input, select, textarea { font: inherit; }
button, .button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid rgba(244, 118, 99, .45); outline-offset: 2px; }
a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .45rem; font-size: clamp(1.6rem, 4vw, 2.35rem); line-height: 1.1; }
h2 { margin-bottom: .5rem; font-size: 1.2rem; }
h3 { font-size: 1rem; }
small, .small { font-size: .82rem; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 .35rem; color: var(--teal-700); font-size: .73rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.topbar { position: sticky; z-index: 20; top: 0; height: 68px; padding: 0 max(1rem, calc((100vw - 1180px) / 2)); display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.92); border-bottom: 1px solid rgba(220,230,228,.8); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: .7rem; font-weight: 850; text-decoration: none; letter-spacing: -.02em; }
.brand img { width: 39px; height: 39px; border-radius: 10px; }
.top-actions { display: flex; gap: .7rem; align-items: center; }
.app-shell { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: 1.3rem 0 7rem; }
.page { display: none; animation: fade-in .18s ease-out; }
.page.active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } }

.date-toolbar { display: flex; justify-content: center; align-items: center; gap: .6rem; margin-bottom: 1rem; }
.date-title { min-width: 12rem; padding: .55rem 1rem; border: 0; border-radius: 999px; color: var(--ink); background: transparent; font-weight: 750; }
.icon-button { width: 42px; height: 42px; display: inline-grid; place-items: center; border: 0; border-radius: 50%; color: var(--teal-800); background: transparent; font-size: 1.65rem; }
.icon-button:hover { background: var(--teal-100); }

.week-strip { display: grid; grid-template-columns: repeat(7, minmax(68px, 1fr)); gap: .55rem; margin: 0 0 1.2rem; overflow-x: auto; padding: .2rem .1rem .5rem; scrollbar-width: thin; }
.day-progress { border: 1px solid var(--line); border-radius: 18px; padding: .65rem .35rem; min-width: 68px; text-align: center; background: rgba(255,255,255,.72); cursor: pointer; }
.day-progress.selected { border-color: var(--teal-700); box-shadow: 0 0 0 2px rgba(8,112,109,.12); background: white; }
.day-progress .day-name { display: block; font-size: .7rem; color: var(--muted); text-transform: uppercase; }
.day-progress .day-num { display: block; margin-top: .2rem; font-weight: 800; }
.mini-ring { --progress: 0; --ring: var(--line); width: 42px; height: 42px; display: grid; place-items: center; margin: .4rem auto 0; border-radius: 50%; background: conic-gradient(var(--ring) calc(min(var(--progress), 1) * 1turn), #e9efee 0); }
.mini-ring::after { content: attr(data-text); width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: white; font-size: .62rem; font-weight: 750; }
.mini-ring.good, .progress-ring.good { --ring: var(--good); }
.mini-ring.bad, .progress-ring.bad { --ring: var(--bad); }
.mini-ring.neutral, .progress-ring.neutral { --ring: var(--teal-700); }

.card { border: 1px solid var(--line); border-radius: 24px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); }
.hero-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 1rem; }
.progress-card { min-height: 230px; padding: 1.5rem; display: flex; align-items: center; gap: 1.5rem; }
.progress-card h1 small { color: var(--muted); font-size: .46em; font-weight: 650; }
.progress-ring { --progress: 0; --ring: var(--teal-700); flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: conic-gradient(var(--ring) calc(min(var(--progress), 1) * 1turn), #e6efee 0); }
.progress-ring.large { width: 154px; height: 154px; }
.progress-ring::after { content: attr(data-text); width: 118px; height: 118px; display: grid; place-items: center; border-radius: 50%; background: white; font-size: 1.45rem; font-weight: 850; }
.summary-grid { display: grid; grid-template-columns: 1fr; gap: .65rem; }
.summary-card { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.15rem; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,.9); }
.summary-card span { color: var(--muted); font-size: .84rem; }
.summary-card strong { font-size: 1.18rem; }

.quick-actions { display: flex; flex-wrap: wrap; gap: .7rem; margin: 1rem 0; }
button, .button { min-height: 44px; padding: .68rem 1rem; border-radius: 12px; border: 1px solid transparent; font-weight: 750; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .3rem; }
.primary { color: white; background: var(--teal-800); border-color: var(--teal-800); }
.primary:hover { background: var(--teal-950); }
.secondary { color: var(--teal-800); background: white; border-color: var(--line); }
.secondary:hover { background: var(--teal-100); border-color: #bddbd7; }
.danger { color: #a62f2f; background: white; border-color: #efc9c9; }
.danger:hover { background: #fff0f0; }
.text-button { min-height: auto; padding: .35rem 0; border: 0; border-radius: 0; color: var(--teal-700); background: transparent; }
.wide { width: 100%; }

.section-card { padding: 1.25rem; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.section-heading h2 { margin: 0; }
.timeline-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.column-title { padding: .5rem .7rem; border-radius: 10px; }
.intake-col { color: var(--teal-800); background: var(--teal-100); }
.output-col { color: #a9493b; background: var(--coral-soft); }
.entry-list { display: grid; gap: .55rem; }
.entry { min-height: 64px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .7rem; padding: .65rem .7rem; border: 1px solid var(--line); border-radius: 14px; background: white; }
.entry-time { font-size: .78rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.entry-main strong, .entry-main span { display: block; }
.entry-main span { margin-top: .15rem; font-size: .76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34ch; }
.entry-volume { text-align: right; font-weight: 800; white-space: nowrap; }
.entry-delete { width: 30px; height: 30px; min-height: 30px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--muted); opacity: .45; }
.entry:hover .entry-delete, .entry-delete:focus { opacity: 1; color: var(--bad); background: #fff0f0; }
.empty-state { padding: 1.2rem; border: 1px dashed #cbd8d6; border-radius: 14px; text-align: center; color: var(--muted); font-size: .86rem; }

.page-heading { margin: .7rem 0 1.2rem; }
.health-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.health-card { padding: 1rem; display: grid; grid-template-columns: 1fr auto; gap: .5rem; }
.health-card .value { font-size: 1.35rem; font-weight: 850; }
.health-card .meta { color: var(--muted); font-size: .8rem; }

.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; align-items: start; }
.form-card { padding: 1.25rem; }
.form-card h2 { margin-bottom: 1rem; }
.form-card label, .dialog-form label { display: grid; gap: .35rem; margin-bottom: .85rem; color: #35504e; font-size: .84rem; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 46px; padding: .65rem .72rem; color: var(--ink); background: white; border: 1px solid #cbd8d6; border-radius: 10px; }
textarea { resize: vertical; }
fieldset { margin: 0 0 1rem; padding: 0; border: 0; }
legend { margin-bottom: .45rem; color: #35504e; font-size: .84rem; font-weight: 750; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.segmented label { margin: 0; }
.segmented input { position: absolute; opacity: 0; width: 1px; }
.segmented span { min-height: 48px; padding: .65rem; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 10px; text-align: center; font-size: .8rem; }
.segmented input:checked + span { color: var(--teal-800); border-color: var(--teal-700); background: var(--teal-100); box-shadow: inset 0 0 0 1px var(--teal-700); }
.day-selector { display: grid; grid-template-columns: repeat(7, 1fr); gap: .25rem; }
.day-selector legend { grid-column: 1/-1; }
.day-selector label { margin: 0; }
.day-selector input { position: absolute; opacity: 0; width: 1px; }
.day-selector span { min-height: 40px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; font-size: .68rem; }
.day-selector input:checked + span { color: white; background: var(--teal-800); border-color: var(--teal-800); }
.check-row { grid-template-columns: auto 1fr !important; align-items: center; }
.check-row input, .check-list input { width: 20px; min-height: 20px; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
.form-actions { grid-column: 1/-1; text-align: right; }
.data-section, .medical-note.card { margin-top: 1rem; }
.button-row { display: flex; flex-wrap: wrap; gap: .5rem; }
hr { margin: 1.1rem 0; border: 0; border-top: 1px solid var(--line); }
.medical-note { color: #526765; font-size: .78rem; line-height: 1.5; }

dialog { width: min(520px, calc(100% - 1.5rem)); max-height: calc(100vh - 2rem); padding: 0; color: var(--ink); border: 0; border-radius: 22px; box-shadow: 0 28px 80px rgba(4,47,46,.3); }
dialog::backdrop { background: rgba(6,39,38,.55); backdrop-filter: blur(3px); }
.dialog-form { padding: 1.25rem; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.dialog-heading h2 { margin: 0; font-size: 1.35rem; }
.dialog-close { width: 38px; height: 38px; min-height: 38px; padding: 0; border: 0; border-radius: 50%; background: var(--canvas); color: var(--muted); font-size: 1.6rem; }
.check-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: .35rem; margin-bottom: .75rem; }
.check-list label { grid-template-columns: auto 1fr; align-items: center; font-size: .72rem; }

.bottom-nav { position: fixed; z-index: 30; left: 50%; bottom: max(.8rem, env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(420px, calc(100% - 1.5rem)); padding: .35rem; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid rgba(220,230,228,.85); border-radius: 18px; background: rgba(255,255,255,.95); box-shadow: 0 12px 35px rgba(6,63,63,.18); backdrop-filter: blur(16px); }
.bottom-nav a { padding: .45rem; display: grid; place-items: center; gap: .1rem; border-radius: 13px; color: var(--muted); text-decoration: none; font-size: .68rem; font-weight: 750; }
.bottom-nav a span { font-size: 1.15rem; }
.bottom-nav a.active { color: var(--teal-800); background: var(--teal-100); }
.toast-region { position: fixed; z-index: 80; right: 1rem; bottom: 6rem; display: grid; gap: .5rem; }
.toast { max-width: 340px; padding: .8rem 1rem; color: white; border-radius: 12px; background: var(--teal-950); box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
.toast.error { background: #9e3434; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
#confetti { position: fixed; z-index: 70; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.login-page { display: grid; place-items: center; padding: 1rem; background: linear-gradient(135deg, #073f3f, #0b6a67); }
.login-shell { width: min(440px, 100%); }
.login-card { padding: clamp(1.4rem, 5vw, 2.2rem); border-radius: 28px; background: white; box-shadow: 0 30px 90px rgba(0,0,0,.22); }
.login-logo { width: 64px; height: 64px; margin-bottom: 1.2rem; border-radius: 16px; }
.stack-form { display: grid; gap: .1rem; margin: 1.3rem 0; }
.stack-form label { display: grid; gap: .4rem; margin-bottom: .85rem; font-size: .85rem; font-weight: 750; }
.notice { margin: 1rem 0; padding: .7rem .8rem; border-radius: 10px; }
.notice.error { color: #842d2d; background: #fff0f0; border: 1px solid #efc9c9; }

@media (min-width: 900px) {
  .bottom-nav { top: 82px; bottom: auto; left: max(1rem, calc((100vw - 1420px) / 2)); transform: none; width: 150px; grid-template-columns: 1fr; }
  .bottom-nav a { min-height: 62px; grid-template-columns: 28px 1fr; justify-content: start; text-align: left; font-size: .78rem; }
  .app-shell { padding-left: 170px; }
}

@media (max-width: 700px) {
  .desktop-only { display: none; }
  .app-shell { width: min(100% - 1rem, 1180px); padding-top: .7rem; }
  .topbar { height: 60px; padding-inline: .7rem; }
  .brand img { width: 35px; height: 35px; }
  .hero-grid { grid-template-columns: 1fr; }
  .progress-card { min-height: auto; padding: 1rem; gap: 1rem; }
  .progress-ring.large { width: 112px; height: 112px; }
  .progress-ring::after { width: 84px; height: 84px; font-size: 1.08rem; }
  .summary-grid { grid-template-columns: repeat(3, 1fr); gap: .35rem; }
  .summary-card { padding: .7rem .45rem; display: grid; gap: .25rem; text-align: center; }
  .summary-card strong { font-size: .92rem; }
  .quick-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .quick-actions button:first-child { grid-column: 1/-1; }
  .timeline-grid { gap: .45rem; }
  .section-card { padding: .75rem; border-radius: 18px; }
  .section-heading { align-items: start; }
  .section-heading > .small { display: none; }
  .entry { grid-template-columns: 1fr auto; gap: .25rem; padding: .55rem; }
  .entry-time { grid-column: 1/-1; }
  .entry-main span { max-width: 15ch; }
  .entry-delete { grid-column: 2; }
  .health-grid, .settings-grid { grid-template-columns: 1fr; }
  .form-actions { grid-column: auto; }
  .form-actions button { width: 100%; }
  .check-list { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .brand span { font-size: .92rem; }
  .progress-card { display: grid; grid-template-columns: auto 1fr; }
  .progress-ring.large { width: 96px; height: 96px; }
  .progress-ring::after { width: 72px; height: 72px; }
  .timeline-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .two-cols { grid-template-columns: 1fr; gap: 0; }
  dialog { max-height: calc(100vh - .75rem); }
}

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

