/* =========================================
   1. MASTER VARIABLES & THEME ENGINE
   ========================================= */
:root {
    /* Clinical Color Palette (WCAG 4.5:1 Compliant) */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --accent-teal: #0a6c63; /* High-contrast SEO teal */
    --accent-teal-hover: #08524b;
    --accent-navy: #0f172a;
    --border-color: #e2e8f0;
    --danger: #ef4444;
    --success: #10b981;
    
    /* Layered Umbra Shadows (Mathematical depth of field) */
    --shadow-sm: 0 1px 2px 0 rgb(15 23 42 / 0.04);
    --shadow-md: 0 4px 6px -1px rgb(15 23 42 / 0.06), 0 2px 4px -2px rgb(15 23 42 / 0.06);
    --shadow-lg: 
        0 2px 4px rgba(15, 23, 42, 0.02),
        0 4px 8px rgba(15, 23, 42, 0.02),
        0 8px 16px rgba(15, 23, 42, 0.03),
        0 16px 32px rgba(15, 23, 42, 0.04),
        0 32px 64px rgba(15, 23, 42, 0.05);
    
    /* Fluid Spring Animations */
    --transition-fast: 0.15s ease-out;
    --transition-spring: 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.1);
}

/* =========================================
   2. SYSTEM RESET & FLUID NORMALIZATION
   ========================================= */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-main);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh; /* Adaptive dynamic viewport parsing */
    overflow-x: hidden;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection {
    background-color: rgba(10, 108, 99, 0.2);
    color: var(--accent-navy);
}

::-webkit-scrollbar {
    width: 8px;
    height: 0px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

:focus-visible {
    outline: 2px solid var(--accent-teal);
    outline-offset: 3px;
}

a {
    text-decoration: none;
    color: var(--accent-teal);
    transition: color var(--transition-fast);
}

img {
    max-width: 100%;
    height: auto;
    display: block;
}

ul, ol {
    list-style-position: inside;
}

h1, h2, h3, h4 {
    color: var(--accent-navy);
    line-height: 1.2;
    font-weight: 800;
    letter-spacing: -0.02em;
}

h1 { font-size: clamp(2.2rem, 5vw, 3.8rem); }
h2 { font-size: clamp(1.8rem, 4vw, 2.8rem); }
p { margin-bottom: 1rem; }

/* =========================================
   3. DESKTOP HEADER & NAVIGATION ENGINE
   ========================================= */
header {
    display: flex;
    align-items: center;
    padding: calc(1rem + env(safe-area-inset-top)) 5% 1rem 5%;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid rgba(226, 232, 240, 0.6);
    position: sticky;
    top: 0;
    z-index: 1000;
    height: 73px;
}

.logo {
    order: 1;
    margin-right: auto;
    font-size: clamp(1.3rem, 2vw, 1.6rem);
    font-weight: 900;
    color: var(--accent-navy);
    letter-spacing: -0.5px;
}
.logo span { color: var(--accent-teal); }

.menu-toggle {
    display: none;
    flex-direction: column;
    cursor: pointer;
    gap: 5px;
    z-index: 1001;
}
.menu-toggle span {
    width: 25px;
    height: 3px;
    background: var(--accent-navy);
    border-radius: 2px;
    transition: var(--transition-spring);
}

nav#nav-links {
    order: 2;
    display: flex;
    align-items: center;
    gap: 2.5rem;
    margin-right: 2.5rem;
}
nav#nav-links a {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.95rem;
    position: relative;
}
nav#nav-links a:hover { color: var(--accent-navy); }
nav#nav-links a::after {
    content: ''; position: absolute; width: 0; height: 2px; bottom: -4px; left: 0;
    background-color: var(--accent-teal); transition: width var(--transition-spring);
}
nav#nav-links a:hover::after { width: 100%; }

.cart-link {
    order: 3;
    background: #ffffff !important;
    color: var(--accent-navy) !important;
    padding: 0.6rem 1.2rem !important;
    border-radius: 30px;
    font-weight: 700;
    border: 1px solid var(--border-color);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.cart-link:hover {
    background: rgba(10, 108, 99, 0.05) !important;
    color: var(--accent-teal) !important;
    border-color: var(--accent-teal) !important;
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

/* =========================================
   4. LAYOUT ARCHITECTURE & BUTTONS
   ========================================= */
main {
    flex: 1;
    padding: 4rem 5%;
    max-width: 1300px;
    margin: 0 auto;
    width: 100%;
}
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 2.5rem;
}

.btn {
    display: inline-flex; justify-content: center; align-items: center; padding: 1rem 2rem;
    background-color: var(--accent-teal); color: #fff !important; font-weight: 700;
    border-radius: 8px; border: none; cursor: pointer; text-align: center; min-height: 50px;
    transition: all var(--transition-spring); position: relative; overflow: hidden; z-index: 1;
}
.btn:hover {
    background-color: var(--accent-teal-hover);
    transform: translateY(-3px);
    box-shadow: 0 10px 20px -10px var(--accent-teal);
}
.btn:active { transform: translateY(0); }

/* High-Contrast Interactive Hover Overrides for Alternative Buttons */
.hero-btn-secondary:hover, .shop-card-btn-alt:hover, .btn-alt-catalogue:hover {
    color: #ffffff !important;
    background-color: var(--accent-teal) !important;
    border-color: var(--accent-teal) !important;
    transform: translateY(-3px);
    box-shadow: 0 10px 20px -10px var(--accent-teal);
}

/* =========================================
   5. PRODUCT CARDS & INTERACTION PHYSICS
   ========================================= */
.shop-card, .card {
    border: 1px solid var(--border-color); border-radius: 16px; background: #fff;
    transition: all var(--transition-spring); display: flex; flex-direction: column;
    will-change: transform, box-shadow; position: relative; overflow: hidden;
}
.shop-card:hover, .card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-lg);
    border-color: rgba(10, 108, 99, 0.3);
}
.product-img-main, .shop-card-img {
    width: 100%; border-radius: 16px; aspect-ratio: 1/1; object-fit: cover; background: var(--bg-primary);
}

.shop-card::after, .btn::after {
    content: ''; position: absolute; top: 0; left: -150%; width: 50%; height: 100%;
    background: linear-gradient(to right, rgba(255,255,255,0) 0%, rgba(255,255,255,0.2) 50%, rgba(255,255,255,0) 100%);
    transform: skewX(-25deg); z-index: 1; pointer-events: none;
}
.shop-card:hover::after, .btn:hover::after { animation: glass-sweep 0.7s ease-out forwards; }
@keyframes glass-sweep { 100% { left: 200%; } }

/* =========================================
   6. INTERACTIVE FILTERS & STORAGE STATES
   ========================================= */
.shop-card.hidden, .product-item.hidden {
    opacity: 0 !important;
    transform: scale(0.95) !important;
    position: absolute !important;
    pointer-events: none !important;
    visibility: hidden !important;
}

/* =========================================
   7. FORMS & INPUTS
   ========================================= */
.form-group { margin-bottom: 1.8rem; }
.form-group label { display: block; margin-bottom: 0.6rem; font-weight: 700; font-size: 0.95rem; color: var(--accent-navy); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 1.2rem; border: 1px solid var(--border-color); border-radius: 8px;
    font-size: 1rem; font-family: inherit; background: var(--bg-secondary); transition: all var(--transition-fast);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--accent-teal); background: #fff; box-shadow: 0 0 0 4px rgba(10, 108, 99, 0.1);
}

/* =========================================
   8. CART & MICRO-INTERACTIONS
   ========================================= */
.cart-item {
    display: flex; justify-content: space-between; align-items: center; padding: 1.5rem;
    background: #fff; border: 1px solid var(--border-color); border-radius: 12px; margin-bottom: 1rem; transition: all var(--transition-fast);
}
.cart-item:hover { border-color: #cbd5e1; }
.qty-controls { display: flex; align-items: center; gap: 1rem; background: var(--bg-secondary); border-radius: 8px; padding: 0.3rem; border: 1px solid var(--border-color); }
.qty-btn {
    background: #fff; border: 1px solid var(--border-color); width: 36px; height: 36px; border-radius: 6px; cursor: pointer;
    font-weight: 800; font-size: 1.2rem; color: var(--accent-navy); transition: all var(--transition-fast); display: flex; align-items: center; justify-content: center;
}
.qty-btn:hover { background: var(--accent-navy); color: #fff; border-color: var(--accent-navy); }

/* =========================================
   9. TOAST NOTIFICATIONS
   ========================================= */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 12px; pointer-events: none; }
.toast {
    background-color: var(--accent-navy); color: #fff; padding: 1.2rem 1.8rem; border-radius: 10px; box-shadow: var(--shadow-lg);
    font-weight: 600; font-size: 0.95rem; opacity: 0; transform: translateY(30px) scale(0.95);
    animation: toastEnter 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards, toastExit 0.4s 3.5s forwards; display: flex; align-items: center; gap: 1rem;
}
.toast.success { border-left: 5px solid var(--success); }
.toast.error { border-left: 5px solid var(--danger); }
@keyframes toastEnter { to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastExit { to { opacity: 0; transform: translateY(-20px) scale(0.95); } }

/* =========================================
   10. SPECIFICITY OVERRIDE MOBILE HEADER GRID (SWAPPED COORDINATES)
   ========================================= */
@media (max-width: 768px) {
    /* Safe-Area mobile header setup */
    header { 
        display: grid !important;
        grid-template-columns: 1fr auto 1fr !important;
        grid-template-rows: 1fr !important;
        align-items: center !important;
        height: 70px !important;
        min-height: 70px !important;
        padding: calc(0.5rem + env(safe-area-inset-top)) 5% 0.5rem 5% !important; 
        gap: 0 !important;
    }

    /* 1. FORCE THE BURGER MENU TO THE FAR LEFT (Specificity Override) */
    html body header div.menu-toggle { 
        grid-column: 1 !important; 
        grid-row: 1 !important; 
        order: 1 !important; 
        justify-self: start !important; 
        display: flex !important;
        margin: 0 !important;
        z-index: 1002 !important;
    }
    
    /* 2. FORCE THE LOGO DEAD CENTER (Specificity Override) */
    html body header a.logo { 
        grid-column: 2 !important; 
        grid-row: 1 !important; 
        order: 2 !important; 
        justify-self: center !important; 
        margin: 0 !important;
        font-size: 1.5rem !important; 
        white-space: nowrap !important; 
    }
    
    /* 3. FORCE THE CART TO THE FAR RIGHT (Specificity Override) */
    html body header a.cart-link { 
        grid-column: 3 !important; 
        grid-row: 1 !important; 
        order: 3 !important; 
        justify-self: end !important; 
        margin: 0 !important; 
        padding: 0.5rem 0.8rem !important; 
        background: #ffffff !important; 
        color: var(--accent-navy) !important; 
        border-radius: 8px; 
        border: 1px solid var(--border-color);
        z-index: 1002 !important;
        display: flex !important;
        align-items: center !important;
        gap: 0.4rem !important;
    }
    html body header a.cart-link:hover { background: rgba(10, 108, 99, 0.05) !important; }
    
    nav#nav-links { 
        display: flex !important;
        flex-direction: column;
        position: absolute; 
        top: 100%; 
        left: 0; 
        width: 100%; 
        background: rgba(255, 255, 255, 0.98); 
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); 
        border-top: 1px solid var(--border-color);
        max-height: 0; 
        overflow: hidden; 
        opacity: 0;
        padding: 0 5%;
        transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
        z-index: 999;
        order: 4 !important;
    }
    nav#nav-links.active { max-height: 400px; padding: 1rem 5%; opacity: 1; }
    nav#nav-links a {
        width: 100%; text-align: center; font-size: 1.15rem; color: var(--text-muted);
        padding: 1.2rem 0; border-bottom: 1px solid rgba(226, 232, 240, 0.3); display: block;
    }
    nav#nav-links a:last-child { border-bottom: none; }
    nav#nav-links a::after { display: none !important; }

    .menu-toggle.open span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
    .menu-toggle.open span:nth-child(2) { opacity: 0; }
    .menu-toggle.open span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

    /* Spacing adjustments for mobile fold viewports and bottom height compression */
    main {
        padding: 1.5rem 5% 1.5rem 5% !important;
    }
    
    /* Fold Spacing Compression */
    section.hero, .catalogue-hero, .hero-section { 
        padding-top: 1.8rem !important; 
        padding-bottom: 1.5rem !important; 
    }
    .hero h1, .catalogue-hero h1, .hero-section h1 { 
        font-size: 2.3rem !important; 
        margin-top: 0.5rem !important; 
        margin-bottom: 0.8rem !important; 
        line-height: 1.2 !important;
    }
    .hero p, .catalogue-hero p, .hero-section p { 
        font-size: 1rem !important; 
        margin-bottom: 1.5rem !important; 
        padding: 0; 
    }

    /* Horizontal Catalog Interaction Track */
    .filter-container {
        margin: 0.8rem auto 1.2rem auto !important;
        padding: 0 5% 0.5rem 5% !important;
        gap: 0.5rem !important;
        justify-content: flex-start !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        display: flex !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
    }
    .filter-container::-webkit-scrollbar { display: none !important; }
    .filter-btn { padding: 0.5rem 1.2rem !important; white-space: nowrap !important; flex-shrink: 0 !important; }

    /* Component Grid Adjustments */
    section.product-layout { grid-template-columns: 1fr !important; gap: 2rem !important; }
    .product-gallery { position: relative !important; top: 0 !important; width: 100% !important; display: block !important; }
    .product-img-main { width: 100% !important; height: auto !important; max-height: 450px; object-fit: cover; }
    .grid, .grid-catalogue { grid-template-columns: 1fr !important; gap: 1.5rem !important; padding: 0 !important; }
    .cart-item { flex-direction: column; align-items: flex-start; gap: 1.5rem; }
    .cart-item > div:last-child { width: 100%; display: flex; flex-direction: column; gap: 1rem; }
    
    /* Tighten bottom margins explicitly on mobile to avoid excessive white space */
    footer {
        margin-top: 2rem !important;
        padding: 2rem 5% !important;
    }
}

/* =========================================
   11. PRINT OVERLAYS
   ========================================= */
@media print {
    body { background: #ffffff; color: #000000; font-size: 12pt; }
    header, footer, .btn, .qty-controls, .menu-toggle, #toast-container, .filter-container { display: none !important; }
    main { padding: 0; margin: 0; width: 100%; }
    .cart-item { border: none; border-bottom: 1px solid #000000; padding: 1rem 0; }
}

/* =========================================
   12. MOTION ACCESSIBILITY DEFAULTS
   ========================================= */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}