:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #1d4ed8;
    --primary-dark: #1e3a8a;
    --income: #2a78d6;
    --expense: #eb6834;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f172a;
        --surface: #1e293b;
        --surface-alt: #17233b;
        --border: #334155;
        --text: #e2e8f0;
        --text-muted: #94a3b8;
        --primary: #3b82f6;
        --primary-dark: #60a5fa;
    }
}
:root[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-alt: #17233b;
    --border: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-dark: #60a5fa;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px 0;
    display: flex;
    flex-direction: column;
}
.sidebar-brand { padding: 0 20px 16px; font-weight: 700; font-size: 16px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.sidebar-brand-logo { display: block; height: 36px; width: auto; margin-bottom: 8px; }
.sidebar-brand small { display: block; font-weight: 400; color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.nav-group { margin-bottom: 4px; }
.nav-title { padding: 10px 20px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.nav-link {
    display: block; padding: 8px 20px; color: var(--text); border-left: 3px solid transparent;
}
.nav-link:hover { background: var(--surface-alt); text-decoration: none; }
.nav-link.active { border-left-color: var(--primary); color: var(--primary); font-weight: 600; background: var(--surface-alt); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.content { padding: 24px; flex: 1; }

.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { margin: 0; font-size: 20px; }
.page-header .sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card h2, .card h3 { margin-top: 0; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1000px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-card .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.stat-card .value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat-card .value.income { color: var(--income); }
.stat-card .value.expense { color: var(--expense); }
.stat-card .value.negative { color: var(--danger); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
tr:hover td { background: var(--surface-alt); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.row-group td { background: var(--surface-alt); font-weight: 700; }
.row-total td { font-weight: 700; border-top: 2px solid var(--text); }

.btn {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
    font-size: 13px; font-weight: 600; text-decoration: none;
}
.btn:hover { background: var(--surface-alt); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-in { background: rgba(42,120,214,.12); color: var(--income); }
.badge-out { background: rgba(235,104,52,.12); color: var(--expense); }
.badge-adj { background: rgba(100,116,139,.15); color: var(--text-muted); }

form.stack { display: flex; flex-direction: column; gap: 14px; max-width: 560px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
.field .hint { color: var(--text-muted); font-size: 12px; margin-top: 3px; }
input, select, textarea {
    width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text); font-size: 14px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }
.radio-row { display: flex; gap: 16px; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-weight: 500; }
.radio-row input { width: auto; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.alert-success { background: rgba(22,163,74,.12); color: var(--success); border: 1px solid rgba(22,163,74,.3); }
.alert-error { background: rgba(220,38,38,.12); color: var(--danger); border: 1px solid rgba(220,38,38,.3); }

.tree-row { display: flex; align-items: center; gap: 6px; }
.tree-indent { display: inline-block; }
.tree-group { font-weight: 700; }
.tree-code { color: var(--text-muted); font-variant-numeric: tabular-nums; margin-right: 8px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { padding: 8px 16px; border-bottom: 2px solid transparent; color: var(--text-muted); font-weight: 600; }
.tab.active { color: var(--primary); border-color: var(--primary); }

.theme-toggle, .icon-btn { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; cursor: pointer; color: var(--text); }

.company-pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface-alt); border: 1px solid var(--border); }

.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.calendar .dow { font-size: 11px; text-transform: uppercase; color: var(--text-muted); text-align: center; padding: 4px; }
.calendar .day { min-height: 90px; border: 1px solid var(--border); border-radius: 8px; padding: 6px; background: var(--surface); font-size: 12px; }
.calendar .day.empty { background: transparent; border: none; }
.calendar .day .date-num { font-weight: 700; margin-bottom: 4px; }
.calendar .day .amt { font-size: 11px; padding: 2px 6px; border-radius: 6px; margin-top: 2px; display: block; }
.calendar .day .amt.aman { background: rgba(22,163,74,.12); color: var(--success); }
.calendar .day .amt.kurang { background: rgba(220,38,38,.12); color: var(--danger); }

.revision-item { border-left: 2px solid var(--border); padding: 6px 0 6px 12px; margin-bottom: 4px; }
.revision-item .meta { color: var(--text-muted); font-size: 12px; }

@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .main { display: block !important; }
    .content { padding: 0; }
    body { background: #fff; }
    .card { box-shadow: none; border: none; padding: 0; }
}

.print-letterhead { text-align: center; margin-bottom: 16px; }
.print-letterhead h1 { margin: 0; font-size: 18px; }
.print-letterhead .period { color: var(--text-muted); margin-top: 2px; }
