/* ══════════════════════════════════════════════════
   responsive.css — Mobile views, dock, drawer,
                 and screen ratio-based rules
   ══════════════════════════════════════════════════ */

/* ── Mobile Layout Detection Classes ── */

/* Mobile dock is ALWAYS hidden by default; JS shows it only in mobile ratio mode */
#mobileDockContainer {
    display: none !important;
}

.is-mobile-ratio .side-rail {
    display: none !important;
}

.is-mobile-ratio #toolView {
    flex-direction: column !important;
}

/* Hide redundant per-view headers on mobile since we have a global top bar */
.is-mobile-ratio .workspace-header {
    display: none !important;
}

/* ── MOBILE: Allow landing scroll by default ── */
.is-mobile-ratio,
.is-mobile-ratio body,
.is-mobile-ratio .app-wrapper {
    min-height: 100dvh !important;
    height: auto !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    position: relative !important;
}

/* ── MOBILE: Lock viewport ONLY when app is active (class added via JS) ── */
.is-mobile-ratio.lock-scroll,
.is-mobile-ratio.lock-scroll body,
.is-mobile-ratio.lock-scroll .app-wrapper {
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
}

.is-mobile-ratio.lock-scroll #toolView {
    display: flex !important;
    flex-direction: column !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
    position: relative !important;
    background: #000000;
}

.is-mobile-ratio #appContainer {
    flex: 1 !important;
    min-height: 0 !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

.is-mobile-ratio .ai-helper-layout,
.is-mobile-ratio .chat-workspace {
    flex: 1 !important;
    height: 100% !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    /* Restore vertical centering */
    background: #000000;
    padding-top: 0 !important;
    /* Reset padding for perfect centering */
}

/* Hide original mobile nav that might be conflicting */
.is-mobile-ratio .bottom-nav-wrap {
    display: none !important;
}

/* Ensure history panel doesn't break flex flow on mobile */
.is-mobile-ratio #historyPanel {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100dvh !important;
    z-index: 4500 !important;
    display: none !important;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.is-mobile-ratio #historyPanel.active {
    display: flex !important;
    transform: translateX(0);
}

/* ── Mobile Top Header Bar ── */
.mobile-top-bar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 56px;
    flex-shrink: 0;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    z-index: 4000;
    width: 100%;
}

.is-mobile-ratio .mobile-top-bar {
    display: flex !important;
}

.mobile-top-bar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Hamburger now lives inside the top bar, not floating */
.mobile-hamburger {
    position: relative;
    top: unset;
    left: unset;
    width: 40px;
    height: 40px;
    background: rgba(30, 30, 30, 0.7);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: white;
    font-size: 1.1rem;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: unset;
    transition: var(--transition);
    flex-shrink: 0;
}

.is-mobile-ratio .mobile-hamburger {
    display: flex !important;
}

.mobile-hamburger:active {
    transform: scale(0.9);
    background: var(--primary);
}

/* ── Sidebar Drawer ── */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 3000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

.sidebar-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: #0a0a0a;
    border-right: 1px solid var(--border);
    z-index: 3100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.sidebar-drawer.open {
    transform: translateX(0);
}

.sidebar-drawer .drawer-header {
    padding: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.sidebar-drawer .logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.sidebar-drawer .close-drawer {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.25rem;
    cursor: pointer;
}

.sidebar-drawer .drawer-nav {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.sidebar-drawer .nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 16px;
    border-radius: 12px;
    color: var(--text-dim);
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 8px;
    transition: var(--transition);
}

.sidebar-drawer .nav-item:hover,
.sidebar-drawer .nav-item.active {
    background: var(--primary-dim);
    border: 1px solid var(--primary-border);
    color: white;
}

.sidebar-drawer .nav-item i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

.sidebar-drawer .drawer-footer {
    padding: 24px;
    border-top: 1px solid var(--border);
}

.sidebar-drawer .user-email {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 16px;
}

.sidebar-drawer .btn-logout {
    width: 100%;
    padding: 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

/* ── Mobile Bottom Dock ── */
.mobile-dock-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(75px + env(safe-area-inset-bottom));
    z-index: 3500;
    display: none;
    /* Desktop default */
}

.is-mobile-ratio .mobile-dock-container {
    display: block;
}



.bottom-dock {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 75px;
    background: rgba(15, 15, 15, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: env(safe-area-inset-bottom);
}

.dock-item {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-dim);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.65rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.dock-item i {
    font-size: 1.4rem;
}

.dock-item:active,
.dock-item.active {
    color: var(--primary);
    transform: translateY(-2px);
}

.dock-center-slot {
    width: 70px;
}

/* ── Floating Home Button ── */
.dock-home-btn {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    width: 70px;
    height: 70px;
    background: transparent;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 3600;
}

.dock-home-btn .home-icon {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.4);
    border: 4px solid #000;
    transition: var(--transition);
}

.dock-home-btn:active .home-icon {
    transform: scale(0.9);
}

/* ── Responsive View Adjustments ── */
@media (max-width: 768px) {
    #landingView .navbar .nav-center {
        display: none;
    }

    #landingView .hero h1 {
        font-size: 2.5rem;
    }

    #toolView .side-rail {
        display: none;
    }

    #appContainer {
        flex: 1 !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }

    /* Fallback: Always show hamburger on mobile widths, regardless of JS class */
    .mobile-hamburger {
        display: flex !important;
    }

    .is-mobile-ratio .mobile-hamburger,
    .mobile-hamburger {
        display: flex !important;
    }

    /* Hide Floating Action Button (often fixed bottom right/top right) */
    /* Many templates or external scripts use classnames like .fab, .chat-chat-fab, or specific IDs */
    .fab,
    .chat-fab,
    [id*="chat-widget"],
    [class*="chat-widget"],
    [id*="chat-button"],
    [class*="chat-button"],
    .floating-chat-btn {
        display: none !important;
    }

    /* Prevent top workspace header from colliding with hamburger menu */
    .workspace-header {
        padding-left: 16px !important;
    }

    /* Fix the workspace height to not overlap with the bottom dock */
    .chat-workspace {
        padding-bottom: 90px !important;
        /* Space for the dock */
    }

    /* Adjust the input container for mobile */
    .chat-input-container {
        padding: 0 16px 16px !important;
        background: transparent !important;
    }

    .main-input-group {
        padding-bottom: 0 !important;
    }

    .new-chat-hero {
        margin-top: 0 !important;
        padding-bottom: 40px !important;
        /* Center focus */
    }

    .new-chat-hero h1 {
        font-size: 2.2rem !important;
        line-height: 1.3;
        color: white !important;
        text-align: center;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .new-chat-hero h1 .welcome-text {
        font-size: 1.5rem;
        color: var(--text-dim);
        font-weight: 500;
    }

    .new-chat-hero h1 .user-name-text {
        font-size: 2.5rem;
        font-weight: 800;
        color: white;
    }

    /* --- MOBILE: Chips Refinement --- */

    /* When NOT in a new chat (i.e., active conversation), move chips above input */
    .chat-workspace:not(.is-new-chat) .chat-input-container {
        flex-direction: column-reverse !important;
        padding-bottom: 10px !important;
    }

    /* When NOT in a new chat, make chips scrollable horizontally */
    .chat-workspace:not(.is-new-chat) .task-chips {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        justify-content: flex-start !important;
        padding: 5px 15px !important;
        margin-bottom: 5px !important;
        width: 100vw;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* Hide scrollbar Firefox */
    }

    .chat-workspace:not(.is-new-chat) .task-chips::-webkit-scrollbar {
        display: none;
        /* Hide scrollbar Chrome/Safari */
    }

    .chat-workspace:not(.is-new-chat) .task-chip {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
    }

    /* Hide the greeting hero when in active conversation (just in case) */
    .chat-workspace:not(.is-new-chat) .new-chat-hero {
        display: none !important;
    }

    /* --- MOBILE: Sidebar Drawer Refinement --- */

    .sidebar-drawer {
        top: 56px !important;
        /* Below mobile header */
        bottom: calc(75px + env(safe-area-inset-bottom)) !important;
        /* Above mobile dock */
        height: auto !important;
        width: 280px !important;
        z-index: 3800 !important;
        /* Below top-bar (4000) but above overlay */
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.5);
    }

    /* Ensure drawer inner stays scrollable */
    .sidebar-drawer .drawer-nav {
        flex: 1 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
    }
}

/* ── Screen Ratio Utility ── */
/* Vertical (mobile) ratio detection via CSS as backup */
@media (max-aspect-ratio: 13/19) {
    /* Rules for vertical screens if class isn't applied yet */
}