:root {
  --bg: #fbf7ef; --card: #ffffff; --ink: #1b1a17; --muted: #645f55; --line: #e4dccb;
  --accent: #1f6b3a; --accent-ink: #ffffff; --accent-soft: #e3f1e6;
  --warn: #8a5a00; --warn-soft: #fdf0cf; --danger: #b3261e; --danger-soft: #fbe4e2;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141310; --card: #1e1c18; --ink: #f2eee6; --muted: #a9a294; --line: #37332b;
    --accent: #6fcf8e; --accent-ink: #0d1f13; --accent-soft: #1d2f22;
    --warn: #f0c35a; --warn-soft: #33290f; --danger: #ff8a80; --danger-soft: #3a1b18;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; letter-spacing: -0.02em; }
h2 { font-size: 15px; font-weight: 700; }
h3 { font-size: 17px; font-weight: 700; line-height: 1.25; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); font-size: 14px; }

.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: 12px 16px 10px; border-bottom: 1px solid var(--line);
  padding-top: calc(12px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.logo { width: 22px; height: 22px; border-radius: 50% 50% 50% 12%; background: var(--accent); transform: rotate(-20deg); }
.tag { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--accent); border: 1px solid var(--accent); border-radius: 99px; padding: 2px 8px; }

.tabs { display: flex; gap: 8px; }
.tabs button {
  flex: 1; min-height: 44px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 8px;
}
.tabs button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

main { max-width: 640px; margin: 0 auto; padding: 14px 16px 40px; display: grid; gap: 14px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.person-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.person-head strong { font-size: 18px; }
.stats { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; color: var(--muted); }
.stats b { color: var(--ink); font-weight: 600; }
.hint { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 14.5px; font-weight: 600; }
.alert { background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.alert button { flex: none; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg button { min-height: 46px; border-radius: 10px; border: 1.5px solid var(--line); background: transparent; font-weight: 600; font-size: 14px; padding: 4px; }
.seg button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.add { display: flex; gap: 8px; }
.add input { flex: 1; min-width: 0; min-height: 46px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg); padding: 0 12px; }
.add input:focus, select:focus, dialog input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.add button, .primary { min-height: 46px; padding: 0 16px; border-radius: 10px; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
.ghost { min-height: 46px; padding: 0 16px; border-radius: 10px; border: 1.5px solid var(--line); background: transparent; font-weight: 600; }
.link { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 6px 0; min-height: 36px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 99px; border: 1.5px solid var(--line); background: var(--bg); font-size: 14px; font-weight: 500; }
.chip.have { background: var(--accent-soft); border-color: transparent; font-weight: 600; }
.chip.unknown { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.chip .x { font-size: 16px; line-height: 1; opacity: 0.6; }
.quick .chip { border-style: dashed; color: var(--muted); }
.suggest .chip { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.results { display: grid; gap: 10px; }
.toggle { font-size: 13.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; min-height: 36px; }
#cards { display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; }
.card.best { border: 2px solid var(--accent); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.badge.need { background: var(--danger-soft); color: var(--danger); }
.badge.plain { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.portion { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.portion li { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.portion li span:last-child { color: var(--muted); font-size: 13px; white-space: nowrap; }
.portion li.buy span:first-child { color: var(--danger); font-weight: 600; }
.macros { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; text-align: center; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 8px 0; }
.macros div { display: grid; }
.macros b { font-size: 15px; }
.macros span { font-size: 11px; color: var(--muted); }
.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 14px; }
.notes li { padding-left: 20px; position: relative; }
.notes li::before { position: absolute; left: 0; font-weight: 700; }
.notes li.ok::before { content: "✓"; color: var(--accent); }
.notes li.tip::before { content: "!"; color: var(--warn); left: 4px; }
.notes li.tip { color: var(--muted); }
.extra { font-size: 13.5px; color: var(--muted); }
.empty { text-align: center; padding: 26px 14px; color: var(--muted); border: 1.5px dashed var(--line); border-radius: var(--radius); }

.rules summary { font-weight: 700; font-size: 15px; cursor: pointer; min-height: 30px; }
.rules ul { margin: 0; padding-left: 18px; font-size: 14px; color: var(--muted); display: grid; gap: 4px; }
.disclaimer { font-size: 12.5px; color: var(--muted); text-align: center; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(92vw, 460px); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgb(0 0 0 / 0.55); }
dialog form { padding: 18px; display: grid; gap: 12px; }
dialog label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
dialog input:not([type="checkbox"]), dialog select { min-height: 44px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--bg); padding: 0 10px; font-weight: 400; color: var(--ink); width: 100%; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; }
legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 4px; }
.checks { display: grid; gap: 2px; }
.checks label { display: flex; flex-direction: row; align-items: center; gap: 10px; min-height: 38px; font-size: 15px; font-weight: 400; color: var(--ink); }
.checks input { width: 20px; height: 20px; accent-color: var(--accent); }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

@media (max-width: 380px) {
  .macros { grid-template-columns: repeat(3, 1fr); row-gap: 8px; }
  .seg button { font-size: 13px; }
}

/* ---------- chat screen ---------- */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.small { font-size: 13px; min-height: 28px; padding: 2px 0; }
body.chat { min-height: 100dvh; display: flex; flex-direction: column; }
body.chat .top { padding-bottom: 8px; }
body.chat main { flex: 1; width: 100%; max-width: 640px; display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; align-content: start; }
.person-strip { display: grid; gap: 6px; margin-top: 8px; max-width: 640px; }
.person-strip:empty { display: none; }
.person-line { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.person-strip .hint, .person-strip .alert { font-size: 13.5px; padding: 8px 10px; }
.person-strip .alert .ghost { min-height: 34px; padding: 0 12px; }

.msg { max-width: 88%; padding: 10px 13px; border-radius: 16px; font-size: 15.5px; overflow-wrap: anywhere; display: grid; gap: 6px; }
.msg p { margin: 0; }
.msg ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.msg.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg.thinking { color: var(--muted); font-style: italic; }
.msg.error { align-self: stretch; max-width: none; background: var(--danger-soft); color: var(--danger); font-size: 14.5px; }
.msg .warn { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 6px 8px; font-size: 13.5px; }
.photo-tag { font-size: 12px; font-weight: 700; opacity: 0.85; }
#thread .empty { margin: auto 0; display: grid; gap: 6px; }
#thread .empty strong { color: var(--ink); font-size: 17px; }

.composer { position: sticky; bottom: 0; z-index: 5; background: var(--bg); border-top: 1px solid var(--line);
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.composer > * { width: 100%; max-width: 608px; margin: 0 auto; }
.shortcuts { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.shortcuts::-webkit-scrollbar { display: none; }
.shortcuts .chip { flex: none; background: var(--card); }
.chip:disabled, .tabs button:disabled { opacity: 0.5; }
.attach { display: flex; align-items: center; gap: 12px; }
.attach[hidden] { display: none; }
.attach img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.send { display: flex; align-items: flex-end; gap: 8px; }
.send textarea { flex: 1; min-width: 0; min-height: 46px; max-height: 140px; resize: none; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--ink); padding: 11px 12px; font: inherit; line-height: 1.35; }
.send textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.photo-btn { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); cursor: pointer; }
.photo-btn:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.send .primary:disabled { opacity: 0.5; }
.composer .disclaimer { font-size: 11.5px; }
dialog .rules summary { font-size: 13px; color: var(--muted); }

/* ---------- family chat: header actions, log lines, today sheet ---------- */
.brand .tag { margin-left: 0; }
.head-actions { margin-left: auto; display: flex; gap: 8px; }
.mini { min-height: 36px; padding: 0 12px; font-size: 14px; }
.sheet { padding: 18px; display: grid; gap: 12px; }
.sheet h2 { margin: 0; }
.photo-btn[aria-pressed="true"] { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
button.photo-btn { color: inherit; padding: 0; }
.logged { border-top: 1px solid var(--line); padding-top: 6px; display: grid; gap: 4px; font-size: 13.5px; color: var(--muted); }
.logged div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.logged b { color: var(--ink); font-weight: 600; }
.logged .gone { text-decoration: line-through; }
.today { display: grid; gap: 14px; max-height: 62vh; overflow-y: auto; }
.today section { display: grid; gap: 6px; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.today section:last-child { border-bottom: 0; padding-bottom: 0; }
.today h3 { margin: 0; font-size: 16px; }
.meter { display: grid; grid-template-columns: 5.2em 1fr auto; align-items: center; gap: 8px; font-size: 13.5px; }
.meter span:first-child { color: var(--muted); }
.meter .bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.meter .bar i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.meter.over .bar i { background: var(--danger); }
.meter.over span:last-child { color: var(--danger); font-weight: 600; }
.meter span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.today ul { margin: 2px 0 0; padding: 0; list-style: none; display: grid; gap: 2px; font-size: 13.5px; }
.today li { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.today li span:first-child { overflow-wrap: anywhere; }
.today .none { color: var(--muted); font-size: 13.5px; }
.family { display: grid; gap: 8px; }
.family div { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.family small { display: block; color: var(--muted); font-size: 13px; }
.composer { grid-template-columns: minmax(0, 1fr); }
.send .primary { flex: none; }
.logged button, .logged div > span:last-child:not(:first-child), .today li button { flex: none; white-space: nowrap; }
.today { padding-right: 12px; }
