/* ============================================================
 * APEXO — Design Tokens
 * Sistema de diseño centralizado. Colores brand vienen del tenant.
 * Estos tokens son universales: typography, spacing, radius, shadows, eases.
 * ============================================================ */

:root {
    /* ============ TYPOGRAPHY ============ */
    --font-display: 'Manrope', system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-body: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

    /* Modular scale ratio 1.250 (major third) — armoniza headings */
    --fs-xs:   0.75rem;   /* 12px */
    --fs-sm:   0.875rem;  /* 14px */
    --fs-base: 1rem;      /* 16px */
    --fs-md:   1.125rem;  /* 18px */
    --fs-lg:   1.25rem;   /* 20px */
    --fs-xl:   1.5rem;    /* 24px */
    --fs-2xl:  1.875rem;  /* 30px */
    --fs-3xl:  2.25rem;   /* 36px */
    --fs-4xl:  3rem;      /* 48px */
    --fs-5xl:  3.75rem;   /* 60px */

    /* Line heights */
    --lh-tight:   1.15;
    --lh-snug:    1.3;
    --lh-normal:  1.55;
    --lh-relaxed: 1.7;

    /* Font weights — Inter/Manrope variable soportan 100-900 */
    --fw-normal:    400;
    --fw-medium:    500;
    --fw-semibold:  600;
    --fw-bold:      700;
    --fw-extrabold: 800;

    /* Letter spacing — display tighter, body normal, eyebrow wider */
    --tracking-tightest: -0.04em;
    --tracking-tight:    -0.02em;
    --tracking-normal:    0;
    --tracking-wide:      0.05em;
    --tracking-wider:     0.08em;
    --tracking-widest:    0.12em;

    /* ============ SPACING (8px base scale) ============ */
    --space-0:   0;
    --space-1:   0.25rem;   /* 4px */
    --space-2:   0.5rem;    /* 8px */
    --space-3:   0.75rem;   /* 12px */
    --space-4:   1rem;      /* 16px */
    --space-5:   1.25rem;   /* 20px */
    --space-6:   1.5rem;    /* 24px */
    --space-8:   2rem;      /* 32px */
    --space-10:  2.5rem;    /* 40px */
    --space-12:  3rem;      /* 48px */
    --space-14:  3.5rem;    /* 56px */
    --space-16:  4rem;      /* 64px */
    --space-20:  5rem;      /* 80px */
    --space-24:  6rem;      /* 96px */
    --space-32:  8rem;      /* 128px */

    /* ============ BORDER RADIUS ============ */
    --radius-xs:   2px;
    --radius-sm:   4px;
    --radius-md:   8px;
    --radius-lg:   12px;
    --radius-xl:   16px;
    --radius-2xl:  24px;
    --radius-3xl:  32px;
    --radius-full: 9999px;

    /* ============ SHADOWS (refined, sutiles) ============ */
    --shadow-xs:  0 1px 2px rgba(15, 23, 42, .04);
    --shadow-sm:  0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px -1px rgba(15, 23, 42, .04);
    --shadow-md:  0 4px 6px -1px rgba(15, 23, 42, .07), 0 2px 4px -2px rgba(15, 23, 42, .04);
    --shadow-lg:  0 10px 15px -3px rgba(15, 23, 42, .08), 0 4px 6px -4px rgba(15, 23, 42, .04);
    --shadow-xl:  0 20px 25px -5px rgba(15, 23, 42, .1), 0 8px 10px -6px rgba(15, 23, 42, .04);
    --shadow-2xl: 0 25px 50px -12px rgba(15, 23, 42, .18);
    --shadow-inset: inset 0 2px 4px 0 rgba(15, 23, 42, .04);

    /* Glow effects para CTAs principales (usa brand color) */
    --glow-brand: 0 0 0 3px rgba(99, 102, 241, .15);

    /* ============ EASINGS ============ */
    --ease-linear:    linear;
    --ease-in:        cubic-bezier(0.4, 0, 1, 1);
    --ease-out:       cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out:    cubic-bezier(0.65, 0, 0.35, 1);
    --ease-bounce:    cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-anticipate: cubic-bezier(0.65, -0.05, 0.35, 1);

    /* ============ DURATIONS ============ */
    --duration-instant: 0s;
    --duration-fast:    0.12s;
    --duration-base:    0.2s;
    --duration-slow:    0.35s;
    --duration-slower:  0.5s;

    /* ============ Z-INDEX SCALE ============ */
    --z-base:      1;
    --z-dropdown:  50;
    --z-sticky:    60;
    --z-fixed:     70;
    --z-overlay:   80;
    --z-modal:     90;
    --z-popover:   100;
    --z-toast:     110;
    --z-tooltip:   120;
}

/* Dark mode overrides — shadows más profundos sobre fondo oscuro */
[data-theme="dark"] {
    --shadow-xs:  0 1px 2px rgba(0, 0, 0, .25);
    --shadow-sm:  0 1px 3px rgba(0, 0, 0, .35), 0 1px 2px -1px rgba(0, 0, 0, .25);
    --shadow-md:  0 4px 6px -1px rgba(0, 0, 0, .4), 0 2px 4px -2px rgba(0, 0, 0, .3);
    --shadow-lg:  0 10px 15px -3px rgba(0, 0, 0, .45), 0 4px 6px -4px rgba(0, 0, 0, .3);
    --shadow-xl:  0 20px 25px -5px rgba(0, 0, 0, .5), 0 8px 10px -6px rgba(0, 0, 0, .35);
    --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, .65);
}
@media (prefers-color-scheme: dark) {
    [data-theme="auto"] {
        --shadow-xs:  0 1px 2px rgba(0, 0, 0, .25);
        --shadow-sm:  0 1px 3px rgba(0, 0, 0, .35), 0 1px 2px -1px rgba(0, 0, 0, .25);
        --shadow-md:  0 4px 6px -1px rgba(0, 0, 0, .4), 0 2px 4px -2px rgba(0, 0, 0, .3);
        --shadow-lg:  0 10px 15px -3px rgba(0, 0, 0, .45), 0 4px 6px -4px rgba(0, 0, 0, .3);
        --shadow-xl:  0 20px 25px -5px rgba(0, 0, 0, .5), 0 8px 10px -6px rgba(0, 0, 0, .35);
        --shadow-2xl: 0 25px 50px -12px rgba(0, 0, 0, .65);
    }
}

/* ============ UTILITY: smooth font rendering ============ */
html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "kern", "liga", "calt", "ss01";
}

/* ============ UTILITY: focus rings accesibles ============ */
:focus-visible {
    outline: 2px solid var(--ac, #6366f1);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ============ UTILITY: scrollbar styling moderado ============ */
* { scrollbar-width: thin; scrollbar-color: rgba(100,116,139,.4) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(100,116,139,.4); border-radius: var(--radius-full); border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(100,116,139,.6); background-clip: padding-box; }

/* ============ UTILITY: selection con brand color ============ */
::selection {
    background: rgba(99, 102, 241, .25);
    color: inherit;
}

/* ============================================================
 * K.3.5: MICRO-INTERACCIONES
 * ============================================================ */

/* Smooth scroll para anchor links (#categorias, etc.) */
html { scroll-behavior: smooth; }

/* Respeta usuarios que prefieren menos movimiento */
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Page fade-in al cargar (sutil) */
@keyframes pageEnter {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}
body > main, body > section, body > .container { animation: pageEnter var(--duration-slow) var(--ease-out); }

/* Link underline animado (overrides default underline en algunos contextos) */
.link-anim {
    position: relative;
    display: inline-block;
    text-decoration: none !important;
}
.link-anim::after {
    content: '';
    position: absolute;
    left: 0; bottom: -2px;
    width: 100%; height: 2px;
    background: currentColor;
    transform: scaleX(0);
    transform-origin: right;
    transition: transform var(--duration-base) var(--ease-out);
}
.link-anim:hover::after {
    transform: scaleX(1);
    transform-origin: left;
}

/* Input focus animado */
input:focus, select:focus, textarea:focus {
    transition: border-color var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
}

/* Toast notifications (positioned top-right) — para usar con JS */
.toast-stack {
    position: fixed;
    top: var(--space-5);
    right: var(--space-5);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    max-width: 380px;
    pointer-events: none;
}
.toast {
    background: #fff;
    border: 1px solid var(--border, rgba(15,23,42,.08));
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-5);
    box-shadow: var(--shadow-xl);
    font-size: var(--fs-sm);
    line-height: var(--lh-snug);
    pointer-events: auto;
    animation: toastIn var(--duration-slow) var(--ease-bounce);
    border-left: 4px solid var(--ac, #6366f1);
}
.toast.success { border-left-color: #10b981; }
.toast.error   { border-left-color: #ef4444; }
.toast.warn    { border-left-color: #f59e0b; }
.toast.exit    { animation: toastOut var(--duration-base) var(--ease-in) forwards; }
@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px) scale(.95); }
    to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastOut {
    to { opacity: 0; transform: translateX(20px) scale(.95); }
}
[data-theme="dark"] .toast { background: #18213a; color: #e2e8f0; border-color: #1e293b; }

/* Scroll snap para galerías horizontales (futuro) */
.scroll-snap-x {
    scroll-snap-type: x mandatory;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.scroll-snap-x > * { scroll-snap-align: start; }

/* Button press ripple sutil */
button:active, .btn:active { transform: translateY(0) scale(.98); }

/* Loading spinner mini (CSS only) */
.spinner {
    display: inline-block;
    width: 1em; height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: var(--radius-full);
    animation: spin .6s linear infinite;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
