/* ================================
   COMPONENTS.CSS
   ================================ */

/* === Splash Screen === */
.splash-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 100dvh;
  background: linear-gradient(135deg, #FFF8F0 0%, #FFE8D6 100%);
  text-align: center; gap: var(--sp-md);
}
.splash-emoji {
  font-size: 5rem; line-height: 1;
  animation: splash-bounce 1s var(--ease-bounce) infinite;
}
.splash-title {
  font-family: var(--font-display); font-size: 3.5rem;
  background: linear-gradient(135deg, var(--coral), var(--orange));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.splash-sub { color: var(--text-muted); font-weight: 600; }
.splash-dots { display: flex; gap: 8px; margin-top: 8px; }
.splash-dots span {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--coral); display: inline-block;
  animation: dot-pulse 1.2s ease-in-out infinite;
}
.splash-dots span:nth-child(2) { animation-delay: 0.2s; background: var(--orange); }
.splash-dots span:nth-child(3) { animation-delay: 0.4s; background: var(--yellow); }

/* === Bottom Nav === */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: var(--max-w);
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255,248,240,0.95);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 2px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  z-index: 100;
}
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 16px; border: none; background: none; cursor: pointer;
  color: var(--text-light); font-family: var(--font-body);
  font-size: 0.68rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.04em; transition: all var(--t-fast) var(--ease-bounce);
  border-radius: var(--r-md); flex: 1;
}
.nav-btn .nav-icon { font-size: 1.6rem; line-height: 1; transition: transform var(--t-fast) var(--ease-bounce); }
.nav-btn:active .nav-icon { transform: scale(0.85); }
.nav-btn.active { color: var(--coral); }
.nav-btn.active .nav-icon { transform: scale(1.15); }

/* === Page Header === */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px var(--sp-md) 8px;
  background: var(--bg); position: sticky; top: 0; z-index: 10;
}
.page-title { font-family: var(--font-display); font-size: 1.8rem; color: var(--text); }

/* === Diary Header === */
.diary-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px var(--sp-md) 8px;
  background: var(--bg); position: sticky; top: 0; z-index: 10;
}
.diary-header .date-block { text-align: center; }
.diary-header .date-label { font-family: var(--font-display); font-size: 1.6rem; color: var(--text); line-height: 1; }
.diary-header .date-sub { font-size: 0.85rem; color: var(--text-muted); font-weight: 700; }
.date-nav-btn {
  width: 40px; height: 40px; border-radius: var(--r-full);
  border: 2px solid var(--border); background: var(--surface);
  font-size: 1.2rem; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--t-fast) var(--ease-bounce); color: var(--text);
  box-shadow: var(--shadow-sm);
}
.date-nav-btn:active { transform: scale(0.88); }
.date-nav-btn.disabled { opacity: 0.3; pointer-events: none; }

/* === Macro Summary === */
.macro-summary {
  margin: 8px var(--sp-md) var(--sp-md);
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: var(--sp-lg) var(--sp-md);
  box-shadow: var(--shadow-md);
  border: 2px solid var(--border);
}
.macro-rings-row {
  display: flex; justify-content: space-around; align-items: center;
  gap: var(--sp-sm);
}
.macro-ring-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.macro-ring { position: relative; width: 72px; height: 72px; }
.macro-ring svg { transform: rotate(-90deg); }
.macro-ring .ring-bg { fill: none; stroke: var(--border); stroke-width: 8; }
.macro-ring .ring-fill {
  fill: none; stroke-width: 8; stroke-linecap: round;
  stroke-dasharray: var(--ring-length, 188.5);
  stroke-dashoffset: var(--ring-offset, 188.5);
  animation: ring-fill var(--t-slow) var(--ease-bounce) forwards;
  transition: stroke-dashoffset var(--t-slow) var(--ease-bounce);
}
.macro-ring .ring-center {
  position: absolute; inset: 0; display: flex;
  flex-direction: column; align-items: center; justify-content: center;
  line-height: 1.1;
}
.ring-value { font-size: 0.85rem; font-weight: 900; color: var(--text); }
.ring-unit  { font-size: 0.58rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; }
.ring-label { font-size: 0.72rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.ring-label-kcal    { color: var(--macro-kcal); }
.ring-label-protein { color: var(--macro-protein); }
.ring-label-carbs   { color: var(--macro-carbs); }
.ring-label-fat     { color: var(--macro-fat); }

/* === Meal Slots === */
.meal-slots { display: flex; flex-direction: column; gap: var(--sp-sm); padding: 0 var(--sp-md); }

.meal-slot {
  background: var(--surface); border-radius: var(--r-lg);
  border: 2px solid var(--border); overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--t-normal) var(--ease-out);
}
.meal-slot:hover { box-shadow: var(--shadow-md); }

.meal-slot-header {
  display: flex; align-items: center; gap: var(--sp-sm);
  padding: var(--sp-sm) var(--sp-md);
  cursor: pointer; user-select: none;
  transition: background var(--t-fast) var(--ease-out);
}
.meal-slot-header:hover { background: var(--surface-alt); }
.meal-slot-header:active { background: var(--border); }

.meal-emoji { font-size: 1.5rem; line-height: 1; flex-shrink: 0; }
.meal-name  { font-family: var(--font-display); font-size: 1.1rem; color: var(--text); flex: 1; }
.meal-kcal  { font-size: 0.8rem; font-weight: 800; color: var(--text-muted); }
.meal-chevron { font-size: 0.9rem; color: var(--text-light); transition: transform var(--t-normal) var(--ease-bounce); }
.meal-slot.open .meal-chevron { transform: rotate(90deg); }
.meal-add-btn {
  width: 32px; height: 32px; border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; font-weight: 700; flex-shrink: 0;
  transition: transform var(--t-fast) var(--ease-bounce), box-shadow var(--t-fast);
  box-shadow: var(--shadow-sm); color: white;
}
.meal-add-btn:active { transform: scale(0.88); }

.slot-breakfast .meal-add-btn { background: var(--breakfast-color); }
.slot-lunch     .meal-add-btn { background: var(--lunch-color); }
.slot-dinner    .meal-add-btn { background: var(--dinner-color); }
.slot-snacks    .meal-add-btn { background: var(--snacks-color); }
.slot-drinks    .meal-add-btn { background: var(--drinks-color); }

.slot-breakfast .meal-name { color: var(--breakfast-color); }
.slot-lunch     .meal-name { color: var(--lunch-color); }
.slot-dinner    .meal-name { color: var(--dinner-color); }
.slot-snacks    .meal-name { color: var(--snacks-color); }
.slot-drinks    .meal-name { color: var(--drinks-color); }

.meal-entries {
  display: none; flex-direction: column;
  border-top: 1px solid var(--border);
  padding: var(--sp-xs) 0;
}
.meal-slot.open .meal-entries { display: flex; }

.entry-row {
  display: flex; align-items: center; gap: var(--sp-sm);
  padding: 10px var(--sp-md); transition: background var(--t-fast);
  animation: fade-in-up var(--t-normal) var(--ease-out) both;
}
.entry-row:hover { background: var(--surface-alt); }
.entry-food-name { flex: 1; font-size: 0.9rem; font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry-amount { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; flex-shrink: 0; }
.entry-kcal { font-size: 0.85rem; font-weight: 800; color: var(--coral); flex-shrink: 0; min-width: 48px; text-align: right; }
.entry-delete {
  width: 28px; height: 28px; border-radius: var(--r-full); background: #FFE8E8;
  color: var(--coral); font-size: 0.85rem; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; opacity: 0; transition: opacity var(--t-fast), transform var(--t-fast) var(--ease-bounce);
}
.entry-row:hover .entry-delete { opacity: 1; }
.entry-delete:active { transform: scale(0.85); }

.slot-empty {
  padding: var(--sp-md); text-align: center;
  font-size: 0.85rem; color: var(--text-light); font-weight: 600;
  font-style: italic;
}

/* === Search View === */
.search-header {
  padding: var(--sp-md);
  background: var(--bg);
  position: sticky; top: 0; z-index: 10;
  border-bottom: 1px solid var(--border);
}
.search-context {
  font-size: 0.78rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.search-bar {
  display: flex; align-items: center; gap: var(--sp-sm);
  background: var(--surface); border: 2px solid var(--border);
  border-radius: var(--r-full); padding: 10px var(--sp-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.search-bar:focus-within {
  border-color: var(--coral); box-shadow: 0 0 0 3px rgba(255,107,107,0.15);
}
.search-icon { font-size: 1.1rem; color: var(--text-muted); flex-shrink: 0; }
.search-input {
  flex: 1; border: none; background: none; font-size: 1rem;
  font-weight: 700; color: var(--text); font-family: var(--font-body);
}
.search-input::placeholder { color: var(--text-light); font-weight: 600; }
.search-clear {
  font-size: 1rem; color: var(--text-light); padding: 2px 4px;
  border-radius: var(--r-full); transition: all var(--t-fast);
  display: none;
}
.search-bar:focus-within .search-clear { display: block; }
.search-clear:hover { background: var(--border); color: var(--text); }

.search-section-title {
  font-size: 0.72rem; font-weight: 900; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  padding: var(--sp-md) var(--sp-md) var(--sp-xs);
}

.food-card {
  display: flex; align-items: center; gap: var(--sp-md);
  padding: 12px var(--sp-md); background: var(--surface);
  cursor: pointer; transition: background var(--t-fast), transform var(--t-fast) var(--ease-bounce);
  border-bottom: 1px solid var(--border);
}
.food-card:active { background: var(--surface-alt); transform: scale(0.99); }
.food-card-emoji { font-size: 2rem; line-height: 1; flex-shrink: 0; }
.food-card-info { flex: 1; min-width: 0; }
.food-card-name { font-size: 0.95rem; font-weight: 800; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.food-card-brand { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.food-card-macros { display: flex; gap: var(--sp-sm); margin-top: 2px; flex-wrap: wrap; }
.macro-pill {
  font-size: 0.68rem; font-weight: 800; padding: 2px 7px;
  border-radius: var(--r-full); white-space: nowrap;
}
.macro-pill-kcal    { background: #FFE8E8; color: var(--coral); }
.macro-pill-protein { background: #EDE8FF; color: var(--lavender); }
.macro-pill-carbs   { background: #FFF9CC; color: #B8960A; }
.macro-pill-fat     { background: #FFF0E0; color: var(--orange); }
.food-card-confidence {
  font-size: 0.65rem; font-weight: 800; padding: 3px 8px;
  border-radius: var(--r-full); flex-shrink: 0; align-self: flex-start;
}
.conf-exact   { background: #D4EDDA; color: #155724; }
.conf-close   { background: #FFF3CD; color: #856404; }
.conf-generic { background: #E2E3E5; color: #383D41; }

/* === Quantity Picker Modal === */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(45,52,54,0.5);
  backdrop-filter: blur(4px); z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in var(--t-normal) var(--ease-out) both;
}
.modal-sheet {
  background: var(--surface); border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: var(--sp-lg) var(--sp-md) calc(var(--sp-xl) + var(--safe-bottom));
  width: 100%; max-width: var(--max-w);
  animation: slide-in-right var(--t-normal) var(--ease-bounce) both;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.2);
}
.modal-handle {
  width: 40px; height: 4px; background: var(--border-mid);
  border-radius: 2px; margin: 0 auto var(--sp-lg);
}
.modal-title { font-family: var(--font-display); font-size: 1.4rem; color: var(--text); margin-bottom: 4px; }
.modal-subtitle { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; margin-bottom: var(--sp-lg); }
.qty-row { display: flex; align-items: center; gap: var(--sp-sm); margin-bottom: var(--sp-md); }
.qty-label { font-weight: 800; font-size: 0.9rem; color: var(--text); flex: 1; }
.qty-input {
  width: 80px; text-align: center; font-size: 1.1rem; font-weight: 900;
  border: 2px solid var(--border); border-radius: var(--r-md);
  padding: 8px; background: var(--surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.qty-input:focus { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(255,107,107,0.15); }
.unit-select {
  border: 2px solid var(--border); border-radius: var(--r-md);
  padding: 8px 10px; font-family: var(--font-body); font-weight: 700;
  background: var(--surface); color: var(--text); font-size: 0.9rem;
  transition: border-color var(--t-fast);
}
.unit-select:focus { border-color: var(--coral); outline: none; }
.modal-macros-preview {
  background: var(--surface-alt); border-radius: var(--r-md);
  padding: var(--sp-md); margin-bottom: var(--sp-md);
  display: flex; gap: var(--sp-md); flex-wrap: wrap;
}
.modal-log-btn {
  width: 100%; padding: var(--sp-md); border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--coral), var(--orange));
  color: white; font-family: var(--font-display); font-size: 1.2rem;
  font-weight: 400; letter-spacing: 0.02em;
  box-shadow: 0 4px 20px rgba(255,107,107,0.4);
  transition: transform var(--t-fast) var(--ease-bounce), box-shadow var(--t-fast);
}
.modal-log-btn:active { transform: scale(0.97); box-shadow: 0 2px 10px rgba(255,107,107,0.3); }

/* === History View === */
.month-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-md); gap: var(--sp-sm);
}
.month-label { font-family: var(--font-display); font-size: 1.4rem; }
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 4px; padding: 0 var(--sp-md) var(--sp-md);
}
.cal-day-name {
  text-align: center; font-size: 0.7rem; font-weight: 900;
  text-transform: uppercase; color: var(--text-muted); padding: 4px 0;
}
.cal-day {
  aspect-ratio: 1; border-radius: var(--r-sm); display: flex;
  flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; transition: all var(--t-fast) var(--ease-bounce);
  position: relative;
}
.cal-day.empty { pointer-events: none; }
.cal-day-num { font-size: 0.9rem; font-weight: 800; color: var(--text); }
.cal-day.has-entries { background: var(--surface); box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.cal-day.has-entries .cal-day-num { color: var(--coral); }
.cal-day.today { background: linear-gradient(135deg, var(--coral), var(--orange)); }
.cal-day.today .cal-day-num { color: white; }
.cal-day.selected { box-shadow: 0 0 0 2px var(--coral); }
.cal-day:active { transform: scale(0.9); }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--teal); margin-top: 2px; }

/* === Onboarding === */
.onboarding {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100dvh; padding: var(--sp-xl) var(--sp-md);
  background: linear-gradient(160deg, #FFF8F0 0%, #FFE8D6 50%, #FFD6F0 100%);
  text-align: center; gap: var(--sp-md);
}
.onboarding-emoji { font-size: 4rem; animation: wiggle 2s ease-in-out infinite; }
.onboarding-title { font-family: var(--font-display); font-size: 2.5rem; color: var(--text); }
.onboarding-sub { font-size: 1rem; color: var(--text-muted); font-weight: 600; max-width: 300px; }
.onboarding-card {
  background: var(--surface); border-radius: var(--r-xl); padding: var(--sp-xl);
  box-shadow: var(--shadow-lg); width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: var(--sp-md);
  animation: bounce-in var(--t-slow) var(--ease-bounce) both;
}
.field-label { font-size: 0.8rem; font-weight: 900; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 4px; text-align: left; }
.field-input {
  width: 100%; padding: 12px var(--sp-md); border: 2px solid var(--border);
  border-radius: var(--r-md); font-size: 1rem; font-weight: 700;
  background: var(--surface-alt); color: var(--text); font-family: var(--font-body);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.field-input:focus { border-color: var(--coral); box-shadow: 0 0 0 3px rgba(255,107,107,0.15); outline: none; }
.targets-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-sm); }
.primary-btn {
  width: 100%; padding: var(--sp-md); border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--coral), var(--orange));
  color: white; font-family: var(--font-display); font-size: 1.3rem;
  box-shadow: 0 4px 20px rgba(255,107,107,0.4);
  transition: transform var(--t-fast) var(--ease-bounce), box-shadow var(--t-fast);
}
.primary-btn:active { transform: scale(0.97); box-shadow: 0 2px 10px rgba(255,107,107,0.25); }
.skip-btn { color: var(--text-muted); font-size: 0.85rem; font-weight: 700; background: none; border: none; cursor: pointer; }

/* === Settings === */
.settings-section { padding: var(--sp-md); }
.settings-group {
  background: var(--surface); border-radius: var(--r-lg);
  border: 2px solid var(--border); overflow: hidden; margin-bottom: var(--sp-md);
}
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-md); border-bottom: 1px solid var(--border); gap: var(--sp-md);
}
.settings-row:last-child { border-bottom: none; }
.settings-label { font-weight: 800; font-size: 0.95rem; color: var(--text); }
.settings-desc { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.settings-input {
  width: 90px; text-align: right; border: 2px solid var(--border);
  border-radius: var(--r-md); padding: 6px 10px; font-weight: 800;
  font-family: var(--font-body); font-size: 0.9rem; background: var(--surface-alt);
  color: var(--text); transition: border-color var(--t-fast);
}
.settings-input:focus { border-color: var(--coral); outline: none; }
.section-title {
  font-size: 0.72rem; font-weight: 900; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: var(--sp-sm);
}

/* === Empty States === */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: var(--sp-2xl) var(--sp-lg);
  text-align: center; gap: var(--sp-sm);
}
.empty-emoji { font-size: 3.5rem; animation: wiggle 3s ease-in-out infinite; }
.empty-title { font-family: var(--font-display); font-size: 1.5rem; color: var(--text); }
.empty-sub { font-size: 0.9rem; color: var(--text-muted); font-weight: 600; max-width: 260px; }

/* === Toast Notifications === */
.toast-container { position: fixed; bottom: calc(var(--nav-h) + 12px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  background: var(--text); color: white; padding: 10px 20px;
  border-radius: var(--r-full); font-weight: 800; font-size: 0.9rem;
  box-shadow: var(--shadow-lg); animation: bounce-in var(--t-normal) var(--ease-bounce) both;
  white-space: nowrap; display: flex; align-items: center; gap: 8px;
}
.toast.success { background: var(--teal); }
.toast.error   { background: var(--coral); }

/* === Spinner === */
.spinner {
  width: 32px; height: 32px; border: 3px solid var(--border);
  border-top-color: var(--coral); border-radius: 50%;
  animation: spin 0.7s linear infinite; margin: 0 auto;
}

/* === Confetti Particle === */
.confetti-particle {
  position: fixed; width: 8px; height: 8px; border-radius: 2px;
  pointer-events: none; z-index: 999;
  animation: confetti-fall 0.9s ease-out forwards;
}
