/* ==========================================================================
   ماكروز — Multi-User Arabic RTL Nutrition, Grocery & Admin App Styles
   Auto-fitting across mobile (320px+), tablets, laptops, and ultra-wide screens
   ========================================================================== */

:root {
  --font-sans: 'Cairo', -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, Arial, sans-serif;

  /* Brand & Surfaces (Light Mode — crisp card vs canvas separation) */
  --bg: #EBF1EE;
  --surface: #FFFFFF;
  --surface-subtle: #F6F9F8;
  --surface-hover: #EDF4F1;
  --border: #DCE6E2;
  --border-strong: #C3D4CD;

  --text: #112420;
  --text-secondary: #4D645E;
  --text-muted: #7C928C;

  --primary: #0F766E;
  --primary-hover: #0D5F59;
  --primary-soft: #E6F4F1;
  --primary-gradient: linear-gradient(135deg, #0F766E 0%, #059669 100%);

  /* Macro Semantic Colors */
  --protein: #059669;
  --protein-soft: #ECFDF5;
  --protein-border: #A7F3D0;

  --carbs: #D97706;
  --carbs-soft: #FFFBEB;
  --carbs-border: #FDE68A;

  --fat: #E11D48;
  --fat-soft: #FFF1F2;
  --fat-border: #FECDD3;

  --calories: #4F46E5;
  --calories-soft: #EEF2FF;
  --calories-border: #C7D2FE;

  --danger: #DC2626;
  --danger-soft: #FEF2F2;
  --success: #059669;
  --success-soft: #ECFDF5;
  --warning: #D97706;
  --warning-soft: #FFFBEB;

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 3px rgba(15, 36, 32, 0.05), 0 1px 2px rgba(15, 36, 32, 0.03);
  --shadow-md: 0 8px 24px rgba(15, 36, 32, 0.07), 0 2px 6px rgba(15, 36, 32, 0.04);
  --shadow-lg: 0 20px 50px rgba(15, 36, 32, 0.18);

  --sidebar-width: 260px;
  --bottom-nav-height: 68px;
}

[data-theme="dark"] {
  --bg: #08100F;
  --surface: #121F1E;
  --surface-subtle: #182927;
  --surface-hover: #1E3330;
  --border: #253C39;
  --border-strong: #32504B;

  --text: #EEF5F3;
  --text-secondary: #A4BCB6;
  --text-muted: #6F8B84;

  --primary: #14B8A6;
  --primary-hover: #2DD4BF;
  --primary-soft: rgba(20, 184, 166, 0.14);
  --primary-gradient: linear-gradient(135deg, #0D9488 0%, #059669 100%);

  --protein: #34D399;
  --protein-soft: rgba(16, 185, 129, 0.14);
  --protein-border: rgba(52, 211, 153, 0.3);

  --carbs: #FBBF24;
  --carbs-soft: rgba(245, 158, 11, 0.14);
  --carbs-border: rgba(251, 191, 36, 0.3);

  --fat: #FB7185;
  --fat-soft: rgba(244, 63, 94, 0.14);
  --fat-border: rgba(251, 113, 133, 0.3);

  --calories: #818CF8;
  --calories-soft: rgba(99, 102, 241, 0.16);
  --calories-border: rgba(129, 140, 248, 0.3);

  --danger: #F87171;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --success: #34D399;
  --success-soft: rgba(16, 185, 129, 0.14);
  --warning: #FBBF24;
  --warning-soft: rgba(245, 158, 11, 0.14);

  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.38);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
}

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

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  min-height: 100%;
  overflow-x: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   Auth Screen
   ========================================================================== */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 14px;
  background: radial-gradient(circle at top right, var(--primary-soft), transparent 55%), var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 26px 24px 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.auth-brand h1 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.15;
}

.auth-brand p {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

.auth-security-badge {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  text-align: center;
}

.auth-first-admin-note {
  font-size: 0.8rem;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--warning-soft);
  border: 1px solid var(--carbs-border);
  color: var(--text);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.auth-tab {
  padding: 9px 10px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-secondary);
  transition: all 0.16s ease;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-submit-btn {
  width: 100%;
  padding: 12px;
  font-size: 0.96rem;
  margin-top: 4px;
}

.auth-error {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.84rem;
  font-weight: 700;
}

.auth-info {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--success-soft);
  color: var(--success);
  font-size: 0.84rem;
  font-weight: 700;
}

.strength-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

.strength-bar-track {
  flex: 1;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--surface-hover);
  overflow: hidden;
}

.strength-bar-fill {
  height: 100%;
  width: 0;
  border-radius: var(--radius-full);
  transition: width 0.25s ease, background 0.25s ease;
}

.strength-label {
  font-size: 0.74rem;
  font-weight: 700;
  min-width: 66px;
  text-align: left;
}

.auth-footer-links {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ==========================================================================
   Site Announcement Banner
   ========================================================================== */
.site-announcement {
  background: var(--warning-soft);
  border-bottom: 1px solid var(--carbs-border);
  color: var(--text);
  padding: 9px 18px;
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
}

/* ==========================================================================
   App Shell Layout (Auto-Fitting Fluid Width)
   ========================================================================== */
.app-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-left: 1px solid var(--border);
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  padding: 20px 14px 16px;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 6px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.brand-logo-sm {
  width: 32px;
  height: 32px;
  border-radius: 9px;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 1.2rem;
  font-weight: 800;
  line-height: 1.15;
}

.brand-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 600;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  margin-bottom: 14px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--primary-gradient);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-meta {
  min-width: 0;
  flex: 1;
}

.user-name {
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.role-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  background: var(--primary-soft);
  color: var(--primary);
}

.role-badge.admin {
  background: var(--calories-soft);
  color: var(--calories);
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: background 0.16s ease, color 0.16s ease;
  text-align: right;
  width: 100%;
}

.nav-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
}

.nav-icon {
  font-size: 1.15rem;
  line-height: 1;
}

.nav-badge {
  margin-right: auto;
  background: var(--fat);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  min-width: 21px;
  height: 21px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sync-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: var(--radius-full);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.sync-dot.local { background: var(--text-muted); }
.sync-dot.synced { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.sync-dot.syncing { background: var(--warning); animation: pulse 1s infinite; }
.sync-dot.error { background: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.2); }
}

.main-wrapper {
  flex: 1;
  margin-right: var(--sidebar-width);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Auto-fit wide workspace for Grid/Table overview */
.main-content {
  width: 100%;
  max-width: 1380px;
  margin: 0 auto;
  padding: 20px 22px 56px;
}

.tab-view {
  display: none;
}

.tab-view.active {
  display: block;
}

.mobile-header,
.bottom-nav {
  display: none;
}

/* ==========================================================================
   Buttons & Inputs
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary-gradient);
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(15, 118, 110, 0.22);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-soft {
  background: var(--primary-soft);
  color: var(--primary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger-soft {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

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

.btn-xs {
  padding: 4px 9px;
  font-size: 0.74rem;
  border-radius: 7px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.95rem;
  transition: all 0.14s ease;
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-btn.danger:hover:not(:disabled) {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}

.icon-btn.sm {
  width: 28px;
  height: 28px;
  font-size: 0.82rem;
  border-radius: 8px;
}

input[type="text"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ==========================================================================
   Compact & Responsive Daily Dashboard Card
   ========================================================================== */
.dashboard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

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

.dashboard-heading h2 {
  margin: 0;
  font-size: 1.18rem;
  font-weight: 800;
}

.dashboard-heading p {
  margin: 1px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.dashboard-body {
  display: grid;
  grid-template-columns: 146px 1fr;
  gap: 20px;
  align-items: center;
}

.calories-ring-wrap {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto;
}

.calories-ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--surface-hover);
  stroke-width: 13;
}

.ring-segment {
  fill: none;
  stroke-width: 13;
  transition: stroke-dasharray 0.35s ease, stroke-dashoffset 0.35s ease;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.ring-kcal {
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.1;
}

.ring-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

.ring-goal {
  font-size: 0.68rem;
  color: var(--primary);
  font-weight: 700;
}

.macro-cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.macro-stat-card {
  border-radius: 14px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.macro-stat-card.protein { background: var(--protein-soft); border-color: var(--protein-border); }
.macro-stat-card.carbs { background: var(--carbs-soft); border-color: var(--carbs-border); }
.macro-stat-card.fat { background: var(--fat-soft); border-color: var(--fat-border); }

.macro-stat-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 700;
}

.macro-stat-card.protein .macro-stat-head { color: var(--protein); }
.macro-stat-card.carbs .macro-stat-head { color: var(--carbs); }
.macro-stat-card.fat .macro-stat-head { color: var(--fat); }

.macro-stat-value {
  font-size: 1.32rem;
  font-weight: 800;
  line-height: 1.15;
}

.macro-stat-value small {
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.macro-progress-track {
  height: 6px;
  background: rgba(128, 128, 128, 0.16);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.macro-progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

.macro-stat-card.protein .macro-progress-fill { background: var(--protein); }
.macro-stat-card.carbs .macro-progress-fill { background: var(--carbs); }
.macro-stat-card.fat .macro-progress-fill { background: var(--fat); }

.macro-stat-sub {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
}

.macro-split-bar {
  margin-top: 10px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--surface-hover);
  overflow: hidden;
  display: flex;
  gap: 2px;
}

.split-seg.protein { background: var(--protein); }
.split-seg.carbs { background: var(--carbs); }
.split-seg.fat { background: var(--fat); }

/* ==========================================================================
   Meals Toolbar & Multi-View Switcher
   ========================================================================== */
.meals-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 210px;
}

.search-box input {
  padding-right: 36px;
  padding-top: 8px;
  padding-bottom: 8px;
}

.search-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  pointer-events: none;
  opacity: 0.65;
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.view-switcher {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.view-btn {
  padding: 5px 10px;
  border-radius: 7px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  transition: all 0.14s ease;
}

.view-btn.active {
  background: var(--primary);
  color: #FFFFFF;
}

.undo-count {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.7rem;
  padding: 0 6px;
  border-radius: var(--radius-full);
}

/* ==========================================================================
   MEAL VIEWS: 1) Grid Board  2) Compact Matrix Table  3) Detailed List
   ========================================================================== */
.meals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 22px;
  align-items: start;
}

.meals-list {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.meal-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top: 3.5px solid var(--primary);
  border-radius: var(--radius-md);
  box-shadow: 0 6px 20px rgba(15, 36, 32, 0.065);
  overflow: visible;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
}

.meal-card:hover {
  border-color: var(--border-strong);
  border-top-color: var(--primary);
  box-shadow: 0 10px 26px rgba(15, 36, 32, 0.09);
}

.meal-card-header {
  padding: 15px 18px 13px;
  background: var(--surface-subtle);
  border-bottom: 1.5px solid var(--border);
  border-radius: calc(var(--radius-md) - 2px) calc(var(--radius-md) - 2px) 0 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stock-toggle-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

/* Clean Floating Action Menu (...) */
.action-menu-wrap {
  position: relative;
  display: inline-flex;
}

.action-menu-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  min-width: 175px;
  background: #FFFFFF;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 5px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

[data-theme="dark"] .action-menu-dropdown {
  background: #172725;
}

.menu-action-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
  text-align: right;
  transition: background 0.12s ease;
}

.menu-action-item:hover:not(:disabled) {
  background: var(--surface-hover);
}

.menu-action-item.danger {
  color: var(--danger);
}

.menu-action-item.danger:hover {
  background: var(--danger-soft);
}

.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 3px 6px;
}

/* Collapsible Drawer in Item Modal */
.collapsible-drawer {
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface-subtle);
  overflow: hidden;
}

.collapsible-drawer summary {
  padding: 11px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  list-style: none;
  user-select: none;
}

.collapsible-drawer summary::-webkit-details-marker {
  display: none;
}

.collapsible-drawer summary::before {
  content: '◂';
  font-size: 0.8rem;
  color: var(--primary);
  margin-left: 6px;
  transition: transform 0.16s ease;
}

.collapsible-drawer[open] summary::before {
  transform: rotate(-90deg);
}

.collapsible-drawer .drawer-content {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 11px;
}

.drawer-summary-pill {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--primary);
  margin-right: auto;
}

.meal-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.meal-title-group {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.meal-emoji {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.meal-name {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meal-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

.meal-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.meal-totals-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.macro-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 0.74rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.macro-pill.protein { background: var(--protein-soft); color: var(--protein); border-color: var(--protein-border); }
.macro-pill.carbs { background: var(--carbs-soft); color: var(--carbs); border-color: var(--carbs-border); }
.macro-pill.fat { background: var(--fat-soft); color: var(--fat); border-color: var(--fat-border); }
.macro-pill.calories { background: var(--calories-soft); color: var(--calories); border-color: var(--calories-border); }

.meal-items {
  display: flex;
  flex-direction: column;
}

.meal-item-row {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meal-item-row:last-child {
  border-bottom: none;
}

.meal-item-row:hover {
  background: var(--surface-subtle);
}

.item-main-line {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

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

.item-name-line {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.item-name {
  font-weight: 700;
  font-size: 0.92rem;
}

.item-portion {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--surface-hover);
  padding: 1px 7px;
  border-radius: 6px;
  font-weight: 600;
}

/* Servings Multiplier Control (x1, x2, x3) */
.servings-control {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--primary-soft);
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: var(--radius-full);
  padding: 1px 4px;
}

.servings-badge {
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--primary);
  padding: 0 4px;
  direction: ltr;
}

.servings-btn {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--surface);
  color: var(--primary);
  font-weight: 800;
  font-size: 0.78rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

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

.item-macros-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.mini-macro {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  cursor: pointer;
}

.mini-macro.protein { background: var(--protein-soft); color: var(--protein); }
.mini-macro.carbs { background: var(--carbs-soft); color: var(--carbs); }
.mini-macro.fat { background: var(--fat-soft); color: var(--fat); }
.mini-macro.calories { background: var(--calories-soft); color: var(--calories); }

.item-row-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

/* Stock Strip (Compact in Grid, Expanded in List) */
.item-stock-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--surface-subtle);
  border: 1px dashed var(--border-strong);
  font-size: 0.78rem;
}

.stock-field {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.stock-field label {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.74rem;
}

.inline-qty-input {
  width: 64px !important;
  padding: 3px 6px !important;
  font-size: 0.8rem !important;
  font-weight: 700;
  text-align: center;
  border-radius: 7px !important;
}

.qty-stepper {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.step-btn {
  width: 23px;
  height: 23px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-weight: 800;
  font-size: 0.84rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
}

.step-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.stock-unit {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
}

.to-buy-badge {
  margin-right: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 9px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 700;
}

.to-buy-badge.needed { background: var(--warning-soft); color: var(--warning); border: 1px solid var(--carbs-border); }
.to-buy-badge.stocked { background: var(--success-soft); color: var(--success); border: 1px solid var(--protein-border); }

.grid-stock-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.74rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

/* Inline Macro Editor */
.inline-macro-editor {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px 10px;
  background: var(--primary-soft);
  border-radius: 10px;
  align-items: end;
}

.inline-macro-editor label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  margin-bottom: 2px;
  color: var(--text-secondary);
}

.inline-macro-editor input {
  padding: 5px 6px;
  font-size: 0.8rem;
  font-weight: 700;
}

.inline-editor-btns {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
}

.meal-card-footer {
  padding: 10px 18px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 0 0 calc(var(--radius-md) - 2px) calc(var(--radius-md) - 2px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}

.shopping-pack-note {
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 700;
  margin-top: 3px;
}

/* Per-meal toggle icon active state */
.icon-btn.toggle-active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

/* Drag & Drop Reordering / Moving Between Meals */
.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1;
  padding: 2px 3px;
  user-select: none;
  opacity: 0.6;
  transition: opacity 0.14s ease, color 0.14s ease;
}

.drag-handle:hover {
  opacity: 1;
  color: var(--primary);
}

.meal-item-row.dragging {
  opacity: 0.42;
  background: var(--primary-soft);
}

.meal-item-row.drag-over-item {
  border-top: 2.5px solid var(--primary);
  background: var(--primary-soft);
}

.meal-card.drag-over-meal {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* Daily Eating Tracker View */
.tracker-hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tracker-stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}

.tracker-stat-pill {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  text-align: center;
}

.tracker-stat-pill strong {
  display: block;
  font-size: 1.15rem;
  font-weight: 800;
}

.tracker-stat-pill span {
  font-size: 0.74rem;
  color: var(--text-secondary);
  font-weight: 700;
}

.tracker-section-label {
  font-size: 0.96rem;
  font-weight: 800;
  color: var(--text);
  margin: 18px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tracker-meal-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: var(--radius-md);
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.tracker-meal-head {
  padding: 12px 16px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.tracker-item-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.14s ease;
}

.tracker-item-row:last-child {
  border-bottom: none;
}

.tracker-item-row:hover {
  background: var(--surface-subtle);
}

.tracker-item-row.eaten {
  opacity: 0.68;
}

.tracker-item-row.eaten .tracker-item-name {
  text-decoration: line-through;
}

.tracker-checkbox {
  width: 22px;
  height: 22px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.tracker-deduct-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--surface-hover);
  color: var(--text-secondary);
  white-space: nowrap;
}

.eaten-drawer {
  margin-top: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}

.eaten-drawer summary {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 800;
  font-size: 0.92rem;
  color: var(--success);
  background: var(--success-soft);
}

.empty-meal-hint {
  padding: 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* ==========================================================================
   Compact All-in-One Matrix Table View
   ========================================================================== */
.compact-matrix-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

.compact-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  min-width: 720px;
}

.compact-table th {
  text-align: right;
  padding: 10px 12px;
  background: var(--surface-subtle);
  border-bottom: 1.5px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 800;
  white-space: nowrap;
}

.compact-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.compact-meal-group-row td {
  background: var(--primary-soft);
  font-weight: 800;
  padding: 8px 12px;
}

.compact-table tr:last-child td {
  border-bottom: none;
}

/* ==========================================================================
   Daily Footer Card
   ========================================================================== */
.daily-footer-card {
  margin-top: 18px;
  background: var(--primary-gradient);
  color: #FFFFFF;
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.22);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.daily-footer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.daily-footer-top h3 { margin: 0; font-size: 1.06rem; font-weight: 800; }
.daily-footer-top p { margin: 2px 0 0; font-size: 0.8rem; opacity: 0.88; }

.daily-footer-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.footer-stat {
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  padding: 8px 10px;
  text-align: center;
}

.footer-stat-val { font-size: 1.15rem; font-weight: 800; line-height: 1.2; }
.footer-stat-lbl { font-size: 0.72rem; opacity: 0.9; font-weight: 600; }

.btn-white {
  background: #FFFFFF;
  color: #0F766E;
  font-weight: 800;
}

/* ==========================================================================
   Shopping List, Pantry, History & Food Library
   ========================================================================== */
.section-header-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.section-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.section-header-top h2 { margin: 0; font-size: 1.22rem; font-weight: 800; }
.section-header-top p { margin: 2px 0 0; font-size: 0.84rem; color: var(--text-muted); }

.header-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.shopping-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shopping-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.shopping-card.checked {
  opacity: 0.62;
  background: var(--surface-subtle);
}

.shopping-card.checked .shopping-item-name {
  text-decoration: line-through;
}

.shopping-checkbox {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.shopping-info {
  flex: 1;
  min-width: 200px;
}

.shopping-item-name {
  font-size: 0.96rem;
  font-weight: 800;
}

.shopping-meta {
  font-size: 0.78rem;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.shopping-source-box {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 175px;
}

.shopping-source-input {
  padding: 5px 9px !important;
  font-size: 0.8rem !important;
  border-radius: 8px !important;
}

.source-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--calories-soft);
  color: var(--calories);
  font-size: 0.72rem;
  font-weight: 700;
}

.shopping-buy-qty {
  background: var(--warning-soft);
  color: var(--warning);
  border: 1px solid var(--carbs-border);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-weight: 800;
  font-size: 0.86rem;
  white-space: nowrap;
}

.filter-pills {
  display: flex;
  gap: 7px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.filter-pill {
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.filter-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.pantry-grid,
.library-grid,
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.pantry-card,
.library-card,
.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.pantry-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.pantry-meal-tag {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-subtle);
  padding: 2px 7px;
  border-radius: 6px;
}

.pantry-bar-track {
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--surface-hover);
  overflow: hidden;
}

.pantry-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--success);
  transition: width 0.25s ease;
}

.pantry-bar-fill.low { background: var(--warning); }
.pantry-bar-fill.empty { background: var(--danger); }

.pantry-inputs-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pantry-inputs-row label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 700;
  margin-bottom: 3px;
}

.history-reason-badge {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.history-reason-badge.deleted { background: var(--danger-soft); color: var(--danger); }
.history-reason-badge.saved { background: var(--primary-soft); color: var(--primary); }
.history-reason-badge.created { background: var(--calories-soft); color: var(--calories); }

.history-items-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 190px;
  overflow-y: auto;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
}

.history-item-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 8px;
  background: var(--surface-subtle);
  font-size: 0.78rem;
}

/* ==========================================================================
   Admin Dashboard & Security Audit
   ========================================================================== */
.admin-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 700;
}

.kpi-val {
  font-size: 1.55rem;
  font-weight: 800;
  margin-top: 2px;
}

.kpi-sub {
  font-size: 0.74rem;
  color: var(--primary);
  font-weight: 700;
}

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
  min-width: 680px;
}

.admin-table th {
  text-align: right;
  padding: 10px 12px;
  background: var(--surface-subtle);
  border-bottom: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--text-secondary);
}

.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.status-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 800;
}

.status-chip.active { background: var(--success-soft); color: var(--success); }
.status-chip.suspended { background: var(--danger-soft); color: var(--danger); }
.status-chip.locked { background: var(--warning-soft); color: var(--warning); }

.severity-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 800;
}

.severity-badge.info { background: var(--primary-soft); color: var(--primary); }
.severity-badge.warning { background: var(--warning-soft); color: var(--warning); }
.severity-badge.critical { background: var(--danger-soft); color: var(--danger); }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
}

.toggle-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ==========================================================================
   Settings & Cloud Sync View
   ========================================================================== */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--shadow-sm);
}

.settings-card h3 {
  margin: 0 0 4px;
  font-size: 1.06rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-card > p {
  margin: 0 0 14px;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.status-banner {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  font-weight: 700;
  margin-bottom: 14px;
}

.status-banner.local { background: var(--surface-subtle); border: 1px solid var(--border); color: var(--text-secondary); }
.status-banner.connected { background: var(--success-soft); border: 1px solid var(--protein-border); color: var(--success); }
.status-banner.error { background: var(--danger-soft); color: var(--danger); }

.code-details {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  padding: 10px 14px;
}

.code-details summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 0.84rem;
  color: var(--primary);
}

.code-pre {
  margin: 10px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #0F172A;
  color: #E2E8F0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.74rem;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
  max-height: 260px;
}

/* ==========================================================================
   Empty States
   ========================================================================== */
.empty-state {
  background: var(--surface);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 36px 20px;
  text-align: center;
}

.empty-state-icon { font-size: 2.6rem; margin-bottom: 8px; }
.empty-state h3 { margin: 0 0 6px; font-size: 1.1rem; font-weight: 800; }
.empty-state p { margin: 0 0 16px; color: var(--text-muted); font-size: 0.88rem; }

/* ==========================================================================
   Modals (Solid Opaque Surface, Zero Bleed-Through)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 22, 20, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 1000;
}

.modal-card {
  position: relative;
  z-index: 1001;
  width: 100%;
  max-width: 480px;
  max-height: 92vh;
  overflow-y: auto;
  background: #FFFFFF;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  isolation: isolate;
}

[data-theme="dark"] .modal-card {
  background: #131F1E;
}

.modal-card.modal-lg {
  max-width: 620px;
}

.modal-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.modal-header h2 { margin: 0; font-size: 1.1rem; font-weight: 800; }
.modal-subtitle { margin: 2px 0 0; font-size: 0.8rem; color: var(--primary); font-weight: 700; }

.modal-body {
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.library-quick-pick {
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--primary-soft);
  border: 1px solid rgba(15, 118, 110, 0.25);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.library-quick-pick label {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--primary);
}

.confirm-hint-box {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 700;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.form-row {
  display: grid;
  gap: 10px;
}

.form-row.two-col { grid-template-columns: 1fr 1fr; }
.form-row.three-col { grid-template-columns: 1.2fr 1fr 0.8fr; }

.form-section-title {
  font-size: 0.84rem;
  font-weight: 800;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.macros-input-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.macro-input-box {
  padding: 9px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.macro-input-box label {
  display: block;
  font-size: 0.76rem;
  font-weight: 800;
  margin-bottom: 5px;
}

.macro-input-box.protein { background: var(--protein-soft); border-color: var(--protein-border); }
.macro-input-box.protein label { color: var(--protein); }
.macro-input-box.carbs { background: var(--carbs-soft); border-color: var(--carbs-border); }
.macro-input-box.carbs label { color: var(--carbs); }
.macro-input-box.fat { background: var(--fat-soft); border-color: var(--fat-border); }
.macro-input-box.fat label { color: var(--fat); }

.live-calories-bar,
.live-shopping-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 0.84rem;
  flex-wrap: wrap;
  gap: 6px;
}

.live-calories-bar strong { color: var(--calories); font-size: 0.96rem; }
.live-shopping-preview strong.needed { color: var(--warning); }
.live-shopping-preview strong.stocked { color: var(--success); }

.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.chip {
  padding: 5px 10px;
  border-radius: var(--radius-full);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.chip:hover {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.emoji-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 1.2rem;
  background: var(--surface-subtle);
  border: 1.5px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.emoji-btn.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* ==========================================================================
   Toasts
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 22px;
  left: 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
  max-width: calc(100vw - 28px);
}

.toast {
  background: var(--text);
  color: var(--surface);
  padding: 11px 15px;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast-undo-btn {
  background: var(--primary);
  color: #fff;
  padding: 4px 10px;
  border-radius: 7px;
  font-size: 0.76rem;
  font-weight: 800;
}

/* ==========================================================================
   Auto-Fit Responsive Breakpoints (Tablet & Mobile)
   ========================================================================== */
@media (max-width: 960px) {
  .sidebar { display: none; }
  .main-wrapper { margin-right: 0; }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }

  .mobile-brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
  .mobile-title { margin: 0; font-size: 1rem; font-weight: 800; line-height: 1.2; }
  .mobile-user-sub { display: block; font-size: 0.7rem; color: var(--text-muted); font-weight: 600; }
  .mobile-actions { display: flex; align-items: center; gap: 6px; }

  .sync-mini-btn {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--surface-subtle);
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .main-content {
    padding: 14px 12px calc(var(--bottom-nav-height) + 26px);
  }

  .bottom-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.06);
    z-index: 60;
  }

  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 700;
    position: relative;
  }

  .bottom-nav-item.active { color: var(--primary); }
  .bottom-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    width: 32px;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: var(--primary);
  }

  .bottom-nav-icon-wrap { position: relative; display: inline-flex; }
  .bottom-nav-icon { font-size: 1.22rem; line-height: 1; }

  .bottom-badge {
    position: absolute;
    top: -5px;
    left: -11px;
    background: var(--fat);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 800;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: var(--radius-full);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .toast-container {
    bottom: calc(var(--bottom-nav-height) + 14px);
    left: 12px;
    right: 12px;
  }
}

@media (max-width: 680px) {
  .dashboard-body { grid-template-columns: 1fr; gap: 12px; }
  .macro-cards-grid { gap: 7px; }
  .macro-stat-card { padding: 9px; }
  .macro-stat-value { font-size: 1.08rem; }
  .daily-footer-grid { grid-template-columns: repeat(2, 1fr); }
  .meals-grid { grid-template-columns: 1fr; }
  .form-row.two-col, .form-row.three-col { grid-template-columns: 1fr; }
  .inline-macro-editor { grid-template-columns: repeat(2, 1fr); }
}
