/* MacroPulse — styles.css. Values follow the mockup (Main.dc.html) inline styles. */

@font-face {
  font-family: 'Geist';
  src: url('./fonts/Geist-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('./fonts/GeistMono-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  /* surfaces */
  --page: #0D1012;
  --card: #15191C;
  --inset: #0F1315;
  --hover: #1C2125;
  --track: #232A2F;
  --header: rgba(13, 16, 18, .94);
  --header-border: #1F2428;
  /* borders */
  --border: #262C31;
  --border-inner: #222830;
  --divider: #1E2429;
  --border-ghost: #2E353B;
  /* text */
  --text: #EEF1F3;
  --text-2: #B4BCC3;
  --muted: #9AA3AB;
  --subtle: #8A939B;
  --placeholder: #7D868E;
  /* accent & data colours */
  --accent: #B6F36A;
  --accent-50: rgba(182, 243, 106, .5);
  --on-accent: #0D1012;
  --p: #7AB0FF;
  --c: #F7B955;
  --f: #F08BA8;
  --fib: #63D9B8;
  --water: #7FC8F0;
  --warn: #FF9B73;
  /* type */
  --font: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  /* shape */
  --r-card: 16px;
  --r-inner: 12px;
  --r-ctl: 10px;
  --r-chip: 8px;
  --r-pill: 999px;
  --pad-card: 20px;
  --ctl-h: 40px;
  --tap: 40px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--page);
}
body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word;
}
h1, h2, h3, p { margin: 0; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
button { font: inherit; cursor: pointer; color: inherit; }
button:disabled { cursor: default; opacity: .4; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); }
select option { background: var(--card); color: var(--text); }
input::placeholder, textarea::placeholder { color: var(--placeholder); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }
a:hover { color: #D4FF9E; }
.mono { font-family: var(--mono); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.hov:hover { background: var(--hover); }
.lift:hover { filter: brightness(1.08); }

/* ---------- header ---------- */

.hdr {
  position: sticky; top: 0; z-index: 20;
  background: var(--header);
  border-bottom: 1px solid var(--header-border);
  padding-top: env(safe-area-inset-top);
}
.hdr-in {
  max-width: 1360px; margin: 0 auto;
  padding: 12px max(24px, env(safe-area-inset-right)) 12px max(24px, env(safe-area-inset-left));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: conic-gradient(var(--accent) 0deg 250deg, var(--border) 250deg 360deg);
  display: flex; align-items: center; justify-content: center;
}
.logo::after { content: ''; width: 20px; height: 20px; border-radius: 50%; background: var(--page); }
.brand-text { min-width: 0; }
.wordmark { font-weight: 650; font-size: 17px; letter-spacing: -.01em; line-height: 1.25; }
.hdr-date { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr-date.is-past { color: var(--accent); }
.hdr-tabs { display: none; gap: 8px; }
.hdr-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }

.btn, .hdr-tab {
  height: var(--ctl-h); padding: 0 14px; border-radius: var(--r-ctl);
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 13px; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.btn:hover, .hdr-tab:hover { background: var(--hover); color: var(--text); }
.hdr-tab[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); color: var(--on-accent); }
.btn-ghost { background: transparent; border: 1px solid var(--border-ghost); }
.btn-danger { color: var(--warn); border-color: var(--warn); background: transparent; }
.btn-danger:hover { background: rgba(255, 155, 115, .08); color: var(--warn); }
.btn-sm { height: 36px; padding: 0 12px; }
.icon-btn {
  width: var(--tap); height: var(--tap); flex-shrink: 0;
  border-radius: var(--r-ctl); border: 0; background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.icon-btn.bordered { border: 1px solid var(--border); background: var(--card); color: var(--text); }

/* "⋯" menu */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 200px; padding: 6px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-inner);
  display: flex; flex-direction: column; gap: 2px;
}
.menu-item {
  min-height: 44px; padding: 0 12px; border: 0; border-radius: var(--r-chip);
  background: transparent; color: var(--text); text-align: left;
  display: flex; align-items: center; gap: 10px; font-size: 14px;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); }

/* bottom tab bar (phones) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--header); border-top: 1px solid var(--header-border);
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
}
.tab {
  min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 500;
}
.tab:hover { color: var(--text); }
.tab[aria-current="page"] { color: var(--accent); }

/* ---------- layout ---------- */

.main {
  max-width: 1360px; margin: 0 auto;
  padding: 24px max(24px, env(safe-area-inset-right)) 24px max(24px, env(safe-area-inset-left));
}
.main:focus { outline: none; }
.view { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.boot { color: var(--muted); padding: 40px 0; text-align: center; }
.foot { margin: 8px 0 0; font-size: 12px; color: var(--subtle); text-align: center; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-card);
  padding: var(--pad-card); min-width: 0;
}
.card-stack { display: flex; flex-direction: column; gap: 16px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.card-head.baseline { align-items: baseline; gap: 8px; }
.sub { margin-top: 4px; font-size: 13px; color: var(--muted); }
.sub strong { color: var(--text); font-weight: 500; }
.label-sm { font-size: 12px; color: var(--muted); }
.count { font-family: var(--mono); font-size: 13px; color: var(--muted); font-weight: 400; }
.is-warn { color: var(--warn) !important; }
.inset {
  background: var(--inset); border: 1px solid var(--border-inner); border-radius: var(--r-inner); padding: 16px;
}

.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-inner);
  padding: 10px 10px 10px 16px; font-size: 13px; color: var(--text-2);
}
.banner.warn { border-color: rgba(255, 155, 115, .55); }
.banner .actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* bars */
.bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar.thin { height: 6px; border-radius: 3px; }
.bar > span { display: block; height: 100%; border-radius: inherit; }
.bg-p { background: var(--p); } .bg-c { background: var(--c); } .bg-f { background: var(--f); }
.bg-fib { background: var(--fib); } .bg-water { background: var(--water); } .bg-accent { background: var(--accent); }
.bg-warn { background: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* ---------- today: glance ---------- */

.glance { display: flex; flex-wrap: wrap; gap: 16px; }
.ring-card { flex: 1 1 360px; padding: 24px; display: flex; flex-wrap: wrap; align-items: center; gap: 24px; }
.ring {
  width: 172px; height: 172px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.ring-in {
  width: 140px; height: 140px; border-radius: 50%; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
}
.ring-num { font-family: var(--mono); font-size: 32px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
.ring-label { font-size: 13px; color: var(--muted); }
.ring-stats { flex: 1 1 160px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.stat-row { display: flex; justify-content: space-between; gap: 8px; }
.stat-row.ruled { padding-bottom: 10px; border-bottom: 1px solid var(--border-inner); }
.stat-row > span:first-child { color: var(--muted); }
.stat-row > span:last-child { font-family: var(--mono); font-weight: 500; }
.split { margin-top: 6px; }
.split-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--track); gap: 2px; margin-top: 6px; }
.split-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 6px; font-size: 12px; font-family: var(--mono); color: var(--text-2); }

.macros-card {
  flex: 999 1 560px; padding: 24px; display: flex; flex-direction: column; gap: 18px;
  container-type: inline-size;
}
.chip-btn {
  height: 36px; padding: 0 12px; border-radius: var(--r-pill); border: 1px solid var(--border);
  background: transparent; color: var(--text-2); font-size: 13px;
  display: inline-flex; align-items: center; gap: 8px;
}
.chip-btn .dot { width: 6px; height: 6px; background: var(--accent); }
.macro-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@container (min-width: 600px) {
  .macro-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.macro {
  background: var(--inset); border: 1px solid var(--border-inner); border-radius: var(--r-inner);
  padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.macro-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.macro-name { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
.macro-pct { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.macro-val { font-family: var(--mono); }
.macro-val .big { font-size: 28px; font-weight: 600; letter-spacing: -.02em; }
.macro-val .of { font-size: 13px; color: var(--muted); }
.macro-rem { font-size: 12px; color: var(--muted); }

/* ---------- today: columns ---------- */

.today-cols { display: flex; flex-direction: column; gap: 16px; }
.today-aside { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* meal log */
.meal-log { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.meal-log-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; padding: 4px 4px 0;
}
.hint { font-size: 13px; color: var(--muted); }
.meal { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-card); overflow: hidden; }
.meal.is-target { border-color: var(--accent-50); }
.meal-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 8px 12px 8px 8px; }
.meal-toggle {
  flex: 1 1 200px; min-width: 0; min-height: 48px;
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; color: inherit; text-align: left; padding: 4px 8px; border-radius: var(--r-ctl);
}
.meal-toggle .chev { flex-shrink: 0; color: var(--muted); transition: transform .15s; }
.meal-toggle[aria-expanded="false"] .chev { transform: rotate(-90deg); }
.meal-title { min-width: 0; }
.meal-name { display: block; font-size: 15px; font-weight: 600; }
.meal-count { display: block; font-size: 12px; color: var(--muted); }
.meal-sub { display: none; font-family: var(--mono); font-size: 12px; color: var(--subtle); }
.meal-nums { text-align: right; font-family: var(--mono); }
.meal-kcal { font-size: 15px; font-weight: 500; }
.meal-kcal .u { font-size: 12px; color: var(--muted); }
.meal-macros { font-size: 12px; color: var(--muted); }
.add-here {
  height: var(--ctl-h); padding: 0 14px; border-radius: var(--r-ctl); font-size: 13px;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: transparent; color: var(--text); font-weight: 500; border: 1px solid var(--border-ghost);
}
.add-here[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; border-color: var(--accent); }
.item-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  padding: 10px 12px 10px 42px; border-top: 1px solid var(--divider);
}
.item-info { flex: 1 1 180px; min-width: 0; }
.item-name { font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.item-macros { font-family: var(--mono); font-size: 12px; color: var(--subtle); }
.item-ctl { display: flex; align-items: center; gap: 8px; min-width: 0; }
.item-ctl .qty { width: 76px; text-align: right; }
.item-ctl .sel { width: 140px; }
.item-kcal { width: 56px; text-align: right; font-family: var(--mono); font-size: 14px; }
.meal-empty {
  border-top: 1px solid var(--divider); padding: 10px 12px 10px 42px; min-height: 48px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 13px; color: var(--subtle);
}

/* controls */
.ctl {
  height: var(--ctl-h); padding: 0 10px; min-width: 0;
  background: var(--page); border: 1px solid var(--border); border-radius: var(--r-ctl);
  color: var(--text); font-size: 16px;
}
.ctl.num { font-family: var(--mono); }
.ctl[aria-invalid="true"] { border-color: var(--warn); }
textarea.ctl { height: auto; min-height: 80px; padding: 10px; resize: vertical; }
.sel { position: relative; display: block; min-width: 0; }
.sel select {
  -webkit-appearance: none; appearance: none; width: 100%; padding-right: 30px; text-overflow: ellipsis;
}
.sel::after {
  content: ''; position: absolute; right: 13px; top: 50%; width: 7px; height: 7px; pointer-events: none;
  border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
}
input[type="number"] { -moz-appearance: textfield; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* ---------- add panel ---------- */

.add-panel { display: flex; flex-direction: column; gap: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 34px; padding: 0 12px; border-radius: var(--r-pill); font-size: 13px;
  background: transparent; color: var(--text-2); font-weight: 500; border: 1px solid var(--border);
}
.chip[aria-pressed="true"], .cat-chip[aria-pressed="true"] {
  background: var(--accent); color: var(--on-accent); font-weight: 600; border-color: var(--accent);
}
.cat-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; min-width: 0; }
.cat-chip {
  height: 32px; padding: 0 12px; border-radius: var(--r-chip); font-size: 12px; white-space: nowrap; flex-shrink: 0;
  background: transparent; color: var(--text-2); font-weight: 500; border: 1px solid var(--border);
}
.list { display: flex; flex-direction: column; border: 1px solid var(--border-inner); border-radius: var(--r-inner); overflow: hidden; }
.list-empty { padding: 20px 12px; font-size: 13px; color: var(--muted); text-align: center; }
.staple-row { display: flex; align-items: center; gap: 12px; padding: 12px; }
.staple-row + .staple-row { border-top: 1px solid var(--border-inner); }
.staple-info { flex: 1; min-width: 0; }
.staple-line { display: flex; justify-content: space-between; gap: 8px; }
.staple-name { font-size: 14px; font-weight: 500; min-width: 0; }
.staple-kcal { font-family: var(--mono); font-size: 13px; white-space: nowrap; }
.staple-note { font-size: 12px; color: var(--subtle); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.staple-macros { font-family: var(--mono); font-size: 12px; color: var(--text-2); margin-top: 2px; }
.staple-add {
  width: 44px; height: 44px; flex-shrink: 0; border-radius: var(--r-ctl); border: 0;
  display: flex; align-items: center; justify-content: center; background: var(--track); color: var(--text);
}
.food-row { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 12px; }
.food-row + .food-row { border-top: 1px solid var(--divider); }
.food-row:hover { background: var(--hover); }
.food-info { flex: 1; min-width: 0; }
.food-name { font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.food-meta { font-family: var(--mono); font-size: 12px; color: var(--subtle); }
.add-btn {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: var(--r-ctl);
  display: flex; align-items: center; justify-content: center;
  background: transparent; color: var(--text); border: 1px solid var(--border-ghost);
}
.add-btn.is-added, .staple-add.is-added { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.search { position: relative; }
.search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { width: 100%; height: 42px; padding: 0 44px 0 38px; }
.search .clear { position: absolute; right: 1px; top: 50%; transform: translateY(-50%); }
.add-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.add-strip { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.add-strip .what { font-size: 13px; color: var(--muted); }
.add-strip .what strong { color: var(--text); font-weight: 500; }

/* ---------- habits & water, weight ---------- */

.habits { display: flex; flex-direction: column; gap: 8px; }
.habit {
  width: 100%; min-height: 56px; display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: var(--r-inner); border: 1px solid var(--border-inner); background: var(--inset);
  color: var(--text); text-align: left;
}
.habit:hover { background: var(--hover); }
.habit-box {
  width: 22px; height: 22px; flex-shrink: 0; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1.5px solid #4A535B; color: var(--on-accent);
}
.habit[aria-pressed="true"] .habit-box { background: var(--accent); border: 1px solid var(--accent); }
.habit-text { flex: 1; min-width: 0; }
.habit-label { display: block; font-size: 14px; font-weight: 500; }
.habit-sub { display: block; font-size: 12px; color: var(--muted); }
.water { display: flex; flex-direction: column; gap: 12px; }
.water-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; }
.water-title { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.water-title svg { color: var(--water); }
.water-val { font-family: var(--mono); }
.water-val .big { font-size: 20px; font-weight: 600; }
.water-val .of { font-size: 13px; color: var(--muted); }
.water-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.water-btn {
  height: 44px; border-radius: var(--r-ctl); border: 1px solid var(--border); background: var(--card);
  color: var(--text); font-family: var(--mono); font-size: 13px; font-weight: 500; min-width: 0;
}
.water-btn:hover { background: var(--hover); }
.water-btn.minus { color: var(--muted); }
.weight-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; }
.weight-row .field { flex: 1 1 140px; }

/* ---------- forms (settings, dialogs) ---------- */

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.form-grid.tight { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.span-2 { grid-column: 1 / -1; }
.field { min-width: 0; }
.field > label, .field > .label {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 12px; color: var(--muted); margin-bottom: 6px;
}
.field .ctl { width: 100%; height: 42px; padding: 0 12px; }
.field .ctl.num { text-align: left; }
.field .sel select { padding-right: 30px; }
.field-err { margin-top: 6px; font-size: 12px; color: var(--warn); }
.field-note { margin-top: 6px; font-size: 12px; color: var(--muted); }
.seg { display: flex; gap: 4px; padding: 4px; background: var(--page); border: 1px solid var(--border); border-radius: var(--r-ctl); }
.seg button {
  flex: 1; min-width: 0; height: 32px; border: 0; border-radius: 7px; font-size: 13px;
  background: transparent; color: var(--text-2); font-weight: 500;
}
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.stats { display: flex; flex-wrap: wrap; gap: 12px 24px; font-family: var(--mono); }
.stat .k { font-size: 12px; color: var(--muted); font-family: var(--font); }
.stat .v { font-size: 16px; font-weight: 500; }
.stat .v.accent { color: var(--accent); font-weight: 600; }
.ruled-top { border-top: 1px solid var(--border-inner); padding-top: 16px; display: flex; flex-direction: column; gap: 14px; }
.check {
  display: inline-flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; min-height: 32px;
}
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; flex-shrink: 0; }
.flag { font-size: 12px; color: var(--text-2); background: var(--inset); border: 1px solid var(--border-inner); border-radius: var(--r-chip); padding: 8px 10px; }
.target-chips { display: flex; flex-wrap: wrap; gap: 8px; font-family: var(--mono); font-size: 13px; color: var(--text-2); }
.target-chips span { display: inline-flex; align-items: center; gap: 6px; }

.rows { display: flex; flex-direction: column; border: 1px solid var(--border-inner); border-radius: var(--r-inner); overflow: hidden; }
.row-item { display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 12px; min-height: 56px; }
.row-item + .row-item { border-top: 1px solid var(--divider); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.row-sub { font-size: 12px; color: var(--subtle); overflow-wrap: anywhere; }
.row-actions { display: flex; gap: 4px; flex-shrink: 0; }
.group-label { font-size: 12px; color: var(--muted); margin: 4px 0 8px; }
.disclosure > summary {
  cursor: pointer; font-size: 13px; color: var(--muted); min-height: 40px;
  display: flex; align-items: center; gap: 8px; list-style: none;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before {
  content: ''; width: 6px; height: 6px; border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s; margin: 0 4px;
}
.disclosure[open] > summary::before { transform: rotate(45deg); }
.data-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.data-tile { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.data-tile p { font-size: 13px; color: var(--muted); }
.kv { font-size: 13px; color: var(--muted); }
.kv strong { color: var(--text); font-weight: 500; }
.unit-rows { display: flex; flex-direction: column; gap: 8px; }
.unit-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px 44px; gap: 8px; align-items: center; }
.combo-item { display: grid; grid-template-columns: minmax(0, 1fr) 76px minmax(0, 120px) 44px; gap: 8px; align-items: center; }
.warn-note { font-size: 12px; color: var(--warn); }

/* ---------- history ---------- */

.week-nav { display: flex; align-items: center; gap: 4px; }
.week-label { font-family: var(--mono); font-size: 13px; color: var(--text-2); min-width: 0; text-align: center; padding: 0 4px; }
.week-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.wstat { background: var(--inset); border: 1px solid var(--border-inner); border-radius: var(--r-inner); padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.wstat .k { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
.wstat .v { font-family: var(--mono); }
.wstat .v .big { font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.wstat .v .of { font-size: 13px; color: var(--muted); }
.wstat .n { font-size: 12px; color: var(--muted); }
.chart { display: flex; flex-direction: column; gap: 8px; }
.plot { position: relative; height: 160px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; align-items: end; }
.plot .col { height: 100%; display: flex; align-items: flex-end; justify-content: center; min-width: 0; }
.plot .col > span { display: block; width: 100%; max-width: 44px; border-radius: 6px 6px 2px 2px; background: var(--accent); min-height: 0; }
.plot .col > span.empty { background: var(--track); height: 2px !important; }
.plot .col > span.over { background: var(--warn); }
.target-line { position: absolute; left: 0; right: 0; border-top: 1.5px dashed var(--muted); pointer-events: none; }
.target-tag { position: absolute; right: 0; transform: translateY(-120%); font-family: var(--mono); font-size: 11px; color: var(--muted); background: var(--card); padding: 0 4px; }
.xlabels { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.xlabels button {
  min-height: 44px; border: 0; background: transparent; border-radius: var(--r-chip); color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 12px; line-height: 1.2; min-width: 0; padding: 0;
}
.xlabels button .d { font-family: var(--mono); color: var(--text-2); }
.xlabels button:hover { background: var(--hover); }
.xlabels button.today .d { color: var(--accent); }
.day-list .row-item { min-height: 52px; }

/* ---------- dialogs & toasts ---------- */

.dlg {
  width: min(560px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 0;
  background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-card);
}
.dlg::backdrop { background: rgba(5, 7, 8, .72); }
.dlg-in { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dlg-head { padding: 18px 20px 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dlg-body { padding: 16px 20px 20px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; min-height: 0; }
.dlg-body p { color: var(--text-2); }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border-inner); }

.toast-region {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 50;
  display: flex; justify-content: center; pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 8px; max-width: 520px; min-height: 52px;
  background: var(--hover); border: 1px solid var(--border-ghost); border-radius: var(--r-inner);
  padding: 6px 6px 6px 16px; font-size: 14px; color: var(--text);
}
.toast .msg { flex: 1; min-width: 0; padding: 8px 0; }
.toast-btn {
  height: 40px; padding: 0 14px; border-radius: var(--r-ctl); border: 0; background: transparent;
  color: var(--accent); font-weight: 600; white-space: nowrap;
}
.toast-btn:hover { background: var(--track); }

/* ---------- breakpoints ---------- */

@media (min-width: 768px) {
  .hdr-tabs { display: flex; }
  .tabbar { display: none; }
}

@media (min-width: 1024px) {
  .hdr-tab.tab-add { display: none; }
  .today-cols { display: grid; grid-template-columns: minmax(0, 1fr) 380px; align-items: start; }
  .span-2 { grid-column: span 2; }
}

/* phones */
@media (max-width: 767px) {
  :root { --pad-card: 16px; --ctl-h: 44px; --tap: 44px; }
  .hdr-in { padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left)); gap: 8px; }
  .brand { gap: 10px; }
  .main { padding: 16px max(16px, env(safe-area-inset-right)) calc(88px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .toast-region { bottom: calc(68px + env(safe-area-inset-bottom)); }
  .ring-card, .macros-card { padding: 16px; }
  .ring-card { justify-content: center; }
  .macro { padding: 12px; }
  .meal-head { flex-wrap: nowrap; gap: 8px; padding: 8px 8px 8px 4px; }
  .meal-toggle { flex: 1 1 auto; align-items: flex-start; padding-top: 6px; padding-bottom: 6px; }
  .meal-toggle .chev { margin-top: 3px; }
  .meal-nums { display: none; }
  .meal-sub { display: block; }
  .item-row { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 10px 12px; }
  .item-ctl { display: grid; grid-template-columns: 68px minmax(0, 1fr) auto 44px; gap: 8px; }
  .item-ctl .qty, .item-ctl .sel { width: auto; }
  .item-kcal { width: auto; min-width: 40px; }
  .meal-empty { padding: 8px 12px 8px 16px; }
  .chip, .cat-chip { height: auto; min-height: 44px; }
  .seg button { height: 40px; }
  .field .ctl, .search input { height: 44px; }
  .chip-btn { height: 44px; }
  .xlabels button { min-height: 44px; }
  .dlg { width: calc(100% - 16px); max-height: calc(100% - 16px); }
  .dlg-head { padding: 16px 16px 0; }
  .dlg-body { padding: 14px 16px 16px; }
  .dlg-actions { padding: 12px 16px; }
  .combo-item { grid-template-columns: minmax(0, 1fr) 68px 44px; }
  .combo-item .sel { grid-column: 1 / 3; }
}

@media (pointer: coarse) {
  .chip, .cat-chip { min-height: 44px; }
  .add-btn { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
