/* ============================================
   BricoDiscount — Animations Stylesheet
   ============================================
   Page transitions, toast notifications,
   skeleton loading, hover effects, keyframes.
   ============================================ */

/* ============================================
   Page Fade-In Transition
   ============================================ */
.main-content {
    animation: pageFadeIn 0.2s ease-out;
}

@keyframes pageFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Body animated gradient — matches admin grayWave pattern */
@keyframes darkWave {
    0%   { background-position: 0% 50%; }
    25%  { background-position: 50% 100%; }
    50%  { background-position: 100% 50%; }
    75%  { background-position: 50% 0%; }
    100% { background-position: 0% 50%; }
}

/* Red sections animated gradient — hero, bulk-supply, footer, CTA */
@keyframes redWave {
    0%   { background-position: 0% 50%; }
    25%  { background-position: 50% 100%; }
    50%  { background-position: 100% 50%; }
    75%  { background-position: 50% 0%; }
    100% { background-position: 0% 50%; }
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-width: 400px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.12), 0 2px 8px -2px rgba(0, 0, 0, 0.06);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    animation: toastSlideIn 0.35s var(--transition-spring);
    pointer-events: auto;
    border: 1px solid rgba(0, 0, 0, 0.04);
    line-height: 1.5;
}

.toast--exiting {
    animation: toastSlideOut 0.3s ease forwards;
}

.toast__icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin-top: 1px;
}

.toast__content {
    flex: 1;
    min-width: 0;
}

.toast__close {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    opacity: 0.5;
    cursor: pointer;
    transition: opacity var(--duration-hover) var(--ease-smooth);
    margin-top: 1px;
}

.toast__close:hover {
    opacity: 1;
}

.toast--success {
    background: rgba(212, 237, 218, 0.95);
    color: #155724;
    border-left: 4px solid var(--color-success);
}

.toast--error {
    background: rgba(248, 215, 218, 0.95);
    color: #721c24;
    border-left: 4px solid var(--color-danger);
}

.toast--warning {
    background: rgba(255, 243, 205, 0.95);
    color: #856404;
    border-left: 4px solid var(--color-warning);
}

.toast--info {
    background: rgba(209, 236, 241, 0.95);
    color: #0c5460;
    border-left: 4px solid var(--color-info);
}

@keyframes toastSlideIn {
    from {
        transform: translateX(100%) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
}

@keyframes toastSlideOut {
    from {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
    to {
        transform: translateX(100%) scale(0.95);
        opacity: 0;
    }
}

/* ============================================
   Legacy Flash Messages (backward compat)
   ============================================ */
.flash-messages {
    position: fixed;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-width: 400px;
}

.flash {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    font-weight: var(--font-weight-medium);
    box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.12);
    animation: toastSlideIn 0.35s ease;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.flash-success { background: rgba(212, 237, 218, 0.95); color: #155724; border-left: 4px solid var(--color-success); }
.flash-error { background: rgba(248, 215, 218, 0.95); color: #721c24; border-left: 4px solid var(--color-danger); }
.flash-warning { background: rgba(255, 243, 205, 0.95); color: #856404; border-left: 4px solid var(--color-warning); }
.flash-info { background: rgba(209, 236, 241, 0.95); color: #0c5460; border-left: 4px solid var(--color-info); }

/* ============================================
   Skeleton Loading
   ============================================ */
.skeleton {
    position: relative;
    overflow: hidden;
    background: var(--color-light-gray);
    border-radius: var(--radius-md);
}

.skeleton::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--skeleton-shimmer) 50%,
        transparent 100%
    );
    animation: skeletonShimmer 1.5s infinite;
}

.skeleton--text {
    height: 14px;
    width: 80%;
    margin-bottom: 0.5rem;
}

.skeleton--text-sm {
    height: 10px;
    width: 60%;
    margin-bottom: 0.4rem;
}

.skeleton--title {
    height: 20px;
    width: 50%;
    margin-bottom: 0.75rem;
}

.skeleton--image {
    width: 100%;
    aspect-ratio: 1;
}

.skeleton--circle {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-full);
}

.skeleton--card {
    background: var(--color-surface);
    border: 1px solid var(--color-light-gray);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.skeleton--card .skeleton--image {
    border-radius: 0;
}

.skeleton--card .skeleton__body {
    padding: var(--space-md) var(--space-lg);
}

.skeleton--table-row {
    display: grid;
    grid-template-columns: 40px 2fr 1fr 1fr 80px;
    gap: 1rem;
    padding: 0.75rem 1rem;
    align-items: center;
    border-bottom: 1px solid var(--color-light-gray);
}

.skeleton--table-row .skeleton {
    height: 14px;
}

.skeleton--table-row .skeleton:first-child {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
}

@keyframes skeletonShimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* ============================================
   Hero Entrance — staggered fade-up, runs once
   ============================================ */
@keyframes heroEntrance {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   Sand Drift — GPU-only (transform), 20s
   Subtle gradient drift, zero repaints
   ============================================ */
@keyframes sandDrift {
    0% {
        transform: translate3d(0, 0, 0) scale(1);
    }
    100% {
        transform: translate3d(-4%, 3%, 0) scale(1.04);
    }
}

/* ============================================
   Ambient Blue — GPU-friendly (transform+opacity)
   20s cycle, subtle glow drift on dark blue
   ============================================ */
@keyframes ambientBlue {
    0% {
        opacity: 0.3;
        transform: translateZ(0) translate(0, 0) scale(1);
    }
    100% {
        opacity: 0.6;
        transform: translateZ(0) translate(-1.5%, 1%) scale(1.03);
    }
}

/* ============================================
   Hero Ambient — gold glow drift, 20s
   ============================================ */
@keyframes heroAmbient {
    0% {
        opacity: 0.4;
        transform: translateZ(0) translate(0, 0) scale(1);
    }
    100% {
        opacity: 0.75;
        transform: translateZ(0) translate(1.5%, -1%) scale(1.03);
    }
}

/* ============================================
   Scroll-triggered Reveal System
   ============================================
   - 0.4s duration
   - cubic-bezier(0.16, 1, 0.3, 1) easing
   - Stagger via --reveal-delay (set by JS)
   ============================================ */
.reveal-on-scroll {
    opacity: 0;
    transform: translateY(20px);
    transition:
        opacity var(--duration-reveal) var(--ease-smooth),
        transform var(--duration-reveal) var(--ease-smooth);
    transition-delay: var(--reveal-delay, 0s);
}

.reveal-on-scroll.is-revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger children: cards, grid items */
.reveal-children > * {
    opacity: 0;
    transform: translateY(20px);
    transition:
        opacity var(--duration-reveal) var(--ease-smooth),
        transform var(--duration-reveal) var(--ease-smooth);
    transition-delay: var(--child-delay, 0s);
}

.reveal-children.is-revealed > * {
    opacity: 1;
    transform: translateY(0);
}

/* Legacy compat */
.fade-in-up {
    opacity: 0;
    transform: translateY(20px);
    transition:
        opacity var(--duration-reveal) var(--ease-smooth),
        transform var(--duration-reveal) var(--ease-smooth);
    transition-delay: var(--reveal-delay, 0s);
}

.fade-in-up.is-visible,
.fade-in-up.is-revealed {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================
   Pulse Animation (badges, notifications)
   ============================================ */
.pulse {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* ============================================
   Spinner (loading indicator)
   ============================================ */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-light-gray);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.spinner--sm {
    width: 14px;
    height: 14px;
    border-width: 1.5px;
}

.spinner--lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Responsive Toast
   ============================================ */
@media (max-width: 480px) {
    .toast-container,
    .flash-messages {
        right: var(--space-md);
        left: var(--space-md);
        max-width: none;
    }
}

/* ============================================
   Accessibility: Reduced Motion
   ============================================
   Respects user OS preference.
   Disables transforms, stagger delays, and
   non-essential keyframe animations.
   Keeps opacity fades (instant) for context.
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    /* Universal motion kill — !important is unavoidable here:
       specificity (0,0,0) cannot override any class-based rule
       by cascade alone. This is the standard a11y pattern
       (W3C, MDN, Bootstrap, Tailwind all use this). */
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        transition-delay: 0s !important;
        scroll-behavior: auto !important;
    }

    /* Reveal elements: show content immediately.
       Same specificity (0,1,0) as base rules; cascade wins
       because animations.css loads after layout.css. */
    .reveal-on-scroll,
    .reveal-children > *,
    .fade-in-up,
    .hero__badge,
    .hero__title,
    .hero__title .char,
    .hero__subtitle,
    .hero__actions,
    .hero__stats {
        opacity: 1;
        transform: none;
    }

    /* Ambient overlays: hide (their opacity comes from
       animation which is now killed by * above). */
    .hero__overlay,
    .departments::after,
    .featured-products::after,
    .bulk-supply::after,
    .why-choose::after,
    .cta-banner::after,
    .footer__main::after {
        opacity: 0;
    }

    /* Interactive hover/active states: remove transforms.
       Targets :hover/:active explicitly so specificity (0,1,1)
       matches .btn--primary:hover etc. Cascade wins. */
    .btn:hover,
    .btn:active,
    .dept-card:hover,
    .product-card:hover,
    .trust-card:hover,
    .bulk-stat:hover,
    .contact-info-card:hover,
    .footer__social-link:hover,
    .footer__social-link:active,
    .header__action-btn:hover,
    .header__action-btn:active {
        transform: none;
    }

    /* Functional spinners: exempt from motion kill */
    .btn-loading::after,
    .btn.is-loading::after {
        animation: btnSpin 0.55s linear infinite;
    }

    .spinner {
        animation: spin 0.6s linear infinite;
    }
}
