/* =========================================================================
   Protocolo de la Remolacha — Sistema de diseño
   Health-Tech premium · Accesibilidad Sénior (50+)
   - Tipografía base 18px (mín. 16px) · Títulos 22px+
   - Botones mínimo 48px de altura
   - Verde sálvia (salud/éxito) · Off-white · Bordó/Remolacha (acción)
   ========================================================================= */

:root {
  /* Colores */
  --bg: #F4F1EA;            /* off-white cálido */
  --surface: #FFFFFF;
  --surface-2: #FBFAF6;

  --sage: #6E8B6A;          /* verde sálvia */
  --sage-dark: #4F6B4C;
  --sage-light: #E7EFE4;
  --sage-tint: #F1F6EF;

  --beet: #8E2C48;          /* bordó / remolacha (acción) */
  --beet-dark: #6F2038;
  --beet-light: #F6E7EC;

  --text: #2B2724;
  --muted: #6E6A64;
  --line: #E5E0D6;

  --danger: #B23A48;
  --warn: #C98A2B;

  /* Tipografía */
  --fs-base: 18px;
  --fs-sm: 16px;
  --fs-lg: 20px;
  --fs-title: 24px;
  --fs-hero: 28px;

  /* Medidas */
  --tap: 56px;              /* altura mínima de toque (> 48px) */
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 6px 20px rgba(43, 39, 36, 0.08);
  --shadow-lg: 0 12px 32px rgba(43, 39, 36, 0.14);
  --maxw: 560px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

img { max-width: 100%; }

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; }
h1 { font-size: var(--fs-hero); }
h2 { font-size: var(--fs-title); }
h3 { font-size: var(--fs-lg); }
p { margin: 0 0 1em; }

.app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
}

/* --- Utilidades --------------------------------------------------------- */
.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--muted); }
.stack > * + * { margin-top: 16px; }

/* --- Botones ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: var(--fs-lg);
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
  text-align: center;
}
.btn:active { transform: scale(.985); }

.btn-primary { background: var(--beet); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--beet-dark); }

.btn-secondary {
  background: var(--surface);
  color: var(--beet);
  border: 2px solid var(--beet);
}
.btn-secondary:hover { background: var(--beet-light); }

.btn-sage { background: var(--sage); color: #fff; box-shadow: var(--shadow); }
.btn-sage:hover { background: var(--sage-dark); }

.btn-ghost {
  background: var(--sage-light);
  color: var(--sage-dark);
}

/* --- Campos ------------------------------------------------------------- */
.field { margin-bottom: 16px; text-align: left; }
.field label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}
.field input, .field select {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 16px;
  font-size: var(--fs-base);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--sage);
  box-shadow: 0 0 0 3px var(--sage-light);
}

.form-error {
  color: var(--danger);
  font-size: var(--fs-sm);
  font-weight: 600;
  min-height: 1.2em;
  margin: 4px 0 12px;
}

/* =========================================================================
   ONBOARDING / AUTH
   ========================================================================= */
.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 28px 22px calc(28px + env(safe-area-inset-bottom));
}
.auth-screen { justify-content: center; gap: 8px; }

.brand {
  text-align: center;
  margin-bottom: 18px;
}
.brand .logo {
  width: 88px; height: 88px;
  margin: 0 auto 14px;
  display: block;
}
.brand h1 { color: var(--beet); }
.brand .tagline { color: var(--sage-dark); font-weight: 600; }

.welcome-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
  border-left: 6px solid var(--beet);
}
.welcome-card p { margin: 0; font-size: var(--fs-base); }

.auth-actions { display: grid; gap: 14px; }

.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow);
}
.auth-card h2 { color: var(--beet); text-align: center; }

.link-btn {
  background: none;
  border: none;
  color: var(--sage-dark);
  font-size: var(--fs-base);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  width: 100%;
  min-height: var(--tap);
}

/* =========================================================================
   APP SHELL — encabezado, vistas, bottom nav
   ========================================================================= */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(135deg, var(--sage) 0%, var(--sage-dark) 100%);
  color: #fff;
  padding: calc(16px + env(safe-area-inset-top)) 20px 16px;
  box-shadow: var(--shadow);
}
.app-header .greeting { font-size: var(--fs-sm); opacity: .92; margin: 0; }
.app-header .gami {
  font-size: var(--fs-lg);
  font-weight: 800;
  margin: 4px 0 0;
}

.view {
  padding: 20px 18px 110px;
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to {opacity:1; transform:none;} }

.section-title {
  color: var(--beet);
  margin: 6px 0 14px;
}
.section-intro { color: var(--muted); margin-top: -6px; }

/* Tarjetas grandes de acción (Inicio) */
.cta-grid { display: grid; gap: 16px; margin: 18px 0 26px; }
.cta-big {
  min-height: 84px;
  border: none;
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  font-size: var(--fs-lg);
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .08s ease;
  color: #fff;
}
.cta-big:active { transform: scale(.99); }
.cta-big .ico { font-size: 30px; line-height: 1; }
.cta-big.beet { background: var(--beet); }
.cta-big.sage { background: var(--sage); }
.cta-big.outline {
  background: var(--surface);
  color: var(--beet);
  border: 2px solid var(--beet);
  box-shadow: var(--shadow);
}

/* Tarjeta genérica */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h3 { color: var(--beet); }

/* Tracker de glucemia */
.tracker-row { display: flex; gap: 12px; align-items: flex-end; }
.tracker-row .field { flex: 1; margin-bottom: 0; }
.tracker-row .btn { width: auto; padding: 14px 22px; white-space: nowrap; }

.glucose-stat { display: flex; gap: 14px; margin-top: 8px; flex-wrap: wrap; }
.stat-pill {
  flex: 1;
  min-width: 120px;
  background: var(--sage-tint);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: center;
}
.stat-pill .num { font-size: var(--fs-title); font-weight: 800; color: var(--sage-dark); display:block; }
.stat-pill .lbl { font-size: var(--fs-sm); color: var(--muted); }

/* Gráfico */
.chart-wrap { margin-top: 10px; }
.chart-empty {
  text-align: center;
  color: var(--muted);
  padding: 26px 10px;
  background: var(--sage-tint);
  border-radius: var(--radius-sm);
}
svg.chart { width: 100%; height: 220px; display: block; }

/* Progreso / gamificación */
.progress-bar {
  height: 14px;
  background: var(--sage-light);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 6px;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: var(--beet);
  border-radius: 999px;
  transition: width .4s ease;
}

/* =========================================================================
   TAB 2 — Protocolo
   ========================================================================= */
.proto-hero {
  background: linear-gradient(135deg, var(--beet) 0%, var(--beet-dark) 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.proto-hero h2 { color: #fff; }
.proto-hero p { margin: 0; opacity: .95; }

.ingredients-list { list-style: none; margin: 0; padding: 0; }
.ingredients-list li {
  padding: 12px 6px 12px 38px;
  position: relative;
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-base);
}
.ingredients-list li:last-child { border-bottom: none; }
.ingredients-list li::before {
  content: "•";
  color: var(--beet);
  font-size: 26px;
  position: absolute;
  left: 10px; top: 6px;
}

/* Pasos como checklist */
.step {
  display: flex;
  gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
  align-items: flex-start;
  cursor: pointer;
}
.step:last-child { border-bottom: none; }
.step .check {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 3px solid var(--sage);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--sage-dark);
  background: var(--surface);
  font-size: var(--fs-base);
  transition: all .15s ease;
}
.step.done .check { background: var(--sage); color: #fff; border-color: var(--sage); }
.step.done .step-title { text-decoration: line-through; color: var(--muted); }
.step-body { flex: 1; }
.step-title { font-weight: 800; font-size: var(--fs-base); margin-bottom: 3px; }
.step-detail { color: var(--muted); font-size: var(--fs-sm); }

.tip-box {
  background: var(--sage-light);
  border-left: 6px solid var(--sage);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin-top: 16px;
}
.tip-box strong { color: var(--sage-dark); display: block; margin-bottom: 4px; }

/* =========================================================================
   TAB 3 — Biblioteca
   ========================================================================= */
.cat-block { margin-bottom: 26px; }
.cat-head {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px;
}
.cat-head .cat-ico {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--beet-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  flex: 0 0 auto;
}
.cat-head h3 { color: var(--beet); margin: 0; }
.cat-head .cat-desc { font-size: var(--fs-sm); color: var(--muted); }

.recipe-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  overflow: hidden;
}
.recipe-toggle {
  width: 100%;
  min-height: var(--tap);
  background: var(--surface);
  border: none;
  padding: 16px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: var(--fs-base);
  font-weight: 700;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.recipe-toggle .chev { color: var(--beet); font-size: 22px; transition: transform .2s ease; flex: 0 0 auto;}
.recipe-card.open .recipe-toggle .chev { transform: rotate(180deg); }
.recipe-body {
  padding: 0 18px 18px;
  border-top: 1px solid var(--line);
}
.recipe-body h4 {
  color: var(--sage-dark);
  font-size: var(--fs-sm);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 16px 0 8px;
}
.recipe-body ul { margin: 0; padding-left: 22px; }
.recipe-body ol { margin: 0; padding-left: 22px; }
.recipe-body li { margin-bottom: 8px; }

/* =========================================================================
   TAB 4 — Recursos (Acordeón)
   ========================================================================= */
.accordion-item {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
.accordion-head {
  width: 100%;
  min-height: 68px;
  background: var(--surface);
  border: none;
  padding: 16px 18px;
  display: flex; align-items: center; gap: 14px;
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.accordion-head .acc-ico {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--sage-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex: 0 0 auto;
}
.accordion-head .chev { margin-left: auto; color: var(--sage); font-size: 22px; transition: transform .2s ease; }
.accordion-item.open .accordion-head .chev { transform: rotate(180deg); }
.accordion-body { padding: 0 18px 18px; border-top: 1px solid var(--line); }
.accordion-body p { margin: 14px 0 0; }
.accordion-body p:first-child { font-weight: 600; }

/* =========================================================================
   BOTTOM NAV
   ========================================================================= */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: var(--maxw);
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 18px rgba(43,39,36,.07);
}
.nav-btn {
  background: none;
  border: none;
  min-height: 64px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 700;
}
.nav-btn .nav-ico { font-size: 24px; line-height: 1; }
.nav-btn.active { color: var(--beet); }
.nav-btn.active .nav-ico { transform: translateY(-1px); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 88px;
  transform: translateX(-50%) translateY(20px);
  background: var(--sage-dark);
  color: #fff;
  padding: 14px 22px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all .3s ease;
  z-index: 50;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Encabezado interno de cuenta */
.account-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
