
:root {
    --bg-color: #f4f6f9;
    --sidebar-bg: #ffffff;
    --card-bg: rgba(255,255,255,0.98);
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --border-color: #e2e8f0;
    --primary-color: #4361ee;
    --primary-hover: #3a56d4;
    --success-color: #38a169;
    --danger-color: #e53e3e;
    --warning-color: #d69e2e;
    --glass-border: rgba(255,255,255,0.4);
    --glass-shadow: 0 4px 15px rgba(0,0,0,0.03);
    --sidebar-width: 240px;
    --content-padding: 24px;
    --font-size-base: 0.9rem; /* Perfectly readable, not too huge */
}

[data-theme="dark"] {
    --bg-color: #1a202c;
    --sidebar-bg: #2d3748;
    --card-bg: rgba(45, 55, 72, 0.98);
    --text-primary: #f7fafc;
    --text-secondary: #a0aec0;
    --border-color: #4a5568;
    --glass-border: rgba(255,255,255,0.05);
    --glass-shadow: 0 4px 15px rgba(0,0,0,0.25);
}

*, *::before, *::after { box-sizing: border-box; }

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: var(--font-size-base);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    line-height: 1.5;
}

/* ─── SIDEBAR ─────────────────────────────────── */
#sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    z-index: 1000;
    padding-top: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

#sidebar img {
    max-height: 65px !important;
    width: auto;
}

#sidebar .px-4 {
    padding: 15px 20px 10px !important;
}

#sidebar .mt-3 {
    margin-top: 10px !important;
}

#sidebar small { font-size: 0.75rem; color: var(--text-secondary); }
#sidebar strong { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
#sidebar .badge { font-size: 0.7rem; padding: 4px 8px; }

#sidebar .nav-link {
    color: var(--text-secondary);
    padding: 10px 20px;
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: 0 25px 25px 0;
    margin-right: 15px;
    margin-bottom: 4px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

#sidebar .nav-link:hover,
#sidebar .nav-link.active {
    background-color: rgba(67,97,238,0.08);
    color: var(--primary-color);
}

#sidebar .nav-link i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

/* ─── MAIN CONTENT ────────────────────────────── */
#main-content {
    margin-left: var(--sidebar-width);
    padding: var(--content-padding);
    min-height: 100vh;
}

#main-content h3 {
    font-size: 1.35rem !important;
    margin-bottom: 0 !important;
    font-weight: 600;
}

#main-content h5, #main-content h6 {
    font-size: 1.05rem !important;
    font-weight: 600;
}

/* ─── CARDS ───────────────────────────────────── */
.card-custom {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--glass-shadow);
    margin-bottom: 15px;
}

.card-custom .card-body {
    padding: 16px 20px !important;
}

.glass-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: var(--glass-shadow);
    padding: 0;
    overflow: hidden;
}

/* ─── TABLES ──────────────────────────────────── */
.table-custom th,
.table-custom td {
    padding: 10px 14px !important;
    font-size: 0.88rem !important;
    vertical-align: middle;
    border-color: var(--border-color);
    white-space: nowrap;
}

.table-custom th {
    background-color: rgba(0,0,0,0.015);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.78rem !important;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border-color);
}

.table-responsive {
    border-radius: 12px;
}

/* DataTables overrides */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    font-size: 0.85rem !important;
    padding: 12px 16px !important;
}

.dataTables_wrapper .dataTables_filter input {
    font-size: 0.85rem;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

div.dataTables_wrapper div.dataTables_length select {
    font-size: 0.85rem;
    padding: 4px 8px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.page-link { padding: 4px 10px; font-size: 0.85rem; }

/* ─── BUTTONS ─────────────────────────────────── */
.btn {
    font-size: 0.88rem;
    padding: 6px 14px;
    border-radius: 6px;
    font-weight: 500;
}

.btn-sm {
    padding: 4px 10px !important;
    font-size: 0.82rem !important;
    border-radius: 5px !important;
}

.btn-xs {
    padding: 2px 8px !important;
    font-size: 0.75rem !important;
    border-radius: 4px !important;
}

/* ─── FORMS ───────────────────────────────────── */
.form-control-sm, .form-select-sm {
    font-size: 0.85rem !important;
    padding: 4px 10px !important;
    min-height: 32px !important;
    border-radius: 6px;
}

.form-control, .form-select {
    font-size: 0.9rem;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.form-label {
    font-size: 0.82rem !important;
    margin-bottom: 4px !important;
    font-weight: 500;
    color: var(--text-secondary);
}

.row.g-2 { --bs-gutter-y: 0.5rem; --bs-gutter-x: 0.5rem; }
.row.g-3 { --bs-gutter-y: 1rem; --bs-gutter-x: 1rem; }

/* ─── BADGES ──────────────────────────────────── */
.badge {
    font-size: 0.72rem !important;
    padding: 4px 8px !important;
    font-weight: 500;
    border-radius: 4px;
}

/* ─── MODALS ──────────────────────────────────── */
.modal-content {
    border-radius: 12px;
    border: none;
    box-shadow: 0 10px 40px rgba(0,0,0,0.1);
}
.modal-header {
    padding: 16px 24px !important;
    border-bottom: 1px solid var(--border-color);
}
.modal-body {
    padding: 20px 24px !important;
}
.modal-footer {
    padding: 12px 24px !important;
    border-top: 1px solid var(--border-color);
}
.modal-title { font-size: 1.1rem !important; font-weight: 600; }

/* ─── NAV TABS ────────────────────────────────── */
.nav-tabs .nav-link {
    padding: 10px 16px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border: none;
    border-bottom: 2px solid transparent;
    font-weight: 500;
}
.nav-tabs .nav-link:hover {
    border-color: transparent;
    color: var(--primary-color);
}
.nav-tabs .nav-link.active {
    border: none;
    border-bottom: 2px solid var(--primary-color);
    color: var(--primary-color);
    font-weight: 600;
    background: transparent;
}

/* ─── OFFCANVAS ───────────────────────────────── */
.offcanvas-header { padding: 16px 20px !important; }
.offcanvas-body { padding: 16px 20px !important; font-size: 0.9rem; }

/* ─── FILTER BAR ──────────────────────────────── */
#main-content .card-custom select,
#main-content .card-custom input,
#main-content .card-custom button {
    font-size: 0.85rem !important;
}

/* ─── ALERTS / SCORECARD ─────────────────────── */
.alert { padding: 10px 14px; font-size: 0.85rem; border-radius: 8px; }

/* ─── DASHBOARD KPIS ─────────────────────────── */
.card h2, .card .display-4 { font-size: 1.6rem !important; font-weight: 700; }
.card h5 { font-size: 0.85rem !important; color: var(--text-secondary); }

/* ─── KANBAN ─────────────────────────────────── */
.kanban-board {
    display: flex;
    overflow-x: auto;
    padding-bottom: 16px;
    gap: 16px;
    height: calc(100vh - 120px);
}
.kanban-column {
    min-width: 280px;
    background: var(--card-bg);
    border-radius: 10px;
    padding: 12px;
    flex-direction: column;
    border: 1px solid var(--border-color);
}
.kanban-header {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    justify-content: space-between;
}
.kanban-card {
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 10px;
    cursor: grab;
    font-size: 0.85rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

/* ─── LOGIN PAGE ──────────────────────────────── */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}
[data-theme="dark"] .login-body {
    background: linear-gradient(135deg, #232526 0%, #414345 100%);
}
.login-card { width: 100%; max-width: 400px; padding: 40px; border-radius: 16px; box-shadow: 0 20px 40px rgba(0,0,0,0.1); }

/* ─── SCROLLBAR ───────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #475569; }



/* ─── MOBILE RESPONSIVE UPGRADES ──────────────────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    transition: opacity 0.3s ease;
}
.sidebar-backdrop.show { display: block; opacity: 1; }

@media (max-width: 768px) {
    #sidebar { 
        transform: translateX(-100%); 
        width: 260px;
        box-shadow: 5px 0 25px rgba(0,0,0,0.15);
    }
    #sidebar.active { transform: translateX(0); }
    #main-content { 
        margin-left: 0 !important; 
        padding: 12px 10px !important; 
        width: 100vw;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Flexible Headers: Stack header elements (e.g. Title + Buttons) */
    .d-flex.justify-content-between.align-items-center.mb-2,
    .d-flex.justify-content-between.align-items-center.mb-4,
    .d-flex.justify-content-between.align-items-center.mb-3 {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px;
    }
    .d-flex.justify-content-between.align-items-center > div {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    /* KPI Cards */
    .kpi-card { padding: 15px; gap: 10px; }
    .kpi-icon { width: 45px; height: 45px; font-size: 1.2rem; }
    .kpi-value { font-size: 1.25rem; }
    
    /* Tables: Ensure perfect horizontal scroll */
    .card-body { padding: 10px !important; }
    .table-responsive {
        border-radius: 8px;
        margin-bottom: 0;
        border: none;
    }
    .table-custom th, .table-custom td {
        padding: 8px 10px !important;
        font-size: 0.85rem !important;
    }
    
    /* DataTables Mobile Overrides */
    div.dataTables_wrapper div.dataTables_filter { text-align: left; margin-top: 10px; }
    div.dataTables_wrapper div.dataTables_filter input { width: 100%; margin-left: 0; margin-top: 5px; }
    div.dataTables_wrapper div.dataTables_length,
    div.dataTables_wrapper div.dataTables_info,
    div.dataTables_wrapper div.dataTables_paginate { text-align: left; padding-left: 0; }
    .dataTables_wrapper .row { margin: 0; }
    .dataTables_wrapper .col-sm-12.col-md-6 { padding: 0; }
    
    /* Scrollable Tabs */
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 5px;
    }
    .nav-tabs::-webkit-scrollbar { height: 3px; }
    .nav-item { white-space: nowrap; }
    
    /* Modals */
    .modal-dialog { margin: 0.5rem; max-width: calc(100% - 1rem); }
    .modal-body { padding: 15px !important; }
    
    /* Buttons */
    .btn { padding: 6px 12px; font-size: 0.85rem; }
    
    /* Dropdowns */
    .form-select.status-select { font-size: 0.75rem !important; }
}
