:root {
  --bg: #0e0c13;
  --surface: #18151f;
  --surface2: #221e2b;
  --line: #322c3d;
  --text: #f6f3f9;
  --muted: #a39cae;
  --accent: #b46cff;
  --verde: #22c55e;
  --amarillo: #facc15;
  --rojo: #ef4444;
  --ok: #22c55e;
  --bad: #ef4444;
  --radius: 16px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* ---------- Botones ---------- */
.btn, button.chip, .seg button {
  border: 1px solid var(--line);
  background: var(--surface2);
  border-radius: 12px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  transition: transform .08s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; }
.btn.big { width: 100%; padding: 18px; font-size: 1.25rem; border-radius: var(--radius); font-weight: 800; letter-spacing: .02em; }
.btn.sm { padding: 6px 10px; font-size: .85rem; border-radius: 10px; }
.btn.primary { background: var(--accent); border-color: transparent; color: #12001f; }
.btn.ok { background: var(--ok); border-color: transparent; color: #04210f; }
.btn.bad { background: var(--bad); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); background: transparent; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

.seg { display: flex; background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 6px; border-radius: 9px; font-size: .92rem; }
.seg button.on { background: var(--text); color: var(--bg); }

/* ---------- Formularios ---------- */
label.field { display: block; margin: 14px 0 6px; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
input[type=text], input[type=search], input[type=number], select, textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 110px; resize: vertical; }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
button.chip { padding: 6px 12px; border-radius: 999px; font-size: .9rem; font-weight: 500; }
button.chip.on { background: var(--accent); color: #12001f; border-color: transparent; }
button.chip.on.bad { background: var(--bad); color: #fff; }
button.chip.on.ok { background: var(--ok); color: #04210f; }

/* ---------- Niveles ---------- */
.lv-verde { --lv: var(--verde); }
.lv-amarillo { --lv: var(--amarillo); }
.lv-rojo { --lv: var(--rojo); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--lv, var(--muted)); display: inline-block; flex: none; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; left: 50%; bottom: calc(160px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: #2a1520; border: 1px solid var(--bad); padding: 12px 14px; border-radius: 12px; font-weight: 600; transition: opacity .3s, transform .3s; box-shadow: 0 10px 30px #0008; }
.toast.ok { background: #10251a; border-color: var(--ok); }
.toast.warn { background: #2a2410; border-color: var(--amarillo); }
.toast.out { opacity: 0; transform: translateY(8px); }

.pin-gate { position: fixed; inset: 0; z-index: 300; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 16px; }
.pin-gate form { width: min(100%, 340px); text-align: center; }
.pin-gate .pin-icon { font-size: 3rem; }
.pin-gate h2 { margin: 8px 0 20px; }
.pin-gate input { text-align: center; font-size: 1.6rem; letter-spacing: .3em; padding: 14px; }
.pin-gate .pin-msg { color: var(--bad); min-height: 1.4em; font-weight: 600; }

body.offline::before {
  content: "Sin conexión con el servidor… reconectando";
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  background: var(--bad); color: #fff; text-align: center; padding: 6px; font-weight: 700; font-size: .85rem;
}
