:root {
  --bg: #f1f0fa;
  --bg-grad: linear-gradient(180deg, #ecebfa 0%, #f5f5fb 60%);
  --card: #ffffff;
  --text: #16151c;
  --muted: #6f6c7c;
  --line: #e6e4ef;
  --accent: #8b74e8;
  --accent-soft: #ece7fd;
  --accent-text: #6a51d6;
  --strength: #f5a524;
  --cardio: #2b8fd6;
  --walk: #3bb273;
  --rest: #8c8a99;
  --danger: #d6453d;
  --ok: #2e9e5b;
  --radius: 22px;
  --shadow: 0 1px 2px rgba(30, 20, 80, .04), 0 4px 18px rgba(30, 20, 80, .05);
  --nav-h: 68px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121118;
    --bg-grad: linear-gradient(180deg, #17151f 0%, #121118 60%);
    --card: #1d1b26;
    --text: #f1f0f6;
    --muted: #a19eb0;
    --line: #2c2a37;
    --accent: #9a86f0;
    --accent-soft: #2b2545;
    --accent-text: #b8a9f7;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); background-image: var(--bg-grad); background-attachment: fixed;
  color: var(--text); font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); }

#app { max-width: 560px; margin: 0 auto; min-height: 100%; }
.view { padding: calc(env(safe-area-inset-top) + 16px) 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); }
.hidden { display: none !important; }

h1 { font-size: 28px; line-height: 1.15; margin: 8px 0 16px; letter-spacing: -.02em; }
h2 { font-size: 21px; margin: 26px 0 10px; letter-spacing: -.01em; }
h3 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 12px; }
.card.tap { cursor: pointer; display: flex; align-items: center; gap: 14px; }
.card.tap .grow { flex: 1; min-width: 0; }
.chev { color: var(--muted); font-size: 22px; }

.pill { display: inline-flex; align-items: center; gap: 8px; background: var(--card); border-radius: 999px; padding: 10px 16px; box-shadow: var(--shadow); font-weight: 700; font-size: 20px; border: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.iconbtn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--card); box-shadow: var(--shadow); font-size: 18px; display: inline-flex; align-items: center; justify-content: center; }

.btn { border: 0; border-radius: 999px; padding: 13px 20px; font-weight: 650; font-size: 16px; background: var(--card); border: 1.5px solid var(--line); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btns { display: flex; gap: 10px; margin-top: 14px; }
.btns .btn { flex: 1; }

.coach-head { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.md p { margin: 0 0 8px; } .md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 22px; }
.md strong { color: var(--accent-text); font-weight: 650; }
.md table { border-collapse: collapse; font-size: 14px; } .md td, .md th { border: 1px solid var(--line); padding: 4px 6px; }

.kind { width: 34px; height: 34px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; flex: none; }
.kind.strength, .kind.class, .kind.mixed, .kind.sport { color: var(--strength); }
.kind.cardio { color: var(--cardio); }
.kind.walk, .kind.mobility { color: var(--walk); }
.kind.rest { color: var(--rest); }

.badge { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); white-space: nowrap; }
.badge.done { background: #def3e6; color: var(--ok); }
.badge.skipped { background: #f6e1df; color: var(--danger); }
@media (prefers-color-scheme: dark) { .badge.done { background: #173726; } .badge.skipped { background: #3d1d1b; } }

/* Métricas */
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 12px 14px; }
.metric .v { font-size: 22px; font-weight: 700; }
.metric .l { font-size: 13px; color: var(--muted); }

.rings { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.ring { position: relative; width: 66px; height: 66px; margin: 0 auto 6px; }
.ring svg { transform: rotate(-90deg); }
.ring .val { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; }
.ring-label { font-weight: 650; font-size: 14px; }
.ring-sub { font-size: 12px; color: var(--muted); }

.meal { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.meal:first-child { border-top: 0; }
.meal .grow { flex: 1; }
.meal button { border: 0; background: none; color: var(--muted); font-size: 16px; }

/* Plan */
.seg { display: flex; background: var(--card); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 9px; border-radius: 999px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--bg); color: var(--text); }
.day { display: flex; gap: 12px; align-items: stretch; margin-bottom: 10px; }
.day .date { width: 46px; text-align: center; flex: none; padding-top: 10px; }
.day .date .dow { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.day .date .num { font-size: 26px; font-weight: 700; line-height: 1.1; color: var(--muted); }
.day.today .date .num, .day.today .date .dow { color: var(--text); }
.day.today .date .num::after { content: "•"; display: block; font-size: 14px; line-height: .6; }
.day .card { flex: 1; margin: 0; }
.day.past .card h3 { color: var(--muted); }
.day details summary { list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.day details summary::-webkit-details-marker { display: none; }
.day details[open] .chev { transform: rotate(180deg); }
.day .body { margin-top: 10px; font-size: 14px; }

/* Detalle de sesión */
.sheet-bg { position: fixed; inset: 0; background: rgba(10, 8, 25, .35); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 26px 26px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.ex { display: flex; align-items: center; gap: 12px; }
.ex .grow { flex: 1; }
.ex .meta { color: var(--muted); font-size: 15px; }
.ex a { font-size: 13px; text-decoration: none; white-space: nowrap; }

form.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
form.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
form.grid label.full { grid-column: 1 / -1; }
input, textarea, select { background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; padding: 11px 12px; width: 100%; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); }
.scale { display: flex; gap: 6px; }
.scale button { flex: 1; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 0; font-weight: 650; }
.scale button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Chat */
#view-coach { display: flex; flex-direction: column; height: 100dvh; padding-bottom: 0; }
.msgs { flex: 1; overflow-y: auto; padding-bottom: 12px; }
.msg { margin: 10px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--accent); color: #fff; border-radius: 22px 22px 6px 22px; padding: 10px 16px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.msg.user img { display: block; max-width: 220px; border-radius: 14px; margin-bottom: 6px; }
.msg.bot .card { max-width: 92%; }
.chips { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.chip { display: flex; align-items: center; gap: 10px; border: 1.5px solid var(--line); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 15px; }
.chip .spin { width: 16px; height: 16px; border: 2.5px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.chip .ok { color: var(--ok); }
@keyframes spin { to { transform: rotate(360deg); } }
.dots span { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 5px; animation: blink 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: .2s; } .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.composer { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding: 10px 0 12px; background: transparent; }
.composer .box { display: flex; align-items: flex-end; gap: 8px; background: var(--card); border-radius: 28px; padding: 6px 6px 6px 16px; box-shadow: var(--shadow); border: 1.5px solid var(--line); }
.composer textarea { border: 0; padding: 10px 0; resize: none; max-height: 140px; background: transparent; }
.composer .roundbtn { width: 44px; height: 44px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--card); font-size: 20px; flex: none; display: inline-flex; align-items: center; justify-content: center; }
.composer .roundbtn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.composer .roundbtn.rec { background: var(--danger); border-color: var(--danger); color: #fff; }
.preview { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; }
.preview img { height: 56px; border-radius: 10px; }
.disclaimer { font-size: 12px; color: var(--muted); margin: 4px 0; }

/* Nav inferior */
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.tabs .in { max-width: 560px; margin: 0 auto; display: flex; height: var(--nav-h); }
nav.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--text); text-decoration: none; font-size: 13px; }
nav.tabs a .ic { font-size: 21px; padding: 3px 18px; border-radius: 999px; }
nav.tabs a.on { color: var(--accent-text); }
nav.tabs a.on .ic { background: var(--accent-soft); }

/* Login */
.login { max-width: 380px; margin: 0 auto; padding: 18vh 20px 40px; }
.login .logo { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.login form { display: flex; flex-direction: column; gap: 12px; margin-top: 24px; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-size: 14px; z-index: 60; }
