/* ===== FOCA NO PRATO — DESIGN SYSTEM =====
   Versão 2.1 — Fix 3: CSS unificado, sem duplicação com index.html
   
   VARIÁVEIS CANÔNICAS (use sempre estes nomes):
     --green-light  → verde claro (botões, gradientes)
     --radius       → border-radius padrão (16px)
     --radius-sm    → border-radius pequeno (10px)
     --nav-h        → altura da bottom nav (64px)
     --top-h        → altura da topbar (56px)
     --text-light   → texto secundário/cinza
   
   ALIASES DE COMPATIBILIDADE (mantidos para não quebrar código legado):
     --green2, --r, --r2, --nav, --top, --text2
   ============================================== */

/* ===== RESET ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* ===== VARIÁVEIS ===== */
:root {
  /* Cores principais */
  --green: #27AE60;
  --green-light: #2ECC71;
  --green-dark: #1E8449;
  --green-bg: #E8F8F0;
  --orange: #E67E22;
  --red: #E74C3C;
  --blue: #3498DB;
  --yellow: #F1C40F;

  /* Neutros */
  --gray: #95A5A6;
  --gray-light: #F4F6F7;
  --gray-mid: #ECF0F1;
  --text: #2C3E50;
  --text-light: #7F8C8D;
  --white: #FFFFFF;

  /* Espaçamento e forma */
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --nav-h: 64px;
  --top-h: 56px;

  /* ── Aliases de compatibilidade ──────────────────────────────
     Mantidos para que código legado que use --green2, --r, etc.
     continue funcionando sem quebrar. NÃO use estes em código novo.
     Use sempre os nomes canônicos acima.
  ─────────────────────────────────────────────────────────── */
  --green2: var(--green-light);   /* alias → --green-light */
  --r: var(--radius);             /* alias → --radius      */
  --r2: var(--radius-sm);         /* alias → --radius-sm   */
  --nav: var(--nav-h);            /* alias → --nav-h       */
  --top: var(--top-h);            /* alias → --top-h       */
  --text2: var(--text-light);     /* alias → --text-light  */
}

/* ===== BASE ===== */
html, body {
  height: 100%;
  font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  background: #E8F5E9;
  color: var(--text);
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: #F0F4F0;
  box-shadow: 0 0 40px rgba(0,0,0,0.1);
  overflow: hidden;
}

/* ===== TOPBAR ===== */
.topbar {
  height: var(--top-h);
  background: var(--white);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  border-bottom: 1px solid var(--gray-mid);
  flex-shrink: 0;
  z-index: 10;
}
.topbar h2 { flex: 1; font-size: 18px; font-weight: 800; }
.btn-back {
  background: none; border: none; font-size: 22px;
  cursor: pointer; padding: 4px 8px; border-radius: 8px;
  color: var(--text); font-family: inherit;
}
.btn-icon {
  background: none; border: none; font-size: 24px;
  cursor: pointer; padding: 4px; font-family: inherit;
}
.hidden { display: none !important; }

/* ===== PAGES ===== */
.pages { flex: 1; position: relative; overflow: hidden; }
.page {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 16px calc(var(--nav-h) + 16px);
  display: none;
  background: #F0F4F0;
  -webkit-overflow-scrolling: touch;
}
.page.active { display: block; }

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  height: var(--nav-h);
  background: var(--white);
  display: flex;
  align-items: center;
  border-top: 1px solid var(--gray-mid);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 4px;
  font-family: inherit;
}
.nav-icon { font-size: 22px; }
.nav-label { font-size: 10px; color: var(--gray); font-weight: 600; }
.nav-btn.active .nav-label { color: var(--green); font-weight: 800; }

/* ===== CARDS ===== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-weight: 700;
  font-size: 14px;
}
.card-title { font-size: 16px; font-weight: 800; margin-bottom: 14px; }
.section-label { font-size: 13px; color: var(--text-light); margin-bottom: 12px; }

/* ===== HERO ===== */
.hero-card {
  background: linear-gradient(135deg, #27AE60, #1ABC9C);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  box-shadow: 0 4px 20px rgba(39,174,96,0.3);
}
.hero-greeting { font-size: 13px; opacity: 0.9; }
.hero-text h2 { font-size: 22px; font-weight: 800; margin: 2px 0; }
.hero-sub { font-size: 12px; opacity: 0.8; }
.hero-emoji { font-size: 52px; }

/* ===== ÁGUA ===== */
.water-progress-wrap { margin-bottom: 12px; }
.water-progress-bar-bg {
  height: 14px;
  background: var(--gray-mid);
  border-radius: 7px;
  overflow: hidden;
  margin-bottom: 6px;
}
.water-progress-bar-fill {
  height: 100%;
  border-radius: 7px;
  background: var(--blue);
  transition: width 0.4s ease, background 0.3s;
  width: 0%;
}
.water-progress-label { font-size: 12px; color: var(--text-light); text-align: center; }
.water-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.water-btn {
  background: #EBF5FB;
  border: 2px solid #AED6F1;
  border-radius: 10px;
  padding: 10px 4px;
  font-size: 12px;
  font-weight: 700;
  color: #2980B9;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
  font-family: inherit;
}
.water-btn span { font-size: 18px; }
.water-btn:active { background: #AED6F1; transform: scale(0.95); }
.water-custom-row { display: flex; gap: 8px; align-items: center; }
.water-custom-row input {
  flex: 1; padding: 8px 12px;
  border: 2px solid var(--gray-mid);
  border-radius: 10px; font-size: 14px;
  outline: none; min-width: 0; font-family: inherit;
}
.water-custom-row input:focus { border-color: var(--blue); }

/* ===== QUICK GRID ===== */
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.quick-btn {
  background: var(--white);
  border: none;
  border-radius: var(--radius);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
  font-family: inherit;
}
.quick-btn:active { transform: scale(0.96); }
.quick-icon { font-size: 32px; }
.quick-btn span:last-child { font-size: 13px; font-weight: 700; }

/* ===== MEAL QUICK ===== */
.meal-quick-list { display: flex; flex-direction: column; gap: 8px; }
.meal-quick-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--gray-mid);
}
.meal-quick-item:last-child { border-bottom: none; }
.meal-quick-icon { font-size: 22px; width: 36px; text-align: center; }
.meal-quick-name { font-size: 13px; font-weight: 700; }
.meal-quick-time { font-size: 11px; color: var(--text-light); }
.meal-quick-check { font-size: 20px; cursor: pointer; margin-left: auto; }

/* ===== WEEK SELECTOR ===== */
.week-selector { display: flex; gap: 10px; margin-bottom: 14px; }
.week-btn {
  flex: 1; padding: 10px;
  border: 2px solid var(--gray-mid);
  background: var(--white);
  border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 700;
  cursor: pointer; color: var(--text-light);
  transition: all 0.2s; font-family: inherit;
}
.week-btn.active { border-color: var(--green); background: var(--green-bg); color: var(--green-dark); }

/* ===== MEAL PLAN ===== */
.meal-section {
  background: var(--white);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.meal-section-header {
  padding: 14px 16px; display: flex; align-items: center;
  gap: 10px; cursor: pointer; user-select: none;
}
.meal-section-icon { font-size: 24px; }
.meal-section-title { font-size: 15px; font-weight: 800; }
.meal-section-time { font-size: 12px; color: var(--text-light); }
.meal-section-arrow { font-size: 16px; color: var(--gray); transition: transform 0.2s; margin-left: auto; }
.meal-section.open .meal-section-arrow { transform: rotate(90deg); }
.meal-section-body { display: none; padding: 0 16px 16px; }
.meal-section.open .meal-section-body { display: block; }
.meal-option { background: var(--gray-light); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 10px; }
.meal-option-title { font-size: 13px; font-weight: 800; color: var(--green-dark); margin-bottom: 8px; }
.meal-ingredient {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; border-bottom: 1px solid rgba(0,0,0,0.05); font-size: 13px;
}
.meal-ingredient:last-child { border-bottom: none; }
.meal-ingredient-qty {
  font-size: 12px; color: var(--text-light);
  background: white; padding: 2px 8px;
  border-radius: 20px; flex-shrink: 0; margin-left: 8px;
}
.meal-how-to {
  margin-top: 10px; padding: 10px;
  background: #FFF9E6; border-radius: var(--radius-sm);
  border-left: 3px solid var(--yellow);
  font-size: 12px; color: #7D6608; line-height: 1.5;
}
.meal-how-to strong { display: block; margin-bottom: 4px; }

/* ===== SEARCH ===== */
.search-bar { margin-bottom: 12px; }
.search-bar input {
  width: 100%; padding: 12px 16px;
  border: 2px solid var(--gray-mid);
  border-radius: var(--radius-sm);
  font-size: 14px; background: var(--white);
  outline: none; font-family: inherit;
}
.search-bar input:focus { border-color: var(--green); }

/* ===== CATEGORY TABS ===== */
.category-tabs {
  display: flex; gap: 8px; overflow-x: auto;
  margin-bottom: 12px; padding-bottom: 4px; scrollbar-width: none;
}
.category-tabs::-webkit-scrollbar { display: none; }
.cat-tab {
  flex-shrink: 0; padding: 8px 16px;
  border: 2px solid var(--gray-mid);
  background: var(--white); border-radius: 20px;
  font-size: 13px; font-weight: 700;
  cursor: pointer; color: var(--text-light);
  white-space: nowrap; font-family: inherit;
}
.cat-tab.active { border-color: var(--green); background: var(--green-bg); color: var(--green-dark); }

/* ===== FOOD LIST ===== */
.food-group { margin-bottom: 14px; }
.food-group-title {
  font-size: 12px; font-weight: 700; color: var(--text-light);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 8px; padding-left: 4px;
}
.food-item {
  background: var(--white); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow); cursor: pointer;
}
.food-item:active { opacity: 0.8; }
.food-item-icon { font-size: 28px; width: 40px; text-align: center; flex-shrink: 0; }
.food-item-name { font-size: 14px; font-weight: 700; }
.food-item-qty { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.food-item-kcal {
  font-size: 13px; font-weight: 800; color: var(--green);
  background: var(--green-bg); padding: 4px 10px;
  border-radius: 20px; margin-left: auto; flex-shrink: 0;
}

/* ===== SUBSTITUIÇÕES ===== */
.sub-group { margin-bottom: 14px; }
.sub-group-title {
  font-size: 14px; font-weight: 800; margin-bottom: 10px;
  padding: 8px 12px; background: var(--green-bg);
  border-radius: var(--radius-sm); border-left: 4px solid var(--green);
}
.sub-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: var(--white);
  border-radius: var(--radius-sm); margin-bottom: 6px;
  box-shadow: var(--shadow); gap: 8px;
}
.sub-item-name { font-size: 13px; font-weight: 600; flex: 1; }
.sub-item-qty { font-size: 12px; color: var(--text-light); flex-shrink: 0; }

/* ===== DOCINHOS ===== */
.info-banner {
  background: linear-gradient(135deg, #F39C12, #E67E22);
  color: white; border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
  font-size: 13px; line-height: 1.5;
}
.docinho-week-tracker {
  background: var(--white); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.docinho-week-title { font-size: 14px; font-weight: 700; margin-bottom: 12px; }
.docinho-dots { display: flex; gap: 10px; }
.docinho-dot {
  width: 40px; height: 40px; border-radius: 50%;
  border: 2px solid var(--gray-mid);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; cursor: pointer; transition: all 0.2s;
  color: var(--gray-mid);
}
.docinho-dot.used { background: var(--orange); border-color: var(--orange); color: white; }
.docinho-item {
  background: var(--white); border-radius: var(--radius-sm);
  padding: 14px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow); cursor: pointer;
}
.docinho-icon { font-size: 32px; width: 44px; text-align: center; flex-shrink: 0; }
.docinho-name { font-size: 14px; font-weight: 700; }
.docinho-qty { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.docinho-kcal { font-size: 14px; font-weight: 800; color: var(--orange); margin-left: auto; flex-shrink: 0; }

/* ===== HÁBITOS ===== */
.habit-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--gray-mid);
  cursor: pointer; user-select: none;
}
.habit-item:last-child { border-bottom: none; }
.habit-check {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--gray-mid);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0; transition: all 0.2s;
}
.habit-item.done .habit-check { background: var(--green); border-color: var(--green); color: white; }
.habit-icon { font-size: 22px; flex-shrink: 0; }
.habit-text { flex: 1; font-size: 14px; font-weight: 600; }
.habit-item.done .habit-text { text-decoration: line-through; color: var(--text-light); }
.streak-box {
  display: flex; align-items: center; gap: 12px; padding: 12px;
  background: linear-gradient(135deg, #F39C12, #E67E22);
  border-radius: var(--radius-sm); color: white;
}
.streak-num { font-size: 36px; font-weight: 800; }
.streak-label { font-size: 13px; opacity: 0.9; }

/* ===== PROGRESSO ===== */
.weight-input-row { display: flex; gap: 10px; margin-bottom: 14px; }
.weight-input-row input {
  flex: 1; padding: 12px;
  border: 2px solid var(--gray-mid);
  border-radius: var(--radius-sm);
  font-size: 16px; outline: none; min-width: 0; font-family: inherit;
}
.weight-input-row input:focus { border-color: var(--green); }
.weight-entry {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--gray-mid); gap: 8px;
}
.weight-entry:last-child { border-bottom: none; }
.weight-entry-date { font-size: 13px; color: var(--text-light); }
.weight-entry-val { font-size: 16px; font-weight: 800; }
.weight-entry-diff { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 20px; flex-shrink: 0; }
.weight-entry-diff.down { background: var(--green-bg); color: var(--green-dark); }
.weight-entry-diff.up { background: #FDEDEC; color: var(--red); }
.week-stat {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--gray-mid);
  font-size: 14px; gap: 8px;
}
.week-stat:last-child { border-bottom: none; }
.week-stat-val { font-weight: 800; color: var(--green); flex-shrink: 0; }
.achievement { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--gray-mid); }
.achievement:last-child { border-bottom: none; }
.achievement-icon { font-size: 28px; flex-shrink: 0; }
.achievement-name { font-size: 14px; font-weight: 700; }
.achievement-desc { font-size: 12px; color: var(--text-light); }
.achievement.locked { opacity: 0.4; filter: grayscale(1); }

/* ===== HISTÓRICO ===== */
.history-section { margin-bottom: 18px; }
.history-title {
  font-size: 12px; font-weight: 700; color: var(--text-light);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 10px;
}
.history-grid { display: flex; gap: 6px; align-items: flex-end; height: 90px; margin-bottom: 6px; }
.history-day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; height: 100%; justify-content: flex-end; }
.history-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.history-bar { width: 100%; border-radius: 4px 4px 0 0; min-height: 4px; }
.history-day-val { font-size: 10px; font-weight: 700; }
.history-day-label { font-size: 9px; color: var(--text-light); text-align: center; }
.history-table { border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--gray-mid); }
.history-table-header {
  display: grid; grid-template-columns: 2fr 1fr 1fr 0.5fr;
  padding: 8px 12px; background: var(--gray-light);
  font-size: 11px; font-weight: 700; color: var(--text-light); text-transform: uppercase;
}
.history-table-row {
  display: grid; grid-template-columns: 2fr 1fr 1fr 0.5fr;
  padding: 10px 12px; font-size: 12px;
  border-top: 1px solid var(--gray-mid); cursor: pointer;
}
.history-table-row:active { background: var(--gray-light); }
.history-table-day { font-weight: 700; }

/* ===== PERFIL ===== */
.profile-header {
  display: flex; align-items: center; gap: 14px;
  background: var(--white); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow); overflow: hidden;
}
.profile-avatar { font-size: 48px; flex-shrink: 0; }
.profile-header h3 { font-size: 18px; font-weight: 800; }
.profile-header p { font-size: 13px; color: var(--text-light); }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 700; color: var(--text-light); margin-bottom: 6px; }
.form-group input, .form-group select {
  width: 100%; padding: 12px;
  border: 2px solid var(--gray-mid);
  border-radius: var(--radius-sm);
  font-size: 14px; outline: none;
  background: var(--white); font-family: inherit;
}
.form-group input:focus, .form-group select:focus { border-color: var(--green); }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--gray-mid);
  cursor: pointer; font-size: 14px; font-weight: 600; gap: 8px;
}
.settings-row:last-child { border-bottom: none; }
.settings-row.danger { color: var(--red); }
.settings-row span:first-child { flex: 1; }
.toggle {
  width: 44px; height: 24px; background: var(--gray-mid);
  border-radius: 12px; position: relative;
  transition: background 0.2s; flex-shrink: 0;
}
.toggle::after {
  content: ''; position: absolute;
  width: 20px; height: 20px; background: white;
  border-radius: 50%; top: 2px; left: 2px;
  transition: transform 0.2s; box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}
.toggle.on { background: var(--green); }
.toggle.on::after { transform: translateX(20px); }

/* ===== ACCOUNT PANEL ===== */
#accountContent { overflow: hidden; width: 100%; }
#accountContent input { width: 100%; font-family: inherit; }
#accountContent button { font-family: inherit; }

/* ===== DIET BANNER ===== */
.diet-banner { border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 12px; }
.diet-banner-setup { background: #FEF9E7; border-left: 4px solid var(--yellow); cursor: pointer; font-size: 13px; }
.diet-banner-soon { background: #FEF9E7; border-left: 4px solid var(--orange); font-size: 13px; }
.diet-banner-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; font-size: 13px; font-weight: 700; }
.diet-day-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 800; color: white; }
.diet-progress-bar-wrap { height: 6px; background: rgba(0,0,0,0.08); border-radius: 3px; overflow: hidden; margin-bottom: 4px; }
.diet-progress-bar { height: 100%; border-radius: 3px; }
.diet-banner-sub { font-size: 12px; color: var(--text-light); }

/* ===== BOTÕES ===== */
.btn-primary {
  background: linear-gradient(135deg, var(--green), var(--green-light));
  color: white; border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px; font-size: 14px; font-weight: 800;
  cursor: pointer; box-shadow: 0 3px 12px rgba(39,174,96,0.3);
  font-family: inherit;
}
.btn-primary:active { opacity: 0.9; }
.btn-primary.full-width { width: 100%; }
/* Alias legado: .fw → .full-width */
.btn-primary.fw { width: 100%; }
.btn-sm {
  background: var(--green-bg); color: var(--green-dark);
  border: none; border-radius: 20px;
  padding: 5px 12px; font-size: 12px; font-weight: 700;
  cursor: pointer; font-family: inherit;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--white);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px; width: 100%;
  max-width: 480px; max-height: 80vh; overflow-y: auto;
}
.modal-title { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.modal-sub { font-size: 13px; color: var(--text-light); margin-bottom: 16px; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-light); }
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--gray-mid); border-radius: 4px; }

/* ===== RESPONSIVE ===== */
@media (min-width: 480px) {
  body { background: #D5E8D4; }
}