/* ============================================================
   Iceguin — Cold Storage Monitoring
   Design tokens + base styles
   ============================================================ */

:root {
  /* Surfaces (light) */
  --bg: #fafbfc;
  --surface: #ffffff;
  --surface-2: #f3f5f8;
  --surface-3: #eaeef3;
  --surface-inset: #f7f9fb;

  /* Borders */
  --border: #e4e8ee;
  --border-strong: #cdd5df;
  --border-soft: #eef1f5;

  /* Text */
  --text: #0e1a2b;
  --text-muted: #5a6b80;
  --text-dim: #8a98ad;
  --text-inverse: #ffffff;

  /* Brand — paleta corporativa Mariposa Andina (ver README §"Paleta corporativa") */
  --primary: #92007D;        /* púrpura oscuro corporativo (andes.svg) */
  --primary-hover: #7a006a;
  --accent: #bf1c7f;         /* magenta principal del logo */
  --accent-soft: #fce7f3;    /* rosa pálido derivado del magenta */

  /* Status — solo --warn se alinea al naranja corporativo. --ok y --crit
     se mantienen en verde/rojo semánticos universales por accesibilidad. */
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --ok-fg: #14532d;

  --warn: #e66728;           /* naranja corporativo (seleccionados.svg) */
  --warn-soft: #fff1e3;
  --warn-fg: #7a3010;

  --crit: #dc2626;
  --crit-soft: #fee2e2;
  --crit-fg: #7f1d1d;

  --offline: #6b7280;
  --offline-soft: #f1f3f6;
  --offline-fg: #374151;

  /* Chart — color único para todas las líneas de temperatura.
     Independiente del estado del sensor para no confundir histórico con estado en vivo. */
  --chart-line: #1e40af;
  --chart-line-soft: rgba(30, 64, 175, 0.14);

  /* Type */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Bricolage Grotesque', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-pill: 999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15, 27, 46, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 27, 46, 0.06), 0 1px 2px rgba(15, 27, 46, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 27, 46, 0.06), 0 2px 4px rgba(15, 27, 46, 0.04);
  --shadow-lg: 0 12px 32px rgba(15, 27, 46, 0.10), 0 4px 12px rgba(15, 27, 46, 0.05);

  /* Elevación con propósito — capas para construir jerarquía visual */
  --elev-flat:  0 1px 2px rgba(15, 27, 46, 0.04);
  --elev-card:  0 1px 3px rgba(15, 27, 46, 0.06), 0 4px 16px rgba(15, 27, 46, 0.04);
  --elev-pop:   0 2px 6px rgba(15, 27, 46, 0.08), 0 12px 32px rgba(15, 27, 46, 0.06);
  --elev-modal: 0 8px 28px rgba(15, 27, 46, 0.18), 0 24px 60px rgba(15, 27, 46, 0.12);

  /* Glows por estado — halos sutiles que comunican severidad */
  --glow-crit:   0 0 0 1px rgba(220, 38, 38, 0.20), 0 4px 24px rgba(220, 38, 38, 0.18);
  --glow-warn:   0 0 0 1px rgba(230, 103, 40, 0.22), 0 4px 24px rgba(230, 103, 40, 0.18);
  --glow-accent: 0 0 0 1px rgba(191, 28, 127, 0.20), 0 4px 24px rgba(191, 28, 127, 0.16);
  --glow-ok:     0 0 0 1px rgba(22, 163, 74, 0.18), 0 4px 24px rgba(22, 163, 74, 0.12);

  /* Gradientes brand — derivados de la paleta corporativa */
  --grad-primary: linear-gradient(135deg, #bf1c7f 0%, #92007D 100%);
  --grad-warn:    linear-gradient(135deg, #f0814a 0%, #e66728 100%);
  --grad-crit:    linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  /* Canvas: dos halos rosa/peach muy tenues sobre el bg neutro.
     Da "calor" sin saturar y crea separación tonal con las cards blancas. */
  --grad-canvas:
    radial-gradient(1200px 600px at 15% -10%, rgba(252, 231, 243, 0.55) 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 110%, rgba(255, 241, 227, 0.55) 0%, transparent 55%),
    var(--bg);

  /* Tipografía con peso intencional — escala que comunica jerarquía */
  --t-display: 700 32px/1.1 var(--font-display);
  --t-h1:      700 22px/1.25 var(--font-display);
  --t-h2:      600 16px/1.3 var(--font-display);
  --t-body:    400 13px/1.5 var(--font-sans);
  --t-label:   600 11px/1 var(--font-sans);
  --t-meta:    400 11px/1.4 var(--font-sans);

  /* Transiciones canónicas — todas las animaciones derivan de estas */
  --t-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --sidebar-w: 224px;
  --header-h: 60px;
  --rail-w: 380px;

  /* Density (overridden) */
  --density-pad: 16px;
  --density-row-h: 44px;
}

[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111a2c;
  --surface-2: #1a2438;
  --surface-3: #243049;
  --surface-inset: #0e1626;

  --border: #243049;
  --border-strong: #344661;
  --border-soft: #1a2438;

  --text: #e6ecf5;
  --text-muted: #9aa9bf;
  --text-dim: #6d7d94;
  --text-inverse: #0b1220;

  /* Brand (dark) — variantes más claras del magenta corporativo para
     legibilidad sobre superficies oscuras. */
  --primary: #e879c0;
  --primary-hover: #f5a3d6;
  --accent: #e879c0;
  --accent-soft: #3d0a2c;

  --ok: #34d399;
  --ok-soft: #064e3b;
  --ok-fg: #a7f3d0;

  --warn: #f5a85c;           /* naranja corporativo aclarado para dark */
  --warn-soft: #5c2a10;
  --warn-fg: #ffd7b0;

  --crit: #f87171;
  --crit-soft: #7f1d1d;
  --crit-fg: #fecaca;

  --offline: #94a3b8;
  --offline-soft: #1f2a3d;
  --offline-fg: #cbd5e1;

  --chart-line: #60a5fa;
  --chart-line-soft: rgba(96, 165, 250, 0.16);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);

  /* Elevación dark — sombras más negras, glows más vivos por contraste */
  --elev-flat:  0 1px 2px rgba(0, 0, 0, 0.45);
  --elev-card:  0 1px 3px rgba(0, 0, 0, 0.5), 0 6px 20px rgba(0, 0, 0, 0.35);
  --elev-pop:   0 2px 8px rgba(0, 0, 0, 0.6), 0 16px 40px rgba(0, 0, 0, 0.4);
  --elev-modal: 0 10px 32px rgba(0, 0, 0, 0.7), 0 32px 80px rgba(0, 0, 0, 0.55);

  --glow-crit:   0 0 0 1px rgba(248, 113, 113, 0.35), 0 4px 28px rgba(248, 113, 113, 0.30);
  --glow-warn:   0 0 0 1px rgba(245, 168, 92, 0.35), 0 4px 28px rgba(245, 168, 92, 0.30);
  --glow-accent: 0 0 0 1px rgba(232, 121, 192, 0.30), 0 4px 28px rgba(232, 121, 192, 0.25);
  --glow-ok:     0 0 0 1px rgba(52, 211, 153, 0.28), 0 4px 28px rgba(52, 211, 153, 0.20);

  --grad-primary: linear-gradient(135deg, #e879c0 0%, #bf1c7f 100%);
  --grad-warn:    linear-gradient(135deg, #f5a85c 0%, #e66728 100%);
  --grad-crit:    linear-gradient(135deg, #f87171 0%, #b91c1c 100%);
  /* Canvas dark: halos magenta/púrpura muy tenues sobre el bg azul-noche.
     Suma profundidad sin perder el carácter industrial del modo oscuro. */
  --grad-canvas:
    radial-gradient(1200px 600px at 15% -10%, rgba(146, 0, 125, 0.18) 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 110%, rgba(230, 103, 40, 0.10) 0%, transparent 55%),
    var(--bg);
}

/* ===== Marca Iceguin (mía): SOLO login y consola super-admin =====
   Se activa con data-brand="iceguin" en <html> (lo pone app.jsx en login/admin).
   Las apps de clientes NO llevan este atributo: usan sus propios colores
   (applyBranding setea --primary/--accent inline en :root, que gana sobre esto). */
[data-brand="iceguin"] {
  --primary: #006293;            /* Baltic Blue */
  --primary-hover: #00567f;
  --accent: #01A7C2;             /* Pacific Blue */
  --accent-soft: #e2f5f9;        /* cyan claro para rings/chips */
  --grad-primary: linear-gradient(135deg, #01A7C2 0%, #006293 100%);
  --grad-canvas:
    radial-gradient(1200px 600px at 15% -10%, rgba(1, 167, 194, 0.12) 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 110%, rgba(0, 98, 147, 0.12) 0%, transparent 55%),
    var(--bg);
}
[data-theme="dark"][data-brand="iceguin"] {
  --primary: #01A7C2;            /* más contraste sobre fondo oscuro */
  --primary-hover: #4cc3d6;
  --accent: #01A7C2;
}

[data-density="compact"] {
  --density-pad: 12px;
  --density-row-h: 36px;
}
[data-density="comfortable"] {
  --density-pad: 20px;
  --density-row-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--grad-canvas);     /* halos cálidos sobre bg neutro */
  background-attachment: fixed;        /* el halo no scrollea con el contenido */
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
}

#root { min-height: 100vh; }

button { font-family: inherit; cursor: pointer; }

/* ============================================================
   App shell
   ============================================================ */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border-soft);
  font-weight: 600;
  letter-spacing: -0.01em;
  font-size: 15px;
}
.sidebar-brand-mark {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
  user-select: none;
}

.sidebar-section {
  padding: 14px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  padding: 8px 10px 6px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13.5px;
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
  transition: background 0.12s, color 0.12s;
}
.sidebar-item:hover { background: var(--surface-2); color: var(--text); }
.sidebar-item.active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}
.sidebar-item.active .sidebar-item-icon { color: var(--accent); }
.sidebar-item-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-dim);
}
.sidebar-item-badge {
  margin-left: auto;
  background: var(--crit);
  color: white;
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--r-pill);
  font-family: var(--font-mono);
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border-soft);
}
/* Franja de marca (logotipo Iceguin) al pie del sidebar, debajo de la cuenta. */
.sidebar-brand-footer {
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border-soft);
  text-align: center;
}
.sidebar-footer-brand {
  display: block;
  width: 130px;
  max-width: 78%;
  height: auto;
  margin: 0 auto;
  opacity: 0.9;
  user-select: none;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--r-sm);
}
.sidebar-user:hover { background: var(--surface-2); }
.sidebar-user-avatar {
  width: 30px;
  height: 30px;
  object-fit: contain;
  flex-shrink: 0;
  user-select: none;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; }
.sidebar-user-role { font-size: 11.5px; color: var(--text-dim); }

/* Main */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Header */
.header {
  height: var(--header-h);
  /* depth: el header se separa del canvas con una sombra fina + fondo
     levemente translúcido para que se sienta "encima" */
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border-soft), 0 1px 12px rgba(15, 27, 46, 0.03);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 30;
}
[data-theme="dark"] .header {
  background: rgba(17, 26, 44, 0.80);
}
.header-title {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-title .crumb-sep { color: var(--text-dim); }
.header-title .crumb-muted { color: var(--text-muted); font-weight: 500; }

.plant-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  position: relative;
}
.plant-switcher:hover { background: var(--surface-3); }
.plant-switcher-mark {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  background: var(--primary);
  display: grid;
  place-items: center;
  color: white;
  font-size: 10px;
  font-weight: 700;
}
[data-theme="dark"] .plant-switcher-mark { color: var(--bg); }

.plant-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 50;
}
.plant-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
}
.plant-menu-item:hover { background: var(--surface-2); }
.plant-menu-item.active { background: var(--surface-2); }
.plant-menu-meta { margin-left: auto; font-size: 11.5px; color: var(--text-dim); font-family: var(--font-mono); }

.header-spacer { flex: 1; }

.global-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 8px;
  background: var(--ok-soft);
  color: var(--ok-fg);
  border-radius: var(--r-pill);
  font-size: 12.5px;
  font-weight: 600;
}
.global-status.warn { background: var(--warn-soft); color: var(--warn-fg); }
.global-status.crit { background: var(--crit-soft); color: var(--crit-fg); }
.global-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  background: transparent;
  border: 1px solid transparent;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  position: relative;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .dot-indicator {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--crit);
  border: 2px solid var(--surface);
}

/* Content area */
.content {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr var(--rail-w);
  min-height: 0;
}
.content.no-rail { grid-template-columns: 1fr; }

.canvas {
  padding: 20px 24px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.canvas.tight { padding: 0; }

.rail {
  border-left: 1px solid var(--border);
  /* surface más cálida vs canvas — refuerza la separación del rail */
  background:
    linear-gradient(180deg, var(--surface) 0%, var(--surface) 100%);
  overflow-y: auto;
  max-height: calc(100vh - var(--header-h));
  position: sticky;
  top: var(--header-h);
}

/* ============================================================
   Secciones del rail derecho (Tanda 5)

   Jerarquía: eyebrow uppercase → título 15px → hero value 44px
   (la temperatura es la protagonista) → meta opcional → chart →
   meta cards → CTA. La sección de alertas usa el mismo patrón pero
   con un chip por severidad como meta.
   ============================================================ */
.rail-section {
  padding: 0;
}
.rail-section + .rail-section,
.rail-section--alerts {
  /* separación visual fuerte entre IndicadorRail y AlertsRail */
  border-top: 1px solid var(--border);
  background:
    linear-gradient(180deg, var(--surface-inset) 0%, var(--surface) 24px);
}
.rail-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 16px 6px;
}
.rail-section-body {
  padding: 4px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rail-eyebrow {
  font: var(--t-label);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
}

.rail-title {
  font: var(--t-h2);
  color: var(--text);
}

/* Hero value — la temperatura en grande, único elemento "ruidoso" del rail */
.rail-hero {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  padding: 2px 0 6px;
}
.rail-hero-value {
  font-size: 44px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
  font-family: var(--font-mono);
  font-feature-settings: 'tnum';
}
.rail-hero-target {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Meta cards (Histeresis / Sensor) — fondo tenue, valor mono compacto */
.rail-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.rail-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  background: var(--surface-inset);
  border-radius: var(--r-sm);
  border: 1px solid var(--border-soft);
}
.rail-meta-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 600;
}
.rail-meta-value {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}

.rail-alerts-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.rail-alerts-summary .chip {
  font-size: 10.5px;
  padding: 2px 7px;
}

/* ============================================================
   Components
   ============================================================ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-card);                 /* subimos un nivel: las cards flotan */
  transition: box-shadow var(--t-base), transform var(--t-base);
}
.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-title { font-weight: 600; font-size: 14px; }
.card-sub { font-size: 12px; color: var(--text-muted); }
.card-body { padding: 16px; }
.card-tight .card-body { padding: 0; }

/* ============================================================
   Sistema de botones (Tanda 3)

   Jerarquía:
   - .btn (default): secondary tonal — fondo de superficie con borde
   - .btn.primary: gradiente brand magenta→púrpura + glow al hover
   - .btn.ghost: terciario sin bordes ni fondo
   - .btn.danger: gradiente crit (rojo)
   - .btn.sm / .btn.icon-only: tamaños

   Estados: :hover (lift + sombra), :active (presión visual),
   :focus-visible (anillo de foco accesible), :disabled (opaco),
   .loading (spinner).
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  position: relative;
  transition:
    background var(--t-fast),
    border-color var(--t-fast),
    box-shadow var(--t-base),
    transform var(--t-fast),
    color var(--t-fast);
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  box-shadow: var(--elev-flat);
}
.btn:active { transform: translateY(0.5px); box-shadow: none; }
.btn:focus-visible {
  outline: none;
  box-shadow: var(--glow-accent);
  border-color: var(--accent);
}
.btn:disabled,
.btn.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn:disabled:hover,
.btn.is-disabled:hover {
  background: var(--surface);
  border-color: var(--border);
  box-shadow: none;
}

/* Primary — gradiente brand + glow al hover. CTA con peso visual. */
.btn.primary {
  background: var(--grad-primary);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(15, 27, 46, 0.16);
}
[data-theme="dark"] .btn.primary { color: #ffffff; }
.btn.primary:hover {
  /* el gradiente no se anima — usamos el glow para señalar hover.
     Sombra neutra: funciona con cualquier color de marca (Iceguin azul o cliente). */
  box-shadow: 0 4px 16px rgba(15, 27, 46, 0.22), 0 0 0 1px rgba(15, 27, 46, 0.10);
  transform: translateY(-1px);
  filter: brightness(1.05);
}
.btn.primary:active { filter: brightness(0.95); transform: translateY(0.5px); }
.btn.primary:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-soft), 0 4px 16px rgba(15, 27, 46, 0.22);
}

/* Ghost — terciario para acciones discretas */
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn.ghost:hover {
  background: var(--surface-2);
  border-color: transparent;
  color: var(--text);
  box-shadow: none;
}

/* Danger — para acciones destructivas confirmadas */
.btn.danger {
  background: var(--grad-crit);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 1px 2px rgba(220, 38, 38, 0.20);
}
.btn.danger:hover {
  box-shadow: 0 4px 16px rgba(220, 38, 38, 0.30), 0 0 0 1px rgba(220, 38, 38, 0.35);
  transform: translateY(-1px);
  filter: brightness(1.05);
}
.btn.danger:active { filter: brightness(0.95); transform: translateY(0.5px); }

.btn.sm { padding: 5px 10px; font-size: 12px; gap: 5px; }
.btn.icon-only { padding: 7px; }

/* Loading state — un spinner discreto en lugar del contenido */
.btn.loading { color: transparent !important; pointer-events: none; }
.btn.loading::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
  color: var(--text);
}
.btn.primary.loading::after,
.btn.danger.loading::after { color: #ffffff; }
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
  .btn:hover, .btn:active, .btn.primary:hover { transform: none; }
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.chip.ok { background: var(--ok-soft); color: var(--ok-fg); }
.chip.warn { background: var(--warn-soft); color: var(--warn-fg); }
.chip.crit { background: var(--crit-soft); color: var(--crit-fg); }
.chip.offline { background: var(--offline-soft); color: var(--offline-fg); }
.chip.solid {
  background: var(--primary);
  color: var(--text-inverse);
}
[data-theme="dark"] .chip.solid { color: var(--bg); }

.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  font-weight: 600;
}
.kpi-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-feature-settings: 'tnum';
}
.kpi-value.mono { font-family: var(--font-mono); font-weight: 500; letter-spacing: -0.04em; }
.kpi-trend { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }

/* ============================================================
   KPI cards con estado vivo (Tanda 2)

   Cada card recibe una clase de estado (.ok / .warn / .crit / .info) que
   pinta una barra vertical de acento a la izquierda + ajusta el glow.
   La intención: una alerta crítica debe SENTIRSE crítica con un vistazo.
   ============================================================ */
.kpi-card {
  position: relative;
  overflow: hidden;                  /* contiene el barra de acento */
}
.kpi-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--border);         /* default: barra neutra muy fina */
  transition: background var(--t-base), width var(--t-base);
}
.kpi-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--elev-pop);
}
.kpi-card:hover::before { width: 4px; }

/* Estado OK — barra verde sutil, sin glow (no requiere atención) */
.kpi-card.ok::before { background: var(--ok); }

/* Estado INFO (neutro, "Última lectura" cuando hay datos) — barra accent */
.kpi-card.info::before { background: var(--accent); }

/* Estado WARN — barra naranja brand + glow tibio */
.kpi-card.warn {
  box-shadow: var(--elev-card), var(--glow-warn);
  border-color: rgba(230, 103, 40, 0.28);
}
.kpi-card.warn::before { background: var(--grad-warn); width: 4px; }

/* Estado CRIT — barra roja + glow rojo + pulso suave (animación) */
.kpi-card.crit {
  box-shadow: var(--elev-card), var(--glow-crit);
  border-color: rgba(220, 38, 38, 0.30);
  animation: kpi-pulse-crit 2.4s ease-in-out infinite;
}
.kpi-card.crit::before { background: var(--grad-crit); width: 4px; }

/* El pulso es muy sutil — solo varía la intensidad del glow, no el tamaño.
   En crit es vital que el ojo lo capte sin ser distractor. */
@keyframes kpi-pulse-crit {
  0%, 100% { box-shadow: var(--elev-card),
                          0 0 0 1px rgba(220, 38, 38, 0.30),
                          0 4px 24px rgba(220, 38, 38, 0.18); }
  50%      { box-shadow: var(--elev-card),
                          0 0 0 1px rgba(220, 38, 38, 0.45),
                          0 4px 32px rgba(220, 38, 38, 0.28); }
}
@media (prefers-reduced-motion: reduce) {
  .kpi-card.crit { animation: none; }
}

/* En dark mode los glows son más vivos por contraste */
[data-theme="dark"] .kpi-card.warn { border-color: rgba(245, 168, 92, 0.40); }
[data-theme="dark"] .kpi-card.crit {
  border-color: rgba(248, 113, 113, 0.40);
  animation-name: kpi-pulse-crit-dark;
}
@keyframes kpi-pulse-crit-dark {
  0%, 100% { box-shadow: var(--elev-card),
                          0 0 0 1px rgba(248, 113, 113, 0.40),
                          0 4px 28px rgba(248, 113, 113, 0.28); }
  50%      { box-shadow: var(--elev-card),
                          0 0 0 1px rgba(248, 113, 113, 0.55),
                          0 4px 36px rgba(248, 113, 113, 0.40); }
}

/* El icono del trend se tinta con el estado */
.kpi-card.ok .kpi-trend { color: var(--ok-fg); }
.kpi-card.warn .kpi-trend { color: var(--warn-fg); }
.kpi-card.crit .kpi-trend { color: var(--crit-fg); }

.divider {
  height: 1px;
  background: var(--border-soft);
  margin: 8px 0;
}

.muted { color: var(--text-muted); }
.dim { color: var(--text-dim); }
.mono { font-family: var(--font-mono); }

/* Tabs */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
}
.tab {
  padding: 12px 12px 11px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* Table */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 12px 12px 10px;
  /* refuerzo del border-bottom para que el header se sienta como header */
  border-bottom: 2px solid var(--border);
  background: linear-gradient(180deg, var(--surface-inset) 0%, var(--surface) 100%);
}
.table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-soft);
}
.table tr:hover td { background: var(--surface-inset); }
.table tr:last-child td { border-bottom: none; }
.table tr.row-clickable { cursor: pointer; }
/* Link individual dentro de una celda — sobrescribe el click de la fila. */
.table .row-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.table .row-link:hover { text-decoration: underline; }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  flex: 1;
  min-width: 200px;
  max-width: 360px;
}
.search input {
  border: none;
  outline: none;
  background: transparent;
  flex: 1;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
}
.search input::placeholder { color: var(--text-dim); }

.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 2px;
}
.seg-btn {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* Status bar (alert blink) */
@keyframes blink-soft {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.blink-soft { animation: blink-soft 2s ease-in-out infinite; }

@keyframes zone-blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(2.6); opacity: 0; }
}

/* Sparkline */
.spark {
  display: block;
  width: 100%;
  height: 28px;
}

/* Scrollbars */
.rail::-webkit-scrollbar, .canvas::-webkit-scrollbar { width: 10px; height: 10px; }
.rail::-webkit-scrollbar-track, .canvas::-webkit-scrollbar-track { background: transparent; }
.rail::-webkit-scrollbar-thumb, .canvas::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
  border: 2px solid var(--surface);
}

/* Empty state */
/* ============================================================
   Empty states (Tanda 6)
   Antes: ícono chiquito + texto. Genérico, sin identidad.
   Ahora: contenedor con fondo radial sutil + ícono en círculo con
   acento de marca + tipografía con jerarquía. La mariposa monocroma
   aparece de forma decorativa (opacidad baja) cuando hay espacio.
   ============================================================ */
.empty {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  color: var(--text-muted);
  text-align: center;
  gap: 8px;
  background:
    radial-gradient(420px 220px at 50% 0%, var(--accent-soft) 0%, transparent 60%);
  border-radius: var(--r-md);
}
.empty-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--accent);
  margin-bottom: 4px;
  box-shadow: var(--elev-flat);
}

/* ============================================================
   Skeleton loading (Tanda 6) — para cuando el snapshot/historial
   se está cargando. Reemplaza el "Cargando…" genérico.
   ============================================================ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-2) 0%,
    var(--surface-3) 50%,
    var(--surface-2) 100%
  );
  background-size: 200% 100%;
  border-radius: var(--r-sm);
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}
.skeleton-line {
  height: 12px;
  margin: 6px 0;
}
.skeleton-line.lg { height: 28px; }
.skeleton-line.sm { height: 8px; }

/* ============================================================
   Micro-animaciones (Tanda 7)

   Movimiento con propósito. Cada animación apuntala una lectura
   visual concreta:
   - Cards y row-clickable suben en hover → "esto es interactivo".
   - El contenido entrante hace fade-in con un desplazamiento muy
     pequeño → la pantalla "respira" en lugar de aparecer de golpe.
   - Tabs y seg-btn transicionan suave entre activos.
   - Sidebar item activo trae un slide del indicador.

   Todo apoyado por --t-fast/base/slow definidos en Tanda 1 y
   condicionado a prefers-reduced-motion.
   ============================================================ */

/* Hover de cards no-KPI (las KPI ya tienen su lift en Tanda 2) */
.card:not(.kpi-card):hover {
  box-shadow: var(--elev-pop);
  /* sin translate para no romper layout en cards anchas */
}

/* Fila clickeable de tabla — hover con un toque más visible */
.table tr.row-clickable {
  transition: background var(--t-fast);
}
.table tr.row-clickable:hover td {
  background: var(--accent-soft);
}

/* Sidebar item: indicador izquierdo que entra/sale con la activación */
.sidebar-item {
  position: relative;
  transition: background var(--t-fast), color var(--t-fast);
}
.sidebar-item::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
  transform: scaleY(0);
  transform-origin: center;
  transition: transform var(--t-base);
}
.sidebar-item.active::before { transform: scaleY(1); }

/* Tabs — underline animado en lugar de un toggle abrupto */
.tab { transition: color var(--t-fast); }
.tabs { position: relative; }
.tab.active { color: var(--accent); }

/* Segmented buttons — fondo de activación suave */
.seg-btn { transition: background var(--t-fast), color var(--t-fast); }

/* Aparición progresiva del contenido principal — sutil, no distracción.
   El .content (canvas + rail) entra con fade-up al cambiar de página. */
.content {
  animation: content-enter var(--t-slow) ease-out;
}
@keyframes content-enter {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Stagger para las KPI cards del strip (4 cards entran en cascada chiquita) */
.grid-4 > .card,
.grid-3 > .card {
  animation: card-enter var(--t-slow) ease-out backwards;
}
.grid-4 > .card:nth-child(1), .grid-3 > .card:nth-child(1) { animation-delay: 0ms; }
.grid-4 > .card:nth-child(2), .grid-3 > .card:nth-child(2) { animation-delay: 60ms; }
.grid-4 > .card:nth-child(3), .grid-3 > .card:nth-child(3) { animation-delay: 120ms; }
.grid-4 > .card:nth-child(4)                              { animation-delay: 180ms; }
@keyframes card-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .content,
  .grid-4 > .card, .grid-3 > .card,
  .sidebar-item::before { animation: none; transition: none; }
}

/* Alert row */
.alert-row {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  padding: 12px 16px 12px 18px;     /* +2px izq para dejar lugar al strip */
  border-bottom: 1px solid var(--border-soft);
  align-items: start;
  cursor: pointer;
  transition: background var(--t-fast), padding-left var(--t-fast);
}
/* Indicador lateral izquierdo por severidad (oculto en .ack) */
.alert-row::before {
  content: '';
  position: absolute;
  left: 0; top: 12px; bottom: 12px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--border);
  transition: background var(--t-fast), width var(--t-fast);
}
.alert-row:has(.alert-icon-wrap.crit)::before    { background: var(--crit); }
.alert-row:has(.alert-icon-wrap.warn)::before    { background: var(--warn); }
.alert-row:has(.alert-icon-wrap.offline)::before { background: var(--offline); }
.alert-row:hover {
  background: var(--surface-inset);
  padding-left: 22px;
}
.alert-row:hover::before { width: 5px; }
.alert-row:last-child { border-bottom: none; }
.alert-row.ack { opacity: 0.55; }
.alert-row.ack::before { background: var(--border-strong); }
.alert-icon-wrap {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.alert-icon-wrap.crit { background: var(--crit-soft); color: var(--crit); }
.alert-icon-wrap.warn { background: var(--warn-soft); color: var(--warn); }
.alert-icon-wrap.offline { background: var(--offline-soft); color: var(--offline); }
.alert-title { font-weight: 600; font-size: 13.5px; }
.alert-meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.alert-meta .mono { color: var(--text-muted); }

/* Sensor list item */
.sensor-row {
  display: grid;
  grid-template-columns: 28px 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}
.sensor-row:last-child { border-bottom: none; }
.sensor-row .sensor-id { font-family: var(--font-mono); font-size: 12px; color: var(--text); font-weight: 500; }
.sensor-row .sensor-loc { color: var(--text-muted); font-size: 11.5px; }
.sensor-row .sensor-val { font-family: var(--font-mono); font-weight: 500; font-size: 13px; }
.sensor-icon {
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  display: grid; place-items: center;
  color: var(--text-muted);
}

/* Camera */
.camera-tile {
  position: relative;
  border-radius: var(--r-md);
  overflow: hidden;
  background: #0b0e14;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border);
}
.camera-grid-bg {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.04) 1px, transparent 1px);
  background-size: 24px 24px;
}
.camera-noise {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 30% 40%, rgba(96,165,250,0.15), transparent 50%),
    radial-gradient(circle at 70% 70%, rgba(255,255,255,0.05), transparent 60%);
}
.camera-label {
  position: absolute;
  top: 10px; left: 10px;
  background: rgba(0,0,0,0.55);
  color: white;
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 3px 7px;
  border-radius: var(--r-xs);
  display: flex; align-items: center; gap: 6px;
}
.camera-label .rec-dot {
  width: 6px; height: 6px; border-radius: 50%; background: #ef4444;
  animation: blink-soft 1.6s infinite;
}
.camera-time {
  position: absolute;
  bottom: 10px; right: 10px;
  background: rgba(0,0,0,0.55);
  color: white;
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 3px 7px;
  border-radius: var(--r-xs);
}

/* Generic grids */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* Toggle */
.toggle {
  width: 32px; height: 18px;
  background: var(--border-strong);
  border-radius: var(--r-pill);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.toggle::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  background: white;
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: left 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.toggle.on { background: var(--accent); }
.toggle.on::after { left: 16px; }

/* Map specific */
.map-stage {
  position: relative;
  flex: 1;
  background: var(--surface-inset);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  min-height: 580px;
}
.map-controls {
  position: absolute;
  top: 14px; right: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-sm);
  padding: 4px;
  z-index: 5;
}
.map-controls .icon-btn { width: 28px; height: 28px; }

.map-legend {
  position: absolute;
  bottom: 14px; left: 14px;
  display: flex;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  box-shadow: var(--shadow-sm);
  font-size: 11.5px;
  color: var(--text-muted);
  z-index: 5;
}
.map-legend-item { display: flex; align-items: center; gap: 6px; }
.map-legend-dot { width: 8px; height: 8px; border-radius: 50%; }

.map-stats-overlay {
  position: absolute;
  top: 14px; left: 14px;
  display: flex;
  gap: 8px;
  z-index: 5;
}
.map-stat-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
}
.map-stat-pill .mono { font-family: var(--font-mono); font-weight: 600; }

/* Pulse animation for sensors */
@keyframes sensor-pulse {
  0% { transform: scale(0.8); opacity: 0.7; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* Page header */
.page-head {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding-bottom: 4px;
}
.page-head h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
}
.page-head .page-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}
.page-head-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* Status pill on cards */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 6px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: var(--r-pill);
  background: var(--ok-soft);
  color: var(--ok-fg);
}
.status-pill.warn { background: var(--warn-soft); color: var(--warn-fg); }
.status-pill.crit { background: var(--crit-soft); color: var(--crit-fg); }
.status-pill.offline { background: var(--offline-soft); color: var(--offline-fg); }
.status-pill svg { width: 12px; height: 12px; }

/* Form */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.input, select.input, textarea.input {
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ============================================================
   Modal y toasts in-page (DialogHost)
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(8, 12, 22, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  z-index: 1000;
  padding: 16px;
  animation: modalFadeIn 120ms ease-out;
}
@keyframes modalFadeIn { from { opacity: 0 } to { opacity: 1 } }

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35), 0 4px 12px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  animation: modalCardIn 140ms ease-out;
}
@keyframes modalCardIn {
  from { opacity: 0; transform: translateY(6px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.modal-header {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-title {
  flex: 1; margin: 0;
  font-size: 15px; font-weight: 600;
  color: var(--text);
}
.modal-close {
  background: transparent; border: 0;
  color: var(--text-dim);
  font-size: 22px; line-height: 1;
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

.modal-body {
  padding: 14px 16px 6px 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-message {
  margin: 0;
  font-size: 13.5px; line-height: 1.45;
  color: var(--text-muted);
  white-space: pre-wrap;
}
.modal-backdrop.danger .modal-message { color: var(--text); }

.modal-field {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px;
}
.modal-label {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.modal-input, .modal-select {
  padding: 9px 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--surface-inset);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.modal-input:focus, .modal-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.modal-input.has-error, .modal-select.has-error {
  border-color: var(--crit);
  box-shadow: 0 0 0 3px var(--crit-soft);
}
textarea.modal-input { resize: vertical; min-height: 70px; }

.modal-error {
  font-size: 12px;
  color: var(--crit);
  font-weight: 500;
}
.modal-help {
  font-size: 11.5px;
  color: var(--text-dim);
}

.modal-actions {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px 14px 16px;
  border-top: 1px solid var(--border-soft);
  background: var(--surface-inset);
}

.btn.danger {
  background: var(--crit);
  color: #fff;
  border-color: var(--crit);
}
.btn.danger:hover { filter: brightness(1.05); }

/* ----- Toast stack ----- */
.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex; flex-direction: column;
  gap: 8px;
  z-index: 1100;
  max-width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast-item {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--r-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-size: 13px;
  color: var(--text);
  animation: toastIn 180ms ease-out;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast-item.error   { border-left-color: var(--crit); }
.toast-item.success { border-left-color: var(--ok); }
.toast-item.info    { border-left-color: var(--accent); }
.toast-item.warn    { border-left-color: #f59e0b; }
.toast-message { flex: 1; line-height: 1.4; word-break: break-word; }
.toast-close {
  background: transparent; border: 0;
  color: var(--text-dim);
  font-size: 18px; line-height: 1;
  cursor: pointer; padding: 0 4px;
}
.toast-close:hover { color: var(--text); }

/* ----- WhatsApp en Alertas ----- */
.wa-panel {
  margin-top: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--r-md);
  background: var(--surface-inset);
  color: var(--text);
}
.wa-panel.connected { border-left-color: var(--ok); }
.wa-panel.disconnected { border-left-color: var(--offline); }
.wa-panel.problem {
  border-left-color: var(--warn);
  box-shadow: 0 0 0 1px rgba(230, 103, 40, 0.12);
}
.wa-panel-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.wa-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}
.wa-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: var(--ok-soft);
  color: var(--ok-fg);
}
.wa-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.wa-sub {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.wa-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: var(--r-pill);
  font-size: 12px;
  font-weight: 700;
}
.wa-status.connected { background: var(--ok-soft); color: var(--ok-fg); }
.wa-status.disconnected { background: var(--offline-soft); color: var(--offline-fg); }
.wa-status.problem { background: var(--warn-soft); color: var(--warn-fg); }
.wa-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
}
.wa-problem {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: var(--warn-soft);
  color: var(--warn-fg);
  font-size: 12px;
  line-height: 1.35;
  word-break: break-word;
}
.wa-problem.muted {
  background: var(--offline-soft);
  color: var(--offline-fg);
}
.wa-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.wa-phone-modal { max-width: 460px; }
.wa-phone-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.wa-country-select {
  flex: 0 0 200px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%237a7a7a' stroke-width='1.5'><path d='M1 1.5l5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px 8px;
  padding-right: 32px;
}
.wa-country-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(151, 71, 255, 0.15);
}
.wa-phone-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-family: var(--mono, ui-monospace, monospace);
  letter-spacing: 0.4px;
}
.wa-phone-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(151, 71, 255, 0.15);
}
@media (max-width: 540px) {
  .wa-phone-row { flex-direction: column; }
  .wa-country-select { flex: 1 1 auto; }
}

.wa-qr-modal { max-width: 420px; }
.wa-qr-box {
  display: grid;
  place-items: center;
  min-height: 260px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: #ffffff;
  padding: 14px;
}
.wa-qr-box img,
.wa-qr-svg svg {
  width: min(260px, 72vw);
  height: min(260px, 72vw);
  display: block;
}
.wa-qr-fallback {
  max-width: 100%;
  word-break: break-all;
  color: #0e1a2b;
  font-size: 11px;
}
.wa-pairing {
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  font-size: 12px;
}
.wa-list-modal { max-width: 820px; }
.wa-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.wa-list-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(260px, 1.4fr) auto auto;
  gap: 8px;
  align-items: center;
}
.wa-list-nombre { min-width: 0; }
.wa-list-phone { min-width: 0; }
.wa-list-phone .wa-country-select { flex: 0 0 110px; padding: 8px 26px 8px 10px; font-size: 13px; }
.wa-list-phone .wa-phone-input { padding: 8px 10px; font-size: 14px; }
@media (max-width: 640px) {
  .wa-list-row {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "nombre delete"
      "phone  phone"
      "active active";
    row-gap: 6px;
  }
  .wa-list-nombre { grid-area: nombre; }
  .wa-list-phone { grid-area: phone; }
  .wa-list-row > .wa-toggle { grid-area: active; }
  .wa-list-row > .icon-only { grid-area: delete; }
}
.wa-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}
.wa-toggle input { accent-color: var(--accent); }

/* ============================================================
   Viewport del plano + controles de zoom flotantes
   ============================================================ */
.plano-viewport {
  /* width / aspectRatio / background / border / radius vienen inline desde el JSX
     para que el aspect ratio dependa del plano cargado. Acá ponemos solo el
     comportamiento de la "cámara": cursor de pan + sin selección de texto. */
  cursor: grab;
  /* Sombra elevada + halo brand sutil: el plano es el corazón visual del
     dashboard, merece "despegarse" del canvas. */
  box-shadow:
    0 1px 3px rgba(15, 27, 46, 0.10),
    0 12px 32px rgba(15, 27, 46, 0.08),
    0 0 0 1px rgba(191, 28, 127, 0.06);
  transition: box-shadow var(--t-base);
}
.plano-viewport:hover {
  box-shadow:
    0 2px 6px rgba(15, 27, 46, 0.12),
    0 16px 40px rgba(15, 27, 46, 0.10),
    0 0 0 1px rgba(191, 28, 127, 0.12);
}
.plano-viewport.panning { cursor: grabbing; }
/* A zoom 1 no hay nada que pan-ear: dejamos el cursor por defecto para que
   el usuario no se confunda creyendo que puede arrastrar el plano. */
.plano-viewport.no-pan { cursor: default; }
/* El pin sigue mostrando su propio cursor (grab/pointer) por encima. */
.plano-viewport .indicador-pin { cursor: inherit; }
.plano-viewport.no-pan .indicador-pin { cursor: pointer; }
.plano-viewport.no-pan .indicador-pin.editable { cursor: grab; }

.plano-zoom-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-sm);
  user-select: none;
}
.plano-zoom-controls button {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  color: var(--text);
  display: grid;
  place-items: center;
  padding: 0;
}
.plano-zoom-controls button:hover:not(:disabled) { background: var(--surface-inset); }
.plano-zoom-controls button:active:not(:disabled) { background: var(--surface-3); }
.plano-zoom-controls button:disabled { opacity: 0.35; cursor: default; }
.plano-zoom-controls span {
  font-size: 11.5px;
  font-weight: 500;
  min-width: 44px;
  text-align: center;
  color: var(--text-muted);
  letter-spacing: -0.01em;
}

/* En móvil reducimos un toque los controles para que no tapen el plano. */
@media (max-width: 640px) {
  .plano-zoom-controls { top: 8px; right: 8px; gap: 0; padding: 3px; }
  .plano-zoom-controls button { width: 26px; height: 26px; }
  .plano-zoom-controls span { font-size: 11px; min-width: 38px; }
}

/* ============================================================
   Leyenda de estados — overlay flotante en el plano del Dashboard
   y también renderizada inline en la card de la página Alertas.
   El wrapper `.alert-legend-overlay` se ancla a la esquina superior
   izquierda de `.dashboard-plano-wrap`; vive FUERA del `.plano-stage`
   así que no se mueve cuando el operador hace zoom/pan/pinch.
   ============================================================ */
.alert-legend-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 20;
  /* Sin pointer-events: none — queremos que el texto siga siendo
     seleccionable y los <b> internos hoverables. El overlay es chico
     y no tapa los pines, así que el "robo de eventos" es aceptable. */
}
.alert-legend {
  list-style: none;
  margin: 0;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  max-width: 320px;
}
.alert-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.alert-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--surface) 70%, transparent);
}

@media (max-width: 640px) {
  .alert-legend-overlay { top: 8px; left: 8px; }
  .alert-legend { font-size: 10.5px; padding: 6px 10px; gap: 4px; max-width: 240px; }
}

/* ============================================================
   Pines de indicadores sobre el plano (PlanoEditor)

   Diseño: mariposa transparente (cambia de color por estado) con la
   temperatura sobreimpresa en el centro de su cuerpo, y el nombre del
   sensor debajo. Texto blanco con text-shadow para legibilidad sobre
   cualquier fondo del plano. Sin cajita/marco.
   ============================================================ */
.indicador-pin {
  position: absolute;
  /* `left` / `top` / `transform: translate(-50%,-50%) scale(escala)` los aplica
     el JSX inline. Acá solo definimos layout interno y feedback visual. */
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: auto;
  transition: filter 0.12s;
}
.indicador-pin:hover { filter: brightness(1.06); }
.indicador-pin.selected {
  /* outline punteado alrededor de TODO el pin (mariposa + nombre) */
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  border-radius: 6px;
}

/* Bloque "figura": contiene la mariposa + la temperatura sobreimpresa.
   Tamaño base 88×88 — el padre `.indicador-pin` lo escala vía CSS transform. */
.indicador-pin-figure {
  position: relative;
  width: 88px;
  height: 88px;
  display: grid;
  place-items: center;
}
.indicador-pin-butterfly {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  /* Halo suave para que la mariposa se separe del plano cuando hay zonas
     claras de fondo. Sutil — no rompe la sensación de "calcomanía". */
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
  transition: filter var(--t-base);
}

/* Pines vivos por estado (Tanda 4)

   - selected: glow magenta brand para resaltar la elección del usuario.
   - crit: pulso de halo rojo que llama la atención sin tapar la mariposa.
   - warn: glow naranja persistente (no pulsa).
   - offline: drop-shadow más neutra, mariposa negra ya comunica el estado.

   La animación es sobre `filter: drop-shadow()` para que respete el
   PNG transparente de la mariposa (un box-shadow se vería como rectángulo). */
.indicador-pin.crit .indicador-pin-butterfly {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35))
          drop-shadow(0 0 6px rgba(220, 38, 38, 0.55));
  animation: pin-pulse-crit 2s ease-in-out infinite;
}
.indicador-pin.warn .indicador-pin-butterfly {
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35))
          drop-shadow(0 0 6px rgba(230, 103, 40, 0.50));
}
.indicador-pin.selected .indicador-pin-butterfly {
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.45))
          drop-shadow(0 0 8px rgba(191, 28, 127, 0.65));
}

@keyframes pin-pulse-crit {
  0%, 100% { filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35))
                     drop-shadow(0 0 6px rgba(220, 38, 38, 0.45)); }
  50%      { filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35))
                     drop-shadow(0 0 14px rgba(220, 38, 38, 0.75)); }
}
@media (prefers-reduced-motion: reduce) {
  .indicador-pin.crit .indicador-pin-butterfly { animation: none; }
}

/* Temperatura: centrada sobre el cuerpo de la mariposa.
   El cuerpo está visualmente un poco arriba del centro geométrico del PNG,
   por eso usamos -56% en lugar de -50%. */
.indicador-pin-temp {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -56%);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  color: #ffffff;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.7),
    0 0 6px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  pointer-events: none;
}

/* Nombre del sensor debajo de la mariposa. */
.indicador-pin-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #ffffff;
  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.85),
    0 0 4px rgba(0, 0, 0, 0.6);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

/* Botón × (eliminar) — esquina superior derecha del bloque figure */
.indicador-pin-x {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--crit);
  color: #fff;
  border: 2px solid var(--surface);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  z-index: 3;
}
.indicador-pin-x:hover { filter: brightness(1.1); }

/* Handle de redimensionar — esquina inferior derecha del bloque figure */
.indicador-pin-resize {
  position: absolute;
  bottom: -6px;
  right: -6px;
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  background: var(--surface);
  border-radius: 3px;
  cursor: nwse-resize;
  z-index: 3;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  display: block;
}
.indicador-pin-resize:hover { background: var(--accent); }

/* ============================================================
   Responsive — tablet (≤1024px) y mobile (≤640px).
   El CSS original era 100% desktop; agregamos overrides hacia
   abajo (no es mobile-first). 2 piezas clave:

   1) Sidebar pasa a ser un DRAWER en ≤1024px:
      - oculta por default (`transform: translateX(-100%)`),
      - se abre con `.sidebar.open` (el JSX agrega esa clase
        cuando el botón hamburguesa lo dispara),
      - tiene un backdrop `.sidebar-backdrop` que cuando
        recibe `.open` ocupa toda la pantalla y al click cierra.
   2) El layout principal `.app` cambia a 1 sola columna
      (sin sidebar fija) y el `.content` apila canvas + rail.
   ============================================================ */

/* Botón hamburguesa: oculto por default, visible solo en mobile/tablet */
.btn-menu { display: none !important; }
.sidebar-backdrop { display: none; }

/* ============================================================
   App — modo Dashboard (Inicio)

   En la pestaña Inicio el plano es el foco absoluto: la sidebar
   se oculta y queda accesible vía drawer overlay (hamburguesa
   visible), el plano ocupa todo el canvas disponible. El resto
   de las pestañas mantienen el comportamiento anterior.
   ============================================================ */
.app--dashboard {
  grid-template-columns: 1fr;
}
.app--dashboard .sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 280px;
  max-width: 85vw;
  transform: translateX(-100%);
  transition: transform var(--t-base);
  z-index: 50;
  box-shadow: var(--elev-pop);
}
.app--dashboard .sidebar.open { transform: translateX(0); }
.app--dashboard .btn-menu { display: inline-flex !important; }

/* El backdrop del drawer (ya existe para mobile <=1024px) — lo activamos
   también en Dashboard cuando la sidebar está abierta. La regla genérica
   del backdrop (.sidebar-backdrop.open) sigue funcionando. */
.app--dashboard .sidebar-backdrop { display: none; }
.app--dashboard .sidebar-backdrop.open {
  display: block;
  position: fixed;
  inset: 0;
  background: rgba(15, 27, 46, 0.45);
  z-index: 49;
  animation: backdrop-fade-in var(--t-fast) ease-out;
}
@keyframes backdrop-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* Content del Dashboard: ocupa todo el espacio disponible (alto = viewport
   menos el header). Sin padding ni rail. Sin animación de entrada porque
   un fade-up de pantalla completa marea. */
.content.dashboard-bleed {
  display: flex;
  flex-direction: column;
  padding: 0;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
  animation: none;
}

/* Wrapper del plano: ocupa el alto del .dashboard-bleed (header global ya
   está fuera del .content, así que el plano vive en su propio contenedor). */
.dashboard-plano-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  /* El viewport interno (con aspect-ratio = al del plano del piso activo)
     queda centrado y crece hasta el límite disponible. Sin esto el viewport
     dejaba espacio sobrante a los costados o arriba/abajo con object-fit. */
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Acciones del Dashboard montadas en el header global (vía prop `dashboardActions`).
   Reemplaza al breadcrumb tradicional cuando page === 'dashboard'.

   Layout: el container ocupa todo el ancho disponible (flex:1) — el
   header-spacer se neutraliza en modo Dashboard para no competir con
   este flex y dejar a los botones pegarse al borde derecho de las
   acciones (margin-left: auto en .page-head-actions). */
.header-dashboard-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1 1 auto;
  min-width: 0;
}
.app--dashboard .header-spacer { flex: 0 0 0; }
.header-dashboard-actions > div:first-child {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.1;
  flex-shrink: 0;                /* el título no se comprime */
  min-width: 0;
}
.header-h1 {
  font: var(--t-h2);
  margin: 0;
  line-height: 1.1;
  color: var(--text);
  white-space: nowrap;           /* "Resumen en vivo" en una sola línea */
}
.header-sub {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}
.header-dashboard-actions .page-head-actions {
  margin-left: auto;             /* empuja los botones al borde derecho */
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

/* ─── Selector de piso (dropdown a la derecha del título "Resumen en vivo") ─── */
.piso-switcher {
  position: relative;
  flex-shrink: 0;
}
.piso-switcher-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font: var(--t-body);
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
  max-width: 220px;
}
.piso-switcher-btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.piso-switcher-btn.open { background: var(--surface-3); border-color: var(--primary); }
.piso-switcher-btn .piso-switcher-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}
.piso-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 240px;
  max-width: 320px;
  /* Fondo opaco: --surface (no existe --surface-1 en los tokens del proyecto;
     antes el menú quedaba transparente sobre el plano oscuro del Dashboard). */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--elev-pop);
  padding: 6px;
  z-index: 50;
  animation: piso-menu-in 120ms cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes piso-menu-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.piso-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  font: var(--t-body);
  color: var(--text);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}
.piso-menu-item:hover { background: var(--surface-2); }
.piso-menu-item.active {
  background: var(--accent-soft);
  color: var(--primary);
  font-weight: 600;
}
.piso-menu-mark {
  display: inline-flex;
  width: 14px;
  height: 14px;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  flex-shrink: 0;
}
.piso-menu-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.piso-menu-actions {
  display: inline-flex;
  gap: 2px;
  align-items: center;
}
.piso-menu-actions .icon-btn.sm {
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--text-dim);
}
.piso-menu-actions .icon-btn.sm:hover { color: var(--text); background: var(--surface-3); }
.piso-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}
.piso-menu-create {
  color: var(--primary);
  font-weight: 600;
}
.piso-menu-create:hover { background: var(--accent-soft); }
.piso-menu-create .piso-menu-mark { color: var(--primary); }

/* ============================================================
   Bell popover — notificaciones del header

   Reemplaza la navegación directa a /alerts del bell por una tarjeta
   flotante que aparece debajo del ícono. Lista las alertas activas
   agrupadas por severidad; "Ver todas" navega a la pestaña Alertas.
   ============================================================ */
.bell-wrap { position: relative; display: inline-flex; }
.bell-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  font-family: var(--font-mono);
  display: grid;
  place-items: center;
  pointer-events: none;
  box-shadow: 0 0 0 2px var(--surface);
}
.bell-badge.crit { background: var(--crit); }
.bell-badge.warn { background: var(--warn); }
.icon-btn.has-crit { color: var(--crit); }

.bell-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: -4px;
  width: 360px;
  max-width: calc(100vw - 16px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--elev-pop);
  z-index: 60;
  animation: pop-in var(--t-base) cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.96); }
  to   { opacity: 1; transform: none; }
}
.bell-popover-head {
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-inset);
}
.bell-popover-title {
  font: var(--t-h2);
  color: var(--text);
}
.bell-popover-body {
  max-height: 360px;
  overflow-y: auto;
}
.bell-popover-foot {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: none;
  border-top: 1px solid var(--border-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--t-fast);
}
.bell-popover-foot:hover { background: var(--accent-soft); }

/* Mobile: el popover ocupa todo el ancho disponible y se centra debajo del
   header en lugar de salir desde el borde derecho. */
@media (max-width: 640px) {
  .bell-popover { right: 8px; left: 8px; width: auto; }
}

/* ============================================================
   PinPopover — tarjeta flotante al hacer click en un pin del plano

   Se posiciona vía JS (position: fixed con left/top calculados desde
   el rect del pin). El JS la reposiciona en resize/scroll/zoom/pan
   del plano. Misma estética que el bell popover.
   ============================================================ */
.pin-popover {
  position: fixed;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--elev-pop);
  z-index: 55;
  display: flex;
  flex-direction: column;
  animation: pop-in var(--t-base) cubic-bezier(0.34, 1.56, 0.64, 1);
}
.pin-popover-head {
  padding: 12px 14px 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border-soft);
}
.pin-popover-close {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--r-xs);
  display: grid;
  place-items: center;
  transition: background var(--t-fast), color var(--t-fast);
}
.pin-popover-close:hover { background: var(--surface-2); color: var(--text); }
.pin-popover-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pin-popover-value {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1;
  font-feature-settings: 'tnum';
}

@media (max-width: 1024px) {
  /* === Layout shell: sidebar como drawer fijo === */
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: 280px;
    max-width: 85vw;
    transform: translateX(-100%);
    transition: transform 0.22s ease-out;
    z-index: 900;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
  }
  .sidebar-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(8, 12, 22, 0.45);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 899;
    animation: backdropFadeIn 0.18s ease-out;
  }
  @keyframes backdropFadeIn { from { opacity: 0 } to { opacity: 1 } }

  .btn-menu { display: inline-flex !important; }

  /* === Content: apilamos canvas y rail === */
  .content {
    grid-template-columns: 1fr;
  }
  .rail {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  /* === KPIs: 4-col → 2-col === */
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }

  /* === Header — esconder elementos secundarios === */
  .icon-btn[title="Ayuda"] { display: none; }

  /* === Tabs y segmented controls scroll-x === */
  .tabs, .seg {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar,
  .seg::-webkit-scrollbar { display: none; }

  /* === Tablas con scroll-x si no entran === */
  .card .table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 640px) {
  /* === KPIs: ya están en 2-col, los grid-3 a 1-col === */
  .grid-4 { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .grid-3 { grid-template-columns: 1fr; }

  /* === Header compacto === */
  .global-status {
    padding: 4px;
    font-size: 0;            /* esconde el label */
  }
  .global-status .global-status-dot {
    width: 10px; height: 10px;
  }
  .header-title .crumb-muted { display: none; }
  .header-title { font-size: 13px; gap: 4px; }
  .plant-switcher {
    min-width: 0;
    max-width: 50vw;
  }
  .plant-switcher span:not(.plant-switcher-mark) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 30vw;
  }

  /* === Pines de indicadores más chicos === */
  .indicador-pin-body {
    min-width: 64px;
    padding: 5px 8px 4px 8px;
    border-radius: 11px;
  }
  .indicador-pin-temp { font-size: 13px; }
  .indicador-pin-name { font-size: 8px; letter-spacing: 0.06em; }

  /* === Touch targets 44x44 mínimo en iconos del header === */
  .icon-btn {
    min-width: 40px;
    min-height: 40px;
  }
  .btn { min-height: 36px; }

  /* === Padding general más chico === */
  .canvas, .canvas.tight { padding: 12px; gap: 12px; }
  .modal-card { max-width: calc(100vw - 24px); }

  /* === Reducir KPI value gigante === */
  .kpi-value { font-size: 22px; }

  /* === Page-head wrap === */
  .page-head {
    flex-wrap: wrap;
    gap: 10px;
  }
  .page-head h1 { font-size: 22px; }
  .page-head-actions {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* === Card padding reducido === */
  .card { padding: 14px; }
  .card-tight, .card.card-tight { padding: 0; }
  .wa-actions { justify-content: stretch; }
  .wa-actions .btn { flex: 1 1 130px; }
  .wa-list-row { grid-template-columns: 1fr; }
  .wa-list-row .btn.icon-only { justify-self: end; }

  /* === Sidebar con padding ajustado === */
  .sidebar { width: 280px; }
  .sidebar-section { padding: 0 10px 10px; }
}

/* === Targets táctiles más generosos en cualquier touch device === */
@media (hover: none) and (pointer: coarse) {
  .indicador-pin { padding: 4px; }
  .seg-btn, .tab { padding: 8px 12px; }
}

/* ============================================================
   Informes (page-reports.jsx) — wizard + previsualización
   ============================================================ */

.wizard-canvas { max-width: 960px; }

.wizard-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin: 4px 0 4px;
  font-size: 12.5px;
}
.wizard-step {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  padding: 6px 14px 6px 0;
  position: relative;
}
.wizard-step + .wizard-step::before {
  content: '';
  display: block;
  width: 28px;
  height: 1px;
  background: var(--border-strong);
  margin-right: 8px;
}
.wizard-step.active { color: var(--text); font-weight: 600; }
.wizard-step.done { color: var(--text-muted); }
.wizard-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  font-size: 11.5px;
  font-weight: 600;
  font-family: var(--font-mono);
}
.wizard-step.active .wizard-step-num {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.wizard-step.done .wizard-step-num {
  background: var(--ok);
  color: white;
  border-color: var(--ok);
}

.wizard-card { display: flex; flex-direction: column; }

.wizard-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px solid var(--border-soft);
  background: var(--surface);
}

.wizard-radio-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wizard-radio {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.wizard-radio:hover { border-color: var(--border-strong); background: var(--surface-2); }
.wizard-radio.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.wizard-radio input { position: absolute; opacity: 0; pointer-events: none; }
.wizard-radio-mark {
  flex-shrink: 0;
  width: 16px; height: 16px;
  border-radius: 999px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  position: relative;
  margin-top: 2px;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.wizard-radio.active .wizard-radio-mark {
  border-color: var(--accent);
  background: var(--accent);
}
.wizard-radio.active .wizard-radio-mark::after {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 999px;
  background: white;
}
.wizard-radio-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wizard-radio-title { font-weight: 600; font-size: 14px; color: var(--text); }
.wizard-radio-desc { font-size: 12.5px; color: var(--text-muted); }

.wizard-field-group { display: flex; flex-direction: column; gap: 6px; }
.wizard-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}
.wizard-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  border: 1px solid var(--border-soft);
  color: var(--text);
  font-size: 13.5px;
}
.wizard-inline-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.wizard-inline-field > span:first-child {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.wizard-help {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.wizard-preview-wrap { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Informe (printable) ---------- */
.report-printable {
  background: white;
  color: #1a1a1a;
  padding: 36px 40px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
[data-theme="dark"] .report-printable {
  color: #1a1a1a;
}
.report-printable .muted { color: #5a6b80; }

.report-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 16px;
  border-bottom: 2px solid #92007D;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.report-header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.report-header-logo {
  width: 56px; height: 56px;
  object-fit: contain;
}
.report-header-title {
  font-size: 22px;
  font-weight: 700;
  color: #92007D;
  letter-spacing: -0.01em;
}
.report-header-sub {
  font-size: 12.5px;
  color: #5a6b80;
}
.report-header-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12.5px;
  color: #1a1a1a;
  text-align: right;
  min-width: 240px;
}

.report-section { margin: 20px 0; }
.report-section-title {
  font-size: 16px;
  font-weight: 700;
  color: #1a1a1a;
  margin: 0 0 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e4e8ee;
}
.report-subsection-title {
  font-size: 13.5px;
  font-weight: 600;
  color: #1a1a1a;
  margin: 16px 0 6px;
}
.report-caption {
  font-size: 12px;
  color: #5a6b80;
  margin-bottom: 10px;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 4px;
}
.report-table thead { display: table-header-group; }
.report-table th, .report-table td {
  border-bottom: 1px solid #e4e8ee;
  padding: 6px 8px;
  text-align: left;
  vertical-align: top;
}
.report-table th {
  font-weight: 600;
  background: #f7f9fb;
  color: #1a1a1a;
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.04em;
}
.report-table tr { page-break-inside: avoid; break-inside: avoid; }

.report-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 8px 0 4px;
}
.report-stat {
  border: 1px solid #e4e8ee;
  border-radius: 6px;
  padding: 10px 12px;
  background: #f7f9fb;
}
.report-stat-label {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #5a6b80;
  margin-bottom: 2px;
}
.report-stat-value {
  font-size: 20px;
  font-weight: 700;
  color: #1a1a1a;
}

.report-sev {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.report-sev-crit { background: #fee2e2; color: #7f1d1d; }
.report-sev-warn { background: #fff1e3; color: #7a3010; }
.report-sev-offline { background: #f1f3f6; color: #374151; }

.report-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 28px 16px;
  background: #f7f9fb;
  border: 1px dashed #cdd5df;
  border-radius: 6px;
  color: #5a6b80;
  font-size: 13px;
}

.report-footer {
  margin-top: 28px;
  padding-top: 12px;
  border-top: 1px solid #e4e8ee;
  font-size: 10.5px;
  color: #5a6b80;
  text-align: center;
}

/* ============================================================
   @media print — oculta el chrome del dashboard y deja sólo el
   .report-printable a página completa con bg blanco.
   ============================================================ */
@media print {
  html, html[data-theme="dark"] {
    background: white !important;
    --bg: white;
    --surface: white;
    --surface-2: white;
    --surface-3: white;
    --surface-inset: white;
    --text: #1a1a1a;
    --text-muted: #5a6b80;
    --text-dim: #8a98ad;
    --border: #e4e8ee;
    --border-strong: #cdd5df;
    --border-soft: #eef1f5;
    --grad-canvas: white;
  }

  body { background: white !important; }

  .sidebar, .header, .sidebar-backdrop,
  .wizard-steps, .wizard-actions, .page-head,
  .no-print, .toast-stack, .modal-backdrop,
  .twk-panel, .tweaks-panel {
    display: none !important;
  }

  .app { display: block !important; }
  .main { display: block !important; }
  .content, .canvas, .wizard-preview-wrap {
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
    background: white !important;
  }

  .report-printable {
    border: none !important;
    border-radius: 0 !important;
    padding: 12mm 16mm !important;
    box-shadow: none !important;
    page-break-after: avoid;
  }

  .report-header, .report-stats-grid {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .report-section { page-break-inside: auto; }
  .report-section-title, .report-subsection-title {
    page-break-after: avoid;
  }

  svg { print-color-adjust: exact; -webkit-print-color-adjust: exact; }

  @page {
    size: A4;
    margin: 0;
  }
}

/* ============================================================
   Login / sesión / multi-cliente (super admin)
   ============================================================ */

/* El sidebar-user pasó de <div> a <button>: reset de estilos nativos. */
.sidebar-footer { position: relative; }
.sidebar-user {
  width: 100%;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.sidebar-user.open { background: var(--surface-2); }

/* Menú desplegable del usuario (se abre hacia arriba sobre el footer). */
.user-menu {
  position: absolute;
  bottom: calc(100% - 4px);
  left: 12px;
  right: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--elev-pop);
  padding: 6px;
  z-index: 60;
}
.user-menu-head { padding: 8px 10px 6px; border-bottom: 1px solid var(--border-soft); margin-bottom: 4px; }
.user-menu-name { font-size: 13px; font-weight: 600; color: var(--text); }
.user-menu-sub { font-size: 11px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; }
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  border-radius: var(--r-sm);
  cursor: pointer;
}
.user-menu-item:hover { background: var(--surface-2); }
.user-menu-item.danger { color: var(--crit); }
.user-menu-item.danger:hover { background: var(--crit-soft); }

/* Pantalla de login / cambio de contraseña obligatorio. */
.login-gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--grad-canvas);
  z-index: 100;
}
.login-loading { color: var(--text-muted); font-size: 14px; }
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--elev-modal);
  padding: 32px 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-brand { text-align: center; margin-bottom: 6px; }
.login-logo { width: 64px; height: 64px; object-fit: contain; margin: 0 auto 10px; display: block; }
.login-title { font: var(--t-h1); color: var(--text); }
.login-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.login-field { display: flex; flex-direction: column; gap: 6px; }
.login-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.login-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
.login-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.login-pw-wrap { position: relative; }
.login-pw-wrap .login-input { padding-right: 40px; }
.login-pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  display: inline-flex;
}
.login-pw-toggle:hover { color: var(--text); }
.login-error {
  background: var(--crit-soft);
  color: var(--crit-fg);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: 12.5px;
}
.login-submit { width: 100%; justify-content: center; padding: 11px; font-size: 14px; margin-top: 4px; }
.login-foot { text-align: center; font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.login-link {
  border: none; background: none; color: var(--text-muted);
  font: inherit; font-size: 12.5px; cursor: pointer; text-align: center; padding: 4px;
}
.login-link:hover { color: var(--text); text-decoration: underline; }

/* ============================================================
   Panel super admin (clientes)
   ============================================================ */
.admin-canvas { max-width: 980px; }
.admin-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.admin-list { display: flex; flex-direction: column; gap: 10px; }
.admin-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--elev-card);
  overflow: hidden;
}
.admin-card.open { border-color: var(--border-strong); }
.admin-card-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
}
.admin-card-logo {
  width: 38px; height: 38px;
  border-radius: var(--r-sm);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 16px;
  overflow: hidden;
}
.admin-card-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.admin-card-main { flex: 1; min-width: 0; }
.admin-card-name { font-size: 14px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.admin-card-meta { font-size: 12px; color: var(--text-dim); display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.admin-card-actions { display: flex; align-items: center; gap: 6px; }
.admin-badge {
  font-size: 10px; font-weight: 600; padding: 1px 7px; border-radius: var(--r-pill);
  background: var(--surface-3); color: var(--text-muted); text-transform: uppercase;
}
.admin-badge.off { background: var(--offline-soft); color: var(--offline-fg); }

.admin-panel { border-top: 1px solid var(--border-soft); padding: 16px 14px; background: var(--surface-inset); }
.admin-panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.admin-section-wide { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border-soft); }
.admin-section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 8px; }
.admin-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.admin-field > span { font-size: 12px; color: var(--text-muted); }
.admin-colors { display: flex; gap: 14px; margin-bottom: 10px; }
.admin-colors label { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted); }
.admin-colors input[type="color"] { width: 40px; height: 32px; border: 1px solid var(--border); border-radius: var(--r-sm); background: none; cursor: pointer; }
.admin-logo-row { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--text-muted); }
.admin-logo-prev { width: 32px; height: 32px; object-fit: contain; border: 1px solid var(--border); border-radius: var(--r-xs); background: #fff; }
.admin-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-tab-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border: 1px solid var(--border-strong); border-radius: var(--r-pill);
  font-size: 12.5px; color: var(--text-muted); cursor: pointer; user-select: none;
}
.admin-tab-chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--primary); }
.admin-tab-chip input { accent-color: var(--primary); }

.admin-panel-foot { display: flex; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border-soft); }

.admin-users-head { display: flex; align-items: center; justify-content: space-between; }
.admin-users { display: flex; flex-direction: column; gap: 8px; }
.admin-users-empty { font-size: 12.5px; color: var(--text-dim); padding: 8px 0; }
.admin-user {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border-soft); border-radius: var(--r-sm);
  background: var(--surface);
}
.admin-user.off { opacity: 0.6; }
.admin-user-main { flex: 1; min-width: 0; }
.admin-user-name { font-size: 13px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.admin-user-email { font-size: 11.5px; color: var(--text-dim); }
.admin-rol { font-size: 10px; font-weight: 600; padding: 1px 7px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-muted); text-transform: uppercase; }
.admin-rol.admin { background: var(--accent-soft); color: var(--primary); }
.admin-user-actions { display: flex; gap: 4px; }

@media (max-width: 720px) {
  .admin-panel-grid { grid-template-columns: 1fr; }
}

/* Banner de "ver app de un cliente" (super admin viendo una empresa) */
.impersonation-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--grad-primary);
  color: #fff;
  font-size: 13px;
  flex-wrap: wrap;
}
.impersonation-banner-text { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.impersonation-banner-text b { font-weight: 700; }
.impersonation-banner-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--r-pill);
  cursor: pointer;
  white-space: nowrap;
}
.impersonation-banner-btn:hover { background: rgba(255, 255, 255, 0.26); }
