/* ══════════════════════════════════════════════════════════════
   NexoQR · Sistema de diseño base
   Tokens, tipografía, botones, formularios, tarjetas y utilidades.
   Todas las páginas importan este archivo.
   ══════════════════════════════════════════════════════════════ */

:root {
  /* Marca */
  --brand: #0ea5e9;
  --brand-600: #0284c7;
  --brand-700: #0369a1;
  --brand-soft: rgba(14, 165, 233, 0.12);
  --accent: #a855f7;
  --accent-soft: rgba(168, 85, 247, 0.14);

  /* Superficies (tema oscuro por defecto) */
  --bg: #070b14;
  --bg-2: #0b1220;
  --surface: #111a2b;
  --surface-2: #16203a;
  --surface-3: #1c2842;
  --line: rgba(148, 163, 184, 0.16);
  --line-strong: rgba(148, 163, 184, 0.3);

  /* Texto */
  --text: #eef2ff;
  --text-dim: #a8b3cf;
  --text-mute: #71809e;

  /* Estados */
  --ok: #22c55e;
  --ok-soft: rgba(34, 197, 94, 0.14);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);

  /* Formas */
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 18px;
  --r-xl: 26px;
  --r-full: 999px;

  --shadow-sm: 0 1px 2px rgba(2, 6, 23, 0.4);
  --shadow: 0 10px 30px -12px rgba(2, 6, 23, 0.6);
  --shadow-lg: 0 24px 60px -18px rgba(2, 6, 23, 0.75);
  --glow: 0 0 0 1px rgba(14, 165, 233, 0.25), 0 18px 50px -20px rgba(14, 165, 233, 0.55);

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --nav-h: 64px;
  --maxw: 1160px;

  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f6f8fc;
  --bg-2: #eef2f9;
  --surface: #ffffff;
  --surface-2: #f4f7fc;
  --surface-3: #e9eff8;
  --line: rgba(15, 23, 42, 0.1);
  --line-strong: rgba(15, 23, 42, 0.2);
  --text: #0b1220;
  --text-dim: #495775;
  --text-mute: #6b7a99;
  --shadow: 0 10px 30px -14px rgba(15, 23, 42, 0.25);
  --shadow-lg: 0 24px 60px -20px rgba(15, 23, 42, 0.3);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.has-bg {
  background:
    radial-gradient(1100px 600px at 12% -10%, rgba(14, 165, 233, 0.16), transparent 60%),
    radial-gradient(900px 500px at 92% 0%, rgba(168, 85, 247, 0.14), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

h1, h2, h3, h4 { margin: 0 0 0.4em; line-height: 1.2; font-weight: 700; letter-spacing: -0.02em; }
h1 { font-size: clamp(2rem, 5vw, 3.1rem); }
h2 { font-size: clamp(1.5rem, 3.2vw, 2.1rem); }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1em; color: var(--text-dim); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
small { color: var(--text-mute); }
code, kbd, pre { font-family: var(--font-mono); }
img { max-width: 100%; display: block; }

::selection { background: var(--brand-soft); }

/* ── Layout ─────────────────────────────────────────────────── */
.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
.row { display: flex; gap: 12px; align-items: center; }
.row.wrap-row { flex-wrap: wrap; }
.between { justify-content: space-between; }
.center { justify-content: center; }
.end { justify-content: flex-end; }
.col { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.grid.four { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stack-24 { display: flex; flex-direction: column; gap: 24px; }
.stack-40 { display: flex; flex-direction: column; gap: 40px; }
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; } .mt-40 { margin-top: 40px; }
.mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; } .mb-40 { margin-bottom: 40px; }
.hide { display: none !important; }
.text-center { text-align: center; }
.dim { color: var(--text-dim); }
.mute { color: var(--text-mute); }
.tiny { font-size: 0.78rem; }
.small { font-size: 0.88rem; }
.strong { font-weight: 700; }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ── Tarjetas ───────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card.pad-lg { padding: 28px; }
.card.flat { box-shadow: none; }
.card.hover:hover { border-color: var(--line-strong); transform: translateY(-2px); transition: 0.2s ease; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { margin: 0; }
.panel {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  padding: 32px;
}
.divider { height: 1px; background: var(--line); margin: 18px 0; border: 0; }

/* ── Botones ────────────────────────────────────────────────── */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-line: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; min-height: 42px;
  font: inherit; font-weight: 600; font-size: 0.94rem;
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-line); border-radius: var(--r);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform 0.12s ease, filter 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:hover { filter: brightness(1.12); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn[disabled], .btn.is-loading { opacity: 0.55; pointer-events: none; }
.btn.primary { --btn-bg: linear-gradient(135deg, var(--brand), var(--brand-600)); --btn-fg: #04121f; --btn-line: transparent; box-shadow: var(--glow); }
.btn.accent { --btn-bg: linear-gradient(135deg, var(--accent), #7c3aed); --btn-fg: #fff; --btn-line: transparent; }
.btn.ghost { --btn-bg: transparent; --btn-line: var(--line); }
.btn.ghost:hover { --btn-bg: var(--surface-2); }
.btn.danger { --btn-bg: var(--danger-soft); --btn-fg: #fecaca; --btn-line: rgba(239, 68, 68, 0.4); }
.btn.ok { --btn-bg: var(--ok-soft); --btn-fg: #bbf7d0; --btn-line: rgba(34, 197, 94, 0.4); }
.btn.sm { padding: 6px 11px; min-height: 34px; font-size: 0.84rem; border-radius: var(--r-sm); }
.btn.lg { padding: 14px 24px; min-height: 52px; font-size: 1.02rem; border-radius: var(--r-lg); }
.btn.block { width: 100%; }
.btn.icon { padding: 8px; min-width: 38px; min-height: 38px; }
.btn .spinner { width: 15px; height: 15px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Formularios ────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field > label { font-size: 0.86rem; font-weight: 600; color: var(--text-dim); }
.field .hint { font-size: 0.78rem; color: var(--text-mute); }
.field .error { font-size: 0.8rem; color: #fca5a5; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="tel"], input[type="url"], input[type="search"], input[type="date"],
input[type="time"], select, textarea {
  width: 100%; padding: 11px 13px; min-height: 44px;
  font: inherit; font-size: 0.95rem; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-mute); }
input[type="color"] { width: 46px; height: 40px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); cursor: pointer; }
input[type="range"] { width: 100%; accent-color: var(--brand); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); width: 17px; height: 17px; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-mute) 50%), linear-gradient(135deg, var(--text-mute) 50%, transparent 50%); background-position: calc(100% - 18px) 19px, calc(100% - 13px) 19px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.check { display: flex; align-items: center; gap: 9px; cursor: pointer; font-size: 0.92rem; }
.check input { flex: none; }
.inline-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 620px) { .inline-2, .inline-3 { grid-template-columns: 1fr; } }

/* ── Etiquetas y píldoras ───────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: 0.74rem; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase;
  background: var(--surface-3); color: var(--text-dim); border: 1px solid var(--line);
}
.badge.brand { background: var(--brand-soft); color: #7dd3fc; border-color: rgba(14, 165, 233, 0.3); }
.badge.ok { background: var(--ok-soft); color: #86efac; border-color: rgba(34, 197, 94, 0.3); }
.badge.warn { background: var(--warn-soft); color: #fcd34d; border-color: rgba(245, 158, 11, 0.3); }
.badge.danger { background: var(--danger-soft); color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: var(--r-full); background: var(--surface-2); border: 1px solid var(--line); font-size: 0.84rem; cursor: pointer; }
.chip[aria-pressed="true"], .chip.active { background: var(--brand-soft); border-color: var(--brand); color: #7dd3fc; }

/* ── Avisos ─────────────────────────────────────────────────── */
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); font-size: 0.9rem; margin-bottom: 14px; }
.alert.ok { background: var(--ok-soft); border-color: rgba(34, 197, 94, 0.35); }
.alert.warn { background: var(--warn-soft); border-color: rgba(245, 158, 11, 0.35); }
.alert.danger { background: var(--danger-soft); border-color: rgba(239, 68, 68, 0.35); }
.alert.brand { background: var(--brand-soft); border-color: rgba(14, 165, 233, 0.35); }

/* ── Tablas ─────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-mute); font-weight: 700; }
tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); }

/* ── Toasts ─────────────────────────────────────────────────── */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; max-width: min(380px, 92vw); }
.toast {
  padding: 12px 15px; border-radius: var(--r); border: 1px solid var(--line-strong);
  background: var(--surface); box-shadow: var(--shadow-lg); font-size: 0.9rem;
  animation: toast-in 0.22s ease; display: flex; gap: 9px; align-items: flex-start;
}
.toast.ok { border-color: rgba(34, 197, 94, 0.5); }
.toast.error { border-color: rgba(239, 68, 68, 0.5); }
.toast.warn { border-color: rgba(245, 158, 11, 0.5); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ── Diálogos ───────────────────────────────────────────────── */
dialog.modal {
  border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface);
  color: var(--text); padding: 0; width: min(620px, 94vw); box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgba(2, 6, 23, 0.66); backdrop-filter: blur(3px); }
dialog.modal .modal-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
dialog.modal .modal-body { padding: 22px; max-height: 70vh; overflow: auto; }
dialog.modal .modal-foot { padding: 16px 22px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Cabecera ───────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50; height: var(--nav-h);
  display: flex; align-items: center; gap: 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.brand-logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -0.03em; color: var(--text); font-size: 1.1rem; }
.brand-logo:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  background: linear-gradient(135deg, var(--brand), var(--accent));
  display: grid; place-items: center; color: #04121f; font-weight: 900; font-size: 0.95rem;
  box-shadow: 0 6px 18px -6px rgba(14, 165, 233, 0.7);
}

/* ── Varios ─────────────────────────────────────────────────── */
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sk 1.3s ease-in-out infinite; border-radius: var(--r-sm); }
@keyframes sk { to { background-position: -200% 0; } }
.empty { text-align: center; padding: 44px 20px; color: var(--text-mute); }
.empty .ico { font-size: 2.4rem; margin-bottom: 8px; }
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi .v { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.03em; }
.kpi .l { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-mute); font-weight: 700; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; background: var(--surface-3); border-radius: var(--r-full); transition: 0.2s; border: 1px solid var(--line); }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--text-dim); transition: 0.2s; }
.switch input:checked + span { background: var(--brand-soft); border-color: var(--brand); }
.switch input:checked + span::after { transform: translateX(18px); background: var(--brand); }
.scroll-x { overflow-x: auto; display: flex; gap: 8px; padding-bottom: 4px; }
.scroll-x::-webkit-scrollbar { height: 6px; }
.scroll-x::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
.bar { height: 8px; border-radius: var(--r-full); background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent)); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

@media print {
  .no-print, .topbar, #toasts { display: none !important; }
  body { background: #fff; color: #000; }
}
