:root {
    --sb-primary: #16a34a;
    --sb-primary-strong: #15803d;
    --sb-primary-deep: #166534;
    --sb-primary-bright: #22c55e;
    --sb-primary-soft: #dcfce7;
    --sb-bg: #f3f8f4;
    --sb-sidebar: #0b1a12;
    --bs-primary: #16a34a;
    --bs-primary-rgb: 22, 163, 74;
}
* { box-sizing: border-box; }

/* Green primary theme overrides for Bootstrap utilities used across the app */
.btn-primary {
    --bs-btn-bg: var(--sb-primary); --bs-btn-border-color: var(--sb-primary);
    --bs-btn-hover-bg: var(--sb-primary-strong); --bs-btn-hover-border-color: var(--sb-primary-strong);
    --bs-btn-active-bg: var(--sb-primary-deep); --bs-btn-active-border-color: var(--sb-primary-deep);
    --bs-btn-disabled-bg: var(--sb-primary); --bs-btn-disabled-border-color: var(--sb-primary);
}
.btn-outline-primary {
    --bs-btn-color: var(--sb-primary); --bs-btn-border-color: var(--sb-primary);
    --bs-btn-hover-bg: var(--sb-primary); --bs-btn-hover-border-color: var(--sb-primary);
    --bs-btn-active-bg: var(--sb-primary); --bs-btn-active-border-color: var(--sb-primary);
}
.text-primary { color: var(--sb-primary) !important; }
.bg-primary { background-color: var(--sb-primary) !important; }
.text-bg-primary { background-color: var(--sb-primary) !important; color: #fff !important; }
.badge.text-bg-primary { background-color: var(--sb-primary) !important; }
.link-primary { color: var(--sb-primary) !important; }
.border-primary { border-color: var(--sb-primary) !important; }
.progress-bar { background-color: var(--sb-primary); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--sb-primary); }
.page-link { color: var(--sb-primary); }
.page-item.active .page-link { background-color: var(--sb-primary); border-color: var(--sb-primary); }
.form-check-input:checked { background-color: var(--sb-primary); border-color: var(--sb-primary); }
.form-control:focus, .form-select:focus, .form-check-input:focus {
    border-color: var(--sb-primary-bright);
    box-shadow: 0 0 0 .2rem rgba(22, 163, 74, .18);
}
a { color: var(--sb-primary); }
a:hover { color: var(--sb-primary-strong); }
.feature-icon { width: 44px; height: 44px; flex: 0 0 44px; display: grid; place-items: center; border-radius: 12px; color: var(--sb-primary); background: var(--sb-primary-soft); font-size: 1.1rem; }
html, body { max-width: 100%; overflow-x: hidden; }
body { background: var(--sb-bg); font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
.app-shell { min-height: 100vh; }
.app-main { min-width: 0; width: 100%; padding: 1rem; }
.sidebar {
    --bs-offcanvas-width: min(82vw, 280px);
    color: #fff; background: linear-gradient(180deg, var(--sb-sidebar), #101a2e);
    border-right: 1px solid rgba(255,255,255,.05);
    display: flex; flex-direction: column; overflow: hidden;
}
.sidebar-inner { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; overflow: hidden; }
.sidebar-inner > nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.sidebar-footer { flex: 0 0 auto; padding-top: .25rem; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer .nav-section { padding-top: .65rem; }
.sidebar-inner > form { flex: 0 0 auto; }
.sidebar .brand { display: flex; align-items: center; gap: .65rem; padding: .25rem 0 1rem; border-bottom: 1px solid rgba(255,255,255,.08); margin-bottom: 1rem; }
.sidebar .brand-logo { width: 40px; height: 40px; flex: 0 0 40px; border-radius: 12px; background: linear-gradient(135deg, #4ade80, #16a34a); display: grid; place-items: center; color: #fff; font-weight: 700; }
.sidebar a.nav-link { color: rgba(255,255,255,.72); display: flex; align-items: center; gap: .7rem; padding: .65rem .9rem; border-radius: .75rem; font-size: .93rem; font-weight: 500; }
.sidebar a.nav-link i { width: 1.2rem; text-align: center; font-size: 1.05rem; }
.sidebar a.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar a.nav-link.active { color: #fff; background: linear-gradient(135deg, rgba(22,163,74,.4), rgba(22,163,74,.16)); box-shadow: inset 3px 0 0 #4ade80; }
.sidebar .nav-section { padding: 1rem .9rem .3rem; color: rgba(255,255,255,.35); font-size: .72rem; text-transform: uppercase; letter-spacing: .09em; }
.card-soft { border: 0; border-radius: 1rem; box-shadow: 0 8px 24px rgba(15,23,42,.06); }
.renewal-plan-option { cursor: pointer; border: 1px solid #e2e8f0; transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease; }
.renewal-plan-option:hover { border-color: var(--sb-primary); transform: translateY(-1px); }
.renewal-plan-option:has(input:checked) { border-color: var(--sb-primary); box-shadow: 0 0 0 3px rgba(22,163,74,.14); }
.card-stat { border: 0; border-radius: 1rem; overflow: hidden; }
.card-stat .stat-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.15rem; }
.status-dot { width: .8rem; height: .8rem; border-radius: 50%; display: inline-block; }
.status-connected { background: #16a34a; box-shadow: 0 0 0 6px rgba(22,163,74,.15); }
.status-disconnected { background: #dc2626; box-shadow: 0 0 0 6px rgba(220,38,38,.15); }
.badge-status { padding: .35rem .6rem; border-radius: .5rem; font-weight: 500; white-space: nowrap; }
.topbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; padding: .8rem; background: #fff; border-radius: 1rem; box-shadow: 0 8px 24px rgba(15,23,42,.05); }
.page-heading { display: flex; align-items: flex-start; gap: .65rem; min-width: 0; }
.page-heading-text { min-width: 0; }
.page-heading-text .small { line-height: 1.35; }
.topbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: .5rem; width: 100%; }
.topbar .user-chip { display: inline-flex; align-items: center; gap: .6rem; padding: .3rem .65rem; background: #f1f5f9; border-radius: 999px; font-size: .88rem; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: linear-gradient(135deg, #4ade80, #16a34a); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.quick-btn { border-radius: .75rem; }
.icon-btn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: .5rem; }
.table thead th { color: #64748b; border-bottom: 1px solid #e2e8f0; font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.table tbody td { vertical-align: middle; }
.stat-value { overflow-wrap: anywhere; }
.invoice-toolbar { display: grid; gap: .75rem; margin-bottom: 1rem; }
.invoice-filters { display: grid; grid-template-columns: 1fr; gap: .5rem; }
.invoice-primary-actions { display: grid; grid-template-columns: 1fr; gap: .5rem; }
.invoice-primary-actions .btn { white-space: nowrap; }
.bulk-actions { flex-direction: column; align-items: stretch; gap: .65rem; }
.bulk-buttons { display: flex; flex-wrap: wrap; gap: .4rem; }
.invoice-table-wrap { overflow: visible; }
.invoice-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .3rem; }
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; display: flex; justify-content: space-around; align-items: stretch; gap: 2px; padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid #e2e8f0; box-shadow: 0 -6px 20px rgba(15,23,42,.08); }
.bottom-nav-link { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: .35rem .1rem; border: 0; background: none; color: #64748b; font-size: .66rem; font-weight: 600; text-decoration: none; border-radius: .6rem; min-width: 0; }
.bottom-nav-link i { font-size: 1.2rem; line-height: 1; }
.bottom-nav-link span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bottom-nav-link.active { color: var(--sb-primary); }
.bottom-nav-link:active { background: #f1f5f9; }
@media (max-width: 991.98px) {
    .app-main { padding-bottom: 5rem; }
}
@media (max-width: 767.98px) {
    .card-soft { border-radius: .85rem; }
    .card-soft > .card-body { padding: .85rem; }
    .invoice-summary > [class*="col-"] { min-width: 0; }
    .invoice-summary .card-body { min-height: 104px; padding: .8rem; }
    .invoice-summary .stat-value { font-size: 1rem !important; }
    .invoice-table { margin: 0; }
    .invoice-table thead { display: none; }
    .invoice-table tbody, .invoice-table tr, .invoice-table td { display: block; width: 100%; }
    .invoice-table tr { position: relative; margin-bottom: .75rem; padding: .8rem; background: #fff; border: 1px solid #e2e8f0; border-radius: .8rem; box-shadow: 0 4px 14px rgba(15,23,42,.05); }
    .invoice-table td { display: grid; grid-template-columns: 94px minmax(0, 1fr); gap: .6rem; padding: .35rem 0; text-align: left !important; border: 0; }
    .invoice-table td::before { content: attr(data-label); color: #64748b; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
    .invoice-table td.invoice-select { display: block; position: absolute; top: .7rem; right: .7rem; width: auto; padding: 0; }
    .invoice-table td.invoice-select::before { display: none; }
    .invoice-table td.invoice-number { padding-right: 2rem; }
    .invoice-table td.invoice-actions-cell { display: block; padding-top: .65rem; border-top: 1px solid #eef2f7; margin-top: .35rem; }
    .invoice-table td.invoice-actions-cell::before { display: none; }
    .invoice-actions { justify-content: flex-start; }
    .invoice-table tr.invoice-empty-row { padding: 1.25rem; }
    .invoice-table tr.invoice-empty-row td { display: block; text-align: center !important; }
    .invoice-table tr.invoice-empty-row td::before { display: none; }
}
@media (min-width: 576px) {
    .app-main { padding: 1.25rem; }
    .topbar-actions { width: auto; }
    .invoice-filters { grid-template-columns: minmax(210px, 1.5fr) minmax(150px, .8fr) repeat(2, minmax(145px, .7fr)); }
    .invoice-filter-buttons { grid-column: 1 / -1; }
    .invoice-primary-actions { grid-template-columns: repeat(3, auto); justify-content: start; }
    .bulk-actions { flex-direction: row; align-items: center; justify-content: space-between; }
}
@media (min-width: 768px) {
    .invoice-toolbar { grid-template-columns: minmax(0, 1fr); }
    .invoice-table-wrap { overflow-x: auto; }
    .invoice-table { min-width: 900px; }
}
@media (min-width: 992px) {
    .app-shell { display: flex; align-items: stretch; }
    .sidebar { position: fixed !important; inset: 0 auto 0 0; z-index: 1035; width: 250px !important; height: 100dvh; min-height: 0; overflow: hidden; visibility: visible !important; transform: none !important; }
    .sidebar-inner { height: 100%; }
    .app-main { width: calc(100% - 250px); margin-left: 250px; padding: 1.5rem; }
    .topbar { flex-wrap: nowrap; padding: .85rem 1.1rem; }
    .invoice-toolbar { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
    .invoice-primary-actions { justify-content: end; }
}
@media (min-width: 1400px) {
    .sidebar { width: 270px !important; }
    .app-main { width: calc(100% - 270px); margin-left: 270px; padding: 1.75rem 2rem; }
}
@media (display-mode: standalone) {
    body { padding-top: env(safe-area-inset-top); }
}

/* ============ Mode malam (dark mode) ============ */
[data-bs-theme="dark"] {
    --sb-bg: #0b1220;
    --sb-surface: #111a2b;
    --sb-border: #1f2a3c;
}
[data-bs-theme="dark"] body { background: var(--sb-bg); color: #e5e7eb; }
[data-bs-theme="dark"] .topbar { background: var(--sb-surface); box-shadow: 0 8px 24px rgba(0,0,0,.35); }
[data-bs-theme="dark"] .page-heading-text .small,
[data-bs-theme="dark"] .text-muted { color: #94a3b8 !important; }
[data-bs-theme="dark"] .card,
[data-bs-theme="dark"] .card-soft,
[data-bs-theme="dark"] .card-stat { background: var(--sb-surface); color: #e5e7eb; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
[data-bs-theme="dark"] .card .text-dark,
[data-bs-theme="dark"] .user-chip.text-dark { color: #e5e7eb !important; }
[data-bs-theme="dark"] .topbar .user-chip { background: #1e293b; color: #e5e7eb; }
[data-bs-theme="dark"] .bottom-nav { background: var(--sb-surface); border-top-color: var(--sb-border); box-shadow: 0 -6px 20px rgba(0,0,0,.4); }
[data-bs-theme="dark"] .bottom-nav-link { color: #94a3b8; }
[data-bs-theme="dark"] .bottom-nav-link.active { color: #4ade80; }
[data-bs-theme="dark"] .bottom-nav-link:active { background: #1e293b; }
[data-bs-theme="dark"] .table thead th { color: #94a3b8; border-bottom-color: var(--sb-border); }
[data-bs-theme="dark"] .alert-light { background: #1e293b; border-color: var(--sb-border); color: #e5e7eb; }
[data-bs-theme="dark"] .border,
[data-bs-theme="dark"] .border-top,
[data-bs-theme="dark"] .border-bottom { border-color: var(--sb-border) !important; }
[data-bs-theme="dark"] .bg-light { background-color: #16213a !important; color: #e5e7eb; }
[data-bs-theme="dark"] .badge.text-bg-light { background-color: #1e293b !important; color: #e5e7eb !important; border-color: var(--sb-border) !important; }
[data-bs-theme="dark"] .feature-icon { background: rgba(22,163,74,.18); }
[data-bs-theme="dark"] .renewal-plan-option { border-color: var(--sb-border); }
[data-bs-theme="dark"] .renewal-plan-option:has(input:checked) { border-color: #4ade80; }
@media (max-width: 767.98px) {
    [data-bs-theme="dark"] .invoice-table tr { background: var(--sb-surface); border-color: var(--sb-border); box-shadow: 0 4px 14px rgba(0,0,0,.35); }
    [data-bs-theme="dark"] .invoice-table td::before { color: #94a3b8; }
    [data-bs-theme="dark"] .invoice-table td.invoice-actions-cell { border-top-color: var(--sb-border); }
}
