/* =============================================================
   IntegrationHub Design System
   Inspired by Shopify Polaris / modern SaaS dashboards.
============================================================= */

:root {
    /* =========================================================
       CONTRATO DE TOKENS (sistema de temas).
       Los temas (html[data-theme=...]) overridean SOLO esto.
       Defaults = tema "flow" identico al look original.
    ========================================================= */
    --bg: #f6f6f7;
    --surface: #ffffff;
    --card: #ffffff;
    --border: #e1e3e5;
    --text: #1a1a1a;
    --dim: #616161;
    --accent: #2c6ecb;
    --on-accent: #ffffff;
    --accent-2: #6366f1;
    --ok: #008060;
    --warn: #b98900;
    --err: #d72c0d;
    --chip: #f1f2f3;
    --line: #d0d4da;
    --particle: #2c6ecb;
    --particle-op: .5;
    --blur: none;
    --glow: 0 0 0 transparent; /* componible: box-shadow: var(--shadow), var(--glow) */
    --radius: 12px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
    --grad: linear-gradient(135deg, #2c6ecb 0%, #6366f1 100%);
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* Paleta 4x2 (fuerte / suave) - flow */
    --c1: #2563eb;  --c1s: #93c5fd;
    --c2: #0891b2;  --c2s: #a5f3fc;
    --c3: #4f46e5;  --c3s: #c7d2fe;
    --c4: #0d9488;  --c4s: #99f6e4;

    /* Series de graficas comparativas (Reportes: Ventas vs Compras / vs Notas credito).
       Tonos deliberadamente separados en matiz para que cada serie se reconozca sola. */
    --chart-s1: #2c6ecb;
    --chart-s2: #d97706;

    /* ===== Tokens extendidos (consumidos por vistas; themeables) ===== */
    /* Escala de texto (slate) usada en vistas */
    --ink: #0f172a;
    --ink-2: #334155;
    --ink-3: #475569;
    --ink-4: #64748b;
    --ink-5: #94a3b8;
    /* Superficies y bordes sutiles de paneles/arbol */
    --surface-2: #f8fafc;
    --surface-3: #f1f5f9;
    --border-2: #e2e8f0;
    --border-3: #cbd5e1;
    /* Lecturas (azul) / escrituras (verde) del arbol de flujo */
    --read: #1d4ed8;
    --read-bg: #dbeafe;
    --read-bg-hover: #bfdbfe;
    --read-bg-faint: #eff6ff;
    --read-text: #1e40af;
    --read-border: #93c5fd;
    --read-chip: #eef2f7;
    --read-chip-hover: #dbe5f5;
    --read-border-soft: #b8c8e4;
    --write: #157a3d;
    --write-bg: #dcfce7;
    /* Ambar (default/warning soft) */
    --amber: #f59e0b;
    --amber-bg: #fef3c7;
    --amber-text: #92400e;
    --amber-border: #fbbf24;
    --amber-bg-hover: #fde68a;
    --amber-bg-faint: #fffbeb;
    --amber-text-deep: #78350f;
    /* Rojos soft (paneles de peligro en modales) */
    --err-deep: #b91c1c;
    --err-bg-soft: #fef2f2;
    --err-border-soft: #fecaca;
    --err-text-soft: #991b1b;
    /* Fuchsia (directivas por cuenta) */
    --fuchsia: #a21caf;
    --fuchsia-text: #86198f;
    --fuchsia-bg: #fdf4ff;
    --fuchsia-border: #f0abfc;
    /* Tooltip oscuro + header de modal */
    --tooltip-bg: #0f172a;
    --tooltip-text: #e2e8f0;
    --err-on-dark: #fca5a5;
    --clock-hand: #0a2c75;
    --modal-grad: linear-gradient(135deg, #1e3a8a 0%, #172554 100%);
    --modal-grad-text: #bfdbfe;
    --modal-grad-accent: #1e3a8a;
    /* Bloques de codigo */
    --code-bg: #2d2d2d;
    --code-text: #cccccc;
    --terminal-bg: #0a0a0a;
    --terminal-text: #d4d4d4;
    /* Estados de registros (badges s-N) */
    --status-0: #94a3b8;
    --status-2: #16a34a;
    --status-3: #dc2626;
    --status-4: #f59e0b;
    --status-5: #475569;
    --status-6: #7c3aed;
    --live: #16a34a;
    /* Icono del page-toolbar */
    --toolbar-icon-bg: linear-gradient(135deg, #eef4ff 0%, #dbe7ff 100%);
    --toolbar-icon-fg: #1d4ed8;
    --grad-glow: rgba(99, 102, 241, 0.3);

    /* =========================================================
       Tokens legacy --color-* (rebasados sobre el contrato).
       Los componentes existentes los consumen; cascadean al
       cambiar de tema sin tocar cada regla.
    ========================================================= */
    /* Colors - Surface */
    --color-bg: var(--bg);
    --color-surface: var(--surface);
    --color-surface-hover: #f9fafb;
    --color-surface-subdued: #fafbfb;
    --color-surface-pressed: var(--chip);

    /* Colors - Border */
    --color-border: var(--border);
    --color-border-subdued: #ebebeb;
    --color-border-strong: #c9cccf;

    /* Colors - Text */
    --color-text: var(--text);
    --color-text-strong: #0a0a0a;
    --color-text-secondary: var(--dim);
    --color-text-muted: #8c8c8c;
    --color-text-disabled: #b5b5b5;
    --color-text-inverse: #ffffff;

    /* Colors - Brand & Action */
    --color-primary: var(--accent);
    --color-primary-hover: #1f5aab;
    --color-primary-pressed: #103a73;
    --color-primary-subdued: #ebf1fb;

    /* Status */
    --color-success: var(--ok);
    --color-success-hover: #006a4f;
    --color-success-bg: #e3f1df;
    --color-success-text: #0c5132;
    --color-warning: var(--warn);
    --color-warning-bg: #fff3d6;
    --color-warning-text: #7a5b00;
    --color-danger: var(--err);
    --color-danger-hover: #b62308;
    --color-danger-bg: #fde2dd;
    --color-danger-text: #8e1100;
    --color-info: var(--accent);
    --color-info-bg: #ebf1fb;
    --color-info-text: #103a73;

    /* Sidebar */
    --color-sidebar-bg: #1a1a1a;
    --color-sidebar-surface: #2a2a2a;
    --color-sidebar-text: #d2d2d3;
    --color-sidebar-text-muted: #8c8c8c;
    --color-sidebar-active: #ffffff;
    --color-sidebar-active-bg: rgba(255, 255, 255, 0.08);
    --color-sidebar-hover-bg: rgba(255, 255, 255, 0.04);
    --color-sidebar-border: #2e2e2e;

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: var(--radius);
    --radius-xl: 16px;
    --radius-full: 999px;

    /* Shadows */
    --shadow-xs: 0 1px 0 rgba(0, 0, 0, 0.04);
    --shadow-sm: var(--shadow);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.04), 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.06), 0 4px 8px rgba(0, 0, 0, 0.04);
    --shadow-focus: 0 0 0 3px rgba(44, 110, 203, 0.18);

    /* Typography */
    --font-sans: var(--font);
    --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, Monaco, monospace;

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 72px;
    --topbar-height: 60px;
    --content-max-width: 1400px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
}

/* =============================================================
   TEMAS. Cada bloque overridea SOLO variables. data-theme lo pone
   _Layout (server) + script anti-FOUC + _ThemeSelector (runtime).
============================================================= */

/* --- Flow Intelligence (actual mejorado, referencia mockup) --- */
html[data-theme="flow"] {
    --bg: #f4f6fa; --border: #e2e8f0; --text: #0f1c2e; --dim: #5d6b81;
    --accent: #2563eb; --accent-2: #0891b2;
    --ok: #16a34a; --warn: #d97706; --err: #dc2626;
    --chip: #eef2f9; --line: #c6d2e2; --particle: #2563eb;
    --grad: linear-gradient(135deg, #2563eb 0%, #0891b2 100%);
    --c1: #2563eb; --c1s: #93c5fd; --c2: #0891b2; --c2s: #a5f3fc; --c3: #4f46e5; --c3s: #c7d2fe; --c4: #0d9488; --c4s: #99f6e4;
    --chart-s1: #2563eb; --chart-s2: #d97706;
    --grad-glow: rgba(8, 145, 178, 0.25);
    --color-primary-hover: #1d4ed8; --color-primary-pressed: #1e40af; --color-primary-subdued: #e8effc;
    --color-success-bg: #dcfce7; --color-success-text: #166534; --color-success-hover: #15803d;
    --color-warning-bg: #fef3c7; --color-warning-text: #92400e;
    --color-danger-bg: #fee2e2; --color-danger-text: #991b1b; --color-danger-hover: #b91c1c;
    --color-info-bg: #e8effc; --color-info-text: #1e40af;
    --shadow-focus: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

/* --- Automation Flow (n8n: naranja/grafito) --- */
html[data-theme="n8n"] {
    --bg: #131316; --surface: #1b1b1f; --card: #222227; --border: #36363e; --text: #f3f2ef; --dim: #9c9ba5;
    --accent: #ff6d2e; --on-accent: #1a0d05; --accent-2: #ffb86b;
    --ok: #2dd896; --warn: #ffc44d; --err: #ff5c5c;
    --chip: #2b2b32; --line: #4a4a54; --particle: #ff6d2e; --particle-op: 1;
    --radius: 10px; --shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    --grad: linear-gradient(135deg, #ff6d2e 0%, #ff9b52 100%);
    --c1: #ff6d2e; --c1s: #ffc29e; --c2: #ff5c5c; --c2s: #ffb3b3; --c3: #2dd896; --c3s: #9ef0d0; --c4: #9d7bff; --c4s: #d6c8ff;
    --chart-s1: #ff8a50; --chart-s2: #4dabf7;
    /* extendidos (vistas) */
    --ink: #f3f2ef; --ink-2: #d9d8e0; --ink-3: #b9b8c2; --ink-4: #9c9ba5; --ink-5: #6e6d78;
    --surface-2: #1f1f24; --surface-3: #26262c; --border-2: #36363e; --border-3: #44444e;
    --read: #ff8a50; --read-bg: #3a2317; --read-bg-hover: #4a2c1b; --read-bg-faint: #2a1c12; --read-text: #ffc29e; --read-border: #7a4326; --read-chip: #2f2218; --read-chip-hover: #3a2a1d; --read-border-soft: #5c3a22;
    --write: #2dd896; --write-bg: #143527;
    --amber: #ffc44d; --amber-bg: #3a2f12; --amber-text: #ffd98a; --amber-border: #8a6d2a; --amber-bg-hover: #4a3c17; --amber-bg-faint: #2a230f; --amber-text-deep: #ffe3a8;
    --tooltip-bg: #0a0a0c; --tooltip-text: #d9d8e0; --err-on-dark: #ff8a8a; --clock-hand: #ffb86b;
    --err-deep: #ff7a7a; --err-bg-soft: #3a1717; --err-border-soft: #5c2626; --err-text-soft: #ffb3b3;
    --fuchsia: #9d7bff; --fuchsia-text: #d6c8ff; --fuchsia-bg: #241b38; --fuchsia-border: #4a3a6e;
    --modal-grad: linear-gradient(135deg, #2b2b32 0%, #1b1b1f 100%); --modal-grad-text: #ffc29e; --modal-grad-accent: #ff6d2e;
    --code-bg: #0f0f12; --code-text: #d4d4d4; --terminal-bg: #0a0a0c; --terminal-text: #d4d4d4;
    --status-0: #6e6d78; --status-2: #2dd896; --status-3: #ff5c5c; --status-4: #ffc44d; --status-5: #9c9ba5; --status-6: #9d7bff; --live: #2dd896;
    --toolbar-icon-bg: linear-gradient(135deg, #3a2317 0%, #4a2c1b 100%); --toolbar-icon-fg: #ff8a50;
    --grad-glow: rgba(255, 109, 46, 0.35);
    /* legacy */
    --color-surface-hover: #222228; --color-surface-subdued: #19191d;
    --color-border-subdued: #2e2e36; --color-border-strong: #4a4a54;
    --color-text-strong: #ffffff; --color-text-muted: #98979f; --color-text-disabled: #5c5b66; --color-text-inverse: #131316;
    --color-primary-hover: #ff8a50; --color-primary-pressed: #e85d20; --color-primary-subdued: #3a2317;
    --color-success-hover: #4ae3a8; --color-success-bg: #143527; --color-success-text: #9ef0d0;
    --color-warning-bg: #3a2f12; --color-warning-text: #ffd98a;
    --color-danger-hover: #ff7a7a; --color-danger-bg: #3a1717; --color-danger-text: #ffb3b3;
    --color-info-bg: #3a2317; --color-info-text: #ffc29e;
    --shadow-xs: 0 1px 0 rgba(0, 0, 0, 0.3); --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5); --shadow-lg: 0 12px 28px rgba(0, 0, 0, 0.6); --shadow-focus: 0 0 0 3px rgba(255, 109, 46, 0.25);
    --color-sidebar-bg: #0f0f12; --color-sidebar-surface: #1b1b1f; --color-sidebar-border: #26262c;
}

/* --- Cyber Command (SOC verde neon mono) --- */
html[data-theme="cyber"] {
    --bg: #040907; --surface: #07120d; --card: #0a1812; --border: #16382a; --text: #d8ffe9; --dim: #639a7e;
    --accent: #22ff88; --on-accent: #02180c; --accent-2: #14d8c4;
    --ok: #22ff88; --warn: #ffd44a; --err: #ff4d6d;
    --chip: #0e231a; --line: #1d4b36; --particle: #22ff88; --particle-op: 1;
    --glow: 0 0 16px rgba(34, 255, 136, 0.14);
    --radius: 6px; --shadow: 0 0 0 1px rgba(34, 255, 136, 0.07);
    --grad: linear-gradient(135deg, #22ff88 0%, #14d8c4 100%);
    --font: ui-monospace, "Cascadia Mono", Consolas, monospace;
    --c1: #22ff88; --c1s: #0e7a44; --c2: #14d8c4; --c2s: #0a6b62; --c3: #ffd44a; --c3s: #8a6d14; --c4: #ff4d6d; --c4s: #7a1f31;
    --chart-s1: #22ff88; --chart-s2: #ff9f43;
    /* extendidos (vistas) */
    --ink: #d8ffe9; --ink-2: #b4e8cb; --ink-3: #8fc4a8; --ink-4: #639a7e; --ink-5: #3f6b54;
    --surface-2: #081510; --surface-3: #0c1f16; --border-2: #16382a; --border-3: #1d4b36;
    --read: #14d8c4; --read-bg: #0a2a26; --read-bg-hover: #0e3a34; --read-bg-faint: #081f1c; --read-text: #7df0e4; --read-border: #11574f; --read-chip: #0a2420; --read-chip-hover: #0e302a; --read-border-soft: #11574f;
    --write: #22ff88; --write-bg: #0a2a18;
    --amber: #ffd44a; --amber-bg: #2a2410; --amber-text: #ffe78a; --amber-border: #8a6d14; --amber-bg-hover: #3a3114; --amber-bg-faint: #1f1b0c; --amber-text-deep: #fff0b3;
    --tooltip-bg: #02120a; --tooltip-text: #b4e8cb; --err-on-dark: #ff8aa0; --clock-hand: #14d8c4;
    --err-deep: #ff7088; --err-bg-soft: #2a0d14; --err-border-soft: #4a1722; --err-text-soft: #ffb3c1;
    --fuchsia: #c79bff; --fuchsia-text: #dec2ff; --fuchsia-bg: #1c1228; --fuchsia-border: #3a2a55;
    --modal-grad: linear-gradient(135deg, #0a1812 0%, #040907 100%); --modal-grad-text: #7df0e4; --modal-grad-accent: #22ff88;
    --code-bg: #02120a; --code-text: #b4e8cb; --terminal-bg: #010a06; --terminal-text: #22ff88;
    --status-0: #3f6b54; --status-2: #22ff88; --status-3: #ff4d6d; --status-4: #ffd44a; --status-5: #639a7e; --status-6: #c79bff; --live: #22ff88;
    --toolbar-icon-bg: linear-gradient(135deg, #0a2a26 0%, #0e3a34 100%); --toolbar-icon-fg: #22ff88;
    --grad-glow: rgba(34, 255, 136, 0.3);
    /* legacy */
    --color-surface-hover: #0c1f16; --color-surface-subdued: #06100b;
    --color-border-subdued: #10291f; --color-border-strong: #1d4b36;
    --color-text-strong: #eafff3; --color-text-muted: #5d8f74; --color-text-disabled: #33523f; --color-text-inverse: #040907;
    --color-primary-hover: #5cffa8; --color-primary-pressed: #0fd96b; --color-primary-subdued: #0a2a18;
    --color-success-hover: #5cffa8; --color-success-bg: #0a2a18; --color-success-text: #9affc8;
    --color-warning-bg: #2a2410; --color-warning-text: #ffe78a;
    --color-danger-hover: #ff7088; --color-danger-bg: #2a0d14; --color-danger-text: #ffb3c1;
    --color-info-bg: #0a2a26; --color-info-text: #7df0e4;
    --shadow-xs: none; --shadow-md: 0 0 0 1px rgba(34, 255, 136, 0.1); --shadow-lg: 0 0 24px rgba(34, 255, 136, 0.12); --shadow-focus: 0 0 0 3px rgba(34, 255, 136, 0.25);
    --color-sidebar-bg: #03100a; --color-sidebar-surface: #07120d; --color-sidebar-text: #8fc4a8; --color-sidebar-text-muted: #639a7e; --color-sidebar-active: #d8ffe9; --color-sidebar-border: #0e231a;
    --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

/* --- Pangea (key "midnight" en el contrato y en la BD: se renombro solo la etiqueta visible).
   Navy premium glassmorphism: turquesa/azul/violeta. --- */
html[data-theme="midnight"] {
    --bg: #0a1024; --surface: #0e1733; --card: #131d3a; --border: #25325a; --text: #eaf2ff; --dim: #93a4c8;
    --accent: #22d3ee; --on-accent: #04121a; --accent-2: #a855f7;
    --ok: #2dd4bf; --warn: #fbbf24; --err: #f87171;
    --chip: #182542; --line: #2a3a63; --particle: #22d3ee; --particle-op: 1;
    /* Cristal ajustable (slider del perfil): --glass-a = alfa del relleno de las superficies. El anti-FOUC
       del _Layout lo sobreescribe inline desde la preferencia del usuario. --glass-a2 = variante mas translucida. */
    --glass-a: 0.05; --glass-a2: calc(var(--glass-a) * 0.64);
    --glow: 0 0 18px rgba(34, 211, 238, 0.12);
    --radius: 14px; --shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
    --grad: linear-gradient(135deg, #3b82f6 0%, #a855f7 100%);
    --c1: #22d3ee; --c1s: #0a5b66; --c2: #3b82f6; --c2s: #14365f; --c3: #a855f7; --c3s: #3a2362; --c4: #2dd4bf; --c4s: #0e4a40;
    --chart-s1: #22d3ee; --chart-s2: #fbbf24;
    /* extendidos (vistas) */
    --ink: #eaf2ff; --ink-2: #c7d4ec; --ink-3: #a7b6d6; --ink-4: #8093ba; --ink-5: #5b6b91;
    --surface-2: #111a33; --surface-3: #16213f; --border-2: #25325a; --border-3: #33436b;
    --read: #8fb8ff; --read-bg: #16233f; --read-bg-hover: #1d2f52; --read-bg-faint: #111b30; --read-text: #bcd2ff; --read-border: #2f4d86; --read-chip: #141f38; --read-chip-hover: #1b2a48; --read-border-soft: #2a4474;
    --write: #2dd4bf; --write-bg: #0e2f2a;
    --amber: #fbbf24; --amber-bg: #2e2611; --amber-text: #fcd97a; --amber-border: #8a6d2a; --amber-bg-hover: #3a3016; --amber-bg-faint: #221c0d; --amber-text-deep: #fde7a8;
    --tooltip-bg: #060a16; --tooltip-text: #c7d4ec; --err-on-dark: #fca5a5; --clock-hand: #22d3ee;
    --err-deep: #f87171; --err-bg-soft: #2e1316; --err-border-soft: #5a2330; --err-text-soft: #fda4af;
    --fuchsia: #c084fc; --fuchsia-text: #e2c7ff; --fuchsia-bg: #1e1733; --fuchsia-border: #3c2f63;
    --modal-grad: linear-gradient(135deg, #131d3a 0%, #0a1024 100%); --modal-grad-text: #bcd2ff; --modal-grad-accent: #3b82f6;
    --code-bg: #060c1c; --code-text: #c7d4ec; --terminal-bg: #050914; --terminal-text: #7df0e4;
    --status-0: #5b6b91; --status-2: #2dd4bf; --status-3: #f87171; --status-4: #fbbf24; --status-5: #8093ba; --status-6: #a855f7; --live: #2dd4bf;
    --toolbar-icon-bg: linear-gradient(135deg, #16233f 0%, #1d2f52 100%); --toolbar-icon-fg: #22d3ee;
    --grad-glow: rgba(168, 85, 247, 0.32);
    /* legacy */
    --color-surface-hover: #16213f; --color-surface-subdued: #0c1428;
    --color-border-subdued: #1d2945; --color-border-strong: #33436b;
    --color-text-strong: #ffffff; --color-text-muted: #8093ba; --color-text-disabled: #51608a; --color-text-inverse: #0a1024;
    --color-primary-hover: #4fdcef; --color-primary-pressed: #18b6d4; --color-primary-subdued: #0e2a32;
    --color-success-hover: #4fe0cd; --color-success-bg: #0e2f2a; --color-success-text: #9af0e4;
    --color-warning-bg: #2e2611; --color-warning-text: #fcd97a;
    --color-danger-hover: #fb8a8a; --color-danger-bg: #2e1316; --color-danger-text: #fda4af;
    --color-info-bg: #16233f; --color-info-text: #bcd2ff;
    --shadow-xs: 0 1px 0 rgba(0, 0, 0, 0.3); --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5); --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.6); --shadow-focus: 0 0 0 3px rgba(34, 211, 238, 0.25);
    --color-sidebar-bg: #070d1d; --color-sidebar-surface: #0e1733; --color-sidebar-text: #a7b6d6; --color-sidebar-text-muted: #8093ba; --color-sidebar-active: #eaf2ff; --color-sidebar-border: #16213f;
}

/* Pangea (midnight): efecto CRISTAL (fondo navy con glows + superficies translucidas con blur) */
html[data-theme="midnight"] body {
    /* Base derivada de los tokens (la variante steel/violet/dark cambia --surface/--bg
       -> el fondo del glass cambia con el color); glows cyan/violeta = identidad fija. */
    background:
        radial-gradient(72% 60% at 86% -5%, rgba(168, 85, 247, 0.20), transparent 60%),
        radial-gradient(60% 60% at 0% 105%, rgba(34, 211, 238, 0.16), transparent 60%),
        linear-gradient(160deg, var(--surface) 0%, var(--bg) 62%, color-mix(in srgb, var(--bg) 78%, #000) 100%);
    background-attachment: fixed;
}
html[data-theme="midnight"] .app-sidebar,
html[data-theme="midnight"] .app-topbar {
    background: rgba(12, 18, 40, 0.55);
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
}
html[data-theme="midnight"] .app-sidebar { border-right: 1px solid rgba(255, 255, 255, 0.08); }
html[data-theme="midnight"] .app-topbar { border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
html[data-theme="midnight"] .card,
html[data-theme="midnight"] .metric-card,
html[data-theme="midnight"] .connection-card,
html[data-theme="midnight"] .data-table-wrap,
html[data-theme="midnight"] .page-toolbar,
html[data-theme="midnight"] .modal-content {
    background: rgba(255, 255, 255, var(--glass-a, 0.05));
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.10);
}
html[data-theme="midnight"] .card-header,
html[data-theme="midnight"] .card-section { border-color: rgba(255, 255, 255, 0.08); background: transparent; }
html[data-theme="midnight"] .card-footer { border-color: rgba(255, 255, 255, 0.08); background: rgba(255, 255, 255, 0.02); }
html[data-theme="midnight"] .card:hover,
html[data-theme="midnight"] .metric-card:hover {
    box-shadow: 0 22px 56px rgba(0, 0, 0, 0.5), 0 0 28px rgba(34, 211, 238, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.14);
    border-color: rgba(34, 211, 238, 0.28);
}
html[data-theme="midnight"] .form-control,
html[data-theme="midnight"] .form-select {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.12);
}
/* Midnight + editor de nodos (layout canvas): lienzo y nodos en cristal */
html[data-theme="midnight"] .canvas-flow {
    background-color: rgba(255, 255, 255, 0.015);
    background-image: radial-gradient(circle, rgba(34, 211, 238, 0.14) 1px, transparent 1.6px);
    border-color: rgba(255, 255, 255, 0.12);
}
html[data-theme="midnight"] .cf-node {
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(12px) saturate(140%);
    -webkit-backdrop-filter: blur(12px) saturate(140%);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.10);
}
/* Pangea (midnight) en dashboard y demas paginas: lienzo punteado detras del contenido
   (como el canvas) + tarjetas mas translucidas -> se ve "a traves" del cristal. */
html[data-theme="midnight"] .app-main {
    background-image: radial-gradient(circle, rgba(34, 211, 238, 0.06) 1px, transparent 1.6px);
    background-size: 22px 22px;
    background-attachment: fixed;
}
html[data-theme="midnight"] .card,
html[data-theme="midnight"] .metric-card {
    background: rgba(255, 255, 255, var(--glass-a2, 0.03));
    backdrop-filter: blur(22px) saturate(155%);
    -webkit-backdrop-filter: blur(22px) saturate(155%);
}
html[data-theme="midnight"] .metric-card { background: rgba(255, 255, 255, var(--glass-a2, 0.038)); }
/* Modal de Equivalencias contables en cristal (igual que el modal de prueba): su .eq-modal-header
   (--modal-grad navy opaco) y .eq-modal-body (--color-surface-subdued opaco) tapaban el glass del
   .modal-content -> se ponen translucidos para que se vea el cristal+blur detras. Tambien se restituye
   el borde/sombra de cristal del .modal-content (el inline border:none;box-shadow del partial los pisaba). */
html[data-theme="midnight"] .eq-modal-header {
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
html[data-theme="midnight"] .eq-modal-body { background: transparent; }
html[data-theme="midnight"] .modal-content:has(.eq-modal-header) {
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.10) !important;
}

/* === Overlay de carga entre vistas (loader configurable por usuario en el perfil) === */
.ih-loader { position: fixed; inset: 0; z-index: 4000; display: none; align-items: center; justify-content: center; --ih-bg: 0.55; background: rgba(8, 10, 18, var(--ih-bg)); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.ih-loader.is-on { display: flex; }
.ih-loader-inner { display: flex; align-items: center; justify-content: center; filter: drop-shadow(0 10px 32px rgba(0, 0, 0, .35)); }
.ih-loader canvas { width: 200px; height: 180px; }
.ih-loader img { max-width: 220px; max-height: 220px; object-fit: contain; }

/* === Perfil: selector de animacion de carga === */
.loader-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.loader-opt { position: relative; background: var(--surface-3, rgba(0, 0, 0, .12)); border: 1px solid var(--border-2, var(--color-border)); border-radius: 12px; padding: 8px 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; color: var(--accent); transition: border-color .15s, transform .1s; }
.loader-opt:hover { transform: translateY(-1px); }
.loader-opt.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.loader-opt canvas { width: 84px; height: 64px; }
.loader-opt-name { font-size: 10.5px; color: var(--ink-3, var(--color-text-muted)); text-align: center; }
.loader-opt.loader-none { justify-content: center; min-height: 92px; color: var(--ink-3, var(--color-text-muted)); font-size: 12px; }
.loader-opt.loader-custom .loader-opt-media { width: 84px; height: 64px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.loader-opt.loader-custom img { max-width: 84px; max-height: 64px; object-fit: contain; }
.loader-slider-row { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; }
.loader-slider-row label { font-size: 12px; font-weight: 600; display: flex; justify-content: space-between; color: var(--ink-2, var(--color-text)); }
.loader-slider-row input[type=range] { width: 100%; accent-color: var(--accent); cursor: pointer; }

/* --- Flow Canvas (lienzo claro punteado, editor de nodos; data-layout=canvas) --- */
html[data-theme="canvas"] {
    --bg: #f6f7fb; --border: #e3e6f2; --text: #171a3d; --dim: #6b7090;
    --accent: #6366f1; --accent-2: #0ea5a4;
    --ok: #0ea5a4; --warn: #d97706; --err: #dc2626;
    --chip: #eef0fa; --line: #c9cfe8; --particle: #6366f1; --particle-op: .8;
    --grad: linear-gradient(135deg, #6366f1 0%, #2563eb 100%);
    --c1: #6366f1; --c1s: #c7d2fe; --c2: #ff6d2e; --c2s: #ffd6bf; --c3: #0ea5a4; --c3s: #99f6e4; --c4: #2563eb; --c4s: #bfdbfe;
    --chart-s1: #6366f1; --chart-s2: #d97706;
    --read: #6366f1; --read-bg: #e0e7ff; --read-bg-hover: #c7d2fe; --read-bg-faint: #eef2ff; --read-text: #3730a3; --read-border: #a5b4fc; --read-chip: #eef0fa; --read-chip-hover: #e0e7ff; --read-border-soft: #c7d2fe;
    --write: #0ea5a4; --write-bg: #ccfbf1;
    --color-primary-hover: #4f46e5; --color-primary-pressed: #4338ca; --color-primary-subdued: #e0e7ff;
    --color-info-bg: #e0e7ff; --color-info-text: #3730a3;
    --toolbar-icon-bg: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%); --toolbar-icon-fg: #4f46e5;
    --grad-glow: rgba(99, 102, 241, 0.3);
    --shadow-focus: 0 0 0 3px rgba(99, 102, 241, 0.2);
}
html[data-theme="canvas"] body {
    background-image: radial-gradient(circle, rgba(99, 102, 241, 0.16) 1px, transparent 1.6px);
    background-size: 22px 22px;
}

/* Editor de nodos (canvas-flow.js reemplaza el arbol cuando data-layout=canvas).
   El arbol basico se oculta desde el primer paint (data-layout viene del server) para que no se vea
   el "flash" del flujo normal antes del canvas; cf-keep lo re-muestra si el canvas no puede montarse. */
html[data-layout="canvas"] .tree-graph:not(.cf-keep) { display: none; }
.cf-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.cf-toolbar.cf-loading { opacity: 0; }
/* Fallback sin posiciones embebidas: nodos y cables invisibles hasta aplicar lo guardado (sin texto de carga) */
.canvas-flow > * { transition: opacity 0.18s ease; }
.canvas-flow.cf-loading > * { opacity: 0; }
.cf-hint { font-size: 11.5px; color: var(--dim); }
.canvas-flow {
    position: relative; overflow: hidden;
    border: 1px dashed var(--line); border-radius: var(--radius);
    background-image: radial-gradient(circle, rgba(99, 102, 241, 0.14) 1px, transparent 1.6px);
    background-size: 18px 18px;
    margin-bottom: 12px;
}
/* Solo el SVG de cables (hijo DIRECTO del canvas) va a pantalla completa; NO los svg de iconos dentro de los nodos. */
.canvas-flow > svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.cf-path { fill: none; stroke: var(--line); stroke-width: 2; transition: stroke 0.3s; }
.canvas-flow.cf-active .cf-path { stroke: var(--accent); stroke-dasharray: 8 6; animation: cf-dash 0.6s linear infinite; }
@keyframes cf-dash { to { stroke-dashoffset: -14; } }
.cf-node {
    position: absolute; min-width: 170px; max-width: 240px;
    background: var(--card); border: 1px solid var(--border);
    border-left: 4px solid var(--c1); border-radius: 10px;
    box-shadow: var(--shadow); padding: 8px 10px;
    cursor: grab; user-select: none; touch-action: none;
    font-size: 12.5px;
}
.cf-node.is-dragging { cursor: grabbing; box-shadow: var(--shadow-lg); z-index: 5; }
.cf-node.src { border-left-color: var(--c2); }
.cf-node.write { border-left-color: var(--c3); }
.cf-node.is-running { border-color: var(--accent); box-shadow: 0 0 0 2px var(--color-primary-subdued); }
.cf-node-head { display: flex; gap: 6px; align-items: center; font-weight: 600; min-width: 0; }
.cf-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-seq {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 24px; height: 19px; padding: 0 5px; border-radius: 4px;
    font-family: var(--font-mono); font-size: 10.5px; font-weight: 600;
    background: var(--chip); color: var(--dim); flex-shrink: 0;
}
.cf-node.read .cf-seq { background: var(--read-bg); color: var(--read-text); }
.cf-node.write .cf-seq { background: var(--write-bg); color: var(--accent-2); }
.cf-node .op { color: var(--dim); font-family: var(--font-mono); font-size: 10.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-node-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.cf-node-actions .btn { min-height: 24px; padding: 2px 8px; font-size: 11px; }
.cf-file rect { stroke: rgba(0, 0, 0, 0.15); stroke-width: 0.5; }

/* Badge de equivalencias contables en el nodo write del canvas */
.cf-eq-badge {
    display: inline-flex; align-items: center; gap: 4px; margin-top: 7px;
    padding: 2px 8px; border-radius: 999px; font-size: 10.5px; font-weight: 600;
    background: var(--read-bg); color: var(--read-text);
    border: 1px solid color-mix(in srgb, var(--read-text) 28%, transparent);
    cursor: default; user-select: none; max-width: 100%;
}
.cf-eq-badge svg { flex-shrink: 0; opacity: 0.85; width: 11px; height: 11px; position: static; inset: auto; }
.cf-eq-badge.is-editable { cursor: pointer; }
.cf-eq-badge.is-editable:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Popup flotante con el resumen de equivalencias (hover) */
.cf-eq-pop {
    position: fixed; z-index: 1080; min-width: 220px; max-width: 300px;
    background: var(--card); color: var(--text);
    border: 1px solid var(--border); border-radius: 10px;
    box-shadow: var(--shadow-lg); padding: 10px 12px; font-size: 12px;
}
.cf-eq-pop-title { font-weight: 700; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cf-eq-pop-loading { color: var(--dim); font-size: 11.5px; }
.cf-eq-row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-top: 1px solid var(--line); }
.cf-eq-row:first-of-type { border-top: 0; }
.cf-eq-row .cf-eq-lvl { color: var(--text); }
.cf-eq-row.off { opacity: 0.5; }
.cf-eq-row .cf-eq-val { font-family: var(--font-mono); font-size: 11px; color: var(--dim); }
.cf-eq-row.on .cf-eq-val { color: var(--read-text); }
.cf-eq-pop-foot { margin-top: 7px; padding-top: 6px; border-top: 1px solid var(--line); font-size: 10.5px; color: var(--dim); }

/* --- Terminal Ops (TUI fosforo; data-layout=terminal activa chrome) --- */
html[data-theme="terminal"] {
    --bg: #050805; --surface: #0a0f0a; --card: #0a0f0a; --border: #1d3a22; --text: #b6f2bd; --dim: #577a5b;
    --accent: #b6f2bd; --on-accent: #06140a; --accent-2: #ffc94d;
    --ok: #b6f2bd; --warn: #ffc94d; --err: #ff6b6b;
    --chip: #112911; --line: #2a4a30; --particle: #b6f2bd; --particle-op: 1;
    --glow: 0 0 0 transparent;
    --radius: 0px; --shadow: none;
    --grad: linear-gradient(135deg, #b6f2bd 0%, #5ad7d0 100%);
    --font: ui-monospace, "Cascadia Mono", Consolas, monospace;
    --c1: #b6f2bd; --c1s: #577a5b; --c2: #ffc94d; --c2s: #8a6d2a; --c3: #5ad7d0; --c3s: #2a6b68; --c4: #ff6b6b; --c4s: #7a2e2e;
    --chart-s1: #b6f2bd; --chart-s2: #ffc94d;
    /* extendidos (vistas) */
    --ink: #d2ffd8; --ink-2: #b6f2bd; --ink-3: #8fc79a; --ink-4: #577a5b; --ink-5: #3d5a42;
    --surface-2: #0c130c; --surface-3: #101a11; --border-2: #1d3a22; --border-3: #2a4a30;
    --read: #5ad7d0; --read-bg: #0c2624; --read-bg-hover: #103230; --read-bg-faint: #091c1b; --read-text: #9ae8e3; --read-border: #2a6b68; --read-chip: #0c2220; --read-chip-hover: #102e2b; --read-border-soft: #2a6b68;
    --write: #b6f2bd; --write-bg: #11290f;
    --amber: #ffc94d; --amber-bg: #2a2310; --amber-text: #ffe08a; --amber-border: #8a6d2a; --amber-bg-hover: #3a3014; --amber-bg-faint: #1f1a0c; --amber-text-deep: #ffeab3;
    --tooltip-bg: #020502; --tooltip-text: #b6f2bd; --err-on-dark: #ff9b9b; --clock-hand: #ffc94d;
    --err-deep: #ff8585; --err-bg-soft: #2a0f0f; --err-border-soft: #4a1d1d; --err-text-soft: #ffb3b3;
    --fuchsia: #c79bff; --fuchsia-text: #dec2ff; --fuchsia-bg: #1c1228; --fuchsia-border: #3a2a55;
    --modal-grad: linear-gradient(135deg, #101a11 0%, #050805 100%); --modal-grad-text: #9ae8e3; --modal-grad-accent: #b6f2bd;
    --code-bg: #020502; --code-text: #b6f2bd; --terminal-bg: #020502; --terminal-text: #b6f2bd;
    --status-0: #3d5a42; --status-2: #b6f2bd; --status-3: #ff6b6b; --status-4: #ffc94d; --status-5: #577a5b; --status-6: #c79bff; --live: #b6f2bd;
    --toolbar-icon-bg: linear-gradient(135deg, #11290f 0%, #0c2624 100%); --toolbar-icon-fg: #b6f2bd;
    --grad-glow: rgba(182, 242, 189, 0.25);
    /* legacy */
    --color-surface-hover: #101a11; --color-surface-subdued: #080d08;
    --color-border-subdued: #14291a; --color-border-strong: #2a4a30;
    --color-text-strong: #e8ffe9; --color-text-muted: #577a5b; --color-text-disabled: #314535; --color-text-inverse: #050805;
    --color-primary-hover: #d2ffd8; --color-primary-pressed: #8fc79a; --color-primary-subdued: #11290f;
    --color-success-hover: #d2ffd8; --color-success-bg: #11290f; --color-success-text: #d2ffd8;
    --color-warning-bg: #2a2310; --color-warning-text: #ffe08a;
    --color-danger-hover: #ff8585; --color-danger-bg: #2a0f0f; --color-danger-text: #ffb3b3;
    --color-info-bg: #0c2624; --color-info-text: #9ae8e3;
    --shadow-xs: none; --shadow-md: none; --shadow-lg: none; --shadow-focus: 0 0 0 2px rgba(182, 242, 189, 0.35);
    --color-sidebar-bg: #030503; --color-sidebar-surface: #0a0f0a; --color-sidebar-text: #8fc79a; --color-sidebar-text-muted: #577a5b; --color-sidebar-active: #d2ffd8; --color-sidebar-border: #14291a;
    --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

/* TUI estructural: sin radios ni sombras, densidad maxima, cajas con borde */
html[data-layout="terminal"] body { font-size: 13px; }
html[data-layout="terminal"] .card,
html[data-layout="terminal"] .metric-card,
html[data-layout="terminal"] .data-table-wrap,
html[data-layout="terminal"] .connection-card,
html[data-layout="terminal"] .btn,
html[data-layout="terminal"] .form-control,
html[data-layout="terminal"] .form-select,
html[data-layout="terminal"] .badge,
html[data-layout="terminal"] .status-pill,
html[data-layout="terminal"] .modal-content { border-radius: 0 !important; box-shadow: none !important; }
html[data-layout="terminal"] .app-main { padding: 12px 16px 96px 16px; }
html[data-layout="terminal"] .card-body, html[data-layout="terminal"] .metric-card { padding: 10px 12px; }
html[data-layout="terminal"] .card-header { padding: 8px 12px; }
html[data-layout="terminal"] table.app-table thead th { padding: 6px 10px; }
html[data-layout="terminal"] table.app-table tbody td { padding: 6px 10px; }
/* Estados como [TAGS]: corchetes en badges/pills, sin dot */
html[data-layout="terminal"] .badge::before { content: "["; width: auto; height: auto; background: none; border-radius: 0; opacity: 1; }
html[data-layout="terminal"] .badge::after { content: "]"; }
html[data-layout="terminal"] .status-pill { text-transform: uppercase; }
html[data-layout="terminal"] .status-pill .dot { display: none; }
html[data-layout="terminal"] .status-pill::before { content: "["; }
html[data-layout="terminal"] .status-pill::after { content: "]"; }
/* Progreso con bloques (htop) */
html[data-layout="terminal"] .run-progress-bar { height: 10px; border: 1px solid var(--border-3); background: var(--surface-2); border-radius: 0; }
html[data-layout="terminal"] .run-progress-fill {
    background: repeating-linear-gradient(90deg, var(--accent) 0 6px, transparent 6px 8px);
    border-radius: 0;
}

/* Chrome TUI: prompt ih> + reloj + footer de teclas (partial _TerminalChrome, oculto fuera del tema) */
.term-chrome { display: none; }
html[data-layout="terminal"] .term-chrome {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 300;
    background: var(--terminal-bg); border-top: 1px solid var(--border-3);
    font-family: var(--font-mono); color: var(--text);
}
.term-prompt-row { display: flex; align-items: center; gap: 8px; padding: 8px 14px 4px 14px; }
.term-ps1 { color: var(--accent-2); font-weight: 700; }
.term-input {
    flex: 1; background: transparent; border: none; outline: none;
    color: var(--text); font-family: inherit; font-size: 13px;
    caret-color: var(--accent);
}
.term-cursor { width: 8px; height: 15px; background: var(--accent); animation: term-blink 1.1s steps(1) infinite; }
.term-input:focus ~ .term-cursor { display: none; }
@keyframes term-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
.term-clock { color: var(--dim); font-size: 12px; white-space: nowrap; }
.term-fkeys { display: flex; gap: 14px; flex-wrap: wrap; padding: 4px 14px 8px 14px; font-size: 11.5px; color: var(--dim); }
.term-fkeys b { color: var(--terminal-bg); background: var(--accent-2); padding: 0 5px; font-weight: 700; margin-right: 4px; }
.term-help {
    padding: 8px 14px; border-top: 1px dashed var(--border-3);
    font-size: 12px; color: var(--ink-3); white-space: pre; overflow-x: auto;
}
.term-msg { padding: 2px 14px 6px 14px; font-size: 12px; color: var(--err); }

/* --- Arcade Synthwave (CRT retro; data-layout=arcade activa overlays) --- */
html[data-theme="arcade"] {
    --bg: #0a0412; --surface: #14081f; --card: #190a2e; --border: #3a2155; --text: #f3e8ff; --dim: #b89ad6;
    --accent: #ff3cde; --on-accent: #1f0419; --accent-2: #29e6ff;
    --ok: #ffd84d; --warn: #ffd84d; --err: #ff3cde;
    --chip: #221040; --line: #4a2a78; --particle: #29e6ff; --particle-op: 1;
    --glow: 0 0 18px rgba(255, 60, 222, 0.16);
    --radius: 4px; --shadow: 0 0 0 1px rgba(255, 60, 222, 0.10);
    --grad: linear-gradient(135deg, #ff3cde 0%, #29e6ff 100%);
    --font: ui-monospace, "Cascadia Mono", Consolas, monospace;
    --c1: #ff3cde; --c1s: #8a1f78; --c2: #29e6ff; --c2s: #136f7d; --c3: #ffd84d; --c3s: #8a6d14; --c4: #c79bff; --c4s: #5d3a8a;
    --chart-s1: #ff3cde; --chart-s2: #29e6ff;
    /* extendidos (vistas) */
    --ink: #f3e8ff; --ink-2: #ddc8f5; --ink-3: #c8addf; --ink-4: #b89ad6; --ink-5: #7d62a0;
    --surface-2: #160a24; --surface-3: #1d0e33; --border-2: #3a2155; --border-3: #4a2a78;
    --read: #29e6ff; --read-bg: #0e2a38; --read-bg-hover: #123a4a; --read-bg-faint: #0a1f2a; --read-text: #8ff2ff; --read-border: #136f7d; --read-chip: #102433; --read-chip-hover: #143042; --read-border-soft: #136f7d;
    --write: #ffd84d; --write-bg: #2a2410;
    --amber: #ffd84d; --amber-bg: #2a2410; --amber-text: #ffe78a; --amber-border: #8a6d14; --amber-bg-hover: #3a3114; --amber-bg-faint: #1f1b0c; --amber-text-deep: #fff0b3;
    --tooltip-bg: #0a0412; --tooltip-text: #ddc8f5; --err-on-dark: #ff9bef; --clock-hand: #29e6ff;
    --err-deep: #ff6ae8; --err-bg-soft: #2e0a26; --err-border-soft: #57174a; --err-text-soft: #ff9bef;
    --fuchsia: #c79bff; --fuchsia-text: #dec2ff; --fuchsia-bg: #241b38; --fuchsia-border: #4a3a6e;
    --modal-grad: linear-gradient(135deg, #221040 0%, #14081f 100%); --modal-grad-text: #8ff2ff; --modal-grad-accent: #ff3cde;
    --code-bg: #0a0412; --code-text: #ddc8f5; --terminal-bg: #060210; --terminal-text: #29e6ff;
    --status-0: #7d62a0; --status-2: #ffd84d; --status-3: #ff3cde; --status-4: #ffd84d; --status-5: #b89ad6; --status-6: #c79bff; --live: #29e6ff;
    --toolbar-icon-bg: linear-gradient(135deg, #2e0a26 0%, #0e2a38 100%); --toolbar-icon-fg: #ff3cde;
    --grad-glow: rgba(255, 60, 222, 0.35);
    /* legacy */
    --color-surface-hover: #1d0e33; --color-surface-subdued: #120822;
    --color-border-subdued: #2e1a45; --color-border-strong: #4a2a78;
    --color-text-strong: #ffffff; --color-text-muted: #9d82bf; --color-text-disabled: #5d4a78; --color-text-inverse: #0a0412;
    --color-primary-hover: #ff6ae8; --color-primary-pressed: #d922b8; --color-primary-subdued: #2e0a26;
    --color-success-hover: #ffe066; --color-success-bg: #2a2410; --color-success-text: #ffe78a;
    --color-warning-bg: #2a2410; --color-warning-text: #ffe78a;
    --color-danger-hover: #ff6ae8; --color-danger-bg: #2e0a26; --color-danger-text: #ff9bef;
    --color-info-bg: #0e2a38; --color-info-text: #8ff2ff;
    --shadow-xs: none; --shadow-md: 0 0 0 1px rgba(41, 230, 255, 0.12); --shadow-lg: 0 0 24px rgba(255, 60, 222, 0.15); --shadow-focus: 0 0 0 3px rgba(41, 230, 255, 0.3);
    --color-sidebar-bg: #0d0518; --color-sidebar-surface: #14081f; --color-sidebar-text: #c8addf; --color-sidebar-text-muted: #7d62a0; --color-sidebar-active: #f3e8ff; --color-sidebar-border: #221040;
    --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

/* Overlays estructurales arcade (CRT + rejilla + glitch + HUD) */
html[data-layout="arcade"] body::after {
    content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 9999;
    background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px);
    mix-blend-mode: multiply;
}
html[data-layout="arcade"] body::before {
    content: ""; position: fixed; left: -40%; right: -40%; bottom: -8%; height: 42%;
    pointer-events: none; z-index: -1;
    background:
        linear-gradient(transparent 0%, rgba(255, 60, 222, 0.10) 100%),
        repeating-linear-gradient(90deg, rgba(41, 230, 255, 0.22) 0 1px, transparent 1px 56px),
        repeating-linear-gradient(0deg, rgba(255, 60, 222, 0.22) 0 1px, transparent 1px 38px);
    transform: perspective(380px) rotateX(62deg);
    transform-origin: bottom;
}
html[data-layout="arcade"] .page-title,
html[data-layout="arcade"] h1,
html[data-layout="arcade"] .sidebar-brand-text,
html[data-layout="arcade"] .metric-card-label {
    font-family: "Press Start 2P", ui-monospace, monospace;
    letter-spacing: 0.02em;
}
html[data-layout="arcade"] .page-title { font-size: 15px; line-height: 1.6; animation: arcade-glitch 3.5s steps(1) infinite; }
html[data-layout="arcade"] h1 { font-size: 16px; line-height: 1.6; }
html[data-layout="arcade"] .sidebar-brand-text { font-size: 10px; }
html[data-layout="arcade"] .metric-card-label { font-size: 9px; line-height: 1.7; }
html[data-layout="arcade"] .metric-card-value { color: var(--c3); text-shadow: 0 0 10px rgba(255, 216, 77, 0.4); }
@keyframes arcade-glitch {
    0%, 91%, 100% { text-shadow: 2px 0 var(--c2), -2px 0 var(--accent); transform: none; }
    92% { text-shadow: -3px 0 var(--accent), 3px 0 var(--c2); transform: translateX(2px); }
    95% { text-shadow: 3px 1px var(--c2), -3px -1px var(--accent); transform: translateX(-2px); }
}
@keyframes arcade-shake {
    0%, 100% { transform: none; }
    20% { transform: translate(-3px, 2px); }
    40% { transform: translate(3px, -2px); }
    60% { transform: translate(-2px, -2px); }
    80% { transform: translate(2px, 2px); }
}
body.arcade-shake .app-shell { animation: arcade-shake 0.35s linear; }
/* Accesibilidad: CRT/glitch fuera con reduced motion o animaciones off */
@media (prefers-reduced-motion: reduce) {
    html[data-layout="arcade"] body::before, html[data-layout="arcade"] body::after { display: none; }
}
html[data-motion="off"][data-layout="arcade"] body::before, html[data-motion="off"][data-layout="arcade"] body::after { display: none; }


/* --- Toteat (marca del cliente). Jerarquia de la identidad, tal cual toteat.com: manda el
   BLANCO (fondo casi blanco #f7f7f7, tarjetas y MENU blancos), el NEGRO #1b1b1b es la estructura
   de los titulos y el texto, y el CORAL #ff4b33 firma el menu (enlaces e iconos) y los acentos.
   Los neutros calidos de la marca (crema #f7f3ee, arena #e6d9ca) visten los estados
   suaves. Las series de graficas (--c1..--c4) suman un ocre, un verde agua y un rosa vino:
   cuatro tonos de la familia calida no se distinguirian en un apilado, y todos van en version
   oscura porque el fondo es claro. --- */
html[data-theme="toteat"] {
    --bg: #f7f7f7; --surface: #ffffff; --card: #ffffff; --border: #e4e4e4; --text: #1b1b1b; --dim: #464646;
    --accent: #ff4b33; --on-accent: #ffffff; --accent-2: #1b1b1b;
    --ok: #1f7a52; --warn: #a56a10; --err: #c62a45;
    --chip: #f2f2f2; --line: #d8d8d8; --particle: #ff4b33; --particle-op: .55;
    --radius: 12px; --shadow: 0 1px 2px rgba(27, 27, 27, 0.05), 0 2px 8px rgba(27, 27, 27, 0.05);
    --grad: linear-gradient(135deg, #ff4b33 0%, #ff8a5c 100%);
    --c1: #ff4b33; --c1s: #ffc2b1; --c2: #b07514; --c2s: #ffe0a8; --c3: #22867a; --c3s: #b6e8e1; --c4: #c2566c; --c4s: #ffd0d9;
    --chart-s1: #e03a23; --chart-s2: #22867a;
    /* extendidos (vistas): escala de gris de la marca en vez del slate azulado del default */
    --ink: #1b1b1b; --ink-2: #333333; --ink-3: #464646; --ink-4: #767676; --ink-5: #a1a1a1;
    --surface-2: #fbfaf9; --surface-3: #f2f2f2; --border-2: #e4e4e4; --border-3: #cfcfcf;
    --read: #c2451f; --read-bg: #ffe8e2; --read-bg-hover: #ffd6cb; --read-bg-faint: #fff5f2; --read-text: #8f2f14; --read-border: #ffb5a3; --read-chip: #f7f0ed; --read-chip-hover: #ffe1d8; --read-border-soft: #f0c4b6;
    --write: #1f7a52; --write-bg: #dcf3e8;
    --amber: #a56a10; --amber-bg: #fdf1d8; --amber-text: #7a4f0c; --amber-border: #e6c078; --amber-bg-hover: #fae3b8; --amber-bg-faint: #fffaf0; --amber-text-deep: #5c3b08;
    --err-deep: #a52038; --err-bg-soft: #fdeef1; --err-border-soft: #f5c2cc; --err-text-soft: #8f1c30;
    --fuchsia: #b04a63; --fuchsia-text: #8f3a4f; --fuchsia-bg: #fdf2f5; --fuchsia-border: #edbccb;
    /* el tooltip y la cabecera de modal son el negro de marca, no el azul del default */
    --tooltip-bg: #1b1b1b; --tooltip-text: #f7f3ee; --err-on-dark: #ff9aa6; --clock-hand: #1b1b1b;
    --modal-grad: linear-gradient(135deg, #1b1b1b 0%, #2e2e30 100%); --modal-grad-text: #ffc2b1; --modal-grad-accent: #ff4b33;
    --code-bg: #1b1b1b; --code-text: #e6d9ca; --terminal-bg: #0f0f10; --terminal-text: #e6d9ca;
    --status-0: #a1a1a1; --status-2: #1f7a52; --status-3: #c62a45; --status-4: #a56a10; --status-5: #464646; --status-6: #b04a63; --live: #1f7a52;
    --toolbar-icon-bg: linear-gradient(135deg, #fff5f2 0%, #ffe1d8 100%); --toolbar-icon-fg: #c2451f;
    --grad-glow: rgba(255, 75, 51, 0.28);
    /* legacy */
    --color-surface-hover: #fbfaf9; --color-surface-subdued: #f7f7f7;
    --color-border-subdued: #ededed; --color-border-strong: #cfcfcf;
    --color-text-strong: #000000; --color-text-muted: #767676; --color-text-disabled: #b3b3b3; --color-text-inverse: #ffffff;
    --color-primary-hover: #e03a23; --color-primary-pressed: #c22f1a; --color-primary-subdued: #fff0ec;
    --color-success-hover: #175f3f; --color-success-bg: #dcf3e8; --color-success-text: #14543a;
    --color-warning-bg: #fdf1d8; --color-warning-text: #7a4f0c;
    --color-danger-hover: #a52038; --color-danger-bg: #fdeef1; --color-danger-text: #8f1c30;
    --color-info-bg: #fff0ec; --color-info-text: #8f2f14;
    --shadow-xs: 0 1px 0 rgba(27, 27, 27, 0.04); --shadow-md: 0 4px 10px rgba(27, 27, 27, 0.07); --shadow-lg: 0 12px 26px rgba(27, 27, 27, 0.10); --shadow-focus: 0 0 0 3px rgba(255, 75, 51, 0.2);
    /* Menu BLANCO: la pieza clara de la pantalla, no la oscura. El TEXTO sigue al fondo (negro de
       marca sobre el menu claro; bajo variante oscura el motor lo pasa a claro) y el coral queda
       reservado a los ICONOS -regla .sidebar-icon mas abajo- y a los estados activo/hover. */
    --color-sidebar-bg: #ffffff; --color-sidebar-surface: #fbf7f5; --color-sidebar-text: #1b1b1b; --color-sidebar-text-muted: #767676; --color-sidebar-active: #000000; --color-sidebar-active-bg: rgba(255, 75, 51, 0.12); --color-sidebar-hover-bg: rgba(255, 75, 51, 0.07); --color-sidebar-border: #ececec;
}

/* =============================================================
   VARIANTES DE COLOR POR TEMA (data-variant en <html>).
   Arquitectura en 2 capas para NO duplicar estilos:
   1) Cada variante define SOLO 7 seeds neutros (--v-*). Agregar una
      variante nueva = un bloque de seeds + entrada en el catalogo JS
      (_ThemeSelector VARIANTS); la logica no cambia.
   2) El motor html[data-variant] (debajo) deriva TODO el contrato
      neutro de esos seeds y re-tinta las sub-paletas (read/amber/
      err/fuchsia/legacy) con color-mix desde los tokens DEL TEMA
      (--read/--amber/--err/--ok/--warn/--accent), conservando la
      identidad: el motor NUNCA toca --accent, --c1..--c4s, --grad,
      los --status-N, --font ni --radius.
   Estos bloques van DESPUES de los temas: a igual especificidad
   (html[attr]) gana el ultimo, asi la variante pisa al tema.
   Sin data-variant (o variante "default"): el tema queda intacto.
============================================================= */
html[data-variant="dark"]     { --v-bg: #0a0a0d; --v-surface: #121217; --v-card: #18181f; --v-border: #2a2a35; --v-text: #e8e9f0; --v-dim: #9a9caa; --v-strong: #ffffff; }
html[data-variant="graphite"] { --v-bg: #0f1318; --v-surface: #151b23; --v-card: #1b232e; --v-border: #2c3a4a; --v-text: #e6edf5; --v-dim: #93a4b8; --v-strong: #ffffff; }
html[data-variant="steel"]    { --v-bg: #0b1220; --v-surface: #111a2c; --v-card: #16223a; --v-border: #263654; --v-text: #e4ebf7; --v-dim: #8fa1c0; --v-strong: #ffffff; }
html[data-variant="carbon"]   { --v-bg: #121212; --v-surface: #1a1a1a; --v-card: #212121; --v-border: #333333; --v-text: #ececec; --v-dim: #9e9e9e; --v-strong: #ffffff; }
html[data-variant="ember"]    { --v-bg: #14100d; --v-surface: #1c1612; --v-card: #241c16; --v-border: #3d2f24; --v-text: #f2e9e1; --v-dim: #b09a88; --v-strong: #ffffff; }
html[data-variant="emerald"]  { --v-bg: #0a1410; --v-surface: #101c16; --v-card: #15241d; --v-border: #28443a; --v-text: #e4f2ea; --v-dim: #8fb3a3; --v-strong: #ffffff; }
html[data-variant="forest"]   { --v-bg: #0c120c; --v-surface: #121a12; --v-card: #172217; --v-border: #2c402c; --v-text: #e8f0e6; --v-dim: #9ab096; --v-strong: #ffffff; }
html[data-variant="violet"]   { --v-bg: #100d1a; --v-surface: #161224; --v-card: #1c172e; --v-border: #322a4e; --v-text: #eae6f5; --v-dim: #a299c0; --v-strong: #ffffff; }

/* --- PASTEL (familia CLARA). Ademas de los 7 seeds neutros definen los ganchos que el motor
   consulta con var(..., fallback): --v-mix (color hacia el que se empujan los textos de estado;
   en las variantes oscuras el fallback es #ffffff, aqui un tinte profundo de la misma familia
   para que el texto siga legible sobre fondo claro), el menu en claro (--v-side-*), el tooltip
   -que sigue siendo oscuro, es lo unico legible sobre cualquier fondo- y una sombra suave.
   Los seeds de superficie llevan un tinte del color: en blanco puro la paleta no se notaria. */
html[data-variant="blush"], html[data-variant="mint"], html[data-variant="lilac"],
html[data-variant="sky"], html[data-variant="sand"] {
    --v-strong: #000000;
    --v-shadow: 0 1px 2px rgba(24, 20, 28, 0.05), 0 4px 12px rgba(24, 20, 28, 0.06);
    --v-shadow-xs: 0 1px 0 rgba(24, 20, 28, 0.04);
    --v-shadow-md: 0 4px 10px rgba(24, 20, 28, 0.07);
    --v-shadow-lg: 0 12px 26px rgba(24, 20, 28, 0.10);
    --v-side-active-bg: rgba(24, 20, 28, 0.07);
    --v-side-hover-bg: rgba(24, 20, 28, 0.04);
    --v-tip-text: #f5f2f7;
    /* Peso del COLOR al armar un texto de estado: en oscuro manda el color (55-75%) porque
       se empuja a blanco; en claro se empuja al tinte profundo --v-mix y hay que bajarlo o
       el texto queda pastel sobre pastel (medido: verde 3,9 y ambar 3,1 -> por debajo de AA). */
    --v-txt-w: 30%;
    --v-txt-w2: 45%;
}
html[data-variant="blush"] {
    --v-bg: #fdf4f6; --v-surface: #fffbfc; --v-card: #ffffff; --v-border: #f0dbe1; --v-text: #33262c; --v-dim: #7c6870;
    --v-mix: #3a2830; --v-tip-bg: #33262c;
    --v-side-bg: #fae7ec; --v-side-surface: #fffbfc; --v-side-text: #4a3a41; --v-side-dim: #6f5b64; --v-side-active: #2a1f24; --v-side-border: #f0dbe1;
}
html[data-variant="mint"] {
    --v-bg: #f1faf5; --v-surface: #fafefb; --v-card: #ffffff; --v-border: #d6eade; --v-text: #1f2e28; --v-dim: #5f7a6e;
    --v-mix: #17322a; --v-tip-bg: #1f2e28;
    --v-side-bg: #e3f4ea; --v-side-surface: #fafefb; --v-side-text: #35473e; --v-side-dim: #52655c; --v-side-active: #16241d; --v-side-border: #d6eade;
}
html[data-variant="lilac"] {
    --v-bg: #f7f4fd; --v-surface: #fdfbff; --v-card: #ffffff; --v-border: #e3dcf4; --v-text: #2a2437; --v-dim: #6f6889;
    --v-mix: #2a2340; --v-tip-bg: #2a2437;
    --v-side-bg: #ece5fa; --v-side-surface: #fdfbff; --v-side-text: #3f3854; --v-side-dim: #625b78; --v-side-active: #221d2e; --v-side-border: #e3dcf4;
}
html[data-variant="sky"] {
    --v-bg: #f1f7fd; --v-surface: #fafcff; --v-card: #ffffff; --v-border: #d8e5f4; --v-text: #1f2b3a; --v-dim: #607588;
    --v-mix: #17293d; --v-tip-bg: #1f2b3a;
    --v-side-bg: #e2eefb; --v-side-surface: #fafcff; --v-side-text: #35455a; --v-side-dim: #556777; --v-side-active: #17212d; --v-side-border: #d8e5f4;
}
/* Arena: los neutros calidos de la identidad de Toteat (crema #f7f3ee, arena #e6d9ca). */
html[data-variant="sand"] {
    --v-bg: #f7f3ee; --v-surface: #fdfbf8; --v-card: #ffffff; --v-border: #e6d9ca; --v-text: #2c251f; --v-dim: #7b6d60;
    --v-mix: #33291f; --v-tip-bg: #2c251f;
    --v-side-bg: #efe6da; --v-side-surface: #fdfbf8; --v-side-text: #46392e; --v-side-dim: #6c5f52; --v-side-active: #241d18; --v-side-border: #e6d9ca;
}

/* Motor: deriva el contrato desde los seeds. Sirve a las dos familias: las variantes OSCURAS
   solo declaran los 7 seeds y todo lo demas cae en los fallbacks historicos; las PASTEL
   (claras) declaran ademas --v-mix, --v-side-*, --v-tip-* y --v-shadow-*, que son justo los
   puntos donde una formula pensada para fondo oscuro se rompia en claro (texto empujado a
   blanco, menu ennegrecido, sombras al 45% de negro). El motor NUNCA toca --accent, --c1..--c4s,
   --grad, los --status-N, --font ni --radius: la identidad del tema se conserva. */
html[data-variant] {
    /* Neutros directos */
    --bg: var(--v-bg); --surface: var(--v-surface); --card: var(--v-card);
    --border: var(--v-border); --text: var(--v-text); --dim: var(--v-dim);
    --chip: color-mix(in srgb, var(--v-card) 88%, var(--v-text) 12%);
    --line: color-mix(in srgb, var(--v-border) 78%, var(--v-text) 22%);
    --shadow: var(--v-shadow, 0 2px 10px rgba(0, 0, 0, 0.45));
    /* Extendidos de vistas */
    --ink: var(--v-text);
    --ink-2: color-mix(in srgb, var(--v-text) 88%, var(--v-bg) 12%);
    --ink-3: color-mix(in srgb, var(--v-text) 72%, var(--v-bg) 28%);
    --ink-4: var(--v-dim);
    --ink-5: color-mix(in srgb, var(--v-dim) 65%, var(--v-bg) 35%);
    --surface-2: color-mix(in srgb, var(--v-surface) 60%, var(--v-card) 40%);
    --surface-3: color-mix(in srgb, var(--v-card) 92%, var(--v-text) 8%);
    --border-2: var(--v-border);
    --border-3: color-mix(in srgb, var(--v-border) 82%, var(--v-text) 18%);
    /* Sub-paletas re-tintadas con los colores DEL TEMA (identidad intacta) */
    --read-bg: color-mix(in srgb, var(--read) 16%, var(--v-bg) 84%);
    --read-bg-hover: color-mix(in srgb, var(--read) 24%, var(--v-bg) 76%);
    --read-bg-faint: color-mix(in srgb, var(--read) 9%, var(--v-bg) 91%);
    --read-text: color-mix(in srgb, var(--read) var(--v-txt-w, 55%), var(--v-mix, #ffffff));
    --read-border: color-mix(in srgb, var(--read) 38%, var(--v-bg) 62%);
    --read-chip: color-mix(in srgb, var(--read) 12%, var(--v-card) 88%);
    --read-chip-hover: color-mix(in srgb, var(--read) 20%, var(--v-card) 80%);
    --read-border-soft: color-mix(in srgb, var(--read) 30%, var(--v-bg) 70%);
    --write-bg: color-mix(in srgb, var(--write) 16%, var(--v-bg) 84%);
    --amber-bg: color-mix(in srgb, var(--amber) 14%, var(--v-bg) 86%);
    --amber-text: color-mix(in srgb, var(--amber) var(--v-txt-w, 62%), var(--v-mix, #ffffff));
    --amber-border: color-mix(in srgb, var(--amber) 42%, var(--v-bg) 58%);
    --amber-bg-hover: color-mix(in srgb, var(--amber) 22%, var(--v-bg) 78%);
    --amber-bg-faint: color-mix(in srgb, var(--amber) 8%, var(--v-bg) 92%);
    --amber-text-deep: color-mix(in srgb, var(--amber) var(--v-txt-w2, 72%), var(--v-mix, #ffffff));
    --err-deep: color-mix(in srgb, var(--err) var(--v-txt-w2, 75%), var(--v-mix, #ffffff));
    --err-bg-soft: color-mix(in srgb, var(--err) 14%, var(--v-bg) 86%);
    --err-border-soft: color-mix(in srgb, var(--err) 32%, var(--v-bg) 68%);
    --err-text-soft: color-mix(in srgb, var(--err) var(--v-txt-w, 55%), var(--v-mix, #ffffff));
    --err-on-dark: color-mix(in srgb, var(--err) var(--v-txt-w, 60%), var(--v-mix, #ffffff));
    --fuchsia-text: color-mix(in srgb, var(--fuchsia) var(--v-txt-w, 55%), var(--v-mix, #ffffff));
    --fuchsia-bg: color-mix(in srgb, var(--fuchsia) 14%, var(--v-bg) 86%);
    --fuchsia-border: color-mix(in srgb, var(--fuchsia) 35%, var(--v-bg) 65%);
    /* Cromos */
    --tooltip-bg: var(--v-tip-bg, color-mix(in srgb, var(--v-bg) 65%, #000000 35%));
    --tooltip-text: var(--v-tip-text, color-mix(in srgb, var(--v-text) 88%, var(--v-bg) 12%));
    --clock-hand: color-mix(in srgb, var(--accent) var(--v-txt-w2, 70%), var(--v-mix, #ffffff));
    --modal-grad: linear-gradient(135deg, var(--v-card) 0%, var(--v-bg) 100%);
    --modal-grad-text: color-mix(in srgb, var(--accent) var(--v-txt-w, 55%), var(--v-mix, #ffffff));
    --modal-grad-accent: var(--accent);
    --toolbar-icon-bg: linear-gradient(135deg, color-mix(in srgb, var(--accent) 18%, var(--v-bg) 82%) 0%, color-mix(in srgb, var(--accent) 28%, var(--v-bg) 72%) 100%);
    --toolbar-icon-fg: color-mix(in srgb, var(--accent) var(--v-txt-w, 65%), var(--v-mix, #ffffff));
    /* Legacy --color-* */
    --color-surface-hover: color-mix(in srgb, var(--v-card) 90%, var(--v-text) 10%);
    --color-surface-subdued: color-mix(in srgb, var(--v-surface) 85%, var(--v-bg) 15%);
    --color-border-subdued: color-mix(in srgb, var(--v-border) 75%, var(--v-bg) 25%);
    --color-border-strong: color-mix(in srgb, var(--v-border) 78%, var(--v-text) 22%);
    --color-text-strong: var(--v-strong);
    --color-text-muted: var(--v-dim);
    --color-text-disabled: color-mix(in srgb, var(--v-dim) 50%, var(--v-bg) 50%);
    --color-text-inverse: var(--v-bg);
    --color-primary-subdued: color-mix(in srgb, var(--accent) 16%, var(--v-bg) 84%);
    --color-success-bg: color-mix(in srgb, var(--ok) 16%, var(--v-bg) 84%);
    --color-success-text: color-mix(in srgb, var(--ok) var(--v-txt-w, 55%), var(--v-mix, #ffffff));
    --color-warning-bg: color-mix(in srgb, var(--warn) 16%, var(--v-bg) 84%);
    --color-warning-text: color-mix(in srgb, var(--warn) var(--v-txt-w, 60%), var(--v-mix, #ffffff));
    --color-danger-bg: color-mix(in srgb, var(--err) 16%, var(--v-bg) 84%);
    --color-danger-text: color-mix(in srgb, var(--err) var(--v-txt-w, 55%), var(--v-mix, #ffffff));
    --color-info-bg: color-mix(in srgb, var(--accent) 16%, var(--v-bg) 84%);
    --color-info-text: color-mix(in srgb, var(--accent) var(--v-txt-w, 55%), var(--v-mix, #ffffff));
    --shadow-xs: var(--v-shadow-xs, 0 1px 0 rgba(0, 0, 0, 0.3));
    --shadow-md: var(--v-shadow-md, 0 4px 12px rgba(0, 0, 0, 0.5));
    --shadow-lg: var(--v-shadow-lg, 0 12px 28px rgba(0, 0, 0, 0.6));
    /* Menu: en las pastel es claro (--v-side-*), en las oscuras se sigue derivando del seed. */
    --color-sidebar-bg: var(--v-side-bg, color-mix(in srgb, var(--v-bg) 75%, #000000 25%));
    --color-sidebar-surface: var(--v-side-surface, var(--v-surface));
    --color-sidebar-border: var(--v-side-border, color-mix(in srgb, var(--v-border) 70%, var(--v-bg) 30%));
    --color-sidebar-text: var(--v-side-text, #d2d2d3);
    --color-sidebar-text-muted: var(--v-side-dim, #8c8c8c);
    --color-sidebar-active: var(--v-side-active, #ffffff);
    --color-sidebar-active-bg: var(--v-side-active-bg, rgba(255, 255, 255, 0.08));
    --color-sidebar-hover-bg: var(--v-side-hover-bg, rgba(255, 255, 255, 0.04));
}

/* Toteat es un tema CLARO, asi que sus estados y series van en version oscura. Bajo una variante
   OSCURA hay que subirlos: mismo concepto, tono que se lee sobre negro. (Las pastel no necesitan
   nada: el tema base ya esta pensado para fondo claro.) */
html[data-theme="toteat"][data-variant="dark"], html[data-theme="toteat"][data-variant="carbon"],
html[data-theme="toteat"][data-variant="ember"] {
    --c1: #ff6a55; --c1s: #7a2418; --c2: #ffc46b; --c2s: #7a5c22; --c3: #7fd1c4; --c3s: #2f6159; --c4: #f6a9b8; --c4s: #75404a;
    --chart-s1: #ff6a55; --chart-s2: #7fd1c4;
    --ok: #4cc38a; --warn: #ffb020; --err: #ff5a6e;
    --read: #ff8a6b; --write: #4cc38a; --amber: #ffb020; --fuchsia: #f6a9b8;
    --status-2: #4cc38a; --status-3: #ff5a6e; --status-4: #ffb020; --status-6: #f6a9b8; --live: #4cc38a;
}
/* Toteat firma con el ICONO, no con la tipografia: los svg del menu (que pintan con currentColor)
   van siempre en el naranja de la marca, mientras el texto sigue al fondo -negro sobre el menu claro,
   claro cuando una variante oscura lo oscurece-. El mismo naranja marca los titulos principales de
   cada vista, que es donde la marca se reconoce sin gritar. */
html[data-theme="toteat"] .sidebar-icon { color: var(--accent); }
html[data-theme="toteat"] .page-title { color: var(--accent); }
/* El contador de los enlaces trae un fondo blanco translucido pensado para menus oscuros: sobre el
   menu blanco de Toteat desaparece, asi que ahi va un tinte del coral. */
html[data-theme="toteat"] .sidebar-link-count { background: color-mix(in srgb, var(--accent) 14%, transparent); }
/* n8n es un tema OSCURO: bajo variante PASTEL sus series y estados (ambar, verde menta, violeta
   claro) desaparecen sobre fondo casi blanco -medido: 1,5 a 1,8 de contraste-, asi que aqui van
   en su version oscura. flow y canvas ya son claros y no necesitan nada. */
html[data-theme="n8n"][data-variant="sand"], html[data-theme="n8n"][data-variant="blush"] {
    --c1: #d1541b; --c1s: #ffc29e; --c2: #c23b3b; --c2s: #ffb3b3; --c3: #147a54; --c3s: #9ef0d0; --c4: #6b4bc4; --c4s: #d6c8ff;
    --chart-s1: #d1541b; --chart-s2: #2b6fb5;
    --read: #c25218; --write: #147a54; --amber: #9a7212; --fuchsia: #6b4bc4;
    --ok: #147a54; --warn: #9a7212; --err: #c23b3b;
    --status-2: #147a54; --status-3: #c23b3b; --status-4: #9a7212; --status-6: #6b4bc4; --live: #147a54;
}
/* Iconos btn-close de Bootstrap: en variantes oscuras se invierten (igual que n8n/cyber). */
html[data-variant] .btn-close { filter: invert(1) brightness(1.6); }
/* ...pero las pastel son claras: el icono negro original es el que se lee. */
html[data-variant="blush"] .btn-close, html[data-variant="mint"] .btn-close, html[data-variant="lilac"] .btn-close,
html[data-variant="sky"] .btn-close, html[data-variant="sand"] .btn-close { filter: none; }

/* ============= Base ============= */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 { color: var(--color-text-strong); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 24px; line-height: 1.25; }
h2 { font-size: 20px; line-height: 1.3; }
h3 { font-size: 17px; line-height: 1.35; }
h4 { font-size: 15px; line-height: 1.4; }
h5 { font-size: 13px; line-height: 1.4; }
h6 { font-size: 12px; line-height: 1.4; text-transform: uppercase; letter-spacing: 0.04em; color: var(--color-text-muted); font-weight: 600; }
p { margin: 0; color: var(--color-text-secondary); }
a { color: var(--color-primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--color-primary-hover); }

code, pre { font-family: var(--font-mono); font-size: 12.5px; }
code {
    padding: 1px 6px;
    background: var(--color-surface-pressed);
    border-radius: var(--radius-sm);
    color: var(--color-text-strong);
    font-size: 12.5px;
}
pre {
    margin: 0;
    padding: var(--space-4);
    background: var(--color-surface-subdued);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow-x: auto;
    color: var(--color-text);
}
pre code { padding: 0; background: transparent; }

/* ============= Layout ============= */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--topbar-height) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
    transition: grid-template-columns var(--transition-base);
}

.app-sidebar { grid-area: sidebar; background: var(--color-sidebar-bg); color: var(--color-sidebar-text); border-right: 1px solid var(--color-sidebar-border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; transition: transform var(--transition-base); overflow: hidden; }
.app-topbar { grid-area: topbar; background: var(--color-surface); border-bottom: 1px solid var(--color-border); padding: 0 var(--space-6); display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); position: sticky; top: 0; z-index: 20; }
.app-main { grid-area: main; padding: var(--space-6) var(--space-8); width: 100%; min-width: 0; }
/* Vistas densas (Dashboard/Conexiones): equivalen a ~85% de zoom del navegador sin tocar cada px. */
.app-main.is-compact { zoom: 0.85; }

/* Sidebar hidden (desktop) */
.app-shell.sidebar-collapsed { grid-template-columns: 0 1fr; }
.app-shell.sidebar-collapsed .app-sidebar { transform: translateX(-100%); border-right: none; }
.app-shell .sidebar-show-btn { display: none; }
.app-shell.sidebar-collapsed .sidebar-show-btn { display: inline-flex; }
.app-shell.sidebar-collapsed .sidebar-hide-btn { display: none; }

/* ============= Sidebar ============= */
.sidebar-header { padding: var(--space-5) var(--space-5) var(--space-4); border-bottom: 1px solid var(--color-sidebar-border); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.sidebar-hide-btn {
    width: 30px; height: 30px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid var(--color-sidebar-border);
    color: var(--color-sidebar-text);
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all var(--transition-fast);
    flex-shrink: 0;
}
.sidebar-hide-btn:hover { background: var(--color-sidebar-hover-bg); color: var(--color-sidebar-active); }
.sidebar-hide-btn svg { width: 16px; height: 16px; }
.sidebar-brand { display: flex; align-items: center; gap: var(--space-3); text-decoration: none; min-width: 0; flex: 1; }
.sidebar-brand:hover { color: var(--color-sidebar-active); }
/* El isotipo es vertical (247x392): a 32px de alto mide ~20px de ancho. La caja de 36px centrada dejaba
   aire a la izquierda y el logo no alineaba con los iconos del menu de abajo. Caja al ancho del isotipo. */
.sidebar-logo {
    height: 36px; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: flex-start;
}
.sidebar-logo img { height: 32px; width: auto; display: block; }
.sidebar-brand-text { color: var(--color-sidebar-active); font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.sidebar-brand-subtitle { display: block; font-size: 11px; color: var(--color-sidebar-text-muted); font-weight: 400; letter-spacing: 0.04em; }
.sidebar-edition-badge { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 999px; font-size: 10px; font-weight: 700; letter-spacing: 0.06em; line-height: 16px; color: #fff; background: #0a7c3e; vertical-align: middle; }

.sidebar-nav { flex: 1; padding: var(--space-3) var(--space-3); overflow-y: auto; }
.sidebar-section { margin-bottom: var(--space-4); }
.sidebar-section-title { padding: var(--space-2) var(--space-3); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-sidebar-text-muted); font-weight: 600; margin-top: var(--space-3); }

.sidebar-link {
    display: flex; align-items: center; gap: var(--space-3);
    padding: 9px var(--space-3);
    border-radius: var(--radius-md);
    color: var(--color-sidebar-text);
    font-weight: 500; font-size: 13.5px;
    text-decoration: none;
    transition: background var(--transition-fast), color var(--transition-fast);
    margin-bottom: 2px;
}
.sidebar-link:hover { background: var(--color-sidebar-hover-bg); color: var(--color-sidebar-active); }
.sidebar-link.active { background: var(--color-sidebar-active-bg); color: var(--color-sidebar-active); font-weight: 600; }
.sidebar-link .sidebar-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.9; }
.sidebar-link.active .sidebar-icon { opacity: 1; }
.sidebar-link-count { margin-left: auto; background: rgba(255, 255, 255, 0.08); color: var(--color-sidebar-text); padding: 2px 8px; border-radius: var(--radius-full); font-size: 11px; font-weight: 600; }

.sidebar-footer { padding: var(--space-4); border-top: 1px solid var(--color-sidebar-border); }
.sidebar-user { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2); border-radius: var(--radius-md); }
.sidebar-user-avatar {
    width: 32px; height: 32px; border-radius: var(--radius-full);
    background: var(--grad);
    color: var(--on-accent); display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; color: var(--color-sidebar-active); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-email { font-size: 11.5px; color: var(--color-sidebar-text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ============= Topbar ============= */
.topbar-title { font-size: 14px; color: var(--color-text-secondary); }
.topbar-actions { display: flex; align-items: center; gap: var(--space-3); }

.topbar-search {
    position: relative;
    flex: 1;
    max-width: 480px;
}
.topbar-search input {
    width: 100%; height: 36px;
    padding: 0 var(--space-4) 0 36px;
    background: var(--color-surface-pressed);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: 13px;
    transition: all var(--transition-fast);
}
.topbar-search input:focus { background: var(--color-surface); border-color: var(--color-primary); outline: none; box-shadow: var(--shadow-focus); }
.topbar-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--color-text-muted); width: 16px; height: 16px; }

.topbar-iconbtn {
    width: 36px; height: 36px;
    border-radius: var(--radius-md);
    background: transparent;
    border: 1px solid transparent;
    color: var(--color-text-secondary);
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all var(--transition-fast);
    position: relative;
}
.topbar-iconbtn:hover { background: var(--color-surface-pressed); color: var(--color-text); }
.topbar-iconbtn .icon { width: 18px; height: 18px; }
.topbar-iconbtn .dot { position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--color-danger); border: 2px solid var(--color-surface); }

.mobile-menu-toggle { display: none; }
.sidebar-show-btn {
    align-items: center; justify-content: center; gap: var(--space-2);
}
.sidebar-show-btn .icon { width: 18px; height: 18px; }

/* ============= Page header ============= */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); flex-wrap: wrap; }
.page-header-content { flex: 1; min-width: 0; }
.page-title { font-size: 22px; font-weight: 600; color: var(--color-text-strong); letter-spacing: -0.01em; margin-bottom: 4px; }
.page-subtitle { font-size: 14px; color: var(--color-text-secondary); }
.page-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* ============= Page toolbar (card variant del page-header) ============= */
.page-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    padding: 14px 20px;
    margin-bottom: var(--space-6);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
.page-toolbar-info { display: flex; align-items: center; gap: var(--space-3); flex: 1; min-width: 0; }
.page-toolbar-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px;
    border-radius: 10px;
    background: var(--toolbar-icon-bg);
    color: var(--toolbar-icon-fg);
    flex-shrink: 0;
}
.page-toolbar-text { min-width: 0; }
.page-toolbar-text .page-title { margin-bottom: 2px; font-size: 18px; }
.page-toolbar-text .page-subtitle { font-size: 12.5px; line-height: 1.4; }
.page-toolbar-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.page-toolbar-divider {
    width: 1px; height: 24px;
    background: var(--color-border);
    margin: 0 var(--space-1);
}

/* Botones agrupados (segmented control) */
.btn-group { display: inline-flex; align-items: stretch; }
.btn-group > .btn { border-radius: 0; margin-left: -1px; position: relative; }
.btn-group > .btn:first-child { border-top-left-radius: var(--radius-md, 6px); border-bottom-left-radius: var(--radius-md, 6px); margin-left: 0; }
.btn-group > .btn:last-child { border-top-right-radius: var(--radius-md, 6px); border-bottom-right-radius: var(--radius-md, 6px); }
.btn-group > .btn:hover, .btn-group > .btn:focus { z-index: 1; }
.btn-group > .btn svg { flex-shrink: 0; }

@media (max-width: 880px) {
    .page-toolbar { padding: 12px 14px; }
    .page-toolbar-actions { width: 100%; justify-content: flex-end; }
}
@media (max-width: 640px) {
    .page-toolbar { flex-direction: column; align-items: stretch; }
    .page-toolbar-info { width: 100%; }
    .page-toolbar-actions { width: 100%; }
    .page-toolbar-divider { display: none; }
    .btn-group { flex: 1; }
    .btn-group > .btn { flex: 1; justify-content: center; }
}

/* ============= Cards ============= */
.card {
    background: var(--color-surface);
    /* Bootstrap pone color: var(--bs-body-color) (#212529 fijo) en .card; en temas
       oscuros eso deja el texto heredado casi negro. Override con el token del tema. */
    color: var(--text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-base);
}
.card:hover { box-shadow: var(--shadow-md), var(--glow); }
.card-header { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--color-border); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.card-title { font-size: 14px; font-weight: 600; color: var(--color-text-strong); }
.card-subtitle { font-size: 12.5px; color: var(--color-text-muted); margin-top: 2px; }
.card-body { padding: var(--space-5); }
.card-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--color-border); background: var(--color-surface-subdued); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card-section { padding: var(--space-5); border-top: 1px solid var(--color-border); }
.card-section:first-child { border-top: none; }

/* ============= Metric cards ============= */
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-6); }
.metric-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-base);
    position: relative;
    overflow: hidden;
}
.metric-card:hover { box-shadow: var(--shadow-md), var(--glow); }
.metric-card-icon {
    width: 40px; height: 40px;
    border-radius: var(--radius-md);
    display: inline-flex; align-items: center; justify-content: center;
    margin-bottom: var(--space-3);
}
.metric-card-icon.is-primary { background: var(--color-primary-subdued); color: var(--color-primary); }
.metric-card-icon.is-success { background: var(--color-success-bg); color: var(--color-success-text); }
.metric-card-icon.is-warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.metric-card-icon.is-danger { background: var(--color-danger-bg); color: var(--color-danger-text); }
.metric-card-icon svg { width: 20px; height: 20px; }
.metric-card-label { font-size: 12.5px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; margin-bottom: var(--space-1); }
.metric-card-value { font-size: 28px; font-weight: 700; color: var(--color-text-strong); letter-spacing: -0.02em; line-height: 1.1; }
.metric-card-meta { font-size: 12.5px; color: var(--color-text-muted); margin-top: var(--space-2); }
.metric-card-trend { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: var(--radius-full); margin-top: var(--space-2); }
.metric-card-trend.up { color: var(--color-success-text); background: var(--color-success-bg); }
.metric-card-trend.down { color: var(--color-danger-text); background: var(--color-danger-bg); }

/* ============= Buttons ============= */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 13px; font-weight: 600;
    line-height: 1;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    min-height: 36px;
    white-space: nowrap;
}
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn .icon { width: 16px; height: 16px; }

.btn-primary { background: var(--color-primary); color: #fff; border-color: var(--color-primary); }
.btn-primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); color: #fff; }
.btn-primary:active { background: var(--color-primary-pressed); }

.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-surface-hover); color: var(--color-text-strong); border-color: var(--color-border-strong); }

.btn-ghost { background: transparent; color: var(--color-text-secondary); border-color: transparent; }
.btn-ghost:hover { background: var(--color-surface-pressed); color: var(--color-text); }

.btn-danger { background: var(--color-danger); color: #fff; border-color: var(--color-danger); }
.btn-danger:hover { background: var(--color-danger-hover); border-color: var(--color-danger-hover); color: #fff; }

.btn-success { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.btn-success:hover { background: var(--color-success-hover); color: #fff; }

.btn-sm { padding: 5px 10px; font-size: 12px; min-height: 28px; border-radius: var(--radius-sm); }
.btn-sm .icon { width: 14px; height: 14px; }
.btn-lg { padding: 10px 18px; font-size: 14px; min-height: 42px; }

.btn-icon { width: 32px; height: 32px; padding: 0; }
.btn-icon.btn-sm { width: 28px; height: 28px; }

/* ============= Badges ============= */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    font-size: 11.5px; font-weight: 600;
    line-height: 1.3;
    text-transform: none;
    letter-spacing: 0;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.badge-default { background: var(--color-surface-pressed); color: var(--color-text-secondary); }
.badge-primary { background: var(--color-primary-subdued); color: var(--color-primary-pressed); }
.badge-success { background: var(--color-success-bg); color: var(--color-success-text); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger-text); }
.badge-info { background: var(--color-info-bg); color: var(--color-info-text); }
.badge-soft { background: var(--color-surface-pressed); color: var(--color-text); }
.badge-soft::before { display: none; }

/* ============= Forms ============= */
.form-group { margin-bottom: var(--space-4); }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--color-text); margin-bottom: 6px; }
.form-label .required { color: var(--color-danger); }
.form-help { font-size: 12.5px; color: var(--color-text-muted); margin-top: 4px; }
.form-error { font-size: 12.5px; color: var(--color-danger-text); margin-top: 4px; }

.form-control, .form-select, input.form-control, select.form-select, textarea.form-control {
    width: 100%;
    padding: 8px 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-md);
    font-size: 13.5px;
    color: var(--color-text);
    transition: all var(--transition-fast);
    min-height: 36px;
    font-family: inherit;
}
.form-control:focus, .form-select:focus { outline: none; background: var(--color-surface); color: var(--color-text); border-color: var(--color-primary); box-shadow: var(--shadow-focus); }
.form-control::placeholder { color: var(--color-text-muted); }
.form-control:disabled { background: var(--color-surface-pressed); cursor: not-allowed; }
textarea.form-control { min-height: 88px; resize: vertical; }

/* Opciones del dropdown nativo de los <select>: usar tokens del tema. Sin esto el navegador pinta el
   item seleccionado con el azul del sistema, que choca con los temas (sobre todo oscuros). El item
   seleccionado/activo usa un realce sutil de superficie en vez del azul foraneo. */
.form-control option, .form-select option, select option, select optgroup {
    background-color: var(--color-surface);
    color: var(--color-text);
}
.form-control option:checked, .form-select option:checked, select option:checked,
.form-control option:hover, .form-select option:hover, select option:hover {
    background-color: var(--color-surface-hover, var(--color-surface-pressed));
    color: var(--color-text);
}
/* color-scheme por tema: el popup nativo del select (y scrollbars) se renderiza acorde al tema, con un
   realce de seleccion atenuado en vez del azul claro del sistema. */
html[data-theme="n8n"], html[data-theme="cyber"], html[data-theme="terminal"],
html[data-theme="arcade"], html[data-theme="midnight"] { color-scheme: dark; }
html[data-theme="flow"], html[data-theme="canvas"] { color-scheme: light; }

/* Boton nativo de <input type=file> (importar Excel, etc.): tematizado en vez del gris del navegador. */
input[type="file"].form-control { padding: 6px 8px; line-height: 1.5; }
input[type="file"]::file-selector-button {
    margin-right: 10px;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-strong);
    background: var(--color-surface-hover, var(--color-surface));
    color: var(--color-text);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition-fast);
}
input[type="file"]::file-selector-button:hover {
    background: var(--color-primary-subdued, var(--color-surface-pressed));
    border-color: var(--color-primary);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }

.input-group { display: flex; align-items: stretch; }
.input-group .form-control { border-radius: 0; }
.input-group .form-control:first-child { border-top-left-radius: var(--radius-md); border-bottom-left-radius: var(--radius-md); }
.input-group .form-control:last-child { border-top-right-radius: var(--radius-md); border-bottom-right-radius: var(--radius-md); }

.form-check { display: flex; align-items: center; gap: var(--space-2); }
.form-check-input { width: 16px; height: 16px; accent-color: var(--color-primary); cursor: pointer; }
.form-check-label { font-size: 13px; color: var(--color-text); cursor: pointer; }

.field-secret-wrap { position: relative; }
.field-secret-wrap .form-control { padding-right: 80px; }
.field-secret-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: none; background: transparent; color: var(--color-text-muted); font-size: 12px; font-weight: 600; padding: 4px 8px; cursor: pointer; border-radius: var(--radius-sm); }
.field-secret-toggle:hover { background: var(--color-surface-pressed); color: var(--color-text); }

/* ============= Tables / DataTables ============= */
.data-table-wrap {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
.data-table-toolbar { padding: var(--space-4) var(--space-5); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; border-bottom: 1px solid var(--color-border-subdued); }

/* Neutralizar los tokens de tabla de Bootstrap en TODAS las .table: por defecto fija --bs-table-bg blanco,
   una tinta oscura y bordes claros que rompen el contraste en temas oscuros. Asi cualquier tabla (use o no
   app-table, ej. Cronicle) hereda el fondo del tema (la card) y la tinta/bordes de los tokens de la app. */
.table {
    --bs-table-bg: transparent; --bs-table-accent-bg: transparent;
    --bs-table-color: var(--color-text); --bs-border-color: var(--color-border);
    color: var(--color-text); border-color: var(--color-border);
}
.table > thead > tr > th { background: var(--color-surface-subdued); color: var(--color-text-muted); border-color: var(--color-border); }
.table > tbody > tr > td { color: var(--color-text); border-color: var(--color-border-subdued); }
.table > tbody > tr > td, .table > thead > tr > th { box-shadow: none; }

/* Acciones de conexion/local (Index): grupos segmentados, boton dividido y menus (kebab). Todo con tokens
   del tema -> se adapta al acento seleccionado en cualquier tema. */
.ih-actions { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ih-grp { display: inline-flex; border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); overflow: hidden; }
.ih-grp > .btn { border: 0 !important; border-radius: 0 !important; }
.ih-grp > .btn + .btn { border-left: 1px solid var(--color-border-strong) !important; }
.ih-dd { position: relative; display: inline-flex; align-items: stretch; }
.ih-split { border-radius: var(--radius-md); }
.ih-split > form { margin: 0; display: inline-flex; }
.ih-split > form > .btn { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.ih-split > .ih-caret { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 1px solid rgba(255,255,255,.28) !important; padding-left: 8px; padding-right: 8px; }
.ih-menu {
    position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; z-index: 60;
    background: var(--color-surface); border: 1px solid var(--color-border-strong); border-radius: 10px;
    padding: 6px; box-shadow: 0 16px 44px -10px rgba(0,0,0,.55); display: none;
}
.ih-menu.open { display: block; }
/* El backdrop-filter de temas glass (midnight) convierte cada .connection-card en stacking context:
   el z-index:60 del menu no puede rebasar la card siguiente. Elevar la card con menu abierto. */
.connection-card:has(.ih-menu.open) { position: relative; z-index: 70; }
.ih-menu > a, .ih-menu > button, .ih-menu > form > button {
    display: flex; width: 100%; align-items: center; gap: 8px; box-sizing: border-box;
    background: transparent; border: 0; color: var(--color-text-secondary);
    font-family: inherit; font-size: 12.5px; font-weight: 600; line-height: 1.3;
    padding: 8px 10px; border-radius: 7px; cursor: pointer; text-align: left; text-decoration: none; white-space: nowrap;
}
.ih-menu > a:hover, .ih-menu > button:hover, .ih-menu > form > button:hover { background: var(--color-surface-hover); color: var(--color-text); }
.ih-menu > form { margin: 0; }
.ih-menu .ih-mdiv { height: 1px; background: var(--color-border); margin: 5px 4px; }
.ih-menu .danger { color: var(--status-3); }
.ih-menu .danger:hover { color: var(--status-3); background: var(--status-3-bg, var(--color-surface-hover)); }
/* Iconografia propuesta 5: glifo de ancho fijo para que las etiquetas de cada menu/boton alineen su borde izquierdo. */
.ih-ico { flex: 0 0 18px; width: 18px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; line-height: 1; }
.ih-ico-mono { font-family: var(--font-mono, ui-monospace, Consolas, monospace); font-weight: 700; }
.btn .ih-ico { width: auto; min-width: 14px; margin-right: 5px; }

/* === Modal URL global (cronicleGlobalModal): asistente 2 pasos + chips seleccionables de locales === */
#cronicleGlobalModal .cg-steps { display: flex; gap: 8px; margin-bottom: 16px; }
#cronicleGlobalModal .cg-stp { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-4); padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border-2); }
#cronicleGlobalModal .cg-stp .b { width: 20px; height: 20px; border-radius: 50%; background: var(--surface-3); display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; color: var(--ink-3); }
#cronicleGlobalModal .cg-stp.on { border-color: var(--read-border); color: var(--read-text); background: var(--read-bg); }
#cronicleGlobalModal .cg-stp.on .b { background: var(--read); color: #fff; }
#cronicleGlobalModal .cg-stp.done .b { background: var(--read-border); color: var(--read-text); }
#cronicleGlobalModal .cg-ins { font-size: 12.5px; line-height: 1.5; margin: 0 0 12px; }
#cronicleGlobalModal .cg-toolbar { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--ink-3); margin-bottom: 11px; }
#cronicleGlobalModal .cg-lnk { background: 0; border: 0; color: var(--read); font-size: 12px; cursor: pointer; padding: 0; }
#cronicleGlobalModal .cg-lnk:hover { text-decoration: underline; }
#cronicleGlobalModal .cg-chips { display: flex; flex-wrap: wrap; gap: 7px; }
#cronicleGlobalModal .cg-chip { font-size: 11.5px; padding: 5px 10px; border-radius: 18px; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--ink-3); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-family: inherit; line-height: 1.4; }
#cronicleGlobalModal .cg-chip:hover { border-color: var(--border-3); }
#cronicleGlobalModal .cg-chip-n { font-weight: 600; color: var(--ink-4); }
#cronicleGlobalModal .cg-chip.on { background: var(--read-bg); border-color: var(--read-border); color: var(--read-text); }
#cronicleGlobalModal .cg-chip.on .cg-chip-n { color: var(--read-text); }
#cronicleGlobalModal .cg-chip.on::before { content: "\2713"; font-size: 11px; }

/* Contenedor de tablas anchas: scroll horizontal propio. Varias vistas (Retenciones, Costos) ya
   usaban la clase sin definicion global (solo existia local en Notifications) y la tabla desbordaba
   la card recortando la ultima columna (botones Activar/Desactivar). */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.app-table { width: 100%; border-collapse: separate; border-spacing: 0; }
table.app-table thead th { padding: 11px 16px; text-align: left; font-size: 11.5px; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; background: var(--color-surface-subdued); border-bottom: 1px solid var(--color-border); }
table.app-table tbody td { padding: 13px 16px; font-size: 13px; color: var(--color-text); border-bottom: 1px solid var(--color-border-subdued); vertical-align: middle; }
table.app-table tbody tr:hover td { background: var(--color-surface-hover); }
table.app-table tbody tr:last-child td { border-bottom: none; }
table.app-table td .row-actions { display: inline-flex; gap: 4px; opacity: 0.85; }
table.app-table tbody tr:hover .row-actions { opacity: 1; }

/* DataTables overrides */
.dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { color: var(--color-text-secondary); font-size: 12.5px; padding: var(--space-3) var(--space-5); }
.dataTables_wrapper .dataTables_filter input { padding: 6px 12px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); font-size: 13px; margin-left: 8px; min-width: 240px; }
.dataTables_wrapper .dataTables_filter input:focus { outline: none; border-color: var(--color-primary); box-shadow: var(--shadow-focus); }
.dataTables_wrapper .dataTables_length select { padding: 6px 28px 6px 10px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); font-size: 13px; }
.dataTables_wrapper .dataTables_paginate .paginate_button { padding: 5px 10px !important; margin: 0 2px; border-radius: var(--radius-md) !important; border: 1px solid transparent !important; background: transparent !important; color: var(--color-text-secondary) !important; font-size: 12.5px; font-weight: 500; min-width: 32px; text-align: center; }
.dataTables_wrapper .dataTables_paginate .paginate_button:hover { background: var(--color-surface-pressed) !important; color: var(--color-text) !important; border-color: transparent !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current, .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover { background: var(--color-primary) !important; color: #fff !important; border-color: var(--color-primary) !important; }
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled, .dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover { opacity: 0.45; cursor: not-allowed; }

/* Paginacion de DataTables con integracion Bootstrap5 (.pagination/.page-link): por defecto sale gris/blanca
   y rompe los temas oscuros. Tematizar con tokens (cubre Plugins y cualquier tabla DataTables). */
.pagination { --bs-pagination-bg: transparent; --bs-pagination-color: var(--color-text-secondary); --bs-pagination-border-color: var(--color-border); --bs-pagination-hover-bg: var(--color-surface-pressed); --bs-pagination-hover-color: var(--color-text); --bs-pagination-hover-border-color: var(--color-border-strong); --bs-pagination-focus-bg: var(--color-surface-pressed); --bs-pagination-focus-color: var(--color-text); --bs-pagination-active-bg: var(--color-primary); --bs-pagination-active-border-color: var(--color-primary); --bs-pagination-active-color: #fff; --bs-pagination-disabled-bg: transparent; --bs-pagination-disabled-color: var(--color-text-muted); --bs-pagination-disabled-border-color: var(--color-border); }
.page-link { background: transparent; color: var(--color-text-secondary); border-color: var(--color-border); }
.page-link:hover { background: var(--color-surface-pressed); color: var(--color-text); border-color: var(--color-border-strong); }
.page-link:focus { background: var(--color-surface-pressed); color: var(--color-text); box-shadow: var(--shadow-focus); }
.page-item.active .page-link { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.page-item.disabled .page-link { background: transparent; color: var(--color-text-muted); border-color: var(--color-border); }

/* ============= Alerts ============= */
.alert-modern {
    display: flex; align-items: flex-start; gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-size: 13.5px;
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-xs);
}
.alert-modern .alert-icon { flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px; }
.alert-modern .alert-body { flex: 1; }
.alert-modern .alert-title { font-weight: 600; color: var(--color-text-strong); margin-bottom: 2px; }
.alert-modern .alert-close { background: transparent; border: none; padding: 0; cursor: pointer; color: var(--color-text-muted); opacity: 0.7; }
.alert-modern .alert-close:hover { opacity: 1; }

.alert-modern.is-success { background: var(--color-success-bg); border-color: rgba(0, 128, 96, 0.22); color: var(--color-success-text); }
.alert-modern.is-warning { background: var(--color-warning-bg); border-color: rgba(185, 137, 0, 0.25); color: var(--color-warning-text); }
.alert-modern.is-danger { background: var(--color-danger-bg); border-color: rgba(215, 44, 13, 0.22); color: var(--color-danger-text); }
.alert-modern.is-info { background: var(--color-info-bg); border-color: rgba(44, 110, 203, 0.18); color: var(--color-info-text); }

/* ============= Empty states ============= */
.empty-state { text-align: center; padding: var(--space-10) var(--space-6); color: var(--color-text-muted); }
.empty-state-icon { width: 56px; height: 56px; margin: 0 auto var(--space-4); border-radius: var(--radius-full); background: var(--color-surface-pressed); display: flex; align-items: center; justify-content: center; color: var(--color-text-secondary); }
.empty-state-icon svg { width: 28px; height: 28px; }
.empty-state-title { font-size: 15px; font-weight: 600; color: var(--color-text-strong); margin-bottom: 4px; }
.empty-state-text { font-size: 13.5px; color: var(--color-text-muted); max-width: 360px; margin: 0 auto var(--space-4); }

/* ============= Status pills (records) ============= */
.status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 600; line-height: 1.4; }
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; }
.status-pill.is-enviado { background: var(--color-success-bg); color: var(--color-success-text); }
.status-pill.is-enviado .dot { background: var(--color-success); }
.status-pill.is-error { background: var(--color-danger-bg); color: var(--color-danger-text); }
.status-pill.is-error .dot { background: var(--color-danger); }
.status-pill.is-leido { background: var(--color-info-bg); color: var(--color-info-text); }
.status-pill.is-leido .dot { background: var(--color-primary); }
.status-pill.is-pendiente { background: var(--color-surface-pressed); color: var(--color-text-secondary); }
.status-pill.is-pendiente .dot { background: var(--color-text-muted); }
.status-pill.is-reintentando { background: var(--color-warning-bg); color: var(--color-warning-text); }
.status-pill.is-reintentando .dot { background: var(--color-warning); }

/* ============= Utilities ============= */
.text-muted { color: var(--color-text-muted) !important; }
.text-secondary { color: var(--color-text-secondary) !important; }
.text-strong { color: var(--color-text-strong) !important; font-weight: 600; }
.text-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.text-mono { font-family: var(--font-mono); }

.stack { display: flex; }
.stack-vertical { flex-direction: column; }
.stack-1 { gap: var(--space-1); }
.stack-2 { gap: var(--space-2); }
.stack-3 { gap: var(--space-3); }
.stack-4 { gap: var(--space-4); }
.stack-6 { gap: var(--space-6); }
.stack-spread { justify-content: space-between; align-items: center; }
.stack-center { align-items: center; }

.mt-0 { margin-top: 0; } .mt-2 { margin-top: var(--space-2); } .mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); } .mt-6 { margin-top: var(--space-6); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--space-2); } .mb-3 { margin-bottom: var(--space-3); } .mb-4 { margin-bottom: var(--space-4); } .mb-6 { margin-bottom: var(--space-6); }

.divider { border: 0; border-top: 1px solid var(--color-border-subdued); margin: var(--space-4) 0; }

.kbd { font-family: var(--font-mono); font-size: 11.5px; padding: 2px 6px; background: var(--color-surface-pressed); border: 1px solid var(--color-border); border-radius: var(--radius-sm); color: var(--color-text-secondary); }

/* ============= Plugin cards ============= */
.plugin-card { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.plugin-card-logo { width: 40px; height: 40px; border-radius: var(--radius-md); background: var(--grad); color: var(--on-accent); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; text-transform: uppercase; }
.plugin-card-body { flex: 1; min-width: 0; }
.plugin-card-name { font-size: 13.5px; font-weight: 600; color: var(--color-text-strong); }
.plugin-card-meta { font-size: 12px; color: var(--color-text-muted); }

/* ============= Soporte de temas en componentes Bootstrap ============= */
.modal-content { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.modal-header, .modal-footer { border-color: var(--border); }
html[data-theme="n8n"] .btn-close, html[data-theme="cyber"] .btn-close { filter: invert(1) brightness(1.6); }

/* ============= Particulas en conectores del arbol (n8n/cyber) ============= */
@keyframes wire-particle {
    from { background-position: -6px 50%; }
    to { background-position: calc(100% + 6px) 50%; }
}
html[data-theme="n8n"] .tree-graph .branch::after,
html[data-theme="cyber"] .tree-graph .branch::after {
    height: 2px; border-top: none;
    background-color: var(--line);
    background-image: radial-gradient(circle, var(--particle) 0 1px, transparent 2px);
    background-size: 6px 2px;
    background-repeat: no-repeat;
    animation: wire-particle 1.4s linear infinite;
    opacity: var(--particle-op);
}

/* ============= Theme selector (topnav) ============= */
.theme-selector { position: relative; }
.theme-pill {
    display: inline-flex; align-items: center; gap: 8px;
    height: 36px; padding: 0 12px;
    background: var(--surface);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-full);
    cursor: pointer; font-size: 12.5px; font-weight: 600;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.theme-pill:hover { border-color: var(--accent); color: var(--color-text); }
.theme-pill-dots, .theme-item-sw { display: inline-flex; gap: 3px; }
.theme-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--chip); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08); }
.theme-caret { width: 14px; height: 14px; opacity: 0.7; }
.theme-menu {
    position: absolute; right: 0; top: calc(100% + 6px);
    min-width: 230px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px; z-index: 200;
}
.theme-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 8px 10px;
    background: transparent; border: none; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13px; color: var(--text); text-align: left;
    font-family: inherit;
}
.theme-item:hover { background: var(--chip); }
.theme-item.is-active { background: var(--color-primary-subdued); }
.theme-item-name { flex: 1; }
.theme-check { width: 15px; height: 15px; color: var(--accent); flex-shrink: 0; }

/* Submenu de variantes de color por tema (jerarquia tema > variantes) */
.theme-expand {
    display: inline-flex; align-items: center; justify-content: center;
    width: 22px; height: 22px; flex-shrink: 0;
    background: transparent; border: none; border-radius: var(--radius-sm);
    color: var(--dim); cursor: pointer; padding: 0;
}
.theme-expand:hover { background: var(--chip); color: var(--text); }
.theme-expand svg { width: 13px; height: 13px; transition: transform var(--transition-fast); }
.theme-row.is-open .theme-expand svg { transform: rotate(180deg); }
.theme-row { border-radius: var(--radius-sm); }
.theme-row-head { display: flex; align-items: center; gap: 2px; }
.theme-row-head .theme-item { flex: 1; }
.theme-variants { display: none; padding: 2px 0 6px 14px; }
.theme-row.is-open .theme-variants { display: block; }
.theme-variant {
    display: flex; align-items: center; gap: 9px;
    width: 100%; padding: 6px 10px;
    background: transparent; border: none; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 12.5px; color: var(--text); text-align: left;
    font-family: inherit;
}
.theme-variant:hover { background: var(--chip); }
.theme-variant.is-active { background: var(--color-primary-subdued); }
.theme-variant .theme-check { width: 13px; height: 13px; }
.theme-variant-name { flex: 1; }
.theme-swatch {
    width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18), 0 0 0 1px rgba(0, 0, 0, 0.25);
}
@media (max-width: 992px) { .theme-pill-name { display: none; } }

/* Transicion suave al cambiar tema: clase temporal (500ms) puesta por el selector. */
html.theme-switching, html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after {
    transition: background-color 0.45s ease, color 0.45s ease, border-color 0.45s ease, box-shadow 0.45s ease, fill 0.45s ease, stroke 0.45s ease !important;
}

/* Accesibilidad: sin animaciones si el SO lo pide o el usuario lo apaga en el perfil. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
html[data-motion="off"] *, html[data-motion="off"] *::before, html[data-motion="off"] *::after {
    animation: none !important; transition: none !important;
}

/* ============= Perfil ============= */
.profile-header { margin-bottom: var(--space-4); }
.profile-header-row { display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap; }
.profile-avatar {
    width: 56px; height: 56px; border-radius: var(--radius-full);
    background: var(--grad); color: var(--on-accent);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; font-weight: 700; flex-shrink: 0;
}
.profile-id { flex: 1; min-width: 200px; }
.profile-name { font-size: 17px; font-weight: 600; color: var(--color-text-strong); }
.profile-email { font-size: 13px; color: var(--dim); }
.profile-badges { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.profile-stats { display: flex; gap: var(--space-6); }
.profile-stat { text-align: center; }
.profile-stat-num { font-size: 18px; font-weight: 700; color: var(--color-text-strong); }
.profile-stat-lbl { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.04em; }
.profile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.profile-card-wide { grid-column: span 2; }
@media (max-width: 760px) { .profile-card-wide { grid-column: span 1; } }
.profile-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 7px 0; font-size: 13px; border-bottom: 1px solid var(--color-border-subdued); }
.profile-row:last-of-type { border-bottom: none; }
.profile-row-label { color: var(--dim); }
/* Panel de ajustes maestro-detalle (Propuesta 3) */
.profile-settings { margin-top: 12px; }
.profile-settings .card-body { padding: 0; }
.ps-layout { display: grid; grid-template-columns: 210px 1fr; min-height: 320px; }
.ps-rail { border-right: 1px solid var(--color-border-subdued); padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.ps-nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: none; border-radius: var(--radius-md); background: transparent; color: var(--dim); font: inherit; font-size: 13px; text-align: left; cursor: pointer; transition: background var(--transition-fast), color var(--transition-fast); }
.ps-nav-item:hover { background: var(--color-surface-hover); color: var(--color-text-strong); }
.ps-nav-item.is-active { background: var(--color-primary-subdued); color: var(--color-primary); font-weight: 600; }
.ps-nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; }
.ps-detail { padding: 22px 24px; min-width: 0; }
.ps-panel { display: none; }
.ps-panel.is-active { display: block; animation: psFade var(--transition-fast); }
@keyframes psFade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.ps-panel-title { font-size: 16px; font-weight: 600; color: var(--color-text-strong); }
.ps-panel-sub { font-size: 12px; color: var(--dim); margin: 2px 0 18px; }
.ps-panel-form { max-width: 380px; }
.ps-actions { display: flex; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--color-border-subdued); }
@media (max-width: 760px) {
    .ps-layout { grid-template-columns: 1fr; }
    .ps-rail { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--color-border-subdued); }
    .ps-nav-item { white-space: nowrap; }
}
/* Miniaturas de tema */
.theme-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-bottom: var(--space-4); }
.theme-thumb {
    background: transparent; border: 2px solid var(--border); border-radius: var(--radius-md);
    padding: 5px; cursor: pointer; text-align: center; transition: border-color var(--transition-fast);
}
.theme-thumb:hover { border-color: var(--accent-2); }
.theme-thumb.is-active { border-color: var(--accent); }
.theme-thumb-preview {
    position: relative; display: block; height: 56px; border-radius: 6px; overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
}
.ttp-side { position: absolute; left: 0; top: 0; bottom: 0; width: 12px; opacity: 0.85; }
.ttp-bar { position: absolute; left: 12px; right: 0; top: 0; height: 9px; opacity: 0.7; }
.ttp-dots { position: absolute; left: 18px; bottom: 8px; display: flex; gap: 4px; }
.ttp-dots i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.theme-thumb-name { display: block; font-size: 10.5px; font-weight: 600; color: var(--dim); margin-top: 5px; }
/* Switch del perfil reusa .switch-mini de los modales (definido aqui para vistas sin ese CSS) */
.switch-mini { position: relative; display: inline-block; width: 34px; height: 18px; cursor: pointer; }
.switch-mini input { opacity: 0; width: 0; height: 0; }
.switch-mini .slot { position: absolute; inset: 0; background: var(--border-3); border-radius: 10px; transition: background 0.2s; }
.switch-mini .slot::before { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }
.switch-mini input:checked + .slot { background: var(--accent); }

/* ============================================================
   Barras de scroll ocultas en TODO el sistema (pedido 2026-07-02):
   el scroll sigue funcionando (rueda, teclado, tactil, drag),
   solo se oculta la barra visual en pagina y contenedores internos.
   ============================================================ */
* { scrollbar-width: none; -ms-overflow-style: none; }
*::-webkit-scrollbar { display: none; width: 0; height: 0; }

.switch-mini input:checked + .slot::before { transform: translateX(16px); }

/* Densidad compacta (switch del perfil; localStorage ih-density) */
html[data-density="compact"] .app-main { padding: var(--space-4) var(--space-5); }
html[data-density="compact"] .card-body { padding: var(--space-3) var(--space-4); }
html[data-density="compact"] .card-header { padding: var(--space-3) var(--space-4); }
html[data-density="compact"] .metric-card { padding: var(--space-3) var(--space-4); }
html[data-density="compact"] table.app-table thead th { padding: 7px 12px; }
html[data-density="compact"] table.app-table tbody td { padding: 8px 12px; }

/* ============= Toast / animations ============= */
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.animate-in { animation: fadeIn 0.2s ease forwards; }
.animate-slide-up { animation: slideUp 0.25s ease forwards; }

/* ============= Responsive ============= */
@media (max-width: 992px) {
    .app-shell, .app-shell.sidebar-collapsed { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
    .app-sidebar { position: fixed; left: 0; top: 0; width: 280px; height: 100vh; z-index: 100; transform: translateX(-100%); transition: transform var(--transition-base); box-shadow: var(--shadow-lg); }
    .app-sidebar.is-open { transform: translateX(0); }
    .app-shell.sidebar-collapsed .app-sidebar { transform: translateX(-100%); }
    .app-shell.sidebar-collapsed .app-sidebar.is-open { transform: translateX(0); }
    .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 99; opacity: 0; pointer-events: none; transition: opacity var(--transition-base); }
    .sidebar-backdrop.is-open { opacity: 1; pointer-events: auto; }
    .mobile-menu-toggle { display: inline-flex; }
    /* En movil el sidebar es off-canvas (lo abre .mobile-menu-toggle); el boton "mostrar menu" de
       escritorio sobra y duplicaba el icono hamburguesa. Mostrar SOLO uno. */
    .app-shell .sidebar-show-btn,
    .app-shell.sidebar-collapsed .sidebar-show-btn { display: none; }
    .topbar-search { display: none; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .app-main { padding: var(--space-4); }
    /* Los informes (BI Pangea) piden CompactScale para meter mas columnas en el escritorio. En el
       celular ese zoom 0.85 encima del ancho de 360px deja la letra ilegible: se anula. */
    .app-main.is-compact { zoom: 1; }
    .metric-grid { grid-template-columns: 1fr; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-actions { flex-wrap: wrap; gap: var(--space-2); }

    /* Topbar mas compacto */
    .app-topbar { padding: 0 var(--space-3); }
    .topbar-actions { gap: var(--space-1); }
    .topbar-actions .topbar-iconbtn { padding: 6px; }

    /* Alerts ocupan todo el ancho con padding menor */
    .alert-modern { padding: var(--space-3); gap: var(--space-2); }
    .alert-body { font-size: 12px; }

    /* Cards con menos padding */
    .connection-card { border-radius: 8px; }
    .connection-card .card-header[data-toggle-body] { padding: 10px 12px; gap: 8px; }
    /* Acciones del header: que ENVUELVAN a ancho natural en varias filas en vez de apretarse en una sola
       (flex:1 con 7-9 botones recortaba el texto: "ConfigEquivalencURLs"). */
    .connection-card .row-actions { width: 100%; justify-content: flex-start; flex-wrap: wrap; gap: 6px; }
    .connection-card .row-actions .btn,
    .connection-card .row-actions form,
    .connection-card .row-actions form .btn { flex: 0 0 auto; min-width: 0; width: auto; }

    /* Acciones por local: misma idea, envolver sin montarse. */
    .lf-actions { flex-wrap: wrap; gap: 6px; }
    .lf-actions .btn, .lf-actions form, .lf-actions form .btn { flex: 0 0 auto; }

    /* Barras de botones dentro de modales (eq/cuentas/reglas): envolver y no desbordar el contenedor. */
    .modal-footer { flex-wrap: wrap; gap: 8px; }
    .modal-body .input-group { flex-wrap: wrap; }

    /* Tree node: info arriba a ancho completo, cluster de acciones abajo alineado a la derecha. */
    .tree-node {
        flex-wrap: wrap;
        gap: 8px;
        padding: 8px 10px;
        font-size: 12px;
    }
    .tree-node .info { flex: 1 1 100%; }
    .tree-node .node-acts { margin-left: 0; width: 100%; justify-content: flex-end; }
    .tree-node .node-acts .reorder-cell { flex-direction: row; gap: 4px; }
    .tree-node .node-acts .reorder-cell .reorder-form .reorder-btn { width: 36px !important; height: 22px !important; min-height: 22px !important; }

    .tree-graph .branch { margin-left: 8px; padding-left: 14px; }
    .tree-graph .branch::after { width: 12px; top: 18px; }

    /* Status panel: 1 columna y cards mas compactas */
    .status-panel-grid { grid-template-columns: 1fr; }
    .status-card { padding: 8px 10px; }

    /* Match key inline: wrap mas chico, ocultar columnas individuales (mostrar solo etiqueta + modo) */
    .match-key-inline .mk-col { display: none; }
    .match-key-inline { font-size: 10px; gap: 3px; }

    /* Modal: full screen friendly */
    .modal-dialog { margin: 0.5rem; max-width: calc(100% - 1rem); }
}

/* Tablet: tree node stack hibrido (info arriba, controles en fila) */
@media (max-width: 880px) and (min-width: 641px) {
    .tree-node {
        grid-template-columns: 1fr 44px 90px 110px;
        gap: 8px;
        padding: 8px 12px;
    }
    .connection-card .row-actions { flex-wrap: wrap; }
}

/* Aprovechar bien el ancho en monitores grandes: sin max-width, padding mayor para no pegarse al borde */
@media (min-width: 1600px) {
    .app-main { padding: var(--space-6) 48px; }
}
@media (min-width: 1920px) {
    .app-main { padding: var(--space-6) 64px; }
}

/* ============================================================
   Campana de notificaciones internas (topbar): badge de no
   leidas + panel con los mensajes que aparecieron en pantalla.
   ============================================================ */
.notif-bell { position: relative; display: inline-flex; }
.notif-badge {
    position: absolute; top: 2px; right: 2px; min-width: 15px; height: 15px; padding: 0 4px;
    background: var(--color-danger); color: #fff; border-radius: 8px;
    font-size: 9.5px; font-weight: 700; line-height: 15px; text-align: center; pointer-events: none;
}
.notif-panel {
    position: absolute; top: calc(100% + 8px); right: 0; width: 360px; max-width: 90vw; z-index: 200;
    background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 10px;
    box-shadow: var(--shadow-lg); overflow: hidden; animation: fadeIn 0.15s ease;
}
.notif-panel-header {
    display: flex; justify-content: space-between; align-items: center; padding: 10px 14px;
    border-bottom: 1px solid var(--color-border); font-size: 13px; font-weight: 600; color: var(--color-text);
}
.notif-markall {
    background: none; border: none; cursor: pointer; font-size: 11.5px; color: var(--color-primary); padding: 0;
}
.notif-markall:hover { text-decoration: underline; }
.notif-list { max-height: 380px; overflow-y: auto; }
.notif-empty { padding: 22px 14px; text-align: center; color: var(--color-text-muted); font-size: 12.5px; }
.notif-item {
    display: flex; gap: 10px; padding: 10px 14px; text-decoration: none;
    border-bottom: 1px solid var(--color-border-subdued); color: var(--color-text);
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--color-surface-hover); }
.notif-item .notif-dot { flex: 0 0 8px; width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: var(--color-border-strong); }
.notif-item.is-success .notif-dot { background: var(--color-success); }
.notif-item.is-error .notif-dot { background: var(--color-danger); }
.notif-item .notif-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.notif-item .notif-msg {
    font-size: 12.5px; line-height: 1.35; word-break: break-word;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.notif-item .notif-time { font-size: 10.5px; color: var(--color-text-muted); }
.notif-item.is-unread { background: var(--color-primary-subdued); }
.notif-item.is-unread .notif-msg { font-weight: 600; }
