:root {
  --bg: var(--tg-theme-bg-color, #0f1720);
  --bg2: var(--tg-theme-secondary-bg-color, #17212b);
  --text: var(--tg-theme-text-color, #f1f5f9);
  --muted: var(--tg-theme-hint-color, #8b9bab);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #62bcf9);
  --danger: #ef5350;
  --ok: #43a047;
  --warn: #f9a825;
  --radius: 14px;
  --border: rgba(127, 127, 127, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; padding: 24px 0; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.update-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px; background: rgba(249, 168, 37, 0.15); font-size: 14px; line-height: 1.4;
}
.update-banner .btn { padding: 8px 12px; white-space: nowrap; }
.bloqueada { pointer-events: none; opacity: 0.4; }
.login-espera { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%; line-height: 1.4; text-align: center; }
.logout-btn { display: block; margin: 16px auto 0; color: var(--muted); }
.brand { font-weight: 700; font-size: 17px; }
.saldo-chip {
  border: 1px solid var(--border); background: var(--bg2); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600;
  display: inline-flex; gap: 8px; align-items: center; white-space: nowrap;
}
.chip-bono { color: var(--muted); font-weight: 500; }

main { padding: 12px; max-width: 560px; margin: 0 auto; }

.card {
  background: var(--bg2);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; margin-bottom: 10px;
}
.login-card h1 { margin: 4px 0 8px; font-size: 22px; }
.login-widget { display: flex; justify-content: center; margin: 18px 0 6px; min-height: 48px; }

.label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.label:first-child { margin-top: 0; }

.row { display: flex; gap: 8px; align-items: stretch; }
.row > .input { flex: 1; min-width: 0; }
.row > .btn { flex: 1; }
.row > .btn-secondary:first-child { flex: 0 0 auto; }

.input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.input:focus { border-color: var(--accent); }
.select { flex: 0 0 92px !important; }

.btn {
  border: 0; border-radius: 10px; padding: 12px 14px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  text-align: center; text-decoration: none; display: inline-block;
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-block { display: block; width: 100%; margin-top: 12px; }
.btn-sm { padding: 6px 12px; font-size: 13px; flex-shrink: 0; }

.retiro-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.retiro-item:last-child { border-bottom: 0; }
.link-btn { background: none; border: 0; color: var(--link); font-size: 14px; cursor: pointer; padding: 4px; }

.seg { display: flex; gap: 6px; margin-bottom: 8px; }
.seg button {
  flex: 1; padding: 10px 6px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg2); color: var(--text);
  font-size: 14px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.seg button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.seg button:disabled { opacity: 0.45; }
.seg button .estado { font-size: 11px; font-weight: 500; opacity: 0.85; }
.seg-small button { padding: 8px 4px; font-size: 13px; background: var(--bg); }

.horario { font-size: 12px; margin: 0 4px 10px; line-height: 1.5; }
.hint { font-size: 12px; margin-top: 6px; min-height: 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border);
  font-weight: 600; font-variant-numeric: tabular-nums;
}
.chip button { background: none; border: 0; color: var(--muted); font-size: 15px; padding: 0; cursor: pointer; }

.ticket-list { list-style: none; margin: 0; padding: 0; }
.ticket-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.ticket-list li:last-child { border-bottom: 0; }
.ticket-list .tipo { color: var(--muted); font-size: 13px; margin-right: 6px; }
.ticket-list .num { font-weight: 700; word-break: break-word; }
.ticket-list .der { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.ticket-list li:not(.ticket-tipo) { gap: 12px; }
.ticket-list li.ticket-tipo { color: var(--muted); font-size: 13px; padding: 10px 0 2px; border-bottom: 0; }
.ticket-list .quitar { background: none; border: 0; color: var(--danger); font-size: 18px; cursor: pointer; padding: 0 2px; }
.ticket-empty { color: var(--muted); padding: 8px 0; }
.ticket-total { font-weight: 700; margin-top: 8px; text-align: right; }

.review-section { margin-bottom: 12px; }
.review-section h4 { margin: 0 0 6px; font-size: 14px; }
.review-line { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.review-line.bad { color: var(--danger); }
.review-aviso { padding: 6px 0; line-height: 1.4; white-space: pre-line; border-bottom: 1px solid var(--border); }
.review-aviso:last-child { border-bottom: 0; }
.review-saldo { padding: 8px 0; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.review-saldo:last-child { margin-bottom: 8px; }
.tag { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: rgba(249, 168, 37, 0.2); color: var(--warn); margin-left: 6px; }

.saldos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.saldo-box { background: var(--bg); border-radius: 12px; padding: 12px; }
.saldo-box .moneda { color: var(--muted); font-size: 12px; }
.saldo-box .valor { font-size: 20px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.saldo-box.bono { grid-column: span 2; }
.saldo-box .nota { font-size: 11px; color: var(--muted); margin-top: 2px; }

.acciones-dinero { margin-bottom: 12px; }
.opciones { display: flex; flex-wrap: wrap; gap: 6px; }
.opciones button {
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer;
}
.opciones button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.recarga-datos {
  background: var(--bg); border-radius: 12px; padding: 12px; margin-top: 12px;
  white-space: pre-wrap; line-height: 1.6; word-break: break-word;
}
.copiable {
  display: inline; border: 0; border-radius: 6px; padding: 1px 6px; margin: 0 1px;
  background: rgba(46, 166, 255, 0.15); color: var(--link); cursor: pointer;
  font-family: ui-monospace, Menlo, monospace; font-size: 14px; white-space: normal; word-break: break-all;
}

.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); margin-top: 12px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.aviso-ok {
  margin-bottom: 12px; padding: 10px 12px; border-radius: 10px; line-height: 1.5;
  background: rgba(67, 160, 71, 0.15);
}

.jug-loteria { margin-bottom: 14px; }
.jug-loteria h4 { margin: 0 0 6px; }
.jug-tipo { margin: 6px 0 2px; color: var(--muted); font-size: 13px; }
.jug-item { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-variant-numeric: tabular-nums; }
.jug-item > span:last-child { white-space: nowrap; font-weight: 600; }
.jug-nums { word-break: break-word; }
.jug-total { text-align: right; font-weight: 700; margin-top: 4px; }
.quitar-btn { background: none; border: 0; padding: 0 0 0 10px; font-size: 15px; cursor: pointer; line-height: 1; }
#quitar-numeros { margin-top: 10px; }
#programar-btn { margin-top: 8px; }
.cal { margin: 4px 0 6px; }
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.cal-mes { font-weight: 700; font-size: 16px; }
.cal-nav { background: none; border: 0; color: var(--link); font-size: 26px; line-height: 1; padding: 0 10px; cursor: pointer; }
.cal-nav:disabled { color: var(--muted); opacity: 0.35; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px 0; text-align: center; }
.cal-sem { font-size: 11px; color: var(--muted); padding-bottom: 4px; }
.cal-dia {
  justify-self: center; width: 38px; height: 38px; border-radius: 50%;
  background: none; border: 0; color: var(--text); font-size: 16px; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.cal-dia:disabled { color: var(--muted); opacity: 0.4; cursor: default; }
.cal-dia.hoy { color: var(--link); font-weight: 700; }
.cal-dia.rango { background: rgba(46, 166, 255, 0.18); }
.cal-dia.sel { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.prog-fila {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--border); font-size: 15px;
}
.prog-fila .opciones { justify-content: flex-end; }
.prog-fila .opciones button { font-size: 13px; padding: 6px 10px; }
.prog-fila .opciones button:disabled { opacity: 0.35; cursor: default; }
.prog-repetir { width: auto; flex: 0 1 auto; padding: 8px 12px; border-radius: 999px; }
.prog-resumen { font-size: 13px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.prog-resumen.error { color: var(--warn); }
.prog-confirmar { border-radius: 999px; padding: 14px; font-size: 16px; }
.programada { padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.programada:last-child { border-bottom: 0; }

.alert {
  margin-top: 12px; padding: 10px 12px; border-radius: 10px;
  background: rgba(239, 83, 80, 0.12); color: var(--text); line-height: 1.4;
}
.alert a { color: var(--link); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--bg2);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; background: none; border: 0; color: var(--muted);
  padding: 8px 0 10px; font-size: 12px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tab span { font-size: 20px; }
.tab.active { color: var(--accent); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #222c36; color: #fff; padding: 10px 16px; border-radius: 10px;
  font-size: 14px; z-index: 30; max-width: 90%; text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }
