/* ════════════════════════════════════════════════════════════════════════
   MATRIX V83 — Global Immersive FX Layer (FAXIL·POS)
   Site-wide visual upgrade: parallax mesh + particles + tilt + magnetic +
   neon active states + grain noise + page transitions.
   • Pure CSS / Canvas — no Three.js, no deps, ~7 KB.
   • Decorative only: pointer-events:none on FX layers; never blocks UI.
   • Honors prefers-reduced-motion + body[data-fx-disable] escape hatch.
═════════════════════════════════════════════════════════════════════════ */

/* ── Decorative root that never blocks interaction ──────────────────────── */
.fxl-fx-root {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
    contain: strict;
}
body[data-fx-disable="1"] .fxl-fx-root,
body[data-fx-loaded="0"] .fxl-fx-root { display: none !important; }

/* ── Mesh blob backdrop (subtle on admin pages) ─────────────────────────── */
.fxl-fx-mesh {
    position: absolute; inset: 0;
}
.fxl-fx-blob {
    position: absolute;
    width: 38vmax; height: 38vmax;
    border-radius: 50%;
    filter: blur(110px);
    opacity: 0.18;
    will-change: transform;
}
.fxl-fx-blob--1 { background: radial-gradient(circle, #6366f1, transparent 60%); top: -12vmax; left: -12vmax;
                  animation: fxlFxBlob1 26s ease-in-out infinite; }
.fxl-fx-blob--2 { background: radial-gradient(circle, #ec4899, transparent 60%); top: 30vh; right: -16vmax;
                  animation: fxlFxBlob2 32s ease-in-out infinite; }
.fxl-fx-blob--3 { background: radial-gradient(circle, #10b981, transparent 60%); bottom: -14vmax; left: 30vw;
                  animation: fxlFxBlob3 38s ease-in-out infinite; }
@keyframes fxlFxBlob1 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(8vw, 6vh); } }
@keyframes fxlFxBlob2 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(-7vw, 9vh); } }
@keyframes fxlFxBlob3 { 0%,100% { transform: translate(0,0); } 50% { transform: translate(5vw, -8vh); } }

/* ── Canvas particle layer (low density on admin) ───────────────────────── */
.fxl-fx-particles {
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
    opacity: 0.42;
    mix-blend-mode: screen;
}

/* ── Grainy noise overlay — premium analog look ─────────────────────────── */
.fxl-fx-grain {
    position: absolute; inset: 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.92' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.04 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    mix-blend-mode: overlay;
    opacity: 0.55;
}

/* ── Custom cursor (opt-in via body class .fxl-fx-cursor) ───────────────── */
body.fxl-fx-cursor #fxl-fx-cursor-dot {
    position: fixed; top: 0; left: 0;
    width: 8px; height: 8px;
    background: radial-gradient(circle, #fff, rgba(255,255,255,.2) 70%, transparent);
    border-radius: 50%;
    pointer-events: none;
    z-index: 999999;
    transform: translate(-50%, -50%);
    mix-blend-mode: difference;
    transition: width .12s, height .12s;
    will-change: transform;
}
body.fxl-fx-cursor #fxl-fx-cursor-halo {
    position: fixed; top: 0; left: 0;
    width: 36px; height: 36px;
    border: 1.5px solid rgba(99,102,241,0.45);
    border-radius: 50%;
    pointer-events: none;
    z-index: 999998;
    transform: translate(-50%, -50%);
    transition: transform .14s ease, width .14s, height .14s, border-color .14s;
    will-change: transform;
}
body.fxl-fx-cursor.fxl-fx-cursor-active #fxl-fx-cursor-halo { width: 60px; height: 60px; border-color: #ec4899; }

/* ── Auto-decorate generic UPOS components ──────────────────────────────── */
/* Bento-style hover lift on .box / .info-box / .small-box */
body[data-fx-loaded="1"] .box,
body[data-fx-loaded="1"] .info-box,
body[data-fx-loaded="1"] .small-box {
    transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s, border-color .25s;
    will-change: transform;
}
body[data-fx-loaded="1"] .box:hover,
body[data-fx-loaded="1"] .info-box:hover,
body[data-fx-loaded="1"] .small-box:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px -10px rgba(99,102,241,.35), 0 0 0 1px rgba(99,102,241,.08);
}

/* Neon active glow on primary buttons in admin pages */
body[data-fx-loaded="1"] .btn-primary,
body[data-fx-loaded="1"] .btn-success,
body[data-fx-loaded="1"] .tw-dw-btn {
    position: relative;
    transition: transform .15s, box-shadow .25s, filter .25s;
    will-change: transform;
}
body[data-fx-loaded="1"] .btn-primary:hover,
body[data-fx-loaded="1"] .btn-success:hover {
    box-shadow: 0 6px 20px -4px currentColor, 0 0 0 1px rgba(255,255,255,.08) inset;
    filter: brightness(1.06);
}
body[data-fx-loaded="1"] .btn-primary:active,
body[data-fx-loaded="1"] .btn-success:active { transform: scale(.97); }

/* Loading state for buttons (used by JS) */
.fxl-fx-loading {
    position: relative;
    pointer-events: none;
    color: transparent !important;
}
.fxl-fx-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    margin: auto;
    width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: fxlFxSpin .65s linear infinite;
}
@keyframes fxlFxSpin { to { transform: rotate(360deg); } }

/* Animated diagonal shine on .box hover */
body[data-fx-loaded="1"] .box {
    position: relative; overflow: hidden;
}
body[data-fx-loaded="1"] .box::after {
    content: '';
    position: absolute; top: -50%; left: -100%;
    width: 80%; height: 200%;
    background: linear-gradient(115deg, transparent 30%, rgba(255,255,255,.10) 50%, transparent 70%);
    transform: rotate(15deg);
    transition: left .65s ease;
    pointer-events: none;
    z-index: 1;
}
body[data-fx-loaded="1"] .box:hover::after { left: 130%; }

/* ── NIVEL floating button (V83 — task #4) ──────────────────────────────── */
.fxl-fab-nivel {
    position: fixed;
    right: 20px; bottom: 20px;
    z-index: 9999;
    width: 56px; height: 56px;
    display: grid; place-items: center;
    border-radius: 50%;
    border: none;
    color: #fff;
    background: linear-gradient(135deg, #6366f1, #ec4899);
    box-shadow: 0 8px 24px -4px rgba(99,102,241,.55), 0 0 0 0 rgba(236,72,153,.4);
    cursor: pointer;
    font-size: 20px;
    transition: transform .2s cubic-bezier(.2,.8,.2,1), box-shadow .25s;
    animation: fxlNivelHalo 2.6s ease-in-out infinite;
}
@keyframes fxlNivelHalo {
    0%,100% { box-shadow: 0 8px 24px -4px rgba(99,102,241,.55), 0 0 0 0 rgba(236,72,153,.4); }
    50%     { box-shadow: 0 12px 28px -4px rgba(99,102,241,.65), 0 0 0 12px rgba(236,72,153,0); }
}
.fxl-fab-nivel:hover { transform: translateY(-3px) scale(1.05); }
.fxl-fab-nivel:active { transform: scale(.94); }

.fxl-fab-nivel-tooltip {
    position: fixed;
    right: 88px; bottom: 24px;
    z-index: 9998;
    background: rgba(15,23,42,.96);
    color: #f1f5f9;
    padding: 14px 18px;
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,.1);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 18px 36px -10px rgba(0,0,0,.45);
    min-width: 220px; max-width: 320px;
    font-size: 12.5px;
    line-height: 1.45;
    opacity: 0; transform: translateX(8px) scale(.96);
    pointer-events: none;
    transition: opacity .18s ease, transform .18s cubic-bezier(.2,.8,.2,1);
}
.fxl-fab-nivel-tooltip[data-show="1"] {
    opacity: 1; transform: translateX(0) scale(1);
    pointer-events: auto;
}
.fxl-fab-nivel-tooltip h4 {
    margin: 0 0 6px; font-size: 13px; font-weight: 800;
    color: #fff; display: flex; align-items: center; gap: 8px;
}
.fxl-fab-nivel-tooltip ul { list-style: none; margin: 0; padding: 0; }
.fxl-fab-nivel-tooltip li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-top: 1px dashed rgba(255,255,255,.08); }
.fxl-fab-nivel-tooltip li:first-child { border-top: 0; }
.fxl-fab-nivel-tooltip li span:first-child { color: #94a3b8; }
.fxl-fab-nivel-tooltip li span:last-child { color: #fff; font-weight: 600; }
.fxl-fab-nivel-tooltip::before {
    content: '';
    position: absolute; right: -8px; bottom: 22px;
    width: 16px; height: 16px;
    background: rgba(15,23,42,.96);
    transform: rotate(45deg);
    border-right: 1px solid rgba(255,255,255,.1);
    border-top: 1px solid rgba(255,255,255,.1);
    border-radius: 2px;
}

/* Hide the FAB on POS / customer-display routes (set by middleware) */
body[data-fxl-no-nivel="1"] .fxl-fab-nivel,
body[data-fxl-no-nivel="1"] .fxl-fab-nivel-tooltip { display: none !important; }

/* ── Reduced motion ─────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .fxl-fx-blob,
    .fxl-fab-nivel { animation: none !important; }
    .fxl-fx-particles { display: none !important; }
    body[data-fx-loaded="1"] .box,
    body[data-fx-loaded="1"] .btn-primary,
    body[data-fx-loaded="1"] .btn-success,
    body[data-fx-loaded="1"] .tw-dw-btn { transition: none !important; }
}
