:root {
  --blue: #0386CA;
  --blue-d: #04639B;
  --blue-dd: #0B3F63;
  --orange: #F07A28;
  --red: #E6452E;
  --bg: #F3F6F9;
  --card: #FFFFFF;
  --ink: #0F2133;
  --ink-2: #4A5B6C;
  --ink-3: #8696A6;
  --line: #E3E9EF;
  --ok: #1E9E62;
  --warn: #D98A0B;
  --bad: #D2382A;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(15,33,51,.06), 0 4px 16px rgba(15,33,51,.06);
  --grad: linear-gradient(135deg, var(--blue) 0%, var(--blue-d) 100%);
  --grad-warm: linear-gradient(135deg, var(--orange) 0%, var(--red) 100%);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: #DCE4EC;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
p { margin: 0; }

/* Marco de app: ocupa todo en móvil, columna centrada en escritorio */
#app {
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
  box-shadow: 0 0 40px rgba(15,33,51,.12);
  overflow-x: hidden;
}
.screen { padding: 0 16px calc(96px + var(--safe-b)); }
.screen.no-tab { padding-bottom: calc(32px + var(--safe-b)); }

/* ---------- Header ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: rgba(243,246,249,.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  margin: 0 -16px 8px; padding: 14px 16px 10px;
  display: flex; align-items: center; gap: 12px;
}
.top h1 { font-size: 20px; font-weight: 700; flex: 1; letter-spacing: -.2px; }
.top .sub { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--card); box-shadow: var(--shadow); flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.brand-mini { width: 40px; height: 40px; object-fit: contain; flex: none; }

/* ---------- Hero ---------- */
.hero {
  background: var(--grad); color: #fff; border-radius: 24px; padding: 20px;
  position: relative; overflow: hidden; margin-bottom: 16px;
}
.hero::after {
  content: ''; position: absolute; right: -40px; top: -40px; width: 180px; height: 180px;
  border-radius: 50%; border: 22px solid rgba(255,255,255,.10);
}
.hero::before {
  content: ''; position: absolute; right: 18px; top: 18px; width: 10px; height: 10px; border-radius: 50%; background: var(--orange); box-shadow: -18px 0 0 rgba(255,255,255,.5);
}
.hero > * { position: relative; z-index: 1; }
.hero .kicker { font-size: 12px; opacity: .85; font-weight: 500; text-transform: uppercase; letter-spacing: .8px; }
.hero h2 { font-size: 22px; margin: 4px 0 6px; font-weight: 700; }
.hero p { font-size: 14px; opacity: .9; }

/* ---------- Cards ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card.tight { padding: 12px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 20px 2px 10px; }
.section-title h3 { font-size: 16px; font-weight: 700; }
.section-title a, .section-title button { font-size: 13px; color: var(--blue); font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 4px; }
.stat { background: var(--card); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); }
.stat .v { font-size: 24px; font-weight: 700; letter-spacing: -.5px; }
.stat .l { font-size: 11.5px; color: var(--ink-2); line-height: 1.25; }

/* ---------- Listas ---------- */
.row { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); margin-bottom: 10px; width: 100%; text-align: left; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: var(--ink-3); flex: none; }
.chev svg { width: 18px; height: 18px; display: block; }

.avatar {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; flex: none;
  font-weight: 700; color: #fff; font-size: 15px; background: var(--grad);
}
.avatar.lg { width: 64px; height: 64px; border-radius: 20px; font-size: 22px; }
.avatar.warm { background: var(--grad-warm); }

.thumb { width: 56px; height: 56px; border-radius: 14px; flex: none; position: relative; overflow: hidden; display: grid; place-items: center; color: #fff; }
.thumb svg { width: 22px; height: 22px; opacity: .95; }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: #EAF4FB; color: var(--blue-d); white-space: nowrap; }
.pill.warm { background: #FDEEE4; color: #B9481A; }
.pill.ok { background: #E3F5EC; color: #127347; }
.pill.warn { background: #FCF1DC; color: #8F5B05; }
.pill.bad { background: #FBE6E3; color: #A42A1F; }
.pill.gray { background: #EEF2F5; color: var(--ink-2); }
.pill svg { width: 13px; height: 13px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 16px 8px; margin: 0 -16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { padding: 8px 14px; border-radius: 99px; background: var(--card); box-shadow: var(--shadow); font-size: 13px; font-weight: 600; white-space: nowrap; color: var(--ink-2); }
.chip.on { background: var(--ink); color: #fff; }

.search { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 14px; padding: 0 12px; box-shadow: var(--shadow); margin-bottom: 12px; }
.search svg { width: 18px; height: 18px; color: var(--ink-3); flex: none; }
.search input { border: 0; outline: 0; background: none; padding: 12px 0; width: 100%; }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 14px 18px; border-radius: 14px; font-weight: 600; font-size: 15px; background: var(--grad); color: #fff; box-shadow: 0 6px 16px rgba(3,134,202,.28); width: 100%; }
.btn.warm { background: var(--grad-warm); box-shadow: 0 6px 16px rgba(230,69,46,.28); }
.btn.ghost { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.btn.sm { padding: 9px 14px; font-size: 13.5px; width: auto; border-radius: 12px; }
.btn.danger { background: #FBE6E3; color: var(--bad); box-shadow: none; }
.btn svg { width: 18px; height: 18px; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }
.fab { position: fixed; bottom: calc(86px + var(--safe-b)); z-index: 25; width: 56px; height: 56px; border-radius: 18px; background: var(--grad-warm); color: #fff; display: grid; place-items: center; box-shadow: 0 10px 24px rgba(230,69,46,.35); right: max(16px, calc(50vw - 240px + 16px)); }
.fab svg { width: 24px; height: 24px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; z-index: 30;
  background: rgba(255,255,255,.96); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); display: flex; padding: 6px 6px calc(6px + var(--safe-b));
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 11px; font-weight: 600; color: var(--ink-3); border-radius: 12px; }
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.on { color: var(--blue); }

/* ---------- Media (póster de video) ---------- */
.media { position: relative; border-radius: 20px; overflow: hidden; aspect-ratio: 16/10; color: #fff; display: grid; place-items: center; }
.media iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.media .ring { position: absolute; width: 70%; aspect-ratio: 1; border-radius: 50%; border: 26px solid rgba(255,255,255,.09); right: -18%; top: -30%; }
.media .play { width: 64px; height: 64px; border-radius: 50%; background: rgba(255,255,255,.95); display: grid; place-items: center; color: var(--blue-d); box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.media .play svg { width: 26px; height: 26px; margin-left: 3px; }
.media .cap { position: absolute; left: 14px; bottom: 12px; right: 14px; display: flex; justify-content: space-between; align-items: flex-end; font-size: 12px; font-weight: 600; }
.media .cap span { background: rgba(0,0,0,.22); padding: 4px 10px; border-radius: 99px; }
.media .wm { position: absolute; top: 12px; left: 14px; width: 34px; height: 34px; background: #fff; border-radius: 10px; padding: 3px; }

/* ---------- Ejercicio (lista dentro de rutina) ---------- */
.ex { display: flex; align-items: center; gap: 12px; padding: 10px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow); margin-bottom: 10px; }
.ex.done { opacity: .62; }
.ex.done .t { text-decoration: line-through; }
.check { width: 30px; height: 30px; border-radius: 10px; border: 2px solid var(--line); display: grid; place-items: center; flex: none; color: #fff; transition: all .15s; }
.check svg { width: 18px; height: 18px; }
.ex.done .check { background: var(--ok); border-color: var(--ok); }
.dose { font-size: 12.5px; font-weight: 600; color: var(--blue-d); }

/* ---------- Progreso ---------- */
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--grad); border-radius: 99px; transition: width .3s; }
.hero .progress { background: rgba(255,255,255,.25); }
.hero .progress > i { background: #fff; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; text-align: center; }
.week .d { font-size: 11px; color: var(--ink-3); font-weight: 600; }
.week .dot { width: 34px; height: 34px; margin: 4px auto 0; border-radius: 11px; display: grid; place-items: center; background: #EEF2F5; color: var(--ink-3); font-size: 12px; font-weight: 600; }
.week .dot.on { background: var(--grad); color: #fff; }
.week .dot.today { outline: 2px solid var(--orange); outline-offset: 2px; }
.week .dot svg { width: 16px; height: 16px; }

/* ---------- Gráfica ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 9px; white-space: nowrap; transform: translate(-50%, -115%); opacity: 0; transition: opacity .12s; }
.chart .tip.on { opacity: 1; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--ink-3); font-size: 10px; font-family: inherit; }

/* ---------- Formularios ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; outline: 0;
}
.input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); }
.field textarea { min-height: 84px; resize: vertical; }
.mini-inputs { display: flex; gap: 8px; margin-top: 10px; }
.mini-inputs label { flex: 1; font-size: 11px; color: var(--ink-3); font-weight: 600; }
.mini-inputs input { width: 100%; margin-top: 3px; padding: 8px 10px; border-radius: 10px; border: 1.5px solid var(--line); text-align: center; font-weight: 600; }
.mini-inputs input.note { text-align: left; font-weight: 400; }

/* ---------- Sheet / modal ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(15,33,51,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .18s; }
.sheet { background: var(--bg); width: 100%; max-width: 480px; max-height: 88vh; overflow-y: auto; border-radius: 24px 24px 0 0; padding: 10px 16px calc(24px + var(--safe-b)); animation: up .22s ease-out; }
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: #C9D3DC; margin: 0 auto 12px; }
.sheet h3 { font-size: 18px; margin-bottom: 12px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 14px; font-size: 13.5px; z-index: 80; max-width: 90vw; width: max-content; box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: up .2s; }

/* ---------- Login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; padding: 28px 20px calc(24px + var(--safe-b)); background: #fff; }
.login .logo { width: 200px; margin: 8px auto 4px; display: block; }
.login .welcome { text-align: center; color: var(--ink-2); font-size: 14px; margin-bottom: 22px; }
.role { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 18px; border: 1.5px solid var(--line); margin-bottom: 12px; width: 100%; text-align: left; background: #fff; }
.role .ic { width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center; color: #fff; flex: none; }
.role .ic svg { width: 24px; height: 24px; }
.role b { display: block; font-size: 15.5px; }
.role span { font-size: 12.5px; color: var(--ink-2); }
.demo-note { margin-top: auto; text-align: center; font-size: 12px; color: var(--ink-3); padding-top: 20px; }
.pin-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

/* ---------- Player ---------- */
.player { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; padding: 0 16px calc(16px + var(--safe-b)); background: var(--bg); }
.player .bar { display: flex; align-items: center; gap: 12px; padding: 14px 0; }
.player .bar .progress { flex: 1; }
.player .count { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.player h2 { font-size: 22px; font-weight: 700; margin: 16px 0 6px; }
.sets { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
.set { flex: 1; min-width: 64px; padding: 10px 6px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); text-align: center; font-size: 12px; color: var(--ink-2); font-weight: 600; }
.set b { display: block; font-size: 17px; color: var(--ink); }
.set.on { background: var(--ok); color: #fff; }
.set.on b { color: #fff; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { counter-increment: s; position: relative; padding: 0 0 10px 34px; font-size: 14px; color: var(--ink-2); }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 22px; height: 22px; border-radius: 8px; background: #EAF4FB; color: var(--blue-d); font-weight: 700; font-size: 12px; display: grid; place-items: center; }
.note-box { display: flex; gap: 10px; background: #FFF6EF; border: 1px solid #FBDCC6; border-radius: 16px; padding: 12px; font-size: 13.5px; color: #7A3A12; margin: 12px 0; }
.note-box img { width: 32px; height: 32px; border-radius: 10px; background: #fff; padding: 2px; flex: none; }
.tip-box { font-size: 13px; color: var(--ink-2); background: #EEF2F5; border-radius: 14px; padding: 10px 12px; margin-top: 4px; }
.player .actions { margin-top: auto; padding-top: 16px; display: flex; gap: 10px; }
.player .actions .btn.ghost { width: 64px; flex: none; }

.timer { display: grid; place-items: center; margin: 10px 0; }
.timer-wrap svg { width: 150px; height: 150px; transform: rotate(-90deg); }
.timer .num { position: absolute; font-size: 34px; font-weight: 700; letter-spacing: -1px; }
.timer-wrap { position: relative; display: grid; place-items: center; }

/* ---------- Feedback ---------- */
.scale { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }
.scale button { aspect-ratio: 1; border-radius: 10px; background: var(--card); box-shadow: var(--shadow); font-weight: 700; font-size: 13px; }
.scale button.on { color: #fff; }
.scale-l { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); margin-top: 6px; }
.seg { display: flex; gap: 8px; }
.seg button { flex: 1; padding: 12px 6px; border-radius: 14px; background: var(--card); box-shadow: var(--shadow); font-size: 13px; font-weight: 600; }
.seg button.on { background: var(--ink); color: #fff; }

.celebrate { text-align: center; padding: 40px 10px 10px; }
.celebrate .big { width: 96px; height: 96px; border-radius: 30px; margin: 0 auto 16px; background: var(--grad-warm); display: grid; place-items: center; color: #fff; box-shadow: 0 14px 30px rgba(230,69,46,.35); }
.celebrate .big svg { width: 48px; height: 48px; }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetti i { position: absolute; top: -10px; width: 8px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); } }

/* ---------- Barra demo ---------- */
.demo-bar { position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 60; display: none; }

.empty { text-align: center; padding: 28px 16px; color: var(--ink-2); font-size: 14px; }
.empty svg { width: 40px; height: 40px; color: var(--ink-3); margin-bottom: 8px; }
.muted { color: var(--ink-3); font-size: 12.5px; }
.flex { display: flex; align-items: center; gap: 8px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.comment { border-left: 3px solid var(--orange); padding: 2px 0 2px 10px; margin-bottom: 10px; font-size: 13.5px; }
.comment .muted { font-size: 11.5px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-weight: 500; }
.order { display: flex; flex-direction: column; gap: 2px; }
.order button { width: 26px; height: 22px; border-radius: 7px; background: #EEF2F5; display: grid; place-items: center; color: var(--ink-2); }
.order button svg { width: 14px; height: 14px; }

@media (min-width: 520px) {
  #app { margin-top: 0; }
}
