/* Objetivo 90 — ETAPA 2: carcasa visual. Mobile-first, sin dependencias. */
:root {
  /* Colores base */
  --bg: #f6f4ee;
  --card: #ffffff;
  --ink: #1d2420;
  --muted: #6b7280;
  --brand: #1b7a5a;
  --brand-soft: #e3f0e9;
  --line: #e7e2d6;

  /* Colores semánticos */
  --success: #1b7a5a;
  --warning: #f59e0b;
  --error: #b3261e;
  --info: #3b82f6;

  /* Espaciado */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;

  /* Tipografía */
  --font-xs: 0.75rem;
  --font-sm: 0.875rem;
  --font-base: 1rem;
  --font-lg: 1.125rem;
  --font-xl: 1.25rem;
  --font-2xl: 1.5rem;
  --font-3xl: 1.875rem;

  /* Bordes */
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.12);
  --shadow-brand: 0 2px 8px rgba(27, 122, 90, 0.15);

  /* Layout */
  --tabbar-h: 64px;
  --header-h: 56px;
  --max-width-sm: 560px;
  --max-width-md: 720px;
  --max-width-lg: 960px;

  /* Transiciones */
  --transition-fast: 0.15s ease;
  --transition-base: 0.3s ease;
  --transition-slow: 0.5s ease;

  transition: background-color var(--transition-base), color var(--transition-base);
}

/* Modo oscuro */
[data-theme="dark"] {
  --bg: #1a1a1a;
  --card: #2d2d2d;
  --ink: #e5e5e5;
  --muted: #a0a0a0;
  --brand: #4ec88a;
  --brand-soft: #1b7a5a33;
  --line: #404040;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow-brand: 0 2px 8px rgba(78, 200, 138, 0.3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  font-size: var(--font-base);
}

h1 { font-size: var(--font-xl); margin: 0.4rem 0 0.2rem; font-weight: 700; }
h2 { font-size: var(--font-lg); margin: 0 0 0.6rem; font-weight: 600; }

/* Spinner global de carga (ETAPA 12) */
#global-spinner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--brand);
  z-index: 9999;
  transition: transform 0.3s ease;
  transform: translateY(-100%);
  box-shadow: 0 2px 8px rgba(27, 122, 90, 0.3);
}
#global-spinner.visible { transform: translateY(0); }
#global-spinner .spinner {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, var(--brand), transparent);
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Barra superior: solo marca en móvil, navegación en desktop */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  font-weight: 700;
  color: var(--brand);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topnav { display: none; gap: 16px; }
.topnav a {
  color: var(--ink);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
}
.topnav a:hover {
  background: var(--brand-soft);
  color: var(--brand);
}
.topnav a.active {
  color: var(--brand);
  font-weight: 700;
  background: var(--brand-soft);
}

.shell {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + 32px);
}

/* Animaciones de sección */
section[data-screen] {
  animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Animación de entrada para cards con stagger */
.card {
  animation: slideUp 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Micro-interacción: Ripple effect en botones */
.btn {
  position: relative;
  overflow: hidden;
}
.btn::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.6s ease, height 0.6s ease;
}
.btn:active::after {
  width: 300px;
  height: 300px;
}

/* Micro-interacción: Scale en cards al hacer click */
.card:active {
  transform: scale(0.98);
  transition: transform 0.1s ease;
}

/* Animación de skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--line) 25%, var(--brand-soft) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
}
@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Animación de pulsación para elementos importantes */
.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Animación de shake para errores */
.shake {
  animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}
@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Transición suave para cambios de tema */
* {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.greeting { margin: 0.2rem 0 0; color: var(--muted); }
.demo-note {
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--brand-soft);
  border-radius: 8px;
  padding: 6px 10px;
  display: inline-block;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: var(--space-lg);
  margin: var(--space-md) 0;
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--transition-fast), transform var(--transition-fast);
}
.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

/* Cards con iconos */
.card-icon {
  position: relative;
  padding-top: 44px;
}
.card-icon-wrapper {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  background: var(--brand-soft);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-icon-wrapper .icon {
  width: 18px;
  height: 18px;
  stroke: var(--brand);
}

.label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0 0 4px; }
.big { font-size: 1.3rem; font-weight: 700; margin: 0; }
.big small { font-size: 0.85rem; font-weight: 400; color: var(--muted); }
.big.small-line { font-size: 1rem; font-weight: 600; }
.hero-value { font-size: 1.5rem; font-weight: 700; margin: 0; }
.hero-value small { font-size: 0.85rem; font-weight: 400; color: var(--muted); }
.hero-row { display: flex; gap: 16px; justify-content: space-between; }
.hero-row > div {
  flex: 1;
  text-align: center;
  padding: 8px;
  background: var(--brand-soft);
  border-radius: var(--radius-sm);
}

.progress {
  height: 10px;
  background: var(--line);
  border-radius: 6px;
  margin-top: 12px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}
.progress.slim { height: 6px; margin-top: 8px; }
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--brand);
  border-radius: 6px;
  transition: width 0.4s ease;
  box-shadow: 0 1px 2px rgba(27, 122, 90, 0.2);
}

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid .card { margin: 0; }
.grid .card:first-child { grid-column: 1 / -1; }

.next ul { margin: 0 0 12px 18px; padding: 0; }
.next li { margin: 4px 0; }

.btn {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  cursor: pointer;
}
.btn:hover {
  box-shadow: var(--shadow-brand);
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  padding: 8px 0;
  border-top: 1px solid var(--line);
  transition: background-color 0.2s ease, padding-left 0.2s ease;
}
.list li:hover {
  background-color: var(--brand-soft);
  padding-left: 8px;
  padding-right: 8px;
  border-radius: var(--radius-sm);
  margin: 0 -8px;
}
.list li:first-child { border-top: none; }
.list small { color: var(--muted); }
.done { color: var(--brand); font-weight: 700; }
.pending { color: var(--muted); }

.profile { margin: 0; }
.profile div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); }
.profile div:first-child { border-top: none; }
.profile dt { color: var(--muted); font-size: 0.85rem; }
.profile dd { margin: 0; font-weight: 600; text-align: right; }

canvas { width: 100%; display: block; }

.muted { color: var(--muted); }

/* Barra inferior móvil */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--tabbar-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 1px solid var(--line);
  display: flex;
  z-index: 10;
}
.tabbar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.72rem;
  transition: color 0.2s ease;
}
.tab-icon {
  width: 24px;
  height: 24px;
  transition: transform 0.2s ease, stroke 0.2s ease;
}
.tabbar a.active { color: var(--brand); font-weight: 700; }
.tabbar a.active .tab-icon {
  stroke: var(--brand);
  transform: scale(1.1);
}
.tabbar a:hover .tab-icon {
  transform: scale(1.05);
}

/* Tablet / desktop */
@media (min-width: 900px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  .shell { max-width: 960px; padding-bottom: 48px; }
  .grid { grid-template-columns: repeat(3, 1fr); }
  .grid .card:first-child { grid-column: auto; }
}

/* ETAPA 4: formularios e historial. Solo reglas nuevas, nada existente cambia. */
.field { margin: 8px 0; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.field input {
  width: 100%;
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}
.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(27, 122, 90, 0.1);
}
/* ETAPA 6: el selector de tipo de comida usa el mismo aspecto que los inputs. */
.field select {
  width: 100%;
  font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
  cursor: pointer;
}
.field select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(27, 122, 90, 0.1);
}
.row { display: flex; gap: 12px; }
.row .field { flex: 1; }
.row-btns { display: flex; gap: 10px; margin-top: 10px; }
/* ETAPA 5: los 4 botones rápidos de agua ocupan dos filas en móvil. */
.row-btns.wrap { flex-wrap: wrap; }
.row-btns.wrap .btn { flex: 1 1 40%; }
.btn.secondary { background: #fff; color: var(--brand); border: 1px solid var(--brand); }
.btn.secondary:hover {
  background: var(--brand-soft);
}
a.btn { text-decoration: none; }
.error { color: #b3261e; font-size: 0.85rem; }

/* Estados de botones */
.btn.loading {
  opacity: 0.7;
  pointer-events: none;
  position: relative;
}
.btn.loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid transparent;
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn.success {
  background: #1b7a5a;
  animation: successPulse 0.3s ease;
}
@keyframes successPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
.hist-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hist-item .val { font-weight: 700; }
.hist-item small { display: block; }
.link-btn {
  background: none;
  border: none;
  padding: 6px 4px;
  font-size: 0.85rem;
  color: var(--brand);
}
.link-btn.danger { color: #b3261e; }
/* ETAPA 8: checkbox de hábitos y fila con texto. */
.hab-check { width: 22px; height: 22px; accent-color: var(--brand); flex-shrink: 0; }
.hab-left { display: flex; align-items: flex-start; gap: 10px; }
/* ETAPA 9: grilla de días y atenuado de inactivos. */
.days-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.days-grid label { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; }
.rem-inactive { opacity: 0.55; }

/* Toggle de tema */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle .btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
}
.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
  transition: transform 0.3s ease;
}
.theme-toggle .btn:hover .icon-sun,
.theme-toggle .btn:hover .icon-moon {
  transform: rotate(15deg);
}

/* Logros */
.achievement-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--brand-soft);
  margin-bottom: 8px;
  transition: all var(--transition-fast);
}
.achievement-item:hover {
  transform: translateX(4px);
  box-shadow: var(--shadow-sm);
}
.achievement-item.locked {
  opacity: 0.5;
  background: var(--line);
}
.achievement-icon {
  font-size: 1.5rem;
  min-width: 32px;
  text-align: center;
}
.achievement-info {
  flex: 1;
}
.achievement-name {
  font-weight: 600;
  font-size: var(--font-sm);
  margin-bottom: 2px;
}
.achievement-desc {
  font-size: var(--font-xs);
  color: var(--muted);
}
.achievement-date {
  font-size: var(--font-xs);
  color: var(--muted);
  font-style: italic;
}

/* Nutrición IA */
.meals-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}
.meal-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  border: 1px solid var(--line);
}
.meal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}
.meal-type {
  font-weight: 700;
  color: var(--brand);
  font-size: var(--font-sm);
}
.meal-time {
  font-size: var(--font-xs);
  color: var(--muted);
}
.meal-name {
  font-size: var(--font-base);
  font-weight: 600;
  margin: var(--space-sm) 0;
  color: var(--ink);
}
.meal-desc {
  font-size: var(--font-sm);
  color: var(--muted);
  margin-bottom: var(--space-sm);
  line-height: 1.5;
}
.meal-macros {
  display: flex;
  gap: var(--space-md);
  font-size: var(--font-xs);
  color: var(--muted);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--line);
}
.meal-macros span {
  background: var(--brand-soft);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.weekly-menu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
}
.day-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  border: 1px solid var(--line);
}
.day-name {
  font-weight: 700;
  color: var(--brand);
  margin-bottom: var(--space-sm);
  font-size: var(--font-sm);
}
.day-meals {
  list-style: none;
  margin: 0;
  padding: 0;
}
.day-meals li {
  padding: 4px 0;
  font-size: var(--font-sm);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.day-meals li:last-child {
  border-bottom: none;
}

.shopping-category {
  margin-bottom: var(--space-lg);
}
.shopping-category h4 {
  font-weight: 700;
  color: var(--brand);
  margin-bottom: var(--space-sm);
  font-size: var(--font-base);
}
.shopping-items {
  list-style: none;
  margin: 0;
  padding: 0;
}
.shopping-items li {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--font-sm);
}
.shopping-items li:last-child {
  border-bottom: none;
}
.item-name {
  color: var(--ink);
}
.item-qty {
  color: var(--muted);
  font-size: var(--font-xs);
}
