:root {
    --sidebar-width: 260px;
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --border-color: #e2e8f0;
    --navbar-bg: #ffffff;
}

[data-theme="dark"] {
    --body-bg: #0f172a;
    --card-bg: #1e293b;
    --text-color: #e2e8f0;
    --border-color: #334155;
    --navbar-bg: #1e293b;
}

* { box-sizing: border-box; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--body-bg); color: var(--text-color); margin: 0; }
.wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width); background: var(--sidebar-bg); color: var(--sidebar-text);
    position: fixed; top: 0; left: 0; height: 100vh; overflow-y: auto; z-index: 1000;
    transition: transform 0.3s ease;
}
.sidebar-header { padding: 1.25rem; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-logo { max-height: 50px; max-width: 100%; }
.sidebar-nav { list-style: none; padding: 0.5rem 0; margin: 0; }
.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.7rem 1.25rem;
    color: var(--sidebar-text); text-decoration: none; transition: all 0.2s;
}
.sidebar-nav .nav-link:hover, .sidebar-nav .nav-link.active {
    background: rgba(79, 70, 229, 0.35); color: #fff; font-weight: 600;
}
.sidebar-nav .nav-link.active { border-left: 3px solid #818cf8; padding-left: calc(1.25rem - 3px); }
.sidebar-nav .nav-link i { width: 20px; text-align: center; flex-shrink: 0; }
.submenu { list-style: none; padding: 0; margin: 0; display: none; background: rgba(0,0,0,0.2); }
.submenu li a {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.5rem 1.25rem 0.5rem 3rem; color: var(--sidebar-text);
    text-decoration: none; font-size: 0.875rem; transition: all 0.2s;
}
.submenu li a:hover { color: #fff; background: rgba(255,255,255,0.06); }
.submenu li a.active {
    color: #fff; background: rgba(79, 70, 229, 0.45); font-weight: 600;
    border-left: 3px solid #818cf8; padding-left: calc(3rem - 3px);
}
.has-submenu.open .submenu { display: block; }
.has-submenu.open > .nav-link { color: #fff; }
.has-submenu.open .submenu-arrow { transform: rotate(180deg); }
.submenu-arrow { margin-left: auto; font-size: 0.7rem; transition: transform 0.2s; }

.sidebar-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
    z-index: 999; opacity: 0; transition: opacity 0.25s ease;
}
.sidebar-backdrop.show { display: block; opacity: 1; }
body.sidebar-open { overflow: hidden; }

.content {
    flex: 1; width: 100%; min-width: 0; margin-left: var(--sidebar-width);
    display: flex; flex-direction: column; min-height: 100vh; transition: margin-left 0.3s;
}
.top-navbar {
    background: var(--navbar-bg); border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1rem; display: flex; align-items: center; gap: 1rem; position: sticky; top: 0; z-index: 999;
}
.navbar-title { font-weight: 600; font-size: 1.1rem; flex: 1; }
.navbar-actions { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }
.workspace-badge { font-size: 0.8rem; white-space: nowrap; }

.dt-export-btn,
.export-icon-btns .btn {
    margin-right: 4px;
    padding: 0.35rem 0.5rem !important;
    min-width: 2.1rem;
    line-height: 1;
    border: none !important;
    color: #fff !important;
    box-shadow: none !important;
}
.export-icon-btns .btn i,
.dt-export-btn i { pointer-events: none; color: #fff !important; }
div.dt-buttons .dt-export-btn { min-width: 2.1rem; }
.dt-buttons { margin-bottom: 0; gap: 4px; }

.dt-export-excel,
.export-btn-excel { background-color: #198754 !important; }
.dt-export-excel:hover,
.export-btn-excel:hover { background-color: #157347 !important; color: #fff !important; }

.dt-export-csv,
.export-btn-csv { background-color: #0d6efd !important; }
.dt-export-csv:hover,
.export-btn-csv:hover { background-color: #0b5ed7 !important; color: #fff !important; }

.dt-export-pdf,
.export-btn-pdf { background-color: #dc3545 !important; }
.dt-export-pdf:hover,
.export-btn-pdf:hover { background-color: #bb2d3b !important; color: #fff !important; }

.dt-export-print,
.report-export-actions .btn-report-print-standalone {
    background-color: #1e3a5f !important;
    border-color: #1e3a5f !important;
    color: #fff !important;
    font-weight: 600;
    padding-left: 0.85rem;
    padding-right: 0.85rem;
}
.report-export-actions .btn-report-print-standalone:hover {
    background-color: #152a45 !important;
    border-color: #152a45 !important;
    color: #fff !important;
}

.export-btn-print { background-color: #6c757d !important; }
.dt-export-print:hover,
.export-btn-print:hover { background-color: #5c636a !important; color: #fff !important; }

/* Head balance report — WhatsApp language buttons */
.btn-head-wa {
    color: #fff !important;
    font-weight: 600;
    border: none !important;
}
.btn-head-wa i { color: #fff !important; }
.btn-head-wa-en {
    background-color: #0d6efd !important;
}
.btn-head-wa-en:hover,
.btn-head-wa-en:focus {
    background-color: #0b5ed7 !important;
    color: #fff !important;
}
.btn-head-wa-hi {
    background-color: #e67e22 !important;
}
.btn-head-wa-hi:hover,
.btn-head-wa-hi:focus {
    background-color: #d35400 !important;
    color: #fff !important;
}

[data-theme="dark"] .btn-head-wa-en { background-color: #3b82f6 !important; }
[data-theme="dark"] .btn-head-wa-en:hover { background-color: #2563eb !important; }
[data-theme="dark"] .btn-head-wa-hi { background-color: #f59e0b !important; color: #1e293b !important; }
[data-theme="dark"] .btn-head-wa-hi i { color: #1e293b !important; }
[data-theme="dark"] .btn-head-wa-hi:hover { background-color: #d97706 !important; color: #1e293b !important; }

[data-theme="dark"] .dt-export-excel,
[data-theme="dark"] .export-btn-excel { background-color: #22c55e !important; }
[data-theme="dark"] .dt-export-excel:hover,
[data-theme="dark"] .export-btn-excel:hover { background-color: #16a34a !important; }

[data-theme="dark"] .dt-export-csv,
[data-theme="dark"] .export-btn-csv { background-color: #3b82f6 !important; }
[data-theme="dark"] .dt-export-csv:hover,
[data-theme="dark"] .export-btn-csv:hover { background-color: #2563eb !important; }

[data-theme="dark"] .dt-export-pdf,
[data-theme="dark"] .export-btn-pdf { background-color: #ef4444 !important; }
[data-theme="dark"] .dt-export-pdf:hover,
[data-theme="dark"] .export-btn-pdf:hover { background-color: #dc2626 !important; }

[data-theme="dark"] .dt-export-print,
[data-theme="dark"] .export-btn-print { background-color: #94a3b8 !important; color: #0f172a !important; }
[data-theme="dark"] .dt-export-print i,
[data-theme="dark"] .export-btn-print i { color: #0f172a !important; }
[data-theme="dark"] .dt-export-print:hover,
[data-theme="dark"] .export-btn-print:hover { background-color: #cbd5e1 !important; }
.select2-container--bootstrap-5 .select2-selection { min-height: 38px; }
.fee-grid input.form-control-sm { min-width: 70px; padding: 0.2rem 0.35rem; text-align: right; }
.fee-grid input.fee-input-disabled,
.fee-grid input.fee-input:disabled {
    background-color: #e9ecef;
    color: #6c757d;
    cursor: not-allowed;
    opacity: 0.85;
}
[data-theme="dark"] .fee-grid input.fee-input-disabled,
[data-theme="dark"] .fee-grid input.fee-input:disabled {
    background-color: #334155;
    color: #94a3b8;
}
.fee-grid th { font-size: 0.8rem; text-align: center; white-space: nowrap; }
.fee-grid td:first-child { font-weight: 500; white-space: nowrap; }
.fee-grid-wrap { max-height: 70vh; }
.fee-grid th:first-child,
.fee-grid td:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    background: var(--card-bg);
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.06);
}
.fee-grid th.col-total-head,
.fee-grid th.col-net-head,
.fee-grid td.row-total,
.fee-grid td.row-net,
.fee-grid tfoot td.grand-total,
.fee-grid tfoot td.net-total,
.fee-grid tfoot td.gross-total {
    position: sticky;
    right: 0;
    z-index: 3;
    background: var(--card-bg);
    box-shadow: -2px 0 4px rgba(0, 0, 0, 0.06);
    font-weight: 600;
    text-align: right;
    min-width: 6.5rem;
}
.fee-grid tfoot td {
    background: #f8fafc;
    font-weight: 600;
}
[data-theme="dark"] .fee-grid tfoot td { background: #1e293b; }
.main-content { padding: 1.5rem; flex: 1; }

.card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 0.75rem; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.card-header { background: transparent; border-bottom: 1px solid var(--border-color); font-weight: 600; padding: 1rem 1.25rem; }
.card-body { padding: 1.25rem; }

.stat-card { border-left: 4px solid var(--primary); }
.stat-card .stat-icon { font-size: 2rem; opacity: 0.7; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-card .stat-label { color: #64748b; font-size: 0.875rem; }
[data-theme="dark"] .stat-card .stat-label { color: #94a3b8; }
.stat-breakdown { margin-top: 0.65rem; padding-top: 0.55rem; border-top: 1px solid rgba(148, 163, 184, 0.25); }
.stat-breakdown-line {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.72rem;
    color: #64748b;
    line-height: 1.45;
}
.stat-breakdown-line span:last-child { font-weight: 600; color: #334155; white-space: nowrap; }
[data-theme="dark"] .stat-breakdown-line { color: #94a3b8; }
[data-theme="dark"] .stat-breakdown-line span:last-child { color: #e2e8f0; }
.stat-card .stat-value { font-size: 1.35rem; }

.stat-card.primary { border-color: #4f46e5; }
.stat-card.success { border-color: #22c55e; }
.stat-card.warning { border-color: #f59e0b; }
.stat-card.danger { border-color: #ef4444; }
.stat-card.info { border-color: #3b82f6; }
.stat-card.purple { border-color: #a855f7; }

.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.loading-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex;
    align-items: center; justify-content: center; z-index: 9999;
}

.table th { font-weight: 600; font-size: 0.85rem; white-space: nowrap; }
.form-label { font-weight: 500; font-size: 0.875rem; margin-bottom: 0.25rem; }
.required::after { content: ' *'; color: #ef4444; }

/* Keyboard / desktop-friendly focus */
.form-control:focus,
.form-select:focus,
.form-check-input:focus,
.btn:focus-visible {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(79, 70, 229, 0.2);
    outline: none;
}
.fee-grid .fee-input:focus,
.fee-grid input[type="number"]:focus {
    background: #eef2ff;
    border-color: var(--primary);
}
[data-theme="dark"] .fee-grid .fee-input:focus,
[data-theme="dark"] .fee-grid input[type="number"]:focus {
    background: #312e81;
}
.modal .form-control,
.modal .form-select {
    min-height: 38px;
}
.card-body > .row.g-3 > [class*="col-"] {
    margin-bottom: 0.15rem;
}

.fee-grid input[type="number"] { width: 90px; text-align: right; }
.fee-grid th, .fee-grid td { font-size: 0.8rem; padding: 0.35rem !important; }

.bus-month-grid-wrap { overflow-x: auto; }
.bus-month-grid th,
.bus-month-grid td { font-size: 0.8rem; padding: 0.35rem !important; white-space: nowrap; }
.bus-month-grid .month-fee {
    min-width: 64px;
    width: 72px;
    text-align: right;
    padding: 0.2rem 0.35rem;
}
.bus-month-grid .month-fee:disabled {
    background: #f1f5f9;
    color: #64748b;
}
[data-theme="dark"] .bus-month-grid .month-fee:disabled {
    background: #1e293b;
    color: #94a3b8;
}

.student-photo-preview {
    width: 120px;
    height: 140px;
    object-fit: cover;
}

.rc-fee-cell { min-width: 95px; vertical-align: top; }
.rc-fee-cell .rc-bal { line-height: 1.2; margin-bottom: 2px; }
.rc-fee-cell .pay-amt { width: 100%; min-width: 0; }
.rc-fee-cell.cell-none { background: #fff; }
.rc-fee-cell.cell-partial { background: #f8d7da; }
.rc-fee-cell.cell-full { background: #d1e7dd; }
[data-theme="dark"] .rc-fee-cell.cell-none { background: var(--bs-body-bg, #1e293b); }
[data-theme="dark"] .rc-fee-cell.cell-partial { background: #5c2a2a; }
[data-theme="dark"] .rc-fee-cell.cell-full { background: #1e4d36; }

.receipt-top-row > [class*="col-"] { display: flex; }
.receipt-top-row .card { flex: 1; width: 100%; }
.receipt-student-info {
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    padding-top: 0.75rem;
}
.receipt-student-empty {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.receipt-search-results { max-height: 180px; overflow-y: auto; }
.receipt-fee-grid-wrap { max-height: calc(100vh - 480px); min-height: 240px; overflow: auto; }
.receipt-fee-card .card-body { padding-bottom: 1rem; }
.receipt-totals {
    max-width: 320px;
    margin-left: auto;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 0.375rem;
    overflow: hidden;
}
.receipt-totals-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
    background: var(--bs-body-bg, #fff);
}
.receipt-totals-row:last-child { border-bottom: none; }
.receipt-totals-grand {
    background: #d1e7dd;
    font-size: 1.05rem;
}
[data-theme="dark"] .receipt-totals-grand { background: #1e4d36; }
.receipt-legend .legend-box {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 1px solid #ccc;
    vertical-align: middle;
    margin-right: 2px;
}
.receipt-legend .legend-box.cell-full { background: #d1e7dd; }
.receipt-legend .legend-box.cell-partial { background: #f8d7da; }
.receipt-legend .legend-box.cell-none { background: #fff; }

.page-filter-panel { display: none; }
.page-filter-panel.show { display: block; }
.page-filter-wrap .card.border { border-color: var(--bs-border-color, #dee2e6) !important; }
.page-filter-actions .btn-primary { min-width: 88px; }

.receipt-print { max-width: 800px; margin: 0 auto; }
.receipt-thermal { width: 80mm; font-size: 12px; font-family: monospace; }

@media (max-width: 991.98px) {
    .sidebar { transform: translateX(-100%); box-shadow: none; }
    .sidebar.active {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
    }
    .content { margin-left: 0 !important; }
    .main-content { padding: 1rem; }
    .top-navbar { padding: 0.5rem 0.75rem; gap: 0.5rem; }
    .navbar-title { font-size: 1rem; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .navbar-actions { gap: 0.25rem; }
    .workspace-badge { font-size: 0.75rem; padding: 0.25rem 0.5rem; }
    .workspace-badge .text-muted { display: none; }
    .table-responsive { -webkit-overflow-scrolling: touch; }
}

@media print {
    .sidebar, .sidebar-backdrop, .top-navbar, .footer, .no-print { display: none !important; }
    .content { margin-left: 0 !important; }
    .main-content { padding: 0 !important; }
}

.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}
.login-card { width: 100%; max-width: 420px; border-radius: 1rem; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }

.permission-matrix th, .permission-matrix td { text-align: center; vertical-align: middle; }
.permission-matrix input[type="checkbox"] { width: 18px; height: 18px; }

.scroll-sticky-table {
    max-height: 280px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}
.scroll-sticky-table .crud-matrix-table {
    border-collapse: separate;
    border-spacing: 0;
}
.scroll-sticky-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: #f8f9fa;
    box-shadow: 0 1px 0 var(--border-color);
}
[data-theme="dark"] .scroll-sticky-table thead th {
    background-color: #334155;
}

/* Users permissions matrix: frozen header + scrollable body */
.crud-matrix-panel {
    overflow: hidden;
}
.crud-matrix-panel .crud-matrix-table {
    width: 100%;
    table-layout: fixed;
    margin-bottom: 0;
    border-collapse: collapse;
}
.crud-matrix-panel .crud-col-page { width: 34%; }
.crud-matrix-panel .crud-col-action { width: 11%; }
.crud-matrix-head thead th {
    background-color: #f8f9fa;
    border-bottom-width: 1px;
}
[data-theme="dark"] .crud-matrix-head thead th {
    background-color: #334155;
}
.crud-matrix-body-wrap {
    max-height: 240px;
    overflow-y: scroll;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
}
.crud-matrix-body {
    border-top: 0;
}
.crud-matrix-body tbody tr:first-child td {
    border-top: 0;
}
.crud-matrix-body-wrap::-webkit-scrollbar {
    width: 10px;
}
.crud-matrix-body-wrap::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 5px;
}
.crud-matrix-body-wrap::-webkit-scrollbar-track {
    background: #f1f5f9;
}
[data-theme="dark"] .crud-matrix-body-wrap::-webkit-scrollbar-thumb {
    background: #475569;
}
[data-theme="dark"] .crud-matrix-body-wrap::-webkit-scrollbar-track {
    background: #1e293b;
}

.chart-container { position: relative; height: 300px; }
