/* ===========================================
   RUNPLANNER - Optimized CSS
   Performance-focused, split from index.html
   =========================================== */

/* ===========================================
   CSS LAYERS - Modern cascade management
   =========================================== */
@layer base, components, utilities;

@layer base {
    :root {
        --brand-seed: #0ABF68;
        --brand-seed-dark: #089b54;
        --brand-deep: #0C3B2E;
        --brand-muted: #1B5847;
        --brand-surface: #F4F7F3;
        --brand-dark-bg: #121212;
        --brand-dark-card: #1E1E1E;
        --brand-dark-text: #E0E0E0;
        --brand-dark-sub: #B0B0B0;
        --parallax-x: 0;
        --parallax-y: 0;
        --mouse-x: 0.5;
        --mouse-y: 0.5;
    }

    .dark {
        --brand-surface: #121212;
    }

    body {
        background-color: var(--brand-surface);
        color: var(--brand-deep);
        transition: background-color 0.3s, color 0.3s;
    }

    .dark body {
        background-color: #121212;
        color: #E0E0E0;
    }

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

@layer components {
    /* ===========================================
       SCROLL ANIMATIONS
       =========================================== */
    .scroll-hidden {
        opacity: 0;
    }

    .scroll-hidden.fade-up {
        transform: translateY(40px);
    }

    .scroll-hidden.fade-left {
        transform: translateX(-40px);
    }

    .scroll-hidden.fade-right {
        transform: translateX(40px);
    }

    .scroll-hidden.scale-up {
        transform: scale(0.9);
    }

    .scroll-hidden.fade-in {
        transform: none;
    }

    .scroll-visible {
        opacity: 1;
        transform: translateY(0) translateX(0) scale(1);
        transition: all 0.8s cubic-bezier(0.16, 1, 0.3, 1);
    }

    /* Stagger delays */
    .delay-100 { transition-delay: 100ms; }
    .delay-200 { transition-delay: 200ms; }
    .delay-300 { transition-delay: 300ms; }
    .delay-400 { transition-delay: 400ms; }
    .delay-500 { transition-delay: 500ms; }

    /* ===========================================
       GRADIENT TEXT
       =========================================== */
    .text-gradient {
        background-clip: text;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-image: linear-gradient(135deg, #0ABF68 0%, #1B5847 100%);
    }

    .dark .text-gradient {
        background-image: linear-gradient(135deg, #0ABF68 0%, #A8E6CF 100%);
    }

    /* ===========================================
       TOPOGRAPHIC PATTERN
       =========================================== */
    .topo-pattern {
        position: relative;
    }

    .topo-pattern::before {
        content: '';
        position: absolute;
        inset: 0;
        background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M10 50 Q25 30 50 35 T90 50' stroke='%230ABF68' stroke-width='0.3' fill='none' opacity='0.15'/%3E%3Cpath d='M10 60 Q30 45 55 50 T90 55' stroke='%230ABF68' stroke-width='0.3' fill='none' opacity='0.1'/%3E%3Cpath d='M10 70 Q35 55 60 60 T90 65' stroke='%230ABF68' stroke-width='0.3' fill='none' opacity='0.05'/%3E%3C/svg%3E");
        background-size: 200px 200px;
        pointer-events: none;
        z-index: 0;
    }

    .dark .topo-pattern::before {
        opacity: 0.5;
    }

    /* ===========================================
       PHONE FRAME COMPONENT
       Fixed border-radius for realistic phone shape
       Proportional padding for scaled bezels
       =========================================== */
    .phone-frame {
        background: linear-gradient(145deg, #1a1a1a 0%, #0a0a0a 100%);
        border-radius: 2.5rem;
        padding: 0.4rem;
        box-shadow: 
            0 25px 80px rgba(0, 0, 0, 0.3),
            0 10px 30px rgba(0, 0, 0, 0.2),
            inset 0 1px 1px rgba(255, 255, 255, 0.1);
    }

    .phone-screen {
        background: #000;
        border-radius: 2.1rem;
        overflow: hidden;
        position: relative;
    }

    /* Smaller phone variants - thinner bezels */
    .phone-frame.small,
    .opacity-60 .phone-frame {
        border-radius: 2rem;
        padding: 0.25rem;
    }

    .phone-frame.small .phone-screen,
    .opacity-60 .phone-frame .phone-screen {
        border-radius: 1.75rem;
    }

    /* No dynamic island - clean screen design */

    /* ===========================================
       PARALLAX EFFECTS
       =========================================== */
    .parallax-phone {
        transition: transform 0.15s ease-out;
        will-change: transform;
    }

    .parallax-phone-left,
    .parallax-phone-right {
        transition: transform 0.2s ease-out;
        will-change: transform;
    }

    /* ===========================================
       SCREENSHOT GALLERY
       =========================================== */
    .screenshot-gallery {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 2rem;
        max-width: 900px;
        margin: 0 auto;
    }

    @media (max-width: 768px) {
        .screenshot-gallery {
            grid-template-columns: 1fr;
            gap: 2.5rem;
        }
    }

    .screenshot-card {
        container-type: inline-size;
    }

    /* ===========================================
       FAQ ACCORDION STYLES
       =========================================== */
    details summary {
        list-style: none;
        cursor: pointer;
    }

    details summary::-webkit-details-marker {
        display: none;
    }

    details[open] summary i[data-lucide="chevron-down"] {
        transform: rotate(180deg);
    }

    /* ===========================================
       FEATURE CONTAINERS
       =========================================== */
    .feature-container {
        container-type: inline-size;
    }

    @container (min-width: 300px) {
        .feature-container .relative {
            padding: 2rem;
        }
    }

    /* ===========================================
       WAYPOINT MARKERS
       =========================================== */
    .waypoint-marker {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 700;
        font-size: 14px;
        color: white;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        cursor: pointer;
        transition: transform 0.2s ease;
    }
    
    .waypoint-marker:hover {
        transform: scale(1.1);
    }
    
    .waypoint-marker.start {
        background: linear-gradient(135deg, #0ABF68, #089b54);
    }
    
    .waypoint-marker.end {
        background: linear-gradient(135deg, #0C3B2E, #1B5847);
    }
    
    .waypoint-marker.middle {
        background: linear-gradient(135deg, #1B5847, #0ABF68);
    }

    .waypoint-marker-pulse {
        position: absolute;
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background: #0ABF68;
        animation: markerPulse 2s ease-out infinite;
        z-index: -1;
    }

    @keyframes markerPulse {
        0% { transform: scale(1); opacity: 0.6; }
        100% { transform: scale(2.5); opacity: 0; }
    }

    /* ===========================================
       MAP STYLES
       =========================================== */
    .mapboxgl-map {
        font-family: 'Nunito', sans-serif;
    }

    .map-container {
        position: relative;
        border-radius: 1.5rem;
        overflow: hidden;
    }

    .map-stats-panel {
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(10px);
        border-radius: 1rem;
        padding: 1rem;
        box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    }

    .dark .map-stats-panel {
        background: rgba(30, 30, 30, 0.95);
    }

    .demo-map-container {
        position: relative;
        aspect-ratio: 16/10;
        border-radius: 1.5rem;
        overflow: hidden;
        box-shadow: 0 25px 80px rgba(0,0,0,0.15);
    }

    .dark .demo-map-container {
        box-shadow: 0 25px 80px rgba(0,0,0,0.4);
    }

    .mapboxgl-ctrl-attrib {
        font-size: 10px !important;
        background: rgba(255,255,255,0.7) !important;
    }

    .dark .mapboxgl-ctrl-attrib {
        background: rgba(0,0,0,0.7) !important;
        color: #999 !important;
    }

    .dark .mapboxgl-ctrl-attrib a {
        color: #0ABF68 !important;
    }

    /* City selector buttons */
    .city-btn {
        transition: all 0.3s ease;
    }
    
    .city-btn.active {
        background-color: #0ABF68 !important;
        color: white !important;
        border-color: #0ABF68 !important;
    }

    /* Loading spinner */
    .route-loading {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        background: white;
        padding: 1rem 1.5rem;
        border-radius: 1rem;
        box-shadow: 0 10px 40px rgba(0,0,0,0.2);
        display: flex;
        align-items: center;
        gap: 0.75rem;
        z-index: 20;
    }

    .route-loading .spinner-small {
        width: 20px;
        height: 20px;
        border: 3px solid #e0e0e0;
        border-top-color: #0ABF68;
        border-radius: 50%;
        animation: spin 0.8s linear infinite;
    }

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

    /* ===========================================
       HERO SECTION GLOWS
       =========================================== */
    .hero-glow {
        position: absolute;
        width: 600px;
        height: 600px;
        border-radius: 50%;
        background: radial-gradient(circle, rgba(10, 191, 104, 0.15) 0%, transparent 70%);
        filter: blur(60px);
        pointer-events: none;
        z-index: 0;
    }

    .dark .hero-glow {
        background: radial-gradient(circle, rgba(10, 191, 104, 0.1) 0%, transparent 70%);
    }

    /* ===========================================
       :has() SELECTOR - Interactive states
       =========================================== */
    .faq-section:has(details[open]) {
        --active-count: 1;
    }

    /* Parent styling based on child state */
    .input-group:has(input:focus) {
        border-color: var(--brand-seed);
        box-shadow: 0 0 0 3px rgba(10, 191, 104, 0.1);
    }

    /* ===========================================
       STATS SECTION
       =========================================== */
    .stats-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 2rem;
    }

    @media (max-width: 640px) {
        .stats-grid {
            grid-template-columns: 1fr;
            gap: 1.5rem;
        }
    }

    .stat-card {
        text-align: center;
        padding: 1.5rem;
        border-radius: 1.5rem;
        background: white;
        box-shadow: 0 4px 20px rgba(0,0,0,0.05);
        transition: transform 0.3s, box-shadow 0.3s;
    }
    
    .stat-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 12px 40px rgba(0,0,0,0.1);
    }

    .dark .stat-card {
        background: #1E1E1E;
        box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    }
    
    .dark .stat-card:hover {
        box-shadow: 0 12px 40px rgba(0,0,0,0.4);
    }

    /* ===========================================
       HEADER / NAV
       =========================================== */
    .header-blur {
        background: rgba(244, 247, 243, 0.8);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }

    .dark .header-blur {
        background: rgba(18, 18, 18, 0.8);
    }

    /* Mobile menu */
    .mobile-menu {
        transform: translateY(-100%);
        opacity: 0;
        transition: transform 0.3s ease, opacity 0.3s ease;
        pointer-events: none;
    }

    .mobile-menu.open {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }

    /* Ensure header buttons are clickable */
    header button {
        position: relative;
        z-index: 10;
    }

    /* ===========================================
       BUTTONS & LINKS
       =========================================== */
    .nav-link {
        position: relative;
        padding: 0.5rem 0;
    }

    .nav-link::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        width: 0;
        height: 2px;
        background: var(--brand-seed);
        transition: width 0.3s ease;
    }

    .nav-link:hover::after {
        width: 100%;
    }

    /* ===========================================
       CUSTOM KEYFRAMES
       =========================================== */
    @keyframes float {
        0%, 100% { transform: translateY(0) rotate(-2deg); }
        50% { transform: translateY(-15px) rotate(-2deg); }
    }

    @keyframes draw {
        0% { stroke-dashoffset: 500; }
        100% { stroke-dashoffset: 0; }
    }

    @keyframes slideDown {
        0% { opacity: 0; transform: translateY(-10px); }
        100% { opacity: 1; transform: translateY(0); }
    }

    @keyframes fadeInUp {
        0% { opacity: 0; transform: translateY(40px); }
        100% { opacity: 1; transform: translateY(0); }
    }

    @keyframes fadeInLeft {
        0% { opacity: 0; transform: translateX(-40px); }
        100% { opacity: 1; transform: translateX(0); }
    }

    @keyframes fadeInRight {
        0% { opacity: 0; transform: translateX(40px); }
        100% { opacity: 1; transform: translateX(0); }
    }

    @keyframes scaleIn {
        0% { opacity: 0; transform: scale(0.9); }
        100% { opacity: 1; transform: scale(1); }
    }

    @keyframes staggerIn {
        0% { opacity: 0; transform: translateY(20px); }
        100% { opacity: 1; transform: translateY(0); }
    }

    /* ===========================================
       ANIMATION CLASSES
       =========================================== */
    .animate-float {
        animation: float 6s ease-in-out infinite;
    }

    .animate-pulse-slow {
        animation: pulse 3s ease-in-out infinite;
    }

    .animate-draw {
        animation: draw 2.5s ease-out forwards;
    }

    .animate-slide-down {
        animation: slideDown 0.3s ease-out forwards;
    }

    .animate-fade-in-up {
        animation: fadeInUp 0.6s ease-out forwards;
    }

    .animate-fade-in-left {
        animation: fadeInLeft 0.6s ease-out forwards;
    }

    .animate-fade-in-right {
        animation: fadeInRight 0.6s ease-out forwards;
    }

    .animate-scale-in {
        animation: scaleIn 0.5s ease-out forwards;
    }

    .animate-stagger-in {
        animation: staggerIn 0.4s ease-out forwards;
    }

    /* ===========================================
       MAP PLACEHOLDER (before Mapbox loads)
       =========================================== */
    .map-placeholder {
        background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--brand-muted);
    }

    .dark .map-placeholder {
        background: linear-gradient(135deg, #1a2f1a 0%, #0d1f0d 100%);
    }

    .map-placeholder-spinner {
        width: 40px;
        height: 40px;
        border: 4px solid rgba(10, 191, 104, 0.2);
        border-top-color: var(--brand-seed);
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }

    /* ===========================================
       SKELETON LOADING FOR MAPS
       =========================================== */
    .skeleton-map {
        background: linear-gradient(90deg, #e8f5e9 25%, #c8e6c9 50%, #e8f5e9 75%);
        background-size: 200% 100%;
        animation: skeleton-loading 1.5s ease-in-out infinite;
    }

    .dark .skeleton-map {
        background: linear-gradient(90deg, #1a2f1a 25%, #2a4a2a 50%, #1a2f1a 75%);
        background-size: 200% 100%;
    }

    @keyframes skeleton-loading {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }

    /* ===========================================
       FEATURE CARD MICRO-INTERACTIONS
       =========================================== */
    .feature-container .relative {
        transition: transform 0.3s ease, box-shadow 0.3s ease;
    }

    .feature-container .relative:hover {
        transform: translateY(-4px);
        box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    }

    .dark .feature-container .relative:hover {
        box-shadow: 0 20px 40px rgba(0,0,0,0.3);
    }

    .feature-container .relative:hover [data-lucide] {
        transform: scale(1.1);
    }

    .feature-container [data-lucide] {
        transition: transform 0.3s ease;
    }
}

@layer utilities {
    /* ===========================================
       FOCUS VISIBLE STYLES (Accessibility)
       WCAG 2.4.7 compliance
       =========================================== */
    :focus-visible {
        outline: 3px solid var(--brand-seed);
        outline-offset: 2px;
    }

    button:focus-visible,
    a:focus-visible,
    [role="button"]:focus-visible {
        outline: 3px solid var(--brand-seed);
        outline-offset: 2px;
        box-shadow: 0 0 0 6px rgba(10, 191, 104, 0.2);
    }

    /* Remove default outline for mouse users */
    :focus:not(:focus-visible) {
        outline: none;
    }

    /* ===========================================
       IMPROVED TOUCH TARGETS (Mobile Accessibility)
       Minimum 44x44px for interactive elements
       =========================================== */
    .city-btn {
        min-height: 44px;
        min-width: 44px;
    }

    details summary {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}
