/* ============================================================
   DIETA PWA – Modern Apple iOS Design System
   ============================================================ */

:root {
  --app-bg: #F2F2F7;
  --card-bg: #FFFFFF;
  --card-border: rgba(0, 0, 0, 0.05);
  --text-primary: #1C1C1E;
  --text-secondary: #8E8E93;
  --text-muted: #A1A1A6;
  
  --accent: #007AFF;
  --accent-hover: #0062CC;
  --accent-light: #E5F1FF;
  --accent-glow: rgba(0, 122, 255, 0.2);

  --success: #34C759;
  --success-bg: rgba(52, 199, 89, 0.12);
  --warning: #FF9500;
  --warning-bg: rgba(255, 149, 0, 0.12);
  --danger: #FF3B30;
  --danger-bg: rgba(255, 59, 48, 0.1);
  --purple: #AF52DE;
  --purple-bg: rgba(175, 82, 222, 0.1);

  --lunch-bg: #FFF8EB;
  --lunch-border: #FFE2AF;
  --lunch-text: #8F5200;

  --dinner-bg: #EEF2FF;
  --dinner-border: #C7D2FE;
  --dinner-text: #3730A3;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
  --radius-full: 9999px;

  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
  --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.09);
  --shadow-glow: 0 8px 24px var(--accent-glow);
}

@media (prefers-color-scheme: dark) {
  :root {
    --app-bg: #000000;
    --card-bg: #1C1C1E;
    --card-border: rgba(255, 255, 255, 0.08);
    --text-primary: #FFFFFF;
    --text-secondary: #8E8E93;
    --text-muted: #636366;

    --accent-light: rgba(0, 122, 255, 0.2);
    --lunch-bg: #2C2214;
    --lunch-border: #4A391F;
    --lunch-text: #FFB340;

    --dinner-bg: #1A1F36;
    --dinner-border: #2C355E;
    --dinner-text: #A5B4FC;

    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
  }
}

/* ── Reset & Base ────────────────────────────────────────────── */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  font-family: var(--font-system);
  background-color: var(--app-bg);
  color: var(--text-primary);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}

body {
  padding-top: max(env(safe-area-inset-top), 12px);
  padding-bottom: max(calc(env(safe-area-inset-bottom) + 32px), 48px);
}

/* ── Layout Container ────────────────────────────────────────── */
.app-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Header & Navbar ─────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--app-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 10px 0 14px 0;
  border-bottom: 1px solid var(--card-border);
  margin-bottom: 16px;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 28px;
  line-height: 1;
}

.brand-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.1;
}

.brand-subtitle {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.streak-badge {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-sm);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.streak-fire {
  font-size: 16px;
  display: inline-block;
}

.streak-pop {
  animation: streakPopAnim 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes streakPopAnim {
  0% { transform: scale(1); }
  50% { transform: scale(1.4) rotate(-12deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ── Segmented Control / Navigation Tabs ────────────────────── */
.tabs-wrapper {
  position: sticky;
  top: 65px;
  z-index: 30;
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
  padding: 4px 0;
}

.segmented-control {
  background: rgba(142, 142, 147, 0.16);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius-md);
  padding: 3px;
  display: flex;
  gap: 2px;
  width: 100%;
  max-width: 500px;
}

.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: calc(var(--radius-md) - 3px);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--card-bg);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* ── Tab Views ───────────────────────────────────────────────── */
.tab-content {
  display: none;
  animation: fadeIn 0.25s ease-out;
}

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

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

/* ── Hero / Today Section ────────────────────────────────────── */
.hero-section {
  margin-bottom: 24px;
}

.section-headline {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── iOS Card Design ─────────────────────────────────────────── */
.ios-card {
  background: var(--card-bg);
  border-radius: var(--radius-xl);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.hero-glow {
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-glow);
  background: linear-gradient(180deg, var(--card-bg) 0%, var(--accent-light) 100%);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.badges-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge-sheet {
  background: rgba(142, 142, 147, 0.14);
  color: var(--text-secondary);
}

.badge-category {
  background: var(--accent-light);
  color: var(--accent);
}

.badge-date {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

/* ── Meal Slots ──────────────────────────────────────────────── */
.meal-slots {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.meal-slot {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
}

.meal-slot-lunch {
  background: var(--lunch-bg);
  border-color: var(--lunch-border);
}

.meal-slot-dinner {
  background: var(--dinner-bg);
  border-color: var(--dinner-border);
}

.meal-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.meal-slot-lunch .meal-label { color: var(--lunch-text); }
.meal-slot-dinner .meal-label { color: var(--dinner-text); }

.meal-desc {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.35;
}

/* ── Buttons & Interactions ─────────────────────────────────── */
.btn-primary {
  width: 100%;
  border: none;
  background: var(--accent);
  color: white;
  padding: 13px 18px;
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 14px;
  box-shadow: 0 4px 14px var(--accent-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.btn-primary:active {
  transform: scale(0.97);
  background: var(--accent-hover);
}

.btn-secondary {
  width: 100%;
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--text-primary);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
}

.btn-secondary:active {
  transform: scale(0.98);
  background: rgba(0, 0, 0, 0.05);
}

.btn-danger-ghost {
  border: none;
  background: transparent;
  color: var(--danger);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease;
}

.btn-danger-ghost:active {
  background: var(--danger-bg);
}

.btn-surprise {
  background: linear-gradient(135deg, #AF52DE 0%, #5856D6 100%);
  color: white;
  border: none;
  box-shadow: 0 4px 16px rgba(175, 82, 222, 0.3);
}

.btn-surprise:active {
  transform: scale(0.97);
  opacity: 0.95;
}

/* ── Grid of Cards ───────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 640px) {
  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Search Input ────────────────────────────────────────────── */
.search-box {
  position: relative;
  margin-bottom: 16px;
}

.search-input {
  width: 100%;
  padding: 14px 44px 14px 44px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.search-icon-left {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 16px;
}

.search-clear-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: rgba(142, 142, 147, 0.2);
  color: var(--text-secondary);
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  font-size: 12px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.search-clear-btn.visible {
  display: flex;
}

/* ── Statistics View ─────────────────────────────────────────── */
.stats-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 16px 12px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-number {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  margin-top: 4px;
}

.category-bars {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.category-bar-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.category-bar-header {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.category-bar-track {
  height: 10px;
  background: rgba(142, 142, 147, 0.16);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.category-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--accent);
  transition: width 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── History Table & Settings ────────────────────────────────── */
.history-feed {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-date {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
}

.history-meal-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

.history-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: var(--radius-sm);
}

.settings-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  padding: 20px;
  margin-bottom: 20px;
}

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Empty State ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.6;
}

.empty-state-text {
  font-size: 14px;
  font-weight: 500;
}

/* ── Toast Notifications ─────────────────────────────────────── */
.toast {
  position: fixed;
  top: max(env(safe-area-inset-top), 16px);
  left: 50%;
  transform: translateX(-50%) translateY(-140px);
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-lg);
  padding: 12px 22px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  z-index: 100;
  transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast-icon {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: var(--success);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
}

/* ── Canvas Confetti ─────────────────────────────────────────── */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 99;
}
