:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1a1a);
  --hint: var(--tg-theme-hint-color, #8a8a8f);
  --link: var(--tg-theme-link-color, #2b7cd3);
  --button: var(--tg-theme-button-color, #2b7cd3);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --section: var(--tg-theme-section-bg-color, var(--card));
  --danger: #d1453b;
  --ok: #2e9e5b;
  --warn: #c7841c;
  --r: 14px;
  --gap: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }

/* ---------- pantallas de estado ---------- */
.center {
  min-height: 75vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 32px 24px; gap: 10px;
}
.center h2 { margin: 0; font-size: 19px; }
.center p { margin: 0; color: var(--hint); max-width: 30ch; }

.spinner {
  width: 30px; height: 30px;
  border: 3px solid var(--card);
  border-top-color: var(--button);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- cabecera ---------- */
header {
  padding: 14px 16px 10px;
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
}
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
header h1 { font-size: 18px; margin: 0; letter-spacing: -.2px; }
header .sub { font-size: 12px; color: var(--hint); margin-top: 1px; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  background: var(--card); color: var(--hint);
  text-transform: uppercase; letter-spacing: .5px; white-space: nowrap;
}
.badge.admin { background: #e3edfd; color: #1a5fb4; }
.badge.superadmin { background: #fce4e4; color: #a61b1b; }
.badge.ok { background: #e3f5ea; color: #1d7a45; }
.badge.warn { background: #fdf0dd; color: #8a5300; }
.badge.danger { background: #fce4e4; color: #a61b1b; }

.banner {
  margin-top: 12px; padding: 10px 12px; border-radius: var(--r);
  font-size: 13px; background: #fdf0dd; color: #7a4a00;
  border-left: 3px solid var(--warn);
}
.banner.danger { background: #fce4e4; color: #8a1b1b; border-left-color: var(--danger); }

/* ---------- navegación ---------- */
nav {
  display: flex; gap: 6px; overflow-x: auto;
  padding: 4px 16px 12px; scrollbar-width: none;
  border-bottom: 1px solid var(--card);
  position: sticky; top: 56px; z-index: 19; background: var(--bg);
}
nav::-webkit-scrollbar { display: none; }
nav button {
  flex: 0 0 auto; border: 0; background: var(--card); color: var(--text);
  padding: 8px 14px; border-radius: 999px; font-size: 14px; cursor: pointer;
  font-family: inherit; display: flex; align-items: center; gap: 6px;
}
nav button.active { background: var(--button); color: var(--button-text); font-weight: 600; }
nav .dot {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
nav button.active .dot { background: rgba(255,255,255,.28); }

/* sub-navegación dentro de una sección */
.subnav { display: flex; gap: 4px; margin-bottom: 14px; background: var(--card); padding: 3px; border-radius: 10px; }
.subnav button {
  flex: 1; border: 0; background: transparent; color: var(--hint);
  padding: 7px 4px; border-radius: 8px; font-size: 13px; cursor: pointer;
  font-family: inherit; font-weight: 500; white-space: nowrap;
}
.subnav button.active { background: var(--bg); color: var(--text); font-weight: 600; }

main { padding: 16px; }

h2.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .6px;
         color: var(--hint); margin: 22px 0 8px; font-weight: 700; }
h2.sec:first-child { margin-top: 0; }

/* ---------- tarjetas ---------- */
.card { background: var(--card); border-radius: var(--r); padding: 13px 14px; margin-bottom: var(--gap); }
.card h3 { margin: 0 0 3px; font-size: 15px; font-weight: 600; line-height: 1.3; }
.card .meta { font-size: 13px; color: var(--hint); line-height: 1.45; }
.card.pin { border-left: 3px solid var(--button); }

.row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.due { color: var(--danger); }
.amount.ok  { color: var(--ok); }

/* tarjeta de acción: cosas que requieren atención */
.action {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: var(--card); border: 0; border-radius: var(--r);
  padding: 13px 14px; margin-bottom: var(--gap); cursor: pointer;
  font-family: inherit; font-size: 15px; color: var(--text);
}
.action .n {
  min-width: 30px; height: 30px; border-radius: 9px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums;
  background: var(--button); color: var(--button-text);
}
.action .n.alert { background: var(--danger); }
.action .n.calm  { background: rgba(127,127,127,.18); color: var(--hint); }
.action .txt { flex: 1; min-width: 0; }
.action .txt small { display: block; color: var(--hint); font-size: 12.5px; }
.action .arrow { color: var(--hint); font-size: 18px; flex: 0 0 auto; }

/* ---------- métricas ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--gap); margin-bottom: 4px; }
.stat { background: var(--card); border-radius: var(--r); padding: 12px 13px; }
.stat .label { font-size: 11.5px; color: var(--hint); text-transform: uppercase;
               letter-spacing: .5px; font-weight: 600; }
.stat .value { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums;
               margin-top: 3px; letter-spacing: -.5px; }
.stat .value.due { color: var(--danger); }
.stat .value.ok  { color: var(--ok); }
.stat .foot { font-size: 11.5px; color: var(--hint); margin-top: 2px; }
.stat.wide { grid-column: 1 / -1; }

/* barra de progreso */
.bar { height: 6px; background: rgba(127,127,127,.18); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.bar > i.low { background: var(--warn); }
.bar > i.bad { background: var(--danger); }

/* ---------- formularios ---------- */
label { display: block; font-size: 13px; color: var(--hint); margin: 12px 0 4px; font-weight: 500; }
label.inline { display: flex; align-items: center; gap: 8px; margin: 14px 0 0; color: var(--text); }
label.inline input { width: auto; margin: 0; }
input, textarea, select {
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid transparent; background: var(--bg); color: var(--text);
  font-size: 16px; font-family: inherit;
}
.card input, .card textarea, .card select { background: var(--bg); }
textarea { min-height: 88px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--button); }

button.primary {
  width: 100%; border: 0; background: var(--button); color: var(--button-text);
  padding: 13px; border-radius: 11px; font-size: 15px; font-weight: 600;
  cursor: pointer; margin-top: 12px; font-family: inherit;
}
button.ghost {
  border: 1px solid rgba(127,127,127,.3); background: transparent; color: var(--text);
  padding: 9px 14px; border-radius: 10px; font-size: 14px; cursor: pointer;
  font-family: inherit; font-weight: 500;
}
button.ghost.danger { color: var(--danger); border-color: rgba(209,69,59,.4); }
button:disabled { opacity: .5; cursor: not-allowed; }
.acts { display: flex; gap: 8px; margin-top: 11px; }
.acts button { flex: 1; }

.empty { text-align: center; color: var(--hint); padding: 44px 20px; font-size: 14px; }
.empty .big { font-size: 28px; display: block; margin-bottom: 8px; opacity: .5; }
.error   { color: var(--danger); font-size: 13px; margin-top: 8px; }
.success { color: var(--ok); font-size: 13px; margin-top: 8px; }
.note { font-size: 12.5px; color: var(--hint); margin-top: 12px; line-height: 1.5; }

.list-line { display: flex; justify-content: space-between; gap: 10px;
             padding: 8px 0; border-bottom: 1px solid rgba(127,127,127,.12); font-size: 14px; }
.list-line:last-child { border-bottom: 0; }
.list-line .k { color: var(--hint); min-width: 0; }

/* ---------- modal de bienvenida ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal-box {
  background: var(--bg); width: 100%; max-width: 520px;
  border-radius: 20px 20px 0 0; padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: up .28s cubic-bezier(.2,.8,.3,1);
}
@keyframes up { from { transform: translateY(100%); } }
.modal-box h2 { margin: 0 0 4px; font-size: 21px; letter-spacing: -.3px; }
.modal-box .lead { color: var(--hint); font-size: 14px; margin: 0 0 18px; }

.steps { list-style: none; margin: 0 0 18px; padding: 0; }
.steps li {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 11px 0; border-bottom: 1px solid rgba(127,127,127,.12);
}
.steps li:last-child { border-bottom: 0; }
.steps .num {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 8px;
  background: var(--button); color: var(--button-text);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.steps .t { flex: 1; font-size: 14.5px; line-height: 1.45; }
.steps .t b { font-weight: 600; }
.steps .t small { display: block; color: var(--hint); font-size: 13px; margin-top: 2px; }

/* ---------- reservas ---------- */
.slot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 11px; border-radius: 9px; margin-bottom: 6px;
  background: rgba(127,127,127,.1); font-size: 13.5px;
}
.slot.mine { background: rgba(43,124,211,.14); }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.chip {
  border: 1px solid rgba(127,127,127,.3); background: transparent;
  color: var(--text); padding: 6px 11px; border-radius: 999px;
  font-size: 13px; cursor: pointer; font-family: inherit;
}
.chip.on { background: var(--button); color: var(--button-text); border-color: transparent; }
.chip:disabled { opacity: .35; cursor: not-allowed; text-decoration: line-through; }
