/* ===================================================================
   Calorie Counter PWA — Mobile-First Stylesheet
   =================================================================== */

/* ───────── 1. Reset & Normalize ───────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background-color: var(--color-background);
  overflow: hidden;
  width: 100%;
  height: 100%;
  position: fixed;
  overscroll-behavior: none;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  -webkit-appearance: none;
  appearance: none;
}

input, select, textarea {
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}

a {
  color: inherit;
  text-decoration: none;
}

ul, ol {
  list-style: none;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.2;
}

/* ───────── 2. CSS Custom Properties ───────── */
:root {
  /* Primary palette */
  --color-primary: #4CAF50;
  --color-primary-dark: #388E3C;
  --color-primary-light: #C8E6C9;
  --color-primary-alpha: rgba(76, 175, 80, 0.15);

  /* Neutral palette */
  --color-background: #F5F5F5;
  --color-surface: #FFFFFF;
  --color-text: #333333;
  --color-text-secondary: #6B7280;
  --color-text-tertiary: #9CA3AF;
  --color-border: #E5E7EB;
  --color-divider: #F0F0F0;

  /* Semantic */
  --color-protein: #EF5350;
  --color-carbs: #FFB74D;
  --color-fat: #42A5F5;
  --color-calories: #FF5722;

  /* Tab bar */
  --tab-bar-height: 56px;
  --tab-bar-background: #FFFFFF;
  --tab-bar-border: #E0E0E0;
  --tab-icon-inactive: #9E9E9E;

  /* Header */
  --app-header-height: 52px;

  /* Cards */
  --card-border-radius: 14px;
  --card-padding: 16px;
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;

  /* Safe area insets (filled by viewport-fit=cover + env()) */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);

  /* Status bar */
  --status-bar-height: 44px;
}

/* ───────── 3. Dark Mode ───────── */
@media (prefers-color-scheme: dark) {
  :root {
    --color-background: #121212;
    --color-surface: #1E1E1E;
    --color-text: #E0E0E0;
    --color-text-secondary: #A0A0A0;
    --color-text-tertiary: #707070;
    --color-border: #333333;
    --color-divider: #2A2A2A;
    --tab-bar-background: #1E1E1E;
    --tab-bar-border: #333333;
    --tab-icon-inactive: #707070;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --color-primary-alpha: rgba(76, 175, 80, 0.25);
  }
}

/* ───────── 3b. Offline Banner ───────── */
#offline-banner {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 250;
  padding: 10px 16px;
  background-color: #FFF3CD;
  color: #856404;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  border-bottom: 1px solid #FFEBA7;
}

@media (prefers-color-scheme: dark) {
  #offline-banner {
    background-color: #3D3200;
    color: #FFD54F;
    border-bottom-color: #5C4600;
  }
}

/* ───────── 4. App Header ───────── */
.app-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-area-top) + 6px) var(--spacing-md) 8px;
  background-color: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 50;
  min-height: var(--app-header-height);
}

.app-header-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.3px;
}

/* ───────── 5. Tab Content Containers ───────── */
.tab-content {
  display: none;
  flex: 1;
  position: relative;
  flex-direction: column;
  background-color: var(--color-background);
  overflow: hidden;
}

.tab-content.active {
  display: flex;
}

/* Scrollable content area with bottom padding for tab bar */
.content-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: var(--spacing-md) var(--spacing-md)
    calc(var(--tab-bar-height) + var(--safe-area-bottom) + var(--spacing-md));
}

/* ───────── 6. Cards ───────── */
.card {
  background-color: var(--color-surface);
  border-radius: var(--card-border-radius);
  box-shadow: var(--card-shadow);
  margin-bottom: var(--spacing-md);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--card-padding) var(--card-padding) 0;
}

.card-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
}

.card-subtitle {
  font-size: 14px;
  color: var(--color-text-secondary);
  font-weight: 400;
}

.card-body {
  padding: var(--card-padding);
}

/* ───────── 7. Placeholder State ───────── */
.placeholder-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xl) var(--spacing-md);
  text-align: center;
}

.placeholder-icon {
  font-size: 48px;
  margin-bottom: var(--spacing-md);
  opacity: 0.6;
}

.placeholder-text {
  font-size: 16px;
  color: var(--color-text-secondary);
  margin-bottom: var(--spacing-md);
}

/* ───────── 8. Buttons ───────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 28px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.2;
  transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background-color: var(--color-primary);
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

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

.btn-secondary:active {
  background-color: var(--color-primary-light);
}

.btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  min-height: 36px;
}

/* Loading spinner on buttons */
.loading-spinner {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.loading-spinner::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  top: 50%;
  left: 50%;
  margin-top: -10px;
  margin-left: -10px;
}

/* Icon button (gear, close, etc.) */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--color-text-secondary);
  transition: background-color 0.2s ease, color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.btn-icon:active {
  background-color: var(--color-border);
  color: var(--color-text);
}

/* ───────── 9. Bottom Tab Bar ───────── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-bar-height) + var(--safe-area-bottom));
  padding-bottom: var(--safe-area-bottom);
  background-color: var(--tab-bar-background);
  border-top: 1px solid var(--tab-bar-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  /* iOS blur effect fallback */
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  padding: 4px 0;
  color: var(--tab-icon-inactive);
  transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: relative;
  min-width: 0;
}

.tab-item::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background-color: var(--color-primary);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.tab-item.active {
  color: var(--color-primary);
}

.tab-item.active::after {
  opacity: 1;
}

.tab-item:active {
  opacity: 0.7;
}

.tab-icon {
  font-size: 24px;
  line-height: 1.2;
  margin-bottom: 2px;
}

.tab-label {
  font-size: 10px;
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: 0.2px;
}

/* ───────── 10. Nutrition Summary (Today tab) ───────── */
.nutrition-summary {
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
  padding-bottom: var(--spacing-md);
  margin-bottom: var(--spacing-md);
  border-bottom: 1px solid var(--color-divider);
}

.macro-ring {
  flex-shrink: 0;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: conic-gradient(
    var(--color-calories) 0deg 0deg,
    var(--color-border) 0deg 360deg
  );
  display: flex;
  align-items: center;
  justify-content: center;
}

.macro-ring-segment {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background-color: var(--color-surface);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.macro-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.1;
}

.macro-label {
  font-size: 11px;
  color: var(--color-text-tertiary);
  font-weight: 500;
}

.macro-breakdown {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  flex: 1;
}

.macro-item {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.macro-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.macro-dot.protein {
  background-color: var(--color-protein);
}

.macro-dot.carbs {
  background-color: var(--color-carbs);
}

.macro-dot.fat {
  background-color: var(--color-fat);
}

.macro-grams {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  min-width: 40px;
}

.macro-name {
  font-size: 14px;
  color: var(--color-text-secondary);
}

/* ───────── 11. Meal List ───────── */


.meal-icon {
  font-size: 32px;
  flex-shrink: 0;
}

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

.meal-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meal-time {
  font-size: 13px;
  color: var(--color-text-tertiary);
}

.meal-calories {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-calories);
  flex-shrink: 0;
}

/* ───────── 12. Goals Cards ───────── */
.goal-card {
  padding: var(--spacing-md) 0;
  border-bottom: 1px solid var(--color-divider);
}

.goal-card:last-child {
  border-bottom: none;
}

.goal-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
}

.goal-icon {
  font-size: 20px;
}

.goal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}

.goal-value {
  display: flex;
  align-items: baseline;
  gap: var(--spacing-xs);
  margin-bottom: var(--spacing-sm);
}

.goal-current {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text);
}

.goal-separator {
  font-size: 18px;
  color: var(--color-text-tertiary);
}

.goal-target {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.goal-unit {
  font-size: 14px;
  color: var(--color-text-tertiary);
  margin-left: var(--spacing-xs);
}

.goal-progress {
  height: 6px;
  background-color: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
}

.goal-progress-bar {
  height: 100%;
  border-radius: 3px;
  background-color: var(--color-primary);
  transition: width 0.4s ease;
}

#goal-calories-bar {
  background-color: var(--color-calories);
}

#goal-protein-bar {
  background-color: var(--color-protein);
}

#goal-carbs-bar {
  background-color: var(--color-carbs);
}

#goal-fat-bar {
  background-color: var(--color-fat);
}

/* ───────── 13. Form Elements ───────── */
.form-group {
  margin-bottom: var(--spacing-md);
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--spacing-sm);
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  color: var(--color-text);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  min-height: 48px;
}

.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-alpha);
}

.form-input::placeholder {
  color: var(--color-text-tertiary);
}

.form-input.input-error {
  border-color: var(--color-protein);
  box-shadow: 0 0 0 3px rgba(239, 83, 80, 0.15);
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.form-help {
  font-size: 13px;
  color: var(--color-text-tertiary);
  margin-top: var(--spacing-sm);
  line-height: 1.4;
}

.form-link {
  color: var(--color-primary);
  text-decoration: underline;
  font-weight: 500;
}

textarea.form-input {
  resize: vertical;
  min-height: 100px;
}

select.form-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239CA3AF' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

/* ───────── 14. Modal Overlay & Dialog ───────── */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal-dialog {
  background-color: var(--color-surface);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
  animation: slideUp 0.3s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-lg) var(--spacing-lg) 0;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
}

.modal-body {
  padding: var(--spacing-lg);
}

.modal-footer {
  display: flex;
  gap: var(--spacing-sm);
  padding: 0 var(--spacing-lg) var(--spacing-lg);
}

.modal-footer .btn {
  flex: 1;
}

/* Settings status message */
.settings-status {
  font-size: 14px;
  padding: var(--spacing-sm) 0;
  min-height: 24px;
}

.settings-status.success {
  color: var(--color-primary);
}

.settings-status.error {
  color: var(--color-protein);
}

/* Setup prompt text */
.setup-text {
  font-size: 15px;
  color: var(--color-text-secondary);
  line-height: 1.5;
  margin-bottom: var(--spacing-lg);
}

/* Utility to visually hide elements (used by JS classList.toggle) */
.hidden { display: none !important; }

/* ───────── 15. Loading / Processing Overlay ───────── */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.2s ease;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-xl);
}

.loading-text {
  font-size: 20px;
  font-weight: 700;
  color: #FFFFFF;
  letter-spacing: 0.5px;
}

.loading-subtext {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
  margin-top: -8px;
}

/* Spinner */
.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #FFFFFF;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* ───────── 15b. Toast Container ───────── */
.toast-container {
  position: fixed;
  bottom: calc(var(--tab-bar-height) + var(--safe-area-bottom) + var(--spacing-md));
  left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  align-items: center;
  pointer-events: none;
  max-width: 90%;
}

.toast {
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  color: #FFFFFF;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: toastIn 0.3s ease;
  pointer-events: auto;
  text-align: center;
  max-width: 100%;
}

.toast.toast-error { background-color: var(--color-protein); }
.toast.toast-success { background-color: var(--color-primary); }
.toast.toast-info { background-color: var(--color-text-secondary); }

.toast.removing {
  animation: toastOut 0.3s ease forwards;
}

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

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

.preview-actions {
  display: flex;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-sm);
  justify-content: center;
}

/* ───────── 16. Photo Capture Controls ───────── */
.capture-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-md);
  padding: var(--spacing-lg) 0 var(--spacing-md);
}

.capture-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background-color: var(--color-primary);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(76, 175, 80, 0.4);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: relative;
}

.capture-btn::after {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.4);
}

.capture-btn:active {
  transform: scale(0.92);
  box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
}

.camera-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

/* ───────── 17. Photo Preview ───────── */
.photo-preview {
  margin-bottom: var(--spacing-md);
  border-radius: 12px;
  overflow: hidden;
  background-color: var(--color-border);
  position: relative;
}

.photo-preview img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
}

.photo-preview .btn {
  margin-top: var(--spacing-sm);
}

/* ───────── 18. Scan Results ───────── */
.scan-results {
  margin-bottom: var(--spacing-md);
  padding: var(--spacing-md);
  background-color: var(--color-primary-alpha);
  border-radius: 12px;
}

.results-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--spacing-sm);
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-sm) var(--spacing-md);
  background-color: var(--color-surface);
  border-radius: 10px;
}

.result-item-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}

.result-item-detail {
  font-size: 13px;
  color: var(--color-text-secondary);
}

.result-item-confidence {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  background-color: var(--color-primary-alpha);
  color: var(--color-primary-dark);
  font-weight: 600;
}

/* ───────── 19. Scan Idle State ───────── */
.scan-idle .placeholder-state {
  padding-bottom: var(--spacing-sm);
}

/* ───────── 20. Utilities ───────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-center {
  justify-content: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-sm {
  gap: var(--spacing-sm);
}

.gap-md {
  gap: var(--spacing-md);
}

.text-center {
  text-align: center;
}

.text-secondary {
  color: var(--color-text-secondary);
}

.text-tertiary {
  color: var(--color-text-tertiary);
}

.mt-sm {
  margin-top: var(--spacing-sm);
}

.mt-md {
  margin-top: var(--spacing-md);
}

.mb-md {
  margin-bottom: var(--spacing-md);
}

.p-md {
  padding: var(--spacing-md);
}

/* ───────── 21. Responsive Fine-tuning ───────── */

/* iPhone SE / small screens (375px) */
@media (max-width: 375px) {
  .tab-icon {
    font-size: 22px;
  }

  .tab-label {
    font-size: 9px;
  }

  .macro-ring {
    width: 76px;
    height: 76px;
  }

  .macro-ring-segment {
    width: 62px;
    height: 62px;
  }

  .macro-value {
    font-size: 20px;
  }

  .card-header h2 {
    font-size: 18px;
  }
}

/* iPhone Pro Max / large screens (430px+) */
@media (min-width: 430px) {
  .content-scroll {
    padding-left: var(--spacing-lg);
    padding-right: var(--spacing-lg);
  }

  .card {
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* Scrollbar styling for Webkit */
.content-scroll::-webkit-scrollbar {
  width: 4px;
}

.content-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.content-scroll::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: 2px;
}

/* ───────── 22. Add Meal Button & Meal Card Enhancements ───────── */
.btn-block {
  display: block;
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  border-radius: 12px;
  margin-bottom: 16px;
}

.meal-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-divider);
  position: relative;
  background: var(--color-surface);
  border-radius: 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

.meal-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-left: auto;
  min-width: 50px;
}

.meal-cal-label {
  font-size: 11px;
  color: var(--color-text-tertiary);
}

.meal-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--color-text-tertiary);
  border-radius: 50%;
  background: var(--color-divider);
  line-height: 1;
}

.meal-item:hover .meal-delete-btn,
.meal-item:focus-within .meal-delete-btn {
  display: flex;
}

.meal-items-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.meal-item-chip {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--color-primary-alpha);
  color: var(--color-primary-dark);
  border-radius: 10px;
  white-space: nowrap;
}

.meal-item-more {
  background: var(--color-border);
  color: var(--color-text-tertiary);
}

.meal-finalized-badge {
  font-size: 12px;
  margin-top: 2px;
}

.placeholder-subtext {
  font-size: 13px;
  color: var(--color-text-tertiary);
  margin-top: 4px;
}

/* ───────── 23. Charts ───────── */
.chart-row {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.chart-container {
  background: var(--color-surface);
  border-radius: 12px;
  padding: 16px;
}

.chart-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--color-text);
}

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

.chart-full {
  grid-column: 1 / -1;
}

.chart-half {
  flex: 1;
  min-width: 0;
}

/* ───────── 24. Goals Form ───────── */
.goals-form {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}

.form-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 12px;
  margin-top: 16px;
}

.form-section-title:first-child {
  margin-top: 0;
}

.goal-form-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.form-status {
  margin-top: 8px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.ideal-weight-info {
  margin-top: 16px;
  padding: 12px;
  background: var(--color-primary-alpha);
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.6;
}

.ideal-weight-info p {
  margin-bottom: 4px;
}


/* ───────── 24c. Goal Setting Form ───────── */
.form-hint {
  font-size: 12px;
  color: var(--color-text-tertiary);
  margin-top: 4px;
  line-height: 1.4;
}

.form-label-note {
  font-weight: 400;
  color: var(--color-text-tertiary);
  font-size: 12px;
}

.body-fat-scale {
  margin-top: 8px;
  position: relative;
}

.bf-bar {
  display: flex;
  height: 24px;
  border-radius: 12px;
  overflow: hidden;
  font-size: 10px;
  font-weight: 600;
}

.bf-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex: 1;
}

.bf-segment span {
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.bf-thin-men, .bf-thin-women { background: #3b82f6; }
.bf-ideal-men, .bf-ideal-women { background: #22c55e; flex: 2; }
.bf-high-men, .bf-high-women { background: #f59e0b; }
.bf-too-high-men, .bf-too-high-women { background: #ef4444; }

.bf-marker {
  position: absolute;
  top: -8px;
  font-size: 16px;
  transition: left 0.3s ease;
  transform: translateX(-50%);
}

.bf-category {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  margin-top: 2px;
  min-height: 20px;
}

.approach-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.approach-radio {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.approach-radio:hover {
  border-color: var(--color-primary);
}

.approach-radio input[type="radio"] {
  appearance: auto;
  -webkit-appearance: auto;
  width: 18px;
  height: 18px;
  margin-right: 10px;
  accent-color: var(--color-primary);
  flex-shrink: 0;
}

.approach-radio:has(input:checked) {
  border-color: var(--color-primary);
  background: var(--color-primary-alpha);
}

.approach-label {
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.approach-sub {
  font-size: 12px;
  font-weight: 400;
  color: var(--color-text-tertiary);
}

.goal-results {
  margin-top: 12px;
  padding: 16px;
  background: var(--color-primary-alpha);
  border: 1px solid var(--color-primary);
  border-radius: 12px;
}

.goal-results-empty {
  margin-top: 12px;
  padding: 16px;
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: 12px;
  font-size: 13px;
  color: var(--color-text-tertiary);
  text-align: center;
}

.result-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}

.result-label {
  color: var(--color-text-secondary);
  font-weight: 500;
}

.result-value {
  font-weight: 700;
  font-size: 18px;
  color: var(--color-text);
}

.result-unit {
  font-size: 12px;
  color: var(--color-text-tertiary);
  margin-left: 4px;
}

.result-note {
  font-size: 11px;
  color: var(--color-text-tertiary);
  font-weight: 400;
}

.result-divider {
  height: 1px;
  background: var(--color-border);
  margin: 8px 0;
}

.result-time .result-value {
  color: var(--color-primary);
}

.result-time .result-label {
  font-weight: 600;
  color: var(--color-text);
}

.goal-results .result-note {
  text-align: center;
  font-size: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--color-border);
}


/* ───────── 24b. Chart Empty Overlay ───────── */
.chart-empty-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 16px;
  font-size: 14px;
  color: var(--color-text-tertiary);
  pointer-events: none;
  z-index: 1;
}

.chart-wrapper {
  position: relative;
}

/* ───────── 24c. Loading Button ───────── */
.btn-loading {
  opacity: 0.7;
  cursor: not-allowed;
}

.btn-loading::after {
  content: '…';
}

/* ───────── 24d. Meal Finalization ───────── */
.meal-finalized {
  opacity: 0.6;
}

.meal-finalized .meal-name {
  text-decoration: line-through;
}

.meal-finalized .btn-add-food {
  opacity: 0.5;
  cursor: not-allowed;
}

.meal-finalized .meal-delete-btn {
  display: none !important;
}

.meal-finalize-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  font-size: 14px;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  margin-top: 4px;
}

.meal-finalize-btn:active {
  background: var(--color-border);
  color: var(--color-text);
}

.food-item-chip-disabled {
  opacity: 0.6;
  pointer-events: none;
}

.btn-add-food-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ───────── 25. Weight Log ───────── */
.weight-section {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}

.weight-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.weight-header .form-section-title {
  margin: 0;
  margin-right: auto;
}

.weight-summary {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.weight-stat {
  flex: 1;
  min-width: 80px;
  text-align: center;
  padding: 8px;
  background: var(--color-surface);
  border-radius: 8px;
}

.weight-stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
}

.weight-stat-label {
  font-size: 11px;
  color: var(--color-text-tertiary);
  margin-top: 2px;
}

.weight-log-list {
  max-height: 200px;
  overflow-y: auto;
}

.weight-log-entry {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-divider);
  font-size: 14px;
}

.weight-log-entry:last-child {
  border-bottom: none;
}

.weight-log-date {
  color: var(--color-text-secondary);
  min-width: 80px;
}

.weight-log-value {
  font-weight: 600;
  margin-left: auto;
}

.weight-log-detail {
  font-size: 12px;
  color: var(--color-text-tertiary);
  margin-left: 12px;
}

/* ───────── 26. Nutritionist ───────── */
.nutritionist-controls {
  margin-bottom: 16px;
}

.nutritionist-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.analysis-results {
  margin-top: 8px;
}

.analysis-summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.analysis-stat {
  flex: 1;
  min-width: 70px;
  text-align: center;
  padding: 10px 8px;
  background: var(--color-surface);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.analysis-stat-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--color-primary);
}

.analysis-stat-label {
  display: block;
  font-size: 11px;
  color: var(--color-text-tertiary);
  margin-top: 2px;
}

.analysis-meal-types {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.meal-type-badge {
  font-size: 12px;
  padding: 4px 10px;
  background: var(--color-primary-alpha);
  color: var(--color-primary-dark);
  border-radius: 12px;
}

.analysis-recommendations {
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--color-primary-alpha);
  border-radius: 10px;
}

.analysis-recommendations h4 {
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--color-primary-dark);
}

.analysis-recommendations ul {
  list-style: disc;
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--color-text);
}

.analysis-ai {
  padding: 16px;
  background: var(--color-surface);
  border-radius: 10px;
  border: 1px solid var(--color-border);
}

.analysis-ai h4 {
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--color-text);
}

.analysis-ai-text {
  font-size: 13px;
  line-height: 1.7;
  color: var(--color-text);
  white-space: pre-wrap;
}

.analysis-loading {
  text-align: center;
  padding: 24px;
  color: var(--color-text-secondary);
}

/* ───────── 27. Food Search Modal ───────── */
.food-search-input {
  font-size: 16px;
}

.food-search-results {
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-surface);
}

.food-search-results:empty {
  border: none;
  margin-bottom: 0;
}

.food-search-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-divider);
  cursor: pointer;
  transition: background-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

.food-search-item:active,
.food-search-item.selected {
  background-color: var(--color-primary-alpha);
}

.food-search-item-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}

.food-search-item-cal {
  font-size: 12px;
  color: var(--color-text-tertiary);
  flex-shrink: 0;
  margin-left: var(--spacing-sm);
}

.food-quantity-row {
  padding-top: var(--spacing-sm);
}

/* ───────── 28. Food Item Chips on Meal Cards ───────── */
.meal-items-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.food-item-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 2px 6px;
  background: var(--color-primary-alpha);
  color: var(--color-primary-dark);
  border-radius: 10px;
  white-space: nowrap;
}

.food-item-chip-name {
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.food-item-chip-qty,
.food-item-chip-cal {
  color: var(--color-text-secondary);
}

.food-item-chip-edit,
.food-item-chip-delete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  font-size: 12px;
  line-height: 1;
  border-radius: 50%;
  color: var(--color-text-tertiary);
  background: transparent;
  transition: background 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  cursor: pointer;
}

.food-item-chip-edit:hover,
.food-item-chip-edit:active,
.food-item-chip-delete:hover,
.food-item-chip-delete:active {
  background: var(--color-border);
  color: var(--color-text);
}

.food-item-chip-delete {
  color: var(--color-protein);
  font-weight: 700;
}

.btn-add-food {
  display: block;
  width: 100%;
  padding: 8px 12px;
  margin-top: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
  background: var(--color-primary-alpha);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  text-align: center;
}

.btn-add-food:active {
  background: var(--color-primary-light);
}

/* ───────── Range Slider ───────── */
.range-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range-wrapper input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 6px;
  background: var(--color-border);
  border-radius: 3px;
  outline: none;
  transition: background 0.2s;
}

.range-wrapper input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  transition: transform 0.15s;
}

.range-wrapper input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.range-wrapper input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--color-primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.range-wrapper input[type="range"]:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 3px var(--color-primary-alpha);
}

.range-wrapper input[type="range"]:focus::-moz-range-thumb {
  box-shadow: 0 0 0 3px var(--color-primary-alpha);
}

.range-value {
  font-weight: 700;
  font-size: 16px;
  color: var(--color-text);
  min-width: 60px;
  text-align: right;
  flex-shrink: 0;
}

/* ───────── Current Stats (Live BMI + Ideal Weight) ───────── */
.current-stats {
  margin-top: 12px;
  padding: 12px 16px;
  background: var(--color-primary-alpha);
  border: 1px solid var(--color-primary);
  border-radius: 12px;
}

.stat-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
}

.stat-label {
  color: var(--color-text-secondary);
  font-weight: 500;
}

.stat-value {
  font-weight: 700;
  font-size: 16px;
  color: var(--color-text);
}

/* ───────── BMI Band ───────── */
.bmi-band {
  position: relative;
  margin-top: 10px;
  padding-top: 6px;
}

.bmi-band-track {
  display: flex;
  height: 22px;
  border-radius: 11px;
  overflow: hidden;
}

.bmi-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.bmi-malnourished {
  background: #ef4444;
  flex: 16;
}

.bmi-underweight {
  background: #f59e0b;
  flex: 2.5;
}

.bmi-ideal {
  background: #22c55e;
  flex: 6.5;
}

.bmi-overweight {
  background: #f59e0b;
  flex: 5;
}

.bmi-obese {
  background: #ef4444;
  flex: 10;
}

.bmi-marker {
  position: absolute;
  top: 0;
  font-size: 14px;
  color: #1a1a2e;
  transform: translateX(-50%);
  transition: left 0.3s ease;
  text-shadow: 0 1px 2px rgba(255,255,255,0.5);
  pointer-events: none;
  line-height: 1;
}
