:root {
  color-scheme: light;
  --paper: #f5f7f6;
  --surface: #ffffff;
  --ink: #1e2725;
  --muted: #5c6864;
  --line: #d8e0dd;
  --teal: #087e78;
  --teal-dark: #055e5a;
  --teal-soft: #e6f4f2;
  --amber-soft: #fef5e6;
  --amber-ink: #8a5300;
  --danger: #a33b32;
  font-family: "Segoe UI", "Malgun Gothic", -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); line-height: 1.55; }
body.has-bottom-nav { padding-bottom: 4.5rem; }
a { color: var(--teal-dark); text-underline-offset: .18em; }
button, input, textarea, select { font: inherit; }

button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 2.55rem; max-width: 100%; padding: .5rem .95rem;
  border: 1px solid var(--teal); border-radius: .55rem;
  background: var(--teal); color: #fff; font-weight: 650; cursor: pointer;
  text-decoration: none; overflow-wrap: anywhere; transition: background .15s ease;
}
button:hover, .button:hover { background: var(--teal-dark); }
button:disabled { cursor: wait; opacity: .65; }
button.small, .button.small { min-height: 2.15rem; padding: .35rem .7rem; font-size: .88rem; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid #e29b38; outline-offset: 2px;
}

input, textarea, select {
  width: 100%; min-width: 0; padding: .6rem .7rem;
  border: 1px solid #b5c2bc; border-radius: .45rem; background: #fff; color: var(--ink);
}
input[type="checkbox"], input[type="radio"] { width: 1.1rem; height: 1.1rem; }
textarea { resize: vertical; }
label { display: grid; gap: .3rem; font-weight: 600; font-size: .94rem; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .15rem; font-size: clamp(1.45rem, 4vw, 2rem); line-height: 1.25; }
h2 { margin-bottom: .65rem; font-size: 1.18rem; }
h3 { margin-bottom: .45rem; font-size: 1.02rem; }

/* App Header & Navigation */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .96); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.app-header-inner {
  width: min(1040px, calc(100% - 2rem)); margin: 0 auto; padding: .7rem 0;
  display: flex; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap;
}
.brand-link { font-size: 1.2rem; font-weight: 800; color: var(--ink); text-decoration: none; }
.primary-nav { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.primary-nav a {
  padding: .45rem .85rem; border-radius: .5rem; text-decoration: none;
  color: var(--muted); font-weight: 650; font-size: .95rem;
}
.primary-nav a:hover { background: #edf2f0; color: var(--ink); }
.primary-nav a.active { background: var(--teal-soft); color: var(--teal-dark); font-weight: 750; }
.header-tools { display: flex; align-items: center; gap: .5rem; }
.header-tools form { margin: 0; }

/* Mobile Bottom Nav */
.mobile-bottom-nav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  grid-template-columns: repeat(4, 1fr); box-shadow: 0 -2px 10px rgba(0,0,0,.05);
}
.mobile-bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: .45rem .2rem; text-decoration: none; color: var(--muted); font-size: .75rem; font-weight: 650;
}
.mobile-bottom-nav a.active { color: var(--teal-dark); background: var(--teal-soft); font-weight: 800; }
.nav-icon { font-size: 1.05rem; line-height: 1.1; margin-bottom: .1rem; }

.shell { width: min(1040px, calc(100% - 2rem)); margin: 0 auto; padding: 1.4rem 0 3rem; }
.shell.narrow { width: min(680px, calc(100% - 2rem)); }
.skip-link { position: absolute; left: -9999px; top: .5rem; z-index: 50; padding: .6rem; background: #fff; }
.skip-link:focus { left: .5rem; }

.topbar, .section-heading, .actions, .inline-form, .topbar nav {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
}
.topbar { margin-bottom: .9rem; }
.eyebrow { margin-bottom: .2rem; color: var(--teal-dark); font-size: .73rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.disclaimer { padding: .65rem .95rem; border-left: 4px solid var(--teal); border-radius: 0 .45rem .45rem 0; background: var(--teal-soft); font-size: .88rem; margin-bottom: 1rem; }

.panel {
  min-width: 0; margin: 1rem 0; padding: clamp(1rem, 2.5vw, 1.35rem);
  border: 1px solid var(--line); border-radius: .85rem; background: var(--surface);
  box-shadow: 0 2px 10px rgba(25, 42, 38, .04);
}
.columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin: 1rem 0; }
.columns .panel { margin: 0; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
.stack { display: grid; gap: .75rem; }
.inline-form { justify-content: flex-start; }
.inline-form label { display: block; }
.inline-form input, .inline-form select { width: auto; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .65rem; }
.stat { min-width: 0; padding: .8rem .85rem; border-radius: .65rem; background: #f2f6f4; border: 1px solid #e4ece9; }
.stat span, .stat strong { display: block; }
.stat span, .muted { color: var(--muted); font-size: .88rem; }
.stat strong { margin-top: .2rem; font-size: 1.08rem; overflow-wrap: anywhere; }

/* Goal Progress Bar & Badges */
.progress-track { width: 100%; height: .75rem; border-radius: 999px; background: #e3ebe8; overflow: hidden; margin: .6rem 0; }
.progress-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, #0b9a92, #05635f); transition: width .3s ease; }
.kind, .tag, .badge {
  display: inline-flex; align-items: center; width: fit-content;
  padding: .15rem .55rem; border-radius: 999px; background: var(--teal-soft);
  color: var(--teal-dark); font-size: .78rem; font-weight: 750;
}
.badge.warn { background: var(--amber-soft); color: var(--amber-ink); }
.badge.done { background: #e1f5e8; color: #166534; }

/* Sub-tabs & Quick Chips */
.subtabs { display: flex; gap: .45rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; padding-bottom: .5rem; flex-wrap: wrap; }
.subtab-btn {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  min-height: 2.1rem; padding: .35rem .8rem; border-radius: .45rem; font-weight: 700;
}
.subtab-btn:hover { background: #eef3f1; color: var(--ink); }
.subtab-btn.active { background: var(--teal-soft); color: var(--teal-dark); border-color: #b7deda; }
.tab-pane[hidden] { display: none; }

.chip-row { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .4rem; }
.chip-btn {
  min-height: 1.85rem; padding: .2rem .6rem; border-radius: 999px;
  border: 1px solid var(--line); background: #f8faf9; color: var(--ink); font-size: .8rem; font-weight: 600;
}
.chip-btn:hover { background: var(--teal-soft); border-color: var(--teal); color: var(--teal-dark); }

/* Timeline & Lists */
.empty-state { padding: 1.25rem; border: 1px dashed var(--line); border-radius: .65rem; color: var(--muted); text-align: center; }
.empty-state p { margin: .25rem 0 0; }
.timeline { display: grid; gap: .6rem; margin: 0; padding: 0; list-style: none; }
.timeline-item { display: flex; align-items: flex-start; gap: .75rem; min-width: 0; padding: .85rem 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.timeline-copy { display: grid; flex: 1 1 16rem; min-width: 0; gap: .18rem; }
.timeline-meta { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.timeline-copy strong { overflow-wrap: anywhere; }
.entry-actions { display: flex; gap: .45rem; align-items: center; flex-shrink: 0; }
.full-edit-box {
  flex: 1 1 100%; display: grid; gap: .75rem; margin-top: .45rem; padding: .95rem;
  border: 1px solid var(--line); border-radius: .65rem; background: #f7fbfa;
}
.full-edit-box[hidden], .edit-meal-row[hidden] { display: none !important; }
.edit-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .65rem; align-items: end; }
.edit-meal-row { grid-template-columns: 1.4fr .9fr 1.7fr; }
.macro-inputs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .35rem; }

.schedule-list, .tip-list { margin: 0; padding: 0; list-style: none; display: grid; gap: .55rem; }
.schedule-item {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .75rem .9rem; border: 1px solid var(--line); border-radius: .65rem; background: #fbfdfc; flex-wrap: wrap;
}
.tip-list li {
  padding: .65rem .85rem; border-left: 3px solid var(--teal); background: #f6faf8; border-radius: 0 .45rem .45rem 0; font-size: .93rem;
}

/* InBody Gauge Bars */
.gauge-row { display: grid; grid-template-columns: 7.5rem 1fr 5.5rem; align-items: center; gap: .7rem; margin: .45rem 0; font-size: .92rem; }
.gauge-bar { height: .65rem; background: #e6ecea; border-radius: 999px; overflow: hidden; }
.gauge-bar > span { display: block; height: 100%; background: var(--teal); border-radius: 999px; }

.button.secondary, button.secondary { border-color: var(--line); background: #fff; color: var(--ink); }
.button.secondary:hover, button.secondary:hover { border-color: var(--teal); color: var(--teal-dark); background: #f7fbfa; }
.button.danger, button.danger { border-color: #e3c3bf; background: #fff; color: var(--danger); }
.button.danger:hover, button.danger:hover { background: #fff1ef; }

.message { min-height: 1.3em; margin: .35rem 0 0; color: var(--teal-dark); font-size: .9rem; font-weight: 600; }
.message.error { color: var(--danger); }
.preview-fields { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: .65rem; }
.confirm-line { display: flex; align-items: center; gap: .5rem; cursor: pointer; }
.missing-list { color: var(--danger); margin: .4rem 0; padding-left: 1.2rem; }
blockquote { margin: .6rem 0; padding-left: 1rem; border-left: 3px solid var(--teal); overflow-wrap: anywhere; }
pre.code-box {
  padding: .8rem; border-radius: .55rem; background: #1c2624; color: #e7f3f0;
  font-size: .82rem; overflow-x: auto; line-height: 1.45; margin: .4rem 0;
}

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: .92rem; }
th, td { padding: .65rem .5rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.wrap-cell { white-space: normal; min-width: 160px; }
.weight-chart { display: block; width: min(100%, 540px); height: auto; margin: .8rem auto; }
.chart-axis { stroke: var(--line); stroke-width: 2; }
.chart-line { fill: none; stroke: var(--teal); stroke-width: 2.2; stroke-dasharray: 4 2; }
.chart-point { fill: var(--teal); stroke: #fff; stroke-width: 2; }

@media (max-width: 680px) {
  .primary-nav, .split-btn { display: none; }
  .mobile-bottom-nav { display: grid; }
  .shell { width: calc(100% - 1.4rem); padding-top: 1rem; }
  .app-header-inner { width: calc(100% - 1.4rem); }
  .columns, .grid-3, .edit-grid, .edit-meal-row { grid-template-columns: 1fr; }
  .preview-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .preview-fields label:first-child { grid-column: 1 / -1; }
  .timeline-item { flex-wrap: wrap; }
  .entry-edit { flex: 1 1 100%; }
  .gauge-row { grid-template-columns: 5.8rem 1fr 4.8rem; font-size: .85rem; }
  .inline-form { width: 100%; }
  .inline-form input[type="date"] { flex: 1 1 auto; }
}
