:root {
  color-scheme: light;
  --bg: #f5f5f3;        /* warm off-white */
  --card: #ffffff;
  --text: #16140f;      /* near-black, warm */
  --muted: #8c8c90;
  --line: #ececea;
  --ink: #16140f;       /* primary buttons / active */
  --green: #25b06b;     /* fiber / health accent */
  --green-soft: #e7f6ee;
  --radius: 22px;
  --radius-sm: 14px;
  --tabbar-h: 64px;
  --shadow-sm: 0 1px 2px rgba(22, 20, 15, .05);
  --shadow: 0 1px 2px rgba(22, 20, 15, .04), 0 10px 30px rgba(22, 20, 15, .06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top);
  min-height: 100dvh;
}

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: 14px 20px 8px; background: var(--bg); }
.topbar h1 { margin: 0; font-size: 27px; font-weight: 800; letter-spacing: -.02em; }
.fiber-chip { background: var(--green-soft); color: var(--green); font-weight: 800; font-size: 13px; padding: 7px 13px; border-radius: 999px; }

/* layout */
#app { padding: 4px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px); max-width: 520px; margin: 0 auto; }
.view { display: flex; flex-direction: column; gap: 16px; }
.hint { color: var(--muted); font-size: 14px; margin: 0; }
.section-label { font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 8px 2px -6px; }

/* cards */
.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.card-title { font-weight: 800; font-size: 16px; margin: 0 0 14px; letter-spacing: -.01em; }

/* buttons */
.btn-primary, .big-btn { width: 100%; border: none; border-radius: var(--radius-sm); padding: 16px; font: inherit; font-size: 16px; font-weight: 800; color: #fff; background: var(--ink); cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 9px; box-shadow: var(--shadow-sm); }
.btn-primary:active, .big-btn:active { transform: scale(.99); }
.big-btn:disabled { opacity: .32; box-shadow: none; }
.btn-primary svg, .big-btn svg { width: 20px; height: 20px; }

/* fiber ring */
.ring-wrap { position: relative; width: 172px; height: 172px; margin: 4px auto 4px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 11; }
.ring-fg { fill: none; stroke: var(--green); stroke-width: 11; stroke-linecap: round; stroke-dasharray: 327; stroke-dashoffset: 327; transition: stroke-dashoffset .5s ease; }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-num { font-size: 46px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.ring-unit { font-size: 13px; color: var(--muted); margin-top: 5px; font-weight: 600; }
.mini-stats { display: flex; justify-content: center; gap: 30px; margin-top: 14px; }
.mini-stats > div { display: flex; flex-direction: column; align-items: center; }
.mini-stats b { font-size: 19px; font-weight: 800; }
.mini-stats span { font-size: 12px; color: var(--muted); margin-top: 1px; }

/* date strip */
.toprow { display: flex; align-items: center; gap: 6px; }
.gear { flex: 0 0 auto; background: none; border: none; font-size: 20px; padding: 4px 2px; cursor: pointer; opacity: .6; }
.datestrip { flex: 1; min-width: 0; display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.datestrip::-webkit-scrollbar { display: none; }
.day { flex: 0 0 auto; width: 64px; background: none; border: none; display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 2px; cursor: pointer; font: inherit; }
.day-wd { font-size: 12px; color: var(--muted); font-weight: 600; }
.day-n { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 17px; color: var(--text); border: 1.5px dashed #d6d6d2; }
.day-n.has { border-style: solid; border-color: var(--green); }
.day.sel .day-n { background: var(--ink); color: #fff; border: 1.5px solid var(--ink); }
.day.future { opacity: .36; }

/* calories hero */
.hero { display: flex; align-items: center; justify-content: space-between; }
.hero-num { font-size: 46px; font-weight: 800; letter-spacing: -.03em; line-height: 1; }
.hero-lbl { color: var(--muted); font-size: 14px; font-weight: 600; margin-top: 7px; }
.hero-ring { position: relative; width: 92px; height: 92px; flex: 0 0 auto; }
.hero-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.hero-ring .hr-bg { fill: none; stroke: var(--line); stroke-width: 9; }
.hero-ring .hr-fg { fill: none; stroke: var(--ink); stroke-width: 9; stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.hero-ring-ico { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 25px; }

/* macro cards */
.macro-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.macro-row.three { grid-template-columns: repeat(3, 1fr); }
.macro { background: var(--card); border-radius: var(--radius-sm); padding: 12px 4px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.macro-num { font-size: 15px; font-weight: 800; }
.macro-num .m-goal { font-size: 11px; color: var(--muted); font-weight: 700; }
.macro-lbl { font-size: 11px; color: var(--muted); }
.macro-ring { position: relative; width: 46px; height: 46px; margin-top: 2px; }
.macro-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.macro-ring .mr-bg { fill: none; stroke: var(--line); stroke-width: 6; }
.macro-ring .mr-fg { fill: none; stroke-width: 6; stroke-linecap: round; transition: stroke-dashoffset .5s ease; }
.macro-ico { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; }

/* segmented + inputs */
.seg { display: flex; background: #e9e9e6; border-radius: 13px; padding: 4px; gap: 4px; }
.seg-btn { flex: 1; background: none; border: none; color: var(--muted); padding: 9px; border-radius: 10px; font: inherit; font-weight: 700; font-size: 14px; cursor: pointer; }
.seg-btn.active { background: #fff; color: var(--text); box-shadow: var(--shadow-sm); }
.search-row { display: flex; gap: 8px; }
.search-row input, .search-row select, .wk-input, textarea { background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 13px; padding: 14px; font: inherit; }
.search-row input { flex: 1; }
.search-row button { border: none; border-radius: 13px; padding: 14px 18px; font-weight: 800; background: var(--ink); color: #fff; white-space: nowrap; }
#add-med { flex-wrap: wrap; }
#add-med > input { flex: 1 1 100%; }
.wk-input { width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); }

/* food + result cards */
.food-card { display: flex; align-items: center; gap: 12px; }
.food-card .meta { flex: 1; min-width: 0; }
.food-card .name { font-weight: 700; }
.food-card .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.macros { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.macros .fib { color: var(--green); font-weight: 800; }
.macros .cal { color: var(--text); font-weight: 800; }
.cal-big { font-size: 36px; font-weight: 800; letter-spacing: -.02em; }
.row .kcal, .tl .kcal { color: var(--muted); font-weight: 700; font-size: 12px; }
.card.food-card { cursor: pointer; }
.card.food-card:active { transform: scale(.99); }
.qty { display: flex; align-items: center; gap: 8px; }
.qty button { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: 17px; }
.qty span { min-width: 28px; text-align: center; }
.log-btn { border: none; background: var(--ink); color: #fff; font-weight: 800; border-radius: 11px; padding: 10px 16px; }
.spinner { text-align: center; color: var(--muted); padding: 18px; }

/* list rows (meals / timeline) */
.row, .tl { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: var(--radius-sm); padding: 13px 16px; box-shadow: var(--shadow-sm); }
.row.tappable { cursor: pointer; }
.row.tappable:active { transform: scale(.985); }
.row .t, .tl .t { color: var(--muted); font-size: 12px; min-width: 54px; }
.row .x, .tl .x { flex: 1; font-weight: 600; }
.row .fib, .tl .fib { color: var(--green); font-weight: 800; font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 22px; font-size: 14px; }

/* bristol */
.bristol-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.bristol { background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius-sm); padding: 14px 8px; text-align: center; cursor: pointer; box-shadow: var(--shadow-sm); }
.bristol.sel { border-color: var(--ink); }
.bristol .n { font-size: 22px; font-weight: 800; }
.bristol .d { font-size: 11px; color: var(--muted); margin-top: 4px; line-height: 1.2; }
.bristol.ideal .n { color: var(--green); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--card); border: 1.5px solid var(--line); color: var(--text); border-radius: 999px; padding: 9px 16px; font: inherit; font-size: 14px; font-weight: 600; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* meds */
.med { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: var(--radius-sm); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.med .meta { flex: 1; }
.med .name { font-weight: 700; }
.med .cat { font-size: 12px; color: var(--muted); }
.med .took { border: none; background: var(--ink); color: #fff; border-radius: 11px; padding: 9px 15px; font-weight: 800; }
.med .last { font-size: 12px; color: var(--green); margin-top: 2px; font-weight: 600; }

/* trends */
.stat-row { display: flex; gap: 10px; }
.stat { flex: 1; background: var(--card); border-radius: var(--radius-sm); padding: 15px 6px; text-align: center; box-shadow: var(--shadow-sm); }
.stat-num { display: block; font-size: 25px; font-weight: 800; letter-spacing: -.02em; }
.stat-lbl { font-size: 11px; color: var(--muted); }
#timeline { display: flex; flex-direction: column; gap: 8px; }

/* fiber chart */
.chart { position: relative; }
.cols { display: flex; gap: 6px; align-items: flex-end; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; }
.col-val { height: 14px; font-size: 10px; font-weight: 800; color: var(--green); }
.col-track { width: 100%; height: 90px; display: flex; align-items: flex-end; }
.col-fill { width: 100%; background: #bfe6d1; border-radius: 7px 7px 0 0; min-height: 2px; }
.col-fill.hit { background: var(--green); }
.col-lbl { height: 16px; line-height: 16px; font-size: 10px; color: var(--muted); }
.target { position: absolute; left: 0; right: 0; border-top: 1.5px dashed #cfcfca; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 24px 0; text-align: center; }
.bars-meta { color: var(--muted); font-size: 12px; margin-top: 12px; }

/* AI insight */
.insight { line-height: 1.55; font-size: 14px; }
.insight:not(:empty) { margin-top: 14px; }
.insight p { margin: 0 0 8px; }
.insight p:last-child { margin: 0; }
.insight .md-h { font-weight: 800; margin: 12px 0 6px; }
.insight .md-ul { margin: 0 0 8px; padding-left: 18px; }
.insight .md-ul li { margin: 3px 0; }
.insight strong { font-weight: 800; }

/* banner / toast / sheet */
.banner { background: #fff7e8; color: #8a5a12; padding: 12px 16px; font-size: 13px; line-height: 1.4; border-bottom: 1px solid var(--line); }
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 24px); transform: translateX(-50%); background: var(--ink); color: #fff; font-weight: 700; padding: 11px 20px; border-radius: 999px; z-index: 30; box-shadow: var(--shadow); font-size: 14px; }
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(22, 20, 15, .32); display: flex; align-items: flex-end; }
.sheet-card { width: 100%; max-width: 520px; margin: 0 auto; background: var(--card); border-radius: 26px 26px 0 0; padding: 22px 20px calc(24px + env(safe-area-inset-bottom)); max-height: 82vh; overflow: auto; }
.sheet-card h3 { margin: 0 0 4px; font-size: 19px; }
.fiber-big { color: var(--green); font-size: 36px; font-weight: 800; }
.serving-sel { width: 100%; background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 13px; padding: 13px; font: inherit; margin-top: 12px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; }
.sheet-actions button { flex: 1; border: none; border-radius: 14px; padding: 15px; font-weight: 800; font-size: 15px; }
.btn-cancel { background: #e9e9e6; color: var(--text); }
.btn-confirm { background: var(--ink); color: #fff; }

/* tab bar */
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; align-items: center; background: rgba(255, 255, 255, .9); backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 0 14px env(safe-area-inset-bottom); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
.tabs { flex: 1; display: flex; align-items: center; justify-content: space-around; }
.tab { flex: 1; background: none; border: none; color: #b6b6ba; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font: inherit; font-size: 11px; font-weight: 600; cursor: pointer; }
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--ink); }
.fab { flex: 0 0 auto; width: 64px; height: 64px; margin: -16px 0 0 10px; border-radius: 50%; background: var(--ink); color: #fff; border: none; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 20px rgba(22, 20, 15, .3); cursor: pointer; transition: transform .2s ease; }
.fab svg { width: 30px; height: 30px; }
.fab.open { transform: rotate(45deg); }

/* log action sheet */
.logsheet { position: fixed; inset: 0; z-index: 20; background: rgba(22, 20, 15, .34); display: flex; align-items: flex-end; }
.loggrid { width: 100%; max-width: 520px; margin: 0 auto; padding: 18px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 26px); display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.logact { background: #fff; border: none; border-radius: 20px; padding: 22px 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; gap: 10px; font: inherit; font-size: 15px; font-weight: 800; color: var(--text); cursor: pointer; }
.logact:active { transform: scale(.98); }
.logemoji { font-size: 27px; line-height: 1; }

/* water card */
.water-card { display: flex; align-items: center; justify-content: space-between; }
.water-info { display: flex; align-items: center; gap: 12px; }
.water-emoji { font-size: 26px; }
.water-amt { font-weight: 800; font-size: 17px; }
.water-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.water-btns { display: flex; gap: 8px; }
.water-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: 22px; font-weight: 600; cursor: pointer; line-height: 1; }
.water-btn.plus { background: #4d9fec; border-color: #4d9fec; color: #fff; }

/* home status tiles + infusion */
.statcards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { color: var(--muted); font-size: 14px; font-weight: 600; }
.statcard { background: var(--card); border-radius: var(--radius-sm); padding: 14px 6px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; align-items: center; gap: 3px; }
.statcard-ico { font-size: 20px; }
.statcard-val { font-size: 18px; font-weight: 800; }
.statcard-lbl { font-size: 11px; color: var(--muted); }
.infusion-line { background: var(--card); box-shadow: var(--shadow-sm); color: var(--text); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px; font-weight: 700; }
.day-mark { height: 16px; font-size: 12px; line-height: 16px; white-space: nowrap; }

/* saved foods */
.saved-list { display: flex; flex-direction: column; gap: 8px; }
.saved-row { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: var(--radius-sm); padding: 12px 14px; box-shadow: var(--shadow-sm); }
.saved-meta { flex: 1; min-width: 0; }
.saved-name { font-weight: 700; }
.saved-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.saved-sub .fib { color: var(--green); font-weight: 700; }
.saved-log { border: none; background: var(--ink); color: #fff; font-weight: 800; border-radius: 11px; padding: 9px 16px; cursor: pointer; }
.saved-del { border: none; background: none; color: var(--muted); font-size: 22px; width: 26px; line-height: 1; cursor: pointer; }
.save-btn { border: 1px solid var(--line); background: #fff; color: var(--text); font-weight: 800; border-radius: 11px; padding: 10px 14px; cursor: pointer; }
.btn-save { background: #e9e9e6; color: var(--text); }

/* login */
.login { position: fixed; inset: 0; z-index: 50; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; }
.login-emoji { font-size: 50px; text-align: center; }
.login-title { font-size: 32px; font-weight: 800; text-align: center; margin: 8px 0 2px; letter-spacing: -.02em; }
.login-sub { color: var(--muted); text-align: center; margin: 0 0 22px; font-size: 14px; }
.login .wk-input { margin-bottom: 10px; }
.login-alt { background: none; border: none; color: var(--muted); font: inherit; font-weight: 700; font-size: 14px; margin-top: 12px; cursor: pointer; }
.login-err { color: #d4493f; font-size: 13px; text-align: center; margin-top: 12px; min-height: 16px; }

/* dulcolax logger */
.dulco-card { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 26px 18px; }
.dulco-emoji { font-size: 46px; }
.dulco-name { font-size: 20px; font-weight: 800; }
.dulco-stepper { display: flex; align-items: center; gap: 24px; margin-top: 10px; }
.dulco-stepper button { width: 54px; height: 54px; border-radius: 50%; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: 27px; font-weight: 600; line-height: 1; cursor: pointer; }
.dulco-stepper span { font-size: 36px; font-weight: 800; min-width: 44px; }

/* coach chat */
.chat-log { display: flex; flex-direction: column; gap: 10px; padding-bottom: 84px; min-height: 62vh; }
.chat-empty { text-align: center; padding: 26px 8px 8px; }
.chat-suggest { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.chat-suggest button { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 13px 16px; font: inherit; font-size: 14px; color: var(--text); text-align: left; cursor: pointer; box-shadow: var(--shadow-sm); }
.chat-suggest button:active { transform: scale(.99); }
.cmsg { max-width: 86%; padding: 11px 15px; border-radius: 18px; font-size: 14.5px; line-height: 1.5; box-shadow: var(--shadow-sm); overflow-wrap: anywhere; }
.cmsg.user { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 6px; }
.cmsg.bot { align-self: flex-start; background: var(--card); color: var(--text); border-bottom-left-radius: 6px; }
.cmsg.bot p { margin: 0 0 8px; }
.cmsg.bot p:last-child { margin: 0; }
.cmsg.bot strong { font-weight: 800; }
.cmsg.bot .md-ul { margin: 4px 0; padding-left: 18px; }
.cmsg.bot .md-ul li { margin: 3px 0; }
.cmsg.bot .md-h { font-weight: 800; margin: 8px 0 4px; }
.cmsg.typing { color: var(--muted); }
.chat-bar { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); padding: 10px 16px; z-index: 25; }
.chat-bar-inner { max-width: 520px; margin: 0 auto; display: flex; gap: 8px; }
.chat-bar input { flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 13px 18px; font: inherit; }
.chat-bar button { flex: 0 0 auto; width: 46px; height: 46px; border-radius: 50%; border: none; background: var(--ink); color: #fff; font-size: 21px; font-weight: 800; cursor: pointer; }
.chat-bar button:active { transform: scale(.96); }
