/* GymTracker (web app para iPhone): mismos colores que la web y la app de Android. Pensada para el móvil. */

:root {
    --primary: #E8590C;
    --primary-dark: #A63A00;
    --primary-soft: #FFE8CC;
    --dark: #1F1F1F;
    --bg: #F5F5F4;
    --surface: #FFFFFF;
    --text: #1F1F1F;
    --muted: #6E6E6E;
    --border: #E4E4E4;
    --danger: #E03131;
    --success: #2F9E44;
    --success-soft: #D3F9D8;
    /* Márgenes de la muesca y la barra de inicio del iPhone (0 en el resto). */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: -apple-system, "Segoe UI", system-ui, Roboto, sans-serif; }
body { -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
a { color: var(--primary-dark); }
p { margin: .5rem 0; }
.muted { color: var(--muted); font-size: .9rem; }
.center { text-align: center; }
.section { font-size: .75rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--primary); margin: 1rem 0 .4rem; }
.card .section:first-child { margin-top: 0; }

/* ---------- Barras ---------- */
.topbar { position: sticky; top: 0; z-index: 100; display: flex; align-items: center; gap: .5rem; min-height: 3.25rem;
    padding: calc(var(--safe-top) + .5rem) calc(var(--safe-right) + 1rem) .5rem calc(var(--safe-left) + 1rem); background: var(--dark); color: #fff; }
.topbar h1 { flex: 1; min-width: 0; font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-back { padding: 0 .5rem 0 0; border: 0; background: none; color: #fff; font: inherit; font-size: 2rem; line-height: 1; text-decoration: none; cursor: pointer; }
.topbar-actions { display: flex; gap: .5rem; }
.topbar-btn { padding: .4rem .75rem; border: 1px solid #555; border-radius: 8px; background: none; color: #fff; font: inherit; font-size: .95rem; cursor: pointer; }

.page { padding: 1rem calc(var(--safe-right) + 1rem) 1.5rem calc(var(--safe-left) + 1rem); max-width: 640px; margin: 0 auto; }
.with-tabs .page { padding-bottom: calc(var(--safe-bottom) + 5.5rem); }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 100; display: grid; grid-template-columns: 1fr 1fr;
    padding: .35rem var(--safe-right) calc(var(--safe-bottom) + .35rem) var(--safe-left); background: var(--surface); border-top: 1px solid var(--border); }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: .15rem; padding: .3rem; color: var(--muted); font-size: .75rem; font-weight: 600; text-decoration: none; }
.tabbar svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--primary); }

/* ---------- Componentes ---------- */
.card { display: block; margin-bottom: .75rem; padding: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
a.card { color: inherit; text-decoration: none; }
.card-active { display: flex; align-items: center; justify-content: space-between; gap: 1rem; background: var(--primary); border-color: var(--primary); color: #fff !important; }
.pill { padding: .05rem .4rem; border-radius: 6px; background: var(--primary); color: #fff; font-size: .7rem; font-weight: 700; }
.alert { margin-bottom: .75rem; padding: .75rem 1rem; border-radius: 10px; background: #FFE3E3; color: #A61E1E; }
.empty { padding: 2rem 1rem; text-align: center; }
.empty h3 { margin-bottom: .5rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .8rem 1rem; border: 1px solid transparent; border-radius: 12px;
    background: var(--primary); color: #fff; font: inherit; font-size: 1rem; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:active { filter: brightness(.92); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-secondary { background: var(--primary-soft); color: var(--primary-dark); }
.btn-danger { background: transparent; color: var(--danger); border-color: #F5C2C2; }
.btn-block { display: flex; width: 100%; margin-top: .75rem; }

/* 16px como mínimo: con menos, el iPhone hace zoom al tocar la casilla. */
input, textarea { width: 100%; padding: .7rem .8rem; border: 1px solid #CCC; border-radius: 10px; background: #fff; color: var(--text); font: inherit; font-size: 16px; }
input:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { min-height: 84px; resize: vertical; }
label { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; }

/* ---------- Login ---------- */
.login { display: flex; flex-direction: column; justify-content: center; min-height: 100dvh; max-width: 420px; margin: 0 auto;
    padding: calc(var(--safe-top) + 1.5rem) calc(var(--safe-right) + 1.25rem) calc(var(--safe-bottom) + 1.5rem) calc(var(--safe-left) + 1.25rem); }
.login-brand { margin-bottom: 1.25rem; text-align: center; }
.login-brand img { border-radius: 18px; }
.login-brand h1 { margin: .5rem 0 .25rem; font-size: 1.8rem; }
.login-brand h1 span { color: var(--primary); }
.login .btn { margin-top: 1.25rem; }

/* ---------- Mis entrenos ---------- */
.greeting { margin-bottom: 1rem; }
.sync-status { padding: 0; border: 0; background: none; color: var(--muted); font: inherit; font-size: .8rem; cursor: pointer; }
.sync-status.failed { color: var(--danger); }
.routine { display: flex; align-items: center; gap: .75rem; }
.routine-info { flex: 1; min-width: 0; }
.routine-day { display: flex; align-items: center; gap: .5rem; }
.routine-day .section { margin: 0; }
.routine h3 { margin: .2rem 0 .1rem; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-top: .35rem; }
.notes { margin-top: .35rem; font-size: .9rem; }
.play { display: grid; place-items: center; flex: none; width: 56px; height: 56px; border: 0; border-radius: 50%; background: var(--primary); cursor: pointer; }
.play svg { width: 26px; height: 26px; margin-left: 3px; fill: #fff; }

/* Hoja de acciones (menú de la cuenta) */
.sheet-backdrop { position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, .35); }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 201; padding: .25rem 0 calc(var(--safe-bottom) + .25rem); background: var(--surface); border-radius: 16px 16px 0 0; }
.sheet-title { display: flex; flex-direction: column; align-items: center; gap: .15rem; padding: 1rem; }
.sheet-item { display: block; width: 100%; padding: 1rem; border: 0; border-top: 1px solid var(--border); background: none; color: var(--primary-dark); font: inherit; font-size: 1.05rem; cursor: pointer; }
.sheet-item.danger { color: var(--danger); }

/* ---------- Entreno en curso ---------- */
.progress-head { padding: .6rem calc(var(--safe-right) + 1rem) 0 calc(var(--safe-left) + 1rem); max-width: 640px; margin: 0 auto; }
.progress-text { display: flex; justify-content: space-between; margin-bottom: .4rem; }
.progress { height: 6px; overflow: hidden; border-radius: 3px; background: var(--border); }
.progress div { height: 100%; background: var(--primary); transition: width .2s; }
.workout-page { padding-bottom: calc(var(--safe-bottom) + 10rem); }
.exercise-name { margin: .1rem 0 .2rem; font-size: 1.45rem; }

.sets-table { width: 100%; margin-top: .75rem; border-collapse: separate; border-spacing: 0 3px; table-layout: fixed; }
.sets-table th { padding: .3rem .1rem; color: var(--muted); font-size: .72rem; font-weight: 600; text-align: center; }
.sets-table th:nth-child(1) { width: 2.1rem; }
.sets-table th:nth-child(3) { width: 4.3rem; }
.sets-table th:nth-child(4) { width: 3.4rem; }
.sets-table th:nth-child(5) { width: 3rem; }
.sets-table th:nth-child(6) { width: 2.8rem; }
.sets-table td { padding: .2rem .1rem; text-align: center; vertical-align: middle; }
.sets-table .left { text-align: left; }
.sets-table input { padding: .55rem .15rem; text-align: center; }
.set-number { font-weight: 700; }
.previous { font-size: .75rem; overflow-wrap: anywhere; }
.sets-table tr.done td { background: var(--success-soft); }
.sets-table tr.done td:first-child { border-radius: 8px 0 0 8px; }
.sets-table tr.done td:last-child { border-radius: 0 8px 8px 0; }
.check { width: 2.5rem; height: 2.5rem; border: 2px solid #CCC; border-radius: 8px; background: #fff; color: transparent; font-size: 1.15rem; font-weight: 700; cursor: pointer; }
.check.on { background: var(--success); border-color: var(--success); color: #fff; }

.workout-bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 90; padding-bottom: var(--safe-bottom); background: var(--bg); border-top: 1px solid var(--border); }
.rest-bar { display: flex; align-items: center; gap: .5rem; padding: .6rem calc(var(--safe-right) + 1rem) .6rem calc(var(--safe-left) + 1rem); background: #2B2B2B; color: #fff; }
.rest-bar b { flex: 1; font-size: 1.15rem; }
.rest-bar button { padding: .5rem .8rem; border: 0; border-radius: 8px; background: #fff; color: var(--dark); font: inherit; font-weight: 600; cursor: pointer; }
.step-nav { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; max-width: 640px; margin: 0 auto; padding: .6rem calc(var(--safe-right) + 1rem) .6rem calc(var(--safe-left) + 1rem); }

/* ---------- Historial ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; text-align: center; }
.month-nav .btn { width: 3rem; padding: .6rem 0; font-size: 1.2rem; }
.history-head { display: block; color: inherit; text-decoration: none; }
.history-head .section { margin: 0; }
.history-head h3 { margin: .15rem 0; }
.history-detail summary { margin-top: .6rem; color: var(--primary-dark); font-size: .9rem; font-weight: 600; list-style: none; cursor: pointer; }
.history-detail summary::-webkit-details-marker { display: none; }
.history-detail summary::after { content: " ▾"; }
.history-detail[open] summary::after { content: " ▴"; }
.session-exercise { margin: .75rem 0; }
.session-exercise:first-child { margin-top: 0; }
.session-exercise:last-child { margin-bottom: 0; }
.session-exercise-head { display: flex; justify-content: space-between; gap: .75rem; margin-bottom: .2rem; }
.session-exercise-head a { color: inherit; text-decoration: none; }

.stats { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; gap: .5rem; margin: .75rem 0; }
.stats > div { padding: .65rem .5rem; border-radius: 10px; background: var(--bg); text-align: center; }
.stats > .card { margin: 0; background: var(--surface); }
.stats b { display: block; font-size: 1.1rem; }
.stats span { color: var(--muted); font-size: .75rem; }

/* ---------- Ejercicio ---------- */
.video { display: block; width: 100%; aspect-ratio: 16 / 9; margin-bottom: .25rem; border: 0; border-radius: 14px; background: #000; }
.video + .btn { margin: .5rem 0 .75rem; }

/* ---------- Carga y errores ---------- */
.splash { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; background: var(--dark); color: #fff; }
.splash img { border-radius: 22px; }
.loading-progress-text::after { content: var(--blazor-load-percentage-text, "Cargando"); }
#blazor-error-ui { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000; display: none; padding: .75rem 1.25rem calc(var(--safe-bottom) + .75rem); background: lightyellow; box-shadow: 0 -1px 2px rgba(0, 0, 0, .2); }
#blazor-error-ui .dismiss { position: absolute; top: .6rem; right: .9rem; cursor: pointer; }
