:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --line: #e0dfd8;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7973;
  --accent: #6250d6;          /* overridden per person */
  --accent-ink: #ffffff;
  --p1: #6250d6;              /* person 1: purple */
  --p2: #b88e8d;              /* person 2: dusty rose */
  --danger: #c4314b;
  --grid: #e7e6e0;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #252523;
    --line: #33332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --p1: #9085e9;
    --p2: #b88e8d;
    --danger: #ef6b7e;
    --grid: #2b2b28;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #252523; --line: #33332f;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e86;
  --p1: #9085e9; --p2: #b88e8d; --danger: #ef6b7e; --grid: #2b2b28;
}
body[data-person="1"] { --accent: var(--p1); }
body[data-person="2"] { --accent: var(--p2); --accent-ink: #1f1716; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 640px; margin: 0 auto; padding: 0 16px 24px; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 1rem; font-weight: 650; margin-bottom: 12px; }
h3 { font-size: .9rem; font-weight: 600; margin: 18px 0 10px; }
.muted { color: var(--muted); font-weight: 400; }
.center { text-align: center; }
button, input, select { font: inherit; color: inherit; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  max-width: 672px; margin: 0 auto;
}
.brand { font-size: 1.2rem; font-weight: 750; letter-spacing: -.01em; }
.person-switch { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 999px; }
.person-switch button {
  border: 0; background: transparent; padding: 6px 14px; border-radius: 999px;
  cursor: pointer; display: flex; align-items: center; gap: 6px; font-weight: 550; color: var(--text-2);
}
.person-switch button .dot { width: 8px; height: 8px; border-radius: 50%; }
.person-switch button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}

/* date nav */
.date-nav { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 12px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.icon-btn:disabled { opacity: .35; cursor: default; }
.date-label { border: 0; background: none; font-weight: 650; font-size: 1.05rem; cursor: pointer; padding: 8px 12px; }
.date-label.static { cursor: default; }

/* summary */
.summary .big { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.summary .big strong { font-size: 2.2rem; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.summary .big span { color: var(--text-2); }
.bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 12px 0 8px; }
.bar > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.bar.over > div { background: var(--danger); }
.summary .sub { display: flex; justify-content: space-between; color: var(--text-2); font-size: .9rem; }

/* forms */
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; margin-bottom: 10px; }
.field.small { flex: 0 0 96px; }
.field label { font-size: .8rem; color: var(--text-2); font-weight: 550; }
input, select {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
.row { display: flex; gap: 10px; align-items: flex-end; }
.btn {
  border: 0; border-radius: 10px; padding: 10px 18px; min-height: 44px;
  font-weight: 650; cursor: pointer; background: var(--surface-2);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn:active { transform: scale(.98); }
.add-btn { margin-bottom: 10px; min-width: 88px; }

.food-field { position: relative; }
.suggest {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 4; margin: 4px 0 0; padding: 4px;
  list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgb(0 0 0 / .15); max-height: 260px; overflow: auto;
}
.suggest li { padding: 10px; border-radius: 8px; display: flex; justify-content: space-between; gap: 8px; cursor: pointer; }
.suggest li.hi, .suggest li:hover { background: var(--surface-2); }
.suggest li span:last-child { color: var(--text-2); white-space: nowrap; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px;
  padding: 8px 12px; cursor: pointer; font-size: .9rem; display: flex; gap: 6px; align-items: baseline;
}
.chip small { color: var(--text-2); }
.chip:active { background: var(--line); }

/* meal list */
.meal { margin-bottom: 14px; }
.meal header { display: flex; justify-content: space-between; padding: 0 4px 6px; font-weight: 650; }
.meal header span { color: var(--text-2); font-weight: 500; font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line);
}
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { font-size: .8rem; color: var(--muted); }
.list .kcal { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.del {
  border: 0; background: none; color: var(--muted); font-size: 1.3rem; width: 36px; height: 36px;
  border-radius: 50%; cursor: pointer; flex: none;
}
.del:hover { color: var(--danger); background: var(--surface-2); }
.list input.inline { width: 90px; min-height: 36px; padding: 6px 8px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* segmented control */
.seg { display: flex; background: var(--surface-2); padding: 3px; border-radius: 12px; margin: 6px 0 4px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px; cursor: pointer; font-weight: 550; color: var(--text-2); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat .v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat .l { font-size: .75rem; color: var(--text-2); }

/* charts */
.chart { position: relative; width: 100%; min-height: 220px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .goal { stroke: var(--text-2); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart .goal-label { fill: var(--text-2); font-size: 11px; }
.chart .mark { fill: var(--accent); }
.chart .mark.dim { opacity: .35; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .empty-msg { fill: var(--muted); font-size: 13px; }
.tip {
  position: absolute; pointer-events: none; z-index: 3;
  background: var(--text); color: var(--surface); padding: 6px 10px; border-radius: 8px;
  font-size: .8rem; white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
  box-shadow: 0 4px 12px rgb(0 0 0 / .2);
}
.tip b { font-variant-numeric: tabular-nums; }
.table-view { margin-top: 10px; font-size: .9rem; }
.table-view summary { cursor: pointer; color: var(--text-2); }
.table-view table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.table-view td, .table-view th { text-align: left; padding: 6px 4px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.table-view th { color: var(--text-2); font-weight: 550; }

/* profiles */
.profile-row { display: flex; gap: 10px; align-items: flex-end; }
.profile-row .dot { width: 12px; height: 12px; border-radius: 50%; margin-bottom: 26px; flex: none; }
.filter { margin-bottom: 8px; }

/* bottom tabs */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: flex; justify-content: center; gap: 0;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; max-width: 160px; border: 0; background: none; padding: 8px 0 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .75rem; color: var(--muted); cursor: pointer; font-weight: 550;
}
.tabbar .ti { font-size: 1.2rem; line-height: 1.2; }
.tabbar button.active { color: var(--accent); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 12px; z-index: 10;
  display: flex; gap: 14px; align-items: center; box-shadow: 0 6px 20px rgb(0 0 0 / .25);
  max-width: calc(100% - 32px);
}
.toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0; }
.toast.error { background: var(--danger); color: #fff; }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { font-size: 1.5rem; }
.login-card p { margin: 0; }
.login-card .btn.primary { background: var(--p1); color: #fff; }
.error { color: var(--danger); }

@media (max-width: 380px) {
  .stats { gap: 6px; }
  .stat { padding: 10px 8px; }
  .stat .v { font-size: 1.1rem; }
  .person-switch button { padding: 6px 10px; }
}
