/* =================================================================
   1. VARIABLES & THEME
   ================================================================= */
:root {
    --lenovo-red: #E2231A; 
    --lenovo-red-hover: #c91b13;
    --intel-blue: #0071C5;
    --amd-red: #ED1C24;
    --accent-blue: #007bff;

    /* Light Mode (Default) */
    --bg-body: #F4F4F4;
    --bg-sidebar: #FFFFFF;
    --bg-card: #FFFFFF;
    --bg-hover: #F2F2F2;
    --border-color: #E0E0E0;
    --text-main: #151515;
    --text-muted: #666666;
    --text-color: #333;
    --card-bg: #fff;
    
    /* Status Colors Base */
    --status-green-bg: #E6F4EA;
    --status-green-text: #1E8E3E;
    --status-amber-bg: #FEF7E0;
    --status-amber-text: #B06000;
    --status-red-bg: #FCE8E6;
    --status-red-text: #C5221F;
}

/* Dark Mode Overrides */
body.dark-mode {
    --bg-body: #101010;
    --bg-sidebar: #000000;
    --bg-card: #1F1F1F;
    --bg-hover: #2D2D2D;
    --border-color: #333333;
    --text-main: #F5F5F5;
    --text-muted: #9E9E9E;
    --text-color: #f5f5f5;
    --card-bg: #1F1F1F;
    
    --status-green-bg: rgba(30, 100, 50, 0.3);
    --status-green-text: #81c995;
    --status-amber-bg: rgba(200, 140, 0, 0.2);
    --status-amber-text: #fdd663;
    --status-red-bg: rgba(180, 40, 40, 0.2);
    --status-red-text: #f28b82;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', Inter, Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    display: flex;
    height: 100vh;
    overflow: hidden;
    font-size: 14px;
    transition: background-color 0.3s, color 0.3s;
}

/* =================================================================
   2. SIDEBAR & NAVIGATION
   ================================================================= */
.sidebar {
    width: 240px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: background-color 0.3s;
}

.brand-area {
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
}

.lenovo-logo {
    height: 20px;
    width: auto;
}
body.dark-mode .lenovo-logo { filter: brightness(0) invert(1); opacity: 0.9; }

.nav-menu { padding: 20px 0; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
    padding: 10px 24px;
    cursor: pointer;
    color: var(--text-muted);
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    border-left: 3px solid transparent;
    width: 100%; /* For badges */
}

.nav-item:hover { background-color: var(--bg-hover); color: var(--text-main); }
.nav-item.active { 
    background-color: var(--bg-hover); 
    color: var(--text-main); 
    border-left-color: var(--lenovo-red);
    font-weight: 600;
}

.notification-badge {
    background-color: #e2231a;
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: auto;
    min-width: 18px;
    text-align: center;
    line-height: 1.2;
    box-shadow: 0 2px 4px rgba(226, 35, 26, 0.3);
}

/* =================================================================
   3. MAIN LAYOUT & TOP BAR
   ================================================================= */
.main-content { flex: 1; padding: 0; display: flex; flex-direction: column; overflow: hidden; }

.top-bar {
    height: 64px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
    display: flex; justify-content: space-between; align-items: center;
    padding: 0 32px;
    flex-shrink: 0;
    transition: background-color 0.3s;
}

.page-title-wrap { display: flex; align-items: center; gap: 12px; }
.page-title { font-size: 1.25rem; font-weight: 600; }

.version-badge {
    font-size: 0.75rem;
    background: var(--bg-hover);
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    font-family: monospace;
}

.top-actions { display: flex; gap: 12px; align-items: center; }

.content-scroll { flex: 1; overflow-y: auto; padding: 32px; }

/* =================================================================
   4. UI COMPONENTS (Buttons, Inputs, Badges)
   ================================================================= */
.btn-primary {
    background: var(--lenovo-red); 
    color: white; border: none;
    padding: 8px 16px; 
    border-radius: 4px;
    cursor: pointer; font-weight: 600;
    display: flex; align-items: center; gap: 8px;
    transition: background 0.2s;
}
.btn-primary:hover { background: var(--lenovo-red-hover); }

.btn-secondary {
    padding: 8px 16px; border-radius: 4px; border: 1px solid var(--border-color);
    background: var(--bg-card); color: var(--text-main); cursor: pointer; transition: 0.2s;
    display: flex; align-items: center; gap: 8px; font-size: 0.85rem; font-weight: 500;
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--text-muted); }

.btn-success {
    background-color: #217346;
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 14px;
    padding: 8px 16px;
}
.btn-success:hover { background-color: #1a5c38; }

.theme-toggle {
    background: transparent; border: 1px solid var(--border-color);
    color: var(--text-muted); width: 34px; height: 34px; border-radius: 4px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
}
.theme-toggle:hover { color: var(--text-main); border-color: var(--text-muted); }

.filters-container {
    display: flex; gap: 12px; margin-bottom: 24px; align-items: center; flex-wrap: wrap;
}

.filter-select, .search-input {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.9rem;
    outline: none;
}
.search-input { width: 280px; }
.filter-select:focus, .search-input:focus { border-color: var(--lenovo-red); }

/* Badges */
.badge {
    font-size: 0.7rem; padding: 2px 6px; border-radius: 3px; font-weight: 600; display: inline-block; margin-right: 4px; border: 1px solid transparent;
}
.badge-intel { color: var(--intel-blue); border-color: rgba(0, 113, 197, 0.3); background: rgba(0, 113, 197, 0.05); }
.badge-amd { color: var(--amd-red); border-color: rgba(237, 28, 36, 0.3); background: rgba(237, 28, 36, 0.05); }
.badge-ram { color: var(--text-muted); border-color: var(--border-color); }
.badge-other { color: var(--text-muted); background: var(--bg-hover); }

/* Status Pills - Consolidated */
.status-pill { 
    padding: 4px 10px; border-radius: 4px; font-size: 0.75rem; font-weight: 700; 
    text-align: center; width: fit-content; letter-spacing: 0.5px;
}
.status-available { background: var(--status-green-bg); color: var(--status-green-text); }
.status-repair { background: var(--status-red-bg); color: var(--status-red-text); }

/* Critical Statuses (Reserved/Loaned) */
.status-reserved-main {
    background-color: #2b2b2b !important;
    color: #ffffff !important;
    border: 1px solid #000;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.status-reserved {
    background-color: #ffc107 !important;
    color: #856404 !important;
    border: 1px solid #ffeeba;
    font-weight: 700;
}
.status-reserved:hover { background-color: #ffe8a1; }

.status-loaned {
    background-color: #e2231a !important;
    color: #ffffff !important;
    border: 1px solid #d11f16;
    font-weight: 700;
}

/* =================================================================
   5. DATA GRID & TABLES
   ================================================================= */
.data-grid { 
    display: flex; flex-direction: column; 
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-card);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.grid-header-row {
    display: grid;
    grid-template-columns: 60px 2.5fr 1.5fr 1fr 1fr 1.2fr 40px;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-hover);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.grid-item {
    border-bottom: 1px solid var(--border-color);
    transition: background 0.1s;
}
.grid-item:last-child { border-bottom: none; }
.grid-item:hover { background-color: rgba(0,0,0,0.02); }
body.dark-mode .grid-item:hover { background-color: rgba(255,255,255,0.03); }

.item-summary {
    display: grid;
    grid-template-columns: 60px 2.5fr 1.5fr 1fr 1fr 1.2fr 40px;
    align-items: center;
    padding: 12px 24px;
    cursor: pointer;
    gap: 10px;
}

.item-thumb { 
    width: 48px; height: 36px; object-fit: contain; 
    background: #fff; border-radius: 2px; padding: 2px; border: 1px solid #eee;
}
body.dark-mode .item-thumb { border-color: #333; }

.item-model { font-weight: 600; font-size: 0.95rem; color: var(--text-main); }
.item-sn { font-family: 'Consolas', monospace; color: var(--text-muted); font-size: 0.85rem; }

.chevron { width: 16px; height: 16px; color: var(--text-muted); transition: transform 0.3s; }
.grid-item.open .chevron { transform: rotate(180deg); }

/* Expanded Details */
.item-expanded {
    display: none;
    padding: 24px 32px;
    background: var(--bg-hover);
    border-top: 1px solid var(--border-color);
    grid-template-columns: 240px 1fr;
    gap: 32px;
    position: relative;
}
.grid-item.open .item-expanded { display: grid; }

.edit-btn {
    position: absolute; top: 20px; right: 20px;
    background: transparent; border: 1px solid var(--border-color);
    color: var(--text-muted); width: 32px; height: 32px; border-radius: 4px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.edit-btn:hover { background: var(--bg-card); color: var(--lenovo-red); border-color: var(--lenovo-red); }

.expanded-img-container {
    background: #fff; border-radius: 4px; padding: 10px;
    display: flex; align-items: center; justify-content: center;
    height: 180px; border: 1px solid var(--border-color);
}
.expanded-img { max-width: 100%; max-height: 100%; object-fit: contain; }

.expanded-content h4 { margin: 0 0 8px 0; color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }

.specs-box { 
    line-height: 1.5; color: var(--text-main); 
    background: var(--bg-card); padding: 16px; border-radius: 4px; 
    margin-bottom: 20px; font-size: 0.9rem; border: 1px solid var(--border-color);
}
.action-bar { display: flex; gap: 10px; }

/* =================================================================
   6. MODALS
   ================================================================= */
/* General Modal Styles */
.modal-overlay, .modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px);
    z-index: 2000;
    display: none; /* Hidden by default */
    align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; animation: fadeIn 0.2s; }

.modal-box, .modal-content {
    background: var(--bg-card);
    width: 600px;
    max-width: 90%;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    display: flex; flex-direction: column;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bg-card);
}
.modal-title, .modal-header h2 { font-size: 1.1rem; font-weight: 600; margin: 0; }
.close-modal { background: none; border: none; font-size: 1.5rem; color: var(--text-muted); cursor: pointer; }

.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 16px; max-height: 70vh; overflow-y: auto; }

.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.form-label, .form-group label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; display: block; margin-bottom: 5px; }
.form-input, .form-textarea, .form-group input, .form-group select {
    background: var(--bg-body); border: 1px solid var(--border-color);
    color: var(--text-main); padding: 10px; border-radius: 4px;
    font-family: inherit; font-size: 0.9rem; resize: vertical; width: 100%; box-sizing: border-box;
}
.form-input:focus, .form-group input:focus { border-color: var(--lenovo-red); outline: none; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.modal-footer, .modal-actions {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    display: flex; justify-content: flex-end; gap: 12px;
    background: var(--bg-hover);
    border-radius: 0 0 8px 8px;
    margin-top: 0;
}

/* Specific fix for Create Asset Modal Centering */
#createAssetModal {
    display: none;
    position: fixed !important;
    z-index: 9999 !important;
    left: 0 !important; top: 0 !important;
    width: 100% !important; height: 100% !important;
    overflow: auto !important;
    background-color: rgba(0,0,0,0.5) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}
#createAssetModal[style*="display: none"] { display: none !important; }
#createAssetModal .modal-box {
    margin: 0 auto !important;
    position: relative !important; top: auto !important; left: auto !important;
    transform: none !important; max-height: 90vh; overflow-y: auto;
}

/* =================================================================
   7. PAGE SPECIFIC: LOANS, REPORTS, ADMIN
   ================================================================= */

/* Loans Dashboard */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 20px;
    border-radius: 4px;
    display: flex; flex-direction: column; gap: 8px;
}

.stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; font-weight: 700; letter-spacing: 0.5px; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--text-main); }
.stat-card.overdue { border-top: 4px solid var(--lenovo-red); }
.stat-card.active-loans { border-top: 4px solid var(--accent-blue); }

.loans-grid-row {
    display: grid;
    grid-template-columns: 120px 1.5fr 2fr 1fr 1fr 1fr 120px;
    align-items: center;
    padding: 12px 24px;
    gap: 15px;
}

/* Reports & Dashboard */
.reports-view { padding: 20px 40px; overflow-y: auto; height: calc(100vh - 80px); }
.reports-container { max-width: 1400px; margin: 0 auto; }
.page-header { margin-bottom: 25px; }
.page-header h1 { font-size: 24px; margin: 0; color: var(--text-color); }
.page-header p { color: #6c757d; margin-top: 5px; font-size: 14px; }

.kpi-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px; margin-bottom: 30px;
}
.kpi-card {
    background: var(--card-bg, #fff); padding: 20px; border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05); border-left: 5px solid #ddd;
    transition: transform 0.2s;
}
.kpi-card:hover { transform: translateY(-2px); }
.kpi-card h3 { margin: 0; font-size: 13px; color: #6c757d; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.kpi-card .value { font-size: 32px; font-weight: 700; color: #333; margin: 10px 0; }
.kpi-card .value.large-text { font-size: 24px; }
.kpi-card .trend { font-size: 13px; color: #6c757d; }
.kpi-card .trend.positive { color: #28a745; }
.kpi-card .trend.negative { color: #dc3545; }

/* KPI Colors */
.kpi-card.blue { border-color: #007bff; }
.kpi-card.blue .value { color: #007bff; }
.kpi-card.green { border-color: #28a745; }
.kpi-card.green .value { color: #28a745; }
.kpi-card.red { border-color: #dc3545; }
.kpi-card.red .value { color: #dc3545; }
.kpi-card.orange { border-color: #fd7e14; }
.kpi-card.orange .value { color: #fd7e14; }

.charts-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; margin-bottom: 30px; }
.chart-container { background: var(--card-bg, #fff); padding: 20px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }
.chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.chart-title { font-weight: 700; color: var(--text-color, #333); }
.doughnut-wrapper { height: 200px; display: flex; justify-content: center; }

.tables-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 40px; }
.report-table-container { background: var(--card-bg, #fff); padding: 20px; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.05); }
.overdue-container { border-top: 4px solid #dc3545; }
.danger-text { color: #dc3545; }

.report-table { width: 100%; border-collapse: collapse; margin-top: 10px; }
.report-table th { text-align: left; padding: 12px 10px; border-bottom: 2px solid #eee; color: #6c757d; font-size: 12px; font-weight: 600; }
.report-table td { padding: 12px 10px; border-bottom: 1px solid #f1f1f1; font-size: 14px; color: var(--text-color, #333); }
.report-table tr:last-child td { border-bottom: none; }

.progress-bar { height: 6px; background: #eee; border-radius: 3px; overflow: hidden; width: 80px; }
.progress-fill { height: 100%; background: #007bff; border-radius: 3px; }

/* Admin & PSREF */
.admin-actions {
    position: absolute; top: 15px; right: 15px;
    display: flex; gap: 8px; z-index: 10;
}
.action-icon-btn {
    background: white; border: 1px solid #ddd; border-radius: 6px;
    padding: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.action-icon-btn:hover { background: #f8f9fa; transform: translateY(-1px); box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.text-red { color: #dc3545; }
.text-blue { color: #0d6efd; }

.psref-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px; margin-top: 15px; max-height: 350px; overflow-y: auto;
    border: 1px solid #ddd; padding: 10px; background: #f9f9f9; border-radius: 8px;
}
.psref-item {
    border: 1px solid #eee; border-radius: 6px; padding: 8px;
    text-align: center; cursor: pointer; background: #fff;
    transition: transform 0.2s, box-shadow 0.2s;
}
.psref-item:hover { transform: translateY(-3px); box-shadow: 0 5px 15px rgba(0,0,0,0.1); border-color: #0071C5; }
.psref-item img { width: 100%; height: 80px; object-fit: contain; margin-bottom: 5px; }
.psref-item h4 {
    font-size: 0.75rem; color: #333; margin: 0;
    overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
    -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}

/* =================================================================
   8. TOOLTIPS
   ================================================================= */
.tooltip-container { position: relative; display: inline-block; cursor: help; z-index: 10; }
.custom-tooltip {
    visibility: hidden; opacity: 0; width: 260px;
    background-color: #2c3e50; color: #ecf0f1; text-align: left;
    border-radius: 6px; padding: 12px;
    position: absolute; bottom: 135%; left: 50%; transform: translateX(-50%);
    box-shadow: 0 10px 20px rgba(0,0,0,0.25); z-index: 1000;
    font-size: 0.85rem; line-height: 1.5;
    transition: opacity 0.3s, bottom 0.3s; pointer-events: none;
}
.custom-tooltip::after {
    content: ""; position: absolute; top: 100%; left: 50%; margin-left: -6px;
    border-width: 6px; border-style: solid; border-color: #2c3e50 transparent transparent transparent;
}
.tooltip-container:hover .custom-tooltip { visibility: visible; opacity: 1; bottom: 125%; }
.tooltip-header {
    display: flex; align-items: center; gap: 8px; font-weight: 700;
    text-transform: uppercase; margin-bottom: 8px; padding-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.2); font-size: 0.8rem; letter-spacing: 0.5px;
}
.tooltip-row { display: flex; justify-content: space-between; margin-bottom: 4px; }
.tooltip-label { color: #bdc3c7; font-size: 0.75rem; }
.tooltip-value { font-weight: 600; color: #fff; }

/* =================================================================
   9. THE ABSOLUTE FINAL MOBILE REFINEMENT (v6)
   ================================================================= */
@media (max-width: 768px) {

    /* --- 1. Global Reset --- */
    html, body {
        width: 100vw !important;
        overflow-x: hidden !important;
        position: relative;
    }

    .app-container { display: flex !important; }
    
    .main-content {
        width: 100% !important;
        min-width: 100% !important;
        margin-left: 0 !important;
    }

    /* --- 2. Hide Table Headers --- */
    thead, .grid-header, .inventory-header-row, .users-header, 
    .loans-header, [class*="header"], .grid-header-row { 
        display: none !important; 
    }

    /* --- 3. Loans Dashboard Fix --- */
    .loans-grid-row {
        display: block !important; 
        grid-template-columns: none !important; 
        padding: 15px !important;
        border-bottom: 1px solid #eee;
    }

    .loans-grid-row > div, .loans-grid-row > span {
        display: flex !important;
        align-items: center;
        margin-bottom: 10px;
        width: 100% !important;
        gap: 10px;
    }

    /* --- 4. Inventory List Fix --- */
    .grid-item { display: block !important; margin: 10px 0; border-bottom: 1px solid #eee; }
    
    .item-summary { 
        display: block !important; 
        padding: 15px !important;
    }
    
    .item-summary > div, .item-summary > span {
        margin-bottom: 8px;
        display: block;
    }

    /* Hide redundant images in mobile expanded view */
    .expanded-img-container, 
    .item-expanded img, 
    .item-details img {
        display: none !important;
    }

    /* Re-arrange Actions */
    .configuration-box, .action-bar {
        width: 100% !important;
        margin: 10px 0 !important;
    }
    
    .action-bar { display: flex !important; flex-direction: column !important; gap: 8px; }
    .btn-primary, .btn-secondary { width: 100% !important; justify-content: center; }

    /* --- 5. Reports Fix --- */
    .tables-grid, .charts-grid, .kpi-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px !important;
        padding: 10px !important;
    }

    .report-table-container, .chart-container, .kpi-card {
        width: 100% !important;
        margin: 0 !important;
    }
    
    /* Make charts scrollable horizontally if needed */
    .chart-container { overflow-x: auto; }

    /* --- 6. Settings Fix --- */
    .config-card, .settings-container {
        width: calc(100% - 20px) !important;
        margin: 10px !important;
        padding: 15px !important;
        box-sizing: border-box;
    }

    /* --- 7. Sidebar Mobile --- */
    .sidebar {
        position: fixed !important; left: -280px !important;
        width: 260px !important; z-index: 9999;
        transition: left 0.3s ease;
        height: 100vh;
        box-shadow: 2px 0 10px rgba(0,0,0,0.2);
    }
    .sidebar.active { left: 0 !important; }
    .mobile-menu-btn { display: flex !important; margin-right: 15px; }
    
    /* Modal Mobile Fixes */
    .modal-box, .modal-content {
        width: 95% !important;
        margin: 10px auto !important;
    }
    .form-row { grid-template-columns: 1fr; }
}