/* ═══════════════════════════════════════════════════════════════════════════
 * Adam Demos Foundation — global responsive safety net
 *
 * Linked LAST on every page so its rules win the cascade. Fixes layout
 * distortion at narrow viewports (≤768 / ≤480 / ≤360 px) without forcing us
 * to touch each page's bespoke styles.
 *
 * Strategy:
 *   1. Stop horizontal overflow at the root and on common containers
 *   2. Make all media (img, svg, video, iframe) shrink to fit
 *   3. Force long words / URLs / inline-code to wrap instead of pushing layout
 *   4. Convert multi-column grids to single column on phones
 *   5. Tame oversized decorative pieces (hero shapes, bg circles, particles)
 *   6. Reduce hero/headline type so it never overflows the viewport
 *   7. Trim section padding so cards don't get clipped on tiny screens
 * ═══════════════════════════════════════════════════════════════════════════ */

/* ─── 1. Stop horizontal overflow ─── */
html, body {
    max-width: 100% !important;
    overflow-x: hidden !important;
}

/* ─── 2. Responsive media ─── */
img, svg, video, iframe, canvas {
    max-width: 100%;
    height: auto;
}
img { display: inline-block; }

/* SVG with explicit width/height attributes (logos, icons) — leave intrinsic
 * sizes alone so they don't blow out, but still shrink-to-fit if needed.
 */
svg[width][height] { max-width: 100%; }

/* ─── 3. Word wrapping (no overflow from long URLs / emails / monospace) ─── */
p, h1, h2, h3, h4, h5, h6, li, a, td, code, pre, label {
    overflow-wrap: anywhere;
    word-break: normal;
}
pre, code {
    white-space: pre-wrap;
    word-break: break-word;
}

/* ─── 4. Tablets and below (≤ 1024px) ─── */
@media (max-width: 1024px) {
    .container, .nav-container, .footer-grid, .hero-content {
        padding-left: 20px;
        padding-right: 20px;
    }
}

/* ─── 5. Phones / narrow tablets (≤ 768px) ─── */
@media (max-width: 768px) {
    /* Force every common multi-col grid into one column on phones */
    .programs-grid, .testimonials-grid, .get-involved-grid, .news-grid,
    .impact-cards, .impact-progress-section, .team-grid, .footer-grid,
    .contact-grid, .why-grid, .featured-grid, .stats-grid, .partners-grid,
    .reports-grid, .legacy-grid, .faq-grid, .dash-stats, .dash-projects-grid,
    .dash-proof-grid, .dash-giving-row, .form-row, .video-grid {
        grid-template-columns: 1fr !important;
    }

    /* Section padding tighter on phones */
    section {
        padding-left: 16px;
        padding-right: 16px;
    }
    .container { padding-left: 16px; padding-right: 16px; }

    /* Tame hero typography that's set in px on the desktop layout */
    .hero h1, .hero-title, .page-hero h1 {
        font-size: clamp(28px, 8vw, 44px) !important;
        line-height: 1.15 !important;
    }
    .section-headline, .donation-wrapper h2,
    .impact-left h2, .video-text h2 {
        font-size: clamp(24px, 6vw, 34px) !important;
        line-height: 1.2 !important;
    }
    .hero-sub, .section-subtitle {
        font-size: clamp(15px, 4vw, 17px) !important;
    }

    /* Buttons stack and grow on phones */
    .hero-buttons, .cta-row {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    .hero-buttons > *, .cta-row > * {
        width: 100%;
        justify-content: center;
        text-align: center;
    }

    /* Hide / shrink decorative hero shapes that cause horizontal scroll */
    .hero-shape, .hero-shape-1, .hero-shape-2, .hero-shape-3,
    .decorative-circle, .bg-circle, .floating-shape {
        display: none !important;
    }

    /* Particle canvas — keep but cap so it can't push layout wider than viewport */
    #hero-canvas, .particle-canvas {
        max-width: 100vw !important;
    }

    /* Tables → block on phones (forms, donation tables, etc.) */
    .donation-table, .donation-history-table, .receipt-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Common nav patterns — hide desktop nav lists, leave hamburgers alone */
    .nav-center, .nav-links-desktop, .nav-donate-desktop, .nav-signin-desktop {
        display: none !important;
    }
    .hamburger { display: block !important; }

    /* Cards / pills should never overflow their wrapper */
    .program-card, .testimonial-card, .news-card, .impact-card,
    .involve-card, .team-card, .dash-stat-card, .dash-project-card,
    .dash-proof-card, .partner-card, .report-card, .faq-item {
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
    }

    /* Auth modal full-width on phones */
    .auth-modal, .modal-card, .donation-modal {
        max-width: calc(100vw - 24px) !important;
        margin: 12px;
    }

    /* Footer pads */
    .footer, .main-footer { padding: 48px 16px 24px !important; }
}

/* ─── 6. Small phones (≤ 480px) ─── */
@media (max-width: 480px) {
    .stats-bar .container, .stats-row, .dash-stats {
        grid-template-columns: 1fr 1fr !important;
    }

    /* Reduce big numbers so they don't push the layout */
    .stat-number, .impact-card-number, .dash-stat-value, .progress-ring-text {
        font-size: clamp(22px, 7vw, 32px) !important;
    }

    /* Section paddings tighter */
    section, .section { padding-top: 56px !important; padding-bottom: 56px !important; }

    /* Forms full width */
    .donation-form, .contact-form-card, .auth-form, .signin-form {
        padding: 20px !important;
    }
    .form-group label { font-size: 13px; }
    .form-group input, .form-group textarea, .form-group select {
        font-size: 16px !important; /* prevents iOS zoom-on-focus */
    }

    /* Hero buttons full-width */
    .btn-primary, .btn-secondary, .btn-hero-primary, .btn-hero-secondary,
    .btn-gold, .btn-navy, .btn-outline-navy, .nav-donate {
        width: 100%;
        justify-content: center;
    }

    /* Logo + wordmark — hide tagline-only line on tightest widths */
    .nav-logo-sub, .footer-tagline { display: none; }
    .nav-logo-name { font-size: 14px !important; }
}

/* ─── 7. Tiny phones (≤ 360px) — Galaxy Fold, older Android ─── */
@media (max-width: 360px) {
    .container, section, .container { padding-left: 12px !important; padding-right: 12px !important; }
    .hero h1 { font-size: 26px !important; }
    .section-headline { font-size: 22px !important; }
    .nav-logo-name { font-size: 13px !important; }
    .stat-number, .impact-card-number, .dash-stat-value { font-size: 22px !important; }
    .stats-bar .container, .stats-row, .dash-stats {
        grid-template-columns: 1fr !important;
    }
}

/* ─── 8. 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;
        scroll-behavior: auto !important;
    }
}
