/* ============================================================
   FitTracker — Tema Oscuro (default) + Tema Claro
   ============================================================ */

:root {
  --bg:          #0d0d0d;
  --surface:     #161616;
  --card:        #1e1e1e;
  --border:      #2a2a2a;
  --accent:      #d4ff00;
  --accent-dim:  rgba(212, 255, 0, 0.12);
  --accent-dark: rgba(212, 255, 0, 0.08);
  --text:        #f0f0f0;
  --text-muted:  #888;
  --text-dim:    #444;
  --done-text:   #3a3a3a;
  --green:       #22c55e;
  --yellow:      #eab308;
  --red:         #ef4444;
  --radius:      16px;
  --radius-sm:   10px;
  --radius-xs:   6px;
  --nav-h:       72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-bg:      rgba(13, 13, 13, 0.95);
  --shadow:      none;
}

[data-theme="light"] {
  --bg:          #f2f2f7;
  --surface:     #ffffff;
  --card:        #f2f2f7;
  --border:      #e0e0e5;
  --accent:      #5c6bc0;
  --accent-dim:  rgba(92, 107, 192, 0.12);
  --accent-dark: rgba(92, 107, 192, 0.08);
  --text:        #1a1a1a;
  --text-muted:  #8e8e93;
  --text-dim:    #c7c7cc;
  --done-text:   #c7c7cc;
  --green:       #34c759;
  --yellow:      #ff9500;
  --red:         #ff3b30;
  --nav-bg:      rgba(242, 242, 247, 0.95);
  --shadow:      0 1px 3px rgba(0,0,0,0.08);
}

/* Ajustes específicos para tema claro */
[data-theme="light"] .ring-fill      { stroke: var(--accent); }
[data-theme="light"] .check-icon     { stroke: #fff; }
[data-theme="light"] .progress-pct   { color: var(--accent); }
[data-theme="light"] .streak-num     { color: var(--accent); }
[data-theme="light"] .nav-btn.active { color: var(--accent); }
[data-theme="light"] .nav-btn.active svg { stroke: var(--accent); }
[data-theme="light"] .meal-section,
[data-theme="light"] .card,
[data-theme="light"] .progress-card,
[data-theme="light"] .routine-day-card,
[data-theme="light"] .history-stat-card { box-shadow: var(--shadow); }
[data-theme="light"] #bottom-nav { background: var(--nav-bg); }
[data-theme="light"] .day-badge.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
[data-theme="light"] .ex-chip.more    { color: var(--accent); border-color: var(--accent-dim); background: var(--accent-dim); }
[data-theme="light"] .hist-stat-val   { color: var(--accent); }
[data-theme="light"] .btn-primary     { background: var(--accent); color: #fff; }
[data-theme="light"] .history-cell.is-today { border-color: var(--accent) !important; }

/* Botón de tema */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}
.theme-toggle:active { opacity: 0.7; }

/* ---- Reset & Base ---- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  /* body scrollea naturalmente — más compatible con iOS Safari */
  overscroll-behavior-y: none;
}

button { border: none; background: none; cursor: pointer; font-family: inherit; }
input, textarea { font-family: inherit; }
svg { stroke: currentColor; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
-webkit-tap-highlight-color: transparent;

/* ---- Layout ---- */
#app {
  /* sin overflow ni altura fija — el body hace el scroll */
}

.view {
  display: none;
  padding: 20px 16px 0;
  /* espacio para que el contenido no quede detrás del nav fijo */
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  animation: fadeIn 0.2s ease;
}
.view.active { display: block; }

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

/* ---- Bottom Nav ---- */
#bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(13, 13, 13, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 20px;
  color: var(--text-dim);
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.nav-btn svg { width: 22px; height: 22px; transition: stroke 0.2s; }
.nav-btn span { font-size: 10px; font-weight: 500; letter-spacing: 0.3px; }
.nav-btn.active { color: var(--accent); }
.nav-btn.active svg { stroke: var(--accent); }

/* ---- Page Header ---- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-top: 4px;
}
.header-sub {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
  text-transform: capitalize;
}
.header-title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.1;
}

/* ---- Streak Badge ---- */
.streak-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  flex-shrink: 0;
}
.streak-fire { font-size: 18px; }
.streak-num {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

/* ---- Progress Card ---- */
.progress-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 16px;
}

.progress-ring-wrap {
  position: relative;
  width: 110px;
  height: 110px;
  flex-shrink: 0;
}
.progress-ring { width: 110px; height: 110px; }
.ring-bg {
  fill: none;
  stroke: var(--card);
  stroke-width: 9;
}
.ring-fill {
  fill: none;
  stroke: var(--accent);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 314.16;
  stroke-dashoffset: 314.16;
  transform: rotate(-90deg);
  transform-origin: 55px 55px;
  transition: stroke-dashoffset 0.7s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.progress-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.progress-pct {
  font-size: 22px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -1px;
  line-height: 1;
}
.progress-label {
  font-size: 9px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.progress-stats {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-key {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ---- Rest Day ---- */
.rest-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 16px;
}
.rest-icon { font-size: 36px; }
.rest-text { font-size: 18px; font-weight: 700; margin: 8px 0 4px; }
.rest-sub { font-size: 13px; color: var(--text-muted); }

/* ---- Section Header ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  margin-top: 4px;
}
.section-header h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.section-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}

/* ---- Card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 16px;
  margin-bottom: 12px;
}

/* ---- Check Items ---- */
.check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: opacity 0.15s;
}
.check-item:last-child { border-bottom: none; }
.check-item:active { opacity: 0.6; }

.check-box {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-xs);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: transparent;
}
.check-item.done .check-box {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(1.05);
}

.check-icon {
  width: 13px;
  height: 13px;
  stroke: #000;
  stroke-width: 3;
  opacity: 0;
  transform: scale(0.3);
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.check-item.done .check-icon {
  opacity: 1;
  transform: scale(1);
}

.check-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  transition: color 0.2s;
  line-height: 1.3;
}
.check-item.done .check-label {
  color: var(--text-dim);
  text-decoration: line-through;
  text-decoration-color: var(--text-muted);
}

/* ---- Meal Section ---- */
.meal-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
}
.meal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.meal-emoji { font-size: 20px; flex-shrink: 0; }
.meal-name { font-size: 15px; font-weight: 700; flex: 1; }
.meal-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--card);
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid var(--border);
}
.meal-chevron {
  font-size: 18px;
  color: var(--text-muted);
  transition: transform 0.25s;
  line-height: 1;
  display: inline-block;
  transform: rotate(0deg);
}
.meal-chevron.rotated { transform: rotate(90deg); }

.meal-clip {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.3s ease;
}
.meal-clip.open { grid-template-rows: 1fr; }

.meal-items {
  min-height: 0;
  overflow: hidden;    /* requerido para el truco 0fr */
  touch-action: pan-y; /* iOS: pasar swipe vertical al padre */
  border-top: 1px solid var(--border);
  padding: 0 16px;
}

/* ---- Routine Cards ---- */
.routine-day-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.2s, background 0.2s;
}
.routine-day-card:active { background: var(--card); }
.routine-day-card.today-highlight { border-color: var(--accent); }

.routine-day-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.day-badge {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 4px 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
  min-width: 36px;
  text-align: center;
}
.day-badge.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.routine-day-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.routine-day-emoji { font-size: 18px; flex-shrink: 0; }
.routine-day-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.exercise-count {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.edit-icon {
  width: 16px;
  height: 16px;
  stroke: var(--text-muted);
  flex-shrink: 0;
}
.routine-exercises {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.ex-chip {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}
.ex-chip.more {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--accent-dim);
}
.rest-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
  font-style: italic;
}

/* ---- Diet Cards ---- */
.diet-meal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s;
}
.diet-meal-card:active { background: var(--card); }

.diet-meal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.meal-emoji-lg { font-size: 28px; flex-shrink: 0; }
.diet-meal-info { flex: 1; min-width: 0; }
.diet-meal-info h3 { font-size: 16px; font-weight: 700; }
.diet-meal-info p { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.diet-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.diet-chip {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
}

/* ---- History ---- */
.history-stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.history-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
}
.hist-stat-val { font-size: 22px; font-weight: 900; color: var(--accent); }
.hist-stat-label { font-size: 11px; color: var(--text-muted); font-weight: 500; }

.history-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-bottom: 16px;
}
.history-cell {
  aspect-ratio: 1;
  border-radius: var(--radius-xs);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  gap: 1px;
  border: 2px solid transparent;
  transition: transform 0.15s;
}
.history-cell:active { transform: scale(0.9); }

.history-date { font-size: 11px; font-weight: 700; line-height: 1; }
.history-pct { font-size: 8px; font-weight: 600; opacity: 0.8; line-height: 1; }

.history-cell.no-data { background: #2a2a2a; color: #555; }
[data-theme="light"] .history-cell.no-data { background: #e5e5ea; color: #aeaeb2; }
.history-cell.green { background: rgba(34, 197, 94, 0.2); color: var(--green); border-color: rgba(34, 197, 94, 0.3); }
.history-cell.yellow { background: rgba(234, 179, 8, 0.2); color: var(--yellow); border-color: rgba(234, 179, 8, 0.3); }
.history-cell.red { background: rgba(239, 68, 68, 0.15); color: var(--red); border-color: rgba(239, 68, 68, 0.2); }
.history-cell.is-today { border-color: var(--accent) !important; }

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}
.legend-dot.green  { background: rgba(34, 197, 94, 0.5); }
.legend-dot.yellow { background: rgba(234, 179, 8, 0.5); }
.legend-dot.red    { background: rgba(239, 68, 68, 0.4); }
.legend-dot.gray   { background: #555; }
[data-theme="light"] .legend-dot.gray { background: #aeaeb2; }

/* ---- Modal ---- */
#modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s;
}
#modal-backdrop.visible { opacity: 1; }
#modal-backdrop.hidden { display: none; }

#modal {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #1a1a1a;
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}
#modal.visible { transform: translateY(0); }
#modal.hidden { display: none; }

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--card);
  color: var(--text-muted);
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  -webkit-overflow-scrolling: touch;
}
.modal-footer {
  display: flex;
  gap: 10px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ---- Form Elements ---- */
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  margin-top: 16px;
}
.form-label:first-child { margin-top: 0; }

.form-input {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.form-input:focus { border-color: var(--accent); }

.form-textarea {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.6;
  padding: 12px 14px;
  outline: none;
  resize: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.form-textarea:focus { border-color: var(--accent); }
.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ---- Buttons ---- */
.btn-primary {
  flex: 1;
  background: var(--accent);
  color: #000;
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  padding: 13px;
  text-align: center;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-primary:active { opacity: 0.85; transform: scale(0.98); }

.btn-secondary {
  flex: 1;
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 13px;
  text-align: center;
  transition: opacity 0.15s;
}
.btn-secondary:active { opacity: 0.7; }

/* ---- Reset Button ---- */
.btn-reset {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--red);
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-xs);
  padding: 6px 12px;
}
.btn-reset:active { opacity: 0.7; }

/* ---- Spacer ---- */
.spacer { height: 24px; }

/* ---- History weekday labels ---- */
.history-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-bottom: 5px;
}
.wd-label {
  text-align: center;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* ---- Reset today confirm ---- */
.reset-confirm {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}
.reset-confirm p { font-size: 14px; color: var(--text-muted); margin-bottom: 12px; }
.reset-actions { display: flex; gap: 10px; }
