:root {
  --bg-primary: #0b0f17;
  --bg-secondary: #131b2a;
  --bg-card: #1b253b;
  --bg-card-hover: #222f4b;
  --border-color: #2a3754;
  --accent-color: #10b981; /* Emerald green */
  --accent-hover: #059669;
  --accent-glow: rgba(16, 185, 129, 0.15);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --info-color: #38bdf8;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-family);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0 20px 0;
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-badge {
  background: linear-gradient(135deg, #10b981, #047857);
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Tabs */
.tabs-nav {
  display: flex;
  gap: 8px;
  margin: 20px 0;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.tabs-nav::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 10px 18px;
  border-radius: 9999px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.tab-btn .tab-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.tab-btn:hover {
  color: var(--text-main);
  background: var(--bg-card);
}

.tab-btn.active {
  background: var(--accent-color);
  color: #fff;
  border-color: var(--accent-color);
  box-shadow: 0 2px 8px var(--accent-glow);
}

/* Tab Content */
.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
  animation: fadeIn 0.2s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Cards & Layout */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
}

.stat-card.highlight {
  border-color: var(--accent-color);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), var(--bg-card));
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  margin: 6px 0;
  color: var(--text-main);
}

.stat-meta {
  font-size: 0.8rem;
  font-weight: 500;
}

.text-success { color: #34d399; }
.text-info { color: #38bdf8; }
.text-muted { color: var(--text-muted); }

/* Charts */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
  gap: 20px;
}

@media (max-width: 600px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

.chart-wrapper {
  position: relative;
  height: 280px;
  width: 100%;
}

/* Buttons */
.btn {
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary {
  background: var(--accent-color);
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover {
  background: var(--bg-card);
}

.btn-outline {
  background: transparent;
  color: var(--accent-color);
  border: 1px solid var(--accent-color);
}
.btn-outline:hover {
  background: rgba(16, 185, 129, 0.1);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

/* Meal Plan */
.mealplan-header-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.day-selector-pills {
  display: flex;
  gap: 8px;
  margin: 16px 0 24px 0;
  overflow-x: auto;
  padding-bottom: 6px;
}

.day-pill {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.2s;
}

.day-pill.active {
  background: var(--info-color);
  color: #0b0f17;
  border-color: var(--info-color);
  font-weight: 700;
}

.day-meals-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.meal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.meal-timing {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent-color);
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.meal-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.meal-portion {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.meal-macros {
  display: flex;
  gap: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
  font-size: 0.85rem;
  font-weight: 600;
}

.macro-item span {
  color: var(--accent-color);
}

/* Tables */
.search-box input {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  width: 280px;
}

.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.data-table th, .data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  color: var(--text-muted);
  font-weight: 600;
}

.data-table tr:hover {
  background: var(--bg-card-hover);
}

/* Recipes Grid */
.recipes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.recipe-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
}

.recipe-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 10px;
}

.recipe-time-badge {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-color);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}

.recipe-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.ingredients-list {
  list-style: none;
  margin-bottom: 16px;
  font-size: 0.84rem;
}

.ingredients-list li {
  padding: 4px 0;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.05);
}

.recipe-instructions {
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: auto;
}

/* AI Snap Guide */
.guide-card {
  padding: 30px;
}
.guide-card .lead {
  font-size: 1.05rem;
  color: var(--text-muted);
  margin: 10px 0 24px 0;
}

.guide-steps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.step-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  display: flex;
  flex-direction: column;
}

.step-icon {
  font-size: 2rem;
  margin-bottom: 12px;
}

.step-example {
  background: rgba(0, 0, 0, 0.25);
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  margin: 12px 0;
  border-left: 3px solid var(--accent-color);
}

.step-badge {
  font-size: 0.75rem;
  color: var(--info-color);
  font-weight: 600;
  margin-top: auto;
}

/* Modals */
.modal-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.active {
  display: flex;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  max-width: 500px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.modal.modal-lg {
  max-width: 700px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

.url-badge {
  background: var(--bg-secondary);
  border: 1px solid var(--accent-color);
  color: var(--accent-color);
  font-family: monospace;
  font-size: 1.1rem;
  padding: 12px;
  border-radius: var(--radius-sm);
  text-align: center;
  margin: 16px 0;
  user-select: all;
}

.qr-container {
  display: flex;
  justify-content: center;
  margin: 16px 0;
}

/* Grocery checklist */
.grocery-checklist {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.grocery-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
}

.grocery-item.checked {
  opacity: 0.5;
  text-decoration: line-through;
}

.grocery-item input {
  cursor: pointer;
}

/* Purchase Grouping Styles */
.purchase-view-pills {
  display: flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  padding: 3px;
  gap: 4px;
}

.view-pill {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.view-pill:hover {
  color: var(--text-main);
}

.view-pill.active {
  background: var(--accent-color);
  color: #fff;
  box-shadow: 0 2px 6px var(--accent-glow);
}

.group-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.group-card:hover {
  border-color: #3b4d75;
}

.group-header {
  padding: 16px 20px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  user-select: none;
  background: rgba(255, 255, 255, 0.015);
}

.group-header:hover {
  background: rgba(255, 255, 255, 0.04);
}

.group-title-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.group-chevron {
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: transform 0.25s ease;
}

.group-card.open .group-chevron {
  transform: rotate(90deg);
}

.group-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.group-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.group-summary-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.summary-badge {
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
}

.badge-kcal {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-protein {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.badge-carbs {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-fat {
  background: rgba(236, 72, 153, 0.15);
  color: #f472b6;
  border: 1px solid rgba(236, 72, 153, 0.3);
}

.badge-price {
  background: rgba(148, 163, 184, 0.15);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.badge-upf {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-clean {
  background: rgba(52, 211, 153, 0.15);
  color: #34d399;
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.badge-avg {
  background: rgba(168, 85, 247, 0.15);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.3);
}

.group-content {
  display: none;
  border-top: 1px solid var(--border-color);
  padding: 0;
  background: var(--bg-secondary);
}

.group-card.open .group-content {
  display: block;
}

/* Food Catalog Grouping & Recipe Highlight Styles */
.food-group-card {
  margin-bottom: 16px;
}

.food-group-card.recipe-group-card {
  border: 1px solid rgba(245, 158, 11, 0.45);
  box-shadow: 0 4px 18px rgba(245, 158, 11, 0.08);
}

.food-group-card.recipe-group-card .group-header {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.12) 0%, rgba(255, 255, 255, 0.02) 100%);
}

.recipe-table-row {
  background: rgba(245, 158, 11, 0.035);
  transition: background 0.15s ease;
}

.recipe-table-row:hover {
  background: rgba(245, 158, 11, 0.08) !important;
}

.badge-total-kcal {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  display: inline-block;
  white-space: nowrap;
  font-size: 0.85rem;
}

.badge-total-prot {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.35);
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  display: inline-block;
  white-space: nowrap;
  font-size: 0.85rem;
}

.badge-homemade {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.78rem;
  display: inline-block;
  white-space: nowrap;
}

/* Recipe Ingredients Row Base (Desktop) */
.recipe-ing-row {
  display: grid;
  grid-template-columns: minmax(130px, 1.2fr) minmax(180px, 2fr) 75px 145px 120px 36px;
  gap: 8px;
  align-items: center;
  background: var(--bg-card);
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

/* Food Catalog: Desktop Table vs Mobile Cards */
.desktop-only-table {
  display: block;
}

.mobile-only-cards {
  display: none;
}

/* Food Mobile Cards */
.food-mobile-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  position: relative;
  user-select: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.food-mobile-card:active {
  background: var(--bg-card-hover);
}

.food-mobile-card.recipe-mobile-card {
  border-color: rgba(245, 158, 11, 0.35);
  background: linear-gradient(180deg, rgba(245, 158, 11, 0.05) 0%, var(--bg-card) 100%);
}

.food-mobile-card.trashed-item {
  opacity: 0.65;
  border-style: dashed;
}

.food-card-main-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.food-card-star-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  min-height: auto;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: transform 0.15s ease;
}

.food-card-star-btn:active {
  transform: scale(1.2);
}

.food-card-thumb {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 8px;
  overflow: hidden;
  background: #0b0f17;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
}

.food-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.food-card-icon-fallback {
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}

.food-card-info {
  flex: 1;
  min-width: 0;
}

.food-card-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-main);
  line-height: 1.3;
  word-break: break-word;
}

.food-card-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.food-card-macro-pill {
  flex-shrink: 0;
  text-align: right;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 5px 9px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
}

.food-card-macro-pill strong {
  color: var(--accent-color);
  font-size: 0.95rem;
  line-height: 1.1;
}

.food-card-macro-pill .unit {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
}

.food-card-macro-pill .prot {
  font-size: 0.78rem;
  color: #38bdf8;
  font-weight: 700;
  margin-top: 1px;
}

.badge-upf-pill {
  background: rgba(239, 68, 68, 0.18);
  color: #f87171;
  font-weight: 700;
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 4px;
}

.badge-clean-pill {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  font-weight: 700;
  font-size: 0.72rem;
  padding: 1px 6px;
  border-radius: 4px;
}

.food-card-actions-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.food-card-expand-indicator {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.2s ease;
}

.food-card-expand-indicator .cue-arrow {
  display: inline-block;
  font-size: 0.68rem;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.food-mobile-card.expanded .food-card-expand-indicator {
  color: var(--accent-color);
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.3);
}

.food-mobile-card.expanded .food-card-expand-indicator .cue-arrow {
  transform: rotate(180deg);
}

.food-card-btns {
  display: flex;
  gap: 6px;
}

/* Collapsible Per-100g Nutrition Panel */
.food-card-details-drawer {
  display: none;
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 12px;
  margin-top: 2px;
  animation: fadeInDown 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.food-mobile-card.expanded .food-card-details-drawer {
  display: block;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.food-card-details-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.food-card-nutrition-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.food-detail-item {
  background: var(--bg-card);
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.82rem;
}

.food-detail-item .label {
  color: var(--text-muted);
  font-size: 0.76rem;
}

.food-detail-item .val {
  font-weight: 600;
  color: var(--text-main);
}

.food-detail-item.highlight-prot {
  border-color: rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.08);
}

.food-detail-item.highlight-prot .val {
  color: #38bdf8;
  font-weight: 700;
}

.food-card-details-footer {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
}

.footer-badge-total {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text-main);
}

.chart-range-btn {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}
.chart-range-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}
.chart-range-btn.active {
  background: var(--accent-color) !important;
  color: #0b0f17 !important;
  font-weight: 700;
}

/* Floating Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  background: #1e293b;
  color: #f8fafc;
  border: 1px solid var(--border-color);
  padding: 12px 18px;
  border-radius: 8px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  animation: slideInUp 0.25s ease-out forwards;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.toast-success {
  border-left: 4px solid var(--accent-color);
}
.toast.toast-danger {
  border-left: 4px solid #ef4444;
}
.toast.toast-warning {
  border-left: 4px solid #f59e0b;
}
.toast.toast-info {
  border-left: 4px solid #38bdf8;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   Meals & Planning Tab Components (Previous Meals Log & Weekly Planner)
   ========================================================================== */

.meal-subtab-pane {
  animation: fadeIn 0.2s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* History Timeline Day Card */
.history-day-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.history-day-header {
  padding: 12px 18px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.history-day-meals-list {
  padding: 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-meal-row {
  background: rgba(11, 15, 23, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  transition: border-color 0.2s, background 0.2s;
}

.history-meal-row:hover {
  border-color: rgba(56, 189, 248, 0.4);
  background: rgba(19, 27, 42, 0.8);
}

/* 7-Day Mini Week Strip in Planner */
.planner-week-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  margin-top: 14px;
}

@media (max-width: 900px) {
  .planner-week-strip {
    display: flex;
    overflow-x: auto;
    padding-bottom: 8px;
  }
  .planner-mini-card {
    min-width: 110px;
    flex-shrink: 0;
  }
}

.planner-mini-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.planner-mini-card:hover {
  border-color: var(--info-color);
  transform: translateY(-2px);
}

.planner-mini-card.active {
  border-color: var(--info-color);
  background: rgba(56, 189, 248, 0.12);
}

.planner-mini-card.target-met {
  border-color: var(--accent-color);
}

/* Planner Meal Slot Group */
.planner-slot-group {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

.planner-slot-header {
  padding: 10px 18px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 0.92rem;
}

.planner-slot-body {
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.planned-meal-item {
  background: rgba(11, 15, 23, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  transition: all 0.2s;
}

.planned-meal-item:hover {
  border-color: rgba(16, 185, 129, 0.4);
}

.planner-7day-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px;
}

/* =================================================== */
/* OVERVIEW: TODAY'S MACRO RINGS & QUICK-LOG SECTION   */
/* =================================================== */
.today-hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.today-ring-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  transition: transform 0.2s, border-color 0.2s;
}

.today-ring-card:hover {
  border-color: rgba(56, 189, 248, 0.4);
}

.ring-svg-wrapper {
  position: relative;
  width: 82px;
  height: 82px;
  flex-shrink: 0;
}

.ring-svg {
  transform: rotate(-90deg);
  width: 82px;
  height: 82px;
}

.ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 7;
}

.ring-progress {
  fill: none;
  stroke-width: 7;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.ring-center-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1.1;
}

.today-quick-eat-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 20px;
}

.quick-eat-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  overflow-x: visible;
  padding-bottom: 0;
  margin-top: 10px;
}

.quick-eat-chip {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  padding: 7px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.quick-eat-chip:hover {
  background: rgba(16, 185, 129, 0.15);
  border-color: var(--accent-color);
  color: var(--accent-color);
  transform: translateY(-2px);
  box-shadow: 0 3px 10px rgba(16, 185, 129, 0.2);
}

/* Portion Preset Pills */
.portion-presets {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.portion-pill {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.portion-pill:hover, .portion-pill.active {
  background: rgba(56, 189, 248, 0.15);
  border-color: #38bdf8;
  color: #38bdf8;
}


/* Grocery Interactive Items */
.grocery-check-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.grocery-check-row:hover {
  border-color: var(--info-color);
}

.grocery-check-row.checked {
  opacity: 0.5;
  text-decoration: line-through;
  background: rgba(11, 15, 23, 0.4);
}

/* ==========================================================================
   MOBILE-FIRST ERGONOMICS, BOTTOM NAVIGATION & BOTTOM SHEETS (< 768px)
   ========================================================================== */

/* Modal Drag / Pull Handle */
.modal-handle-bar {
  display: none;
  width: 44px;
  height: 5px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 9999px;
  margin: 0 auto 16px auto;
}

@media (max-width: 768px) {
  /* Prevent content hiding behind fixed bottom navigation */
  body {
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 16px)) !important;
  }

  /* Fixed Bottom Navigation Bar */
  .tabs-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 8px));
    background: rgba(11, 15, 23, 0.96);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--border-color);
    z-index: 999;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 3px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.5);
    overflow: hidden;
  }

  .tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 2px;
    border-radius: 8px;
    background: transparent;
    border: none;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    min-height: 50px;
    gap: 3px;
    transition: all 0.15s ease;
  }

  .tab-btn .tab-icon {
    font-size: 1.25rem;
    line-height: 1;
  }

  .tab-btn .tab-text {
    font-size: 0.67rem;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }

  .tab-btn:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-main);
  }

  .tab-btn.active {
    background: rgba(16, 185, 129, 0.16);
    color: var(--accent-color);
    box-shadow: none;
    border: 1px solid rgba(16, 185, 129, 0.3);
  }

  .tab-btn.active .tab-icon {
    transform: scale(1.12);
    transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  }

  /* Bottom-Sheet Style Modals */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-handle-bar {
    display: block;
  }

  .modal, .modal.modal-lg {
    max-width: 100%;
    width: 100%;
    border-radius: 24px 24px 0 0;
    max-height: 88vh;
    overflow-y: auto;
    padding: 18px 18px calc(24px + env(safe-area-inset-bottom, 16px));
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
    animation: sheetSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes sheetSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  /* 48px Minimum Touch Targets & Form Ergonomics */
  .btn {
    min-height: 46px;
    padding: 10px 16px;
    font-size: 0.92rem;
    border-radius: 8px;
  }

  .btn-sm {
    min-height: 40px;
    padding: 8px 12px;
  }

  .quick-eat-chip {
    min-height: 46px;
    padding: 10px 16px;
    font-size: 0.88rem;
  }

  .portion-pill {
    min-height: 38px;
    padding: 8px 14px;
    font-size: 0.82rem;
  }

  .view-pill {
    min-height: 38px;
    padding: 8px 14px;
    font-size: 0.82rem;
  }

  .form-input, select, input[type="text"], input[type="number"], input[type="date"], textarea {
    min-height: 46px;
    font-size: 1rem !important; /* Prevents auto-zoom on iOS */
    padding: 10px 14px;
  }

  /* Header Compactness on Mobile */
  .header {
    padding: 12px 14px;
    gap: 8px;
  }

  .header h1 {
    font-size: 1.25rem;
  }

  .header .subtitle {
    font-size: 0.78rem;
  }

  /* Stats Grid Compact on Mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .today-hub-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Energy Tab: Strict Zero Side-Scrolling */
  #tab-energy {
    overflow-x: hidden;
    max-width: 100%;
    width: 100%;
  }

  .today-quick-eat-bar {
    max-width: 100%;
    overflow: hidden;
  }

  .quick-eat-scroll {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    overflow-x: visible !important;
    width: 100% !important;
  }

  .quick-eat-chip {
    width: 100% !important;
    justify-content: center !important;
    text-align: center !important;
    white-space: normal !important;
    min-height: 50px !important;
    padding: 8px 10px !important;
    font-size: 0.8rem !important;
    flex-direction: column !important;
    gap: 2px !important;
  }

  .range-btn-group {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 4px !important;
    width: 100% !important;
    overflow-x: visible !important;
  }

  .range-btn-group .chart-range-btn {
    flex: 1 1 calc(33% - 4px) !important;
    text-align: center !important;
    font-size: 0.76rem !important;
    padding: 7px 4px !important;
    white-space: nowrap !important;
  }

  /* Food Catalog: Switch from Wide Table to Mobile Cards */
  .desktop-only-table {
    display: none !important;
  }

  .mobile-only-cards {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px !important;
    padding: 10px 0 !important;
  }

  .food-group-card .group-content {
    padding: 0 10px 10px 10px !important;
  }

  /* Food Catalog Header & Search on Mobile */
  #tab-catalog .card-header > div:last-child {
    width: 100% !important;
  }

  #tab-catalog .search-box {
    width: 100% !important;
  }

  #tab-catalog .search-box input {
    width: 100% !important;
  }

  #tab-catalog #openAddFoodModalBtn {
    flex: 1 1 auto !important;
  }

  #foodFilterPills {
    width: 100% !important;
    display: flex !important;
    justify-content: space-between !important;
  }

  #foodFilterPills .view-pill {
    flex: 1 !important;
    text-align: center !important;
    padding: 8px 4px !important;
  }

  /* Recipe Builder Ingredients Rows: Mobile Vertical Card Layout */
  .recipe-ing-row {
    display: grid !important;
    grid-template-columns: 1fr auto !important;
    grid-template-areas:
      "cat del"
      "food food"
      "amt unit"
      "macro macro" !important;
    gap: 8px !important;
    padding: 12px !important;
    border-radius: 8px !important;
    background: var(--bg-card) !important;
    border: 1px solid rgba(16, 185, 129, 0.3) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25) !important;
  }

  .recipe-ing-cat-filter {
    grid-area: cat !important;
    width: 100% !important;
    min-height: 42px !important;
  }

  .remove-row-btn {
    grid-area: del !important;
    min-height: 42px !important;
    min-width: 42px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .recipe-ing-select {
    grid-area: food !important;
    width: 100% !important;
    min-height: 46px !important;
    font-size: 0.95rem !important;
    font-weight: 600 !important;
  }

  .recipe-ing-amount {
    grid-area: amt !important;
    width: 100% !important;
    min-height: 44px !important;
  }

  .recipe-ing-unit {
    grid-area: unit !important;
    width: 100% !important;
    min-height: 44px !important;
  }

  .recipe-row-macro-badge {
    grid-area: macro !important;
    text-align: left !important;
    padding: 8px 12px !important;
    background: rgba(16, 185, 129, 0.12) !important;
    border: 1px solid rgba(16, 185, 129, 0.25) !important;
    border-radius: 6px !important;
    font-size: 0.88rem !important;
    display: flex !important;
    align-items: center !important;
  }

  /* Recipes Grid on Mobile */
  .recipes-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
}

