/* Base styles - Mobile First */
html {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  max-width: 100%;
  margin: 0;
  padding: 0;
  background: #e5e7eb;
  box-sizing: border-box;
  -webkit-text-size-adjust: 100%; /* Prevent text scaling on iOS */
  min-height: 0;
}

* { box-sizing: border-box; }

h1 { text-align: center; margin: 0; font-size: 22px; color: white; }
h2 { margin: 0 0 15px 0; font-size: 14px; letter-spacing: 0.5px; color: #666; font-weight: 600; }
h3 { margin: 0 0 12px 0; font-size: 16px; color: #333; }

label {
  display: block;
  margin: 16px 0 6px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #666;
}
label:first-of-type { margin-top: 0; }

select, input {
  width: 100%;
  padding: 14px 12px;
  margin: 0;
  font-size: 16px !important; /* Prevent iOS auto-zoom on focus */
  border-radius: 8px;
  border: 2px solid #ddd;
  box-sizing: border-box;
  background: white;
  background-color: white; /* iOS needs background-color not just background */
  color: #1f2937;
  transition: border-color 0.2s;
  -webkit-appearance: none !important;
  appearance: none !important;
  /* iOS Safari specific fixes */
  -webkit-border-radius: 8px;
  -webkit-box-sizing: border-box;
  opacity: 1; /* iOS Safari can reduce opacity */
}

select:focus, input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Restore native checkbox styling */
input[type="checkbox"] {
  width: auto;
  height: auto;
  padding: 0;
  -webkit-appearance: checkbox !important;
  appearance: checkbox !important;
  border: none;
  cursor: pointer;
}

button {
  width: 100%;
  padding: 14px 18px;
  margin: 0;
  font-size: 16px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
  touch-action: manipulation; /* Optimize for touch */
}

button:active {
  transform: scale(0.98);
}

button.main { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; }
button.secondary { background: #f3f4f6; color: #4b5563; border: 1px solid #e5e7eb; }
button.secondary:active { background: #e5e7eb; }
button.add { background: #10b981; color: white; }
button.preset { background: #f59e0b; color: white; }

/* Container and Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px;
}

/* Meals */
.meal {
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin: 0 0 12px 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  border: 1px solid #e5e7eb;
}

.postwo {
  background: linear-gradient(135deg, #e0f2fe 0%, #dbeafe 100%);
  border: 2px solid #3b82f6;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2), 0 1px 3px rgba(0,0,0,0.1);
}

/* Compact meal headers on mobile */
.meal h3 {
  font-size: 15px;
  margin-bottom: 10px;
}

.target-bar {
  height: 24px;
  background: #e0e0e0;
  border-radius: 12px;
  margin: 10px 0;
  position: relative;
}

.target-text {
  position: absolute;
  width: 100%;
  text-align: center;
  top: 50%;
  transform: translateY(-50%);
  font-weight: bold;
  font-size: 11px;
  padding: 0 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logged-text {
  text-align: center;
  font-size: 15px;
  font-weight: bold;
  margin: 10px 0;
}

.macro-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0;
}

.macro-bar {
  height: 24px;
  background: #f3f4f6;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
}

.macro-fill { height: 100%; transition: width 0.5s ease; }
.macro-fill.green { background: linear-gradient(90deg, #10b981 0%, #059669 100%); }
.macro-fill.yellow { background: linear-gradient(90deg, #fbbf24 0%, #f59e0b 100%); }
.macro-fill.red { background: linear-gradient(90deg, #ef4444 0%, #dc2626 100%); }

.macro-label {
  position: absolute;
  width: 100%;
  text-align: center;
  top: 50%;
  transform: translateY(-50%);
  font-weight: 600;
  color: #1f2937;
  font-size: 12px;
}

.carb-breakdown {
  text-align: center;
  font-size: 11px;
  margin-top: 6px;
  color: #6b7280;
  font-weight: 500;
}

/* Food rows - mobile optimized */
.food-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  align-items: stretch;
}

.food-row select {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  padding: 12px 10px;
}

.food-row input {
  flex: 0 0 80px;
  font-size: 15px;
  padding: 12px 10px;
  text-align: center;
}

.food-row button {
  flex: 0 0 44px;
  background: #ef4444;
  color: white;
  font-size: 18px;
  font-weight: 700;
  border-radius: 8px;
  padding: 0;
  transition: background 0.2s;
  width: 44px;
}

.food-row button:active {
  background: #dc2626;
  transform: scale(0.95);
}

/* Quick Pick Bar - Single horizontal row of suggestion chips */
.quick-pick-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  margin-bottom: 6px;
  border-bottom: 1px solid #f1f5f9;
  overflow: hidden;
}

/* Hide bar when no chips */
.quick-pick-bar:has(.quick-pick-chips:empty) {
  display: none;
}

.quick-pick-label {
  font-size: 9px;
  color: #64748b;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  flex-shrink: 0;
}

.quick-pick-chips {
  display: flex;
  gap: 5px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.quick-pick-chips:empty {
  display: none;
}

.quick-pick-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border: 1px solid #7dd3fc;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 500;
  color: #0369a1;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  flex-shrink: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quick-pick-chip:hover {
  background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%);
  border-color: #38bdf8;
}

.quick-pick-chip:active {
  transform: scale(0.95);
  background: #bae6fd;
}

/* Daily totals */
.daily-totals {
  font-size: 18px;
  text-align: center;
  padding: 16px;
  background: linear-gradient(135deg, #1f2937 0%, #374151 100%);
  color: white;
  border-radius: 12px;
  margin: 0;
  line-height: 1.5;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.feedback {
  font-size: 14px;
  text-align: center;
  padding: 12px 16px;
  border-radius: 8px;
  margin: 0;
  font-weight: 600;
  line-height: 1.4;
}

.feedback.green { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.feedback.yellow { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

#review {
  background: white;
  padding: 0;
  border-radius: 12px;
  margin: 0;
  font-size: 14px;
  text-align: center;
  box-shadow: none;
}

#review:empty {
  display: none;
}

hr { border: none; border-top: 1px solid #e5e7eb; margin: 20px 0; }

/* Modal Styles - Mobile Optimized */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-content {
  background: white;
  margin: 20px auto;
  padding: 20px;
  width: calc(100% - 24px);
  max-width: 500px;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.3);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.modal-content h2 {
  margin-top: 0;
  color: #1f2937;
  font-size: 20px;
}

/* Desktop styles */
@media (min-width: 768px) {
  h1 { font-size: 28px; }
  h3 { font-size: 18px; }

  .container { padding: 20px; }

  .meal {
    padding: 20px;
    margin: 0 0 20px 0;
  }

  .meal h3 { font-size: 18px; }

  .target-bar { height: 30px; margin: 15px 0; }
  .target-text { font-size: 16px; }

  .logged-text { font-size: 22px; margin: 15px 0; }

  .macro-bars { gap: 12px; margin: 15px 0; }
  .macro-bar { height: 28px; }
  .macro-label { font-size: 14px; }

  .carb-breakdown { font-size: 13px; margin-top: 8px; }

  .food-row { gap: 8px; margin-bottom: 10px; }
  .food-row select { font-size: 16px; padding: 12px; }
  .food-row input { flex: 0 0 100px; font-size: 16px; padding: 12px; }
  .food-row button { flex: 0 0 50px; width: 50px; }

  .daily-totals { font-size: 26px; padding: 25px; line-height: 1.6; }

  .feedback { font-size: 17px; padding: 14px 20px; }

  #review { padding: 20px; font-size: 16px; }

  hr { margin: 30px 0; }

  .modal-content {
    margin: 5% auto;
    padding: 30px;
    width: 90%;
  }

  .modal-content h2 { font-size: 24px; }

  label { margin: 20px 0 8px; }

  button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  }

  button:active { transform: scale(0.98); }

  button.secondary:hover { background: #e5e7eb; }

  .food-row button:hover {
    background: #dc2626;
    transform: translateY(-1px);
  }
}

/* ===================================
   Collapsible Meal Cards - Ultra Compact
   =================================== */

.meal-card {
  background: white;
  border-radius: 10px;
  margin-bottom: 8px;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15), 0 1px 3px rgba(0,0,0,0.1);
  border: 2px solid #667eea;
  overflow: hidden;
  transition: all 0.2s ease;
}

/* Meal Header - clickable area for expand/collapse */
.meal-header-hybrid {
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.meal-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  gap: 8px;
  min-height: 44px;
  transition: background 0.15s ease;
}

.meal-header-top:active {
  background: #f1f5f9;
}

/* Hover effect on desktop */
@media (hover: hover) {
  .meal-header-top:hover {
    background: #f8fafc;
  }
}

/* Expanded macro cards - also clickable to collapse */
.meal-macro-cards-expanded {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 0 14px 12px 14px;
  cursor: pointer;
}

.meal-card:last-child {
  margin-bottom: 0;
}

.meal-card.expanded {
  box-shadow: 0 4px 16px rgba(102, 126, 234, 0.25), 0 2px 8px rgba(0,0,0,0.12);
  margin-bottom: 12px;
  border-width: 3px;
}

.meal-card.expanded:last-child {
  margin-bottom: 0;
}

/* Ultra-Compact Single Line Header */
.meal-header-ultra {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  transition: all 0.3s ease;
  gap: 8px;
  min-height: 44px;
}

.meal-header-ultra:active {
  background: #f9fafb;
}

/* Meal Complete State - All macros on target */
.meal-header-ultra.meal-complete {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%) !important;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.4),
              0 4px 16px rgba(16, 185, 129, 0.25);
  animation: mealComplete 0.5s ease-out;
}

@keyframes mealComplete {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
  50% {
    transform: scale(1.02);
    box-shadow: 0 0 0 8px rgba(16, 185, 129, 0.5);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.4),
                0 4px 16px rgba(16, 185, 129, 0.25);
  }
}

.meal-header-ultra.meal-complete .meal-number {
  color: #065f46 !important;
  font-weight: 800;
}

.meal-header-ultra.meal-complete .meal-subtitle {
  color: #047857 !important;
}

.meal-header-ultra.meal-complete .macro-label-mini {
  color: #047857 !important;
}

.meal-header-ultra.meal-complete .macro-nums {
  color: #065f46 !important;
  font-weight: 700;
}

.meal-header-ultra.meal-complete .status-dot.hit {
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.4);
  animation: pulse 2s ease-in-out 3;
}

/* Suppress pulse animation during initial page load */
body.no-animate .meal-header-ultra.meal-complete .status-dot.hit {
  animation: none;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.4);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(16, 185, 129, 0.6);
  }
}

/* Meal Title with Status Dot */
.meal-title-ultra {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.meal-title-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meal-number {
  font-size: 15px;
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
  line-height: 1;
}

.meal-subtitle {
  font-size: 11px;
  font-weight: 700;
  color: #3b82f6;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1;
  margin-top: 2px;
}

/* Status Dot */
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.2s;
}

.status-dot.not-logged {
  background: #d1d5db;
}

.status-dot.partial {
  background: #f59e0b;
}

.status-dot.hit {
  background: #10b981;
}

/* Inline Macros with Numbers and Bars */
.meal-macros-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.macro-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.macro-item.calories-item {
  margin-left: auto;
}

.calories-value {
  font-size: 15px;
  font-weight: 700;
  color: #374151;
}

.macro-label-mini {
  font-size: 16px;
  font-weight: 800;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.macro-nums {
  font-size: 16px;
  font-weight: 700;
  color: #111827;
  white-space: nowrap;
}

.macro-nums .target {
  color: #6b7280;
  font-weight: 600;
}

/* Mini Progress Bars */
.mini-bar {
  width: 48px;
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.mini-bar-fill {
  height: 100%;
  transition: width 0.3s ease;
  border-radius: 2.5px;
}

.mini-bar-fill.protein.green {
  background: #e74c3c;
}

.mini-bar-fill.protein.yellow {
  background: #f39c12;
}

.mini-bar-fill.protein.red {
  background: #95a5a6;
}

.mini-bar-fill.fat.green {
  background: #f39c12;
}

.mini-bar-fill.fat.yellow {
  background: #f1c40f;
}

.mini-bar-fill.fat.red {
  background: #95a5a6;
}

.mini-bar-fill.carbs.green {
  background: #3498db;
}

.mini-bar-fill.carbs.yellow {
  background: #5dade2;
}

.mini-bar-fill.carbs.red {
  background: #95a5a6;
}

/* Expand Icon */
.expand-icon-mini {
  font-size: 10px;
  color: #9ca3af;
  transition: transform 0.2s;
  flex-shrink: 0;
  margin-left: 4px;
}

/* Meal Content (Expanded View) */
.meal-content {
  padding: 0 16px 16px 16px;
  animation: slideDown 0.2s ease-out;
}

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

/* Compact Macro Cards - Now inline */
.meal-macro-cards {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.meal-macro-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 6px;
  border-left: 3px solid;
  background: linear-gradient(135deg, #f8f9fa 0%, #f1f3f5 100%);
  transition: all 0.3s ease;
  flex: 0 0 auto;
}

.meal-macro-card.protein-card {
  border-left-color: #e74c3c;
}

.meal-macro-card.fat-card {
  border-left-color: #f39c12;
}

.meal-macro-card.carbs-card {
  border-left-color: #3498db;
}

.meal-macro-card.calories-card {
  border-left-color: #6b7280;
}

/* Hit state - green glow when on target */
.meal-macro-card.hit {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
  border-left-color: #10b981 !important;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2),
              0 4px 12px rgba(16, 185, 129, 0.15);
  animation: macroHit 0.4s ease-out;
}

@keyframes macroHit {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
  50% {
    transform: scale(1.03);
    box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.3);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2),
                0 4px 12px rgba(16, 185, 129, 0.15);
  }
}

.meal-macro-card.hit .macro-card-actual {
  color: #065f46;
  font-weight: 800;
}

.macro-card-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #6b7280;
  margin: 0;
}

.macro-card-values {
  display: flex;
  align-items: baseline;
  gap: 2px;
  margin: 0;
}

.macro-card-actual {
  font-size: 15px;
  font-weight: 700;
  color: #1f2937;
}

.macro-card-slash {
  font-size: 13px;
  color: #9ca3af;
}

.macro-card-target {
  font-size: 13px;
  font-weight: 600;
  color: #6b7280;
}

.target-summary,
.logged-summary {
  background: #f9fafb;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.target-label,
.logged-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6b7280;
  margin-bottom: 8px;
}

.target-macros,
.logged-macros {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.target-macro,
.logged-macro {
  font-size: 13px;
  font-weight: 600;
}

.target-macro {
  color: #667eea;
}

.logged-macro.protein {
  color: #e74c3c;
}

.logged-macro.fat {
  color: #f39c12;
}

.logged-macro.carbs {
  color: #3498db;
}

.logged-macro.calories {
  color: #1f2937;
}

/* Progress Bars */
.macro-progress-bars {
  margin: 16px 0;
}

.progress-bar-item {
  margin-bottom: 12px;
}

.progress-bar-item:last-child {
  margin-bottom: 0;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.progress-percentage {
  color: #667eea;
}

.progress-bar {
  height: 20px;
  background: #f3f4f6;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  transition: width 0.3s ease, background-color 0.3s ease;
  border-radius: 10px;
}

.progress-fill.green {
  background: linear-gradient(90deg, #10b981 0%, #059669 100%);
}

.progress-fill.yellow {
  background: linear-gradient(90deg, #f59e0b 0%, #d97706 100%);
}

.progress-fill.red {
  background: linear-gradient(90deg, #ef4444 0%, #dc2626 100%);
}

.carb-breakdown {
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
  padding: 10px 12px;
  background: #f9fafb;
  border-radius: 6px;
  margin-bottom: 14px;
  text-align: center;
  border: 1px solid #e5e7eb;
}

/* Food List */
.food-list {
  margin: 16px 0;
}

/* Meal Actions */
.meal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.btn-add-food,
.btn-preset,
.btn-template {
  flex: 1;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-add-food {
  background: #667eea;
  color: white;
}

.btn-add-food:active {
  background: #5568d3;
  transform: scale(0.98);
}

.btn-optimize {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: white;
  font-weight: 700;
}

.btn-optimize:active {
  background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
  transform: scale(0.98);
}

.btn-template {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
  color: white;
  font-weight: 600;
}

.btn-template:active {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  transform: scale(0.98);
}

.btn-preset {
  background: #f3f4f6;
  color: #1f2937;
}

.btn-preset:active {
  background: #e5e7eb;
  transform: scale(0.98);
}

/* Compact meal actions - single row */
.meal-actions-compact {
  display: flex;
  gap: 6px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.btn-action {
  flex: 1 1 auto;
  min-width: fit-content;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  background: #667eea;
  color: white;
}

.btn-action.secondary {
  background: #f3f4f6;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  flex: 0 0 auto;
  padding: 10px 12px;
}

.btn-action.danger {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  flex: 0 0 auto;
  padding: 10px 12px;
}

.btn-action:active {
  transform: scale(0.98);
}

.btn-action.secondary:active {
  background: #e5e7eb;
}

.btn-action.danger:active {
  background: #fee2e2;
}

@media (min-width: 769px) {
  .btn-action:hover {
    background: #5568d3;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  }

  .btn-action.secondary:hover {
    background: #e5e7eb;
  }

  .btn-action.danger:hover {
    background: #fee2e2;
  }
}

/* Secondary meal actions */
.meal-actions-secondary {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.btn-copy,
.btn-save-template,
.btn-clear {
  flex: 1;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-copy {
  background: #f3f4f6;
  color: #1f2937;
  border: 1px solid #e5e7eb;
}

.btn-copy:active {
  background: #e5e7eb;
  transform: scale(0.98);
}

.btn-save-template {
  background: #ede9fe;
  color: #6b21a8;
  border: 1px solid #d8b4fe;
}

.btn-save-template:active {
  background: #ddd6fe;
  transform: scale(0.98);
}

.btn-clear {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.btn-clear:active {
  background: #fee2e2;
  transform: scale(0.98);
}

/* Copy meal modal */
#copyMealModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.btn-copy-target {
  width: 100%;
  padding: 14px 18px;
  margin: 0;
  font-size: 16px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  background: #667eea;
  color: white;
}

.btn-copy-target:active {
  background: #5568d3;
  transform: scale(0.98);
}

/* Template modals */
#templateModal,
#saveTemplateModal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

/* Template save success notification */
#templateSaveSuccess {
  animation: slideInDown 0.3s ease-out;
}

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

.template-item-wrapper {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  align-items: stretch;
}

.template-item-wrapper:last-child {
  margin-bottom: 0;
}

.btn-template-item {
  flex: 1;
  padding: 14px 18px;
  margin: 0;
  font-size: 16px;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  background: white;
  color: #1f2937;
  border: 2px solid #e5e7eb;
  text-align: left;
}

.btn-template-item:active {
  background: #f9fafb;
  border-color: #667eea;
  transform: scale(0.98);
}

.btn-delete-template {
  width: 44px;
  padding: 0;
  margin: 0;
  font-size: 18px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  background: #fef2f2;
  color: #dc2626;
  border: 2px solid #fecaca;
  flex-shrink: 0;
}

.btn-delete-template:active {
  background: #fee2e2;
  transform: scale(0.95);
}

/* Mobile Optimizations - Ultra Compact */
@media (max-width: 768px) {
  /* Touch optimization on mobile - keep compact but tappable */
  .meal-header-hybrid {
    touch-action: manipulation;
  }

  .meal-header-top {
    padding: 10px;
    min-height: 44px;
  }

  .meal-macro-cards-expanded {
    padding: 0 10px 10px 10px;
    gap: 6px;
  }

  .meal-title-ultra {
    font-size: 13px;
  }

  .mini-bar {
    width: 24px;
    height: 3px;
  }

  .macro-item {
    gap: 3px;
  }

  .macro-label-mini {
    font-size: 9px;
  }

  .macro-nums {
    font-size: 10px;
  }

  .meal-macros-inline {
    gap: 8px;
  }
}

/* Tablet and Desktop - Ultra Compact */
@media (min-width: 769px) {
  .meal-card {
    margin-bottom: 8px;
  }

  .meal-card:last-child {
    margin-bottom: 0;
  }

  .meal-card.expanded {
    margin-bottom: 16px;
  }

  .meal-card.expanded:last-child {
    margin-bottom: 0;
  }

  .meal-header-ultra {
    padding: 12px 16px;
  }

  .meal-header-ultra:hover {
    background: #f9fafb;
  }

  .meal-content {
    padding: 0 20px 20px 20px;
  }

  .meal-title-ultra {
    font-size: 15px;
  }

  .mini-bar {
    width: 40px;
    height: 4px;
  }

  .macro-nums {
    font-size: 12px;
  }

  .meal-macros-inline {
    gap: 12px;
  }

  .btn-add-food:hover {
    background: #5568d3;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  }

  .btn-optimize:hover {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
  }

  .btn-template:hover {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    box-shadow: 0 2px 8px rgba(251, 191, 36, 0.4);
  }

  .btn-preset:hover {
    background: #e5e7eb;
  }

  .btn-copy:hover {
    background: #e5e7eb;
  }

  .btn-save-template:hover {
    background: #ddd6fe;
  }

  .btn-clear:hover {
    background: #fee2e2;
  }

  .btn-copy-target:hover {
    background: #5568d3;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
  }

  .btn-template-item:hover {
    background: #f9fafb;
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.15);
  }

  .btn-delete-template:hover {
    background: #fee2e2;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.2);
  }
}

/* ============================================
   FAMILY MODE STYLES
   ============================================ */

/* Family Switcher Avatars - small badge style near main avatar */
.family-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: white;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.family-avatar:hover {
  transform: scale(1.15);
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}

.family-avatar.active {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.4);
}

/* Family Member Items in Settings */
.family-member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f9fafb;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  flex-wrap: nowrap;
  min-width: 0;
}

.family-member-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

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

.family-member-name {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
}

.family-member-email {
  font-size: 12px;
  color: #6b7280;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.family-remove-btn {
  padding: 6px 12px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #dc2626;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  white-space: nowrap;
}

.family-remove-btn:hover {
  background: #fee2e2;
  border-color: #fecaca;
}

/* Invite Items */
.invite-section-title {
  font-size: 12px;
  font-weight: 700;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.invite-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 8px;
}

.invite-item.pending {
  background: #fef3c7;
  border: 1px solid #fcd34d;
}

.invite-item.sent {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
}

.invite-info {
  flex: 1;
  font-size: 13px;
  color: #1f2937;
}

.invite-email {
  font-size: 11px;
  color: #6b7280;
  margin-top: 2px;
}

.invite-status {
  font-size: 11px;
  color: #6b7280;
  font-style: italic;
  margin-top: 2px;
}

.invite-actions {
  display: flex;
  gap: 6px;
}

.invite-accept-btn {
  padding: 6px 12px;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: white;
  cursor: pointer;
}

.invite-decline-btn {
  padding: 6px 12px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
}

.invite-cancel-btn {
  padding: 6px 12px;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #dc2626;
  cursor: pointer;
}

/* Prep Mode Styling */
body.prep-mode #mainHeader {
  border: 2px solid #f59e0b;
}

.empty-family {
  text-align: center;
  padding: 20px;
  color: #9ca3af;
  font-size: 13px;
  background: #f9fafb;
  border-radius: 8px;
}

/* ============================================
   PHASE 3 MOBILE ENHANCEMENTS
   ============================================ */

/* Better touch targets for small buttons */
.quick-action-btn {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Smooth scrolling on iOS */
.scrollable-modal {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Prevent pull-to-refresh on modals */
.modal-content {
  overscroll-behavior: contain;
}

/* Safe area padding for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
  .fixed-bottom-bar {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* Responsive card grid for quick actions */
@media (max-width: 360px) {
  /* Very small phones - stack more */
  .header-quick-actions {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* Landscape mode adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .modal-content {
    margin: 10px auto;
    max-height: 90vh;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .meal-card {
    border-width: 2px;
  }

  button {
    border: 2px solid currentColor;
  }
}

/* Close Day Suggestions - v2.3 Polish */
#closeDaySuggestionsContainer {
  animation: slideUpFade 0.3s ease-out;
}

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

/* Suggestion items - staggered animation */
#closeDaySuggestions > div > div {
  animation: suggestionSlide 0.3s ease-out;
  animation-fill-mode: both;
}

#closeDaySuggestions > div > div:nth-child(1) { animation-delay: 0s; }
#closeDaySuggestions > div > div:nth-child(2) { animation-delay: 0.1s; }
#closeDaySuggestions > div > div:nth-child(3) { animation-delay: 0.2s; }

@keyframes suggestionSlide {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Streak badge pulse animation */
#userStreak {
  transition: all 0.3s ease;
}

#userStreak:hover {
  transform: scale(1.05);
}

/* Smooth progress bar transitions for v2.3 */
.mini-bar-fill,
.progress-fill {
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Macro card hover effects */
.macro-card-hybrid {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.macro-card-hybrid:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Hit indicator glow effect */
.macro-card-hybrid.hit {
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3), 0 2px 8px rgba(34, 197, 94, 0.2);
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* Dark mode support (future) */
@media (prefers-color-scheme: dark) {
  /* Placeholder for dark mode styles */
}

/* ============================================
   INLINE FOOD SUGGESTIONS - v2.4
   ============================================ */

/* Food search input wrapper */
.food-input-wrapper {
  position: relative;
  width: 100%;
}

.food-search-input {
  width: 100%;
  padding: 10px 12px !important;
  border: 2px solid #e5e7eb !important;
  border-radius: 8px !important;
  font-size: 14px !important;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.food-search-input:focus {
  outline: none;
  border-color: #667eea !important;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.food-search-input::placeholder {
  color: #9ca3af;
}

/* Inline suggestions dropdown - constrained to not overflow meal card */
.inline-suggestions {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  max-height: 120px;
  overflow-y: auto;
  z-index: 100;
  -webkit-overflow-scrolling: touch;
}

/* Never show when empty */
.inline-suggestions:empty {
  display: none !important;
}

/* Suggestion item */
.suggestion-item {
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.1s;
}

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

.suggestion-item:hover,
.suggestion-item.highlighted {
  background: #f0f9ff !important;
}

.suggestion-item .food-name {
  font-size: 13px;
  font-weight: 500;
  color: #1f2937;
}

.suggestion-item .food-meta {
  font-size: 11px;
  color: #64748b;
  white-space: nowrap;
}

/* Suggestion header */
.suggestion-header {
  padding: 6px 12px;
  font-size: 11px;
  color: #64748b;
  font-weight: 600;
  text-transform: uppercase;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  letter-spacing: 0.5px;
}

/* Food row - updated for slimmer delete button */
.food-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  align-items: stretch;
}

.food-quantity-input {
  flex: 0 0 70px !important;
  width: 70px !important;
  text-align: center;
  font-size: 15px !important;
  padding: 10px 6px !important;
}

.food-delete-btn {
  flex: 0 0 36px !important;
  width: 36px !important;
  min-width: 36px !important;
  padding: 0 !important;
  font-size: 16px !important;
  font-weight: 600;
  border-radius: 6px !important;
  transition: all 0.15s;
}

.food-delete-btn:hover {
  background: #fecaca !important;
}

.food-delete-btn:active {
  transform: scale(0.95);
}

/* Mobile optimizations for food input */
@media (max-width: 768px) {
  .food-search-input {
    font-size: 16px !important; /* Prevent iOS zoom */
    padding: 12px !important;
  }

  .food-quantity-input {
    flex: 0 0 65px !important;
    width: 65px !important;
    font-size: 16px !important;
    padding: 12px 4px !important;
  }

  .food-delete-btn {
    flex: 0 0 40px !important;
    width: 40px !important;
    min-width: 40px !important;
  }

  .inline-suggestions {
    max-height: 120px;
  }

  .suggestion-item {
    padding: 10px 12px;
  }
}

/* Keyboard navigation highlight */
.suggestion-item.keyboard-focus {
  background: #dbeafe !important;
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}
