/* FitLog Premium CSS Design System & Styles */

:root {
  /* Colors */
  --bg-color: #0b131a;
  --surface-color: rgba(21, 38, 53, 0.75);
  --surface-color-solid: #152635;
  --surface-card: rgba(30, 48, 66, 0.5);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-active: rgba(16, 185, 129, 0.3);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --primary: #10b981;
  --primary-glow: rgba(16, 185, 129, 0.25);
  --primary-dark: #059669;
  
  --water: #06b6d4;
  --water-glow: rgba(6, 182, 212, 0.2);
  --water-dark: #0891b2;
  
  --carbs: #3b82f6;
  --protein: #ec4899;
  --fat: #f59e0b;
  --danger: #ef4444;
  
  /* Fonts */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'Outfit', monospace, sans-serif;
}

/* Base Resets */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* Prevents long-press popups on buttons/cards in standalone mode */
  touch-action: manipulation; /* Prevents double-tap zoom across the entire application */
}

/* Allow text selection and cursor movement inside form inputs on iOS */
input, textarea {
  user-select: text !important;
  -webkit-user-select: text !important;
  -webkit-touch-callout: default !important;
}

html, body {
  width: 100%;
  height: 100dvh; /* Force dynamic viewport height to fill modern mobile screens completely */
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: var(--font-sans);
  overflow: hidden;
  font-size: 16px;
  overscroll-behavior-y: contain; /* Prevents pull-to-refresh on mobile Chrome/Safari! */
}

/* App Layout */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh; /* Fill full height of the viewport on all mobile screens */
  max-width: 480px; /* Force premium mobile phone width on desktop */
  margin: 0 auto;
  background-color: var(--bg-color);
  position: relative;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.8);
  border-left: 1px solid rgba(255, 255, 255, 0.03);
  border-right: 1px solid rgba(255, 255, 255, 0.03);
  overflow-x: hidden; /* Strictly prevents any horizontal/side scrolling or leakage */
}

/* Header */
.app-header {
  height: calc(64px + env(safe-area-inset-top)); /* Expand height dynamically for iPhone notches/Dynamic Island */
  background: rgba(11, 19, 26, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: flex-end; /* Align elements beautifully at the bottom of header */
  padding: 0 1.5rem 0.65rem 1.5rem; /* Add clear bottom clearance */
  z-index: 100;
}

.header-content {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo-icon {
  display: flex;
  align-items: center;
  filter: drop-shadow(0 0 6px var(--primary-glow));
}

.header-logo h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.header-logo h1 .highlight {
  color: var(--primary);
  background: linear-gradient(135deg, var(--primary) 0%, #06b6d4 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-date-selector {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  background: var(--surface-card);
  border-radius: 99px;
  border: 1px solid var(--border-color);
  padding: 0.15rem 0.35rem;
}

.date-nav-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.date-nav-btn:active {
  background: rgba(255, 255, 255, 0.05);
  color: var(--primary);
  transform: scale(0.9);
}

.date-nav-btn i {
  width: 14px;
  height: 14px;
}

.date-display-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.15rem 0.35rem;
}

#current-date-display {
  font-size: 0.8rem;
  color: var(--text-primary);
  font-weight: 600;
  white-space: nowrap;
}

#hidden-date-picker {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* Main Content Area */
.app-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1rem;
  padding-bottom: calc(100px + env(safe-area-inset-bottom)); /* Increased bottom padding to prevent overlap with floating navigation bar */
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Hide scrollbars for aesthetic perfection */
.app-content::-webkit-scrollbar {
  display: none;
}

/* Bottom Navigation Bar */
.app-nav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(64px + env(safe-area-inset-bottom)); /* Dynamic height supporting safe area on borderless phones */
  background: rgba(21, 38, 53, 0.85);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}

.nav-item {
  background: none;
  border: none;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.nav-item i {
  width: 20px;
  height: 20px;
  stroke-width: 2px;
  transition: transform 0.2s ease;
}

.nav-item span {
  font-size: 0.7rem;
  font-weight: 600;
}

.nav-item.active {
  color: var(--primary);
  filter: drop-shadow(0 0 4px var(--primary-glow));
}

.nav-item.active i {
  transform: translateY(-2px);
  stroke-width: 2.5px;
}

.nav-item.active::after {
  content: '';
  position: absolute;
  top: 0;
  width: 24px;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 4px 4px;
  box-shadow: 0 1px 6px var(--primary);
}

/* Tab Panels */
.tab-panel {
  display: none;
  animation: fadeIn 0.4s ease forwards;
}

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

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

/* Common Section Styles */
.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
  letter-spacing: -0.3px;
}

/* Dashboard Cards (Glassmorphic) */
.dashboard-card {
  background: var(--surface-color);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

/* --- TAB 1: SUMMARY / CALORIE PROGRESS RING --- */
.summary-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  background: radial-gradient(circle at 50% 0%, rgba(16, 185, 129, 0.1) 0%, var(--surface-color-solid) 80%);
}

.calorie-progress-container {
  position: relative;
  width: 180px;
  height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.progress-ring {
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

.progress-ring__circle {
  transition: stroke-dashoffset 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  filter: drop-shadow(0 0 6px var(--primary-glow));
}

.calorie-values {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.calorie-values .consumed-val {
  font-family: var(--font-mono);
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text-primary);
}

.calorie-values .target-val {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 0.15rem;
}

.calorie-values .status-val {
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 700;
  margin-top: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Macro Bars in Dashboard */
.macro-summary-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.macro-item {
  width: 100%;
}

.macro-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.macro-text {
  font-family: var(--font-mono);
  font-weight: 500;
}

.macro-bar-bg {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 99px;
  overflow: hidden;
}

.macro-bar-fill {
  height: 100%;
  border-radius: 99px;
  width: 0%;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.macro-bar-fill.carbs { background: var(--carbs); box-shadow: 0 0 6px rgba(59, 130, 246, 0.4); }
.macro-bar-fill.protein { background: var(--protein); box-shadow: 0 0 6px rgba(236, 72, 153, 0.4); }
.macro-bar-fill.fat { background: var(--fat); box-shadow: 0 0 6px rgba(245, 158, 11, 0.4); }

/* --- WATER TRACKER CARD --- */
.water-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.water-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.water-title h3 {
  font-size: 1rem;
  font-weight: 700;
}

.water-title p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.icon-water {
  color: var(--water);
  filter: drop-shadow(0 0 4px var(--water-glow));
}

.water-quick-buttons {
  display: flex;
  gap: 0.5rem;
}

.water-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  font-size: 1.2rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.water-btn.btn-minus {
  background: var(--surface-card);
  color: var(--text-secondary);
}

.water-btn.btn-plus {
  background: linear-gradient(135deg, var(--water) 0%, var(--water-dark) 100%);
  color: #fff;
  border: none;
  box-shadow: 0 4px 10px var(--water-glow);
}

.water-btn:active {
  transform: scale(0.9);
}

/* Water filling glass wave */
.water-progress-visual {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.water-wave-container {
  width: 60px;
  height: 75px;
  background: rgba(30, 48, 66, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top: none;
  border-radius: 0 0 16px 16px;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.3);
}

.water-fill-level {
  width: 100%;
  position: absolute;
  bottom: 0;
  background: linear-gradient(to top, rgba(6, 182, 212, 0.8) 0%, rgba(8, 145, 178, 0.6) 100%);
  transition: height 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* SVG Wave effect */
.wave {
  position: absolute;
  top: -10px;
  left: 0;
  width: 200%;
  height: 12px;
  background: radial-gradient(circle, transparent 20%, rgba(6, 182, 212, 0.6) 21%, rgba(6, 182, 212, 0.6) 80%, transparent 81%);
  background-size: 20px 20px;
  animation: waveMotion 1.5s linear infinite;
}

@keyframes waveMotion {
  0% { transform: translateX(0); }
  100% { transform: translateX(-20px); }
}

.water-cups-row {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
}

.cup-slot {
  aspect-ratio: 1;
  border-radius: 8px;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.cup-slot.active {
  background: rgba(6, 182, 212, 0.15);
  border-color: var(--water);
  color: var(--water);
  filter: drop-shadow(0 0 2px var(--water-glow));
  animation: popCup 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popCup {
  0% { transform: scale(0.8); }
  100% { transform: scale(1); }
}

/* Motivation Card */
.motivation-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(135deg, rgba(255,255,255,0.02) 0%, rgba(16, 185, 129, 0.05) 100%);
  border-left: 4px solid var(--primary);
}

.motivation-card p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.icon-sparkle {
  color: var(--primary);
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

/* --- TAB 2: DIARY MEAL CARD --- */
.meal-group-card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.meal-group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.meal-group-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.meal-group-title h3 {
  font-size: 1rem;
  font-weight: 700;
}

.meal-group-sub {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Colors for Meal Group Icons */
.icon-breakfast { color: var(--fat); }
.icon-lunch { color: var(--primary); }
.icon-dinner { color: var(--carbs); }
.icon-snacks { color: var(--protein); }

.add-food-trigger {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.4rem 0.8rem;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.add-food-trigger i {
  width: 14px;
  height: 14px;
}

.add-food-trigger:hover, .add-food-trigger:active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.meal-items-list {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.empty-meal-placeholder {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.5rem 0;
  font-style: italic;
}

/* Added Food Item Row */
.meal-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-card);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

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

.meal-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-width: 70%;
}

.meal-item-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meal-item-amount {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.meal-item-macros {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.meal-item-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.meal-item-calories {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
}

.btn-delete-item {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s ease;
}

.btn-delete-item:hover, .btn-delete-item:active {
  color: var(--danger);
}

/* --- TAB 3: WEIGHT & ANALYTICS --- */
.weight-form-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper input {
  width: 100%;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 1.1rem;
  padding: 0.75rem 1rem;
  padding-right: 2.5rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.input-wrapper input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.input-wrapper .unit-label {
  position: absolute;
  right: 1rem;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.9rem;
}

/* Global button styles */
.btn {
  font-family: var(--font-sans);
  font-weight: 700;
  border-radius: 12px;
  border: none;
  padding: 0.75rem 1.5rem;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: 0 4px 12px var(--primary-glow);
}

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

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:active {
  background: rgba(255, 255, 255, 0.12);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

.btn-outline:active {
  background: rgba(255,255,255,0.03);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:active {
  background: rgba(239, 68, 68, 0.25);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-weight: 600;
}

/* Custom Dynamic SVG Chart Card */
.chart-card {
  padding-bottom: 0.75rem;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.chart-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.chart-sub {
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
}

.chart-wrapper {
  width: 100%;
  overflow: visible;
  padding: 0.25rem 0;
}

#weight-svg-chart {
  overflow: visible;
}

.chart-line {
  fill: none;
  stroke: url(#chartGrad);
  stroke-width: 3.5px;
  stroke-linecap: round;
  filter: drop-shadow(0 4px 8px rgba(16, 185, 129, 0.3));
}

.chart-area {
  fill: url(#chartAreaGrad);
  opacity: 0.15;
}

.chart-grid {
  stroke: rgba(255, 255, 255, 0.03);
  stroke-width: 1px;
}

.chart-dot {
  fill: #0b131a;
  stroke: var(--primary);
  stroke-width: 3px;
  cursor: pointer;
  transition: r 0.2s ease;
}

.chart-dot:hover {
  r: 6;
}

.chart-label-x {
  font-size: 8px;
  fill: var(--text-muted);
  font-family: var(--font-sans);
  text-anchor: middle;
}

.chart-label-y {
  font-size: 8px;
  fill: var(--text-muted);
  font-family: var(--font-mono);
  text-anchor: end;
}

/* Weight history list */
.history-list-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
  max-height: 200px;
  overflow-y: auto;
  padding-right: 0.25rem;
}

.history-list-container::-webkit-scrollbar {
  width: 4px;
}

.history-list-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.empty-history-placeholder {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  padding: 1rem 0;
}

.weight-history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.8rem;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  animation: fadeIn 0.3s ease;
}

.weight-hist-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.weight-hist-date {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.weight-hist-val {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
}

/* --- TAB 4: SETTINGS & TOOLS --- */
.settings-card-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.settings-card-title i {
  color: var(--primary);
  width: 20px;
  height: 20px;
}

.settings-card-title h3 {
  font-size: 1rem;
  font-weight: 700;
}

.settings-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 1rem;
}

.settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

.form-group input {
  width: 100%; /* Prevents text inputs from overflowing their container */
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.65rem 0.85rem;
  color: var(--text-primary);
  font-size: 16px; /* Prevents auto-zoom on iOS Safari */
  outline: none;
  font-family: var(--font-sans);
  transition: all 0.2s ease;
}

.form-group input:focus {
  border-color: var(--primary);
  background: rgba(30, 48, 66, 0.7);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.settings-button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.settings-button-grid button {
  font-size: 0.75rem;
  padding: 0.6rem;
}

/* ==================== MODAL STYLING ==================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end; /* Slides up from bottom */
  justify-content: center;
  visibility: hidden;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal.active {
  visibility: visible;
  opacity: 1;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-container {
  width: 100%;
  max-width: 480px;
  background: #111e2b;
  border-radius: 24px 24px 0 0;
  border-top: 1px solid var(--border-color);
  z-index: 1010;
  display: flex;
  flex-direction: column;
  max-height: 85vh; /* Mobile constraint */
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal.active .modal-container {
  transform: translateY(0);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.close-modal-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Modal Search Engine */
.search-container {
  position: relative;
  display: flex;
  align-items: center;
}

.search-container input {
  width: 100%;
  background: rgba(0,0,0,0.25);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 16px; /* Prevents auto-zoom on iOS Safari */
  padding: 0.7rem 1rem;
  padding-left: 2.25rem;
  outline: none;
  transition: all 0.2s ease;
}

.search-container input:focus {
  border-color: var(--primary);
  background: rgba(0,0,0,0.4);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  color: var(--text-secondary);
  width: 16px;
  height: 16px;
}

/* Category Filters in search */
.category-filters {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.4rem;
  flex-wrap: nowrap;
}

.category-filters::-webkit-scrollbar {
  display: none;
}

.filter-pill {
  white-space: nowrap;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-card);
  padding: 0.35rem 0.7rem;
  border-radius: 99px;
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  filter: drop-shadow(0 2px 4px var(--primary-glow));
}

/* Search results items */
.search-results-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 250px;
  overflow-y: auto;
}

.search-results-container::-webkit-scrollbar {
  width: 4px;
}

.search-results-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.search-food-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.7rem 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.search-food-row:active {
  background: rgba(16, 185, 129, 0.08);
  border-color: var(--primary);
}

.search-food-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.search-food-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.search-food-sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.search-food-calories {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
}

.no-results-placeholder {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 1.5rem 0;
}

/* Amount Config panel inside modal */
.food-amount-selector {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: fadeIn 0.3s ease;
}

.selected-food-info h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.selected-food-info p {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.amount-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
}

.amount-input-row .form-group {
  flex: 1;
}

.quantity-input-wrapper {
  display: flex;
  align-items: center;
  background: var(--surface-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
}

.quantity-input-wrapper input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  text-align: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
  padding: 0.5rem 0;
  outline: none;
  width: 60px;
}

.quantity-input-wrapper input::-webkit-outer-spin-button,
.quantity-input-wrapper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.qty-btn {
  background: rgba(255, 255, 255, 0.03);
  border: none;
  color: var(--text-secondary);
  font-size: 1.1rem;
  font-weight: 600;
  width: 38px;
  height: 38px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.qty-btn:active {
  background: rgba(255, 255, 255, 0.08);
}

.unit-toggle {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Selected Macro Calculation Pills */
.selected-macro-calc-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.calc-macro-pill {
  background: rgba(0,0,0,0.15);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
}

.calc-macro-pill .lbl {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 600;
}

.calc-macro-pill .val {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
}

/* Toast Notifications */
.toast-notification {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(40px);
  background: rgba(16, 185, 129, 0.95);
  color: #fff;
  padding: 0.6rem 1.25rem;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 700;
  box-shadow: 0 4px 15px rgba(0,0,0,0.4);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast-notification.active {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* Custom backgrounds for different toasts (like error, info) */
.toast-notification.danger {
  background: rgba(239, 68, 68, 0.95);
}

.toast-notification.info {
  background: rgba(6, 182, 212, 0.95);
}

/* ==================== BARCODE SCANNER CUSTOM STYLING ==================== */
.barcode-scan-btn {
  position: absolute;
  right: 0.5rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--primary);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 5;
}

.barcode-scan-btn:active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  transform: scale(0.9);
}

.search-container input {
  padding-right: 3.25rem !important; /* Make room for barcode button */
}

/* Form row with input and button */
.input-with-button-row {
  display: flex;
  gap: 0.5rem;
}

.input-with-button-row input {
  flex: 1;
}

.input-with-button-row button {
  padding: 0 0.85rem;
  aspect-ratio: 1;
  color: var(--primary);
  border-color: var(--border-color);
}

.input-with-button-row button:active {
  background: rgba(16, 185, 129, 0.1);
  border-color: var(--primary);
}

/* Scanner Container in modal */
.scanner-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 0.5rem;
  animation: fadeIn 0.3s ease;
}

.scanner-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid var(--primary);
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.2);
  background: #000;
}

#interactive-scanner {
  width: 100% !important;
  height: 100% !important;
}

/* Hide some HTML5 QR Code library ugly default buttons/texts */
#interactive-scanner video {
  object-fit: cover !important;
  width: 100% !important;
  height: 100% !important;
}

#interactive-scanner img {
  display: none !important;
}

#interactive-scanner__header_message, 
#interactive-scanner__status_span,
#interactive-scanner button {
  font-family: var(--font-sans) !important;
  font-size: 0.8rem !important;
  font-weight: 600 !important;
}

/* Customized library choose camera dropdown and start button */
#interactive-scanner select {
  background: var(--surface-color-solid) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 6px !important;
  padding: 0.3rem !important;
  outline: none !important;
  margin: 0.5rem 0 !important;
}

#interactive-scanner button {
  background: var(--primary) !important;
  color: #fff !important;
  border: none !important;
  padding: 0.4rem 1rem !important;
  border-radius: 8px !important;
  cursor: pointer !important;
  margin: 0.5rem 0.25rem !important;
}

/* Glowing Scanning Laser Line */
.scanner-laser {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(to right, transparent, var(--primary), transparent);
  box-shadow: 0 0 8px var(--primary);
  animation: laserScan 2s linear infinite;
  pointer-events: none;
  z-index: 10;
}

@keyframes laserScan {
  0% { top: 0%; }
  50% { top: 100%; }
  100% { top: 0%; }
}

/* Spinner micro-animation */
.spin-icon {
  animation: spin 1s linear infinite;
}

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