/* ============================================================
   Responsive CSS — Media Queries for Phone & Tablet
   Load LAST so it overrides all other stylesheets.
   Works with module-layout.css class system.
   ============================================================ */

/* ── Root overflow protection ────────────────────────────── */
html {
    overflow-x: hidden;
    max-width: 100vw;
}

/* ── Phone (< 768px) ─────────────────────────────────────── */
@media (max-width: 767px) {

    /* --- ROOT: prevent anything from exceeding viewport --- */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw;
    }

    /* --- SIDEBAR: off-canvas overlay on mobile --- */
    #sidebar-toggle {
        display: block !important;
    }

    .platform-tabs {
        display: flex !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 2px;
        padding-bottom: 6px;
        mask-image: linear-gradient(to right, black 88%, transparent 100%);
        -webkit-mask-image: linear-gradient(to right, black 88%, transparent 100%);
    }

    .platform-tabs::-webkit-scrollbar { display: none; }

    #app-layout {
        flex-direction: column;
        height: calc(100dvh - 78px) !important;
    }

    #sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        z-index: 500;
        transition: left 0.25s ease;
        box-shadow: none;
    }

    #sidebar.open {
        left: 0;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.6);
    }

    #main-content {
        width: 100%;
    }

    /* --- TAB CONTENT: scrollable vertically, clip horizontal --- */
    .tab-content {
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    /* --- PLATFORM NAV: stack brand + horizontal-scroll tabs --- */
    #platform-nav {
        height: auto;
        min-height: 44px;
        padding: 0 10px;
        flex-wrap: wrap;
        gap: 0;
    }

    .platform-brand {
        font-size: 13px;
        padding: 8px 0 4px;
    }

    .nav-actions {
        align-self: flex-end;
        margin-bottom: 6px;
        gap: 6px;
    }

    .about-btn { padding: 4px 8px; font-size: 10px; }
    .donate-btn { padding: 5px 10px; font-size: 11px; }

    .about-card { padding: 28px 20px 22px; }
    .about-name { font-size: 16px; }
    .about-body { font-size: 12px; }

    .platform-tab {
        padding: 0 10px;
        font-size: 11px;
        white-space: nowrap;
        min-height: 34px;
        flex-shrink: 0;
    }

    .platform-tab .tab-icon { font-size: 12px; }
    .platform-tab.active::after { left: 6px; right: 6px; }

    /* --- CANVAS: compact padding, clip horizontal overflow --- */
    #ai-canvas,
    #netsec-canvas,
    #devops-canvas,
    #education-canvas,
    #life-canvas {
        padding: 8px !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    /* --- SVG: scale down naturally, tap-to-zoom handles readability --- */
    .module-section svg,
    .module-svg-wrap svg,
    .module-card svg,
    .module-wrap svg,
    .module-canvas svg,
    .devops-section svg,
    #education-canvas svg {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-width: 0 !important;
        cursor: pointer;
    }

    /* --- GRIDS: force single column --- */
    .module-section [style*="grid-template-columns"],
    .module-card [style*="grid-template-columns"],
    .module-wrap [style*="grid-template-columns"],
    .devops-section [style*="grid-template-columns"],
    #education-canvas [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    /* --- CODE/PRE: prevent overflow --- */
    .module-section code,
    .module-card code,
    .module-wrap code,
    .devops-section code,
    #education-canvas code {
        word-break: break-all;
        font-size: 10px !important;
    }

    .module-section pre,
    .module-card pre,
    .module-wrap pre,
    .devops-section pre,
    #education-canvas pre {
        overflow-x: auto;
        max-width: 100%;
        white-space: pre-wrap;
        word-break: break-word;
        font-size: 10px !important;
    }

    /* --- TABLES: horizontal scroll --- */
    .module-section table,
    .module-card table,
    .module-wrap table,
    .devops-section table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        max-width: 100%;
    }

    /* --- DETAILS/SUMMARY (Q&A cards): full width --- */
    .module-section details,
    .module-card details,
    .module-wrap details,
    .devops-section details {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* --- HEADINGS: smaller --- */
    .module-section h2,
    .module-section h3,
    .devops-section h2,
    .devops-section h3 {
        font-size: 16px !important;
    }

    /* ==========================================================
       TAB 1 (legacy): NETWORK SECURITY DASHBOARD
       ========================================================== */

    #dashboard-header {
        height: auto;
        min-height: 38px;
        padding: 6px 12px;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    #dashboard-header h1 { font-size: 13px; }
    #dashboard-header .header-subtitle { font-size: 10px; margin-left: 0; }
    #dashboard-header .header-right { width: 100%; }
    #network-info { display: none !important; }
    #connection-status { font-size: 9px; padding: 2px 8px; }

    #dashboard-grid {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto !important;
        height: auto !important;
        overflow-y: visible;
        padding: 8px;
        gap: 8px;
    }

    #topology-container {
        grid-row: auto !important;
        min-height: 300px;
        max-height: 400px;
    }

    #topology-map { min-height: 280px; }
    #score-container { min-height: 180px; }
    #education-container { min-height: 280px; }
    #attack-container { min-height: 280px; }

    #education-tabs {
        padding: 6px 10px;
        gap: 4px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        flex-wrap: nowrap !important;
    }

    #education-tabs::-webkit-scrollbar { display: none; }

    .edu-tab {
        padding: 4px 9px;
        font-size: 10px;
        border-radius: 6px;
        flex-shrink: 0;
        white-space: nowrap;
    }

    #attack-grid {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto !important;
        overflow-y: auto;
        overflow-x: hidden;
    }

    #attack-grid .scrollable-list {
        grid-column: 1 !important;
        max-height: 200px;
    }

    #device-detail-panel {
        width: 100vw !important;
        border-radius: 12px 12px 0 0;
        padding: 16px 12px;
    }

    .detail-grid { grid-template-columns: 1fr !important; }
}

/* ── Tablet (768px - 1023px) ─────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {

    .tab-content {
        overflow-y: auto !important;
        overflow-x: hidden !important;
    }

    #platform-nav { padding: 0 14px; }

    /* Narrower sidebar on tablet */
    #sidebar {
        width: 220px;
    }

    .tree-cat-toggle {
        font-size: 12px;
        padding: 8px 10px;
    }

    .tree-sec-toggle {
        font-size: 10px;
        padding: 5px 8px 5px 12px;
    }

    .tree-leaf {
        font-size: 11px;
        padding: 3px 8px 3px 28px;
    }

    #ai-canvas,
    #netsec-canvas,
    #devops-canvas,
    #life-canvas {
        padding: 14px !important;
        overflow-x: hidden !important;
    }

    /* SVGs: scale naturally on tablet too */
    .module-section svg,
    .module-svg-wrap svg,
    .module-card svg,
    .module-wrap svg,
    .module-canvas svg,
    .devops-section svg {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        min-width: 0 !important;
    }

    /* 3-col grids → 2-col */
    .module-section [style*="1fr 1fr 1fr"],
    .module-card [style*="1fr 1fr 1fr"],
    .module-wrap [style*="1fr 1fr 1fr"],
    .devops-section [style*="1fr 1fr 1fr"] {
        grid-template-columns: 1fr 1fr !important;
    }

    /* --- TAB 1 --- */
    #dashboard-header .header-right { gap: 8px; }
    #network-info { font-size: 11px; gap: 4px; }

    #dashboard-grid {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto !important;
        height: auto !important;
        padding: 10px;
    }

    #topology-container {
        grid-row: auto !important;
        min-height: 350px;
        max-height: 500px;
    }

    #education-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        scrollbar-width: none;
    }

    #education-tabs::-webkit-scrollbar { display: none; }
}
