:root {
  --bg: #f4f5f7; --panel: #fff; --text: #16191d; --muted: #6b7380; --line: #e4e7eb; --accent: #ff6b1a; --accent-soft: #fff0e6;
  --ok: #148a43; --ok-soft: #e3f6ea; --warn: #b26b00; --warn-soft: #fff4dc; --bad: #c62f34; --bad-soft: #fde8e8;
  --side: #10151b; --side-text: #c7ced8; --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
a { color: inherit; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 17px; padding: 0 8px 8px; }
.logo img { width: 30px; height: 30px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow: auto; }
nav a { text-decoration: none; padding: 9px 12px; border-radius: 8px; font-size: 14.5px; }
nav a:hover { background: #1b232c; }
nav a.on { background: var(--accent); color: #fff; }
.me { border-top: 1px solid #222b35; padding: 12px 8px 0; display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.topbar { display: none; }
.view { padding: 28px 32px 60px; max-width: 1280px; width: 100%; }
body:not(.is-admin) .admin-only { display: none !important; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 20; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .topbar { display: flex; gap: 12px; align-items: center; padding: 12px 16px; background: var(--side); color: #fff; position: sticky; top: 0; z-index: 10; }
  .burger { background: none; border: 0; color: #fff; font-size: 22px; }
  .view { padding: 18px 16px 60px; }
}

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.two { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.kpi { cursor: default; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: 12.5px; margin-top: 2px; }
a.kpi { text-decoration: none; display: block; cursor: pointer; }
a.kpi:hover { border-color: var(--accent); }
.up { color: var(--ok); } .down { color: var(--bad); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1; min-width: 200px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { border: 1px solid var(--line); background: var(--panel); padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 13.5px; }
.pill.on { background: var(--text); color: #fff; border-color: var(--text); }

input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 14px; }
.form .full { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; background: var(--panel); }
legend { font-weight: 650; padding: 0 6px; }
.req::after { content: " *"; color: var(--bad); }

.btn { font: inherit; font-weight: 600; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 9px 16px; border-radius: 8px; cursor: pointer; white-space: nowrap; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: #c9ced5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #ea5c0f; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wa { background: #25d366; border-color: #25d366; color: #fff; }
.link { background: none; border: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-top: 16px; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #fafbfc; }
td.r, th.r { text-align: right; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.b-active, .b-ok { background: var(--ok-soft); color: var(--ok); }
.b-expiring, .b-grace, .b-warning { background: var(--warn-soft); color: var(--warn); }
.b-expired, .b-no_plan, .b-not_found, .b-denied { background: var(--bad-soft); color: var(--bad); }
.b-inactive { background: #eceef1; color: var(--muted); }

.list { display: flex; flex-direction: column; }
.list .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list .row:last-child { border-bottom: 0; }
.list .row a { text-decoration: none; font-weight: 600; }

.bars { display: flex; align-items: flex-end; gap: 4px; height: 150px; padding-top: 10px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; height: 100%; min-width: 0; }
.bars .b i { display: block; width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .b span { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.bars .b em { font-size: 10.5px; font-style: normal; color: var(--text); white-space: nowrap; }
.hbars .hb { display: grid; grid-template-columns: 140px 1fr auto; gap: 10px; align-items: center; padding: 5px 0; font-size: 13.5px; }
.hbars .hb div { background: #f0f1f3; border-radius: 4px; height: 10px; overflow: hidden; }
.hbars .hb div i { display: block; height: 100%; background: var(--accent); }
.hbars .hb span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.profile-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 18px; }
.status-box { border-radius: var(--radius); padding: 16px 20px; display: flex; gap: 18px; align-items: center; margin-bottom: 16px; }
.status-box .big { font-size: 34px; font-weight: 800; line-height: 1; }
.st-active { background: var(--ok-soft); color: var(--ok); }
.st-expiring, .st-grace { background: var(--warn-soft); color: var(--warn); }
.st-expired, .st-no_plan { background: var(--bad-soft); color: var(--bad); }
.st-inactive { background: #eceef1; color: var(--muted); }
dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; }

.modal { position: fixed; inset: 0; background: rgba(10,14,20,.5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: #fff; border-radius: 14px; padding: 22px; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100px); background: var(--text); color: #fff; padding: 11px 20px; border-radius: 10px; transition: transform .2s; z-index: 60; max-width: 90vw; }
.toast.show { transform: translateX(-50%); }
.toast.err { background: var(--bad); }

.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: var(--side); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .card img { width: 48px; }
.auth form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.summary { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.summary:last-child { border: 0; font-weight: 700; }

/* ---------- contraseñas con ojito ---------- */
.pw { position: relative; display: block; }
.pw input { padding-right: 48px; }
.eye { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 44px; height: 40px; border: 0; background: none;
  color: var(--muted); cursor: pointer; display: grid; place-items: center; border-radius: 8px; }
.eye:hover { color: var(--text); }

/* ---------- mientras se guarda: sin dobles toques ---------- */
body.busy form button, body.busy .modal-box button, body.busy [data-pay], body.busy #pay, body.busy #checkin { pointer-events: none; opacity: .55; }
body.busy { cursor: progress; }
.btn.danger-solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.toast { cursor: pointer; }

/* ---------- táctil ---------- */
html { -webkit-text-size-adjust: 100%; }
button, a, input, select, textarea, tr.click, .pill { touch-action: manipulation; -webkit-tap-highlight-color: rgba(255,107,26,.15); }
@media (pointer: coarse) {
  .btn { min-height: 46px; padding: 10px 18px; }
  .btn.small { min-height: 40px; padding: 8px 14px; font-size: 14px; }
  .pill { padding: 10px 16px; font-size: 15px; }
  nav a { padding: 13px 14px; font-size: 16px; }
  input, select, textarea { font-size: 16px; min-height: 46px; }
  th, td { padding: 13px 14px; }
  .list .row { padding: 12px 0; }
  .link { padding: 8px 4px; }
}
/* 16px evita que el celular haga zoom al tocar un campo */
@media (max-width: 860px) {
  input, select, textarea { font-size: 16px; }
  .view { padding-bottom: 90px; }
  .profile-head > div:last-child { width: 100%; }
  .profile-head .btn { flex: 1 1 auto; justify-content: center; }
  .toolbar input[type=date] { flex: 1 1 140px; }
  .hide-sm { display: none; }
  .hbars .hb { grid-template-columns: 110px 1fr auto; }
  .modal { align-items: flex-end; padding: 0; }
  .modal-box { border-radius: 16px 16px 0 0; max-height: 94vh; padding-bottom: calc(22px + env(safe-area-inset-bottom)); }
  .kpi .value { font-size: 24px; }
}
@media (max-width: 480px) {
  .form { grid-template-columns: 1fr; }
  .two { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 21px; }
}

/* las tablas anchas se desplazan dentro de su recuadro sin estirar la página */
.app > *, .view, .card, .grid > * { min-width: 0; }
@media (max-width: 860px) { .app { grid-template-columns: minmax(0, 1fr); } }
.table-wrap { -webkit-overflow-scrolling: touch; max-width: 100%; }
fieldset { min-width: 0; max-width: 100%; }
