:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Login ---------- */
#view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 20% 10%, #1d4ed8 0%, #0f172a 60%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border-radius: 20px;
  padding: 40px 34px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, .35);
  text-align: center;
}

.logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 1px;
}

.logo.small { width: 30px; height: 30px; font-size: 13px; border-radius: 9px; margin: 0; display: inline-flex; }

.login-card h1 { margin: 0 0 6px; font-size: 24px; }
.login-card .subtitle { color: var(--muted); margin: 0 0 28px; font-size: 14px; }

.login-card label {
  display: block;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

.login-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  margin-bottom: 16px;
  transition: border-color .15s, box-shadow .15s;
}

.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

/* ---------- Layout app ---------- */
#app { max-width: 1100px; margin: 0 auto; padding: 20px; }

header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 6px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 17px;
  color: var(--text);
}

nav { flex: 1; display: flex; gap: 6px; }

.nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.nav-btn:hover { background: #e2e8f0; color: var(--text); }
.nav-btn.active { background: var(--primary); color: #fff; }

.logout {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--danger);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.logout:hover { background: #fef2f2; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.card-head h2 { margin: 0; font-size: 20px; }

/* ---------- Tabla ---------- */
.tabla {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.tabla thead th {
  text-align: left;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}

.tabla tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.tabla tbody tr:last-child td { border-bottom: 0; }
.tabla tbody tr:hover { background: #f8fafc; }

.tabla .right { text-align: right; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge.activa { background: #dcfce7; color: #166534; }
.badge.inactiva { background: #fee2e2; color: #991b1b; }

/* ---------- Menú panel admin ---------- */
.stats {
  display: flex;
  gap: 48px;
  padding: 10px 0 26px;
}

.stat-value {
  font-size: 42px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.menu-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  background: linear-gradient(180deg, #f8fafc, #fff);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}

.menu-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 28px rgba(15, 23, 42, .1);
  border-color: #bfdbfe;
}

.menu-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #eff6ff;
  font-size: 22px;
  margin-bottom: 14px;
}

.menu-card h3 { margin: 0 0 6px; font-size: 17px; }
.menu-card p { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }

/* ---------- Botones ---------- */
button.primary {
  background: var(--primary);
  color: #fff;
  border: 0;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}

button.primary:hover { background: var(--primary-dark); }

button.ghost {
  background: #e2e8f0;
  color: var(--text);
  border: 0;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-block { width: 100%; padding: 12px; font-size: 15px; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

.row-actions button {
  border: 1px solid var(--border);
  background: var(--card);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.row-actions button:hover { background: #f1f5f9; }
.row-actions button.act-baja:hover { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.row-actions button.act-activar { color: var(--ok); }

.error-msg {
  color: var(--danger);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 10px 12px;
  margin: 0 0 14px;
  font-size: 13px;
}

/* ---------- Filtro historial ---------- */
.filtro {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.filtro label { font-size: 13px; color: var(--muted); }
.filtro input, .filtro select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: var(--card);
  color: var(--text);
}

.filtro input { width: 160px; }
.filtro input:focus, .filtro select:focus { outline: none; border-color: var(--primary); }

/* ---------- Paginación historial ---------- */
.paginacion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

.paginacion-botones { display: flex; align-items: center; gap: 10px; }

.paginacion-botones label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.paginacion-botones select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--card);
  color: var(--text);
}

.paginacion-botones button:disabled { opacity: .45; cursor: not-allowed; }
.paginacion-botones #h-page-info { font-weight: 600; color: var(--text); white-space: nowrap; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
  animation: fadeIn .15s ease;
}

.modal {
  width: 100%;
  max-width: 560px;
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 30px 70px rgba(0, 0, 0, .35);
  padding: 24px;
  animation: pop .18s ease;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-head h3 { margin: 0; font-size: 18px; }

.modal .close {
  border: 0;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.modal .close:hover { color: var(--danger); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.grid label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.grid input {
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
}

.grid input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.hint { font-size: 13px; color: var(--muted); margin: 0 0 14px; line-height: 1.5; }

.key-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #0f172a;
  border-radius: 10px;
  padding: 12px 14px;
}

.key-box code {
  flex: 1;
  color: #a5f3fc;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  word-break: break-all;
  user-select: all;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  header { flex-wrap: wrap; }
  nav { order: 3; flex-basis: 100%; }
}