/* ============================================
   Meal Planner Mobile Optimizations
   Compact layout for better space utilization
   ============================================ */

/* ==========================================
   Reduce Horizontal Padding on Mobile
   ========================================== */
@media (max-width: 768px) {
  /* Main meal container */
  .meal-card,
  .meal-container,
  .meal-section {
    padding: 12px !important;
    margin: 8px 0 !important;
  }

  /* Food item rows - minimize padding */
  .meal-food-item,
  .food-item-row,
  .selected-food-item {
    padding: 8px 8px !important;
    margin: 4px 0 !important;
    gap: 8px !important;
  }

  /* Food name should take more space */
  .food-name,
  .food-item-name {
    flex: 1 1 auto !important;
    min-width: 0;
    padding-right: 8px !important;
    font-size: 14px !important;
    line-height: 1.3 !important;
  }

  /* Serving controls - more compact */
  .serving-controls,
  .serving-inputs {
    display: flex !important;
    gap: 4px !important;
    flex-shrink: 0 !important;
    align-items: center !important;
  }

  /* Input fields - narrower */
  .serving-input,
  .quantity-input,
  input[type="number"] {
    width: 50px !important;
    padding: 4px 6px !important;
    font-size: 14px !important;
    text-align: center !important;
  }

  /* Unit selector - compact */
  .unit-selector,
  .serving-unit,
  select.form-select-sm {
    width: auto !important;
    min-width: 60px !important;
    max-width: 100px !important;
    padding: 4px 6px !important;
    font-size: 12px !important;
  }

  /* Grams input - narrower */
  .grams-input,
  input[placeholder*="grams"] {
    width: 60px !important;
    padding: 4px 6px !important;
    font-size: 14px !important;
  }

  /* Remove button - smaller */
  .remove-btn,
  .btn-remove,
  .btn-outline-danger {
    padding: 4px 8px !important;
    font-size: 12px !important;
    min-width: unset !important;
  }
}

/* ==========================================
   Macro Display - Single Line Compact
   ========================================== */
@media (max-width: 768px) {
  /* Macro info on same line as calories */
  .food-macros,
  .macro-info {
    display: inline-flex !important;
    gap: 6px !important;
    font-size: 11px !important;
    color: #6b7280 !important;
    margin-left: 8px !important;
    margin-top: 0 !important;
  }

  /* Calories and macros in one line */
  .food-stats {
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
    font-size: 13px !important;
    margin-top: 4px !important;
  }

  .calories-display {
    font-weight: 600 !important;
    color: #374151 !important;
  }
}

/* ==========================================
   Optimize Meal Header
   ========================================== */
@media (max-width: 768px) {
  /* Meal header row */
  .meal-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 12px !important;
    margin-bottom: 8px !important;
  }

  /* Meal title and calories side by side */
  .meal-title-section {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    flex: 1 !important;
  }

  .meal-title {
    font-size: 16px !important;
    font-weight: 600 !important;
    margin: 0 !important;
  }

  .meal-calories {
    font-size: 14px !important;
    color: #6b7280 !important;
  }

  /* Edit button - compact */
  .meal-edit-btn,
  .btn-edit {
    padding: 6px 12px !important;
    font-size: 14px !important;
  }
}

/* ==========================================
   Two-Column Layout for Serving Controls
   ========================================== */
@media (max-width: 480px) {
  /* Stack serving controls vertically on very small screens */
  .food-item-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .food-item-top {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
  }

  .food-item-bottom {
    display: flex !important;
    gap: 8px !important;
    align-items: center !important;
  }

  /* Food name and calories on top */
  .food-info {
    flex: 1 !important;
  }

  /* Serving controls below */
  .serving-controls {
    width: 100% !important;
    display: grid !important;
    grid-template-columns: 60px auto 60px auto !important;
    gap: 4px !important;
    align-items: center !important;
  }
}

/* ==========================================
   Custom Food Button - Full Width Mobile
   ========================================== */
@media (max-width: 768px) {
  .create-custom-food-btn,
  .custom-food-chip.create-new {
    width: 100% !important;
    padding: 12px !important;
    margin: 8px 0 !important;
    font-size: 14px !important;
  }
}

/* ==========================================
   Empty Meal State - Compact
   ========================================== */
@media (max-width: 768px) {
  .meal-empty-state {
    padding: 16px !important;
    text-align: center !important;
  }

  .empty-text {
    font-size: 14px !important;
    color: #9ca3af !important;
    font-style: italic !important;
    margin: 0 !important;
  }

  .add-food-btn {
    margin-top: 8px !important;
  }
}

/* ==========================================
   Remove Unnecessary Borders/Dividers
   ========================================== */
@media (max-width: 768px) {
  /* Remove divider lines between foods */
  .food-item-divider,
  .meal-food-item + .meal-food-item {
    border-top: none !important;
  }

  /* Subtle separation with spacing only */
  .meal-food-item + .meal-food-item {
    margin-top: 8px !important;
  }
}

/* ==========================================
   Landscape Mode - Side by Side Layout
   ========================================== */
@media (max-width: 812px) and (orientation: landscape) {
  /* Food items in two columns in landscape */
  .meal-foods-list {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  .meal-food-item {
    border: 1px solid #e5e7eb !important;
    border-radius: 6px !important;
    padding: 8px !important;
  }
}

/* ==========================================
   Touch-Optimized Interactions
   ========================================== */
@media (max-width: 768px) {
  /* Larger touch targets for inputs */
  input[type="number"],
  select {
    min-height: 36px !important;
    touch-action: manipulation;
  }

  /* Highlight active food item */
  .meal-food-item:active {
    background-color: #f9fafb !important;
  }

  /* Remove hover effects on mobile */
  .meal-food-item:hover {
    background-color: transparent !important;
  }
}

/* ==========================================
   Alternative Compact Food Display
   ========================================== */
@media (max-width: 768px) {
  /* Option 1: Name and controls on same line */
  .compact-food-row {
    display: grid !important;
    grid-template-columns: 1fr auto auto auto !important;
    gap: 4px !important;
    align-items: center !important;
    padding: 6px 8px !important;
  }

  .compact-food-name {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 13px !important;
  }

  .compact-quantity {
    width: 45px !important;
  }

  .compact-unit {
    width: 55px !important;
  }

  .compact-grams {
    width: 50px !important;
  }

  /* Option 2: Inline editing mode */
  .inline-food-edit {
    display: flex !important;
    gap: 4px !important;
    align-items: center !important;
    padding: 4px 8px !important;
  }

  .inline-food-edit input,
  .inline-food-edit select {
    border: none !important;
    background: #f9fafb !important;
    padding: 2px 4px !important;
    border-radius: 4px !important;
  }
}

/* ==========================================
   Reduce Visual Clutter
   ========================================== */
@media (max-width: 768px) {
  /* Smaller text for labels */
  .unit-label,
  .grams-label,
  label {
    display: none !important; /* Hide labels on mobile */
  }

  /* Use placeholders instead */
  input::placeholder {
    font-size: 12px !important;
    color: #9ca3af !important;
  }

  /* Simpler borders */
  .meal-card {
    border: 1px solid #e5e7eb !important;
    box-shadow: none !important;
  }

  /* Remove rounded corners for full-width items */
  .meal-card {
    border-radius: 8px !important;
  }
}

/* ==========================================
   Optimize for iOS Safari
   ========================================== */
@supports (-webkit-touch-callout: none) {
  /* Prevent iOS zoom on input focus */
  input[type="number"],
  select {
    font-size: 16px !important;
  }

  /* iOS-specific padding adjustments */
  .meal-food-item {
    -webkit-tap-highlight-color: transparent;
  }
}