/* ==========================================================================
   WireGuard Cloud — panel multi-tenant
   Tema oscuro por defecto, claro según preferencia del sistema.
   ========================================================================== */
:root {
  --bg: #0b0d14;
  --bg-elev: #11141d;
  --surface: #151925;
  --surface-2: #1b2030;
  --border: #252b3d;
  --text: #e7e9f2;
  --muted: #8a91a8;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --accent-soft: rgba(124, 92, 255, .14);
  --success: #22c55e;
  --success-soft: rgba(34, 197, 94, .14);
  --danger: #f43f5e;
  --danger-soft: rgba(244, 63, 94, .14);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, .14);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6fb;
    --bg-elev: #ffffff;
    --surface: #ffffff;
    --surface-2: #f1f3f9;
    --border: #e3e6ef;
    --text: #151827;
    --muted: #646b82;
    --accent-soft: rgba(124, 92, 255, .10);
    --shadow: 0 10px 30px rgba(20, 24, 40, .08);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
code, .mono { font-family: var(--mono); font-size: .92em; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* ---------- arranque ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.spinner.sm { width: 16px; height: 16px; border-width: 2px; flex: none; }

/* ---------- login ---------- */
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(600px 400px at 15% 10%, rgba(124, 92, 255, .22), transparent 60%),
    radial-gradient(600px 400px at 85% 90%, rgba(34, 211, 238, .16), transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; padding: 34px 30px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; box-shadow: var(--shadow);
}
.auth-card .brand { justify-content: center; margin-bottom: 8px; }
.auth-card p.lead { text-align: center; color: var(--muted); margin: 0 0 24px; }
.auth-card form { display: grid; gap: 14px; }

/* ---------- marca ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand .logo {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.brand .logo svg { width: 20px; height: 20px; stroke: #fff; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 20px; padding: 22px 16px;
  background: var(--bg-elev); border-right: 1px solid var(--border);
}
.nav { display: grid; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px;
  border-radius: var(--radius-sm); color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--text); }
.nav a.active svg { stroke: var(--accent); }
.nav svg { width: 18px; height: 18px; }
.sidebar .spacer { flex: 1; }
.userbox {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 700;
}
.userbox .who { min-width: 0; flex: 1; }
.userbox .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.userbox .who span { color: var(--muted); font-size: 12px; }

.main { padding: 30px 36px 60px; max-width: 1240px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }

.topbar { display: none; }
.nav-backdrop { display: none; }
@media (max-width: 760px) { .nav-backdrop { display: block; } }
.back-btn { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px 4px 4px; height: auto; font-weight: 600; }
.back-btn svg { width: 18px; height: 18px; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.crumbs .btn.back-btn { margin: -4px 6px -4px -6px; color: var(--accent); }
.topbar .btn.back-btn { color: var(--accent); }

/* ---------- componentes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.card + .card { margin-top: 18px; }
.grid > .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

.grid { display: grid; gap: 18px; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; }
.two { grid-template-columns: 1.4fr 1fr; }
.stat { position: relative; overflow: hidden; }
.stat .label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.stat .label svg { width: 16px; height: 16px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.stat .hint { color: var(--muted); font-size: 12.5px; }
.stat::after {
  content: ""; position: absolute; inset: auto -40px -60px auto; width: 140px; height: 140px; border-radius: 50%;
  background: radial-gradient(closest-side, var(--accent-soft), transparent);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); cursor: pointer;
  font-weight: 600; white-space: nowrap; transition: transform .05s, background .15s, border-color .15s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #6246ea); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.icon { width: 34px; height: 34px; padding: 0; }
.btn.block { width: 100%; height: 42px; }
.btn.sm { height: 32px; padding: 0 12px; font-size: 13px; }

.field { display: grid; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field .help { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-elev); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; }
.form-grid { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.form-grid .full { grid-column: 1 / -1; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 38px; height: 22px; border-radius: 99px; background: var(--border); position: relative; transition: background .15s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform .15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px;
  border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted);
}
.badge svg { width: 13px; height: 13px; flex: none; }
.badge { white-space: nowrap; }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.off { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warning-soft); color: var(--warning); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
.dot.dis { background: var(--danger); }

/* ---------- tablas ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px -20px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 20px; text-align: left; border-top: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; border-top: 0; }
tbody tr { transition: background .1s; }
@media (hover: hover) { tbody tr:hover { background: var(--surface-2); } }
tr.link { cursor: pointer; }
td .name { font-weight: 600; }
td .meta { color: var(--muted); font-size: 12.5px; }
td.actions { text-align: right; white-space: nowrap; }
.cell-flex { display: flex; align-items: center; gap: 10px; }

.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty svg { width: 42px; height: 42px; stroke: var(--accent); margin-bottom: 10px; }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.empty p { margin: 0 0 18px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.banner {
  display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-radius: var(--radius);
  background: var(--warning-soft); color: var(--warning); margin-bottom: 18px; font-weight: 500;
}
.banner svg { width: 18px; height: 18px; flex: none; }

.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 11px; width: 17px; height: 17px; stroke: var(--muted); }
.search .input { padding-left: 36px; width: 260px; }

.net-hero {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  background:
    radial-gradient(500px 200px at 0% 0%, rgba(124, 92, 255, .22), transparent 70%),
    radial-gradient(500px 200px at 100% 100%, rgba(34, 211, 238, .14), transparent 70%),
    var(--surface);
}
.net-hero .big { font-family: var(--mono); font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.net-hero .grow { flex: 1; min-width: 220px; }

/* ---------- modal ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: rgba(5, 7, 12, .62); backdrop-filter: blur(4px); animation: fade .15s ease-out;
}
.modal {
  width: 100%; max-width: 520px; max-height: calc(100vh - 40px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  animation: pop .18s ease-out;
}
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 0; }
.modal-body { padding: 18px 22px; display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 22px 20px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

.qr-layout { display: grid; grid-template-columns: 240px 1fr; gap: 20px; align-items: start; }
.qr-box { background: #fff; border-radius: 14px; padding: 10px; display: grid; place-items: center; }
.qr-box img { width: 100%; height: auto; display: block; }
pre.conf {
  margin: 0; padding: 14px; border-radius: var(--radius-sm); background: var(--bg-elev);
  border: 1px solid var(--border); font: 12px/1.6 var(--mono); white-space: pre-wrap; word-break: break-all;
  max-height: 260px; overflow: auto;
}
.note { font-size: 12.5px; color: var(--muted); }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 60; }
.toast {
  display: flex; align-items: center; gap: 10px; min-width: 260px; max-width: 380px; padding: 10px 8px 10px 16px;
  border-radius: 12px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  animation: pop .2s ease-out; transition: transform .18s ease, opacity .18s ease; touch-action: pan-y;
}
.toast-msg { flex: 1; min-width: 0; }
.toast-close {
  flex: none; width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.toast-close:hover { background: var(--surface-2); color: var(--text); }
.toast-close svg { width: 16px; height: 16px; }
.toast.leaving { opacity: 0; transform: translateX(16px); }
.toast.ok { border-left: 3px solid var(--success); }
.toast.err { border-left: 3px solid var(--danger); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 40;
    transform: translateX(-100%); transition: transform .2s;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .nav-backdrop {
    position: fixed; inset: 0; z-index: 35; background: rgba(5, 7, 12, .5);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  body.menu-open .nav-backdrop, body.menu-dragging .nav-backdrop { opacity: 1; pointer-events: auto; }
  body.menu-open { overflow: hidden; }
  .topbar {
    display: flex; align-items: center; gap: 8px; padding: 12px 16px 12px 8px;
    border-bottom: 1px solid var(--border); background: var(--bg-elev); position: sticky; top: 0; z-index: 30;
  }
  .topbar .grow { flex: 1; }
  .topbar .brand { font-size: 16px; }
  .hide-mobile { display: none; }
  .main { padding: 20px 16px 50px; }
  .form-grid, .qr-layout { grid-template-columns: 1fr; }
  .qr-box { max-width: 260px; margin: 0 auto; }
  .search .input { width: 100%; }
  .hide-sm { display: none; }
  th, td { padding: 10px 14px; }
  .table-wrap { margin: 0 -20px -20px; }
}

/* ==========================================================================
   Móvil / PWA
   ========================================================================== */
/* Sin zoom: doble toque desactivado y sin ajuste automático de texto. */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overscroll-behavior-y: none; -webkit-tap-highlight-color: transparent; }
/* Los hijos de un grid tienen min-width:auto: una tabla ancha estiraba toda la
   página (y el navegador hacía zoom-out). min-width:0 deja que se encojan. */
.layout > div, .main { min-width: 0; }
body { overflow-x: clip; } /* clip: no crea un contenedor de scroll (hidden sí) */

/* Zonas seguras (notch, barra de inicio) con viewport-fit=cover. */
.sidebar { padding-top: max(22px, env(safe-area-inset-top)); padding-bottom: max(22px, env(safe-area-inset-bottom)); }
#toasts { right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); }
.auth { padding-top: max(24px, env(safe-area-inset-top)); padding-bottom: max(24px, env(safe-area-inset-bottom)); }

@media (max-width: 760px) {
  /* iOS hace zoom al enfocar campos con letra < 16px. */
  .input, select.input, textarea.input { font-size: 16px; }
  .topbar {
    padding-top: max(12px, env(safe-area-inset-top));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .main {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(50px, calc(env(safe-area-inset-bottom) + 30px));
  }
  .card { padding: 16px; overflow: hidden; }
  tr.link:active { background: var(--surface-2); }
  .page-head { align-items: stretch; }
  .page-head > .cell-flex { width: 100%; flex-wrap: wrap; }
  .page-head > .cell-flex > .search { flex: 1 1 100%; }
  .page-head > .cell-flex > .btn.primary { flex: 1; }
  .stats { gap: 12px; }
  .stat .value { font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .stat.wide { grid-column: 1 / -1; }
  .card > .table-wrap:first-child,
  .card > div:only-child > .table-wrap:only-child { margin-top: -16px; }
  .card > div:only-child > .table-wrap:only-child tbody tr:first-child,
  .card > .table-wrap:first-child tbody tr:first-child { border-top: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: calc(100vh - 24px); }
  .overlay { place-items: end center; padding: 12px 0 0; }
  .modal-body, .modal-head, .modal-foot { padding-left: 18px; padding-right: 18px; }
  .modal-foot { padding-bottom: max(18px, env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
  #toasts { left: 16px; right: 16px; }
  .toast { min-width: 0; max-width: none; }

  /* Tablas -> tarjetas apiladas. */
  .table-wrap { margin: 0 -16px -16px; overflow: visible; }
  table.cards thead { display: none; }
  table.cards, table.cards tbody { display: block; }
  table.cards tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px;
    padding: 14px 16px; border-top: 1px solid var(--border);
  }
  table.cards td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 0; border: 0; grid-column: 1 / -1; min-width: 0;
  }
  table.cards td[data-label]::before { content: attr(data-label); color: var(--muted); font: 12.5px var(--font); }
  table.cards td.primary { grid-column: 1; grid-row: 1; justify-content: flex-start; min-width: 0; }
  table.cards td.aside { grid-column: 2; grid-row: 1; justify-content: flex-end; }
  table.cards td.primary .cell-flex, table.cards td.primary .cell-flex > div { min-width: 0; }
  table.cards td.primary .name, table.cards td.primary .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  table.cards td .progress { flex: 0 0 90px; }
  table.cards td:has(> .meta + .progress) { justify-content: flex-start; }
  table.cards td:has(> .meta + .progress)::before { margin-right: auto; }
  table.cards .hide-sm { display: flex; }
  table.cards td.actions .btn.icon { width: 36px; height: 36px; }
  /* Muchas acciones (dispositivos): van en su propia fila para no tapar el nombre. */
  table.cards tr:has(> td.actions .btn:nth-child(4)) td.primary { grid-column: 1 / -1; }
  table.cards td.actions.aside:has(> .btn:nth-child(4)) {
    grid-column: 1 / -1; grid-row: auto; justify-content: space-between;
    border-top: 1px solid var(--border); padding-top: 8px; margin-top: 2px;
  }
}

/* App instalada (PWA): sin barra del navegador, la cabecera hace de barra de estado. */
@media (display-mode: standalone) {
  body { user-select: none; -webkit-user-select: none; }
  input, textarea, pre, .mono, .kv dd { user-select: text; -webkit-user-select: text; }
}

/* ==========================================================================
   Filtros de navegación
   ========================================================================== */
.presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.preset {
  display: grid; gap: 2px; text-align: left; padding: 12px 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.preset span { color: var(--muted); font-size: 12.5px; }
.preset.on { border-color: var(--accent); background: var(--accent-soft); }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; margin: 18px 0; }
.grid > .card + .card, .filter-grid > .card { margin-top: 0; }
.filter-card { display: flex; align-items: flex-start; gap: 14px; cursor: pointer; transition: border-color .15s; }
.filter-card.on { border-color: var(--accent); }
.filter-card .grow { flex: 1; min-width: 0; }
.filter-card .name { font-weight: 650; }
.filter-card .note { margin-top: 2px; }
.filter-card .meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.filter-icon {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--surface-2); color: var(--muted);
}
.filter-card.on .filter-icon { background: var(--accent-soft); color: var(--accent); }
.filter-icon svg { width: 19px; height: 19px; }
.blocked-list { display: grid; }
.blocked-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.blocked-row:first-child { border-top: 0; padding-top: 0; }
.blocked-row .grow { flex: 1; min-width: 0; }
.blocked-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.blocked-row .meta { color: var(--muted); font-size: 12.5px; }
@media (max-width: 1000px) { .presets { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .filter-grid { grid-template-columns: 1fr; }
  .presets { gap: 8px; }
}

/* ==========================================================================
   Dominios
   ========================================================================== */
.domain-status { display: grid; gap: 8px; padding: 14px; border-radius: var(--radius-sm); background: var(--bg-elev); border: 1px solid var(--border); }
.domain-status .btn { justify-self: start; }
.check-line { display: flex; align-items: flex-start; gap: 8px; font-size: 13.5px; }
.check-line svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.check-line.ok { color: var(--success); }
.check-line.bad { color: var(--warning); }
.check-line span { color: var(--text); overflow-wrap: anywhere; }
ol.steps { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13.5px; line-height: 1.8; }
ol.steps code { color: var(--text); background: var(--surface-2); padding: 1px 6px; border-radius: 6px; overflow-wrap: anywhere; }

/* Ajustes de espaciado y textos de ayuda fuera de .field */
.card + .grid, .grid + .card, .card + .filter-grid { margin-top: 18px; }
.help { font-size: 12px; color: var(--muted); }
@media (max-width: 760px) {
  table.cards td.primary > div { min-width: 0; }
  table.cards td.primary .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ==========================================================================
   Llaves biométricas
   ========================================================================== */
.or-sep { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12.5px; }
.or-sep::before, .or-sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.passkey-hero { display: grid; gap: 14px; justify-items: center; text-align: center; }
.passkey-icon {
  width: 72px; height: 72px; border-radius: 22px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}
.passkey-icon svg { width: 38px; height: 38px; }
@media (max-width: 760px) {
  /* Los avisos arriba: las ventanas salen desde abajo y no deben quedar tapadas. */
  #toasts { top: max(12px, env(safe-area-inset-top)); bottom: auto; z-index: 70; }
}

/* ==========================================================================
   App instalada (PWA) en iOS: la barra de estado translúcida añade un degradado
   difuminado que llega más abajo que la zona segura declarada. Se deja un margen
   extra bajo ella para que nada quede tapado. La clase .standalone la pone app.js
   (iOS antiguos no soportan la media query display-mode).
   ========================================================================== */
:root { --top-gap: 0px; }
html.standalone { --top-gap: 14px; }
html.standalone .sidebar { padding-top: calc(env(safe-area-inset-top) + var(--top-gap) + 18px); }
html.standalone .auth { padding-top: calc(env(safe-area-inset-top) + var(--top-gap) + 24px); }
html.standalone .modal { max-height: calc(100vh - env(safe-area-inset-top) - var(--top-gap) - 24px); }
@media (max-width: 760px) {
  html.standalone .topbar { padding-top: calc(env(safe-area-inset-top) + var(--top-gap)); }
  html.standalone #toasts { top: calc(env(safe-area-inset-top) + var(--top-gap) + 6px); }
  html.standalone .overlay { padding-top: calc(env(safe-area-inset-top) + var(--top-gap)); }
}

/* Selector segmentado (tipo de dispositivo, pestañas de configuración) */
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: var(--radius-sm); background: var(--bg-elev); border: 1px solid var(--border); }
.segmented label { flex: 1; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 10px;
  border-radius: 7px; color: var(--muted); font-weight: 600; font-size: 13.5px; text-align: center;
}
.segmented span svg { width: 16px; height: 16px; flex: none; }
.segmented input:checked + span { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 0 var(--border); }
.segmented input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

/* servicios publicados */
.card.service .card-head { margin-bottom: 0; }
.card.service .domain-status { margin-top: 14px; }
.svc-name { font-weight: 600; font-size: 15px; color: var(--text); text-decoration: none; word-break: break-all; }
.svc-name:hover { color: var(--accent); }
.card.service .meta { margin-top: 4px; color: var(--muted); font-size: 13px; }
.banner + .card, .banner + .banner { margin-top: 14px; }

/* copias de seguridad */
.backup-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 22px; }
.inline-field { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.inline-field select.input { width: auto; padding-top: 6px; padding-bottom: 6px; }

/* gráficos (paleta validada: azul / naranja, pasos propios para claro y oscuro) */
:root { --series-1: #3987e5; --series-2: #d95926; }
@media (prefers-color-scheme: light) { :root { --series-1: #2a78d6; --series-2: #eb6834; } }
.segmented.compact span { height: 30px; font-size: 12.5px; padding: 0 9px; white-space: nowrap; }
.segmented.compact { min-width: 0; }
.big-num { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.big-num .note { font-size: 13px; font-weight: 400; letter-spacing: 0; }
.chart { position: relative; margin-bottom: 8px; }
.card h3 + .rank-list, .card h3 + .blocked-list { margin-top: 10px; }
.chart-legend { display: flex; align-items: center; gap: 16px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.chart-legend .grow { flex: 1; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw.s1, .chart-seg.s1 { background: var(--series-1); }
.sw.s2, .chart-seg.s2 { background: var(--series-2); }
.chart-plot { position: relative; height: 190px; margin-left: 58px; }
.chart-grid { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border); }
.chart-grid span { position: absolute; right: calc(100% + 8px); top: -8px; font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart-cols { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.chart-col { flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; cursor: default; border-radius: 4px; outline: none; }
.chart-col.hover, .chart-col:focus-visible { background: var(--accent-soft); }
.chart-stack { width: min(100%, 26px); display: flex; flex-direction: column-reverse; gap: 2px; }
.chart-seg { min-height: 2px; flex-basis: 0; }
.chart-seg.end { border-radius: 4px 4px 0 0; }
.chart-x { display: flex; gap: 2px; margin: 6px 0 0 58px; }
.chart-x span { flex: 1 1 0; min-width: 0; font-size: 11px; color: var(--muted); text-align: left; white-space: nowrap; overflow: visible; }
.chart-tip { position: absolute; top: 0; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; box-shadow: var(--shadow); pointer-events: none; z-index: 3; min-width: 150px; }
.chart-tip b { display: block; margin-bottom: 4px; font-weight: 600; }
.tip-row { display: flex; align-items: center; gap: 4px; color: var(--muted); }
.tip-row em { font-style: normal; margin-left: auto; padding-left: 12px; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tip-row span { white-space: nowrap; }
.tip-row.total { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.chart-table { width: 100%; font-size: 13px; border-collapse: collapse; }
.chart-table th, .chart-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.event-list { display: grid; }
.event { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.event:last-child { border-bottom: 0; }
.event .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.rank-list { display: grid; gap: 10px; margin-top: 8px; }
.rank { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 0; color: inherit; font: inherit; }
button.rank { cursor: pointer; }
button.rank:hover .name { color: var(--accent); }
.rank-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.rank-head .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-bar { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 5px; overflow: hidden; }
.rank-bar span { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }
@media (max-width: 640px) {
  .chart-plot { margin-left: 56px; height: 160px; }
  .chart-x { margin-left: 56px; }
  .big-num { font-size: 22px; }
}

/* avisos */
.channel-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.channel-icon svg { width: 17px; height: 17px; }
.blocked-row .meta.err { color: var(--danger); }
.blocked-row .switch { flex: none; }

/* páginas públicas: invitación y enlace de instalación */
.auth-card.wide { max-width: 460px; }
.auth-card .steps { text-align: left; margin: 0 0 16px; }
.auth-card .qr-box { max-width: 280px; margin: 0 auto 16px; }

/* salidas por país */
.flag { font-size: 24px; line-height: 1; width: 34px; text-align: center; flex: none; }

/* planes y facturación */
.banner.warn { border-color: var(--warning); background: var(--warning-soft); }
.banner.danger { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.banner a { color: inherit; font-weight: 600; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.plan-grid > .card { margin: 0; }
.plan-card { display: flex; flex-direction: column; gap: 10px; }
.plan-card.current { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.plan-name { font-weight: 700; font-size: 17px; }
.plan-price { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.plan-price span { font-size: 14px; font-weight: 500; color: var(--muted); }
.plan-features { list-style: none; padding: 0; margin: 0 0 6px; display: grid; align-content: start; gap: 6px; font-size: 13.5px; flex: 1; }
.plan-features li { display: flex; gap: 8px; align-items: flex-start; }
.plan-features svg { width: 15px; height: 15px; color: var(--success); flex: none; margin-top: 2px; }
.plan-current { justify-self: start; align-self: flex-start; }
.usage-head { display: flex; justify-content: space-between; font-size: 13.5px; margin-bottom: 6px; }
.blocked-row.muted { opacity: .6; }
.blocked-row.link { cursor: pointer; }
.plan-pick { display: grid; gap: 8px; }
.plan-option { display: block; cursor: pointer; }
.plan-option input { position: absolute; opacity: 0; pointer-events: none; }
.plan-option > span { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elev); }
.plan-option small { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; }
.plan-option em { font-style: normal; font-weight: 700; }
.plan-option input:checked + span { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.plan-option input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.badge.tiny { font-size: 10.5px; padding: 1px 7px; margin-left: 6px; vertical-align: 1px; }

/* ---------- monitor del servidor ---------- */
.line-plot { cursor: crosshair; touch-action: pan-y; }
.line-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.line-svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line-svg .line.s1 { stroke: var(--series-1); }
.line-svg .line.s2 { stroke: var(--series-2); }
.line-svg .line.dash { stroke-width: 1.25; stroke-dasharray: 4 4; opacity: .7; }
.line-svg .area.s1 { fill: var(--series-1); opacity: .14; }
.line-svg .area.s2 { fill: var(--series-2); opacity: .14; }
.sw.dash { background: none !important; border-top: 2px dashed var(--series-1); height: 0; align-self: center; }
.chart-cursor { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--muted); opacity: .5; pointer-events: none; }
.line-x { position: relative; height: 16px; display: block; }
.line-x span { position: absolute; transform: translateX(-50%); flex: none; }
.line-x span:first-child { transform: none; }
.line-x span:last-child { transform: translateX(-100%); }
.progress.meter { margin: 10px 0 8px; }
.progress.meter.warn > span { background: var(--warning); }
.progress.meter.danger > span { background: var(--danger); }
.sys-mini { display: grid; gap: 8px; margin-bottom: 16px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); color: inherit; text-decoration: none; }
.sys-mini:hover { outline: 1px solid var(--accent); }
.sys-row { display: grid; grid-template-columns: 70px 1fr 52px; align-items: center; gap: 10px; font-size: 13px; }
.sys-row .progress.meter { margin: 0; }
.sys-row b { text-align: right; font-variant-numeric: tabular-nums; }
.sys-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.sys-charts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.sys-charts .span-all { grid-column: 1 / -1; }
@media (max-width: 900px) { .sys-charts { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .sys-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
