/* ══════════════════════════════════════════════════════════════
   WEIGHT TRACKER — Mobile-First CSS
   ══════════════════════════════════════════════════════════════ */

:root {
  --primary:       #6366f1;
  --primary-dark:  #4f46e5;
  --primary-50:    #eef2ff;
  --primary-100:   #e0e7ff;
  --success:       #10b981;
  --success-50:    #ecfdf5;
  --error:         #ef4444;
  --error-50:      #fef2f2;
  --warning:       #f59e0b;
  --warning-50:    #fffbeb;

  --bg:            #f1f5f9;
  --card:          #ffffff;
  --text:          #0f172a;
  --text-muted:    #64748b;
  --text-light:    #94a3b8;
  --border:        #e2e8f0;

  --radius-xl: 20px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:    0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.10), 0 4px 6px -4px rgba(0,0,0,0.05);

  --nav-h: 68px;
}

/* ── Reset ──────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 8px));
  -webkit-font-smoothing: antialiased;
}

/* Quitar flechas de inputs numéricos */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type=number] { -moz-appearance: textfield; }

/* ── Contenedor ─────────────────────────────────────────────── */

.page {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 16px;
}

/* ── Cabecera de página ─────────────────────────────────────── */

.page-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 44px 20px 36px;
  margin: 0 -16px;
}

.page-header h1 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.page-header .subtitle {
  font-size: 0.875rem;
  opacity: 0.8;
}

/* ── Cards ──────────────────────────────────────────────────── */

.card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card-sm { padding: 14px 16px; }

.card-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 14px;
}

/* ── Hero de peso (home) ────────────────────────────────────── */

.weight-hero {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: 22px;
  box-shadow: var(--shadow-lg);
  margin-top: -20px;
  margin-bottom: 14px;
}

.weight-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.weight-input-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.weight-input {
  flex: 1;
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  outline: none;
  background: var(--bg);
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
  -webkit-appearance: none;
  letter-spacing: -1px;
}

.weight-input:focus {
  border-color: var(--primary);
  background: var(--primary-50);
}

.weight-unit {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-muted);
}

/* ── Selector de fecha ──────────────────────────────────────── */

.date-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 11px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.date-bar input[type="date"] {
  flex: 1;
  border: none;
  outline: none;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  -webkit-appearance: none;
}

.date-icon {
  width: 18px;
  height: 18px;
  stroke: var(--primary);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* ── Formulario ─────────────────────────────────────────────── */

.form-group { margin-bottom: 14px; }
.form-group:last-child { margin-bottom: 0; }

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 13px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 1rem;
  color: var(--text);
  background: var(--card);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-100);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-light); }

.form-textarea { resize: vertical; min-height: 80px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 4px;
}

/* ── Botones ────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  min-height: 52px;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  line-height: 1;
}

.btn:active { transform: scale(0.97); opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-block { width: 100%; }

.btn-primary {
  background: var(--primary);
  color: white;
  border-radius: var(--radius-lg);
}
.btn-primary:active { background: var(--primary-dark); }

.btn-secondary {
  background: var(--primary-50);
  color: var(--primary);
  border: 2px solid var(--primary-100);
  border-radius: var(--radius-lg);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 10px 14px;
  min-height: auto;
}

.btn-danger {
  background: var(--error-50);
  color: var(--error);
  border: 1px solid #fecaca;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.875rem;
  min-height: 36px;
  border-radius: var(--radius-sm);
}

.btn-icon {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
}

.btn-icon:active { transform: scale(0.92); }
.btn-icon.danger { background: var(--error-50); border-color: #fecaca; color: var(--error); }

/* ── Stats grid (home quick stats) ─────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 14px 10px;
  box-shadow: var(--shadow-sm);
  text-align: center;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card.primary .stat-value { color: var(--primary); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.down    .stat-value { color: var(--success); }
.stat-card.up      .stat-value { color: var(--error); }

/* ── Toggle campos opcionales ───────────────────────────────── */

.toggle-section {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.35s ease;
}
.toggle-section.open { max-height: 700px; }

/* ── Resumen del día ─────────────────────────────────────────── */

.day-summary {
  background: var(--success-50);
  border: 2px solid #a7f3d0;
  border-radius: var(--radius-md);
  padding: 11px 14px;
  font-size: 0.875rem;
  color: #065f46;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Divider ─────────────────────────────────────────────────── */

.divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

/* ── Section header ─────────────────────────────────────────── */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

/* ── Historial (log cards) ──────────────────────────────────── */

.log-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
  border-left: 4px solid var(--border);
  transition: border-color 0.2s;
}

.log-card.has-weight { border-left-color: var(--primary); }

.log-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.log-date-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.log-weight-badge {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.log-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.chip {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  font-weight: 500;
}

.chip.green { background: var(--success-50); border-color: #a7f3d0; color: #065f46; }
.chip.red   { background: var(--error-50);   border-color: #fecaca; color: #991b1b; }

.log-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── Filtro de historial ─────────────────────────────────────── */

.filter-bar {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.filter-bar .form-group { flex: 1; margin-bottom: 0; }

.filter-bar .form-input {
  padding: 10px 12px;
  font-size: 0.875rem;
}

.filter-bar .form-label {
  font-size: 0.75rem;
  margin-bottom: 4px;
}

/* ── KPI grid (stats) ───────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.kpi-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.kpi-value {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: 4px;
}

.kpi-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-card.accent {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
}

.kpi-card.accent .kpi-value,
.kpi-card.accent .kpi-label { color: white; }
.kpi-card.accent .kpi-label { opacity: 0.8; }

.kpi-card.success-card { background: var(--success-50); }
.kpi-card.success-card .kpi-value { color: var(--success); }

/* ── Gráficas ────────────────────────────────────────────────── */

.chart-wrapper {
  position: relative;
  height: 210px;
  margin-bottom: 6px;
}

.chart-range-btns {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.range-btn {
  flex: 1;
  padding: 9px 6px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.range-btn.active {
  border-color: var(--primary);
  background: var(--primary-50);
  color: var(--primary);
}

/* ── Badge de tendencia ──────────────────────────────────────── */

.trend-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 700;
}

.trend-badge.good    { background: var(--success-50); color: var(--success); }
.trend-badge.warning { background: var(--warning-50); color: var(--warning); }
.trend-badge.bad     { background: var(--error-50);   color: var(--error);   }
.trend-badge.neutral { background: var(--bg);          color: var(--text-muted); }

/* ── Tarjeta de predicción ───────────────────────────────────── */

.prediction-card {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.prediction-card .pred-label { font-size: 0.78rem; opacity: 0.8; font-weight: 500; margin-bottom: 4px; }
.prediction-card .pred-value { font-size: 1.7rem; font-weight: 800; margin-bottom: 4px; line-height: 1.2; }
.prediction-card .pred-sub   { font-size: 0.83rem; opacity: 0.75; }

/* ── Ajustes ────────────────────────────────────────────────── */

.settings-section {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.settings-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--primary);
  margin-bottom: 16px;
}

.bmr-box {
  background: var(--primary-50);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-top: 14px;
}

.bmr-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
}

.bmr-label { font-size: 0.85rem; color: var(--text-muted); }
.bmr-value { font-size: 1rem; font-weight: 700; color: var(--primary); }

/* ── Navegación inferior ─────────────────────────────────────── */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  padding-top: 6px;
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.07);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--text-light);
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  padding: 4px;
  min-height: 52px;
}

.nav-item.active { color: var(--primary); }

.nav-item svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-item span {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ── Toast ──────────────────────────────────────────────────── */

.toast-wrap {
  position: fixed;
  top: max(56px, env(safe-area-inset-top, 16px) + 40px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 440px;
  pointer-events: none;
}

.toast {
  padding: 13px 18px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toastIn 0.28s ease;
  pointer-events: all;
}

.toast.success { background: #059669; color: white; }
.toast.error   { background: var(--error); color: white; }
.toast.info    { background: var(--primary); color: white; }

@keyframes toastIn  { from { opacity:0; transform:translateY(-14px); } to { opacity:1; transform:translateY(0); } }
@keyframes toastOut { from { opacity:1; transform:translateY(0); }      to { opacity:0; transform:translateY(-14px); } }
.toast.hiding { animation: toastOut 0.25s ease forwards; }

/* ── Modal confirmación ──────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--card);
  border-radius: var(--radius-xl);
  padding: 24px;
  width: 100%;
  max-width: 440px;
  margin: 0 auto;
  transform: translateY(24px);
  transition: transform 0.25s;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 8px; }
.modal-body  { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 20px; }
.modal-btns  { display: flex; gap: 10px; }
.modal-btns .btn { flex: 1; }

/* ── Estado vacío ────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 2.5rem; margin-bottom: 14px; opacity: 0.5; }
.empty-state h3   { font-size: 1rem; color: var(--text); margin-bottom: 6px; }
.empty-state p    { font-size: 0.875rem; }

/* ── Loader ──────────────────────────────────────────────────── */

.loader {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilidades ──────────────────────────────────────────────── */

.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-0  { margin-bottom: 0 !important; }
.text-center { text-align: center; }
.text-success { color: var(--success); }
.text-error   { color: var(--error); }
.text-muted   { color: var(--text-muted); }
.fw-700       { font-weight: 700; }
.hidden       { display: none !important; }
.flex         { display: flex; }
.gap-8        { gap: 8px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

@media (min-width: 480px) {
  .page { padding: 0 20px 20px; }
  .page-header { padding: 48px 24px 40px; margin: 0 -20px; }
}

/* ── Widget del tiempo ───────────────────────────────────────── */

.weather-widget {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  backdrop-filter: blur(4px);
  flex-shrink: 0;
}

.weather-temps {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
