:root {
  --brand: #E8730C;
  --brand-dark: #C95F05;
  --brand-soft: #FDEBDC;
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --text: #1F2328;
  --muted: #6B7280;
  --line: #E5E7EB;
  --ok: #15803D;      --ok-soft: #DCFCE7;
  --warn: #B45309;    --warn-soft: #FEF3C7;
  --bad: #B91C1C;     --bad-soft: #FEE2E2;
  --off: #4B5563;     --off-soft: #E5E7EB;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.06);
  --top: 60px;
  --nav: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111315; --surface: #1B1E21; --text: #ECEDEE; --muted: #9BA1A6; --line: #2B2F33;
    --brand-soft: #3A2412; --ok-soft: #12301E; --warn-soft: #3A2C10; --bad-soft: #3B1616; --off-soft: #2B2F33;
    --ok: #4ADE80; --warn: #FBBF24; --bad: #F87171; --off: #9CA3AF;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Rubik', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
svg { display: block; flex-shrink: 0; }

/* ---------- Splash / auth ---------- */
.splash { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--brand-soft); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, var(--brand) 0 38%, var(--bg) 38%); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.auth-logo img { width: 44px; height: 44px; }
.auth-logo h1 { margin: 0; font-size: 24px; }
.auth p.lead { color: var(--muted); margin: 4px 0 20px; }
.auth .links { display: flex; justify-content: space-between; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.linkbtn { background: none; border: 0; color: var(--brand); padding: 4px 0; font-weight: 500; }
.center-msg { text-align: center; }
.center-msg .big-ic { width: 64px; height: 64px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; margin: 0 auto 12px; }

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); outline: none; min-height: 46px;
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; margin: 4px 0 16px; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 12px 18px; min-height: 46px; font-weight: 600;
  background: var(--brand); color: #fff; text-decoration: none;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: var(--bad); }
.btn.wa { background: #1FA855; }
.btn.small { min-height: 36px; padding: 8px 12px; font-size: 14px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1 1 140px; }
.err { color: var(--bad); font-size: 14px; margin: 8px 0 0; min-height: 1em; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--top);
  background: var(--brand); color: #fff; display: flex; align-items: center; gap: 6px;
  padding: 0 8px; padding-top: env(safe-area-inset-top);
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
}
.topbar .title { flex: 1; min-width: 0; line-height: 1.15; }
.topbar .title div { font-size: 20px; font-weight: 600; letter-spacing: .3px; }
.topbar .title small { display: block; opacity: .85; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: inherit; }
.icon-btn:hover { background: rgba(127,127,127,.15); }

main#view { max-width: 1100px; margin: 0 auto; padding: 0 0 calc(var(--nav) + 90px); }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--nav) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--brand); display: flex; justify-content: center;
}
.bottomnav button {
  flex: 1; max-width: 200px; background: none; border: 0; color: rgba(255,255,255,.75);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px;
}
.bottomnav button.active { color: #fff; font-weight: 600; }
.bottomnav button.active svg { transform: scale(1.1); }

.fab {
  position: fixed; right: max(18px, calc(50% - 550px + 18px)); bottom: calc(var(--nav) + 18px + env(safe-area-inset-bottom)); z-index: 25;
  width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--brand); color: #fff;
  display: grid; place-items: center; box-shadow: 0 6px 16px rgba(232,115,12,.45);
}
.fab:hover { background: var(--brand-dark); }

.banner { margin: 10px 12px 0; padding: 10px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 14px; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- Clientes ---------- */
.toolbar { position: sticky; top: var(--top); z-index: 10; background: var(--bg); padding: 10px 12px 6px; }
.search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; color: var(--muted); }
.search input { flex: 1; border: 0; outline: none; background: none; padding: 12px 0; min-width: 0; color: var(--text); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 500; }
.chip b { margin-left: 4px; font-weight: 600; }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.group { margin: 8px 12px 0; }
.group-h {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--surface); border: 0; border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.group-h .gname { font-size: 17px; font-weight: 600; letter-spacing: .3px; }
.group-h .badge { background: var(--bg); color: var(--muted); border-radius: 6px; padding: 2px 8px; font-size: 13px; }
.group-h .count { margin-left: auto; font-weight: 600; color: var(--muted); }
.group-h svg { color: var(--muted); transition: transform .2s; }
.group-h.closed svg { transform: rotate(-90deg); }
.group-h .dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.VIGENTE { background: var(--ok); } .dot.VENCIDO { background: var(--bad); } .dot.INACTIVO { background: var(--off); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 8px; margin-top: 8px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; padding: 12px 12px 8px;
}
.avatar {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 600; font-size: 16px; background: var(--brand-soft); color: var(--brand); grid-row: span 2;
}
.avatar.INACTIVO { background: var(--off-soft); color: var(--off); }
.card .info { min-width: 0; cursor: pointer; }
.card .name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.card .sub .when.VENCIDO { color: var(--bad); } .card .sub .when.VIGENTE { color: var(--ok); } .card .sub .when.INACTIVO { color: var(--off); }
.card .actions { display: flex; justify-content: flex-end; gap: 2px; }
.card .actions .icon-btn { color: var(--muted); width: 42px; height: 42px; }
.card .actions .icon-btn:hover { color: var(--brand); }
.card .actions .icon-btn.wa:hover { color: #1FA855; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: .3px; }
.pill.VIGENTE { background: var(--ok-soft); color: var(--ok); }
.pill.VENCIDO { background: var(--bad-soft); color: var(--bad); }
.pill.INACTIVO { background: var(--off-soft); color: var(--off); }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.loading { display: grid; place-items: center; padding: 60px; }
.more { display: block; margin: 10px auto 0; }

/* ---------- Secciones genéricas ---------- */
.section { margin: 12px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.section h3 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.section p.hint { color: var(--muted); font-size: 14px; margin: -4px 0 12px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 12px; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.kpi .k-label { color: var(--muted); font-size: 13px; }
.kpi .k-val { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi.ok .k-val { color: var(--ok); } .kpi.bad .k-val { color: var(--bad); } .kpi.off .k-val { color: var(--off); }

.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li .grow { flex: 1; min-width: 0; }
.li .t { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .s { color: var(--muted); font-size: 13px; }
.li .amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.ingreso { color: var(--ok); } .amt.gasto { color: var(--bad); }

.monthbar { display: flex; align-items: center; gap: 8px; margin: 12px 12px 0; }
.monthbar .input { flex: 1; }

/* Gráfico de barras */
.bars { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; align-items: end; height: 180px; padding-top: 10px; }
.bar-col { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bar { width: 40%; max-width: 22px; border-radius: 4px 4px 0 0; min-height: 2px; }
.bar.in { background: var(--brand); } .bar.out { background: var(--off); opacity: .6; }
.bar-col small { color: var(--muted); font-size: 12px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.hbar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.hbar > div { height: 100%; background: var(--brand); }

/* ---------- Modal (hoja inferior en celular) ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.modal {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom); animation: up .2s ease-out;
}
.modal-h { position: sticky; top: 0; background: var(--surface); display: flex; align-items: center; padding: 10px 8px 6px 18px; border-bottom: 1px solid var(--line); z-index: 1; }
.modal-h h2 { flex: 1; margin: 0; font-size: 18px; }
.modal-b { padding: 16px 18px 20px; }
@media (min-width: 700px) {
  .modal-wrap { align-items: center; }
  .modal { border-radius: 18px; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }

.detail-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.detail-head .avatar { width: 58px; height: 58px; font-size: 20px; }
.detail-head h3 { margin: 0 0 4px; font-size: 19px; }
.kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
.kv div { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.kv small { display: block; color: var(--muted); font-size: 12px; }
.kv b { font-weight: 600; word-break: break-word; }
.preview { background: var(--brand-soft); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; }
.success { text-align: center; padding: 10px 0; }
.success .big-ic { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; margin: 0 auto 12px; }

/* ---------- Drawer ---------- */
.drawer-wrap { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.45); animation: fade .15s; }
.drawer { position: absolute; top: 0; bottom: 0; left: 0; width: min(320px, 86vw); background: var(--surface); display: flex; flex-direction: column; animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(-40px); opacity: .5; } }
.drawer-h { background: var(--brand); color: #fff; padding: calc(22px + env(safe-area-inset-top)) 18px 18px; }
.drawer-h b { display: block; font-size: 18px; }
.drawer-h small { opacity: .85; word-break: break-all; }
.drawer nav { flex: 1; overflow: auto; padding: 8px 0; }
.drawer .d-label { padding: 12px 18px 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.drawer .d-item { width: 100%; display: flex; align-items: center; gap: 14px; background: none; border: 0; padding: 12px 18px; text-align: left; }
.drawer .d-item:hover { background: var(--bg); }
.drawer .d-item.current { color: var(--brand); font-weight: 600; }

/* ---------- Admin ---------- */
.gym-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.gym-card h4 { margin: 0 0 6px; font-size: 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.gym-card .s { color: var(--muted); font-size: 13px; margin-bottom: 4px; word-break: break-word; }
.gym-card .btn-row { margin-top: 10px; }
.gym-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; margin: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav) + 90px); transform: translateX(-50%); z-index: 90;
  background: #1F2328; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow);
  max-width: calc(100% - 32px); font-size: 14px; animation: fade .2s;
}
.toast.bad { background: var(--bad); }

@media (min-width: 900px) {
  .topbar { padding: 0 16px; }
  .group, .section { margin-left: 16px; margin-right: 16px; }
  .toolbar { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
  .row2 { grid-template-columns: 1fr; }
}
