/* ==========================================================
   UNIVERSAL PREMIUM RESPONSIVE FOUNDATION
   HTML / CSS / Vanilla JS

   Loaded in a cascade layer so each page's existing visual
   system can intentionally override these baseline utilities.
   ========================================================== */

@layer foundation {
    /* ==========================================================
       1. DESIGN TOKENS
       ========================================================== */

    :root {
        --container-xs: 720px;
        --container-sm: 960px;
        --container-md: 1200px;
        --container-lg: 1440px;

        --page-padding: clamp(1.25rem, 4vw, 4rem);

        --section-space-sm: clamp(3.5rem, 6vw, 5rem);
        --section-space-md: clamp(5rem, 8vw, 8rem);
        --section-space-lg: clamp(6rem, 10vw, 10rem);

        --space-xs: clamp(0.5rem, 1vw, 0.75rem);
        --space-sm: clamp(0.75rem, 1.5vw, 1rem);
        --space-md: clamp(1rem, 2vw, 1.5rem);
        --space-lg: clamp(1.5rem, 3vw, 2.5rem);
        --space-xl: clamp(2rem, 5vw, 4rem);

        --text-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.875rem);
        --text-sm: clamp(0.875rem, 0.84rem + 0.15vw, 1rem);
        --text-base: clamp(1rem, 0.96rem + 0.2vw, 1.125rem);
        --text-lg: clamp(1.125rem, 1.05rem + 0.35vw, 1.375rem);

        --h6-size: clamp(1rem, 0.95rem + 0.25vw, 1.25rem);
        --h5-size: clamp(1.125rem, 1rem + 0.5vw, 1.5rem);
        --h4-size: clamp(1.25rem, 1.05rem + 0.8vw, 1.75rem);
        --h3-size: clamp(1.5rem, 1.15rem + 1.3vw, 2.5rem);
        --h2-size: clamp(2rem, 1.3rem + 2.5vw, 4rem);
        --h1-size: clamp(2.75rem, 1.5rem + 4.5vw, 6.5rem);

        --radius-sm: 0.5rem;
        --radius-md: 0.875rem;
        --radius-lg: 1.25rem;
        --radius-xl: 2rem;

        --header-height: 80px;

        --transition-fast: 180ms ease;
        --transition-normal: 300ms cubic-bezier(.2, .8, .2, 1);
    }

    /* ==========================================================
       2. MODERN RESET
       ========================================================== */

    *,
    *::before,
    *::after {
        box-sizing: border-box;
    }

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

    body {
        margin: 0;
        min-height: 100vh;
        overflow-x: hidden;
        font-synthesis: none;
        text-rendering: optimizeLegibility;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6,
    p,
    figure,
    blockquote,
    dl,
    dd {
        margin: 0;
    }

    ul,
    ol {
        margin: 0;
        padding: 0;
    }

    button,
    input,
    textarea,
    select {
        font: inherit;
    }

    button {
        border: 0;
    }

    a {
        color: inherit;
        text-decoration: none;
    }

    /* ==========================================================
       3. MEDIA
       ========================================================== */

    img,
    picture,
    video,
    canvas,
    svg {
        display: block;
        max-width: 100%;
    }

    img,
    video {
        height: auto;
    }

    img {
        object-fit: cover;
    }

    iframe {
        display: block;
        max-width: 100%;
        border: 0;
    }

    /* ==========================================================
       4. GLOBAL TYPOGRAPHY
       ========================================================== */

    body {
        font-size: var(--text-base);
        line-height: 1.6;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        line-height: 1.08;
        text-wrap: balance;
    }

    h1 {
        font-size: var(--h1-size);
        letter-spacing: -0.045em;
    }

    h2 {
        font-size: var(--h2-size);
        letter-spacing: -0.035em;
    }

    h3 {
        font-size: var(--h3-size);
        letter-spacing: -0.025em;
    }

    h4 {
        font-size: var(--h4-size);
    }

    h5 {
        font-size: var(--h5-size);
    }

    h6 {
        font-size: var(--h6-size);
    }

    p {
        font-size: var(--text-base);
        line-height: 1.65;
        text-wrap: pretty;
    }

    small {
        font-size: var(--text-sm);
    }

    p,
    li,
    blockquote {
        max-width: 75ch;
    }

    /* ==========================================================
       5. RESPONSIVE CONTAINERS
       ========================================================== */

    .container {
        width: min(calc(100% - (var(--page-padding) * 2)), var(--container-md));
        margin-inline: auto;
    }

    .container-sm {
        width: min(calc(100% - (var(--page-padding) * 2)), var(--container-sm));
        margin-inline: auto;
    }

    .container-lg {
        width: min(calc(100% - (var(--page-padding) * 2)), var(--container-lg));
        margin-inline: auto;
    }

    .container-fluid {
        width: 100%;
        padding-inline: var(--page-padding);
    }

    /* ==========================================================
       6. SECTIONS
       ========================================================== */

    section {
        position: relative;
        padding-block: var(--section-space-md);
    }

    .section-sm {
        padding-block: var(--section-space-sm);
    }

    .section-lg {
        padding-block: var(--section-space-lg);
    }

    /* ==========================================================
       7. UNIVERSAL GRID SYSTEM
       ========================================================== */

    .grid {
        display: grid;
        gap: var(--space-lg);
    }

    .grid-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .grid-4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .auto-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
        gap: var(--space-lg);
    }

    /* ==========================================================
       8. FLEX UTILITIES
       ========================================================== */

    .flex {
        display: flex;
    }

    .flex-center {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .flex-between {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .flex-wrap {
        flex-wrap: wrap;
    }

    /* ==========================================================
       9. TWO-COLUMN CONTENT LAYOUTS
       ========================================================== */

    .split-layout,
    .two-column {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        align-items: center;
        gap: clamp(2.5rem, 6vw, 7rem);
    }

    .split-layout--wide {
        grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    }

    /* ==========================================================
       10. CARDS
       ========================================================== */

    .card {
        min-width: 0;
        border-radius: var(--radius-lg);
        overflow: hidden;
    }

    /* ==========================================================
       11. BUTTONS
       ========================================================== */

    .btn,
    .main-btn,
    button,
    input[type="submit"] {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 48px;
        padding: 0.8rem clamp(1.25rem, 2vw, 1.75rem);
        line-height: 1.1;
        cursor: pointer;
        transition: transform var(--transition-fast), opacity var(--transition-fast);
    }

    @media (hover: hover) and (pointer: fine) {
        .btn:hover,
        .main-btn:hover {
            transform: translateY(-2px);
        }
    }

    /* ==========================================================
       12. FORM ELEMENTS
       ========================================================== */

    input,
    textarea,
    select {
        width: 100%;
        max-width: 100%;
    }

    textarea {
        resize: vertical;
    }

    /* ==========================================================
       13. RESPONSIVE TABLES
       ========================================================== */

    .table-wrapper {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        width: 100%;
        border-collapse: collapse;
    }

    /* ==========================================================
       14. VISIBILITY UTILITIES
       ========================================================== */

    .mobile-only {
        display: none;
    }

    .desktop-only {
        display: initial;
    }

    /* ==========================================================
       15. TEXT UTILITIES
       ========================================================== */

    .text-center {
        text-align: center;
    }

    .text-left {
        text-align: left;
    }

    .text-right {
        text-align: right;
    }

    .text-balance {
        text-wrap: balance;
    }

    .text-pretty {
        text-wrap: pretty;
    }

    /* ==========================================================
       16. ACCESSIBILITY
       ========================================================== */

    :focus-visible {
        outline: 2px solid currentColor;
        outline-offset: 4px;
    }

    [hidden] {
        display: none !important;
    }

    [id] {
        scroll-margin-top: calc(var(--header-height) + 2rem);
    }

    /* ==========================================================
       17. LARGE DESKTOP
       ========================================================== */

    @media (min-width: 1440px) {
        :root {
            --page-padding: clamp(3rem, 4vw, 5rem);
        }
    }

    /* ==========================================================
       18. LAPTOP
       ========================================================== */

    @media (max-width: 1200px) {
        :root {
            --page-padding: clamp(1.5rem, 3vw, 2.5rem);
        }

        .grid-4 {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }
    }

    /* ==========================================================
       19. TABLET
       ========================================================== */

    @media (max-width: 1024px) {
        :root {
            --section-space-md: clamp(4.5rem, 8vw, 6rem);
            --section-space-lg: clamp(5rem, 9vw, 7rem);
        }

        .grid-3 {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }

        .split-layout,
        .split-layout--wide,
        .two-column {
            gap: clamp(2rem, 5vw, 4rem);
        }
    }

    /* ==========================================================
       20. TABLET / MOBILE
       ========================================================== */

    @media (max-width: 768px) {
        :root {
            --page-padding: clamp(1rem, 5vw, 1.5rem);
            --section-space-sm: 3.5rem;
            --section-space-md: 4.5rem;
            --section-space-lg: 5.5rem;
            --header-height: 72px;
        }

        .grid-2,
        .grid-3,
        .grid-4,
        .two-column,
        .split-layout,
        .split-layout--wide {
            grid-template-columns: minmax(0, 1fr);
        }

        .desktop-only {
            display: none !important;
        }

        .mobile-only {
            display: initial;
        }

        .mobile-stack {
            flex-direction: column;
            align-items: stretch;
        }

        .mobile-center {
            text-align: center;
        }

        .mobile-full-image {
            width: 100%;
        }
    }

    /* ==========================================================
       21. MOBILE
       ========================================================== */

    @media (max-width: 600px) {
        :root {
            --section-space-sm: 3rem;
            --section-space-md: 4rem;
            --section-space-lg: 4.5rem;
        }

        .grid,
        .auto-grid {
            gap: clamp(1rem, 4vw, 1.5rem);
        }

        .mobile-full-width {
            width: 100%;
        }
    }

    /* ==========================================================
       22. SMALL MOBILE
       ========================================================== */

    @media (max-width: 480px) {
        :root {
            --page-padding: 1rem;
            --h1-size: clamp(2.25rem, 11vw, 3.25rem);
            --h2-size: clamp(1.875rem, 8vw, 2.5rem);
            --section-space-md: 3.5rem;
        }

        .btn,
        .main-btn,
        button,
        input[type="submit"] {
            min-height: 48px;
        }

        .mobile-buttons-full .btn,
        .mobile-buttons-full .main-btn {
            width: 100%;
        }

        .card {
            border-radius: var(--radius-md);
        }
    }

    /* ==========================================================
       23. VERY SMALL MOBILE
       ========================================================== */

    @media (max-width: 360px) {
        :root {
            --page-padding: 0.875rem;
        }
    }

    /* ==========================================================
       24. LANDSCAPE MOBILE
       ========================================================== */

    @media (max-height: 500px) and (orientation: landscape) {
        section {
            padding-block: 3rem;
        }
    }

    /* ==========================================================
       25. TOUCH DEVICES
       ========================================================== */

    @media (hover: none) and (pointer: coarse) {
        .btn,
        .main-btn,
        button,
        a {
            -webkit-tap-highlight-color: transparent;
        }
    }

    /* ==========================================================
       26. REDUCED MOTION ACCESSIBILITY
       ========================================================== */

    @media (prefers-reduced-motion: reduce) {
        html {
            scroll-behavior: auto;
        }

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

    /* ==========================================================
       27. HIGH-RESOLUTION / PRINT SAFETY
       ========================================================== */

    @media print {
        *,
        *::before,
        *::after {
            background: transparent !important;
            box-shadow: none !important;
            text-shadow: none !important;
        }

        nav,
        footer,
        .no-print {
            display: none !important;
        }

        body {
            overflow: visible;
        }
    }
}
