/* ========================================
   1971 Memory Project - Custom Styles
   ======================================== */

/* CSS Custom Properties for Magic Numbers */
:root {
    /* Colors - Expose Tailwind config to CSS */
    --color-ink: #111111;
    --color-paper: #F9F8F6;
    --color-stone: #595959;
    --color-divider: #D1D1D1;

    /* Thematic accents - 1971 Memory Project */
    --color-sage: #5A6350;      /* Muted green - Bangladesh flag reference */
    --color-sage-light: #EBEDE9; /* Light sage for backgrounds */
    --color-clay: #A65D5D;       /* Muted red - warmth, dignity */
    --color-clay-light: #F5E8E8; /* Light clay for backgrounds */

    /* Spacing */
    --scroll-margin-offset: 140px;
    --hover-slide-offset: 6px;

    /* Transitions - Upscale easing curves */
    --transition-duration: 0.5s;
    --transition-curve: cubic-bezier(0.16, 1, 0.3, 1);
    --transition-curve-subtle: cubic-bezier(0.25, 0.46, 0.45, 0.94);
    --transition-curve-exit: cubic-bezier(0.45, 0, 0.55, 1);
    --transition-curve-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Animation - Balanced pacing for serious content */
    --base-animation-delay: 0.2s;
    --animation-increment-base: 0.08s;
    --animation-duration-premium: 1.1s;
}

/* ========================================
   Base Styles
   ======================================== */

body {
    background-color: var(--color-paper);
    color: var(--color-ink);
    /* Layered paper texture: fine grain + subtle fibers + tonal variation */
    background-image:
        /* Fine surface grain */
        url("data:image/svg+xml,%3Csvg viewBox='0 0 300 300' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='grain'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.5' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23grain)' opacity='0.12'/%3E%3C/svg%3E"),
        /* Subtle paper fibers */
        url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='fibers'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.04' numOctaves='4' seed='42'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23fibers)' opacity='0.065'/%3E%3C/svg%3E"),
        /* Very faint tonal clouds for warmth variation */
        radial-gradient(ellipse at 20% 30%, rgba(0,0,0,0.035) 0%, transparent 70%),
        radial-gradient(ellipse at 80% 70%, rgba(0,0,0,0.028) 0%, transparent 60%);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   Custom Scrollbar (WebKit)
   ======================================== */

::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--color-stone);
    border-radius: 10px;
    transition: background 0.3s ease;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--color-ink);
}

/* ========================================
   Drawer & Backdrop States
   ======================================== */

.drawer-open {
    transform: translateX(0%);
}
.drawer-closed {
    transform: translateX(100%);
}
.backdrop-open {
    opacity: 1;
    pointer-events: auto;
    backdrop-filter: blur(4px);
}
.backdrop-closed {
    opacity: 0;
    pointer-events: none;
    backdrop-filter: blur(0px);
}

/* Simplified backdrop animation - remove expensive blur transition */
#drawerBackdrop {
    transition: opacity 0.4s var(--transition-curve-subtle);
    will-change: opacity;
}

/* Custom Drawer Easing - GPU-accelerated */
#detailDrawer {
    transition: transform 0.6s var(--transition-curve);
    will-change: transform;
}

/* Drawer content cascade animation - GPU-accelerated */
@keyframes cascadeIn {
    from {
        opacity: 0;
        transform: translateY(12px) translateZ(0);
    }
    to {
        opacity: 1;
        transform: translateY(0) translateZ(0);
    }
}

.drawer-cascade {
    opacity: 0;
    animation: cascadeIn 0.5s var(--transition-curve) forwards;
    will-change: transform, opacity;
}

/* ========================================
   Archive Row Styles
   ======================================== */

.archive-row {
    position: relative;
    scroll-margin-top: var(--scroll-margin-offset);
    z-index: 1;
    outline: none;
    transition: transform 0.35s var(--transition-curve-subtle);
    will-change: transform;
}

/* Pseudo-element to span full screen width behind the row */
.archive-row::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100vw;
    right: -100vw;
    bottom: 0;
    background-color: transparent;
    z-index: -1;
    transition: background-color 0.3s var(--transition-curve-subtle);
}

/* Semi-transparent hover preserves the paper texture underneath */
.archive-row:hover::before,
.archive-row:focus-visible::before {
    background-color: rgba(17, 17, 17, 0.045);
}

/* ADA compliant focus ring - refined */
.archive-row:focus-visible {
    box-shadow: inset 3px 0 0 0 var(--color-ink);
}

/* Hover animation for title - GPU-accelerated only */
.archive-row h3 {
    transition: transform 0.35s var(--transition-curve),
                color 0.3s ease;
    letter-spacing: 0.01em;
}
.archive-row:hover h3,
.archive-row:focus-visible h3 {
    transform: translateX(var(--hover-slide-offset)) translateZ(0);
    color: var(--color-sage);
}

/* Subtle lift effect on entire row - GPU-accelerated */
.archive-row:hover {
    transform: translateY(-1px) translateZ(0);
}

/* Sage hover effect for tags */
.archive-row .bg-\\[\\#EBEDE9\\]:hover,
#drawerContent .bg-\\[\\#EBEDE9\\]:hover {
    background-color: #DFE3D8;
}

/* ========================================
   Upscale Animations
   ======================================== */

/* Enhanced entrance animation - GPU-accelerated only */
@keyframes fadeUpPremium {
    0% {
        opacity: 0;
        transform: translateY(16px) translateZ(0);
    }
    100% {
        opacity: 1;
        transform: translateY(0) translateZ(0);
    }
}

.animate-fade-up {
    opacity: 0;
    animation: fadeUpPremium var(--animation-duration-premium) var(--transition-curve) forwards;
    will-change: transform, opacity;
}

/* Quick snap-in animation for filtered results */
@keyframes fadeSnap {
    0% {
        opacity: 0;
        transform: translateY(4px) translateZ(0);
    }
    100% {
        opacity: 1;
        transform: translateY(0) translateZ(0);
    }
}

.animate-instant {
    opacity: 0;
    animation: fadeSnap 0.25s var(--transition-curve) forwards;
    will-change: transform, opacity;
}

.animate-fade-up.animation-complete {
    will-change: auto;
}

/* Stagger variants for organic feel */
.animate-fade-up-delay-1 { animation-delay: 0.1s; }
.animate-fade-up-delay-2 { animation-delay: 0.2s; }
.animate-fade-up-delay-3 { animation-delay: 0.3s; }

/* ========================================
   Navigation & Logo Animations
   ======================================== */

/* Logo and divider entrance animation - graceful and GPU-accelerated */
nav img,
nav .w-px {
    opacity: 0;
    animation: navFadeIn 1.8s var(--transition-curve) forwards;
    will-change: transform, opacity;
}
nav a img {
    --nav-opacity: 0.9;
    transition: transform 0.3s var(--transition-curve-subtle);
}
nav .w-px {
    --nav-opacity: 1;
    animation-delay: 0.35s;
}
nav a:hover img {
    transform: scale(0.97) translateZ(0);
}

@keyframes navFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px) translateZ(0);
    }
    to {
        opacity: var(--nav-opacity);
        transform: translateY(0) translateZ(0);
    }
}

/* ========================================
   Button & Link Micro-interactions
   ======================================== */

button {
    transition: transform 0.2s var(--transition-curve-bounce),
                opacity 0.3s ease;
}
button:not(:disabled):hover {
    transform: translateY(-1px) translateZ(0);
}
button:not(:disabled):active {
    transform: translateY(0) translateZ(0);
}

/* Smooth sticky filter transition with faded background */
#filterInner {
    position: relative;
    background: transparent !important;
    contain: layout style paint;
}
#filterInner::before {
    content: '';
    position: absolute;
    inset: 0;
    background-color: rgb(247, 246, 243);
    opacity: 0.95;
    -webkit-mask-image: linear-gradient(to right, transparent 0%, black 4%, black 96%, transparent 100%);
    mask-image: linear-gradient(to right, transparent 0%, black 4%, black 96%, transparent 100%);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
    z-index: -1;
}

/* Elegant link underline animation */
a:not(nav a) {
    position: relative;
}
a:not(nav a)::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 1px;
    background: currentColor;
    transition: width 0.4s var(--transition-curve);
}
a:not(nav a):hover::after {
    width: 100%;
}

/* ========================================
   Respect user's motion preferences
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .animate-fade-up,
    .animate-fade-up-delay-1,
    .animate-fade-up-delay-2,
    .animate-fade-up-delay-3,
    .animate-instant {
        animation: none;
        opacity: 1;
    }

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ========================================
   Utilities
   ======================================== */

/* Utilities for Screen Readers */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Make visible on focus for skip links */
.sr-only-focusable:focus {
    position: absolute;
    width: auto;
    height: auto;
    padding: 0.5rem 1rem;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
    background: white;
    border: 2px solid var(--color-ink);
    border-radius: 4px;
    z-index: 9999;
}

/* ========================================
   Tag Filter Styles
   ======================================== */

/* Tag filter button active state */
#tagFilterBtn[aria-expanded="true"] {
    color: var(--color-ink);
}
#tagFilterBtn[aria-expanded="true"] i {
    transform: rotate(180deg);
}
#tagFilterBtn i {
    transition: transform 0.25s var(--transition-curve-subtle);
}

/* Tag count badge */
#tagCount {
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.05em;
}

/* Clear All Tags button */
#clearAllTags {
    transition: all 0.2s var(--transition-curve-subtle);
}
#clearAllTags:hover {
    transform: translateX(-2px);
}

/* Tag panel animation */
#tagFilterPanel {
    margin-top: 0; /* No overlap - keep bottom border visible */
}

/* Tag panel opening animation */
.tag-panel-open {
    animation: tagPanelReveal 0.4s var(--transition-curve) forwards;
}

@keyframes tagPanelReveal {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.98);
        filter: blur(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

/* Tag panel content cascade */
.tag-panel-content > div {
    opacity: 0;
    animation: tagContentFade 0.3s var(--transition-curve) forwards;
}
.tag-panel-content > div:nth-child(1) { animation-delay: 0.1s; }
.tag-panel-content > div:nth-child(2) { animation-delay: 0.15s; }
.tag-panel-content > div:nth-child(3) { animation-delay: 0.2s; }
.tag-panel-content > div:nth-child(4) { animation-delay: 0.25s; }

@keyframes tagContentFade {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tag pill styles (shared by selected and popular tags) */
.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background-color: var(--color-paper);
    border: 1px solid var(--color-divider);
    border-radius: 2px;
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--color-stone);
    cursor: pointer;
    transition: all 0.2s var(--transition-curve-subtle);
    user-select: none;
}
.tag-pill:hover {
    border-color: var(--color-ink);
    color: var(--color-ink);
    background-color: rgba(17, 17, 17, 0.03);
}

/* Selected tag pill */
.tag-pill.selected {
    background-color: var(--color-sage-light);
    border-color: rgba(90, 99, 80, 0.3);
    color: var(--color-sage);
    animation: tagPop 0.2s var(--transition-curve-bounce) forwards;
}
.tag-pill.selected:hover {
    background-color: #DFE3D8;
    border-color: rgba(90, 99, 80, 0.5);
}
@keyframes tagPop {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Selected tag remove button */
.tag-pill.selected button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    padding: 0;
    margin-left: 2px;
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.15s ease;
    border-radius: 2px;
}
.tag-pill.selected button:hover {
    opacity: 1;
    background-color: rgba(90, 99, 80, 0.15);
}

/* Tag count badge on popular tags */
.tag-pill .tag-count-badge {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.05em;
    color: var(--color-stone);
    opacity: 0.6;
    margin-left: 2px;
}

/* Tag suggestion item in dropdown */
.tag-suggestion {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    border-bottom: 1px solid var(--color-divider);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-ink);
}
.tag-suggestion:last-child {
    border-bottom: none;
}
.tag-suggestion:hover,
.tag-suggestion:focus {
    background-color: rgba(17, 17, 17, 0.04);
}
.tag-suggestion.selected {
    background-color: var(--color-sage-light);
    color: var(--color-sage);
}
.tag-suggestion .tag-count {
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-stone);
    opacity: 0.7;
    padding: 2px 6px;
    background-color: rgba(89, 89, 89, 0.08);
    border-radius: 2px;
}
.tag-suggestion.selected .tag-count {
    background-color: rgba(90, 99, 80, 0.2);
    color: var(--color-sage);
    opacity: 1;
}

/* No results message */
.tag-no-results {
    padding: 16px;
    text-align: center;
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--color-stone);
    opacity: 0.7;
}

/* Custom scrollbar for tag suggestions */
#tagSuggestions::-webkit-scrollbar {
    width: 4px;
}
#tagSuggestions::-webkit-scrollbar-thumb {
    background: var(--color-stone);
    border-radius: 4px;
}
#tagSuggestions::-webkit-scrollbar-track {
    background: transparent;
}

/* ========================================
   Main Search Autocomplete
   ======================================== */

/* Search suggestions dropdown */
#searchSuggestions {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    margin-top: 4px;
    background: var(--color-paper);
    border: 1px solid var(--color-ink);
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    z-index: 40;
    max-height: 300px;
    overflow-y: auto;
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: opacity 0.2s var(--transition-curve-subtle), transform 0.2s var(--transition-curve-subtle);
}
#searchSuggestions.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.search-suggestion-item {
    padding: 10px 16px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    border-bottom: 1px solid var(--color-divider);
    display: flex;
    align-items: flex-start;
    gap: 10px;
}
.search-suggestion-item:last-child {
    border-bottom: none;
}
.search-suggestion-item:hover,
.search-suggestion-item:focus {
    background-color: rgba(17, 17, 17, 0.04);
}
.search-suggestion-item .suggestion-icon {
    flex-shrink: 0;
    margin-top: 2px;
}
.search-suggestion-item .suggestion-content {
    flex: 1;
    min-width: 0;
}
.search-suggestion-item .suggestion-title {
    font-weight: 500;
    font-size: 13px;
    color: var(--color-ink);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.search-suggestion-item .suggestion-meta {
    font-size: 11px;
    color: var(--color-stone);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.search-suggestion-item .suggestion-match {
    background-color: rgba(166, 93, 93, 0.2);
    border-radius: 2px;
    padding: 0 2px;
}

.search-no-results {
    padding: 16px;
    text-align: center;
    font-size: 12px;
    color: var(--color-stone);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

/* ========================================
   Responsive Improvements
   ======================================== */

@media (max-width: 767px) {
    /* Search suggestions - position properly on mobile */
    #searchSuggestions {
        left: -1rem;
        right: -1rem;
        max-height: 50vh;
    }

    /* Tag suggestions - smaller on mobile */
    #tagSuggestions {
        max-height: 40vh;
    }

    /* Search suggestion items - compact on mobile */
    .search-suggestion-item {
        padding: 10px 12px;
        gap: 8px;
    }
    .search-suggestion-item .suggestion-title {
        font-size: 12px;
    }
    .search-suggestion-item .suggestion-meta {
        font-size: 10px;
    }

    /* Tag pills - slightly smaller on mobile */
    .tag-pill {
        font-size: 9px;
        padding: 4px 8px;
    }

    /* Filter labels - smaller tracking on mobile */
    label .filter-label {
        letter-spacing: 0.08em;
    }
}
