/* Onex Medic · Superadmin — hoja de estilos propia (sin CDN: CSP estricta). */

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #e2e7f0;
  --text: #0f172a;
  --muted: #5b6477;
  --faint: #8a93a6;
  --primary: #2952e3;
  --primary-ink: #ffffff;
  --primary-soft: #e8eefe;
  --ok: #138a4b;
  --ok-soft: #e3f6ec;
  --warn: #b25e00;
  --warn-soft: #fff1dc;
  --danger: #c62f3b;
  --danger-soft: #fde8ea;
  --info-soft: #e7f1fb;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020;
    --surface: #121a2e;
    --surface-2: #19223a;
    --border: #26314d;
    --text: #e7ecf7;
    --muted: #a3adc4;
    --faint: #76809a;
    --primary: #6d8cff;
    --primary-ink: #0b1020;
    --primary-soft: #1d2a52;
    --ok: #4cd18a;
    --ok-soft: #12321f;
    --warn: #f3ad4e;
    --warn-soft: #3a2a12;
    --danger: #ff7b85;
    --danger-soft: #3d1a20;
    --info-soft: #172a45;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b1020;
  --surface: #121a2e;
  --surface-2: #19223a;
  --border: #26314d;
  --text: #e7ecf7;
  --muted: #a3adc4;
  --faint: #76809a;
  --primary: #6d8cff;
  --primary-ink: #0b1020;
  --primary-soft: #1d2a52;
  --ok: #4cd18a;
  --ok-soft: #12321f;
  --warn: #f3ad4e;
  --warn-soft: #3a2a12;
  --danger: #ff7b85;
  --danger-soft: #3d1a20;
  --info-soft: #172a45;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; }
p { margin: 0 0 .75rem; }
code, .mono { font-family: var(--mono); font-size: .88em; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #8b5cf6); color: #fff; font-size: 15px; font-weight: 800;
}
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; margin-top: -3px; }
.nav { display: flex; gap: 4px; margin-left: 12px; }
.nav a {
  color: var(--muted); padding: 7px 11px; border-radius: 8px; font-weight: 550; font-size: 14px;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.spacer { flex: 1; }
.user-chip { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; }
  .nav { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
  .user-chip .email { display: none; }
  .page-head .actions { margin-left: 0; width: 100%; }
  h1 { font-size: 1.3rem; }
}

/* ---------- Cards / grid ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 18px 20px; }
.card-head {
  display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.card-head .hint { color: var(--muted); font-size: 13px; }
.card-head .actions { margin-left: auto; display: flex; gap: 8px; }
.card-body { padding: 18px 20px; }
.stack { display: grid; gap: 16px; }
.grid { display: grid; gap: 16px; }
.grid-tenants { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 400px) { .grid-tenants { grid-template-columns: 1fr; } }

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
@media (max-width: 760px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.6rem; font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ---------- Tenant card ---------- */
.tenant-card { display: flex; flex-direction: column; transition: transform .12s ease, box-shadow .12s ease; }
.tenant-card:hover { transform: translateY(-1px); }
.tenant-card .top { display: flex; align-items: flex-start; gap: 10px; padding: 16px 18px 10px; }
.tenant-card .name { font-weight: 700; font-size: 1.02rem; color: var(--text); }
.tenant-card .url { color: var(--faint); font-size: 12.5px; word-break: break-all; }
.tenant-card .body { padding: 4px 18px 14px; display: grid; gap: 10px; }
.tenant-card .foot {
  margin-top: auto; padding: 10px 18px; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px;
}
.tenant-card .foot .go { margin-left: auto; font-weight: 600; }
.tenant-card .error-box { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px; }

/* ---------- Semáforo / badges ---------- */
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; margin-top: 7px; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.dot.down { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.dot.suspended { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
.dot.unknown { background: var(--faint); box-shadow: 0 0 0 4px var(--surface-2); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 650; white-space: nowrap; border: 1px solid transparent;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.down { background: var(--danger-soft); color: var(--danger); }
.badge.suspended, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.muted { background: var(--surface-2); color: var(--muted); }
.badge.info { background: var(--primary-soft); color: var(--primary); }

/* ---------- Barras de uso ---------- */
.meter { display: grid; gap: 4px; }
.meter .row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.meter .row strong { color: var(--text); font-weight: 650; font-variant-numeric: tabular-nums; }
.bar { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.bar.warn > span { background: var(--warn); }
.bar.full > span { background: var(--danger); }
.bar.unlimited > span { background: repeating-linear-gradient(90deg, var(--border) 0 6px, transparent 6px 10px); width: 100% !important; }
.bar > span.w-0 { width: 0; }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  font-weight: 650; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .muted { color: var(--muted); font-size: 13px; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 760px) {
  .table.responsive thead { display: none; }
  .table.responsive tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 0; }
  .table.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 6px 14px; }
  .table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; }
  .table.responsive td.actions-cell::before { content: none; }
  .table .actions { justify-content: flex-start; }
}

/* ---------- Formularios ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-size: 13px; font-weight: 600; color: var(--text); }
.field .help { font-size: 12.5px; color: var(--muted); }
.field .error { font-size: 12.5px; color: var(--danger); }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; min-height: 42px;
}
textarea.input { min-height: 84px; resize: vertical; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.is-invalid { border-color: var(--danger); }
.input-lg { font-size: 1.25rem; letter-spacing: .3em; text-align: center; font-family: var(--mono); }
.form-row { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }
.check { display: flex; align-items: flex-start; gap: 9px; padding: 6px 0; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex: none; }
.check small { display: block; color: var(--muted); }
.perm-group { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; }
.perm-group h3 { margin-bottom: 4px; }
.perm-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* Interruptor */
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; padding: 6px 0; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  flex: none; width: 44px; height: 26px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
}
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 3px solid var(--primary-soft); }
.switch .text strong { display: block; font-size: 14px; }
.switch .text small { color: var(--muted); font-size: 13px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px; min-height: 40px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled, .btn[aria-busy="true"] { opacity: .6; cursor: progress; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, #000); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 88%, #000); }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn-block { width: 100%; }
.icon { width: 16px; height: 16px; flex: none; }

/* ---------- Alertas / estados ---------- */
.alert {
  border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start;
  border: 1px solid transparent; margin-bottom: 16px;
}
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); color: var(--text); }
.alert .alert-body { flex: 1; }
.alert strong { display: block; }

.empty {
  text-align: center; padding: 40px 20px; color: var(--muted);
}
.empty .empty-icon {
  width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 12px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--faint);
}
.empty h3 { color: var(--text); margin-bottom: 6px; font-size: 1rem; }

.secret-box {
  border: 2px dashed var(--warn); background: var(--warn-soft); border-radius: var(--radius); padding: 16px;
}
.secret-value {
  font-family: var(--mono); font-size: 1.35rem; letter-spacing: .06em; background: var(--surface); color: var(--text);
  padding: 10px 14px; border-radius: var(--radius-sm); display: inline-block; word-break: break-all; user-select: all;
}

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; font-weight: 550; word-break: break-word; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 16px; }
.flex { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.right { margin-left: auto; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; padding: 28px; }
.auth-card .brand { justify-content: center; margin-bottom: 18px; font-size: 1.1rem; }
.auth-card h1 { font-size: 1.25rem; text-align: center; margin-bottom: 6px; }
.auth-card .sub { text-align: center; color: var(--muted); margin-bottom: 20px; font-size: 14px; }
.qr { background: #fff; padding: 12px; border-radius: 12px; display: inline-block; }
.qr svg { display: block; width: 200px; height: 200px; }

/* ---------- Diálogo de confirmación ---------- */
dialog.confirm {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog.confirm::backdrop { background: rgba(8, 12, 24, .55); backdrop-filter: blur(2px); }
dialog.confirm .dlg-body { padding: 20px 22px 8px; }
dialog.confirm .dlg-body h2 { margin-bottom: 8px; }
dialog.confirm .dlg-body p { color: var(--muted); white-space: pre-line; }
dialog.confirm .dlg-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 22px 18px; }

/* Cargando */
.spinner {
  width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.pagination { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
.pagination a, .pagination span {
  padding: 6px 11px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; color: var(--text);
}
.pagination .current { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.pagination .disabled { opacity: .5; }

.theme-toggle { width: 38px; height: 38px; padding: 0; }
.footer-note { text-align: center; color: var(--faint); font-size: 12px; margin-top: 32px; }

/* Anchos de barra en pasos de 5% (la CSP no permite estilos inline) */
.bar > span.w-0 { width: 0%; }
.bar > span.w-5 { width: 5%; }
.bar > span.w-10 { width: 10%; }
.bar > span.w-15 { width: 15%; }
.bar > span.w-20 { width: 20%; }
.bar > span.w-25 { width: 25%; }
.bar > span.w-30 { width: 30%; }
.bar > span.w-35 { width: 35%; }
.bar > span.w-40 { width: 40%; }
.bar > span.w-45 { width: 45%; }
.bar > span.w-50 { width: 50%; }
.bar > span.w-55 { width: 55%; }
.bar > span.w-60 { width: 60%; }
.bar > span.w-65 { width: 65%; }
.bar > span.w-70 { width: 70%; }
.bar > span.w-75 { width: 75%; }
.bar > span.w-80 { width: 80%; }
.bar > span.w-85 { width: 85%; }
.bar > span.w-90 { width: 90%; }
.bar > span.w-95 { width: 95%; }
.bar > span.w-100 { width: 100%; }
.center { text-align: center; }
.steps { padding-left: 18px; margin: 0; display: grid; gap: 6px; }
details > summary { list-style: none; display: inline-flex; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { background: var(--surface-2); }
.flex .input { flex: 1; min-width: 180px; }
pre.secret-value { margin: 6px 0 0; white-space: pre; }
