/* theme.css -- portal de configuracion + sitio publico de Wabbi. Identidad
   de marca del logo (public/logo.svg): morado #431b63 + verde menta
   #0aff8a, fondo crema calido, tarjetas redondeadas y botones tipo pildora
   -- el verde es el color de ACCION (botones principales), el morado el de
   texto/enlaces/estado activo. Todo color pasa por variables
   (custom properties) -- nunca un hex suelto en componentes de superficie,
   para que el toggle claro/oscuro (ver theme-toggle.js) alcance TODO.

   Tres estados de tema, mismo criterio que un Artifact:
     - sin eleccion explicita ("system"): sigue prefers-color-scheme.
     - data-theme="light" en <html>: fuerza claro aunque el SO este en oscuro.
     - data-theme="dark" en <html>: fuerza oscuro aunque el SO este en claro.
   Los tres se declaran por separado (no solo dentro de la media query) --
   si no, elegir "oscuro" a mano en un sistema en modo claro no hace nada. */

:root {
  color-scheme: light;

  /* Marca -- colores exactos del logo (public/logo.svg). */
  --brand-purple: #431b63;
  --brand-green: #0aff8a;

  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #faf7f1;
  --surface-raised: #ffffff;
  --border: #ebe5da;
  --border-strong: #dad2c3;

  --text: #1f1233;
  --text-muted: #5f5572;
  --text-faint: #9a91a8;

  /* Acento de texto/enlaces/estado activo -- morado de marca. */
  --primary: #5b2a86;
  --primary-dark: #431b63;
  --primary-darker: #2e1045;
  --primary-soft: #efe6f7;
  --on-primary: #ffffff;

  /* Acento de accion (botones principales) -- verde menta de marca. */
  --accent: #3fe89a;
  --accent-strong: #1fd184;
  --accent-soft: #dcfaea;
  --on-accent: #1f1233;

  --success: #0a8a5c;
  --success-soft: #e0f7ec;
  --warning: #b45309;
  --warning-soft: #fdf1de;
  --danger: #c2283d;
  --danger-soft: #fbe9eb;
  --info: #3b5bdb;
  --info-soft: #e9edfc;
  --neutral-soft: #f1ede6;

  --sidebar-bg: #ffffff;
  --sidebar-border: #ece6db;
  --sidebar-text: #4f4563;
  --sidebar-text-muted: #9a91a8;
  --sidebar-active-bg: #efe6f7;
  --sidebar-active-text: #431b63;
  --sidebar-hover-bg: #f6f2eb;
  --sidebar-group-label: #aaa2b6;

  --topbar-bg: color-mix(in srgb, var(--surface) 88%, transparent);

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 3px rgba(46, 16, 69, 0.06);
  --shadow-md: 0 12px 28px -12px rgba(46, 16, 69, 0.18);
  --shadow-lg: 0 24px 50px -16px rgba(46, 16, 69, 0.26);

  --font-sans: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', monospace;
}

/* -------- Oscuro por preferencia de sistema (sin eleccion explicita) -------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #150b22;
    --surface: #1d1230;
    --surface-2: #231739;
    --surface-raised: #291c41;
    --border: #33254b;
    --border-strong: #46355f;

    --text: #f4effb;
    --text-muted: #b4a9c8;
    --text-faint: #7e7296;

    --primary: #bf98f5;
    --primary-dark: #a47ae8;
    --primary-darker: #8558d1;
    --primary-soft: #2f1d4a;
    --on-primary: #150b22;

    --accent: #3fe89a;
    --accent-strong: #62f0ae;
    --accent-soft: #123a2a;
    --on-accent: #150b22;

    --success: #3fe89a;
    --success-soft: #123a2a;
    --warning: #fbbf24;
    --warning-soft: #2e2310;
    --danger: #ff6b7e;
    --danger-soft: #3a1422;
    --info: #8fa8ff;
    --info-soft: #1b2145;
    --neutral-soft: #261a3b;

    --sidebar-bg: #180d27;
    --sidebar-border: #2a1e3f;
    --sidebar-text: #b4a9c8;
    --sidebar-text-muted: #7e7296;
    --sidebar-active-bg: #2f1d4a;
    --sidebar-active-text: #d2b6fa;
    --sidebar-hover-bg: #221535;
    --sidebar-group-label: #6c6084;

    --topbar-bg: color-mix(in srgb, var(--surface) 80%, transparent);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 12px 28px -12px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 24px 50px -16px rgba(0, 0, 0, 0.65);
  }
}

/* -------- Oscuro elegido a mano (gana aunque el SO este en claro) -------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #150b22;
  --surface: #1d1230;
  --surface-2: #231739;
  --surface-raised: #291c41;
  --border: #33254b;
  --border-strong: #46355f;

  --text: #f4effb;
  --text-muted: #b4a9c8;
  --text-faint: #7e7296;

  --primary: #bf98f5;
  --primary-dark: #a47ae8;
  --primary-darker: #8558d1;
  --primary-soft: #2f1d4a;
  --on-primary: #150b22;

  --accent: #3fe89a;
  --accent-strong: #62f0ae;
  --accent-soft: #123a2a;
  --on-accent: #150b22;

  --success: #3fe89a;
  --success-soft: #123a2a;
  --warning: #fbbf24;
  --warning-soft: #2e2310;
  --danger: #ff6b7e;
  --danger-soft: #3a1422;
  --info: #8fa8ff;
  --info-soft: #1b2145;
  --neutral-soft: #261a3b;

  --sidebar-bg: #180d27;
  --sidebar-border: #2a1e3f;
  --sidebar-text: #b4a9c8;
  --sidebar-text-muted: #7e7296;
  --sidebar-active-bg: #2f1d4a;
  --sidebar-active-text: #d2b6fa;
  --sidebar-hover-bg: #221535;
  --sidebar-group-label: #6c6084;

  --topbar-bg: color-mix(in srgb, var(--surface) 80%, transparent);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 12px 28px -12px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 24px 50px -16px rgba(0, 0, 0, 0.65);
}

/* -------- Claro elegido a mano (gana aunque el SO este en oscuro) -------- */
:root[data-theme="light"] {
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background 0.15s ease, color 0.15s ease;
}
a { color: var(--primary); }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; }
svg { display: block; }

/* -------- Foco visible -- solo con teclado (focus-visible), consistente en toda la app -------- */
a:focus-visible, button:focus-visible, .nav-link:focus-visible, .tab-btn:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px;
}
.theme-toggle .opt:focus-visible { outline-offset: -2px; }
/* Los campos ya marcan el foco con borde + halo (ver input:focus abajo) -- sin doble contorno. */
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 200;
  background: var(--primary); color: var(--on-primary); padding: 10px 16px; border-radius: 999px;
  font-weight: 700; font-size: 0.85rem; text-decoration: none; transition: top 0.15s ease;
}
.skip-link:focus { top: 12px; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 252px; flex-shrink: 0; background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border); display: flex; flex-direction: column;
  padding: 20px 14px; gap: 2px;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
/* Logo de marca -- <img class="mark" src="/logo.svg"> en todas las paginas. */
.mark { width: 32px; height: 32px; border-radius: 9px; display: block; flex-shrink: 0; }
.sidebar-brand .mark { box-shadow: 0 4px 12px -4px rgba(67, 27, 99, 0.55); }
.sidebar-brand h1 { font-size: 1rem; font-weight: 800; color: var(--text); }
.sidebar-brand p { font-size: 0.7rem; color: var(--sidebar-text-muted); text-transform: uppercase; letter-spacing: 0.06em; margin-top: 1px; }

.nav-group-label {
  font-size: 0.66rem; font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--sidebar-group-label); padding: 14px 10px 6px;
}
.nav-group-label:first-of-type { padding-top: 4px; }

.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px;
  color: var(--sidebar-text); text-decoration: none; font-size: 0.85rem; font-weight: 600; cursor: pointer; border: none; background: none; width: 100%; text-align: left;
  transition: background 0.1s, color 0.1s;
}
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { background: var(--sidebar-hover-bg); color: var(--text); }
.nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); font-weight: 700; }
.nav-link.active svg { opacity: 1; }
.nav-link .nav-badge {
  margin-left: auto; font-size: 0.65rem; font-weight: 800; padding: 1px 6px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-dark); min-width: 16px; text-align: center;
}
.sidebar-foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--sidebar-border); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.sidebar-foot .email { font-size: 0.8rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.sidebar-foot-row { display: flex; gap: 8px; align-items: center; }
.sidebar-foot-row .btn { flex: 1; }

.main { flex: 1; min-width: 0; padding: 28px 40px 60px; }
.page-head { margin-bottom: 22px; }
.page-head h2 { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.page-head p { color: var(--text-muted); font-size: 0.88rem; margin-top: 4px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); margin-bottom: 18px; }
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 0.95rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-head h3 svg { width: 16px; height: 16px; color: var(--text-faint); }
.card-head p { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
/* Encabezado con solo titulo + descripcion (sin boton): la descripcion va DEBAJO del titulo, no apretada a la derecha. */
.card-head:has(> h3 + p:last-child) { flex-direction: column; align-items: flex-start; gap: 2px; }

.grid-channels { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }

.channel-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px 18px; background: var(--surface-2); }
.channel-card .ch-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.channel-card .ch-title { display: flex; align-items: center; gap: 9px; }
.channel-card .ch-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; font-size: 1rem; flex-shrink: 0; }
.channel-card .ch-icon svg { width: 17px; height: 17px; }
.channel-card h4 { font-size: 0.9rem; font-weight: 700; }
.channel-card .ch-sub { font-size: 0.74rem; color: var(--text-faint); }
/* LED de estado real por canal (reemplaza la vieja pestaña "Webhooks", ver cargarCanales() en cliente-dashboard.html/dashboard.html) -- verde: conectado y confirmado por el webhook de Meta; amarillo: conectado pero el webhook todavia no se verifica; rojo: error/expirado; gris: sin configurar. */
.canal-led { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.canal-led.led-verde { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.18), 0 0 6px 1px rgba(34,197,94,.7); }
.canal-led.led-amarillo { background: #eab308; box-shadow: 0 0 0 3px rgba(234,179,8,.16), 0 0 6px 1px rgba(234,179,8,.55); }
.canal-led.led-rojo { background: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,.16), 0 0 6px 1px rgba(239,68,68,.55); }
.canal-led.led-gris { background: #9ca3af; }
.channel-card .field-row { margin-top: 10px; }
.channel-card .actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 0.7rem; font-weight: 700; white-space: nowrap; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-neutral { background: var(--neutral-soft); color: var(--text-muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-weight: 700; font-size: 0.8rem; padding: 8px 16px; border-radius: 999px; border: 1px solid transparent;
  cursor: pointer; transition: filter 0.12s, background 0.12s, border-color 0.12s, transform 0.05s; white-space: nowrap; text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--accent-strong) 80%, transparent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-primary .spinner { border-color: color-mix(in srgb, var(--on-accent) 30%, transparent); border-top-color: var(--on-accent); }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 35%, var(--border-strong)); }
.btn-secondary:hover:not(:disabled) { background: var(--primary-soft); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--neutral-soft); color: var(--text); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border-strong)); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover:not(:disabled) { filter: brightness(1.08); }
.btn-icon { padding: 8px; }
.btn-sm { padding: 6px 10px; font-size: 0.74rem; }
.btn-block { width: 100%; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); }
.field .hint { font-size: 0.7rem; color: var(--text-faint); }
input, select, textarea {
  font-family: inherit; font-size: 0.85rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
  padding: 9px 12px; outline: none; width: 100%;
}
/* Casillas y opciones: tamano natural (la regla de arriba estiraba TODO input al 100%, y una casilla quedaba flotando lejos de su texto). */
input[type="checkbox"], input[type="radio"] { width: auto; padding: 0; flex-shrink: 0; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input:disabled { opacity: 0.6; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius-sm); font-size: 0.82rem; border: 1px solid transparent; }
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }

.table-scroll { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
table.data-table th { text-align: left; padding: 9px 14px; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); border-bottom: 1px solid var(--border); }
table.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data-table tbody tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover td { background: var(--surface-2); }
.mono { font-family: var(--font-mono); font-size: 0.86em; color: var(--text-muted); }

/* Panel plegable ("Nuevo cliente" / "Agregar canal") */
.disclosure { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; }
.disclosure-trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; background: transparent; border: none; cursor: pointer; text-align: left;
  font-family: var(--font-sans); font-weight: 700; font-size: 0.88rem; color: var(--text);
}
.disclosure-trigger .plus-icon {
  width: 24px; height: 24px; border-radius: 8px; background: var(--primary-soft); color: var(--primary-dark);
  display: grid; place-items: center; font-size: 1rem; line-height: 1; transition: transform 0.16s; flex-shrink: 0;
}
.disclosure.open .plus-icon { transform: rotate(45deg); }
.disclosure-body { max-height: 0; overflow: hidden; transition: max-height 0.22s ease; }
.disclosure.open .disclosure-body { max-height: 900px; }
.disclosure-body-inner { padding: 2px 18px 18px; border-top: 1px solid var(--border); }

/* Ayuda "¿dónde consigo esto?" dentro de un formulario -- el cliente casi
   nunca sabe dónde sacar phone_number_id/access token de Meta a mano. */
.help-details { margin-top: 10px; border: 1px solid var(--info); border-radius: var(--radius-md); background: var(--info-soft); overflow: hidden; }
.help-details summary { cursor: pointer; padding: 10px 14px; font-size: 0.82rem; font-weight: 600; color: var(--info); list-style: none; display: flex; align-items: center; gap: 8px; }
.help-details summary::-webkit-details-marker { display: none; }
.help-details summary::before { content: '?'; width: 18px; height: 18px; border-radius: 50%; background: var(--info); color: var(--surface); display: grid; place-items: center; font-size: 0.72rem; flex-shrink: 0; }
.help-details[open] summary { border-bottom: 1px solid var(--border); }
.help-details .help-body { padding: 4px 14px 14px 40px; font-size: 0.82rem; color: var(--text-muted); line-height: 1.55; }
.help-details .help-body ol { margin: 6px 0 10px; padding-left: 18px; }
.help-details .help-body li { margin-bottom: 6px; }
.help-details .help-body a { color: var(--info); }

/* -------- Estados vacios/carga -- con icono, nunca un texto plano suelto -------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
  padding: 38px 20px; color: var(--text-faint); font-size: 0.85rem;
}
.empty-state .empty-icon {
  width: 44px; height: 44px; border-radius: 12px; background: var(--neutral-soft);
  display: grid; place-items: center; color: var(--text-faint);
}
.empty-state .empty-icon svg { width: 22px; height: 22px; }
.empty-state strong { color: var(--text-muted); font-size: 0.86rem; font-weight: 700; }
.empty-state.compact { padding: 20px 14px; flex-direction: row; text-align: left; }
.empty-state.compact .empty-icon { width: 32px; height: 32px; border-radius: 9px; }
.empty-state.compact .empty-icon svg { width: 16px; height: 16px; }

.loading-state { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 34px 20px; color: var(--text-faint); font-size: 0.84rem; }

.skeleton { position: relative; overflow: hidden; background: var(--neutral-soft); border-radius: 6px; }
.skeleton::after {
  content: ''; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 55%, transparent), transparent);
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { 100% { transform: translateX(100%); } }
.skeleton-line { height: 12px; margin: 6px 0; }
.skeleton-tile { height: 74px; border-radius: var(--radius-lg); }
.skeleton-card { height: 130px; border-radius: var(--radius-lg); }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.text-sm { font-size: 0.8rem; }
.text-xs { font-size: 0.72rem; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; }
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.hidden, [hidden] { display: none !important; }
/* Oculto a la vista pero legible por lectores de pantalla (etiquetas de campos con icono). */
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.6s linear infinite; display: inline-block; }
.spinner-dark { border: 2px solid var(--border-strong); border-top-color: var(--primary); }

/* -------- Toggle claro/oscuro -------- */
.theme-toggle {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px; border-radius: 999px;
  background: var(--neutral-soft); border: 1px solid var(--border); cursor: pointer;
  color: var(--text-muted); position: relative; width: 100%;
}
.theme-toggle .opt {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 5px; padding: 5px 8px;
  border-radius: 999px; font-size: 0.72rem; font-weight: 700; position: relative; z-index: 1;
  background: none; border: none; color: inherit; cursor: pointer;
  transition: color 0.15s;
}
.theme-toggle .opt svg { width: 13px; height: 13px; }
.theme-toggle[data-active="light"] .opt[data-theme-opt="light"],
.theme-toggle[data-active="dark"] .opt[data-theme-opt="dark"] { color: var(--sidebar-active-text, var(--primary-dark)); }
.theme-toggle .thumb {
  position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px);
  background: var(--surface); border-radius: 999px; box-shadow: var(--shadow-sm);
  transition: transform 0.18s ease; z-index: 0;
}
.theme-toggle[data-active="dark"] .thumb { transform: translateX(100%); }
.theme-toggle-nav { position: fixed; top: 16px; right: 20px; z-index: 60; width: auto; min-width: 92px; }

@media (max-width: 820px) {
  .app-shell { flex-direction: column; }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--sidebar-border);
    padding: 0;
  }

  .sidebar-brand {
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px 14px;
    gap: 9px;
  }
  .sidebar-brand p { display: none; }
  .sidebar-brand h1 { font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar-brand .mark { width: 30px; height: 30px; }

  .sidebar-foot {
    flex: 0 0 auto;
    margin-top: 0;
    padding: 8px 14px;
    border-top: none;
    flex-direction: row;
    align-items: center;
  }
  .sidebar-foot .email { display: none; }
  .sidebar-foot-row { width: auto; }
  .sidebar-foot-row .btn { flex: 0 0 auto; width: auto; padding: 8px 13px; }
  .theme-toggle-nav { position: static; min-width: 0; }
  .theme-toggle-nav .opt span.opt-label { display: none; }

  .nav-group-label { display: none; }

  .sidebar-nav {
    display: flex;
    flex: 1 1 100%;
    order: 3;
    flex-direction: row;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 10px 14px;
    border-top: 1px solid var(--sidebar-border);
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .nav-link {
    width: auto;
    flex-shrink: 0;
    white-space: nowrap;
    padding: 8px 14px;
    border-radius: 999px;
    background: var(--sidebar-hover-bg);
    text-align: center;
  }
  .nav-link.active { background: var(--primary); color: var(--on-primary); }
  .nav-link.active svg { color: var(--on-primary); }

  .main { padding: 16px; }

  input, select, textarea { font-size: 16px; }
}

/* ============================== Portal: vistas, tabs, chart ============================== */

.view { display: none; }
.view.active { display: block; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn { display: inline-flex; align-items: center; gap: 6px; background: transparent; border: none; padding: 9px 14px; font-size: 0.82rem; font-weight: 600; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; flex-shrink: 0; }
.tab-btn svg { width: 14px; height: 14px; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow-sm); }
.stat-tile .stat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-tile .ico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-dark); }
.stat-tile .ico svg { width: 14px; height: 14px; }
.stat-tile .value { font-family: var(--font-mono); font-size: 1.5rem; font-weight: 700; margin-top: 6px; }
.stat-tile .label { color: var(--text-muted); font-size: 0.76rem; margin-top: 3px; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }

.bars { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding-top: 10px; }
.bars .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.bars .bar { width: 100%; max-width: 34px; background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent-strong) 70%, var(--primary))); border-radius: 5px 5px 0 0; min-height: 2px; }
.bars .bar-label { font-size: 0.65rem; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.bars .bar-value { font-size: 0.68rem; color: var(--text-muted); font-family: var(--font-mono); }

.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 6px; }
.breadcrumb a { color: var(--primary); text-decoration: none; cursor: pointer; }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--surface-2); }

.qr-box { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 18px; }
.qr-box img { width: 220px; height: 220px; border-radius: var(--radius-md); border: 1px solid var(--border); background: #fff; object-fit: contain; }
.plan-pill-sm { display: inline-flex; align-items: center; gap: 6px; background: var(--primary-soft); color: var(--primary-dark); font-weight: 700; padding: 4px 11px; border-radius: 999px; font-size: 0.76rem; }

/* -------- Filtros de tabla (Actividad) -------- */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filter-bar select, .filter-bar input { width: auto; min-width: 150px; }
.filter-bar .filter-label { font-size: 0.72rem; font-weight: 700; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }

/* -------- Webhooks -------- */
.webhook-row { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.webhook-row:last-child { border-bottom: none; }
.webhook-row .wh-ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--neutral-soft); flex-shrink: 0; }
.webhook-row .wh-ico svg { width: 17px; height: 17px; }
.webhook-row .wh-body { flex: 1; min-width: 0; }
.webhook-row .wh-body strong { font-size: 0.85rem; font-weight: 700; }
.webhook-row .wh-body .wh-sub { font-size: 0.74rem; color: var(--text-faint); margin-top: 1px; }
.webhook-row .wh-meta { text-align: right; font-size: 0.72rem; color: var(--text-muted); }

/* -------- Cuenta / claves -------- */
.key-box { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px 12px; }
.key-box .mono { flex: 1; overflow-x: auto; white-space: nowrap; }

/* -------- Banner de consentimiento de cookies (sitio publico) -------- */
.cookie-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  background: var(--surface-raised); border-top: 1px solid var(--border); box-shadow: var(--shadow-lg);
  padding: 16px 20px; transform: translateY(110%); transition: transform 0.28s ease;
}
.cookie-banner.show { transform: translateY(0); }
.cookie-banner .wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; max-width: 1120px; margin: 0 auto; }
.cookie-banner .cb-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--primary-soft); color: var(--primary-dark); display: grid; place-items: center; flex-shrink: 0; }
.cookie-banner .cb-icon svg { width: 17px; height: 17px; }
.cookie-banner .cb-text { flex: 1; min-width: 220px; font-size: 0.82rem; color: var(--text-muted); line-height: 1.5; }
.cookie-banner .cb-text strong { color: var(--text); }
.cookie-banner .cb-actions { display: flex; gap: 10px; flex-wrap: wrap; }
@media (max-width: 560px) { .cookie-banner .cb-actions { width: 100%; } .cookie-banner .cb-actions .btn { flex: 1; } }

/* -------- Toasts (reemplazan alert()) -- ver public/ui-feedback.js -------- */
.toast-stack { position: fixed; top: 16px; right: 16px; z-index: 300; display: flex; flex-direction: column; gap: 10px; max-width: 360px; width: calc(100% - 32px); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--radius-md); background: var(--surface-raised); border: 1px solid var(--border); box-shadow: var(--shadow-lg); font-size: 0.85rem; color: var(--text); line-height: 1.4; animation: toast-in 0.18s ease; }
.toast.leaving { animation: toast-out 0.16s ease forwards; }
.toast .toast-ico { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; margin-top: 1px; }
.toast .toast-ico svg { width: 12px; height: 12px; }
.toast-success .toast-ico { background: var(--success-soft); color: var(--success); }
.toast-error .toast-ico { background: var(--danger-soft); color: var(--danger); }
.toast-info .toast-ico { background: var(--info-soft); color: var(--info); }
.toast .toast-msg { flex: 1; }
.toast .toast-close { background: none; border: none; color: var(--text-faint); cursor: pointer; padding: 2px; flex-shrink: 0; border-radius: 4px; }
.toast .toast-close svg { width: 13px; height: 13px; }
.toast .toast-close:hover { color: var(--text); }
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
@media (max-width: 480px) { .toast-stack { left: 16px; right: 16px; max-width: none; top: auto; bottom: 16px; } }

/* -------- Dialogos modales (reemplazan confirm()/prompt()) -- ver public/ui-feedback.js -------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(8, 10, 16, 0.55); backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; z-index: 310; padding: 20px; animation: modal-fade 0.15s ease; }
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal-dialog { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 24px; animation: modal-pop 0.16s ease; }
@keyframes modal-pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-dialog h3 { font-size: 1.05rem; font-weight: 800; margin-bottom: 8px; }
.modal-dialog .modal-msg { font-size: 0.86rem; color: var(--text-muted); line-height: 1.55; margin-bottom: 4px; }
.modal-dialog .field { margin-top: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
@media (max-width: 480px) { .modal-actions { flex-direction: column-reverse; } .modal-actions .btn { width: 100%; } }
.badge .canal-led { width: 7px; height: 7px; box-shadow: none; }
