:root {
    --sidebar-width: 260px;
    --brand: #1e3a5f;
    --brand-light: #2c5282;
    --brand-accent: #3b82f6;

    --bg-body: #f4f6fa;
    --bg-surface: #ffffff;
    --bg-surface-alt: #f8fafc;
    --text-primary: #1e293b;
    --text-muted: #64748b;
    --border-color: #e6e9ef;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .06);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, .08);
    --shadow-lg: 0 10px 40px rgba(15, 23, 42, .16);
}

[data-bs-theme="dark"] {
    --bg-body: #0f172a;
    --bg-surface: #1a2436;
    --bg-surface-alt: #1e293b;
    --text-primary: #e2e8f0;
    --text-muted: #94a3b8;
    --border-color: #2d3b52;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .35);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .5);
}

* { transition: background-color .15s ease, border-color .15s ease, color .15s ease; }

body {
    background: var(--bg-body);
    color: var(--text-primary);
    font-size: 0.9rem;
}

a { text-decoration: none; }

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

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--brand) 0%, #16283f 100%);
    color: #fff;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    overflow-y: auto;
    z-index: 1030;
    box-shadow: var(--shadow-md);
}

.sidebar-brand {
    padding: 1.1rem 1rem;
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: .2px;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
    color: #fff;
    display: block;
}

.sidebar-section-label {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .38);
    padding: 1rem 1rem .35rem;
}

.sidebar .nav-link {
    color: rgba(255, 255, 255, .78);
    padding: .55rem 1rem;
    border-left: 3px solid transparent;
    border-radius: 0 .4rem .4rem 0;
    margin: 0 .4rem 0 0;
    font-size: .87rem;
}

.sidebar .nav-link i {
    width: 1.3rem;
    display: inline-block;
    opacity: .85;
}

.sidebar .nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, .08);
}

.sidebar .nav-link.active {
    color: #fff;
    background: var(--brand-accent);
    border-left-color: #fff;
    font-weight: 600;
}

.main {
    margin-left: var(--sidebar-width);
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: .6rem 1rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.content {
    padding: 1.4rem;
    flex-grow: 1;
}

.card, .kpi-card {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: .7rem;
    box-shadow: var(--shadow-sm);
}

.kpi-card .kpi-value {
    font-size: 1.65rem;
    font-weight: 700;
}

.btn {
    border-radius: .5rem;
}

.btn-primary {
    background: var(--brand-accent);
    border-color: var(--brand-accent);
}

.table {
    color: var(--text-primary);
}

.modal-content {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-radius: .8rem;
    border: none;
    box-shadow: var(--shadow-lg);
}

.badge-status {
    padding: .3rem .6rem;
    border-radius: .4rem;
    font-size: .75rem;
    font-weight: 600;
}

.badge-active { background: #dcfce7; color: #166534; }
.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-maint { background: #fef9c3; color: #854d0e; }
.badge-inactive { background: #e2e8f0; color: #475569; }

[data-bs-theme="dark"] .badge-active { background: rgba(34, 197, 94, .18); color: #4ade80; }
[data-bs-theme="dark"] .badge-overdue { background: rgba(239, 68, 68, .18); color: #f87171; }
[data-bs-theme="dark"] .badge-warning,
[data-bs-theme="dark"] .badge-maint { background: rgba(234, 179, 8, .18); color: #facc15; }
[data-bs-theme="dark"] .badge-info { background: rgba(59, 130, 246, .18); color: #60a5fa; }
[data-bs-theme="dark"] .badge-inactive { background: rgba(148, 163, 184, .18); color: #cbd5e1; }

.dot-active, .dot-noinvoice, .dot-overdue, .dot-paid, .dot-maint, .dot-inactive {
    display: inline-block;
    width: .6rem;
    height: .6rem;
    border-radius: 50%;
}
.dot-active { background: #16a34a; }
.dot-noinvoice { background: #94a3b8; }
.dot-overdue { background: #dc2626; }
.dot-paid { background: #2563eb; }
.dot-maint { background: #d97706; }
.dot-inactive { background: #cbd5e1; }

.icon-btn {
    width: 2.1rem;
    height: 2.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: .5rem;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-primary);
}
.icon-btn:hover { background: var(--bg-surface-alt); }

#globalSearchResults {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: .5rem;
    box-shadow: var(--shadow-md);
    max-height: 70vh;
    overflow-y: auto;
    z-index: 1050;
    display: none;
}

#globalSearchResults .search-group-title {
    font-size: .7rem;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: .4rem .8rem 0;
}

#globalSearchResults a.search-item {
    display: block;
    padding: .5rem .8rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

#globalSearchResults a.search-item:hover {
    background: var(--bg-surface-alt);
}

.auth-body {
    background: radial-gradient(circle at top left, var(--brand-light), var(--brand) 60%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: none;
    border-radius: .9rem;
    box-shadow: var(--shadow-lg);
}

.auth-topbar {
    width: 100%;
    max-width: 380px;
    display: flex;
    justify-content: flex-end;
    gap: .4rem;
    margin-bottom: .75rem;
}

.theme-toggle, .lang-switch a {
    cursor: pointer;
}

.lang-switch a.active {
    font-weight: 700;
    text-decoration: underline;
}

.global-search-wrap {
    max-width: 320px;
    min-width: 0;
}

@media (max-width: 991.98px) {
    .sidebar {
        left: calc(-1 * var(--sidebar-width));
        transition: left .2s ease;
    }
    .sidebar.show { left: 0; }
    .main { margin-left: 0; }
}

@media (max-width: 575.98px) {
    .global-search-wrap { max-width: 160px; }
    .content { padding: .85rem; }
    .topbar { padding: .5rem .6rem; }
}

/* Chart container heights dikecilkan di layar sempit supaya tidak makan
   terlalu banyak scroll vertikal (lebar tetap responsive lewat Chart.js). */
@media (max-width: 767.98px) {
    canvas { max-height: 220px; }
}

/* Tab laporan (7 tab) jangan sampai overflow horizontal di HP — biarkan wrap. */
.nav-tabs {
    flex-wrap: wrap;
}

/* DataTables bawaan: pastikan kontrol search/length/pagination tidak
   memaksa lebar minimum yang bikin overflow horizontal di layar sempit. */
.dataTables_wrapper .row {
    margin-left: 0;
    margin-right: 0;
}
@media (max-width: 575.98px) {
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_paginate {
        text-align: left !important;
        float: none !important;
        width: 100%;
        margin-bottom: .5rem;
    }
}
