/* ============================================
   PLUS B RESPONSIVE CSS
   Comprehensive mobile optimization for all pages
   ============================================ */

/* ============================================
   MOBILE DEVICES (max-width: 768px)
   ============================================ */

@media (max-width: 768px) {
    /* ===================
       WORKSPACE 
       =================== */
    
    /* Mobile Sidebar Drawer */
    #sidebar {
        position: fixed;
        height: 100vh;
        z-index: 50;
        box-shadow: 20px 0 50px rgba(0,0,0,0.5);
    }
    
    #sidebar.open {
        transform: translateX(0);
    }

    #sidebar-overlay.active {
        display: block;
        animation: fadeIn 0.3s forwards;
    }

    /* Input area adjustments for mobile keyboard */
    #chat-input {
        font-size: 16px !important; /* Prevent iOS zoom */
    }
    
    /* Hide some elements on mobile */
    .hidden-mobile {
        display: none !important;
    }
    
    /* Sidebar Brand Bar - Hide on mobile (redundant with mobile header) */
    #sidebar > .h-16:first-child {
        display: none !important;
    }
    
    /* Sidebar - Reorder for mobile: Account at top */
    #sidebar {
        display: flex;
        flex-direction: column;
    }
    
    /* Move account section to top on mobile */
    #sidebar > .p-4.border-t {
        order: -1;
        border-top: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        padding-top: 1rem;
        overflow: visible;
    }

    /* Profile menu should open downward on mobile (account block is moved to top) */
    #sidebar #profile-menu {
        top: calc(100% + 0.5rem);
        bottom: auto;
        left: 0.75rem;
        right: 0.75rem;
        margin-bottom: 0;
        max-height: calc(100vh - 7rem);
        overflow-y: auto;
    }
    
    /* Adjust experts navigation to fill remaining space */
    #sidebar > .flex-1.overflow-y-auto {
        order: 1;
        padding-top: 0.5rem;
    }
    
    /* PPT Settings Panel - Full Width */
    #ppt-config-panel {
        width: calc(100vw - 32px) !important;
        max-width: none !important;
        left: 16px !important;
        right: 16px !important;
        top: auto !important;
        bottom: 80px !important;
        max-height: 70vh !important;
        overflow-y: auto !important;
    }
    
    /* Image Settings Panel - Full Width */
    #image-settings-panel {
        width: calc(100vw - 32px) !important;
        max-width: none !important;
        left: 16px !important;
        right: 16px !important;
    }
    
    /* Slide Grid - 2 columns on mobile */
    .grid.grid-cols-2 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Slide Modal - Single Column Layout */
    #slide-modal .grid.lg\:grid-cols-3 {
        grid-template-columns: 1fr !important;
        height: auto !important;
        max-height: 90vh !important;
    }
    
    #slide-modal .lg\:col-span-2 {
        min-height: 40vh !important;
        max-height: 50vh !important;
    }
    
    /* Message Containers */
    .message-content {
        max-width: 100% !important;
    }
    
    /* Code Canvas */
    .code-canvas {
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    /* ===================
       INDEX / LANDING PAGE 
       =================== */
    
    /* Hero Section */
    section.min-h-screen {
        padding-top: 6rem !important;
        padding-bottom: 4rem !important;
    }
    
    /* Bento Grid - Single Column */
    .grid.md\:grid-cols-4.md\:grid-rows-3 {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
        height: auto !important;
    }
    
    .grid.md\:grid-cols-4.md\:grid-rows-3 > div {
        grid-column: span 1 !important;
        grid-row: span 1 !important;
        min-height: 200px !important;
    }
    
    /* Bento Cards Padding */
    .bento-card {
        padding: 1.5rem !important;
        border-radius: 24px !important;
    }
    
    /* Marquee Badges */
    .animate-scroll .px-6 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    .animate-scroll .py-3 {
        padding-top: 0.5rem !important;
        padding-bottom: 0.5rem !important;
    }
    
    .animate-scroll .text-sm {
        font-size: 0.75rem !important;
    }
    
    /* FAQ Grid - Single Column */
    .grid.md\:grid-cols-2.gap-8 {
        grid-template-columns: 1fr !important;
    }
    
    /* Pricing Section Card */
    .glass-strong.rounded-\[48px\] {
        border-radius: 24px !important;
        padding: 2rem !important;
    }
    
    /* Target Audience Grid - Single Column */
    .grid.md\:grid-cols-4.gap-6 {
        grid-template-columns: 1fr !important;
    }
    
    /* Footer */
    footer .flex.md\:flex-row {
        flex-direction: column !important;
    }
    
    footer .flex.gap-16 {
        gap: 2rem !important;
    }
    
    /* ===================
       SUBSCRIPTION PAGE 
       =================== */
    
    /* Pricing Grid - Single Column */
    .grid.md\:grid-cols-4.gap-6.items-stretch {
        grid-template-columns: 1fr !important;
    }
    
    /* Pro Card - Remove Vertical Offset */
    .md\:-translate-y-6 {
        transform: none !important;
    }
    
    /* Comparison Table - Scrollable */
    .glass.rounded-2xl.overflow-hidden {
        overflow-x: auto !important;
    }
    
    .grid.grid-cols-3 {
        min-width: 400px !important;
    }
    
    /* ===================
       EXPERTS PAGE 
       =================== */
    
    /* Experts Grid - Single Column */
    .grid.md\:grid-cols-2.lg\:grid-cols-3 {
        grid-template-columns: 1fr !important;
    }
    
    /* Expert Cards - Full Width */
    .card-wrapper.lg\:col-span-2 {
        grid-column: span 1 !important;
    }
    
    /* Hero Text Sizing */
    .hero-text {
        font-size: 2.5rem !important;
        line-height: 1 !important;
    }
    
    /* Expert Card Content */
    .tilt-card {
        padding: 1.5rem !important;
        border-radius: 24px !important;
    }
    
    .tilt-card .card-content {
        flex-direction: column !important;
    }
    
    /* ===================
       AUTH PAGES (Login/Signup)
       =================== */
    
    .w-full.max-w-md.p-6 {
        padding: 1rem !important;
    }
    
    .glass-strong.rounded-\[24px\].p-6 {
        padding: 1.5rem !important;
    }
}

/* ============================================
   SMALL MOBILE DEVICES (max-width: 480px)
   ============================================ */

@media (max-width: 480px) {
    /* Smaller Padding Everywhere */
    .px-6 {
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    /* ===================
       WORKSPACE 
       =================== */
    
    /* Slide Grid - Single Column on very small screens */
    .grid.grid-cols-2 {
        grid-template-columns: 1fr !important;
    }
    
    /* ===================
       LANDING PAGE 
       =================== */
    
    /* Hero Heading */
    h1.text-\[2rem\] {
        font-size: 1.75rem !important;
    }
    
    /* Subheading */
    p.text-sm {
        font-size: 0.875rem !important;
    }
    
    /* CTA Buttons */
    .flex.sm\:flex-row.gap-3 a,
    .flex.sm\:flex-row.gap-3 button {
        width: 100% !important;
    }
    
    /* Bento Cards - Minimal Padding */
    .bento-card {
        padding: 1rem !important;
    }
    
    .bento-card h3 {
        font-size: 1.25rem !important;
    }
    
    /* ===================
       SUBSCRIPTION PAGE 
       =================== */
    
    /* Pricing Cards */
    .glass.rounded-\[28px\] {
        border-radius: 20px !important;
        padding: 1.25rem !important;
    }
    
    /* Price Text */
    .text-4xl.font-bold {
        font-size: 2rem !important;
    }
    
    .text-5xl.font-extrabold {
        font-size: 2.5rem !important;
    }
    
    /* ===================
       EXPERTS PAGE 
       =================== */
    
    .hero-text {
        font-size: 2rem !important;
    }
    
    .tilt-card .text-5xl {
        font-size: 2rem !important;
    }
    
    .tilt-card .text-4xl {
        font-size: 1.5rem !important;
    }
    
    /* ===================
       MODALS
       =================== */
    
    #slide-modal > div {
        margin: 0.5rem !important;
        max-height: 95vh !important;
    }
}

/* ============================================
   TABLET DEVICES (769px - 1024px)
   ============================================ */

@media (min-width: 769px) and (max-width: 1024px) {
    /* ===================
       WORKSPACE 
       =================== */
    
    /* Sidebar - Icon Only Mode */
    #sidebar {
        width: 80px;
    }
    
    #sidebar .sidebar-text,
    #sidebar .sidebar-label,
    #sidebar .app-link span,
    #sidebar .text-xs,
    #sidebar .truncate {
        display: none;
    }

    #sidebar .h-16 {
        justify-content: center;
        padding: 0;
    }
    
    .app-link {
        justify-content: center;
        padding: 12px;
    }
    
    /* Settings Panels */
    #ppt-config-panel {
        width: 500px !important;
    }
    
    /* ===================
       INDEX / LANDING PAGE 
       =================== */
    
    /* Bento Grid - 2 Columns */
    .grid.md\:grid-cols-4.md\:grid-rows-3 {
        grid-template-columns: repeat(2, 1fr) !important;
        grid-template-rows: auto !important;
        height: auto !important;
    }
    
    .grid.md\:grid-cols-4.md\:grid-rows-3 > div.md\:col-span-2 {
        grid-column: span 2 !important;
    }
    
    .grid.md\:grid-cols-4.md\:grid-rows-3 > div.md\:row-span-2 {
        grid-row: span 1 !important;
    }
    
    /* Target Audience - 2 Columns */
    .grid.md\:grid-cols-4.gap-6 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* ===================
       SUBSCRIPTION PAGE 
       =================== */
    
    /* Pricing Grid - 2 Columns */
    .grid.md\:grid-cols-4.gap-6.items-stretch {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Pro Card - Smaller Offset */
    .md\:-translate-y-6 {
        transform: translateY(-0.5rem) !important;
    }
    
    /* ===================
       EXPERTS PAGE 
       =================== */
    
    /* Experts Grid - 2 Columns */
    .grid.md\:grid-cols-2.lg\:grid-cols-3 {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .card-wrapper.lg\:col-span-2 {
        grid-column: span 2 !important;
    }
}

/* ============================================
   COLLAPSED SIDEBAR (Manual Toggle)
   ============================================ */

#sidebar.collapsed {
    width: 64px !important;
    transition: width 0.3s ease;
    overflow: visible !important;
}

/* Hide text elements when collapsed */
#sidebar.collapsed .sidebar-text,
#sidebar.collapsed .sidebar-label,
#sidebar.collapsed .app-link .flex-col,
#sidebar.collapsed .text-xs:not(.toggle-icon),
#sidebar.collapsed .truncate {
    display: none !important;
}

/* Center brand logo when collapsed */
#sidebar.collapsed .h-16 {
    justify-content: center;
    padding: 12px !important;
}

/* Hide the brand text link wrapper, show only logo */
#sidebar.collapsed .h-16 a {
    gap: 0;
}

/* Center the app icons */
#sidebar.collapsed .app-link {
    justify-content: center;
    padding: 12px;
    gap: 0;
}

/* Hide new chat buttons when collapsed */
#sidebar.collapsed button[title="New Chat"] {
    display: none !important;
}

/* Hide info button when collapsed */
#sidebar.collapsed #expert-info-btn {
    display: none !important;
}

/* Position toggle button at right edge of sidebar, vertically centered */
#sidebar.collapsed #toggle-sidebar {
    display: flex !important;
    position: absolute;
    top: 50%;
    right: -12px;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    justify-content: center;
    align-items: center;
    background: #18181b;
    border-radius: 50%;
    z-index: 100;
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

#sidebar.collapsed #toggle-sidebar:hover {
    background: #27272a;
    border-color: rgba(255, 255, 255, 0.25);
}

/* Also hide the "Experts" header row entirely when collapsed */
#sidebar.collapsed .flex.items-center.justify-between.px-3.mb-2 {
    display: none !important;
}

/* Center account section when collapsed */
#sidebar.collapsed .p-4.border-t {
    padding: 8px !important;
    justify-content: center;
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ============================================
   UTILITY OVERRIDES
   ============================================ */

/* Touch-friendly tap targets */
@media (max-width: 768px) {
    button, a, .app-link {
        min-height: 44px;
    }
}

/* Prevent horizontal scroll */
html, body {
    overflow-x: hidden;
}

/* Safe area padding for notched devices */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .fixed.bottom-0 {
            padding-bottom: max(1rem, env(safe-area-inset-bottom));
        }
    }
}

/* ===================
   GLOBAL BUTTON FIXES (Mobile Input)
   =================== */
@media (max-width: 768px) {
    #studio-toggle-btn span,
    #updates-toggle-btn span,
    #research-toggle-btn span,
    #web-search-btn span,
    #thinking-toggle-btn span,
    #image-settings-btn span {
        display: none !important;
    }

    #studio-toggle-btn,
    #chat-attach-btn,
    #updates-toggle-btn,
    #research-toggle-btn,
    #web-search-btn,
    #thinking-toggle-btn,
    #mini-app-mode-btn,
    #image-settings-btn,
    #enhance-prompt-btn,
    #send-btn {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        min-height: 32px !important;
        padding: 0 !important;
        justify-content: center !important;
        border-radius: 9999px !important;
        aspect-ratio: 1 / 1;
    }
}

/* ===================
   WORKSPACE MOBILE NATIVE POLISH
   =================== */
@media (max-width: 768px) {
    :root {
        --mobile-safe-top: max(0px, env(safe-area-inset-top));
        --mobile-safe-bottom: max(0px, env(safe-area-inset-bottom));
    }

    body {
        background:
            radial-gradient(120% 100% at 50% -20%, rgba(148, 163, 184, 0.18), rgba(0, 0, 0, 0)),
            #171717 !important;
    }

    #workspace-shell {
        padding-top: calc(56px + var(--mobile-safe-top)) !important;
    }

    #mobile-header {
        height: calc(56px + var(--mobile-safe-top)) !important;
        padding: calc(var(--mobile-safe-top) + 6px) 12px 8px !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.09) !important;
        background: linear-gradient(180deg, rgba(20, 20, 24, 0.9) 0%, rgba(20, 20, 24, 0.76) 100%) !important;
        backdrop-filter: blur(18px) saturate(140%);
        -webkit-backdrop-filter: blur(18px) saturate(140%);
        box-shadow: 0 12px 28px rgba(0, 0, 0, 0.38);
    }

    #mobile-header #mobile-menu-btn,
    #mobile-header #mobile-new-chat-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        min-width: 36px !important;
        min-height: 36px !important;
        padding: 0 !important;
        line-height: 1;
        overflow: hidden;
        border-radius: 9999px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        background: rgba(255, 255, 255, 0.04);
        color: #e2e8f0;
    }

    #mobile-header #mobile-menu-btn svg,
    #mobile-header #mobile-new-chat-btn svg {
        width: 18px !important;
        height: 18px !important;
        display: block;
        flex-shrink: 0;
    }

    #mobile-header .font-brand {
        font-size: 1.15rem;
        letter-spacing: 0.03em;
    }

    #context-header {
        position: fixed !important;
        top: calc(56px + var(--mobile-safe-top) + 8px) !important;
        left: 12px !important;
        right: 12px !important;
        width: auto !important;
        height: 52px !important;
        padding: 0 8px !important;
        border: 1px solid rgba(255, 255, 255, 0.1) !important;
        border-radius: 16px !important;
        background: rgba(31, 31, 35, 0.76) !important;
        backdrop-filter: blur(16px) saturate(135%);
        -webkit-backdrop-filter: blur(16px) saturate(135%);
        box-shadow: 0 16px 30px rgba(0, 0, 0, 0.35);
    }

    #context-header > .flex.items-center.gap-3:nth-child(2) {
        display: none !important;
    }

    #context-header > .flex.items-center.gap-3.min-w-0.flex-1 {
        gap: 0.45rem !important;
    }

    #context-header #expert-selector,
    #context-header #model-selector {
        flex: 1 1 0;
        min-width: 0;
        height: 38px;
        border-radius: 12px;
        padding: 0 10px;
        background: rgba(255, 255, 255, 0.06);
    }

    #context-header #expert-selector .w-px,
    #context-header #model-selector .w-px {
        margin-left: 6px;
        margin-right: 6px;
    }

    #context-header #current-expert-name,
    #context-header #current-model-name {
        font-size: 0.78rem;
        max-width: none !important;
    }

    #content-area {
        padding-top: 142px !important;
        padding-bottom: calc(166px + var(--mobile-safe-bottom)) !important;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    #welcome-hero,
    #autobee-welcome {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }

    #messages-container {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    #chat-input-wrapper {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: calc(var(--mobile-safe-bottom) + 8px) !important;
        padding: 0 10px !important;
        z-index: 60 !important;
    }

    #chat-input-wrapper > div {
        max-width: none !important;
    }

    #chat-input-surface {
        border-radius: 24px !important;
        border: 1px solid rgba(255, 255, 255, 0.12);
        background: linear-gradient(180deg, rgba(52, 52, 56, 0.95) 0%, rgba(43, 43, 46, 0.95) 100%) !important;
        box-shadow:
            0 20px 40px rgba(0, 0, 0, 0.38),
            inset 0 1px 0 rgba(255, 255, 255, 0.08);
    }

    #chat-input {
        min-height: 46px;
        max-height: 180px;
        padding: 11px 14px !important;
        line-height: 1.35 !important;
    }

    #input-gradient-fade {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: calc(var(--mobile-safe-bottom) + 54px) !important;
        height: 120px !important;
        background: linear-gradient(180deg, rgba(23, 23, 23, 0) 0%, rgba(23, 23, 23, 0.94) 100%) !important;
    }

    #chat-attach-btn,
    #studio-toggle-btn,
    #updates-toggle-btn,
    #research-toggle-btn,
    #web-search-btn,
    #thinking-toggle-btn,
    #mini-app-mode-btn,
    #image-settings-btn,
    #enhance-prompt-btn {
        border: 1px solid rgba(255, 255, 255, 0.12);
        background: rgba(255, 255, 255, 0.08);
    }

    #send-btn {
        border: 1px solid rgba(255, 255, 255, 0.35);
        background: linear-gradient(135deg, #ffffff 0%, #dce7ff 100%);
        color: #0f172a;
        box-shadow: 0 10px 24px rgba(18, 24, 44, 0.26);
    }

    #send-btn > * {
        color: #0f172a !important;
    }

    #sidebar {
        width: min(88vw, 360px) !important;
        border-right: 1px solid rgba(255, 255, 255, 0.1);
        background: linear-gradient(180deg, rgba(31, 31, 35, 0.96) 0%, rgba(24, 24, 27, 0.96) 100%) !important;
        backdrop-filter: blur(20px) saturate(130%);
        -webkit-backdrop-filter: blur(20px) saturate(130%);
        box-shadow: none !important;
        will-change: transform;
    }

    /* Keep depth on the right edge without causing left-side shadow bleed */
    #sidebar::after {
        content: '';
        position: absolute;
        top: 0;
        right: -16px;
        width: 16px;
        height: 100%;
        pointer-events: none;
        background: linear-gradient(90deg, rgba(0, 0, 0, 0.24), rgba(0, 0, 0, 0));
    }

    #sidebar-overlay {
        z-index: 45 !important;
        background: rgba(7, 7, 9, 0.58) !important;
        backdrop-filter: blur(7px) saturate(115%);
        -webkit-backdrop-filter: blur(7px) saturate(115%);
    }

    body.mobile-sidebar-open {
        overflow: hidden !important;
        touch-action: none;
    }
}
