/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE FIXES — Directory of AI
   Breakpoints:
     Mobile:           0 – 639px
     Tablet portrait:  640 – 1023px   (iPad portrait, small tablets)
     Tablet landscape: 1024 – 1279px  (iPad landscape, narrow desktops)
     Desktop:          1280px+
   Ad sidebar cols:    visible ≥1280px only (need room for 160px cols + content)
   ════════════════════════════════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
    --header-height: 60px;
    --container-padding-mobile: 14px;
    --container-padding-tablet: 24px;
    --container-padding-desktop: 20px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   GLOBAL SAFETY
   ═══════════════════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; }
html { overflow-x: clip; }
body { overflow-x: clip; max-width: 100vw; }
img  { max-width: 100%; height: auto; }

/* ═══════════════════════════════════════════════════════════════════════════
   HEADER & NAVIGATION
   ═══════════════════════════════════════════════════════════════════════════ */

/* Mobile header */
@media (max-width: 768px) {
    header {
        position: sticky !important;
        top: 0;
        z-index: 50;
        width: 100%;
    }

    header > div {
        padding: 0 12px !important;
        min-height: 52px !important;
        flex-wrap: nowrap !important;
    }

    .desk-nav { display: none !important; }
    .mob-btn  { display: inline-flex !important; }

    #mob-menu {
        width: 100%;
        padding: 8px 12px;
    }
    #mob-menu a {
        padding: 10px 8px;
        font-size: 14px;
    }

    /* Compact action buttons */
    header a[href*="submit-tool"],
    header a[href*="/sign-in"] {
        padding: 6px 12px !important;
        font-size: 12px !important;
    }
}

/* Tablet header */
@media (min-width: 769px) and (max-width: 1023px) {
    header > div {
        padding: 0 16px !important;
    }
    .desk-nav {
        gap: 0 !important;
    }
    .desk-nav a {
        padding: 5px 8px !important;
        font-size: 13px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   HERO SECTIONS
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    section[style*="padding:80px"],
    section[style*="padding:56px"],
    .ait-hero,
    [class*="hero"] {
        padding: 36px 16px 28px !important;
    }
    
    /* Hero search bar */
    form[role="search"] {
        max-width: 100% !important;
    }
    form[role="search"] input[type="search"] {
        height: 46px !important;
        font-size: 14px !important;
        padding-right: 90px !important;
        padding-left: 38px !important;
    }
    form[role="search"] button[type="submit"] {
        height: 36px !important;
        padding: 0 14px !important;
        font-size: 12px !important;
    }
}

@media (min-width: 640px) and (max-width: 1023px) {
    section[style*="padding:80px"],
    section[style*="padding:56px"],
    .ait-hero,
    [class*="hero"] {
        padding: 48px 24px 36px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   TOOL GRIDS — per-page grid classes
   ═══════════════════════════════════════════════════════════════════════════ */

/* Mobile: 1-col for single-tool pages, 2-col for tool grids on listings */
@media (max-width: 479px) {
    .home-tools-grid,
    .arc-grid,
    .tool-grid,
    .ai-tools-grid {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }
}

@media (min-width: 480px) and (max-width: 767px) {
    .home-tools-grid,
    .arc-grid,
    .tool-grid,
    .ai-tools-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 14px !important;
    }
}

/* Tablet portrait: 2 cols */
@media (min-width: 768px) and (max-width: 1023px) {
    .home-tools-grid,
    .arc-grid,
    .tool-grid,
    .ai-tools-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 18px !important;
    }
}

/* Tablet landscape: 3 cols */
@media (min-width: 1024px) and (max-width: 1279px) {
    .home-tools-grid,
    .arc-grid,
    .tool-grid,
    .ai-tools-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 18px !important;
    }
}

/* Desktop with ad sidebars: 3 cols, narrower content */
@media (min-width: 1280px) {
    .home-tools-grid,
    .arc-grid,
    .tool-grid,
    .ai-tools-grid {
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 20px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   GENERIC GRID OVERRIDES (for inline style grids in templates)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    [style*="grid-template-columns: repeat(3"],
    [style*="grid-template-columns: repeat(4"],
    [style*="grid-template-columns:repeat(3"],
    [style*="grid-template-columns:repeat(4"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns: repeat(2"],
    [style*="grid-template-columns:repeat(2"],
    [style*="grid-template-columns: 2fr 1fr 1fr"],
    [style*="grid-template-columns:2fr 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

@media (min-width: 640px) and (max-width: 1023px) {
    [style*="grid-template-columns: repeat(3"],
    [style*="grid-template-columns:repeat(3"],
    [style*="grid-template-columns: repeat(4"],
    [style*="grid-template-columns:repeat(4"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   INTERCONTENT AD CARDS (mobile/tablet only — sidebar handles desktop)
   These are injected between tool cards on homepage and archive pages.
   ═══════════════════════════════════════════════════════════════════════════ */

/* Default: hidden on desktop where sidebar cols are visible */
.mobile-intercontent-ad {
    display: none !important;
}

/* Show on mobile and tablet (where sidebar cols are hidden) */
@media (max-width: 1279px) {
    .mobile-intercontent-ad {
        display: flex !important;
    }
}

/* On very small screens, make intercontent ads full width */
@media (max-width: 479px) {
    .mobile-intercontent-ad {
        grid-column: 1 / -1 !important;
        max-width: 100% !important;
    }
}

/* On 2-col layouts, ads span full width */
@media (min-width: 480px) and (max-width: 1023px) {
    .mobile-intercontent-ad {
        grid-column: 1 / -1 !important;
        flex-direction: row !important;
        align-items: center !important;
        padding: 14px 16px !important;
    }
    .mobile-intercontent-ad .sdsp-row {
        flex-direction: row !important;
    }
    .mobile-intercontent-ad .sdsp-name {
        font-size: 13px !important;
        text-align: left !important;
    }
    .mobile-intercontent-ad .sdsp-tag {
        font-size: 11px !important;
        text-align: left !important;
    }
    .mobile-intercontent-ad .sdsp-btn {
        width: auto !important;
        padding: 6px 14px !important;
        font-size: 11px !important;
    }
    .mobile-intercontent-ad .sdsp-icon {
        width: 40px !important;
        height: 40px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   AD SIDEBAR COLUMNS — CSS backup for JS positioning
   ═══════════════════════════════════════════════════════════════════════════ */

/* Hide sidebar ad columns below 1280px — not enough room */
@media (max-width: 1279px) {
    .sdsp-col-wrap {
        display: none !important;
    }
    .saasdir-content-col {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   3RD-PARTY AD WRAPS
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .saasdir-3p-ad-wrap,
    [class*="saasdir-3p-fw"] {
        padding: 0 14px !important;
        margin: 16px auto !important;
    }
    .saasdir-3p-desktop-only {
        display: none !important;
    }
}

@media (min-width: 640px) and (max-width: 1023px) {
    .saasdir-3p-ad-wrap,
    [class*="saasdir-3p-fw"] {
        padding: 0 20px !important;
        margin: 20px auto !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   SINGLE TOOL PAGE
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .st-wrap {
        padding: 20px 14px 48px !important;
    }
    .st-header {
        padding: 18px 16px 16px !important;
        border-radius: 14px !important;
    }
    .st-icon {
        width: 56px !important;
        height: 56px !important;
    }
    .st-header h1 {
        font-size: 20px !important;
    }
    .st-content {
        padding: 18px 14px !important;
    }
    .st-bc {
        font-size: 12px !important;
        padding: 0 !important;
    }
    .feat-grid {
        grid-template-columns: 1fr !important;
    }
    .share-bar {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .share-btn {
        justify-content: center !important;
    }
}

@media (min-width: 640px) and (max-width: 1023px) {
    .st-wrap {
        padding: 24px 20px 56px !important;
    }
    .st-grid {
        grid-template-columns: 1fr !important;
    }
    .st-sidebar {
        display: none !important;
    }
    .st-mobile-cta {
        display: block !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   FORMS — TOUCH-FRIENDLY
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 10px 12px;
        border-radius: 8px;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   FILTER BAR (archive pages)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .ait-filter-wrap {
        padding: 0 12px !important;
    }
    .ait-filter-inner {
        gap: 3px !important;
        padding: 8px 0 !important;
    }
    .ait-tab {
        padding: 5px 10px !important;
        font-size: 11.5px !important;
    }
    .arc-filter-bar {
        flex-direction: column !important;
        gap: 8px !important;
        align-items: stretch !important;
    }
    .arc-filter-bar select,
    .arc-filter-bar input {
        width: 100% !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   SECTION PADDING
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    /* Only target main content sections, not embedded sections */
    main > section,
    .saasdir-content-col > section {
        padding-left: 14px !important;
        padding-right: 14px !important;
    }
}

@media (min-width: 640px) and (max-width: 1023px) {
    main > section,
    .saasdir-content-col > section {
        padding-left: 24px !important;
        padding-right: 24px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   FOOTER
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    footer {
        padding: 32px 14px 20px !important;
    }
    .footer-grid {
        grid-template-columns: 1fr !important;
        gap: 24px !important;
    }
    footer a, footer p {
        font-size: 13px !important;
    }
}

@media (min-width: 640px) and (max-width: 1023px) {
    footer {
        padding: 40px 24px 24px !important;
    }
    .footer-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 28px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   TABLES — stack on mobile
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    table { font-size: 13px; }
    table thead { display: none; }
    table tbody, table tr { display: block; width: 100%; }
    table tr {
        margin-bottom: 12px;
        border-bottom: 1px solid #e5e7eb;
        padding-bottom: 12px;
    }
    table td {
        display: block;
        width: 100%;
        padding: 6px 0;
        text-align: left;
    }
    table td::before {
        content: attr(data-label);
        font-weight: 600;
        display: inline-block;
        width: 40%;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   VIDEOS — responsive embed
   ═══════════════════════════════════════════════════════════════════════════ */

.video-container,
[class*="video-embed"] {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    height: 0;
    overflow: hidden;
}
.video-container iframe {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
}

/* ═══════════════════════════════════════════════════════════════════════════
   PAGE-ADS / SPONSOR PAGE — placement grids
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .placement-grid,
    .benefits-grid,
    .feature-grid {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }
}

@media (min-width: 640px) and (max-width: 1023px) {
    .placement-grid,
    .benefits-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px !important;
    }
    .feature-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 16px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   SPONSOR PAGE — login gate
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .sp-login-box {
        padding: 24px 16px !important;
        margin: 0 14px !important;
        max-width: 100% !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════════════════ */

.hide-mobile { display: none; }
@media (min-width: 768px) {
    .hide-mobile    { display: block; }
    .show-mobile-only { display: none; }
}
.show-mobile-only { display: block; }

/* ═══════════════════════════════════════════════════════════════════════════
   CONTAINER WIDTH SAFETY (prevents content wider than viewport)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .saasdir-content-col > *,
    main > *,
    [style*="max-width:1280px"],
    [style*="max-width: 1280px"] {
        max-width: 100vw !important;
        box-sizing: border-box !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   BANNER ADS (full-width between sections)
   ═══════════════════════════════════════════════════════════════════════════ */

.ads-banner-section {
    width: 100%;
    padding: 16px;
    margin: 20px 0;
    background: linear-gradient(135deg, rgba(242,100,25,.05), rgba(242,100,25,.02));
    border: 1px solid rgba(242,100,25,.15);
    border-radius: 12px;
    box-sizing: border-box;
}

.ads-banner-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
}

@media (min-width: 640px) {
    .ads-banner-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
}
@media (min-width: 1024px) {
    .ads-banner-grid { grid-template-columns: repeat(3, 1fr); gap: 20px; }
}

.banner-ad-card {
    padding: 14px;
    background: #fff;
    border: 1.5px dashed rgba(242,100,25,.3);
    border-radius: 10px;
    text-align: center;
    transition: all .3s;
}
.banner-ad-card:hover {
    border-color: #F26419;
    box-shadow: 0 4px 12px rgba(242,100,25,.1);
}
.banner-ad-icon {
    width: 50px; height: 50px;
    margin: 0 auto 10px;
    border-radius: 10px;
    object-fit: cover;
}
.banner-ad-label {
    font-size: 11px; font-weight: 600;
    color: #F26419; text-transform: uppercase;
    letter-spacing: .05em; margin-bottom: 6px;
}
.banner-ad-name {
    font-size: 14px; font-weight: 600;
    color: #111; margin-bottom: 4px;
}
.banner-ad-desc {
    font-size: 12px; color: #6b7280;
    margin-bottom: 10px; line-height: 1.4;
}
.banner-ad-btn {
    display: inline-block;
    padding: 8px 16px;
    background: #F26419; color: #fff;
    border: none; border-radius: 6px;
    font-size: 12px; font-weight: 600;
    text-decoration: none; cursor: pointer;
}
.banner-ad-btn:hover { background: #d9540e; }

/* ═══════════════════════════════════════════════════════════════════════════
   PAGINATION
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .ait-page-link {
        min-width: 32px !important;
        height: 32px !important;
        padding: 0 8px !important;
        font-size: 12px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   SCREENSHOT GALLERY (single tool)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .shot-main-wrap img { border-radius: 10px; }
    .shot-thumb-strip {
        gap: 6px !important;
        padding-bottom: 6px !important;
    }
    .shot-thumb-btn {
        width: 70px !important;
        height: 46px !important;
        border-radius: 7px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   iPad PORTRAIT-SPECIFIC (768×1024)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (min-width: 768px) and (max-width: 1023px) and (orientation: portrait) {
    /* Ensure content fills width nicely */
    .saasdir-content-col {
        padding: 0 !important;
    }

    /* Category filter scrolls horizontally */
    .ait-filter-inner {
        padding: 10px 0;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   iPad LANDSCAPE-SPECIFIC (1024×768)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (min-width: 1024px) and (max-width: 1279px) and (orientation: landscape) {
    /* No ad sidebars here — full width content */
    .saasdir-content-col {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   CLAIM / CTA BANNERS
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    .claim-banner {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        padding: 14px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   COMPARISON / ALTERNATIVES PAGES
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 639px) {
    [style*="grid-template-columns: 1fr 60px 1fr"],
    [style*="grid-template-columns:1fr 60px 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
}
