/* ========================================================
   GLOBAL BULLETPROOF SCROLL & LAYOUT ENGINE (OPENSEO)
   Ensures ALL pages (Dashboard, GSC, Settings, Audit, etc.)
   scroll completely and smoothly on all devices.
======================================================== */
html, body {
    touch-action: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: auto !important;
}

/* Ensure sidebar-wrapper strictly matches viewport height */
[data-slot="sidebar-wrapper"] {
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
}

/* Sidebar inset (main area) must flex-fill and not overflow viewport */
main[data-slot="sidebar-inset"],
[data-slot="sidebar-inset"] {
    height: 100% !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
    overflow: hidden !important;
}

/* The primary page scroll container inside main */
main[data-slot="sidebar-inset"] > div.flex-1,
[data-slot="sidebar-inset"] > div.flex-1,
main[data-slot="sidebar-inset"] > div.overflow-auto,
[data-slot="sidebar-inset"] > div.overflow-auto {
    flex: 1 1 0% !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: 100% !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: auto !important;
    touch-action: pan-y !important;
    scrollbar-gutter: stable;
    scrollbar-width: thin !important;
    scrollbar-color: #cbd5e1 rgba(0, 0, 0, 0.04) !important;
}

/* ALL direct child views (Dashboard, Search Performance, Settings, Audit, etc.)
   must expand naturally to their full content height and NEVER trap vertical scrolling */
main[data-slot="sidebar-inset"] > div.flex-1 > div,
[data-slot="sidebar-inset"] > div.flex-1 > div,
main[data-slot="sidebar-inset"] > div.overflow-auto > div,
[data-slot="sidebar-inset"] > div.overflow-auto > div {
    height: auto !important;
    min-height: min-content !important;
    max-height: none !important;
    overflow-y: visible !important;
}

/* Ensure nested elements with overflow-auto inside the view don't create vertical deadlocks */
main[data-slot="sidebar-inset"] > div.flex-1 div.h-full.overflow-auto,
[data-slot="sidebar-inset"] > div.flex-1 div.h-full.overflow-auto {
    height: auto !important;
    min-height: min-content !important;
    overflow-y: visible !important;
}

/* Sleek modern visible scrollbar for Webkit/Chrome/Edge/Brave/Safari */
main[data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar,
[data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar,
main[data-slot="sidebar-inset"] > div.overflow-auto::-webkit-scrollbar,
[data-slot="sidebar-inset"] > div.overflow-auto::-webkit-scrollbar {
    width: 9px !important;
    height: 9px !important;
    display: block !important;
}

main[data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar-track,
[data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar-track,
main[data-slot="sidebar-inset"] > div.overflow-auto::-webkit-scrollbar-track,
[data-slot="sidebar-inset"] > div.overflow-auto::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.04) !important;
    border-radius: 6px !important;
}

main[data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar-thumb,
[data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar-thumb,
main[data-slot="sidebar-inset"] > div.overflow-auto::-webkit-scrollbar-thumb,
[data-slot="sidebar-inset"] > div.overflow-auto::-webkit-scrollbar-thumb {
    background: #cbd5e1 !important;
    border-radius: 6px !important;
    border: 2px solid transparent !important;
    background-clip: content-box !important;
}

main[data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar-thumb:hover,
[data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar-thumb:hover,
main[data-slot="sidebar-inset"] > div.overflow-auto::-webkit-scrollbar-thumb:hover,
[data-slot="sidebar-inset"] > div.overflow-auto::-webkit-scrollbar-thumb:hover {
    background: #94a3b8 !important;
    background-clip: content-box !important;
}

/* Dark mode scrollbars */
html[data-theme="openseo-dark"] main[data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar-track,
html[data-theme="openseo-dark"] [data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.04) !important;
}

html[data-theme="openseo-dark"] main[data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar-thumb,
html[data-theme="openseo-dark"] [data-slot="sidebar-inset"] > div.flex-1::-webkit-scrollbar-thumb {
    background: #475569 !important;
    background-clip: content-box !important;
}


/* Spacing and gap between OpenSEO sidebar and Auto SEO Writer frame */
div:has(> iframe#asw-writer-frame),
div.p-4.md\:p-6:has(> iframe#asw-writer-frame) {
    padding: 16px 24px 24px 24px !important;
    box-sizing: border-box !important;
}

iframe#asw-writer-frame {
    display: block !important;
    width: 100% !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    border-radius: 12px !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04) !important;
    background: #ffffff !important;
}

html[data-theme="openseo-dark"] iframe#asw-writer-frame {
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4) !important;
    background: #121214 !important;
}


/* Hide Project Switcher / Selector in Sidebar Header */
[data-slot="sidebar-header"] div.flex.items-stretch.rounded-lg,
[data-slot="sidebar-header"] button[aria-label="Switch project"],
[data-slot="sidebar-header"] div:has(> button[aria-label="Switch project"]),
div:has(> button[aria-label="Switch project"]) {
    display: none !important;
}
