/* ===== Athletia — estilos ===== */
:root {
  color-scheme: dark;
  --bg: #0b0c0f;
  --surface: #15171c;
  --surface-2: #1d2027;
  --border: #2a2e37;
  --text: #f2f4f7;
  --muted: #9aa3b2;
  --accent: #c8f53c;
  --accent-ink: #0b0c0f;
  --accent-soft: rgba(200, 245, 60, 0.12);
  --danger: #ff6464;
  --ok: #35d07f;
  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; font-size: 16px; line-height: 1.4; overscroll-behavior-y: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ----- Cabecera ----- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--safe-t)) 16px 12px;
  background: rgba(11, 12, 15, 0.86);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: 0.2px; font-size: 18px; }
.brand img { border-radius: 8px; }
.topbar h1 { font-size: 15px; font-weight: 600; color: var(--muted); }

/* ----- Vista principal ----- */
main {
  max-width: 640px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 96px);
}
main > * + * { margin-top: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card h3 { font-size: 16px; margin-bottom: 6px; }
.hero { text-align: center; padding: 28px 20px; background: linear-gradient(160deg, #1b2110 0%, var(--surface) 60%); }
.hero h2 { font-size: 22px; margin: 10px 0 6px; }
.hero p { color: var(--muted); margin-bottom: 18px; }
.hero .big-icon { width: 52px; height: 52px; color: var(--accent); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin: 22px 4px 8px; }

/* ----- Botones ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-weight: 600; transition: transform 0.08s ease, opacity 0.15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; color: var(--danger); border-color: rgba(255, 100, 100, 0.4); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.icon-btn {
  width: 38px; height: 38px; display: inline-grid; place-items: center;
  border-radius: 10px; border: 0; background: transparent; color: var(--muted);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg, .btn svg { width: 20px; height: 20px; }

/* ----- Chips ----- */
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip-btn {
  flex: none; padding: 7px 14px; border-radius: 999px; font-size: 14px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
}
.chip-btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--accent); color: var(--accent-ink); }

/* ----- Entrenamiento activo ----- */
.active-head .title-input {
  width: 100%; background: transparent; border: 0; padding: 0;
  font-size: 22px; font-weight: 800; outline: none;
}
.active-head .meta { margin-top: 6px; color: var(--muted); font-size: 14px; display: flex; gap: 6px; flex-wrap: wrap; }
.active-head .meta strong { color: var(--accent); font-variant-numeric: tabular-nums; }

.ex-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.ex-head h3 { margin-bottom: 4px; }
.set-row {
  display: grid; grid-template-columns: 34px 1fr 72px 64px 44px;
  align-items: center; gap: 8px; padding: 5px 0;
}
.set-head { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.set-head span:nth-child(n+3) { text-align: center; }
.set-n { font-weight: 700; color: var(--muted); text-align: center; }
.prev { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.set-row input {
  width: 100%; height: 40px; text-align: center; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border); outline: none;
  -moz-appearance: textfield;
}
.set-row input::-webkit-outer-spin-button, .set-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.set-row input:focus { border-color: var(--accent); }
.check {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
}
.check svg { width: 20px; height: 20px; }
.set-row.done input { background: rgba(53, 208, 127, 0.12); border-color: rgba(53, 208, 127, 0.35); }
.set-row.done .check { background: var(--ok); border-color: var(--ok); color: #06210f; }
.ex-card .row { margin-top: 8px; }

/* ----- Descanso ----- */
.rest {
  position: fixed; left: 12px; right: 12px; z-index: 20;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 10px);
  max-width: 616px; margin: 0 auto;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px;
  overflow: hidden; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.rest-bar { height: 4px; background: var(--border); }
.rest-bar div { height: 100%; width: 0; background: var(--accent); transition: width 1s linear; }
.rest-row { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.rest-label { color: var(--muted); font-size: 14px; }
.rest-row strong { font-size: 20px; font-variant-numeric: tabular-nums; margin-right: auto; }

/* ----- Barra de pestañas ----- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(15, 16, 20, 0.92);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 600;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }
.tab .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); position: absolute; margin: -22px 0 0 22px; }
.tab { position: relative; }

/* ----- Hoja inferior (modal) ----- */
.backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.55); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  max-width: 640px; margin: 0 auto; max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(20px + var(--safe-b));
  animation: up 0.22s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { font-size: 19px; }
.ex-list { margin: 4px 0 12px; }
.ex-item {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 4px; background: transparent; border: 0; border-bottom: 1px solid var(--border); text-align: left;
}
.ex-item .chip { flex: none; }
.ex-item.in-use span:first-child::after { content: " ✓"; color: var(--accent); }

/* ----- Formularios ----- */
.input, .field select, .field textarea, .field input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border); outline: none;
}
.input:focus, .field select:focus, .field textarea:focus, .field input:focus { border-color: var(--accent); }
.field { display: block; }
.field + .field { margin-top: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; }
.field textarea { min-height: 80px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-2 .field + .field { margin-top: 0; }

/* ----- Historial ----- */
.w-card { width: 100%; text-align: left; display: block; }
.w-card .w-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.w-card .w-date { font-size: 13px; color: var(--muted); text-transform: capitalize; }
.w-card .w-stats { display: flex; gap: 14px; margin: 8px 0; font-size: 14px; color: var(--muted); }
.w-card .w-stats b { color: var(--text); }
.w-card ul { margin: 0; padding: 0; list-style: none; font-size: 14px; color: var(--muted); }
.w-card li + li { margin-top: 2px; }
.detail-ex + .detail-ex { margin-top: 14px; }
.detail-ex h3 { font-size: 15px; margin-bottom: 4px; }
.detail-ex ol { margin: 0; padding-left: 22px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ----- Progreso ----- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.stat b { display: block; font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .lbl { fill: var(--muted); font-size: 10px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-soft); }
.chart .pt { fill: var(--bg); stroke: var(--accent); stroke-width: 2; }
.records { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.records div { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.records b { display: block; font-size: 17px; }
.records span { font-size: 11px; color: var(--muted); }

/* ----- Coach ----- */
.progress { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 12px 0 6px; }
.progress div { height: 100%; background: var(--accent); border-radius: 999px; }
.feature-list { margin: 8px 0 12px; padding-left: 20px; color: var(--muted); }
.feature-list li + li { margin-top: 6px; }

/* ----- Aviso ----- */
.toast {
  position: fixed; left: 50%; z-index: 40; top: calc(14px + var(--safe-t));
  transform: translate(-50%, -140%); transition: transform 0.25s ease;
  background: var(--accent); color: var(--accent-ink); font-weight: 700;
  padding: 10px 18px; border-radius: 999px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  max-width: calc(100% - 32px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty svg { width: 44px; height: 44px; opacity: 0.6; margin-bottom: 8px; }
.pr-list { list-style: none; padding: 0; margin: 10px 0 0; }
.pr-list li { padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.pr-list li + li { margin-top: 6px; }

/* ----- Control segmentado ----- */
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.segmented button { min-height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 600; font-size: 14px; }
.segmented button.on { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,0.04) inset; }

/* ----- Rutina (plan) ----- */
.plan-head h2 { font-size: 19px; margin: 6px 0 4px; }
.plan-day { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-top: 1px solid var(--border); }
.plan-day:first-of-type { border-top: 0; }
.plan-day b { display: block; }
.plan-day small { color: var(--muted); }
.plan-day.next b::after { content: "  · siguiente"; color: var(--accent); font-weight: 600; font-size: 12px; }
.target { font-size: 13px; color: var(--accent); margin: -4px 0 8px; }
.target-notes { font-size: 13px; color: var(--muted); margin: -4px 0 8px; }
.plan-ex { padding: 8px 0; border-top: 1px dashed var(--border); font-size: 14px; }
.plan-ex:first-child { border-top: 0; }
.plan-ex .muted { font-size: 13px; }
details { margin-top: 10px; }
details summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; }
details p, details ul { margin-top: 8px; color: var(--muted); font-size: 14px; }

/* ----- Dieta ----- */
.kcal { text-align: center; margin: 14px 0 6px; }
.kcal b { font-size: 40px; font-weight: 800; letter-spacing: -1px; }
.kcal span { color: var(--muted); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.macro { background: var(--surface-2); border-radius: 12px; padding: 10px; text-align: center; }
.macro b { display: block; font-size: 18px; }
.macro span { font-size: 12px; color: var(--muted); }
.macro i { display: block; height: 4px; border-radius: 4px; margin-top: 8px; background: var(--c, var(--accent)); }
.meal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.meal-head .chip { margin-left: 6px; }
.meal-opt { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.meal-opt b { font-size: 14px; }
.meal-opt ul { margin: 6px 0; padding-left: 18px; font-size: 14px; color: var(--muted); }
.meal-opt .mline { font-size: 12px; color: var(--muted); }

/* ----- Chat del coach ----- */
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.45; word-wrap: break-word; }
.msg p + p { margin-top: 6px; }
.msg ul { margin: 6px 0; padding-left: 18px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.error { border-color: rgba(255, 100, 100, 0.5); color: #ffb3b3; }
.msg .md-h { font-weight: 700; }
.msg-changes { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.msg-changes button { border: 0; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.typing { align-self: flex-start; display: flex; gap: 5px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.composer { position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); display: flex; gap: 8px; align-items: flex-end; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; }
.composer textarea { flex: 1; min-height: 44px; max-height: 140px; resize: none; padding: 10px 12px; border-radius: 12px; border: 0; background: var(--surface-2); outline: none; }
.composer .btn { min-height: 44px; }
.quick { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
.quick::-webkit-scrollbar { display: none; }

/* ----- Inicio de sesión ----- */
.auth { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 50% 0%, #1b2110 0%, var(--bg) 60%); overflow-y: auto; }
.auth-card { width: 100%; max-width: 380px; text-align: center; }
.auth-card h2 { font-size: 26px; margin: 12px 0 6px; }
.auth-card form { text-align: left; margin-top: 22px; }
.auth-card .btn { margin-top: 10px; }
.auth-msg { min-height: 20px; margin-top: 10px; font-size: 14px; color: var(--accent); }
.auth-msg.err { color: var(--danger); }
.sync-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 6px; }
.sync-dot.synced { background: var(--ok); }
.sync-dot.syncing { background: var(--accent); }
.sync-dot.error { background: var(--danger); }
