/* ==========================================================================
   Wishy AAA UI/UX Polish
   Kole Jain Principles: Visual Hierarchy, 8px Grid, Affordance,
   Consistency, Micro-Interactions
   ========================================================================== */

/* ==========================================================================
   1. EIGHT-PIXEL GRID SPACING TOKENS
   All spacing derives from multiples of 4/8px for mathematical harmony.
   Use via Tailwind's spacing scale (already 4px-based) or these tokens
   for custom components.
   ========================================================================== */

:root {
    --space-0: 0px;
    --space-px: 1px;
    --space-0-5: 2px;
    --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;
    --space-16: 64px;
    --space-20: 80px;
    --space-24: 96px;
}

/* ==========================================================================
   2. VISUAL HIERARCHY — Focus Ring System
   Consistent, accessible focus indicators using primary color.
   ========================================================================== */

/* Universal focus-visible ring — overrides inconsistent browser defaults */
*:focus-visible {
    outline: 2px solid rgb(var(--primary-500));
    outline-offset: 2px;
    border-radius: inherit;
}

/* Suppress outline for mouse clicks — only show on keyboard */
*:focus:not(:focus-visible) {
    outline: none;
}

/* Specific focus ring for inputs (inset style like Tailwind ring-inset) */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgb(var(--primary-500) / 0.3);
    border-color: rgb(var(--primary-500));
}

/* ==========================================================================
   3. AFFORDANCE — Button Press Feedback (Active States)
   Buttons must feel "pressable" — subtle scale-down + shadow reduction.
   ========================================================================== */

/* Primary CTA and all anchor-buttons with bg-primary */
[class*="bg-primary"]:not(div):not(span):active,
button:active,
a[class*="rounded"]:active {
    transform: scale(0.97);
    transition: transform 80ms ease-out;
}

/* Ghost / outline buttons — tighter press */
button[class*="border"]:active,
a[class*="border"]:active {
    transform: scale(0.98);
}

/* Cards and interactive card-links: subtle press */
.wishlist-card:active,
a[class*="rounded-2xl"]:active {
    transform: scale(0.985);
    transition: transform 100ms ease-out;
}

/* ==========================================================================
   4. MICRO-INTERACTIONS — Stagger Reveal on Scroll
   Children of `.stagger-reveal` fade+slide in when scrolled into view.
   Triggered by IntersectionObserver in aaa-polish.js.
   ========================================================================== */

/* Before reveal: hidden state */
.stagger-reveal > * {
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.4s cubic-bezier(0.2, 0.8, 0.2, 1),
                transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Stagger delays for up to 12 children */
.stagger-reveal > *:nth-child(1)  { transition-delay: 0s; }
.stagger-reveal > *:nth-child(2)  { transition-delay: 0.05s; }
.stagger-reveal > *:nth-child(3)  { transition-delay: 0.1s; }
.stagger-reveal > *:nth-child(4)  { transition-delay: 0.15s; }
.stagger-reveal > *:nth-child(5)  { transition-delay: 0.2s; }
.stagger-reveal > *:nth-child(6)  { transition-delay: 0.25s; }
.stagger-reveal > *:nth-child(7)  { transition-delay: 0.3s; }
.stagger-reveal > *:nth-child(8)  { transition-delay: 0.35s; }
.stagger-reveal > *:nth-child(9)  { transition-delay: 0.4s; }
.stagger-reveal > *:nth-child(10) { transition-delay: 0.45s; }
.stagger-reveal > *:nth-child(11) { transition-delay: 0.5s; }
.stagger-reveal > *:nth-child(12) { transition-delay: 0.55s; }

/* Revealed state (class added by IntersectionObserver) */
.stagger-reveal.revealed > * {
    opacity: 1;
    transform: translateY(0);
}

/* ==========================================================================
   5. MICRO-INTERACTIONS — Notification Badge Pulse
   ========================================================================== */

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

#nav-notification-badge:not(.hidden),
#mobile-notification-badge:not(.hidden) {
    animation: badgePulse 2s cubic-bezier(0.4, 0, 0.6, 1) 3;
}

/* ==========================================================================
   6. MICRO-INTERACTIONS — Sidebar Active Indicator
   Animated left-edge bar on the active nav item.
   ========================================================================== */

.nav-item {
    position: relative;
}

.nav-item-active::before {
    content: '';
    position: absolute;
    left: -4px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    border-radius: 9999px;
    background: rgb(var(--primary-500));
    animation: indicatorSlide 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes indicatorSlide {
    from {
        height: 0%;
        opacity: 0;
    }
    to {
        height: 60%;
        opacity: 1;
    }
}

/* ==========================================================================
   7. AFFORDANCE — Ripple Effect on Primary CTAs
   A subtle radial pulse emanates from click point.
   ========================================================================== */

.ripple-host {
    position: relative;
    overflow: hidden;
}

.ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: scale(0);
    animation: rippleExpand 0.5s ease-out forwards;
    pointer-events: none;
}

@keyframes rippleExpand {
    to {
        transform: scale(2.5);
        opacity: 0;
    }
}

/* ==========================================================================
   8. VISUAL HIERARCHY — Section Dividers
   Subtle gradient dividers between major content sections.
   ========================================================================== */

.section-divider {
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgb(var(--primary-200)) 50%,
        transparent 100%
    );
    border: none;
    margin: var(--space-8) 0;
}

.dark .section-divider {
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgb(var(--primary-800)) 50%,
        transparent 100%
    );
}

/* ==========================================================================
   9. CONSISTENCY — Scrollbar Styling
   Custom scrollbar that matches the design system.
   ========================================================================== */

.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 9999px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.5);
}

.dark .custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(71, 85, 105, 0.4);
}

.dark .custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(71, 85, 105, 0.6);
}

/* Global scrollbar for main content scroller */
.overflow-y-auto {
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.3) transparent;
}

.dark .overflow-y-auto {
    scrollbar-color: rgba(71, 85, 105, 0.4) transparent;
}

/* ==========================================================================
   10. JUICINESS — Tooltip Micro-Animation
   ========================================================================== */

[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
    color: white;
    background: #1e293b;
    border-radius: 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
    z-index: 100;
}

.dark [data-tooltip]::after {
    background: #e2e8f0;
    color: #0f172a;
}

[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==========================================================================
   11. REDUCED MOTION — Respect User Preference
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .stagger-reveal > * {
        opacity: 1;
        transform: none;
        transition: none;
    }
}
