@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=DM+Sans:wght@400;500;600;700&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── THEMES ─────────────────────────────────────────────────────────────── */
/* Default theme = Sage (green) — all greens, no yellow */
:root, html[data-theme="sage"] {
  --bg: #F2F5E8;
  --card: #FFFFFF;
  --text: #1F3A0A;
  --muted: #6B7A52;
  --border: #DDE5C7;
  --border-strong: #B8C896;
  --accent: #4A6B1A;
  --accent-light: #C8D9A0;
  --protein:    #2D5B0E; --protein-bg: #E7EFD3;
  --carbs:      #5C8F2A; --carbs-bg:   #EDF3DA;
  --fat:        #94B36B; --fat-bg:     #F3F7E5;
}
/* Rose (pink) — all rose, no gold */
html[data-theme="rose"] {
  --bg: #FBEEF2;
  --card: #FFFFFF;
  --text: #6B1532;
  --muted: #9B6B7A;
  --border: #F0D5DD;
  --border-strong: #E4B5C2;
  --accent: #C8527A;
  --accent-light: #F2C8D4;
  --protein:    #6B1532; --protein-bg: #F5D9E1;
  --carbs:      #C8527A; --carbs-bg:   #FAE2EA;
  --fat:        #E0A8B8; --fat-bg:     #FCEEF3;
}
/* Ocean (blue) */
html[data-theme="ocean"] {
  --bg: #EEF3F9;
  --card: #FFFFFF;
  --text: #13315E;
  --muted: #6B7B95;
  --border: #D7E2EE;
  --border-strong: #B8CFE6;
  --accent: #1F4B82;
  --accent-light: #B8CFE6;
  --protein:    #13315E; --protein-bg: #D7E2EE;
  --carbs:      #3D7CB5; --carbs-bg:   #E6EEF7;
  --fat:        #7DA6C9; --fat-bg:     #EFF5FA;
}
/* White (minimal) */
html[data-theme="white"] {
  --bg: #FFFFFF;
  --card: #FAFAFA;
  --text: #1A1A1A;
  --muted: #737373;
  --border: #E5E5E5;
  --border-strong: #A3A3A3;
  --accent: #1A1A1A;
  --accent-light: #D4D4D4;
  --protein:    #1A1A1A; --protein-bg: #F0F0F0;
  --carbs:      #525252; --carbs-bg:   #F5F5F5;
  --fat:        #8C8C8C; --fat-bg:     #FAFAFA;
}
/* Violet */
html[data-theme="violet"] {
  --bg: #F3EEF9;
  --card: #FFFFFF;
  --text: #3D1A5C;
  --muted: #8B7AA0;
  --border: #E5DBF0;
  --border-strong: #BFA8D6;
  --accent: #6B3FA0;
  --accent-light: #D4B8EE;
  --protein:    #3D1A5C; --protein-bg: #E5DBF0;
  --carbs:      #7B4FBC; --carbs-bg:   #ECE0F7;
  --fat:        #B89AD9; --fat-bg:     #F4ECFA;
}
/* Beige */
html[data-theme="beige"] {
  --bg: #F5F0E6;
  --card: #FCF9F3;
  --text: #3D2E1F;
  --muted: #8B7A66;
  --border: #E8DFD2;
  --border-strong: #CDBFAC;
  --accent: #8B5A2B;
  --accent-light: #D9C5A9;
  --protein:    #3D2E1F; --protein-bg: #ECE2D2;
  --carbs:      #A87B4B; --carbs-bg:   #F1E5D2;
  --fat:        #C4A77D; --fat-bg:     #F6EDDF;
}

:root {
  /* Confidence badges */
  --green-bg: #EAF3DE; --green-text: #4A7A2C;
  --amber-bg: #FEF3DC; --amber-text: #8A6520;
  --red-bg:   #FCEBEB; --red-text:   #B23A39;
  --danger:   #E24B4A;

  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --t: 0.15s ease;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

/* ─── RTL ─────────────────────────────────────────────────────────────────── */
html[dir="rtl"] body { font-family: 'DM Sans', 'Noto Sans Arabic', Tahoma, sans-serif; }
html[dir="rtl"] .toggle-slider::before { left: auto; right: 3px; }
html[dir="rtl"] .toggle input:checked + .toggle-slider::before { transform: translateX(-20px); }

button, input, select, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }
.mono { font-family: 'DM Mono', monospace; }
.hidden { display: none !important; }

/* ─── LAYOUT ──────────────────────────────────────────────────────────────── */
#app {
  max-width: 420px;
  margin: 0 auto;
  padding: 0 20px 110px;
  min-height: 100vh;
  position: relative;
}

/* ─── HEADER ──────────────────────────────────────────────────────────────── */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0 8px;
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
}
.brand {
  font-family: 'DM Mono', monospace;
  font-size: 19px;
  letter-spacing: -0.01em;
  display: inline-flex; align-items: baseline;
  font-weight: 500;
}
.brand .ori { color: var(--text); }
.brand .cal { color: var(--accent); font-weight: 600; }
.icon-btn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: 50%;
  color: var(--text); transition: background var(--t);
}
.icon-btn:hover { background: var(--border); }

/* ─── BOTTOM TAB NAV ──────────────────────────────────────────────────────── */
.tabbar {
  position: fixed;
  bottom: 0; left: 50%;
  transform: translateX(-50%);
  width: 100%; max-width: 420px;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tabbar-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: none;
  padding: 10px 4px 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  transition: color var(--t);
}
.tabbar-btn.active { color: var(--text); }
.tabbar-btn svg { width: 20px; height: 20px; }

/* ─── HERO ────────────────────────────────────────────────────────────────── */
.hero { text-align: center; padding: 32px 0 24px; }
.hero-label {
  font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
  font-weight: 500; margin-bottom: 8px;
}
.hero-number {
  font-family: 'DM Mono', monospace;
  font-size: clamp(64px, 22vw, 92px);
  font-weight: 400; line-height: 1;
  letter-spacing: -0.04em;
  transition: color 0.3s;
}
.hero-number.over { color: var(--danger); }
.hero-unit { font-size: 14px; color: var(--muted); margin-top: 6px; }
.hero-macros {
  margin-top: 14px; font-size: 13px;
  font-family: 'DM Mono', monospace;
  display: flex; justify-content: center; gap: 12px; flex-wrap: wrap;
}
.hero-macros .macro-chip { display: inline-flex; align-items: center; gap: 5px; }
.hero-macros .dot-p, .hero-macros .dot-c, .hero-macros .dot-f {
  width: 8px; height: 8px; border-radius: 50%;
}
.hero-macros .dot-p { background: var(--protein); }
.hero-macros .dot-c { background: var(--carbs); }
.hero-macros .dot-f { background: var(--fat); }
.hero-macros .over { color: var(--danger); }

/* ─── PROGRESS BAR ────────────────────────────────────────────────────────── */
.progress { margin: 0 0 28px; }
.progress-track {
  height: 4px; background: var(--border);
  border-radius: 99px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--text);
  border-radius: 99px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s;
  max-width: 100%;
}
.progress-fill.over { background: var(--danger); }
.progress-meta {
  display: flex; justify-content: space-between;
  margin-top: 8px; font-size: 12px;
  color: var(--muted); font-family: 'DM Mono', monospace;
}

/* ─── LOG BUTTON ──────────────────────────────────────────────────────────── */
.log-btn {
  width: 100%; padding: 16px;
  background: var(--text); color: var(--bg);
  border: none; border-radius: var(--radius);
  font-size: 15px; font-weight: 500;
  transition: opacity var(--t), transform var(--t);
  margin-bottom: 28px;
}
.log-btn:hover { opacity: 0.88; }
.log-btn:active { transform: scale(0.98); }

/* ─── SECTIONS ────────────────────────────────────────────────────────────── */
.section-header {
  font-size: 11px; font-weight: 600;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.08em; margin-bottom: 12px;
}
.meal-list { display: flex; flex-direction: column; gap: 8px; }
.meal-empty {
  text-align: center; padding: 40px 0;
  color: var(--muted); font-size: 14px;
}

.meal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  animation: cardIn 0.2s ease;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.meal-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.meal-info { flex: 1; min-width: 0; }
.meal-name {
  font-size: 14px; font-weight: 500; margin-bottom: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meal-macros {
  font-size: 11px; font-family: 'DM Mono', monospace;
  display: flex; gap: 10px;
}
.meal-macros .m-p { color: var(--protein); }
.meal-macros .m-c { color: var(--carbs); }
.meal-macros .m-f { color: var(--fat); }
.meal-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.meal-cal { font-family: 'DM Mono', monospace; font-size: 15px; font-weight: 500; }
.meal-actions { display: flex; gap: 2px; }
.meal-action {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 6px;
  color: var(--muted); transition: all var(--t);
}
.meal-action:hover { background: var(--bg); color: var(--text); }
.meal-action.del:hover { color: var(--danger); }
.meal-bottom { margin-top: 8px; display: flex; align-items: center; gap: 8px; }

/* ─── BADGE ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 3px 9px; border-radius: 99px;
  font-size: 10px; font-weight: 600;
  letter-spacing: 0.02em; white-space: nowrap;
}
.badge-green { background: var(--green-bg); color: var(--green-text); }
.badge-amber { background: var(--amber-bg); color: var(--amber-text); }
.badge-red   { background: var(--red-bg);   color: var(--red-text); }

/* ─── OVERLAY / SHEET ─────────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(4px);
  display: flex; justify-content: center; align-items: flex-end;
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  background: var(--bg);
  width: 100%; max-width: 420px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 92vh; overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  animation: slideUp 0.25s cubic-bezier(0.32, 0.72, 0, 1);
  overscroll-behavior: contain;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--border-strong);
  border-radius: 2px; margin: 12px auto 0;
}
.sheet-header {
  padding: 16px 20px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.sheet-title { font-size: 17px; font-weight: 600; }
.sheet-close {
  background: none; border: none;
  font-size: 24px; color: var(--muted);
  padding: 4px 8px; line-height: 1;
}
.sheet-body { padding: 20px; }

/* ─── TABS (inside sheets) ────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 4px;
  background: var(--border);
  padding: 4px;
  border-radius: 99px;
  margin-bottom: 20px;
}
.tab {
  flex: 1; background: transparent;
  border: none; border-radius: 99px;
  padding: 9px 12px; font-size: 13px; font-weight: 500;
  color: var(--muted); transition: all var(--t);
}
.tab.active {
  background: var(--card); color: var(--text);
  box-shadow: var(--shadow);
}

/* ─── LOG INPUTS ──────────────────────────────────────────────────────────── */
.text-area {
  width: 100%; min-height: 110px;
  padding: 14px 16px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px; resize: none; outline: none;
  transition: border-color var(--t);
}
.text-area:focus { border-color: var(--text); }
.text-area::placeholder { color: var(--muted); }
.photo-zone {
  width: 100%; padding: 32px 16px;
  background: var(--card);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  text-align: center; transition: border-color var(--t);
}
.photo-zone.has-image { padding: 12px; border-style: solid; }
.photo-zone img {
  max-width: 100%; max-height: 280px;
  border-radius: 8px; display: block; margin: 0 auto;
}
.photo-zone .photo-icon { width: 44px; height: 44px; margin: 0 auto 12px; color: var(--muted); }
.photo-zone .photo-text { color: var(--muted); font-size: 14px; margin-bottom: 16px; }
.photo-buttons { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.photo-btn {
  padding: 10px 18px;
  background: var(--text); color: var(--bg);
  border: none; border-radius: 8px;
  font-size: 13px; font-weight: 500;
}
.photo-btn.secondary {
  background: transparent; color: var(--text);
  border: 1.5px solid var(--border-strong);
}

.btn-row { display: flex; gap: 10px; margin-top: 16px; }
.btn-primary {
  flex: 1; padding: 14px;
  background: var(--text); color: var(--bg);
  border: none; border-radius: var(--radius);
  font-size: 15px; font-weight: 500;
  transition: opacity var(--t);
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary {
  padding: 14px 20px;
  background: transparent; color: var(--text);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 15px; font-weight: 500;
}
.btn-secondary:hover { border-color: var(--text); }
.btn-danger {
  width: 100%; padding: 14px;
  background: transparent; color: var(--danger);
  border: 1.5px solid var(--red-bg);
  border-radius: var(--radius);
  font-size: 15px; font-weight: 500;
}
.btn-danger:hover { background: var(--red-bg); }

/* ─── LOADING ─────────────────────────────────────────────────────────────── */
.loading { text-align: center; padding: 40px 20px; }
.spinner {
  width: 28px; height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 14px; color: var(--muted); }

/* ─── CLARIFY ─────────────────────────────────────────────────────────────── */
.clarify-step {
  font-size: 11px; font-weight: 600;
  color: var(--muted); letter-spacing: 0.08em;
  text-transform: uppercase; margin-bottom: 8px;
}
.clarify-question {
  font-size: 17px; font-weight: 500;
  line-height: 1.35; margin-bottom: 10px;
}
.clarify-why {
  font-size: 13px; color: var(--muted);
  line-height: 1.5;
  padding: 10px 12px;
  background: var(--card);
  border-inline-start: 2px solid var(--border-strong);
  border-radius: 0 8px 8px 0;
  margin-bottom: 18px;
}
html[dir="rtl"] .clarify-why { border-radius: 8px 0 0 8px; }
.clarify-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.clarify-opt {
  text-align: start;
  padding: 13px 16px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px; transition: all var(--t);
}
.clarify-opt:hover { border-color: var(--border-strong); }
.clarify-opt.selected {
  background: var(--text); color: var(--bg); border-color: var(--text);
}
.clarify-free {
  width: 100%; padding: 13px 16px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px; outline: none;
  transition: border-color var(--t);
}
.clarify-free:focus { border-color: var(--text); }

/* ─── CONFIRM ─────────────────────────────────────────────────────────────── */
.confirm-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px; margin-bottom: 14px;
}
.confirm-row {
  display: flex; align-items: center;
  gap: 12px; padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.confirm-row:last-of-type { border-bottom: none; }
.confirm-row label {
  flex: 0 0 90px;
  font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  font-weight: 600;
}
.confirm-row input {
  flex: 1; padding: 8px 10px;
  background: var(--bg);
  border: 1.5px solid transparent;
  border-radius: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 14px; outline: none;
  transition: all var(--t);
}
.confirm-row input.mono { font-family: 'DM Mono', monospace; }
.confirm-row input:focus { background: var(--card); border-color: var(--border-strong); }
.confirm-notes {
  font-size: 13px; color: var(--muted);
  line-height: 1.5; margin-top: 12px;
  padding-top: 12px; border-top: 1px solid var(--border);
}
.confirm-badge-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
}

/* ─── SETUP / FIELDS ──────────────────────────────────────────────────────── */
.setup-intro { text-align: center; padding: 8px 0 24px; }
.setup-title {
  font-family: 'DM Mono', monospace;
  font-size: 28px; font-weight: 500;
  margin-bottom: 6px;
}
.setup-title .ori { color: var(--text); }
.setup-title .cal { color: var(--accent); font-weight: 700; }
.setup-sub { font-size: 14px; color: var(--muted); line-height: 1.4; }

.field-section { margin-bottom: 20px; }
.field-section-title {
  font-size: 11px; font-weight: 600;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.08em; margin-bottom: 10px;
}
.field-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.field-row {
  display: flex; align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.field-row:last-child { border-bottom: none; }
.field-label { flex: 1; font-size: 14px; font-weight: 500; }
.field-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.field-input {
  width: 100px; padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'DM Mono', monospace;
  font-size: 14px; text-align: end;
  background: var(--bg); outline: none;
  transition: border-color var(--t);
}
.field-input:focus { border-color: var(--text); }
.field-input.sm { width: 78px; }
.field-input.lg { width: 130px; }
.field-select {
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px; outline: none;
  min-width: 130px;
}
.field-row .pair { display: flex; gap: 6px; }

/* ─── TOGGLE ──────────────────────────────────────────────────────────────── */
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border-strong);
  border-radius: 12px;
  transition: background 0.2s;
  cursor: pointer;
}
.toggle-slider::before {
  content: ''; position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle input:checked + .toggle-slider { background: var(--text); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }
.toggle input:disabled + .toggle-slider { opacity: 0.4; cursor: not-allowed; }

/* ─── SEGMENTED CONTROL ───────────────────────────────────────────────────── */
.seg {
  display: inline-flex; gap: 4px;
  background: var(--border);
  padding: 4px;
  border-radius: 99px;
}
.seg-btn {
  background: transparent;
  border: none; border-radius: 99px;
  padding: 6px 14px;
  font-size: 12px; font-weight: 500;
  color: var(--muted);
  transition: all var(--t);
}
.seg-btn.active {
  background: var(--card); color: var(--text);
  box-shadow: var(--shadow);
}

/* ─── REMINDERS ───────────────────────────────────────────────────────────── */
.reminder-row {
  display: flex; align-items: center;
  padding: 12px 16px; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.reminder-row:last-child { border-bottom: none; }
.reminder-name { flex: 1; font-size: 13px; font-weight: 500; }
.reminder-time {
  width: 84px; padding: 6px 8px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'DM Mono', monospace;
  font-size: 13px; text-align: center;
  background: var(--bg); outline: none;
}
.reminder-time:focus { border-color: var(--text); }
.reminder-time:disabled { opacity: 0.5; }

/* ─── ESTIMATE TAB ────────────────────────────────────────────────────────── */
.estimate-result {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: center;
  margin-bottom: 20px;
}
.estimate-result .er-label {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted);
  font-weight: 600; margin-bottom: 4px;
}
.estimate-result .er-value {
  font-family: 'DM Mono', monospace;
  font-size: 36px; font-weight: 400;
  letter-spacing: -0.02em;
}
.estimate-result .er-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.goal-grid {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 20px;
}
.goal-card {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: start;
  width: 100%;
  transition: all var(--t);
}
.goal-card:hover { border-color: var(--border-strong); }
.goal-card.selected { border-color: var(--text); }
.goal-card-top {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 6px;
}
.goal-name { font-size: 14px; font-weight: 600; }
.goal-cal { font-family: 'DM Mono', monospace; font-size: 15px; font-weight: 500; }
.goal-desc { font-size: 12px; color: var(--muted); margin-bottom: 10px; line-height: 1.4; }
.goal-macros { display: flex; gap: 6px; font-size: 11px; font-family: 'DM Mono', monospace; flex-wrap: wrap; }
.goal-macro {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 99px;
}
.goal-macro.p { background: var(--protein-bg); color: var(--protein); }
.goal-macro.c { background: var(--carbs-bg);   color: var(--carbs); }
.goal-macro.f { background: var(--fat-bg);     color: var(--fat); }

/* ─── HISTORY TAB / CHART ─────────────────────────────────────────────────── */
.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px 12px;
  margin-bottom: 20px;
}
.chart-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.chart-title { font-size: 14px; font-weight: 600; }
.chart-legend { display: flex; gap: 10px; font-size: 11px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 4px; }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; }
.legend-dot.p { background: var(--protein); }
.legend-dot.c { background: var(--carbs); }
.legend-dot.f { background: var(--fat); }

.chart-wrap { position: relative; height: 160px; margin-bottom: 8px; }
.chart-bars { position: relative; display: flex; gap: 4px; align-items: flex-end; height: 100%; }
.chart-col {
  flex: 1;
  display: flex; flex-direction: column-reverse;
  height: 100%;
  background: transparent;
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.chart-col .col-bg {
  position: absolute; inset: 0;
  background: var(--border);
  opacity: 0.4;
  border-radius: 3px;
}
.chart-seg {
  width: 100%;
  position: relative;
  z-index: 1;
  transition: height 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}
.chart-seg.p { background: var(--protein); }
.chart-seg.c { background: var(--carbs); }
.chart-seg.f { background: var(--fat); }

.chart-goal-line {
  position: absolute;
  left: 0; right: 0;
  height: 0;
  border-top: 1.5px dashed var(--muted);
  pointer-events: none;
  z-index: 2;
}
.chart-goal-label {
  position: absolute;
  inset-inline-end: 0;
  top: -16px;
  font-size: 10px;
  color: var(--muted);
  font-family: 'DM Mono', monospace;
  background: var(--card);
  padding: 0 4px;
}

.chart-x {
  display: flex; gap: 4px;
  font-size: 10px;
  color: var(--muted);
  font-family: 'DM Mono', monospace;
}
.chart-x span { flex: 1; text-align: center; }

/* History list */
.history-day {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}
.history-day-top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.history-day-date { font-size: 13px; font-weight: 600; }
.history-day-cal { font-family: 'DM Mono', monospace; font-size: 13px; }
.history-day-cal .over { color: var(--danger); }
.history-day-bar {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
  display: flex;
}
.history-day-bar .seg-p { background: var(--protein); }
.history-day-bar .seg-c { background: var(--carbs); }
.history-day-bar .seg-f { background: var(--fat); }
.history-day-meta {
  display: flex; gap: 12px;
  margin-top: 6px;
  font-size: 11px; font-family: 'DM Mono', monospace;
  color: var(--muted);
}
.history-day-meta .m-p { color: var(--protein); }
.history-day-meta .m-c { color: var(--carbs); }
.history-day-meta .m-f { color: var(--fat); }
.history-empty {
  text-align: center; padding: 40px 0;
  color: var(--muted); font-size: 14px;
}

/* ─── TOAST ───────────────────────────────────────────────────────────────── */
#toasts {
  position: fixed; bottom: 80px; left: 50%;
  transform: translateX(-50%);
  z-index: 9999; pointer-events: none;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 11px 18px; border-radius: 24px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.25s cubic-bezier(0.32, 0.72, 0, 1);
}
.toast.error { background: var(--danger); }
.toast.fade-out { animation: toastOut 0.25s ease forwards; }
@keyframes toastIn  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(8px); } }

/* ─── SAFE AREAS / RESPONSIVE ─────────────────────────────────────────────── */
@supports (padding: env(safe-area-inset-top)) {
  .header { padding-top: calc(env(safe-area-inset-top) + 20px); }
}
@media (max-width: 390px) { .hero-number { font-size: 68px; } }

/* ─── VOICE TAB ───────────────────────────────────────────────────────────── */
.voice-recorder {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0 24px;
  margin-bottom: 12px;
}
.voice-record-btn {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--border);
  color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.2s ease, color 0.2s ease;
  cursor: pointer;
}
.voice-record-btn svg { width: 38px; height: 38px; }
.voice-record-btn:hover {
  border-color: var(--border-strong);
  transform: scale(1.03);
}
.voice-record-btn:active { transform: scale(0.97); }
.voice-record-btn.recording {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
  animation: voice-pulse-lg 1.4s ease-out infinite;
}
@keyframes voice-pulse-lg {
  0%   { box-shadow: 0 0 0 0   rgba(226, 75, 74, 0.45); }
  70%  { box-shadow: 0 0 0 22px rgba(226, 75, 74, 0);   }
  100% { box-shadow: 0 0 0 0   rgba(226, 75, 74, 0);   }
}
.voice-status {
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  min-height: 18px;
  transition: color 0.2s ease;
}
.voice-status.listening {
  color: var(--danger);
  font-weight: 500;
}

/* ─── THEME PICKER ────────────────────────────────────────────────────────── */
.theme-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.theme-swatch {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 4px;
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  transition: all var(--t);
  cursor: pointer;
}
.theme-swatch:hover { border-color: var(--border-strong); }
.theme-swatch.selected {
  border-color: var(--text);
  background: var(--bg);
}
.swatch-ring {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.swatch-ring::after {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--swatch);
}
.swatch-ring.rose  { background: #F2C8D4; }
.swatch-ring.rose::after  { background: #C8527A; }
.swatch-ring.ocean { background: #B8CFE6; }
.swatch-ring.ocean::after { background: #1F4B82; }
.swatch-ring.sage  { background: #C8D9A0; }
.swatch-ring.sage::after  { background: #4A6B1A; }
.swatch-ring.white { background: #D4D4D4; border: 1px solid #E5E5E5; }
.swatch-ring.white::after { background: #1A1A1A; }
.swatch-ring.violet { background: #D4B8EE; }
.swatch-ring.violet::after { background: #6B3FA0; }
.swatch-ring.beige  { background: #D9C5A9; }
.swatch-ring.beige::after { background: #8B5A2B; }
.theme-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}
.theme-swatch.selected .theme-label { color: var(--text); }

/* ─── MACRO LETTERS (hero P/C/F labels) ───────────────────────────────────── */
.hero-macros .macro-letter {
  font-weight: 600;
  margin-inline-start: 1px;
  opacity: 0.85;
}
.hero-macros .macro-letter.p { color: var(--protein); }
.hero-macros .macro-letter.c { color: var(--carbs); }
.hero-macros .macro-letter.f { color: var(--fat); }

/* ─── CHAT ───────────────────────────────────────────────────────────────── */
.chat-sheet { display: flex; flex-direction: column; height: 88vh; }
.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 16px 20px;
  display: flex; flex-direction: column; gap: 10px;
}
.chat-empty {
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 20px;
}
.chat-bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 20px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat-bubble.u {
  align-self: flex-end;
  background: var(--text); color: var(--bg);
  border-bottom-right-radius: 4px;
}
.chat-bubble.a {
  align-self: flex-start;
  background: var(--card); color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-bubble.thinking {
  align-self: flex-start;
  background: var(--card); color: var(--muted);
  border: 1px solid var(--border);
  font-style: italic;
}
.chat-input-bar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.chat-input {
  flex: 1;
  min-height: 44px; max-height: 120px;
  padding: 10px 14px;
  border-radius: 22px;
  border: 1.5px solid var(--border);
  background: var(--card);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  resize: none;
  outline: none;
  color: var(--text);
  transition: border-color var(--t);
}
.chat-input:focus { border-color: var(--text); }
.chat-send {
  width: 44px; height: 44px;
  border-radius: 22px;
  background: var(--text);
  color: var(--bg);
  border: none;
  display: inline-flex; align-items: center; justify-content: center;
  transition: opacity var(--t);
}
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-send:hover { opacity: 0.88; }

/* ─── ONBOARDING ─────────────────────────────────────────────────────────── */
.setup-welcome {
  text-align: center;
  padding: 32px 8px 28px;
}
.setup-welcome .setup-title {
  font-size: 38px;
  margin-bottom: 18px;
}
.setup-welcome-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}
.setup-welcome-sub {
  font-size: 15px;
  color: var(--muted);
  line-height: 1.5;
  margin: 0 auto;
  max-width: 320px;
}
.setup-feature-pills {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 26px;
}
.feature-pill {
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
}
.feature-pill.p { background: var(--protein-bg); color: var(--protein); }
.feature-pill.c { background: var(--carbs-bg);   color: var(--carbs); }
.feature-pill.f { background: var(--fat-bg);     color: var(--fat); }

.setup-step-header {
  padding: 8px 0 16px;
}
.setup-step-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.setup-step-sub {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.setup-goal-list {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 14px;
}
.setup-goal-choice {
  display: flex; align-items: center; gap: 12px;
  padding: 16px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  text-align: start;
  cursor: pointer;
  transition: border-color var(--t), background var(--t);
  color: var(--muted);
}
.setup-goal-choice:hover { border-color: var(--border-strong); }
.setup-goal-choice .goal-name {
  font-size: 15px; font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.setup-goal-choice .goal-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}
.setup-goal-choice > div { flex: 1; }
.setup-goal-choice > svg { flex-shrink: 0; }

.setup-tdee-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  margin-bottom: 14px;
}
.setup-tdee-lbl {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 4px;
}
.setup-tdee-val {
  font-family: 'DM Mono', monospace;
  font-size: 44px;
  font-weight: 400;
  letter-spacing: -0.04em;
  color: var(--text);
}
.setup-tdee-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.setup-goal-summary {
  background: var(--card);
  border: 1.5px solid var(--text);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

/* calorie input step */
.setup-calorie-wrap {
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 14px;
}
.setup-calorie-input {
  flex: 1;
  font-size: 38px;
  font-family: 'DM Mono', monospace;
  font-weight: 400;
  letter-spacing: -0.04em;
  text-align: center;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  min-width: 0;
}
.setup-calorie-input::placeholder { color: var(--muted); }
.setup-calorie-unit {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
.setup-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 12px;
}
.setup-divider::before, .setup-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.setup-tdee-link {
  display: flex; align-items: center; gap: 12px;
  padding: 16px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  text-align: start;
  cursor: pointer;
  transition: border-color var(--t), background var(--t);
  width: 100%;
  color: var(--muted);
}
.setup-tdee-link:hover { border-color: var(--border-strong); background: var(--bg); }
.setup-tdee-link > div { flex: 1; }
.setup-tdee-link-title {
  font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 3px;
}
.setup-tdee-link-sub {
  font-size: 12px; color: var(--muted); line-height: 1.4;
}
.setup-pick-label {
  font-size: 11px; font-weight: 500;
  color: var(--muted); letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 10px; margin-top: 4px;
}

/* ─── PIE CHART (today remaining) ─────────────────────────────────────────── */
.pie-wrap {
  position: relative;
  width: 240px; height: 240px;
  margin: 0 auto 16px;
}
.pie-svg {
  width: 100%; height: 100%;
  display: block;
  overflow: visible;
}
.pie-track { stroke: var(--border); }
.pie-seg   { transition: stroke-dasharray 0.5s cubic-bezier(0.4, 0, 0.2, 1), stroke-dashoffset 0.5s cubic-bezier(0.4, 0, 0.2, 1); }
#pie-seg-p { stroke: var(--protein); }
#pie-seg-c { stroke: var(--carbs); }
#pie-seg-f { stroke: var(--fat); }

.pie-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  pointer-events: none;
  text-align: center;
}
.pie-number {
  font-family: 'DM Mono', monospace;
  font-size: 42px;
  font-weight: 400;
  line-height: 1;
  letter-spacing: -0.04em;
  transition: color 0.3s;
}
.pie-number.over { color: var(--danger); }
.pie-unit {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  font-family: 'DM Mono', monospace;
}
.pie-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 6px;
  font-weight: 500;
}
.pie-caption {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 600;
  margin-top: -4px;
  margin-bottom: 8px;
}

@media (max-width: 390px) {
  .pie-wrap { width: 220px; height: 220px; }
  .pie-number { font-size: 38px; }
}

/* ─── MACRO RINGS (P / C / F mini donuts) ────────────────────────────────── */
.macro-rings {
  display: flex; justify-content: center;
  gap: 18px;
  margin: 8px 0 22px;
}
.macro-ring {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px;
}
.macro-ring-svg {
  width: 64px; height: 64px;
  position: relative;
}
.macro-ring-track { stroke: var(--border); }
.macro-ring-fill  { transition: stroke-dasharray 0.5s cubic-bezier(0.4, 0, 0.2, 1); }
.macro-ring-letter {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: 'DM Sans', sans-serif;
  font-size: 18px;
  font-weight: 700;
}
.macro-ring-letter.p { color: var(--protein); }
.macro-ring-letter.c { color: var(--carbs); }
.macro-ring-letter.f { color: var(--fat); }
.macro-ring-value {
  font-family: 'DM Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: -0.02em;
}
.macro-ring-value.over { color: var(--danger); }
.macro-ring-name {
  font-family: 'DM Sans', sans-serif;
  font-size: 10px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: -2px;
}

