
/* ============================================================
   MOBILE RESPONSIVE — v6.3
   Covers phones (320-480px) and tablets (481-1024px)
   ============================================================ */

/* ── Variables ── */
:root { --mobile-padding: 16px; }

/* ── Base mobile ── */
@media (max-width: 768px) {
    .container, .container-sm { padding: 0 var(--mobile-padding); }
    .section { padding: 56px 0; }
    .section-sm { padding: 40px 0; }

    /* Nav */
    .nav-links, .nav-cta { display: none !important; }
    .nav-mobile-toggle { display: flex !important; }
    .nav-inner { padding: 0 16px; }

    /* Hero */
    .hero { padding: 100px 0 60px; min-height: auto; }
    .hero-stats { grid-template-columns: repeat(2,1fr) !important; max-width: 100% !important; }
    .hero-actions { flex-direction: column !important; }
    .hero-actions .btn { width: 100%; justify-content: center; }

    /* Grids → single column */
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr !important; gap: 16px !important; }

    /* Footer */
    .footer-grid { grid-template-columns: 1fr !important; gap: 32px; }
    .footer-bottom { flex-direction: column; gap: 12px; text-align: center; }

    /* Tables → scrollable */
    .widget { overflow-x: auto; }
    .table { min-width: 600px; }

    /* Buttons */
    .btn-lg { padding: 13px 20px; font-size: 14px; }

    /* Forms */
    .form-group-row { grid-template-columns: 1fr !important; }

    /* ── PORTAL SPECIFIC ── */

    /* Nav on portal pages */
    .nav { z-index: 300 !important; }
    .portal-layout { padding-top: 60px; }

    /* Sidebar — hidden by default, slide in on toggle */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
        z-index: 250;
        width: 280px !important;
    }
    .sidebar.mobile-open { transform: translateX(0); }
    .sidebar-overlay {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 240;
        backdrop-filter: blur(2px);
    }
    .sidebar-overlay.active { display: block; }

    /* Portal main — full width */
    .portal-main { margin-left: 0 !important; }
    .portal-main.expanded { margin-left: 0 !important; }

    /* Portal topbar */
    .portal-topbar {
        padding: 0 14px;
        height: auto;
        min-height: 60px;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 8px;
        padding-bottom: 8px;
    }
    .portal-topbar-title { font-size: 15px; }
    .portal-topbar-sub { font-size: 12px; }
    /* Hide search and public site on small screens */
    .portal-topbar button[onclick*="search"],
    .portal-topbar a[href*="index.html"] { display: none; }

    /* Portal content */
    .portal-content { padding: 16px; }

    /* Stat cards — 2 per row */
    .portal-content .grid-4 { grid-template-columns: repeat(2,1fr) !important; gap: 12px !important; }
    .portal-content .grid-3 { grid-template-columns: repeat(2,1fr) !important; gap: 12px !important; }
    .portal-content .grid-2 { grid-template-columns: 1fr !important; }

    /* Stat card font sizes */
    .stat-card-value { font-size: 22px; }

    /* Widgets */
    .widget-header { padding: 14px 16px; flex-wrap: wrap; gap: 8px; }
    .widget-body { overflow-x: auto; }

    /* Page header */
    .page-header { flex-direction: column !important; gap: 12px; }
    .page-header > div:last-child { width: 100%; }
    .page-header .btn { width: 100%; justify-content: center; }

    /* Pipeline kanban */
    .portal-content [style*="overflow-x:auto"] { padding-bottom: 12px; }

    /* Login page */
    .wrap { grid-template-columns: 1fr !important; }
    .left { display: none !important; }
    .right { padding: 36px 24px !important; }

    /* Two-column portal layouts → single */
    [style*="grid-template-columns:2fr 1fr"],
    [style*="grid-template-columns:1fr 2fr"],
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns:2fr 1fr;"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns:repeat(3,1fr)"],
    [style*="grid-template-columns:repeat(4,1fr)"] {
        grid-template-columns: repeat(2,1fr) !important;
    }
}

/* ── Small phones (under 400px) ── */
@media (max-width: 400px) {
    .portal-content .grid-4,
    .portal-content .grid-3 { grid-template-columns: 1fr !important; }
    .hero-stats { grid-template-columns: repeat(2,1fr) !important; }
    .hero-title { font-size: 36px !important; }
}

/* ── Tablet (769px - 1024px) ── */
@media (min-width: 769px) and (max-width: 1024px) {
    .container, .container-sm { padding: 0 24px; }
    .grid-4 { grid-template-columns: repeat(2,1fr) !important; }
    .grid-3 { grid-template-columns: repeat(2,1fr) !important; }
    .footer-grid { grid-template-columns: 1fr 1fr !important; gap: 32px; }

    /* Portal */
    .sidebar { width: 220px; }
    .portal-main { margin-left: 220px; }
    .portal-main.expanded { margin-left: 64px; }
    .portal-content { padding: 20px; }
    .portal-topbar { padding: 0 20px; }

    /* Two column layouts stay but compress */
    .stat-card-value { font-size: 24px; }
}

/* ── Hamburger menu button for portal ── */
.portal-hamburger {
    display: none;
    background: none;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 6px;
    width: 38px; height: 38px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: var(--slate);
    font-size: 16px;
    flex-shrink: 0;
}
@media (max-width: 768px) {
    .portal-hamburger { display: flex; }
}

/* Hide on mobile utility */
@media (max-width: 768px) {
    .hide-mobile { display: none !important; }
    .show-mobile { display: flex !important; }

    /* Fix topbar wrapping */
    .portal-topbar {
        flex-wrap: nowrap !important;
        overflow: hidden;
    }
    .portal-topbar > div:first-child {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }
    .portal-topbar-title {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 14px !important;
    }
    .portal-topbar-sub { display: none; }
    
    /* Topbar right — shrink */
    .portal-topbar > div:last-child {
        flex-shrink: 0;
        gap: 8px !important;
    }
    
    /* Hide topbar text labels */
    #user-fullname { display: none; }
    
    /* Search button - hide text, keep icon */
    .portal-topbar button[onclick*="search"] span { display: none; }
}

/* ── Portal main — force zero margin on mobile ── */
@media (max-width: 768px) {
    .portal-main,
    .portal-main.expanded,
    main.portal-main { 
        margin-left: 0 !important; 
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Sidebar completely off screen by default */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        height: 100vh !important;
        transform: translateX(-100%) !important;
        z-index: 250 !important;
    }
    .sidebar.mobile-open {
        transform: translateX(0) !important;
    }

    /* Filter tabs — horizontal scroll */
    .portal-content > div[style*="display:flex"][style*="gap:8px"],
    .portal-content > div[style*="flex"][style*="gap:8px"] {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        padding-bottom: 4px;
    }

    /* Notification and activity items — prevent overflow */
    .activity-item, 
    [style*="border-bottom:1px solid rgba(0,0,0,0.05)"] {
        flex-wrap: wrap;
    }

    /* Fix text truncation */
    .activity-title, .activity-sub,
    .deadline-title, .client-name,
    .funding-title, .task-name {
        white-space: normal !important;
        word-break: break-word;
    }

    /* Topbar right items — hide non-essential */
    .portal-topbar > div:last-child > a,
    .portal-topbar > div:last-child > button:not([onclick*="notification"]):not([class*="hamburger"]) {
        display: none !important;
    }
    /* Always show: hamburger, notifications bell, avatar */
    .portal-hamburger { display: flex !important; }

    /* Tables — horizontal scroll wrapper */
    .widget { overflow: visible; }
    .table-wrapper, .widget > table, .widget > div > table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Inline grid overrides — more specific */
    div[style*="grid-template-columns:2fr 1fr"],
    div[style*="grid-template-columns:1fr 2fr"],
    div[style*="grid-template-columns:1fr 1fr"],
    div[style*="grid-template-columns:repeat(2,1fr)"],
    div[style*="grid-template-columns:repeat(3,1fr)"],
    div[style*="grid-template-columns:repeat(4,1fr)"] {
        grid-template-columns: 1fr !important;
    }

    /* Portal content padding */
    .portal-content { 
        padding: 14px !important; 
        box-sizing: border-box !important;
        width: 100% !important;
        overflow-x: hidden !important;
    }

    /* Page headers */
    .page-header,
    div[style*="justify-content:space-between"][style*="margin-bottom:24px"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }
    .page-header button,
    .page-header a {
        width: auto !important;
    }

    /* Pipeline kanban — horizontal scroll */
    div[style*="overflow-x:auto"][style*="align-items:flex-start"] {
        padding-bottom: 16px;
    }

    /* Stat cards — always 2 per row on phone */
    .stat-card { padding: 16px !important; }
    .stat-card-value { font-size: 22px !important; }

    /* Widget headers */
    .widget-header { 
        flex-wrap: wrap !important; 
        gap: 8px !important;
        padding: 12px 14px !important;
    }

    /* Funding cards */
    div[style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Fix body overflow from mobile menu */
    body { overflow-x: hidden !important; }
}

/* ── Tablet specific fixes ── */
@media (min-width: 769px) and (max-width: 1024px) {
    .portal-main { margin-left: 220px !important; }
    
    /* 2-col grids stay, 3+ become 2 */
    div[style*="grid-template-columns:repeat(3,1fr)"],
    div[style*="grid-template-columns:repeat(4,1fr)"] {
        grid-template-columns: repeat(2,1fr) !important;
    }
    
    .portal-content { padding: 20px !important; }
}
