:root {
    /* Core palette — vibrant indigo/violet primary, warm accents for stat cards */
    --primary: #6366f1;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --secondary: #14b8a6;
    --secondary-light: #ccfbf1;
    --accent: #f59e0b;
    --accent-light: #fef3c7;
    --success: #10b981;
    --success-light: #d1fae5;
    --danger: #f43f5e;
    --danger-light: #ffe4e6;
    --info: #0ea5e9;
    --info-light: #e0f2fe;
    --purple: #a855f7;
    --purple-light: #f3e8ff;
    --pink: #ec4899;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --border: #e7eaf3;
    --text: #1e2233;
    --text-muted: #6b7290;

    --radius: .85rem;
    --radius-sm: .55rem;
    --shadow-sm: 0 1px 3px rgba(30, 34, 51, .06);
    --shadow: 0 6px 20px rgba(30, 34, 51, .08);
    --shadow-lg: 0 16px 40px rgba(30, 34, 51, .12);
}

* { box-sizing: border-box; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

h1, h2, h3, h4, h5, h6, .erp-brand {
    font-family: 'Manrope', 'IBM Plex Sans', sans-serif;
}

a { color: var(--primary); }
a:hover { color: var(--primary-dark); }

/* ================= Shell layout ================= */
.erp-shell {
    display: flex;
    min-height: 100vh;
}

.erp-sidebar {
    width: 272px;
    flex-shrink: 0;
    background: linear-gradient(165deg, #201c4d 0%, #4c1d95 100%);
    color: #d9d7f5;
    display: flex;
    flex-direction: column;
    transition: margin-left .25s ease;
    box-shadow: 4px 0 24px rgba(20, 15, 60, .18);
    z-index: 20;
}

.erp-sidebar.collapsed { margin-left: -272px; }

.erp-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: 1.3rem 1.35rem;
    color: #fff;
    font-weight: 800;
    font-size: 1.05rem;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}

.erp-brand .erp-brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    padding: 4px;
    box-shadow: 0 4px 12px rgba(10, 15, 40, .25);
    flex-shrink: 0;
}
.erp-brand .erp-brand-icon img { width: 100%; height: 100%; object-fit: contain; }

.erp-nav {
    flex: 1;
    overflow-y: auto;
    padding: .85rem .7rem;
}

.erp-nav-group { margin-bottom: .3rem; }

.erp-nav-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .55rem .55rem;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #a29ee0;
    cursor: pointer;
    user-select: none;
    border-radius: .5rem;
}

.erp-nav-section:hover { background: rgba(255, 255, 255, .05); color: #fff; }

.erp-nav-section .chevron {
    transition: transform .2s ease;
    font-size: .7rem;
}

.erp-nav-group.collapsed .chevron { transform: rotate(-90deg); }
.erp-nav-group.collapsed .erp-nav-links { display: none; }

.erp-nav-links { padding: .15rem 0 .4rem; }

.erp-nav a {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .55rem .65rem;
    margin: .1rem 0;
    color: #cdc9f0;
    text-decoration: none;
    font-size: .875rem;
    border-radius: .6rem;
    position: relative;
    transition: background .15s ease, color .15s ease, transform .1s ease;
}

.erp-nav a:hover {
    background: rgba(255, 255, 255, .08);
    color: #fff;
    transform: translateX(2px);
}

.erp-nav a.active {
    background: rgba(255, 255, 255, .14);
    color: #fff;
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--secondary);
}

.erp-nav a i {
    width: 20px;
    text-align: center;
    font-size: .95rem;
    opacity: .9;
}

.erp-nav a.active i { color: #5eead4; }

.erp-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.erp-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: .65rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 10;
    gap: 1rem;
}

.erp-topbar-title {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--text);
}

.erp-sidebar-toggle {
    background: var(--bg);
    border: 1px solid var(--border);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 1rem;
    color: var(--text);
    cursor: pointer;
    transition: background .15s ease;
}
.erp-sidebar-toggle:hover { background: var(--primary-light); color: var(--primary); }

.erp-search {
    position: relative;
    flex: 1;
    max-width: 360px;
}
.erp-search input {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 999px;
    padding: .5rem 1rem .5rem 2.3rem;
    font-size: .85rem;
    outline: none;
    transition: box-shadow .15s ease, background .15s ease;
}
.erp-search input:focus { background: #fff; box-shadow: 0 0 0 3px var(--primary-light); }
.erp-search i {
    position: absolute;
    left: .85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: .8rem;
}
.erp-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    max-height: 320px;
    overflow-y: auto;
    z-index: 30;
    display: none;
}
.erp-search-results.show { display: block; }
.erp-search-results a {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .9rem;
    font-size: .85rem;
    color: var(--text);
    text-decoration: none;
}
.erp-search-results a:hover, .erp-search-results a.active-result { background: var(--primary-light); color: var(--primary-dark); }
.erp-search-results a i { color: var(--text-muted); width: 16px; }

.erp-bell {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    cursor: pointer;
}
.erp-bell .dot {
    position: absolute;
    top: 6px;
    right: 7px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    border: 2px solid var(--surface);
}

.erp-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .85rem;
    flex-shrink: 0;
}

.erp-content {
    padding: 1.5rem;
    flex: 1;
}

/* ================= Module sub-nav ================= */
.erp-subnav {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: .25rem;
}
.erp-subnav a {
    padding: .35rem .75rem;
    border-radius: .35rem;
    font-size: .85rem;
    color: var(--text-muted);
    text-decoration: none;
}
.erp-subnav a.active, .erp-subnav a:hover { background: var(--primary); color: #fff; }

/* ================= Stat cards ================= */
.erp-stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.4rem;
    height: 100%;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: .6rem;
    transition: box-shadow .2s ease, transform .2s ease;
}
.erp-stat-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }

.erp-stat-icon {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.15rem;
    box-shadow: var(--shadow-sm);
}
.erp-stat-icon.bg-teal { background: linear-gradient(135deg, #2dd4bf, #0d9488); }
.erp-stat-icon.bg-blue { background: linear-gradient(135deg, #38bdf8, #0284c7); }
.erp-stat-icon.bg-indigo { background: linear-gradient(135deg, #818cf8, #4338ca); }
.erp-stat-icon.bg-amber { background: linear-gradient(135deg, #fbbf24, #d97706); }
.erp-stat-icon.bg-rose { background: linear-gradient(135deg, #fb7185, #e11d48); }
.erp-stat-icon.bg-purple { background: linear-gradient(135deg, #c084fc, #9333ea); }
.erp-stat-icon.bg-green { background: linear-gradient(135deg, #4ade80, #16a34a); }
.erp-stat-icon.bg-pink { background: linear-gradient(135deg, #f472b6, #db2777); }

.erp-stat-label {
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    font-weight: 600;
}
.erp-stat-value { font-size: 1.7rem; font-weight: 800; color: var(--text); line-height: 1.1; }
.erp-stat-sub { font-size: .8rem; color: var(--text-muted); }
.erp-stat-trend { font-size: .78rem; font-weight: 700; display: inline-flex; align-items: center; gap: .25rem; }
.erp-stat-trend.up { color: var(--success); }
.erp-stat-trend.down { color: var(--danger); }

/* ================= Cards / tables / forms ================= */
.card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    background: var(--surface);
    font-weight: 700;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0 !important;
    padding: .9rem 1.25rem;
}
.card-body { padding: 1.25rem; }
.card-footer { background: transparent; border-top: 1px solid var(--border); }

.table { color: var(--text); }
.table thead th {
    border-bottom: 1px solid var(--border);
    border-top: none;
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    font-weight: 700;
    background: #fafbff;
}
.table td { border-top: 1px solid var(--border); vertical-align: middle; }
.table-hover tbody tr:hover { background: var(--primary-light); }
.table-sm td, .table-sm th { padding: .5rem .6rem; }

.btn {
    border-radius: .6rem;
    font-weight: 600;
    font-size: .875rem;
    transition: transform .12s ease, box-shadow .12s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); border-color: var(--primary); box-shadow: 0 4px 14px rgba(99, 102, 241, .3); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary); border-color: var(--primary); }
.btn-outline-secondary { color: var(--text-muted); border-color: var(--border); }
.btn-outline-secondary:hover { background: var(--text-muted); border-color: var(--text-muted); }
.btn-sm { border-radius: .5rem; }

.form-control {
    border-radius: .55rem;
    border: 1px solid var(--border);
    font-size: .9rem;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
label { font-weight: 600; font-size: .82rem; color: var(--text); }

.badge { border-radius: 999px; font-weight: 700; padding: .38em .75em; font-size: .72rem; letter-spacing: .02em; }
.badge-success { background: var(--success-light); color: #047857; }
.badge-danger { background: var(--danger-light); color: #be123c; }
.badge-warning { background: var(--accent-light); color: #b45309; }
.badge-info { background: var(--info-light); color: #0369a1; }
.badge-secondary { background: #eef0f7; color: #475569; }
.badge-light { background: #f1f5f9; color: #475569; }
.badge-waived { background: var(--info-light); color: #0369a1; }
.badge-chargeable { background: var(--accent-light); color: #b45309; }

.alert { border-radius: var(--radius-sm); border: none; }
.alert-success { background: var(--success-light); color: #065f46; }
.alert-danger { background: var(--danger-light); color: #9f1239; }
.alert-info { background: var(--info-light); color: #075985; }

code {
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: .15em .5em;
    border-radius: .35rem;
    font-size: .85em;
}

/* DataTables restyle */
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    border-radius: .5rem;
    border: 1px solid var(--border);
    padding: .3rem .6rem;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: .5rem !important;
    margin: 0 2px;
    border: 1px solid transparent !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #fff !important;
}

/* Tom Select restyle */
.ts-wrapper.single .ts-control { border-radius: .55rem; border-color: var(--border); }
.ts-wrapper.focus .ts-control { border-color: var(--primary) !important; box-shadow: 0 0 0 3px var(--primary-light); }

/* Chart panel */
.erp-chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 1.25rem; height: 100%; }
.erp-chart-card .erp-chart-title { font-weight: 700; margin-bottom: .75rem; display: flex; justify-content: space-between; align-items: center; }
.erp-chart-legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: .35rem; }

.table-responsive-actions { white-space: nowrap; }

/* ================= Guest / login screen ================= */
.auth-scene {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #201c4d 0%, #4c1d95 55%, #7c3aed 100%);
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
}
.auth-scene::before, .auth-scene::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, .06);
}
.auth-scene::before { width: 420px; height: 420px; top: -120px; right: -120px; }
.auth-scene::after { width: 300px; height: 300px; bottom: -100px; left: -80px; }

.auth-card {
    background: #fff;
    border-radius: 1.25rem;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    padding: 2.25rem;
    position: relative;
    z-index: 1;
}
.auth-card .erp-brand { color: var(--text); padding: 0 0 1.5rem; border: none; }
.auth-card .erp-brand-icon { width: 52px; height: 52px; border-radius: 12px; box-shadow: var(--shadow); }
.auth-card .erp-brand span:last-child { font-size: 1.15rem; }

/* ================= Responsive ================= */
@media (max-width: 991.98px) {
    .erp-sidebar { position: fixed; left: 0; top: 0; bottom: 0; margin-left: -272px; }
    .erp-sidebar.mobile-open { margin-left: 0; }
    .erp-search { display: none; }
}

@media (max-width: 767.98px) {
    /* Title + inline legend fight for the same row once the title wraps —
       stack them instead of letting the legend overlap the second line. */
    .erp-chart-card .erp-chart-title { flex-direction: column; align-items: flex-start; gap: .35rem; }
}

/* ================= Print documents ================= */
@media print {
    .erp-shell, .erp-topbar, .no-print { display: none !important; }
}
