:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --border: #e3e2de;
  --grid: #ecebe7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7974;
  --accent: #2a78d6;
  --income: #2a78d6;
  --expense: #eb6834;
  --user-1: #1baf7a;
  --user-2: #6250d6;
  --danger: #c0392b;
  --warn-bg: #fff4dc;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2e2e2c;
    --grid: #262624;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --accent: #3987e5;
    --income: #3987e5;
    --expense: #d95926;
    --user-1: #199e70;
    --user-2: #9085e9;
    --danger: #e66767;
    --warn-bg: #3a2f14;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --border: #2e2e2c; --grid: #262624;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e88;
  --accent: #3987e5; --income: #3987e5; --expense: #d95926; --danger: #e66767;
  --user-1: #199e70; --user-2: #9085e9; --warn-bg: #3a2f14;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1rem; margin: 0; font-weight: 600; }
.muted { color: var(--muted); font-size: .9rem; margin: 0; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
code { font-size: .85em; }
a { color: var(--accent); }

input, select, button { font: inherit; color: inherit; }
input, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); min-height: 44px;
}
input[type="file"] { padding: 8px; }
label { display: grid; gap: 4px; font-size: .9rem; color: var(--text-2); }

.btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 10px 16px; min-height: 44px; cursor: pointer; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }

/* Login */
.center-view { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.narrow { width: min(420px, 100%); }
.narrow-center { max-width: 520px; width: 100%; justify-self: center; }
.brand-block { display: flex; gap: 12px; align-items: center; }
.brand-block img { border-radius: 10px; }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
}
.brand { white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand img { border-radius: 6px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs button {
  background: none; border: 0; padding: 10px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); font-weight: 500;
}
.tabs button.active { background: var(--bg); color: var(--text); }
.who { font-size: .9rem; color: var(--text-2); white-space: nowrap; }
main { max-width: 1120px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
main > section { display: grid; gap: 16px; }

.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-2 .wide { grid-column: 1 / -1; }

.filters { display: grid; gap: 12px; }
.filter-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.segmented { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented > button, .segmented > label {
  flex: 1; text-align: center; border: 0; background: none; padding: 8px 6px; border-radius: 7px; cursor: pointer;
  color: var(--text-2); font-weight: 500; display: block;
}
.segmented > button.active { background: var(--accent); color: #fff; }
.type-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.type-toggle label:has(input:checked) { background: var(--bg); color: var(--text); box-shadow: inset 0 0 0 1px var(--border); }
.type-toggle label:has(input[value="income"]:checked) span::before,
.type-toggle label:has(input[value="expense"]:checked) span::before {
  content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 1px;
}
.type-toggle label:has(input[value="income"]:checked) span::before { background: var(--income); }
.type-toggle label:has(input[value="expense"]:checked) span::before { background: var(--expense); }

/* Tiles */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 4px; min-width: 0; }
.tile-label { font-size: .85rem; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.tile-value { font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.s-income { background: var(--income); }
.s-expense { background: var(--expense); }
.s-user1 { background: var(--user-1); }
.s-user2 { background: var(--user-2); }
.tile-row { display: flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--text-2); }
.tile-row b { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; font-weight: 650; }
.legend { display: flex; gap: 14px; font-size: .85rem; color: var(--text-2); }
.legend span { display: flex; align-items: center; gap: 6px; }

.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 320px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: 8px 6px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
.table th { color: var(--text-2); font-weight: 500; }
.table .num { text-align: right; }
.table tr.invalid td { color: var(--danger); }

/* Form */
.form { display: grid; gap: 14px; align-content: start; }
#receipt-form { display: grid; gap: 14px; }
#receipt-preview { max-width: 100%; max-height: 260px; object-fit: contain; border-radius: 8px; border: 1px solid var(--border); justify-self: center; }
pre { white-space: pre-wrap; font-size: .8rem; background: var(--bg); padding: 8px; border-radius: 8px; max-height: 200px; overflow: auto; }

/* Riwayat */
.tx-list { list-style: none; margin: 0; padding: 0; }
.tx-list li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 4px; border-bottom: 1px solid var(--grid); cursor: pointer;
}
.tx-list li:last-child { border-bottom: 0; }
.tx-list .t-main { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-list .t-meta { color: var(--muted); font-size: .82rem; }
.tx-list .t-amt { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.tx-list .t-amt.income::before { content: "+ "; }
.tx-list .t-amt.expense::before { content: "− "; }
.tx-list .empty { color: var(--muted); cursor: default; display: block; text-align: center; }

dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; width: min(460px, calc(100% - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
.row-btns { display: grid; grid-template-columns: auto 1fr auto auto; gap: 8px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; transition: .2s; pointer-events: none;
  max-width: calc(100% - 32px); z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Mobile: navigasi di bawah */
@media (max-width: 720px) {
  .topbar { justify-content: space-between; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom)); justify-content: space-around;
  }
  .tabs button { flex: 1; font-size: .85rem; padding: 10px 4px; }
  main { padding-bottom: 96px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-value { font-size: 1.1rem; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .chart-box { height: 240px; }
  #toast { bottom: 88px; }
}

/* Tambahan */
.hint { color: var(--muted); font-size: .82rem; margin: 0; }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: .82rem; font-weight: 500; }
.btn.block { width: 100%; margin-top: 12px; }
a.btn { text-decoration: none; color: inherit; display: inline-flex; align-items: center; justify-content: center; }
.segmented.small { padding: 2px; }
.segmented.small > button { padding: 5px 10px; font-size: .82rem; }
.row-btns.end { grid-template-columns: 1fr auto; align-items: center; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .78rem; border: 1px solid var(--border); }
.badge.ok::before, .badge.warn::before, .badge.bad::before { content: "● "; }
.badge.ok::before { color: #1baf7a; }
.badge.warn::before { color: #eda100; }
.badge.bad::before { color: var(--danger); }
.table td.actions { display: flex; gap: 6px; flex-wrap: wrap; white-space: normal; }
.table td.wrap { white-space: normal; min-width: 220px; }
.table.log td { vertical-align: top; }
.small-text { font-size: .78rem; }
.table tr.warn-row td { background: var(--warn-bg); }
.table.import td { vertical-align: middle; }
.table.import select { min-height: 34px; padding: 4px 6px; width: auto; }
.table.import input[type=checkbox] { width: 18px; height: 18px; min-height: 0; }
.table.import tr.uncertain td { background: var(--warn-bg); }
.note-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.flag { display: inline-block; margin-left: 6px; font-size: .72rem; color: #9a6700; font-weight: 600; }
.tx-list li.locked .t-main::before { content: "🔒 "; font-size: .8em; }
.tx-list .lock { color: var(--muted); }
.qr { display: flex; justify-content: center; padding: 12px; background: #fff; border-radius: 8px; width: fit-content; justify-self: center; }
code.secret { display: inline-block; padding: 6px 10px; background: var(--bg); border-radius: 6px; font-size: 1rem; letter-spacing: .04em; word-break: break-all; user-select: all; }
.steps { margin: 0; padding-left: 18px; }
.meter { display: block; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; margin: 4px 0; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
#admin-tabs { max-width: 520px; }
@media (max-width: 720px) {
  .tabs button { font-size: .78rem; padding: 10px 2px; }
  .brand { font-size: .95rem; }
}
.badge.info::before { content: "● "; color: var(--accent); }
.table tr.dim td { opacity: .55; }
.tx-list .badge { font-size: .72rem; padding: 0 6px; }
#account-form { align-items: end; }
#unmatched-box summary { cursor: pointer; font-weight: 600; color: #9a6700; }
