/* ============================================================
   PyForm Responsive — iPad & iPhone only
   Desktop (>1024px) is untouched.
   ============================================================ */

/* ─── iPad (768–1024px) ──────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1024px) {
    .sidebar               { width: 200px !important; }
    .dashboard-main        { margin-left: 200px !important; }
    .quick-actions         { grid-template-columns: 1fr 1fr !important; }
    .projects-grid,
    .card-grid             { grid-template-columns: repeat(2, 1fr) !important; }
    .toolbar, #toolbar,
    .ide-header            { position: sticky !important; top: 0 !important; z-index: 100 !important; }
    .files-panel, #sidebar { width: 180px !important; }

    /* Special Task arena — stack task pane on top */
    .special-task-arena .main,
    .arena                 { flex-direction: column !important; }
    .task-pane             { width: 100% !important; height: 40vh !important; min-width: 0 !important;
                             border-right: none !important;
                             border-bottom: 1px solid rgba(255,255,255,0.06) !important; }
    .splitter              { display: none !important; }
    .editor-pane           { height: 60vh !important; }
}

/* ─── iPhone (<768px) ────────────────────────────────────── */
@media (max-width: 767px) {
    /* Dashboard */
    .sidebar                                { position: fixed !important; left: -100% !important;
                                              transition: left 0.3s ease !important;
                                              z-index: 200 !important; width: 260px !important; }
    .sidebar.open                           { left: 0 !important; }
    .dashboard-main                         { margin-left: 0 !important; }
    .quick-actions                          { grid-template-columns: 1fr !important; }
    .projects-grid, .card-grid              { grid-template-columns: 1fr !important; }
    .stats-row                              { flex-wrap: wrap !important; gap: 8px !important; }
    .welcome-heading                        { font-size: 28px !important; letter-spacing: -1px !important; }
    .welcome-section                        { flex-direction: column !important; }
    .header-search, .nav-search             { display: none !important; }

    /* IDE content pushed above bottom toolbar */
    body.is-iphone .sidebar,
    body.is-iphone .files-panel,
    body.is-iphone #sidebar                 { display: none !important; }
    body.is-iphone .dashboard-main,
    body.is-iphone .editor-area,
    body.is-iphone .editor-pane             { width: 100% !important; margin-left: 0 !important; }
    body.is-iphone .ide-content-wrap,
    body.is-iphone .app                     { padding-bottom: 68px !important; }
}

/* ─── iPhone bottom IDE toolbar ──────────────────────────── */
.ide-mobile-toolbar { display: none; }

body.is-iphone .ide-mobile-toolbar {
    display: flex !important;
    position: fixed !important;
    left: 0 !important; right: 0 !important; bottom: 0 !important;
    z-index: 100 !important;
    height: 56px;
    background: rgba(10,10,20,0.96) !important;
    backdrop-filter: blur(20px) saturate(160%) !important;
    -webkit-backdrop-filter: blur(20px) saturate(160%) !important;
    border-top: 1px solid rgba(255,255,255,0.07);
    align-items: center;
    justify-content: space-around;
    padding: 0 16px;
    padding-bottom: env(safe-area-inset-bottom);
}

/* Hide the top Run button on iPhone (bottom toolbar replaces it) */
body.is-iphone .run-btn-top { display: none !important; }

/* ═══════════════════════════════════════════════════
   IDE MOBILE LAYOUT (≤768px)
   ═══════════════════════════════════════════════════ */
.ide-mobile-toolbar { display: none; }
.imt-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 54px;
    font-family: inherit;
}
.imt-btn .imt-icon { font-size: 22px; line-height: 1; }
.imt-btn .imt-label { font-size: 10px; letter-spacing: 0.5px; }
.imt-btn.imt-run {
    background: linear-gradient(135deg,#00c853,#00e676);
    color: #000;
    border-radius: 99px;
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 800;
    flex-direction: row;
    gap: 6px;
    box-shadow: 0 4px 16px rgba(0,200,83,0.4);
    letter-spacing: 0.3px;
}

@media (max-width: 768px) {
    html, body {
        height: 100% !important;
        width: 100% !important;
        overflow: hidden !important;
    }

    /* Main IDE shell fills viewport */
    #app, .app, .ide-container {
        display: flex !important;
        flex-direction: column !important;
        height: 100vh !important;
        height: 100dvh !important;
        overflow: hidden !important;
    }

    /* Top bar stays slim */
    .topbar, .top-bar, .ide-topbar {
        height: 48px !important;
        min-height: 48px !important;
        padding: 0 12px !important;
        flex-shrink: 0 !important;
    }
    /* Hide optional topbar items on phones */
    .topbar .topbar-center, .topbar .tab-bar, .topbar .nav-title { display: none !important; }

    /* Main layout becomes a single column (editor + output stacked) */
    .main-layout {
        grid-template-columns: 1fr !important;
        grid-template-rows: 1fr !important;
    }

    /* Hide desktop-only side panels; we use drawers instead */
    .sidebar, #sidebar,
    .sidebar-resize, #sidebar-resize,
    .sensei-panel, #ai-sidebar,
    #ai-resizer { display: none !important; }

    /* Split pane becomes vertical stack */
    .split-pane, #center-pane {
        display: flex !important;
        flex-direction: column !important;
        grid-template-columns: none !important;
        min-width: 0 !important;
        width: 100% !important;
    }
    .split-handle, #terminal-resize { display: none !important; }

    .editor-pane, #editor-pane {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
    }
    .editor-container, #editor-container {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        width: 100% !important;
    }

    .terminal-pane, #terminal-pane {
        flex: 0 0 180px !important;
        height: 180px !important;
        min-height: 180px !important;
        max-height: 180px !important;
        width: 100% !important;
        border-top: 1px solid rgba(255,255,255,0.08) !important;
    }

    /* Leave room for the fixed bottom toolbar */
    body.is-iphone .app,
    body.is-iphone #app { padding-bottom: 62px; }

    /* Compact editor toolbar */
    .editor-toolbar { padding: 6px 10px !important; font-size: 12px; }
    .ide-tool-bar, #pyform-editor-toolbar {
        overflow-x: auto !important;
        white-space: nowrap !important;
        padding: 4px 8px !important;
    }
    .ide-tool-bar .ide-tool-bar-right { display: none !important; }

    /* Bottom mobile toolbar — pinned */
    .ide-mobile-toolbar {
        display: flex !important;
        position: fixed !important;
        left: 0; right: 0; bottom: 0 !important;
        height: 62px;
        z-index: 1000;
        align-items: center;
        justify-content: space-around;
        padding: 0 6px calc(env(safe-area-inset-bottom,0px)) 6px;
        background: rgba(8,10,20,0.96);
        backdrop-filter: blur(24px);
        -webkit-backdrop-filter: blur(24px);
        border-top: 1px solid rgba(255,255,255,0.08);
    }

    /* Mobile drawers */
    .mobile-files-drawer {
        position: fixed;
        top: 48px; bottom: 62px; left: 0;
        width: min(82vw, 300px);
        background: rgba(8,10,20,0.97);
        backdrop-filter: blur(24px);
        border-right: 1px solid rgba(255,255,255,0.08);
        z-index: 800;
        overflow-y: auto;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    .mobile-files-drawer.open { transform: translateX(0); }

    .mobile-ai-panel {
        position: fixed;
        left: 0; right: 0; bottom: 62px;
        height: 65vh;
        background: rgba(8,10,20,0.97);
        backdrop-filter: blur(24px);
        border-top: 1px solid rgba(255,255,255,0.12);
        border-radius: 20px 20px 0 0;
        z-index: 850;
        display: flex;
        flex-direction: column;
        transform: translateY(100%);
        transition: transform 0.3s ease;
    }
    .mobile-ai-panel.open { transform: translateY(0); }

    .mobile-drawer-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 790;
        display: none;
    }
    .mobile-drawer-backdrop.open { display: block; }
}
