/* 
 * Country Search Gateway — Custom Styles
 * Mobile-first, future-proof. Uses CSS custom properties, standard flexbox/grid,
 * and progressive enhancement. Zero dependency on deprecated features.
 * Last reviewed: 2026 — all techniques are W3C stable specifications.
 */

/* ─── CSS Custom Properties (Theming) ─────────────────────────────── */
:root {
    --header-h: 64px;
    --search-bar-h: 72px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-2xl: 28px;
    --shadow-card: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-card-hover: 0 10px 25px rgba(0,0,0,.08), 0 4px 10px rgba(0,0,0,.04);
    --shadow-elevated: 0 20px 40px rgba(0,0,0,.12);
    --transition-fast: 150ms cubic-bezier(.4,0,.2,1);
    --transition-base: 250ms cubic-bezier(.4,0,.2,1);
    --transition-smooth: 350ms cubic-bezier(.4,0,.2,1);
}

@media (min-width: 1024px) {
    :root {
        --header-h: 80px;
        --search-bar-h: 84px;
    }
}

/* ─── Global Resets & Sensible Defaults ───────────────────────────── */
html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Safe area for notched phones (iPhone X+, Pixel etc.) */
body {
    padding-bottom: var(--safe-bottom);
}

/* ─── Accessibility: Reduced Motion ───────────────────────────────── */
@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;
    }
}

/* ─── Custom Scrollbar Hide ───────────────────────────────────────── */
.scrollbar-hide::-webkit-scrollbar {
    display: none;
}
.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

/* ─── Smooth Scroll Snap for Carousels ────────────────────────────── */
.snap-scroll {
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}
.snap-scroll > * {
    scroll-snap-align: start;
}

/* ─── Category Cards ──────────────────────────────────────────────── */
.category-card {
    display: block;
    height: 100%;
}

/* ─── FAQ Accordion ───────────────────────────────────────────────── */
.faq-content {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding-top: 0;
    padding-bottom: 0;
    transition: max-height var(--transition-smooth), 
                padding var(--transition-smooth), 
                opacity var(--transition-smooth);
}
.faq-item.active .faq-content {
    max-height: 500px;
    opacity: 1;
    padding-bottom: 1.25rem;
}
.faq-item.active .faq-chevron {
    transform: rotate(180deg);
}
.faq-item.active .faq-toggle {
    color: var(--color-secondary, #C2185B);
}

/* ─── Autocomplete Dropdown ───────────────────────────────────────── */
.autocomplete-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color var(--transition-fast);
}
.autocomplete-item:last-child {
    border-bottom: none;
}
.autocomplete-item:hover, 
.autocomplete-item.active {
    background-color: #f9fafb;
}
.autocomplete-match {
    font-weight: 700;
    color: var(--color-secondary, #C2185B);
}

/* ─── Focus Styles (Accessibility) ────────────────────────────────── */
*:focus-visible {
    outline: 2px solid var(--color-secondary, #C2185B);
    outline-offset: 2px;
}
/* Remove focus ring for mouse users */
*:focus:not(:focus-visible) {
    outline: none;
}

/* ─── Search Results: View Mode Cards ─────────────────────────────── */
/* List-view specific overrides (horizontal layout on tablet+) */
.view-list .result-card {
    flex-direction: row;
    gap: 1.5rem;
}
.view-list .result-card .card-body {
    flex: 1;
    min-width: 0; /* prevent flex child overflow */
}
.view-list .result-card .card-footer {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}
.view-list .result-card .card-footer .btn-view {
    width: auto;
    min-width: 200px;
}

/* Grid-view (default / mobile) — stacked layout */
.view-grid .result-card .card-footer .btn-view {
    width: 100%;
}

/* ─── Mobile-Specific: Touch-Friendly Targets ─────────────────────── */
@media (max-width: 767px) {
    /* Ensure minimum 44x44px touch targets (WCAG 2.5.5) */
    a, button, [role="button"], select, input[type="submit"] {
        min-height: 44px;
    }
    
    /* Make inputs larger on mobile */
    input[type="text"],
    input[type="email"],
    input[type="search"],
    select {
        font-size: 16px !important; /* Prevents iOS auto-zoom on focus */
    }

    /* Sticky search bar compensation */
    .sticky-search-offset {
        scroll-margin-top: calc(var(--header-h) + var(--search-bar-h) + 16px);
    }

    /* Mobile pagination — full width buttons */
    .pagination-mobile a,
    .pagination-mobile span {
        flex: 1;
        text-align: center;
        padding: 12px 8px;
    }

    /* Mobile bottom safe area spacing on last section */
    main > section:last-child {
        padding-bottom: calc(1rem + var(--safe-bottom));
    }
}

/* ─── Tablet Breakpoint Adjustments ───────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
    .view-list .result-card {
        flex-direction: row;
    }
}

/* ─── Loading Skeleton Animation ──────────────────────────────────── */
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite ease-in-out;
    border-radius: var(--radius-sm);
}

/* ─── Subtle Entrance Animation ───────────────────────────────────── */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.animate-fade-in-up {
    animation: fadeInUp 0.4s ease-out forwards;
}

/* Stagger children */
.stagger-children > * {
    opacity: 0;
    animation: fadeInUp 0.4s ease-out forwards;
}
.stagger-children > *:nth-child(1) { animation-delay: 0ms; }
.stagger-children > *:nth-child(2) { animation-delay: 50ms; }
.stagger-children > *:nth-child(3) { animation-delay: 100ms; }
.stagger-children > *:nth-child(4) { animation-delay: 150ms; }
.stagger-children > *:nth-child(5) { animation-delay: 200ms; }
.stagger-children > *:nth-child(6) { animation-delay: 250ms; }
.stagger-children > *:nth-child(7) { animation-delay: 300ms; }
.stagger-children > *:nth-child(8) { animation-delay: 350ms; }
.stagger-children > *:nth-child(9) { animation-delay: 400ms; }

/* ─── Glassmorphism Utilities ─────────────────────────────────────── */
.glass {
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

/* ─── Line Clamp (for browsers without Tailwind) ──────────────────── */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.line-clamp-4 {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ─── Print Styles ────────────────────────────────────────────────── */
@media print {
    header, footer, .sticky, nav, .faq-toggle svg,
    button, .view-toggle, form {
        display: none !important;
    }
    main {
        padding: 0 !important;
    }
    .result-card {
        break-inside: avoid;
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}
