/* ───────────────────────────────────────────────────────────────────
   Base de temas — paleta violeta + tipografía. Cada tema concreto
   sobrescribe variables específicas (--surface, --shadow, --radius).
   ─────────────────────────────────────────────────────────────────── */

/* Tipografía auto-hosteada (fonts-local.css): Space Grotesk (títulos) + Plus Jakarta Sans (cuerpo). */

:root {
    /* Tipografía */
    --font-display: 'Space Grotesk', 'Plus Jakarta Sans', system-ui, sans-serif;
    --font-body: 'Plus Jakarta Sans', 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;

    /* Paleta violeta — saturación 'vivid' por defecto */
    --violet-50:  #faf5ff;
    --violet-100: #f3e8ff;
    --violet-200: #e9d5ff;
    --violet-300: #d8b4fe;
    --violet-400: #c084fc;
    --violet-500: #a855f7;
    --violet-600: #9333ea;
    --violet-700: #7e22ce;
    --violet-800: #6b21a8;
    --violet-900: #581c87;
    --violet-950: #3b0764;

    /* Indigo-violet noche para dark backgrounds */
    --night-900: #0a0118;
    --night-800: #1e1b4b;
    --night-700: #312e81;

    /* Acento global por defecto */
    --accent: var(--violet-500);
    --accent-strong: var(--violet-600);
    --accent-soft: var(--violet-200);
    --accent-glow: rgba(168, 85, 247, 0.4);

    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
}

/* ────────────────────────────────────────────────────────────────────
   FIX UNIVERSAL: sincronizar --content-bg con --bg-solid del tema activo.
   El critical CSS de base.html aplica `html, body { background: var(--content-bg) }`,
   pero los variants dark/light solo redefinían --bg sin --content-bg, lo que
   dejaba bg "stuck" en el modo default del tema. Esta regla fuerza que
   cualquier override de --bg-solid también afecte content-bg.
   Specificity (0,1,1) gana al :root del critical CSS (0,1,0).
   ──────────────────────────────────────────────────────────────────── */
html[data-theme-style][data-theme] {
    --content-bg: var(--bg-solid) !important;
    --content-text: var(--text) !important;
}
html[data-theme-style] body {
    background: var(--bg, var(--bg-solid)) !important;
    color: var(--text) !important;
}

/* ────────────────────────────────────────────────────────────────────
   PERF — promueve los ::before figurativos a su propia layer GPU para
   que el repaint del body (e.g. al hx-boost swap) no recalcule el SVG.
   Respeta prefers-reduced-motion: pausa animaciones costosas.
   ──────────────────────────────────────────────────────────────────── */
html[data-theme-style] body::before,
html[data-theme-style] body::after {
    will-change: opacity;
    /* No forzar transform aquí: synthwave y otros usan transform propio
       (perspective rotateX para grilla horizonte). will-change ya promueve
       a layer GPU sin necesidad de translateZ. contain:paint removido
       porque recortaba decoraciones que exceden el bbox (ej. sol retro). */
}

@media (prefers-reduced-motion: reduce) {
    html[data-theme-style] *,
    html[data-theme-style] *::before,
    html[data-theme-style] *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Toggle global ya manejado por html.no-anim en base.html */

/* ────────────────────────────────────────────────────────────────────
   KPI/Quick actions theme-aware overrides:
   .kpi-* y .qa-* (tailwind-components.css) usan colors hardcoded
   (#059669, #0284c7, etc.) que en dark mode sobre bg oscuro pierden
   contraste. Aquí se ajustan iconos + textos accent para light/dark.
   El border y bg accent rgba se mantienen pero se boost en dark.
   ──────────────────────────────────────────────────────────────────── */

/* KPI cards: en cualquier dark, iconos más luminosos */
html[data-theme-style][data-theme="dark"] .kpi-emerald .kpi-icon { background: rgba(16,185,129,0.22); color: #6ee7b7; }
html[data-theme-style][data-theme="dark"] .kpi-indigo  .kpi-icon { background: rgba(99,102,241,0.22);  color: #a5b4fc; }
html[data-theme-style][data-theme="dark"] .kpi-amber   .kpi-icon { background: rgba(245,158,11,0.22);  color: #fcd34d; }
html[data-theme-style][data-theme="dark"] .kpi-sky     .kpi-icon { background: rgba(14,165,233,0.22);  color: #7dd3fc; }
html[data-theme-style][data-theme="dark"] .kpi-orange  .kpi-icon { background: rgba(249,115,22,0.22);  color: #fdba74; }
html[data-theme-style][data-theme="dark"] .kpi-violet  .kpi-icon { background: rgba(139,92,246,0.22);  color: #c4b5fd; }
html[data-theme-style][data-theme="dark"] .kpi-rose    .kpi-icon { background: rgba(244,63,94,0.22);   color: #fda4af; }

/* Quick Action buttons: ajustar fondo + texto en dark para visibilidad */
html[data-theme-style][data-theme="dark"] .qa-emerald { background: rgba(16,185,129,0.16);  color: #6ee7b7; border-color: rgba(16,185,129,0.35); }
html[data-theme-style][data-theme="dark"] .qa-emerald:hover { background: rgba(16,185,129,0.26); color: #a7f3d0; border-color: #10b981; }
html[data-theme-style][data-theme="dark"] .qa-orange  { background: rgba(249,115,22,0.16);  color: #fdba74; border-color: rgba(249,115,22,0.35); }
html[data-theme-style][data-theme="dark"] .qa-orange:hover { background: rgba(249,115,22,0.26); color: #fed7aa; border-color: #f97316; }
html[data-theme-style][data-theme="dark"] .qa-sky     { background: rgba(14,165,233,0.16);  color: #7dd3fc; border-color: rgba(14,165,233,0.35); }
html[data-theme-style][data-theme="dark"] .qa-sky:hover { background: rgba(14,165,233,0.26); color: #bae6fd; border-color: #0ea5e9; }
html[data-theme-style][data-theme="dark"] .qa-violet  { background: rgba(139,92,246,0.18);  color: #c4b5fd; border-color: rgba(139,92,246,0.4); }
html[data-theme-style][data-theme="dark"] .qa-violet:hover { background: rgba(139,92,246,0.28); color: #ddd6fe; border-color: #8b5cf6; }

/* ───────────────────────────────────────────────────────────────────
   GLASSMORPHISM — fondos blur + transparencias + gradientes violeta.
   Dark por defecto. Light alternativo.
   ─────────────────────────────────────────────────────────────────── */


[data-theme-style="glass"] {
    --font-display: 'Space Grotesk', 'Cabinet Grotesk', system-ui, sans-serif;
    --bg: radial-gradient(ellipse at top left, #1e1b4b 0%, #0a0118 50%, #000 100%);
    --bg-solid: #0a0118;
    --surface: rgba(30, 27, 75, 0.5);
    /* Superficie casi opaca para popovers/dropdowns flotantes (notificaciones,
       selectores): con --surface translúcido el contenido de la página se ve a
       través y no se puede leer. --surface-strong los hace legibles sin perder
       el tinte glass. */
    --surface-strong: rgba(26, 22, 64, 0.97);
    --sidebar-bg: linear-gradient(180deg, rgba(30, 27, 75, 0.95) 0%, rgba(10, 1, 24, 0.98) 100%);
    --sidebar-border: rgba(168, 85, 247, 0.25);
    --sidebar-text: #c4b5fd;
    --surface-hover: rgba(88, 28, 135, 0.4);
    --surface-glass: rgba(255, 255, 255, 0.04);
    --border: rgba(168, 85, 247, 0.2);
    --border-strong: rgba(168, 85, 247, 0.4);
    --text: #f5f3ff;
    --text-muted: #c4b5fd;
    --text-dim: #a78bfa;
    --content-bg: transparent;
    --content-text: var(--text);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(124, 58, 237, 0.2);
    --shadow-lg: 0 20px 50px rgba(124, 58, 237, 0.35);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 24px;
    --blur: blur(20px) saturate(180%);
}

[data-theme-style="glass"][data-theme="light"] {
    --bg: radial-gradient(ellipse at top, #f3e8ff 0%, #e9d5ff 50%, #faf5ff 100%);
    --bg-solid: #faf5ff;
    --surface: rgba(255, 255, 255, 0.75);
    --surface-strong: rgba(255, 255, 255, 0.98);
    --surface-hover: rgba(243, 232, 255, 0.9);
    --surface-glass: rgba(255, 255, 255, 0.85);
    --sidebar-bg: linear-gradient(180deg, rgba(76, 29, 149, 0.95), rgba(30, 27, 75, 0.98));
    --sidebar-border: rgba(168, 85, 247, 0.4);
    --sidebar-text: #ddd6fe;
    --border: rgba(124, 58, 237, 0.18);
    --border-strong: rgba(124, 58, 237, 0.4);
    --text: #1e1b4b;
    --text-muted: #5b21b6;
    --text-dim: #7e22ce;
    --content-bg: transparent;
    --shadow-md: 0 8px 24px rgba(124, 58, 237, 0.12);
}

/* ───────────────────────────────────────────────────────────────────
   SÓLIDO — estilo plano y sobrio (sin glass/blur/orbes), superficies
   opacas. Alternativa profesional al glass; mismo acento violeta.
   ─────────────────────────────────────────────────────────────────── */
[data-theme-style="solid"] {
    --font-display: 'Space Grotesk', 'Inter', system-ui, sans-serif;
    --bg: #0f1117;
    --bg-solid: #0f1117;
    --surface: #181b23;
    --sidebar-bg: #141720;
    --sidebar-border: rgba(255,255,255,0.07);
    --sidebar-text: #c8ccd6;
    --surface-hover: #20242e;
    --surface-glass: #181b23;
    --border: rgba(255,255,255,0.09);
    --border-strong: rgba(255,255,255,0.18);
    --text: #eef0f4;
    --text-muted: #9aa1ad;
    --text-dim: #6b7280;
    --content-bg: #0f1117;
    --content-text: var(--text);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.45);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --blur: none;
}
[data-theme-style="solid"][data-theme="light"] {
    --bg: #f6f7f9;
    --bg-solid: #f6f7f9;
    --surface: #ffffff;
    --surface-hover: #eef0f3;
    --surface-glass: #ffffff;
    --sidebar-bg: #ffffff;
    --sidebar-border: rgba(15,23,42,0.08);
    --sidebar-text: #475569;
    --border: rgba(15,23,42,0.10);
    --border-strong: rgba(15,23,42,0.20);
    --text: #0f172a;
    --text-muted: #64748b;
    --text-dim: #94a3b8;
    --content-bg: #f6f7f9;
    --shadow-md: 0 4px 12px rgba(15,23,42,0.08);
}
[data-theme-style="solid"] body,
[data-theme-style="solid"] html {
    background: var(--bg-solid);
    color: var(--text);
}
/* Sólido: sin las decoraciones flotantes del body que usa glass. */
[data-theme-style="solid"] body::before,
[data-theme-style="solid"] body::after { content: none !important; display: none !important; }

[data-theme-style="glass"] body,
[data-theme-style="glass"] html {
    background: var(--bg);
    /* background-attachment: fixed eliminado por perf */
    color: var(--text);
    position: relative;
}
/* Orbes flotantes + topología burbujas SVG */
[data-theme-style="glass"] body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(circle at 15% 25%, rgba(168, 85, 247, 0.28) 0%, transparent 35%),
        radial-gradient(circle at 85% 75%, rgba(34, 211, 238, 0.20) 0%, transparent 40%),
        radial-gradient(circle at 55% 50%, rgba(244, 114, 182, 0.14) 0%, transparent 45%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'%3E%3Cg fill='none' stroke='%23a855f7' stroke-opacity='0.06'%3E%3Ccircle cx='30' cy='30' r='20'/%3E%3Ccircle cx='150' cy='80' r='35'/%3E%3Ccircle cx='80' cy='160' r='25'/%3E%3Ccircle cx='170' cy='170' r='15'/%3E%3C/g%3E%3C/svg%3E");
    background-size: cover, cover, cover, 200px 200px;
    animation: glass-orbs 24s ease-in-out infinite alternate;
}
@keyframes glass-orbs {
    0%   { transform: translate(0, 0) scale(1); }
    50%  { transform: translate(-3%, 2%) scale(1.05); }
    100% { transform: translate(2%, -2%) scale(1.02); }
}
[data-theme-style="glass"] .app-shell, [data-theme-style="glass"] main { position: relative; z-index: 1; }
/* Light: orbes más saturados sobre bg claro */
[data-theme-style="glass"][data-theme="light"] body::before {
    background:
        radial-gradient(circle at 15% 25%, rgba(168, 85, 247, 0.18) 0%, transparent 35%),
        radial-gradient(circle at 85% 75%, rgba(244, 114, 182, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 55% 50%, rgba(34, 211, 238, 0.10) 0%, transparent 45%),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 200 200'%3E%3Cg fill='none' stroke='%237c3aed' stroke-opacity='0.14'%3E%3Ccircle cx='30' cy='30' r='20'/%3E%3Ccircle cx='150' cy='80' r='35'/%3E%3Ccircle cx='80' cy='160' r='25'/%3E%3Ccircle cx='170' cy='170' r='15'/%3E%3C/g%3E%3C/svg%3E");
    background-size: cover, cover, cover, 200px 200px;
}

[data-theme-style="glass"] .card,
[data-theme-style="glass"] .card-3d,
[data-theme-style="glass"] .modal-box {
    background: var(--surface);
    backdrop-filter: var(--blur);
    -webkit-backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

[data-theme-style="glass"] .card-header {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.15) 0%, transparent 100%);
    border-bottom: 1px solid var(--border);
}

[data-theme-style="glass"] .btn-primary,
[data-theme-style="glass"] button.btn-primary {
    background: linear-gradient(135deg, var(--violet-500) 0%, var(--violet-700) 100%);
    color: #fff;
    border: 1px solid var(--violet-400);
    box-shadow: 0 4px 14px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}
[data-theme-style="glass"] .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 24px var(--accent-glow), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

[data-theme-style="glass"] .btn-secondary {
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-strong);
    color: var(--text);
    border-radius: var(--radius-sm);
}
[data-theme-style="glass"] .btn-secondary:hover {
    background: rgba(168, 85, 247, 0.12);
    border-color: var(--accent);
}

[data-theme-style="glass"] .btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border: 1px solid #34d399;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}

[data-theme-style="glass"] .btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
    border: 1px solid #f87171;
    box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
}

[data-theme-style="glass"] .form-input,
[data-theme-style="glass"] .form-control,
[data-theme-style="glass"] input,
[data-theme-style="glass"] select,
[data-theme-style="glass"] textarea {
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}
[data-theme-style="glass"] input:focus,
[data-theme-style="glass"] select:focus,
[data-theme-style="glass"] textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

[data-theme-style="glass"] .badge {
    background: var(--surface-glass);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
}
[data-theme-style="glass"] .badge-primary { background: rgba(168, 85, 247, 0.2); color: var(--violet-300); border-color: var(--violet-500); }
[data-theme-style="glass"] .badge-success { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; border-color: #10b981; }
[data-theme-style="glass"] .badge-danger  { background: rgba(239, 68, 68, 0.15);  color: #fca5a5; border-color: #ef4444; }
[data-theme-style="glass"] .badge-warning { background: rgba(245, 158, 11, 0.15); color: #fcd34d; border-color: #f59e0b; }
[data-theme-style="glass"] .badge-info    { background: rgba(59, 130, 246, 0.15); color: #93c5fd; border-color: #3b82f6; }

/* Sidebar nav glass */
[data-theme-style="glass"] aside,
[data-theme-style="glass"] #main-sidebar {
    background: linear-gradient(180deg, #1e1b4b 0%, #0a0118 100%);
    backdrop-filter: none;
    border-right: 1px solid var(--border);
}
[data-theme-style="glass"] .sidebar-link,
[data-theme-style="glass"] .sidebar-sub-item {
    color: var(--sidebar-text);
    border-radius: var(--radius-sm);
    transition: all 0.15s;
}
[data-theme-style="glass"] .sidebar-link:hover,
[data-theme-style="glass"] .sidebar-sub-item:hover {
    background: rgba(168, 85, 247, 0.18);
    color: #fff;
}
[data-theme-style="glass"] .sidebar-link.active,
[data-theme-style="glass"] .sidebar-sub-item.active {
    background: linear-gradient(90deg, rgba(168, 85, 247, 0.3) 0%, rgba(168, 85, 247, 0.05) 100%);
    color: #fff;
    border-left: 2px solid var(--accent);
}

/* Tablas glass */
[data-theme-style="glass"] .table-modern,
[data-theme-style="glass"] table {
    background: transparent;
    color: var(--text);
}
[data-theme-style="glass"] .table-modern thead,
[data-theme-style="glass"] table thead {
    background: rgba(168, 85, 247, 0.1);
}
[data-theme-style="glass"] .table-modern thead th {
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}
[data-theme-style="glass"] .table-modern tbody tr {
    border-bottom: 1px solid var(--border);
}
[data-theme-style="glass"] .table-modern tbody tr:hover {
    background: rgba(168, 85, 247, 0.08);
}

/* Page header con efecto glow */
[data-theme-style="glass"] .page-header-3d {
    background: var(--surface);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}
[data-theme-style="glass"] .page-header-3d .title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    color: var(--text);
}
/* Títulos del panel en la fuente display (Space Grotesk) — ambos estilos. */
html[data-theme-style] h1,
html[data-theme-style] h2,
html[data-theme-style] h3,
html[data-theme-style] h4,
html[data-theme-style] .page-title,
html[data-theme-style] .page-header-3d .title {
    font-family: var(--font-display);
    letter-spacing: -0.01em;
}
[data-theme-style="glass"] .page-header-3d .icon {
    background: linear-gradient(135deg, var(--violet-500), var(--violet-700));
    color: #fff;
    box-shadow: 0 4px 14px var(--accent-glow);
}

/* Modal */
[data-theme-style="glass"] .modal-overlay {
    background: rgba(10, 1, 24, 0.7);
    backdrop-filter: blur(12px);
}
[data-theme-style="glass"] .modal-box {
    background: var(--surface);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-lg);
}

/* Empty state */
[data-theme-style="glass"] .empty-state-3d {
    color: var(--text-muted);
}
[data-theme-style="glass"] .empty-state-3d .icon { color: var(--violet-400); opacity: 0.5; }

/* Mn banner */
[data-theme-style="glass"] .mn-banner {
    background: var(--surface);
    backdrop-filter: var(--blur);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* Floating glow effect on cards hover */
[data-theme-style="glass"] .card:hover,
[data-theme-style="glass"] .card-3d:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(168, 85, 247, 0.35), 0 0 0 1px var(--border-strong);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
[data-theme-style="glass"] .btn-primary { letter-spacing: 0.01em; }
[data-theme-style="glass"] .btn-primary::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent);
    pointer-events: none;
}
[data-theme-style="glass"] .btn-primary { position: relative; overflow: hidden; }

/* Scrollbar violeta */
[data-theme-style="glass"] ::-webkit-scrollbar { width: 8px; height: 8px; }
[data-theme-style="glass"] ::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--violet-500), var(--violet-700));
    border-radius: 999px;
}
[data-theme-style="glass"] ::-webkit-scrollbar-track { background: rgba(168, 85, 247, 0.05); }
