:root {
  --bg: #0f172a;
  --bg2: #0b1320;
  --surface: #1e293b;
  --surface-hover: #273549;
  --surface-active: #334155;
  --border: #334155;
  --border-light: #475569;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-muted: #64748b;
  --primary: #38bdf8;
  --primary-bg: rgba(56, 189, 248, 0.12);
  --primary-hover: #7dd3fc;
  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.12);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.12);
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; }

nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
nav .logo {
  font-size: 1.1rem; font-weight: 700; color: var(--primary);
  display: flex; align-items: center; gap: 0.5rem;
}
nav .logo span { color: var(--text); font-weight: 400; }
nav .nav-links { display: flex; gap: 1rem; align-items: center; }
nav button {
  background: transparent; border: 1px solid var(--border);
  color: var(--text); padding: 0.4rem 0.8rem; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 0.85rem;
}
nav button:hover { background: var(--surface-hover); }
nav button.primary {
  background: var(--primary); color: var(--bg); border-color: var(--primary);
  font-weight: 600;
}
nav button.primary:hover { background: var(--primary-hover); }
.user-badge {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.85rem; color: var(--text-dim);
}
.user-badge .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary); color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem;
}

main {
  max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem;
}

.view-title {
  font-size: 1.3rem; font-weight: 600; margin-bottom: 1.5rem;
  color: var(--text); display: flex; align-items: center; gap: 0.5rem;
}
.view-title .back {
  font-size: 0.8rem; color: var(--text-dim); cursor: pointer; border: none;
  background: none; padding: 0.25rem 0.5rem;
}
.view-title .back:hover { color: var(--primary); }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem;
}
.card h2 { font-size: 1rem; margin-bottom: 0.75rem; color: var(--text); }
.card h3 { font-size: 0.9rem; margin-bottom: 0.5rem; color: var(--text-dim); }

.auth-form {
  max-width: 400px; margin: 4rem auto;
}
.auth-form h1 {
  font-size: 1.5rem; color: var(--primary); text-align: center; margin-bottom: 0.25rem;
}
.auth-form p.sub { text-align: center; color: var(--text-dim); margin-bottom: 1.5rem; font-size: 0.9rem; }

label {
  display: block; margin-bottom: 0.25rem; color: var(--text-dim); font-size: 0.85rem; font-weight: 500;
}
input, select {
  width: 100%; padding: 0.6rem 0.75rem; margin-bottom: 1rem;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 0.9rem; font-family: inherit;
}
input:focus, select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-bg);
}
button {
  cursor: pointer; font-family: inherit; font-size: 0.85rem;
}
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border-radius: var(--radius-sm);
  border: none; font-weight: 500; transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: var(--bg); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--surface-active); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: var(--bg); }
.btn-danger:hover { opacity: 0.85; }
.btn-success { background: var(--success); color: var(--bg); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; padding: 0.7rem; }

.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600;
}
.badge-active { background: var(--success-bg); color: var(--success); }
.badge-sandbox { background: var(--warning-bg); color: var(--warning); }
.badge-production { background: var(--success-bg); color: var(--success); }
.badge-revoked { background: var(--danger-bg); color: var(--danger); }
.badge-verified { background: var(--success-bg); color: var(--success); }
.badge-pending { background: var(--warning-bg); color: var(--warning); }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

.list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem; background: var(--bg); border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
}
.list-item-info { flex: 1; }
.list-item-info .name { font-weight: 600; color: var(--text); }
.list-item-info .meta { font-size: 0.8rem; color: var(--text-dim); }

.stats-row {
  display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem;
}
.stat {
  flex: 1; min-width: 150px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; text-align: center;
}
.stat .value { font-size: 1.6rem; font-weight: 700; color: var(--primary); }
.stat .label { font-size: 0.8rem; color: var(--text-dim); margin-top: 0.25rem; }

table {
  width: 100%; border-collapse: collapse; font-size: 0.85rem;
}
th { text-align: left; color: var(--text-dim); padding: 0.5rem; border-bottom: 1px solid var(--border); font-weight: 500; }
td { padding: 0.5rem; border-bottom: 1px solid var(--border); }
tr:hover td { background: var(--surface-hover); }

code, pre {
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 0.83rem;
}
pre {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.75rem;
  overflow-x: auto; white-space: pre-wrap; word-break: break-all;
  color: var(--text-dim); position: relative;
}
.copy-btn {
  position: absolute; top: 4px; right: 4px;
  background: var(--surface-active); border: 1px solid var(--border);
  color: var(--text-dim); border-radius: var(--radius-sm);
  padding: 2px 8px; font-size: 0.7rem; cursor: pointer;
}
.copy-btn:hover { color: var(--text); }

.copy-field {
  display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem;
}
.copy-field input {
  flex: 1; margin-bottom: 0; font-family: monospace; font-size: 0.82rem;
}
.copy-field button { white-space: nowrap; }

.checklist-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5rem 0; border-bottom: 1px solid var(--border);
}
.checklist-item:last-child { border-bottom: none; }
.checklist-item .dot {
  width: 20px; height: 20px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; flex-shrink: 0;
}
.dot-pass { background: var(--success-bg); color: var(--success); }
.dot-fail { background: var(--danger-bg); color: var(--danger); }

.tab-bar {
  display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1rem; gap: 0;
}
.tab {
  padding: 0.5rem 1rem; cursor: pointer; color: var(--text-dim);
  border-bottom: 2px solid transparent; font-size: 0.85rem; background: none; border-top: none;
  border-left: none; border-right: none;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab:hover { color: var(--text); }

.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; padding: 3rem; gap: 0.75rem; color: var(--text-dim); }

.empty-state { text-align: center; padding: 2rem; color: var(--text-muted); }
.empty-state .icon { font-size: 2.5rem; margin-bottom: 0.5rem; opacity: 0.4; }

.warning-box {
  background: var(--warning-bg); border: 1px solid var(--warning);
  color: var(--warning); border-radius: var(--radius-sm);
  padding: 0.75rem; margin-bottom: 1rem; font-size: 0.85rem;
}
.info-box {
  background: var(--primary-bg); border: 1px solid var(--primary);
  color: var(--primary); border-radius: var(--radius-sm);
  padding: 0.75rem; margin-bottom: 1rem; font-size: 0.85rem;
}

#toast-container {
  position: fixed; bottom: 1rem; right: 1rem; z-index: 200;
  display: flex; flex-direction: column; gap: 0.5rem; max-width: 380px;
}
.toast {
  padding: 0.75rem 1rem; border-radius: var(--radius-sm);
  font-size: 0.82rem; box-shadow: var(--shadow-lg);
  animation: slideIn 0.2s ease; display: flex; align-items: center; gap: 0.5rem;
}
.toast-success { background: #14532d; border: 1px solid #22c55e; color: #bbf7d0; }
.toast-error { background: #7f1d1d; border: 1px solid #ef4444; color: #fecaca; }
.toast-info { background: #0c4a6e; border: 1px solid #38bdf8; color: #bae6fd; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.form-help { font-size: 0.78rem; color: var(--text-muted); margin-top: -0.75rem; margin-bottom: 1rem; }

.step { display: flex; gap: 0.75rem; margin-bottom: 1.5rem; align-items: flex-start; }
.step-num {
  width: 28px; height: 28px; border-radius: 50%; background: var(--primary-bg);
  color: var(--primary); display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem; flex-shrink: 0; margin-top: 2px;
}
.step-content { flex: 1; }
.step-content h3 { margin-bottom: 0.25rem; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center; z-index: 150;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; max-width: 480px; width: 90%;
  box-shadow: var(--shadow-lg);
}

@media (max-width: 600px) {
  nav { padding: 0.5rem 1rem; }
  main { padding: 1rem; }
  .stats-row { flex-direction: column; }
}

/* ── Utilidades (reemplazan estilos inline prohibidos por la CSP) ────── */
.clickable { cursor: pointer; }
.mt-05 { margin-top: 0.5rem; }
.mt-075 { margin-top: 0.75rem; }
.mt-1 { margin-top: 1rem; }
.key-reveal { position: relative; margin-top: 0.25rem; }
.step-desc { color: var(--text-dim); font-size: 0.85rem; }

/* Métricas: contraste, tablas legibles y filtros adaptables. */
.metrics-heading { display:flex; flex-wrap:wrap; gap:1rem; justify-content:space-between; align-items:center; margin-bottom:1.5rem; }
.metrics-filters { display:flex; flex-wrap:wrap; gap:.65rem; align-items:center; }
.metrics-filters input, .metrics-filters select { width:auto; margin:0; }
.metrics-kpis { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:1rem; margin-bottom:1rem; }
.metrics-kpis .stat { min-width:0; }
.metrics-chart { display:flex; gap:6px; height:200px; align-items:flex-end; overflow-x:auto; padding-top:1rem; }
.metrics-column { display:flex; flex-direction:column; justify-content:flex-end; align-items:center; flex:1; min-width:20px; height:100%; }
.metrics-bar { width:100%; max-width:32px; background:var(--accent,#7c6aff); border-radius:4px 4px 0 0; min-height:2px; }
.metrics-count,.metrics-day { font-size:.65rem; color:var(--text-dim); padding:4px 0; }
.muted { color:var(--text-dim); font-size:.85rem; line-height:1.6; }
.metrics-output summary { cursor:pointer; font-weight:600; }
.metrics-output table { width:100%; }
.metrics-output details p { overflow-wrap:anywhere; margin:1rem 0; }
@media(max-width:700px) { .metrics-kpis { grid-template-columns:repeat(2,minmax(0,1fr)); } .metrics-filters { width:100%; } .metrics-filters input { width:calc(50% - .4rem); } }

.portal-footer { text-align:center; padding:1.5rem; color:var(--text-dim); }
.installation-guide { max-width:900px; margin:0 auto; padding:2rem 1.5rem; line-height:1.8; }
.installation-guide h1,.installation-guide h2,.installation-guide h3 { margin:1.5rem 0 1rem; }
.installation-guide p,.installation-guide ul,.installation-guide ol { margin:1rem 0; }
.installation-guide li { margin:.5rem 0 .5rem 1.5rem; }
.installation-guide pre { overflow:auto; padding:1rem; background:var(--bg-card,#171922); border-radius:8px; }
.installation-guide a { overflow-wrap:anywhere; }

/* ── UX de negocio (reforma del portal) ─────────────────────────── */
.summary-row { display:flex; justify-content:space-between; align-items:center; padding:0.6rem 0; border-bottom:1px solid var(--line,#2a2d3a); }
.summary-row:last-child { border-bottom:none; }
.summary-label { font-size:0.88rem; color:var(--muted,#9aa1b5); display:inline-flex; align-items:center; gap:0.3rem; }
.summary-value { font-weight:600; font-size:0.95rem; }
.summary-value.ok { color:var(--success,#3ee08f); }
.summary-value.pending { color:var(--warning,#f5c451); }
.summary-value.neutral { color:var(--ink,#e8eaf2); }

.wizard-step { display:flex; gap:0.75rem; padding:0.85rem 0; border-bottom:1px solid var(--line,#2a2d3a); }
.wizard-step:last-child { border-bottom:none; }
.wizard-step h3 { font-size:1rem; margin:0 0 0.25rem; }
.wizard-step .muted { margin:0; font-size:0.82rem; }
.wizard-body { flex:1; }

.help { display:inline-flex; align-items:center; justify-content:center; width:16px; height:16px; border-radius:50%; background:rgba(255,255,255,0.08); color:var(--muted,#9aa1b5); font-size:11px; cursor:help; margin-left:0.35rem; }
