/* ─── Variables ─────────────────────────────────────── */
:root {
  --chart-text: rgba(255,255,255,0.35);
  --bg: #0f1014;
  --bg2: #16181e;
  --bg3: #1e2028;
  --bg4: #252830;
  --border: #2a2d38;
  --text: #e8eaf0;
  --text2: #9499a8;
  --text3: #5a5f72;
  --accent: #4ade80;
  --accent2: #22c55e;
  --accent-dim: rgba(74, 222, 128, 0.12);
  --accent-dim2: rgba(74, 222, 128, 0.06);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.12);
  --yellow: #fbbf24;
  --blue: #60a5fa;
  --blue-dim: rgba(96, 165, 250, 0.12);
  --purple: #a78bfa;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;
  --font-display: 'Fraunces', serif;
  --nav-h: 60px;
  --bnav-h: 64px;
}


/* ─── Light Theme ────────────────────────────────────── */
[data-theme="light"] {
  --chart-text: rgba(0,0,0,0.45);
  --bg: #f5f6f8;
  --bg2: #ffffff;
  --bg3: #eef0f4;
  --bg4: #e4e7ed;
  --border: #d8dce6;
  --text: #1a1d24;
  --text2: #5a6070;
  --text3: #9499a8;
  --accent: #16a34a;
  --accent2: #15803d;
  --accent-dim: rgba(22, 163, 74, 0.1);
  --accent-dim2: rgba(22, 163, 74, 0.05);
  --red: #dc2626;
  --red-dim: rgba(220, 38, 38, 0.1);
  --yellow: #d97706;
  --blue: #2563eb;
  --blue-dim: rgba(37, 99, 235, 0.1);
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
}

/* ─── Reset ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
input, button, select, textarea { font-family: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; }

/* ─── App Shell ─────────────────────────────────────── */
#app { height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; }
.screen.hidden { display: none; }

/* ─── Auth ──────────────────────────────────────────── */
#auth-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 20% 50%, rgba(74,222,128,0.04) 0%, transparent 60%),
                    radial-gradient(ellipse at 80% 20%, rgba(96,165,250,0.03) 0%, transparent 50%);
  padding: 24px;
}
.auth-container {
  width: 100%;
  max-width: 380px;
}
.auth-logo {
  text-align: center;
  margin-bottom: 40px;
}
.logo-icon {
  font-size: 32px;
  color: var(--accent);
  display: block;
  margin-bottom: 8px;
}
.auth-logo h1 {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.5px;
}
.auth-logo p {
  color: var(--text2);
  font-size: 14px;
  margin-top: 4px;
}
.auth-tabs {
  display: flex;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 24px;
}
.auth-tab {
  flex: 1;
  padding: 8px;
  border-radius: calc(var(--radius) - 3px);
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  transition: all 0.2s;
}
.auth-tab.active { background: var(--bg4); color: var(--text); }
.auth-form { display: none; flex-direction: column; gap: 16px; }
.auth-form.active { display: flex; }

/* ─── Form Elements ─────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text2); }
.field input, .field select, .field textarea {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 15px;
  transition: border-color 0.2s;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.field input::placeholder { color: var(--text3); }
.field select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235a5f72' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
.form-error { color: var(--red); font-size: 13px; padding: 8px 12px; background: var(--red-dim); border-radius: var(--radius-sm); }
.form-error.hidden { display: none; }

/* ─── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #0a1a0f; }
.btn-primary:hover { background: var(--accent2); }
.btn-secondary { background: var(--bg3); border: 1px solid var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--bg4); }
.btn-ghost { color: var(--text2); padding: 8px 12px; }
.btn-ghost:hover { background: var(--bg3); color: var(--text); }
.btn-danger { background: var(--red-dim); color: var(--red); border: 1px solid rgba(248,113,113,0.2); }
.btn-danger:hover { background: rgba(248,113,113,0.2); }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-icon { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); color: var(--text2); font-size: 16px; transition: all 0.2s; }
.btn-icon:hover { background: var(--bg3); color: var(--text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Top Nav ───────────────────────────────────────── */
#top-nav {
  height: var(--nav-h);
  display: flex;
  align-items: center;
  padding: 0 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  gap: 24px;
  flex-shrink: 0;
}
.nav-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.nav-logo .logo-icon { font-size: 18px; color: var(--accent); }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text2);
  transition: all 0.2s;
}
.nav-link:hover { background: var(--bg3); color: var(--text); }
.nav-link.active { background: var(--accent-dim); color: var(--accent); }
.nav-user { display: flex; align-items: center; gap: 10px; margin-left: auto; }
#nav-username { font-size: 13px; color: var(--text2); }

/* ─── Bottom Nav (mobile) ───────────────────────────── */
#bottom-nav {
  display: none;
  height: var(--bnav-h);
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.bnav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text3);
  font-size: 11px;
  font-weight: 500;
  transition: color 0.2s;
  padding: 8px 4px;
}
.bnav-icon { font-size: 18px; line-height: 1; }
.bnav-item.active { color: var(--accent); }

/* ─── Main Content ──────────────────────────────────── */
#main-screen { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
#content { flex: 1; overflow-y: auto; overflow-x: hidden; }
.page { display: none; }
.page.active { display: block; }

/* ─── Page Layout ───────────────────────────────────── */
.page-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
}
.page-subtitle { font-size: 14px; color: var(--text2); margin-top: 2px; }

/* ─── Cards ─────────────────────────────────────────── */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-sm { padding: 14px 16px; }
.card + .card { margin-top: 12px; }

/* ─── Macro Summary Ring ────────────────────────────── */
.macro-summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 24px;
  align-items: center;
}
.macro-ring-wrap {
  position: relative;
  width: 120px;
  height: 120px;
  flex-shrink: 0;
}
.macro-ring-wrap svg { transform: rotate(-90deg); }
.macro-ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.macro-ring-cal { font-size: 22px; font-weight: 600; color: var(--text); font-family: var(--font-mono); }
.macro-ring-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; }
.macro-bars { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.macro-bar-row { display: flex; flex-direction: column; gap: 4px; }
.macro-bar-labels { display: flex; justify-content: space-between; font-size: 12px; }
.macro-bar-name { color: var(--text2); font-weight: 500; }
.macro-bar-value { color: var(--text); font-family: var(--font-mono); }
.bar-track { height: 6px; background: var(--bg4); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; }


.meal-header-macros { display:flex; gap:10px; margin-left:auto; margin-right:8px; flex-shrink:0; }
.meal-header-macro { font-size:12px; color:var(--text2); font-family:var(--font-mono); }
.meal-header-macro span { color:var(--text); }
@media (max-width:480px) {
  .meal-header-macros { gap:6px; }
  .meal-header-macro { font-size:11px; }
}

/* ─── Meal Sections ─────────────────────────────────── */
.meals-grid { display: flex; flex-direction: column; gap: 24px; margin-top: 20px; }
.meal-section { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.meal-header {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  cursor: pointer;
  user-select: none;
  gap: 10px;
}
.meal-icon { font-size: 20px; line-height: 1; }
.meal-name { font-weight: 600; font-size: 14px; flex: 1; }
.meal-cals { font-size: 13px; color: var(--text2); font-family: var(--font-mono); }
.meal-toggle { color: var(--text3); font-size: 12px; transition: transform 0.2s; }
.meal-section.open .meal-toggle { transform: rotate(180deg); }
.meal-entries { display: none; border-top: 1px solid var(--border); }
.meal-section.open .meal-entries { display: block; }
.meal-entry {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.meal-entry:last-child { border-bottom: none; }
.meal-entry:hover { cursor: pointer; }
.entry-info { flex: 1; min-width: 0; }
.entry-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-brand { font-size: 12px; color: var(--text2); }
.entry-macros { display: flex; gap: 12px; flex-shrink: 0; }
.entry-macro { font-size: 12px; color: var(--text2); font-family: var(--font-mono); }
.entry-macro span { color: var(--text); }

.meal-add-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  width: 100%;
  color: var(--text3);
  font-size: 13px;
  transition: all 0.2s;
  border-top: 1px dashed var(--border);
}
.meal-add-btn:hover { background: var(--bg3); color: var(--text2); }


/* ─── Per-meal colors ───────────────────────────────── */
/* Breakfast - green */
.meal-section[data-meal="breakfast"] .meal-header { background: rgba(74, 222, 128, 0.28); }
.meal-section[data-meal="breakfast"] .meal-header:hover { background: rgba(74, 222, 128, 0.35); }
.meal-section[data-meal="breakfast"] .meal-group-header { background: rgba(74, 222, 128, 0.15); }
.meal-section[data-meal="breakfast"] .meal-group-header:hover { background: rgba(74, 222, 128, 0.20); }
.meal-section[data-meal="breakfast"] .meal-group .meal-entry { background: rgba(74, 222, 128, 0.09); }
.meal-section[data-meal="breakfast"] .meal-group .meal-entry:hover { background: rgba(74, 222, 128, 0.14); }
.meal-section[data-meal="breakfast"] > .meal-entries > .meal-entry { background: rgba(74, 222, 128, 0.05); }
.meal-section[data-meal="breakfast"] > .meal-entries > .meal-entry:hover { background: rgba(74, 222, 128, 0.10); }

/* Lunch - blue */
.meal-section[data-meal="lunch"] .meal-header { background: rgba(96, 165, 250, 0.28); }
.meal-section[data-meal="lunch"] .meal-header:hover { background: rgba(96, 165, 250, 0.35); }
.meal-section[data-meal="lunch"] .meal-group-header { background: rgba(96, 165, 250, 0.15); }
.meal-section[data-meal="lunch"] .meal-group-header:hover { background: rgba(96, 165, 250, 0.20); }
.meal-section[data-meal="lunch"] .meal-group .meal-entry { background: rgba(96, 165, 250, 0.09); }
.meal-section[data-meal="lunch"] .meal-group .meal-entry:hover { background: rgba(96, 165, 250, 0.14); }
.meal-section[data-meal="lunch"] > .meal-entries > .meal-entry { background: rgba(96, 165, 250, 0.05); }
.meal-section[data-meal="lunch"] > .meal-entries > .meal-entry:hover { background: rgba(96, 165, 250, 0.10); }

/* Dinner - purple */
.meal-section[data-meal="dinner"] .meal-header { background: rgba(167, 139, 250, 0.28); }
.meal-section[data-meal="dinner"] .meal-header:hover { background: rgba(167, 139, 250, 0.35); }
.meal-section[data-meal="dinner"] .meal-group-header { background: rgba(167, 139, 250, 0.15); }
.meal-section[data-meal="dinner"] .meal-group-header:hover { background: rgba(167, 139, 250, 0.20); }
.meal-section[data-meal="dinner"] .meal-group .meal-entry { background: rgba(167, 139, 250, 0.09); }
.meal-section[data-meal="dinner"] .meal-group .meal-entry:hover { background: rgba(167, 139, 250, 0.14); }
.meal-section[data-meal="dinner"] > .meal-entries > .meal-entry { background: rgba(167, 139, 250, 0.12); }
.meal-section[data-meal="dinner"] > .meal-entries > .meal-entry:hover { background: rgba(167, 139, 250, 0.18); }

/* Snack - orange */
.meal-section[data-meal="snack"] .meal-header { background: rgba(251, 146, 60, 0.28); }
.meal-section[data-meal="snack"] .meal-header:hover { background: rgba(251, 146, 60, 0.35); }
.meal-section[data-meal="snack"] .meal-group-header { background: rgba(251, 146, 60, 0.15); }
.meal-section[data-meal="snack"] .meal-group-header:hover { background: rgba(251, 146, 60, 0.20); }
.meal-section[data-meal="snack"] .meal-group .meal-entry { background: rgba(251, 146, 60, 0.09); }
.meal-section[data-meal="snack"] .meal-group .meal-entry:hover { background: rgba(251, 146, 60, 0.14); }
.meal-section[data-meal="snack"] > .meal-entries > .meal-entry { background: rgba(251, 146, 60, 0.05); }
.meal-section[data-meal="snack"] > .meal-entries > .meal-entry:hover { background: rgba(251, 146, 60, 0.10); }

/* Add food button always neutral regardless of meal color */
.meal-section .meal-add-btn { background: var(--bg2) !important; }
.meal-section .meal-add-btn:hover { background: var(--bg4) !important; color: var(--text2) !important; }

/* Light theme - slightly more opaque */
[data-theme="light"] .meal-section[data-meal="breakfast"] .meal-header { background: rgba(74, 222, 128, 0.35); }
[data-theme="light"] .meal-section[data-meal="breakfast"] .meal-group-header { background: rgba(74, 222, 128, 0.18); }
[data-theme="light"] .meal-section[data-meal="breakfast"] .meal-group .meal-entry { background: rgba(74, 222, 128, 0.10); }
[data-theme="light"] .meal-section[data-meal="breakfast"] > .meal-entries > .meal-entry { background: rgba(74, 222, 128, 0.06); }
[data-theme="light"] .meal-section[data-meal="lunch"] .meal-header { background: rgba(96, 165, 250, 0.35); }
[data-theme="light"] .meal-section[data-meal="lunch"] .meal-group-header { background: rgba(96, 165, 250, 0.18); }
[data-theme="light"] .meal-section[data-meal="lunch"] .meal-group .meal-entry { background: rgba(96, 165, 250, 0.10); }
[data-theme="light"] .meal-section[data-meal="lunch"] > .meal-entries > .meal-entry { background: rgba(96, 165, 250, 0.06); }
[data-theme="light"] .meal-section[data-meal="dinner"] .meal-header { background: rgba(167, 139, 250, 0.35); }
[data-theme="light"] .meal-section[data-meal="dinner"] .meal-group-header { background: rgba(167, 139, 250, 0.18); }
[data-theme="light"] .meal-section[data-meal="dinner"] .meal-group .meal-entry { background: rgba(167, 139, 250, 0.10); }
[data-theme="light"] .meal-section[data-meal="dinner"] > .meal-entries > .meal-entry { background: rgba(167, 139, 250, 0.13); }
[data-theme="light"] .meal-section[data-meal="snack"] .meal-header { background: rgba(251, 146, 60, 0.35); }
[data-theme="light"] .meal-section[data-meal="snack"] .meal-group-header { background: rgba(251, 146, 60, 0.18); }
[data-theme="light"] .meal-section[data-meal="snack"] .meal-group .meal-entry { background: rgba(251, 146, 60, 0.10); }
[data-theme="light"] .meal-section[data-meal="snack"] > .meal-entries > .meal-entry { background: rgba(251, 146, 60, 0.06); }



/* ─── Icon contrast for light/dark themes ───────────── */
/* Light theme: darken ALL small icons and muted UI elements */
body.theme-light .meal-toggle { color: #374151; }
body.theme-light .meal-group-icon { color: #374151; }
body.theme-light .bnav-icon { color: #374151; }
body.theme-light .btn-icon { color: #374151; }
body.theme-light .search-btn { color: #374151; }
body.theme-light .scanner-status { color: #374151; }
body.theme-light .food-item-meta { color: #4b5563; }
body.theme-light .result-brand { color: #4b5563; }
body.theme-light .meal-header-macro { color: #374151; }
body.theme-light .entry-macro { color: #374151; }
body.theme-light .modal-close,
body.theme-light #modal-close { color: #374151; }
body.theme-light .nav-link { color: #374151; }
body.theme-light .bnav-item { color: #374151; }
body.theme-light .bnav-item .bnav-icon { color: #374151; }

/* Dark theme: lighten icons */
body.theme-dark .meal-toggle { color: #d1d5db; }
body.theme-dark .meal-group-icon { color: #d1d5db; }
body.theme-dark .bnav-icon { color: #9ca3af; }
body.theme-dark .food-item-meta { color: #9ca3af; }
body.theme-dark .result-brand { color: #9ca3af; }

/* ─── Meal Group (template log grouping) ────────────── */
.meal-group { border-bottom: 1px solid var(--border); }
.meal-group:last-of-type { border-bottom: none; }
.meal-group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: var(--bg3);
  user-select: none;
  transition: background 0.15s;
}
.meal-group-header:hover { filter: brightness(0.95); }
.meal-group-icon { font-size: 18px; flex-shrink: 0; line-height: 1; }
.meal-group-name { font-size: 13px; font-weight: 600; color: var(--text2); flex: 1; }
.meal-group-items { display: none; }
.meal-group.open .meal-group-items { display: block; }
.meal-group.open .meal-toggle { transform: rotate(180deg); }
.meal-group .meal-entry { padding-left: 32px; }

/* ─── Add Food Modal ────────────────────────────────── */
.add-food-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 0;
  flex-wrap: nowrap;
}
.add-food-tab {
  flex: 1;
  padding: 10px 4px;
  border-radius: calc(var(--radius-sm) - 2px);
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  text-align: center;
  transition: all 0.2s;
  white-space: nowrap;
}
.add-food-tab.active { background: var(--bg); color: var(--text); }
.add-food-panel { display: none; }
.add-food-panel.active { display: block; }

/* ─── Search ────────────────────────────────────────── */
.search-box {
  position: relative;
  margin-bottom: 12px;
}
.search-box input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 40px 10px 14px;
  color: var(--text);
  font-size: 15px;
}
.search-box input:focus { outline: none; border-color: var(--accent); }
.search-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  font-size: 16px;
  background: none;
  border: none;
}
.search-results { display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow-y: auto; }
.search-result-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  gap: 10px;
}
.search-result-item:hover { background: var(--bg3); border-color: var(--accent); }
.result-info { flex: 1; min-width: 0; }
.result-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-brand { font-size: 12px; color: var(--text2); }
.result-cal { font-size: 13px; color: var(--accent); font-family: var(--font-mono); white-space: nowrap; }

/* ─── Barcode Scanner ───────────────────────────────── */
.scanner-container { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 4/3; }
#scanner-video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.scanner-frame {
  width: 70%;
  aspect-ratio: 3/1;
  border: 2px solid var(--accent);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.5);
}
.scanner-line {
  position: absolute;
  left: 15%;
  right: 15%;
  height: 2px;
  background: var(--accent);
  animation: scan 2s linear infinite;
}
@keyframes scan { 0% { top: 30%; } 50% { top: 65%; } 100% { top: 30%; } }
.scanner-status { text-align: center; margin-top: 12px; font-size: 14px; color: var(--text2); }

/* ─── Image Upload ──────────────────────────────────── */
.image-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}
.image-drop-zone:hover, .image-drop-zone.drag-over { border-color: var(--accent); background: var(--accent-dim2); }
.image-drop-zone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-icon { font-size: 32px; margin-bottom: 8px; display: block; }
.drop-text { font-size: 14px; color: var(--text2); }
.drop-hint { font-size: 12px; color: var(--text3); margin-top: 4px; }
.image-preview { margin-top: 12px; border-radius: var(--radius-sm); overflow: hidden; max-height: 200px; display: none; }
.image-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ai-result { margin-top: 16px; }
.ai-result-header { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 13px; color: var(--text2); }
.confidence-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.confidence-high { background: rgba(74,222,128,0.15); color: var(--accent); }
.confidence-medium { background: rgba(251,191,36,0.15); color: var(--yellow); }
.confidence-low { background: rgba(248,113,113,0.15); color: var(--red); }
.ai-items-list { margin-bottom: 12px; }
.ai-item { font-size: 13px; color: var(--text2); padding: 4px 0; border-bottom: 1px solid var(--border); }
.ai-item:last-child { border: none; }

/* ─── Nutrition Form ────────────────────────────────── */
.nutrition-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 4px;
}
.nutrition-grid .field.span2 { grid-column: span 2; }
.serving-row { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }

/* ─── Stats Row ─────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-value { font-size: 24px; font-weight: 600; font-family: var(--font-mono); color: var(--text); }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 2px; }
.stat-sub { font-size: 12px; color: var(--text3); margin-top: 4px; font-family: var(--font-mono); }

/* ─── History Chart ─────────────────────────────────── */
.chart-container { position: relative; height: 200px; }
canvas { max-width: 100%; }

/* ─── History Table ─────────────────────────────────── */
.history-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.history-table th { text-align: left; padding: 8px 12px; font-size: 12px; font-weight: 500; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
.history-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.history-table tr:last-child td { border-bottom: none; }
.history-table tr:hover td { background: var(--bg3); }
.history-table .num { font-family: var(--font-mono); }

/* ─── Foods Page ────────────────────────────────────── */
.foods-list { display: flex; flex-direction: column; gap: 8px; }
.food-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  gap: 12px;
  transition: background 0.15s;
}
.food-item:hover { background: var(--bg3); }
.food-item-info { flex: 1; }
.food-item-name { font-weight: 500; font-size: 14px; }
.food-item-meta { font-size: 12px; color: var(--text2); }
.food-item-macros { font-size: 12px; color: var(--text2); font-family: var(--font-mono); text-align: right; }

/* ─── Settings ──────────────────────────────────────── */
.settings-section { margin-bottom: 32px; }
.settings-section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text3); margin-bottom: 12px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--border); gap: 20px; }
.settings-row:last-child { border-bottom: none; }
.settings-label { font-size: 14px; font-weight: 500; }
.settings-hint { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ─── Admin ─────────────────────────────────────────── */
.user-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.user-table th { text-align: left; padding: 8px 12px; font-size: 12px; font-weight: 500; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
.user-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-green { background: var(--accent-dim); color: var(--accent); }
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-blue { background: var(--blue-dim); color: var(--blue); }

/* ─── Modal ─────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  backdrop-filter: blur(4px);
}
#modal-overlay.hidden { display: none; }
#modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  position: relative;
  padding: 24px;
  box-shadow: var(--shadow);
}
#modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  color: var(--text3);
  font-size: 14px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all 0.2s;
}
#modal-close:hover { background: var(--bg4); color: var(--text); }
.modal-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
  padding-right: 32px;
}

/* ─── Toast ─────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 80px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  animation: slideIn 0.3s ease;
  box-shadow: var(--shadow);
}
.toast-success { background: var(--accent); color: #0a1a0f; }
.toast-error { background: var(--red); color: #fff; }
.toast-info { background: var(--bg4); color: var(--text); border: 1px solid var(--border); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Loading ───────────────────────────────────────── */
.loading { display: flex; align-items: center; justify-content: center; padding: 32px; color: var(--text2); gap: 10px; font-size: 14px; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { text-align: center; padding: 48px 24px; color: var(--text2); }
.empty-state-icon { font-size: 36px; margin-bottom: 12px; display: block; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ─── Dividers / Utils ──────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.text-sm { font-size: 13px; }
.text-muted { color: var(--text2); }
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }

/* ─── Date nav ──────────────────────────────────────── */
.date-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
}
.date-nav-btn { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 6px; color: var(--text2); font-size: 14px; transition: all 0.2s; }
.date-nav-btn:hover { background: var(--bg3); color: var(--text); }
#current-date-label { font-size: 13px; font-weight: 500; width: 80px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Responsive ────────────────────────────────────── */

/* ─── Mobile header ──────────────────────────────────── */
#mobile-header {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

#mobile-page-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}

#mobile-app-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

@media (max-width: 768px) {
  #mobile-header { display: flex; }
}

@media (max-width: 768px) {
  #top-nav { display: none; }
  #bottom-nav { display: flex; }
  #content { padding-bottom: 0; }
  #toast-container { bottom: calc(var(--bnav-h) + 12px); right: 12px; left: 12px; }
  .toast { text-align: center; }
  .page-inner { padding: 16px 14px 24px; }
  .page-header { flex-wrap: nowrap; align-items: flex-start; }
  .date-nav { flex-shrink: 0; margin-left: auto; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .macro-summary { grid-template-columns: 1fr; }
  .macro-ring-wrap { margin: 0 auto; }
  .entry-macros { display: none; }
  .entry-actions { opacity: 1; }
  .history-table { font-size: 13px; }
  .history-table th:nth-child(n+4), .history-table td:nth-child(n+4) { display: none; }
  #modal-box { padding: 20px 16px; }
  .nutrition-grid { grid-template-columns: 1fr; }
  .nutrition-grid .field.span2 { grid-column: span 1; }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-value { font-size: 20px; }
  .add-food-tab { font-size: 10px; padding: 6px 1px; }
}
