:root {
  --bg: #f4f6fb; --card: #ffffff; --txt: #0f172a; --sub: #64748b; --borde: #e2e8f0;
  --pri: #16a34a; --pri-osc: #15803d; --acento: #0ea5e9; --peligro: #dc2626;
  --fuerza: #6366f1; --cardio: #f97316; --hiit: #e11d48; --movilidad: #14b8a6; --deporte: #0ea5e9; --descanso_activo: #a3a3a3;
  --radio: 14px; --sombra: 0 1px 3px rgba(15,23,42,.08), 0 4px 14px rgba(15,23,42,.05);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --card: #131c2e; --txt: #e2e8f0; --sub: #94a3b8; --borde: #23304a; --sombra: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--txt); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: #0f172a; color: #fff; }
.brand { display: flex; gap: 8px; align-items: center; font-weight: 700; font-size: 18px; }
.topbar select { max-width: 55%; background: #1e293b; color: #fff; border: 1px solid #334155; border-radius: 10px; padding: 7px 10px; font-size: 14px; }

main { max-width: 900px; margin: 0 auto; padding: 16px; }
h2 { margin: 4px 0 12px; font-size: 20px; }
h3 { margin: 0 0 8px; font-size: 16px; }
.sub { color: var(--sub); font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px; margin-bottom: 12px; box-shadow: var(--sombra); }
.fila { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.entre { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stat { background: var(--bg); border-radius: 10px; padding: 10px; }
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--sub); font-size: 12px; }

label { display: block; font-size: 13px; color: var(--sub); margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--txt); background: var(--card); border: 1px solid var(--borde); border-radius: 10px; padding: 9px 10px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--acento); outline-offset: 0; }
.campo { margin-bottom: 10px; }
.dias { display: flex; gap: 6px; flex-wrap: wrap; }
.dias label { display: inline-flex; align-items: center; gap: 4px; padding: 6px 10px; border: 1px solid var(--borde); border-radius: 999px; color: var(--txt); cursor: pointer; margin: 0; }
.dias input { width: auto; }

button, .btn { font: inherit; border: 0; border-radius: 10px; padding: 9px 14px; cursor: pointer; background: var(--pri); color: #fff; font-weight: 600; }
button:hover { background: var(--pri-osc); }
button.sec { background: var(--bg); color: var(--txt); border: 1px solid var(--borde); }
button.peligro { background: var(--peligro); }
button.chico { padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: .6; cursor: wait; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--borde); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { background: none; color: var(--sub); border-radius: 0; padding: 8px 2px 9px; font-size: 11px; font-weight: 500; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabs button span { font-size: 20px; }
.tabs button.activo { color: var(--pri); }

/* Calendario */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: 12px; color: var(--sub); padding: 4px 0; }
.cal .dia { min-height: 64px; background: var(--card); border: 1px solid var(--borde); border-radius: 10px; padding: 4px; cursor: pointer; overflow: hidden; }
.cal .dia.fuera { opacity: .4; }
.cal .dia.hoy { border-color: var(--pri); box-shadow: inset 0 0 0 1px var(--pri); }
.cal .num { font-size: 12px; font-weight: 600; }
.cal .pt { display: block; font-size: 10px; color: #fff; border-radius: 5px; padding: 1px 4px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal .pt.hecho { text-decoration: line-through; opacity: .7; }
@media (max-width: 520px) { .cal .pt { font-size: 0; height: 6px; padding: 0; } .cal .dia { min-height: 52px; } }

.chip { display: inline-block; font-size: 11px; font-weight: 600; color: #fff; border-radius: 999px; padding: 2px 8px; }
.ent { border-left: 4px solid var(--fuerza); }
.ent.hecho { opacity: .65; }
.ejs { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; }
.ejs th, .ejs td { text-align: left; padding: 5px 4px; border-bottom: 1px solid var(--borde); vertical-align: top; }
.ejs th { color: var(--sub); font-weight: 500; }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; margin-bottom: 10px; }
.msg { padding: 9px 12px; border-radius: 12px; max-width: 88%; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: var(--pri); color: #fff; }
.msg.assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--borde); }

.vacio { text-align: center; color: var(--sub); padding: 24px 8px; }
.lista-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--borde); }
.lista-item:last-child { border-bottom: 0; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100% - 24px)); max-height: 88vh; background: var(--card); color: var(--txt); }
dialog::backdrop { background: rgba(2,6,23,.55); }
#modalCuerpo { padding: 16px; }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; }
#toast.ver { opacity: 1; }
.cargando::after { content: ""; display: inline-block; width: 14px; height: 14px; margin-left: 8px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: gira .7s linear infinite; vertical-align: -2px; }
@keyframes gira { to { transform: rotate(360deg); } }
svg.graf { width: 100%; height: 120px; }

body.login .tabs, body.login #btnSalir, body.login #clienteActivo { display: none; }
.topbar .fila { flex-wrap: nowrap; }
.topbar button.sec { background: #1e293b; color: #fff; border-color: #334155; }
#nombreYo { font-size: 14px; color: #cbd5e1; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[hidden] { display: none !important; }
