/* ===== Màu & biến (sáng / tối) ===== */
:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --surface-3: #eceef1;
  --border: #e3e5e9;
  --text: #191919;
  --text-2: #5f6368;
  --text-3: #8a8f96;
  --brand: #0f766e;
  --brand-2: #0d9488;
  --brand-soft: #e3f3f1;
  --in: #0b7a2a;
  --out: #c0362c;
  --warn-bg: #fff4d6;
  --warn-text: #8a5a00;
  --bad-bg: #fde8e6;
  --bad-text: #b3261e;
  --ok-bg: #e3f3f1;
  --ok-text: #0f766e;
  --series-1: #257de0;
  --series-2: #f47230;
  --grid: #eceef1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 16px;
  --nav-h: 62px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1011; --surface: #1a1b1d; --surface-2: #222326; --surface-3: #2a2c30; --border: #2d2f33;
    --text: #efefef; --text-2: #a8abb0; --text-3: #7d8187;
    --brand: #2bb3a3; --brand-2: #2bb3a3; --brand-soft: #15302d;
    --in: #4cc76a; --out: #f07167;
    --warn-bg: #3a2e12; --warn-text: #f3c65a; --bad-bg: #3b1c1a; --bad-text: #f2a19a; --ok-bg: #15302d; --ok-text: #5fd3c4;
    --series-1: #338ced; --series-2: #e76624; --grid: #26282c; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1011; --surface: #1a1b1d; --surface-2: #222326; --surface-3: #2a2c30; --border: #2d2f33;
  --text: #efefef; --text-2: #a8abb0; --text-3: #7d8187;
  --brand: #2bb3a3; --brand-2: #2bb3a3; --brand-soft: #15302d;
  --in: #4cc76a; --out: #f07167;
  --warn-bg: #3a2e12; --warn-text: #f3c65a; --bad-bg: #3b1c1a; --bad-text: #f2a19a; --ok-bg: #15302d; --ok-text: #5fd3c4;
  --series-1: #338ced; --series-2: #e76624; --grid: #26282c; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { touch-action: manipulation; }
a { color: var(--brand); text-decoration: none; }
a.card { color: inherit; display: block; }
.boot { padding: 40px; text-align: center; color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.in { color: var(--in); }
.out { color: var(--out); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 14px; }
.section-gap { height: 14px; }

/* Ẩn số tiền (chế độ riêng tư) */
body.privacy .val, body.privacy .big-owed, body.privacy .amt, body.privacy .priv { filter: blur(8px); transition: filter .2s; }

/* ===== Khung ===== */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 236px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; overflow-y: auto;
}
.side .logo { font-weight: 800; font-size: 18px; padding: 4px 12px 16px; display: flex; gap: 10px; align-items: center; }
.side .logo i { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; font-style: normal; }
.side .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 14px 12px 6px; font-weight: 700; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; color: var(--text-2); font-weight: 500; }
.nav a svg { width: 20px; height: 20px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.side .add-btn { margin: 4px 0 8px; }
.main { flex: 1; min-width: 0; padding: 22px 28px 48px; max-width: 1200px; }
.bottom-nav { display: none; }

@media (max-width: 860px) {
  .side { display: none; }
  .main { padding: calc(10px + env(safe-area-inset-top)) 12px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 10.5px; color: var(--text-3); padding: 0; border-radius: 0; font-weight: 600; }
  .bottom-nav a svg { width: 23px; height: 23px; }
  .bottom-nav a.active { color: var(--brand); background: none; }
  .bottom-nav .plus { display: grid; place-items: center; }
  .bottom-nav .plus button {
    width: 54px; height: 54px; border-radius: 18px; border: 0; background: var(--brand); color: #fff; font-size: 30px; line-height: 1;
    box-shadow: 0 6px 16px rgba(15, 118, 110, .35); cursor: pointer; transform: translateY(-10px);
  }
}

/* ===== Thành phần chung ===== */
.page-head { display: flex; align-items: center; gap: 10px; margin: 2px 0 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; margin: 0; flex: 1; min-width: 120px; line-height: 1.25; }
.page-head .sub { flex-basis: 100%; margin-top: -6px; }
.back { border: 0; background: var(--surface); border-radius: 12px; width: 40px; height: 40px; cursor: pointer; box-shadow: var(--shadow); font-size: 18px; flex: none; border: 1px solid var(--border); }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 12px; width: 40px; height: 40px; cursor: pointer; font-size: 17px; display: grid; place-items: center; flex: none; color: var(--text-2); }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); padding: 16px; }
.card + .card, .grid + .card, .card + .grid { margin-top: 14px; }
.grid > .card + .card { margin-top: 0; }
.card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h2 .sp { flex: 1; }
.card.flat { box-shadow: none; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) { .g3.stack, .g2.stack { grid-template-columns: minmax(0, 1fr); } .g3:not(.stack) { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; } }
@media (max-width: 860px) { .g3:not(.stack) .stat { padding: 11px 10px; } .g3:not(.stack) .stat .val { font-size: 15px; } .g3:not(.stack) .stat .lbl { font-size: 12px; } }
@media (max-width: 420px) { .g4 { gap: 8px; } }

.stat { padding: 14px 16px; min-width: 0; }
.stat .lbl { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.stat .val { font-size: 21px; font-weight: 750; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; }
.stat .sub { font-size: 12px; color: var(--text-3); margin-top: 4px; line-height: 1.35; }
@media (max-width: 420px) { .stat { padding: 12px; } .stat .val { font-size: 17px; } }
.hero { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border: 0; }
.hero .lbl, .hero .sub { color: rgba(255,255,255,.85); }
.hero .val { color: #fff !important; }
.delta { font-size: 12px; font-weight: 600; }
.delta.up { color: var(--out); }
.delta.down { color: var(--in); }
.delta.up.good { color: var(--in); }
.delta.down.good { color: var(--out); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface); padding: 9px 14px; border-radius: 11px; cursor: pointer; font-weight: 600; font-size: 14px; white-space: nowrap; min-height: 40px; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--out); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; min-height: 32px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.scroll-x { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
.scroll-x::-webkit-scrollbar { display: none; }
.scroll-x > * { flex: none; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 3px; gap: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text-2); white-space: nowrap; flex: none; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg.full { display: flex; }
.seg.full button { flex: 1; }

.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-size: 13px; cursor: pointer; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.chip.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

.monthpick { display: inline-flex; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.monthpick button { border: 0; background: none; width: 34px; height: 32px; cursor: pointer; border-radius: 9px; font-size: 17px; color: var(--text-2); }
.monthpick button:hover { background: var(--surface-2); }
.monthpick span { min-width: 96px; text-align: center; font-weight: 650; font-size: 14px; cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; min-width: 0; }
.field > label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 11px; padding: 10px 12px; outline: none; min-height: 44px; font-size: 16px;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.input { resize: vertical; min-height: 60px; }
.amount-input { font-size: 28px; font-weight: 750; padding: 10px 14px; letter-spacing: .3px; }
.hint { font-size: 12px; color: var(--text-3); }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px; cursor: pointer; margin-bottom: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); margin: 0; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar select.input, .toolbar .input { width: auto; min-height: 38px; padding: 7px 10px; font-size: 14px; }
.toolbar .search { flex: 1; min-width: 150px; }
@media (max-width: 600px) { .toolbar select.input { flex: 1; min-width: 0; } .toolbar .search { flex-basis: 100%; } }

/* Phím hỗ trợ nhập số */
.keys { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 2px; }
.keys button { border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 9px 0; font-weight: 700; font-size: 14px; cursor: pointer; color: var(--text); }
.keys button:active { background: var(--surface-3); }

/* ===== Danh sách ===== */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border); cursor: pointer; min-height: 60px; }
.item:last-child { border-bottom: 0; }
@media (hover: hover) { .item:hover { background: var(--surface-2); border-radius: 10px; } }
.item:active { background: var(--surface-2); }
.ico { width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-size: 19px; flex: none; }
.ico.t-advance, .ico.t-reimburse { background: #e6effd; }
.ico.t-loan { background: #f1eafd; }
.ico.t-transfer, .ico.t-adjust { background: var(--surface-3); }
:root[data-theme="dark"] .ico.t-advance, :root[data-theme="dark"] .ico.t-reimburse { background: #1d2a3d; }
:root[data-theme="dark"] .ico.t-loan { background: #2a2140; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ico.t-advance, :root:not([data-theme="light"]) .ico.t-reimburse { background: #1d2a3d; }
  :root:not([data-theme="light"]) .ico.t-loan { background: #2a2140; }
}
.item .body { flex: 1; min-width: 0; }
.item .t1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .t2 { font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.item .amt { font-weight: 700; text-align: right; flex: none; }
.item .amt .t2 { font-weight: 400; }
.item .chev { color: var(--text-3); flex: none; }
.day-head { display: flex; justify-content: space-between; padding: 14px 4px 6px; font-size: 13px; color: var(--text-2); font-weight: 650; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.day-head:first-child { padding-top: 2px; }
.empty { text-align: center; padding: 30px 10px; color: var(--text-3); }
.empty b { display: block; font-size: 32px; margin-bottom: 6px; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.badge.ok { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad-text); border-color: transparent; }

.party-card { cursor: pointer; transition: transform .08s; }
@media (hover: hover) { .party-card:hover { transform: translateY(-1px); } }
.party-card .name { font-weight: 700; font-size: 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kv { display: flex; justify-content: space-between; font-size: 13.5px; padding: 5px 0; gap: 10px; }
.kv > span:first-child { color: var(--text-2); }
.kv > :last-child { text-align: right; }
.big-owed { font-size: 23px; font-weight: 800; margin: 6px 0; }
.progress { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.progress i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.progress.warn i { background: #e0a100; }
.progress.over i { background: var(--out); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tbl th { text-align: left; font-size: 12px; color: var(--text-2); font-weight: 650; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tbl td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tbl tr.click { cursor: pointer; }
table.tbl tr.click:hover td { background: var(--surface-2); }
table.tbl .r { text-align: right; }
table.tbl tfoot td { font-weight: 750; border-bottom: 0; }
.tbl-wrap { overflow-x: auto; margin: 0 -4px; }

/* ===== Modal (bottom sheet trên điện thoại) ===== */
dialog.modal {
  border: 0; padding: 0; border-radius: 20px; background: var(--surface); color: var(--text);
  width: min(540px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog.modal[open] { display: flex; flex-direction: column; }
dialog.modal form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
dialog.modal::backdrop { background: rgba(10, 12, 16, .5); }
.modal-head { display: flex; align-items: center; padding: 16px 18px 8px; gap: 8px; }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-head .x { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 19px; color: var(--text-2); }
.modal-body { padding: 8px 18px 4px; overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
.modal-foot { display: flex; gap: 8px; padding: 12px 18px 18px; flex-wrap: wrap; border-top: 1px solid var(--border); }
.modal-foot .sp { flex: 1; }
@media (max-width: 600px) {
  dialog.modal { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 20px 20px 0 0; max-height: 94dvh; }
  dialog.modal[open] { animation: sheet .22s ease-out; }
  .modal-foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .modal-foot .btn { flex: 1; }
  .modal-foot .sp { display: none; }
}
@keyframes sheet { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }

.kind-tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin-bottom: 14px; }
.kind-tabs button { border: 1px solid var(--border); background: var(--surface); border-radius: 11px; padding: 8px 2px; cursor: pointer; font-size: 12.5px; font-weight: 650; color: var(--text-2); display: flex; flex-direction: column; align-items: center; gap: 2px; }
.kind-tabs button span { font-size: 18px; }
.kind-tabs button.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 6px; }
.cat-grid button { border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 8px 4px; cursor: pointer; font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 3px; line-height: 1.2; color: var(--text); min-height: 64px; }
.cat-grid button span { font-size: 21px; }
.cat-grid button.on { border-color: var(--brand); background: var(--brand-soft); }
.subcats { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; padding: 10px; background: var(--surface-2); border-radius: 12px; }
.subcats .lbl { width: 100%; font-size: 12px; color: var(--text-3); font-weight: 600; }

.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { position: relative; width: 72px; height: 72px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); display: grid; place-items: center; font-size: 11px; color: var(--text-2); text-align: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 13px; cursor: pointer; line-height: 1; }
.thumb.add { cursor: pointer; border-style: dashed; font-size: 26px; color: var(--text-3); }
.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 200; display: grid; place-items: center; }
.viewer img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.viewer button { position: fixed; top: calc(12px + env(safe-area-inset-top)); right: 12px; width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff; font-size: 22px; cursor: pointer; }

/* ===== Toast ===== */
#toast { position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translateX(-50%) translateY(-160%); background: #1f2328; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; z-index: 300; transition: transform .25s; max-width: 92vw; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { background: #b3261e; }

/* ===== Đăng nhập ===== */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(380px, 100%); padding: 28px 24px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login .logo { width: 52px; height: 52px; border-radius: 14px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 28px; font-weight: 700; margin-bottom: 14px; }
.err-text { color: var(--out); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ===== Lối tắt / menu ===== */
.quick { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.quick button { border: 1px solid var(--border); background: var(--surface); border-radius: 14px; padding: 10px 2px 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; font-weight: 650; color: var(--text-2); box-shadow: var(--shadow); }
.quick button span { font-size: 22px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer; box-shadow: var(--shadow); color: var(--text); display: flex; flex-direction: column; gap: 4px; min-height: 100px; }
.tile .ti { font-size: 26px; }
.tile b { font-size: 15px; }
.tile small { color: var(--text-3); font-size: 12px; line-height: 1.35; }
@media (max-width: 420px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.alert { background: var(--warn-bg); color: var(--warn-text); border-radius: 13px; padding: 10px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; cursor: pointer; }
.alert.bad { background: var(--bad-bg); color: var(--bad-text); }
.alert.info { background: var(--brand-soft); color: var(--brand); }
.alert .sp { flex: 1; }
.alert + .alert { margin-top: 8px; }

/* ===== Biểu đồ ===== */
.viz { position: relative; }
.viz svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz .axis { fill: var(--text-3); font-size: 13px; }
.viz .gridline { stroke: var(--grid); stroke-width: 1; }
.viz .baseline { stroke: var(--border); stroke-width: 1; }
.viz .hit { fill: transparent; }
.viz .hit:hover, .viz .hit.on { fill: var(--text); fill-opacity: .05; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0,0,0,.14); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; white-space: nowrap; z-index: 5; display: none; color: var(--text); }
.tip b { display: block; margin-bottom: 4px; }
.tip .r { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.tip .r i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 5px; }
.catbars .row { display: grid; grid-template-columns: minmax(110px, 1.2fr) 2fr auto; gap: 10px; align-items: center; padding: 7px 0; font-size: 13.5px; cursor: pointer; }
.catbars .bar { height: 10px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.catbars .bar i { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.catbars .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catbars .v { text-align: right; font-variant-numeric: tabular-nums; }
.catbars .v small { color: var(--text-3); margin-left: 4px; }
@media (max-width: 520px) { .catbars .row { grid-template-columns: minmax(0, 1fr) auto; row-gap: 5px; } .catbars .bar { grid-column: 1 / -1; grid-row: 2; } }

/* Cây danh mục trong báo cáo */
.tree .prow { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 10px 2px; border-bottom: 1px solid var(--border); cursor: pointer; }
.tree .prow .tog { color: var(--text-3); font-size: 12px; transition: transform .15s; text-align: center; }
.tree .prow.open .tog { transform: rotate(90deg); }
.tree .prow .nm { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree .prow .meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.tree .prow .v { text-align: right; font-weight: 700; }
.tree .kids { padding: 2px 0 6px 30px; border-bottom: 1px solid var(--border); }
.tree .crow { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; padding: 6px 0; cursor: pointer; }
.tree .crow span:first-child { color: var(--text-2); }
.tree .minibar { height: 4px; background: var(--surface-3); border-radius: 9px; margin-top: 6px; overflow: hidden; }
.tree .minibar i { display: block; height: 100%; background: var(--series-1); }

/* Ngân sách */
.bud { padding: 11px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.bud:last-child { border-bottom: 0; }
.bud .top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.bud .top b { font-weight: 650; }
.bud .bot { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-3); gap: 10px; }

/* Danh mục quản lý */
.catmgr .parent { display: flex; align-items: center; gap: 10px; padding: 10px 2px; border-bottom: 1px solid var(--border); }
.catmgr .parent .body { flex: 1; min-width: 0; cursor: pointer; }
.catmgr .kids { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 0 12px 50px; border-bottom: 1px solid var(--border); }

/* ===== In bảng kê ===== */
.print-only { display: none; }
.statement h1 { font-size: 20px; text-align: center; margin: 0 0 4px; text-transform: uppercase; }
.statement .meta { text-align: center; color: var(--text-2); font-size: 13px; margin-bottom: 16px; }
.sign { display: grid; grid-template-columns: 1fr 1fr; text-align: center; margin-top: 30px; font-size: 14px; }
.sign div { min-height: 110px; }
@media print {
  :root { color-scheme: light; --bg: #fff; --surface: #fff; --text: #000; --text-2: #333; --text-3: #555; --border: #999; --shadow: none; }
  .side, .bottom-nav, .no-print, #toast { display: none !important; }
  .print-only { display: block; }
  .main { padding: 0; max-width: none; }
  .card { border: 0; padding: 0; box-shadow: none; }
  table.tbl td, table.tbl th { border: 1px solid #999; padding: 6px; }
  body.privacy .val, body.privacy .amt { filter: none; }
}

/* 3 ô thống kê trên điện thoại hẹp: chữ nhỏ hơn và cho xuống dòng thay vì cắt "…" */
@media (max-width: 420px) {
  .g3:not(.stack) { gap: 8px; }
  .g3:not(.stack) .stat { padding: 10px 9px; }
  .g3:not(.stack) .stat .val { font-size: 14px; letter-spacing: -.2px; white-space: normal; overflow-wrap: anywhere; text-overflow: clip; }
  .g3:not(.stack) .stat .lbl { font-size: 11.5px; }
}
