/* =========================================
   1. ROOT VARIABLES & GLOBAL RESET
========================================= */
:root {
    --theme-color: #103a5c;
    --navbar-bg: #13334d;
    --body-text: #4a4a4a;
    --heading-color: #103a5c;
    --gradient-banner: linear-gradient(to right, #103a5c, #1870b4);
    --gradient-footer: linear-gradient(180deg, #103a5c, #081d2e);
    --btn-hover: #1870b4;
    --sidebar-width: 260px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; -webkit-font-smoothing: antialiased; }

/* Critical Mobile Fix: Prevent horizontal wobble */
html, body {
    overflow-x: hidden;
    width: 100%;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: #f4f7f6;
    color: var(--body-text);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5 { color: var(--heading-color); margin-top: 0; }

/* =========================================
   2. BUTTONS & UI COMPONENTS
========================================= */
.btn-primary {
    background-color: var(--theme-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}
.btn-primary:hover { background-color: var(--btn-hover); transform: translateY(-1px); }

.badge-count {
    background: #38bdf8;
    color: white;
    font-size: 10px;
    font-weight: 900;
    padding: 2px 7px;
    border-radius: 10px;
    margin-left: auto;
}

.role-badge { 
    background: #e2e8f0; 
    padding: 4px 10px; 
    border-radius: 20px; 
    font-size: 11px; 
    font-weight: 700; 
    color: var(--theme-color); 
}

/* =========================================
   3. ERP SIDEBAR & MOBILE OVERLAY
========================================= */
.erp-sidebar {
    width: var(--sidebar-width);
    background: var(--gradient-footer);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    left: 0;
    top: 0;
}

.sidebar-logo { padding: 30px 24px; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.1); position: relative; background: rgba(0,0,0,0.1); }
.sidebar-logo img { width: 160px; height: auto; object-fit: contain; }

.sidebar-menu { list-style: none; padding: 0; margin: 20px 0; overflow-y: auto; }
.sidebar-menu a {
    color: #cbd5e1;
    text-decoration: none;
    display: flex;
    align-items: center;
    padding: 12px 24px;
    font-size: 14px;
    transition: var(--transition);
    gap: 10px;
}
.sidebar-menu a:hover, .sidebar-menu a.active {
    background: rgba(255,255,255,0.08);
    color: white;
    border-left: 4px solid #38bdf8;
}

/* Dark Background Overlay for Mobile Sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* =========================================
   4. MAIN CONTENT AREA
========================================= */
.erp-main {
    flex: 1;
    margin-left: var(--sidebar-width); /* Leaves room for the sidebar on desktop */
    transition: margin-left 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}

/* Simplified Header */
.erp-topbar {
    background: white;
    height: 70px;
    padding: 0 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    position: sticky;
    top: 0;
    z-index: 900;
}

.erp-content { 
    padding: 25px 30px; 
    flex: 1; 
    max-width: 1600px; 
    margin: 0 auto; 
    width: 100%; 
}

/* Standardized Footer */
.erp-footer {
    text-align: center;
    padding: 20px;
    font-size: 12px;
    color: #94a3b8;
    border-top: 1px solid #e2e8f0;
    margin-top: auto; /* Pushes footer to the bottom */
}

/* =========================================
   5. DASHBOARD WIDGETS
========================================= */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 15px; margin-bottom: 25px; }
.kpi-card { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border-left: 4px solid var(--theme-color); display: flex; justify-content: space-between; align-items: center; }
.kpi-card.warning { border-left-color: #f59e0b; }
.kpi-card.success { border-left-color: #10b981; }
.kpi-card.purple { border-left-color: #8b5cf6; }
.kpi-value { font-size: 24px; font-weight: 800; color: var(--heading-color); margin: 5px 0; }
.kpi-label { font-size: 11px; text-transform: uppercase; color: #64748b; font-weight: bold; }
.kpi-icon-wrapper { width: 45px; height: 45px; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 20px; }

.widget-panel { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); overflow: hidden;}
.widget-title { font-size: 14px; font-weight: bold; margin-bottom: 15px; color: var(--heading-color); border-bottom: 1px solid #eee; padding-bottom: 10px; display: flex; align-items: center; gap: 8px; }

/* Responsive Table Wrapper */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

/* Hamburger Menu Button (Hidden on Desktop) */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--theme-color);
    cursor: pointer;
    padding: 0 15px 0 0;
}

/* =========================================
   6. GLOBAL MOBILE ARCHITECTURE
========================================= */

/* Tablet & Smaller Screens */
@media (max-width: 1024px) {
    /* 1. Hide the sidebar off-canvas */
    .erp-sidebar {
        transform: translateX(-100%);
    }

    /* 2. Expand main content to full width */
    .erp-main {
        margin-left: 0;
    }

    /* 3. Show hamburger menu */
    .menu-toggle {
        display: block;
    }

    /* 4. Logic for when sidebar is opened via JS */
    .erp-sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    /* Collapse custom grid layouts (if they exist on pages) */
    .widget-grid-3, .widget-grid-2, .split-layout { 
        grid-template-columns: 1fr 1fr; 
    }
}

/* Mobile Phones */
@media (max-width: 768px) {
    /* Tighten up padding for small screens */
    .erp-content { 
        padding: 20px 15px; 
    }
    .erp-topbar { 
        padding: 0 15px; 
        height: 60px;
    }
    
    /* Ensure long titles don't break the topbar */
    .erp-topbar h2 {
        font-size: 18px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 180px;
    }

    /* Force all grids to single column */
    .widget-grid-3, .widget-grid-2, .split-layout, .kpi-grid { 
        grid-template-columns: 1fr !important; 
    }
    
    /* Make tables fit */
    th, td {
        padding: 12px 10px !important;
        font-size: 13px !important;
    }
}