:root {
    --bg-soft: #f4f7fb;
    --card-shadow: 0 10px 24px rgba(12, 22, 44, 0.08);
    --sidebar-width: 250px;
    --app-bg-radial: radial-gradient(circle at 0% 0%, #dbeafe 0%, transparent 40%);
    --app-bg-linear: linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
    --sidebar-bg: linear-gradient(170deg, #0b3a8a 0%, #1e40af 45%, #155e75 100%);
    --sidebar-link: rgba(255, 255, 255, 0.88);
    --sidebar-link-active-bg: rgba(255, 255, 255, 0.15);
    --sidebar-link-active-text: #ffffff;
    --card-bg: #ffffff;
    --muted-text: #64748b;
    --calendar-bg: #ffffff;
    --calendar-border: #e2e8f0;
    --loader-bg: rgba(255, 255, 255, 0.5);
    --select2-bg: #ffffff;
    --select2-border: #ced4da;
    --select2-text: #212529;
    --category-option-type: #6c757d;
}

[data-bs-theme="dark"] {
    --bg-soft: #0f172a;
    --card-shadow: 0 18px 40px rgba(2, 6, 23, 0.55);
    --app-bg-radial: radial-gradient(circle at 10% -10%, rgba(56, 189, 248, 0.18) 0%, transparent 45%);
    --app-bg-linear: linear-gradient(180deg, #0f172a 0%, #111827 48%, #0b1220 100%);
    --sidebar-bg: linear-gradient(170deg, #0b1220 0%, #172554 48%, #083344 100%);
    --sidebar-link: rgba(226, 232, 240, 0.9);
    --sidebar-link-active-bg: rgba(148, 163, 184, 0.2);
    --sidebar-link-active-text: #f8fafc;
    --card-bg: #111827;
    --muted-text: #94a3b8;
    --calendar-bg: #1f2937;
    --calendar-border: #334155;
    --loader-bg: rgba(2, 6, 23, 0.55);
    --select2-bg: #111827;
    --select2-border: #334155;
    --select2-text: #e5e7eb;
    --category-option-type: #93c5fd;
}

body {
    background: var(--app-bg-radial), var(--app-bg-linear);
    min-height: 100vh;
    overflow-x: hidden;
}

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #fff;
    padding: 1rem;
    overflow: hidden;
    transition: width 0.25s ease, min-width 0.25s ease, flex-basis 0.25s ease, padding 0.25s ease;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
    flex-basis: 0;
    padding-left: 0;
    padding-right: 0;
}

.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .nav {
    opacity: 0;
    pointer-events: none;
}

.sidebar-brand {
    font-weight: 700;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 1.25rem;
    letter-spacing: 0.3px;
}

.sidebar-logo {
    display: block;
    max-width: 100%;
    width: 185px;
    height: auto;
    object-fit: contain;
}

.sidebar .nav-link {
    color: var(--sidebar-link);
    border-radius: 10px;
    margin-bottom: 0.8rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 1.3rem;
    padding: 0.65rem 0.75rem;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    background: var(--sidebar-link-active-bg);
    color: var(--sidebar-link-active-text);
}

.content {
    flex: 1;
    min-width: 0;
    background: transparent;
}

.card {
    border: none;
    box-shadow: var(--card-shadow);
    border-radius: 16px;
    background: var(--card-bg);
}

.stat-card span {
    color: var(--muted-text);
    font-size: 0.88rem;
}

.stat-card strong {
    font-size: 1.28rem;
}

.stat-card-large span {
    font-size: 1rem;
}

.stat-card-large strong {
    font-size: 2rem;
}

.dashboard-filter-bar {
    width: 100%;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: thin;
}

.dashboard-filter-bar #filterStart,
.dashboard-filter-bar #filterEnd {
    min-width: 150px;
    width: 150px;
}

.dashboard-filter-bar #btnRefreshDashboard {
    white-space: nowrap;
}

@media (min-width: 992px) {
    .dashboard-filter-bar {
        width: auto;
        margin-left: auto;
        justify-content: flex-end;
        overflow-x: visible;
    }
}

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.content .navbar .ms-auto {
    min-width: 0;
}

.content .navbar .dropdown .dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    max-width: min(320px, 40vw);
}

.content .navbar .dropdown .profile-name {
    display: inline-block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.loader-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: var(--loader-bg);
    z-index: 3000;
}

.auth-page {
    background: linear-gradient(160deg, #0f766e 0%, #1d4ed8 55%, #16a34a 100%);
}

.auth-card {
    max-width: 420px;
    margin: 8vh auto;
    border-radius: 20px;
    background: #fff;
    padding: 2rem;
}

.auth-logo {
    display: block;
    width: min(250px, 100%);
    height: auto;
    object-fit: contain;
}

.pwa-install-btn {
    color: #fff;
    font-weight: 700;
    box-shadow: 0 10px 24px rgba(13, 110, 253, 0.35);
}

.pwa-install-btn-inline {
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(420px, calc(100% - 2rem));
    margin: 1rem auto 0;
    border-radius: 16px;
    padding: 0.9rem 1.2rem;
    font-size: 1rem;
}

.pwa-install-btn-floating {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 4000;
    border-radius: 999px;
    padding: 0.6rem 1rem;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
}

.calendar-day {
    background: var(--calendar-bg);
    border-radius: 12px;
    padding: 0.5rem;
    min-height: 80px;
    border: 1px solid var(--calendar-border);
}

.transaction-table {
    table-layout: fixed;
}

.transaction-table th,
.transaction-table td {
    vertical-align: middle;
}

.transaction-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#tableIncome,
#tableExpense {
    table-layout: auto;
}

#tableIncome td,
#tableExpense td {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
}

#tableIncome th:nth-child(1),
#tableIncome td:nth-child(1),
#tableExpense th:nth-child(1),
#tableExpense td:nth-child(1),
#tableIncome th:nth-child(6),
#tableIncome td:nth-child(6),
#tableExpense th:nth-child(6),
#tableExpense td:nth-child(6) {
    white-space: nowrap;
}

#tableIncome td:nth-child(2),
#tableExpense td:nth-child(2) {
    min-width: 220px;
}

#tableReports {
    table-layout: auto;
    width: 100%;
}

#tableReports th,
#tableReports td {
    white-space: nowrap;
    vertical-align: middle;
}

#tableReports td:nth-child(3) {
    white-space: normal;
    overflow-wrap: anywhere;
}

.category-table {
    min-width: 680px;
}

.category-table td,
.category-table th {
    white-space: nowrap;
    vertical-align: middle;
}

.modal-backdrop {
    z-index: 2100;
}

.modal {
    z-index: 2110;
}

.select2-container {
    width: 100% !important;
}

.select2-container .select2-selection--single {
    height: calc(2.25rem + 2px) !important;
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--select2-border);
    border-radius: 0.375rem;
    background-color: var(--select2-bg);
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    padding-left: 0;
    line-height: 1.5;
    color: var(--select2-text);
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: calc(2.25rem + 2px);
    right: 0.5rem;
}

.select2-container--default.select2-container--focus .select2-selection--single {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.category-option-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
}

.category-option-left {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.category-option-left i {
    font-size: 0.95rem;
}

.category-option-type {
    margin-left: auto;
    font-size: 0.68rem;
    letter-spacing: 0.04em;
    color: var(--category-option-type);
    text-transform: uppercase;
    white-space: nowrap;
}

#categoryIconPreset + .select2 .icon-preset-option,
#categoryIconPreset + .select2 .select2-selection__rendered .icon-preset-option {
    justify-content: flex-start;
}

#categoryIconPreset + .select2 .icon-preset-option i,
#categoryIconPreset + .select2 .select2-selection__rendered .icon-preset-option i {
    font-size: 1.25rem;
    line-height: 1;
}

#categoryIconPreset + .select2 .select2-selection__rendered {
    padding-left: 0.25rem;
    text-align: left;
}

.icon-preset-grid {
    margin-top: 0.25rem;
}

.icon-preset-card {
    width: 100%;
    min-height: 3rem;
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    padding: 0.55rem 0.7rem;
    border-width: 1px;
    border-radius: 0.65rem;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.icon-preset-card i {
    font-size: 1.35rem;
    line-height: 1;
}

.category-icon-preset-radio:checked + .icon-preset-card {
    border-color: #0d6efd;
    background-color: rgba(13, 110, 253, 0.08);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.12);
}

.icon-preset-card:hover {
    transform: translateY(-1px);
}

[data-bs-theme="dark"] .content .navbar {
    background-color: rgba(17, 24, 39, 0.86) !important;
    backdrop-filter: blur(8px);
    border-color: #334155 !important;
}

[data-bs-theme="dark"] .btn-light {
    background-color: #1f2937;
    border-color: #374151;
    color: #e5e7eb;
}

[data-bs-theme="dark"] .dropdown-menu {
    background-color: #111827;
    border-color: #334155;
}

[data-bs-theme="dark"] .dropdown-item {
    color: #e5e7eb;
}

[data-bs-theme="dark"] .dropdown-item:hover,
[data-bs-theme="dark"] .dropdown-item:focus {
    background-color: #1f2937;
}

[data-bs-theme="dark"] .table {
    --bs-table-bg: transparent;
    --bs-table-color: #e5e7eb;
    --bs-table-border-color: #334155;
    --bs-table-striped-bg: rgba(30, 41, 59, 0.32);
}

[data-bs-theme="dark"] .dataTables_wrapper .dataTables_filter input,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_length select {
    background-color: #0f172a;
    color: #e5e7eb;
    border-color: #334155;
}

[data-bs-theme="dark"] .dataTables_wrapper .dataTables_info,
[data-bs-theme="dark"] .dataTables_wrapper .dataTables_paginate .paginate_button {
    color: #cbd5e1 !important;
}

.tab-pane .dataTables_wrapper,
.tab-pane .dataTables_scroll,
.tab-pane .dataTables_scrollHead,
.tab-pane .dataTables_scrollBody {
    width: 100% !important;
}

@media print {
    body * {
        visibility: hidden !important;
    }

    #reportPrintArea,
    #reportPrintArea * {
        visibility: visible !important;
    }

    #reportPrintArea {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        background: #fff;
        padding: 0;
        margin: 0;
    }

    #reportPrintArea .table-responsive {
        overflow: visible !important;
    }

    #reportPrintArea table {
        width: 100% !important;
    }

    #reportPrintArea .dataTables_length,
    #reportPrintArea .dataTables_filter,
    #reportPrintArea .dataTables_info,
    #reportPrintArea .dataTables_paginate {
        display: none !important;
    }

}

@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        z-index: 2000;
        height: 100%;
        top: 0;
        left: 0;
        width: var(--sidebar-width);
        min-width: var(--sidebar-width);
        flex-basis: var(--sidebar-width);
        padding: 1rem;
        transform: translateX(-100%);
        box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
    }

    .sidebar.collapsed {
        width: var(--sidebar-width);
        min-width: var(--sidebar-width);
        flex-basis: var(--sidebar-width);
        padding: 1rem;
        transform: translateX(-100%);
    }

    .sidebar.collapsed .sidebar-brand,
    .sidebar.collapsed .nav {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .content {
        width: 100%;
    }

    .content .navbar {
        position: sticky;
        top: 0;
        z-index: 1020;
    }

    .content .navbar .dropdown .dropdown-toggle {
        max-width: 48vw;
    }

    #tableIncome td,
    #tableExpense td {
        font-size: 0.92rem;
    }

    .report-table {
        min-width: 760px;
    }

    #tableReports th,
    #tableReports td {
        font-size: 0.9rem;
        padding: 0.5rem 0.45rem;
    }

    .calendar-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
