:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --line: #e3e5ea;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --text: #eceef2;
    --muted: #9aa1ad;
    --line: #2a2f38;
    --accent: #5b8cff;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.4rem; margin: 4px 0 16px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* Navegación */
#nav {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
#nav .brand { font-weight: 800; color: var(--text); text-decoration: none; }
#nav .links { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
#nav .links a, #nav .link {
  padding: 6px 10px; border-radius: 8px; color: var(--muted); text-decoration: none;
  font: inherit; font-size: 0.92rem; background: none; border: 0; cursor: pointer;
}
#nav .links a.on { background: var(--bg); color: var(--text); font-weight: 600; }

/* Paneles y formularios */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 860px) { .grid2 { grid-template-columns: 1.1fr 0.9fr; align-items: start; } }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 10px; }
input, textarea, select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
}
textarea { min-height: 110px; resize: vertical; }
input[type="color"] { padding: 2px; height: 42px; cursor: pointer; }
.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.full { width: 100%; }
.error { color: var(--bad); font-size: 0.9rem; }
.hint { font-size: 0.8rem; color: var(--muted); margin: -4px 0 10px; }

/* Logo */
.logo-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.logo-row img { width: 48px; height: 48px; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); background: #fff; }

/* Vista previa y resultados */
.preview canvas, .cards canvas { width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--line); display: block; }
.preview { position: sticky; top: 70px; }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.cards .item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.cards .item .btns { margin-top: 8px; }
.cards .item .btns .btn { flex: 1; }

/* Login */
.login-wrap { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0,0,0,.45); }
.login { width: 100%; max-width: 340px; background: var(--surface); border-radius: var(--radius); padding: 20px; }

/* Administrador */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; cursor: pointer; }
.stat.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.stat .name { font-weight: 700; margin-bottom: 6px; }
.stat .nums { display: flex; gap: 14px; font-size: 0.9rem; color: var(--muted); }
.stat .nums b { color: var(--text); font-size: 1.15rem; display: block; }
.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.bar i { display: block; height: 100%; background: var(--ok); }
.filters { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (min-width: 700px) { .filters { grid-template-columns: 2fr 1fr 1fr auto; align-items: end; } }
.filters label { margin: 0; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font: inherit; cursor: pointer; }
.tabs button.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.list { display: flex; flex-direction: column; gap: 8px; }
.inv { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 6px; grid-template-columns: 1fr auto; }
.inv .who { font-weight: 600; }
.inv .meta { font-size: 0.82rem; color: var(--muted); grid-column: 1 / -1; }
.inv .btns { grid-column: 1 / -1; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; white-space: nowrap; align-self: start; }
.pill.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.pill.used { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.pill.pending { background: var(--bg); color: var(--muted); }
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; }
.modal .box { background: var(--surface); border-radius: var(--radius); padding: 14px; width: 100%; max-width: 420px; max-height: 92vh; overflow: auto; }

/* Lector */
body.scanner main { max-width: 560px; }
.cam { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 3 / 4; max-height: 62vh; width: 100%; }
.cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam .frame { position: absolute; inset: 18%; border: 3px solid rgba(255,255,255,.85); border-radius: 18px; box-shadow: 0 0 0 999px rgba(0,0,0,.28); pointer-events: none; }
.cam .start { position: absolute; inset: 0; display: grid; place-items: center; }
.result {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: 24px; text-align: center; color: #fff;
}
.result.ok { background: var(--ok); }
.result.used { background: var(--warn); }
.result.bad { background: var(--bad); }
.result .icon { font-size: 84px; line-height: 1; font-weight: 800; }
.result .title { font-size: 1.8rem; font-weight: 800; margin: 8px 0 16px; }
.result .data { background: rgba(0,0,0,.18); border-radius: var(--radius); padding: 14px 18px; width: 100%; max-width: 420px; }
.result .data .n { font-size: 1.5rem; font-weight: 700; }
.result .data p { margin: 4px 0; }
.result .tap { margin-top: 18px; opacity: .85; font-size: .9rem; }
.history { margin-top: 16px; }
.history .h { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.manual { display: flex; gap: 8px; margin-top: 12px; }
.manual input { margin: 0; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: .92rem; max-width: 90vw; }
.toast.bad { background: var(--bad); color: #fff; }

/* Página pública /v/:id */
body.public { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card-public { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; max-width: 420px; width: 100%; text-align: center; }
.card-public .big { font-size: 1.2rem; font-weight: 600; }
.badge { display: inline-block; padding: 6px 12px; border-radius: 999px; font-weight: 700; font-size: .9rem; color: #fff; }
.badge.ok { background: var(--ok); } .badge.warn { background: var(--warn); } .badge.bad { background: var(--bad); }
