/* Font Inter tự host: chỉ bộ Latin cơ bản + tiếng Việt (~58 KB). Không khai báo bộ Latin mở rộng (85 KB) —
   các chữ Ă Đ Ơ Ư… đã nằm trong bộ tiếng Việt. */
@font-face {
  font-family: "Inter Variable"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url(/vendor/inter/files/inter-latin-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter Variable"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url(/vendor/inter/files/inter-vietnamese-wght-normal.woff2) format("woff2-variations");
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
/* =====================================================================
   Sổ Chi Tiêu — hệ thống giao diện
   Tối giản, trung tính: màu chỉ dùng cho dữ liệu (thu/chi/đầu tư, trạng thái),
   còn khung, bảng, nút đều xám trung tính. Chữ Inter, số thẳng cột (tabular).
   ===================================================================== */

/* ===== Tokens ===== */
:root {
  color-scheme: light;
  --page: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;      /* dải tiêu đề bảng, dòng tổng, hover */
  --surface-3: #eceef2;      /* nền thanh tiến độ, nhóm nút */
  --raised: #ffffff;         /* nút đang chọn trong nhóm nút */
  --field: #f2f4f7;          /* ô nhập sửa trực tiếp trong bảng */
  --ink: #101828;
  --ink-2: #475467;
  --muted: #667085;
  --line: #eaecf0;
  --line-strong: #d0d5dd;
  --accent: #1f4e5f;
  --accent-ink: #ffffff;
  --accent-soft: #e7eff2;

  --s-income: #2a78d6;
  --s-expense: #eb6834;
  --s-invest: #1baf7a;
  --s-budget: #c5cad3;

  --good: #12a150;
  --good-text: #067647;
  --warning: #f5a524;
  --warning-text: #93370d;
  --serious: #ec835a;
  --serious-text: #9a4420;
  --critical: #d92d20;
  --critical-text: #b42318;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
  --font: "Inter Variable", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --pad: 20px;               /* lề trong của thẻ — bảng tràn sát mép thẻ dùng giá trị này */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0c0e12; --surface: #14171d; --surface-2: #191d24; --surface-3: #232831; --raised: #2c323d; --field: #1d222a;
    --ink: #e8eaed; --ink-2: #b3b9c3; --muted: #8a919c; --line: #242932; --line-strong: #343a46;
    --accent: #7fb7c9; --accent-ink: #0b1a1f; --accent-soft: #1a2a30;
    --s-income: #3987e5; --s-expense: #e0652f; --s-invest: #1fae7b; --s-budget: #3a414c;
    --good-text: #3ccb7f; --warning-text: #f5b84a; --serious-text: #f0956f; --critical-text: #f2716a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0c0e12; --surface: #14171d; --surface-2: #191d24; --surface-3: #232831; --raised: #2c323d; --field: #1d222a;
  --ink: #e8eaed; --ink-2: #b3b9c3; --muted: #8a919c; --line: #242932; --line-strong: #343a46;
  --accent: #7fb7c9; --accent-ink: #0b1a1f; --accent-soft: #1a2a30;
  --s-income: #3987e5; --s-expense: #e0652f; --s-invest: #1fae7b; --s-budget: #3a414c;
  --good-text: #3ccb7f; --warning-text: #f5b84a; --serious-text: #f0956f; --critical-text: #f2716a;
  --shadow: none;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font); background: var(--page); color: var(--ink);
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  font-feature-settings: "cv11";
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.015em; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
h3 { font-size: 13.5px; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.pos { color: var(--good-text); }
.neg { color: var(--critical-text); }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
a, button, input, select, label, .tx, .person { touch-action: manipulation; }
body.modal-open { overflow: hidden; }

/* ===== Khung ứng dụng: trải hết bề ngang màn hình ===== */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 18px 12px; border-right: 1px solid var(--line);
  background: var(--surface); display: flex; flex-direction: column; gap: 2px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; font-weight: 650; font-size: 15.5px; letter-spacing: -0.01em; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.brand-mark svg { width: 17px; height: 17px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--ink-2); text-decoration: none; font-weight: 500; font-size: 13.5px; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav svg { width: 17px; height: 17px; flex: none; }
.sidebar .spacer { flex: 1; }
.sidebar > .btn.primary { margin: 0 4px 12px; }
.side-user { padding: 12px 10px 4px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.main { min-width: 0; width: 100%; padding: 24px 32px 96px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.grid.half { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.two, .grid.month, .grid.half { align-items: start; }
/* Trang Tháng: bảng bên trái giãn theo màn hình, cột phải (tổng kết + nhật ký) rộng theo tỉ lệ */
.grid.month { grid-template-columns: minmax(0, 1fr) clamp(340px, 28vw, 540px); }
.section { margin-top: 16px; }

/* ===== Thẻ ===== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px var(--pad); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; min-height: 28px; }
.card-head h2 { display: flex; align-items: center; gap: 2px; }
.card-head .hint { font-size: 12px; color: var(--muted); }

/* ===== KPI ===== */
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi .label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.kpi .value { font-size: 26px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi .meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 2px 12px; flex-wrap: wrap; }
.kpi .bar { margin: 4px 0 2px; }

/* ===== Thanh tiến độ ===== */
.bar { position: relative; height: 6px; background: var(--surface-3); border-radius: 3px; overflow: visible; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 3px; background: var(--s-expense); max-width: 100%; }
.bar > i.over { background: var(--critical); }
.bar > i.inv { background: var(--s-invest); }
.bar > i.inc { background: var(--s-income); }
.bar .pace { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink-2); border-radius: 1px; opacity: .5; }

/* ===== Trạng thái: chấm màu + chữ (không dùng màu đơn thuần) ===== */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; white-space: nowrap; color: var(--ink-2); }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.chip.good { color: var(--good-text); }
.chip.warning { color: var(--warning-text); }
.chip.serious { color: var(--serious-text); }
.chip.critical { color: var(--critical-text); }
.chip.none { color: var(--muted); }
.chip.none::before { display: none; }

/* ===== Bảng =====
   Dải tiêu đề chữ hoa nhỏ chạy sát hai mép thẻ, dòng phân cách mảnh, số căn phải thẳng cột. */
.table-wrap { overflow-x: auto; margin: 0 calc(-1 * var(--pad)); }
table.t { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; font-variant-numeric: tabular-nums; }
table.t th {
  text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  padding: 9px 12px; background: var(--surface-2); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  white-space: nowrap; position: sticky; top: 0; z-index: 2;
}
table.t th.num { text-align: right; }
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; background: var(--surface); }
table.t th:first-child, table.t td:first-child { padding-left: var(--pad); }
table.t th:last-child, table.t td:last-child { padding-right: var(--pad); }
table.t td.name { white-space: nowrap; font-weight: 500; }
table.t td.name a { color: inherit; text-decoration: none; }
table.t tr.total td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--line-strong); border-bottom: 0; }
table.t tr.sub td { color: var(--ink-2); }
table.t td.over { color: var(--critical-text); font-weight: 600; }
table.t td.zero { color: var(--muted); }
table.t td .bar { min-width: 64px; }
table.t.compact td { padding: 8px 10px; }
table.t.compact th { padding: 8px 10px; }
table.t.compact th:first-child, table.t.compact td:first-child { padding-left: var(--pad); }
table.t.compact th:last-child, table.t.compact td:last-child { padding-right: var(--pad); }
table.t .sticky-col { position: sticky; left: 0; z-index: 1; box-shadow: 1px 0 0 var(--line); }
table.t th.sticky-col { z-index: 3; }
@media (hover: hover) {
  table.t tbody tr:not(.total):hover td { background: var(--surface-2); }
}
/* Ô sửa trực tiếp: nền xám nhạt, viền khi rê chuột, viền màu nhấn khi đang gõ */
table.t input.cell {
  display: block; width: 100%; min-width: 96px; max-width: 160px; margin: -4px 0 -4px auto;
  text-align: right; font-variant-numeric: tabular-nums; color: var(--ink);
  border: 1px solid transparent; background: var(--field); border-radius: var(--radius-sm); padding: 4px 8px;
}
table.t input.cell::placeholder { color: var(--muted); }
table.t input.cell:hover { border-color: var(--line-strong); }
table.t input.cell:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

/* Bảng hạn mức 12 tháng */
.budget-grid td, .budget-grid th { padding: 5px 4px !important; }
.budget-grid td.sticky-col, .budget-grid th.sticky-col { padding-left: var(--pad) !important; padding-right: 12px !important; }
.budget-grid td:last-child, .budget-grid th:last-child { padding-right: var(--pad) !important; }
table.t.budget-grid input.cell { min-width: 98px; max-width: none; font-size: 13px; margin: 0; padding: 4px 6px; }

/* ===== Nút & ô nhập ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 7px 14px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); border-radius: var(--radius-sm);
  cursor: pointer; font-weight: 500; font-size: 13.5px; white-space: nowrap; text-decoration: none; box-shadow: var(--shadow);
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--critical-text); border-color: color-mix(in srgb, var(--critical) 35%, var(--line-strong)); }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.sm { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn.icon { padding: 0; width: 36px; min-height: 36px; }
.btn.sm.icon { width: 30px; min-height: 30px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:focus-visible, .pick:focus-visible, .seg button:focus-visible, .nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (hover: hover) {
  .nav a:hover { background: var(--surface-2); color: var(--ink); }
  .nav a.active:hover { background: var(--accent-soft); color: var(--accent); }
  .btn:hover { background: var(--surface-2); }
  .btn.primary:hover { background: var(--accent); filter: brightness(1.1); }
  .btn.ghost:hover { background: var(--surface-2); }
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .label-s { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field > .seg:not(.full) { align-self: flex-start; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius-sm); padding: 8px 11px; min-height: 38px;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
textarea.input { resize: vertical; min-height: 64px; }
.input.big { font-size: 26px; font-weight: 600; padding: 10px 12px; letter-spacing: -0.015em; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.seg { display: inline-flex; background: var(--surface-3); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-weight: 500; color: var(--ink-2); font-size: 13px; }
.seg button.on { background: var(--raised); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(16, 24, 40, .1); }
.seg.full { display: flex; }
.seg.full button { flex: 1; padding: 8px; }
.seg button[data-kind="expense"].on { color: var(--s-expense); }
.seg button[data-kind="income"].on { color: var(--s-income); }
.seg button[data-kind="invest"].on { color: var(--s-invest); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pick { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 99px; padding: 5px 12px; cursor: pointer; font-size: 13px; }
.pick.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.pick.add { border-style: dashed; color: var(--ink-2); }
@media (hover: hover) { .pick:not(.on):hover { background: var(--surface-2); } }

.period { display: inline-flex; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow); }
.period .btn { border: 0; padding: 0 8px; min-height: 34px; box-shadow: none; background: transparent; }
.period select { border: 0; background: transparent; font-weight: 600; padding: 6px 4px; cursor: pointer; }

/* ===== Nhật ký giao dịch ===== */
.tx-day { margin-top: 10px; }
.tx-day-head { display: flex; justify-content: space-between; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tx { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.tx .k { width: 8px; height: 8px; border-radius: 50%; }
.tx .d { min-width: 0; }
.tx .d .t1 { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .d .t2 { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .a { font-weight: 600; font-variant-numeric: tabular-nums; }
.tx .a.income { color: var(--good-text); }
.k-income { background: var(--s-income); } .k-expense { background: var(--s-expense); } .k-invest { background: var(--s-invest); } .k-none { background: var(--muted); }
.split-tag { color: var(--accent); font-weight: 600; }
/* Máy tính: nhật ký cuộn trong khung, cao theo màn hình */
.journal-scroll { max-height: max(420px, calc(100vh - 380px)); overflow-y: auto; margin: 0 -8px; padding: 0 8px; }
@media (hover: hover) { .tx:hover { background: var(--surface-2); } }

/* ===== Thông báo ===== */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 14px; border: 1px solid var(--line); background: var(--surface); }
.alert.warn { border-color: color-mix(in srgb, var(--warning) 45%, var(--line)); background: color-mix(in srgb, var(--warning) 7%, var(--surface)); }
.alert.bad { border-color: color-mix(in srgb, var(--critical) 35%, var(--line)); background: color-mix(in srgb, var(--critical) 6%, var(--surface)); }
.alert.ok { border-color: color-mix(in srgb, var(--good) 35%, var(--line)); background: color-mix(in srgb, var(--good) 6%, var(--surface)); }
.alert.info { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.alert .ic { font-weight: 700; flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; color: #fff; background: var(--muted); }
.alert.warn .ic { background: var(--warning); color: #101828; } .alert.bad .ic { background: var(--critical); } .alert.ok .ic { background: var(--good); }
.alert.info .ic { background: var(--accent); color: var(--accent-ink); }

/* ===== Biểu đồ ===== */
.chart-box { position: relative; height: 300px; }
.chart-box.tall { height: 360px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ===== Hộp thoại ===== */
.modal-bg { position: fixed; inset: 0; background: rgba(9, 12, 18, .45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .12s ease-out; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; width: min(520px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 24px 64px rgba(0, 0, 0, .22); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 8px; }
.modal-body { padding: 8px 20px 16px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
@keyframes fade { from { opacity: 0; } }
.amount-hint { font-size: 12.5px; color: var(--muted); min-height: 18px; }

/* ===== Toast ===== */
.toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: var(--page); padding: 9px 16px; border-radius: 8px; font-size: 13.5px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); animation: fade .15s; }
.toast.err { background: var(--critical); color: #fff; }

/* ===== Đăng nhập ===== */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth { width: min(400px, 100%); }
.auth .brand { justify-content: center; padding-bottom: 8px; font-size: 19px; }
.auth .tag { text-align: center; color: var(--muted); margin-bottom: 20px; font-size: 13.5px; }
.err-text { color: var(--critical-text); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* ===== Thành phần nhỏ ===== */
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13.5px; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--surface-3); color: var(--ink-2); }
.pill.admin { background: var(--accent-soft); color: var(--accent); }
.pill.off { background: color-mix(in srgb, var(--critical) 12%, transparent); color: var(--critical-text); }
.dropzone { display: block; border: 1.5px dashed var(--line-strong); border-radius: var(--radius); padding: 26px; text-align: center; cursor: pointer; color: var(--ink-2); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.delta-pct { font-size: 11.5px; font-weight: 500; opacity: .85; }
.bottom-nav { display: none; }
.only-mob, .seg.mob-tabs { display: none; }

/* Quản lý nhóm */
.cat-grid { grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); }
.cat-row { display: flex; align-items: center; gap: 2px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.cat-row .nm { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.cat-row .btn.sm { padding: 4px 7px; }

/* Chia tiền (form giao dịch) */
.split-box { margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface-2); }
.split-box .label-s { display: block; margin-bottom: 6px; }
.share-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.share-in { width: 140px; text-align: right; padding: 6px 9px; font-variant-numeric: tabular-nums; }
.split-sum { margin-top: 10px; font-size: 13px; line-height: 1.6; }

/* Sổ nợ & danh bạ */
.debt-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two.debt-grid { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
.debt-types { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.debt-types .pick { border-radius: var(--radius-sm); padding: 9px 10px; text-align: center; }
.person { display: grid; grid-template-columns: 34px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 8px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 8px; }
.person.on { background: var(--accent-soft); }
.person .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-weight: 600; color: var(--ink-2); font-size: 13px; }
.person.on .avatar { background: var(--accent); color: var(--accent-ink); }
.person .t1 { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .t2 { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .a { text-align: right; font-size: 12px; line-height: 1.3; }
.person .a b { font-size: 14.5px; font-variant-numeric: tabular-nums; }
@media (hover: hover) { .person:not(.on):hover { background: var(--surface-2); } }
.letter { position: sticky; top: 0; z-index: 1; background: var(--surface); font-size: 11px; font-weight: 700; letter-spacing: .05em; color: var(--muted); padding: 10px 8px 4px; border-bottom: 1px solid var(--line); }
.contact-info { display: flex; flex-direction: column; gap: 2px; margin: -6px 0 10px; font-size: 13.5px; }
.contact-info a { font-weight: 600; text-decoration: none; }
.debt-balance { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 14px; }
.debt-hist tr { cursor: pointer; }
.debt-scroll { max-height: min(560px, 65vh); overflow: auto; -webkit-overflow-scrolling: touch; }
.debt-scroll thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.howto p { margin: 0 0 10px; color: var(--ink-2); font-size: 13.5px; }

/* So sánh */
.cmp-bar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.cmp-row { display: flex; gap: 6px; align-items: center; }
.cmp-row select.input { width: auto; padding: 6px 9px; }
.cmp-lab { color: var(--muted); font-size: 13px; }

/* Trang Tháng trên điện thoại: danh sách dọc thay bảng */
.lim-hint { font-size: 12.5px; margin: 0 0 4px; }
.lim-row { padding: 11px 0; border-bottom: 1px solid var(--line); }
.lim-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.lim-name { color: var(--ink); text-decoration: none; font-weight: 600; min-width: 0; }
.lim-amt { display: flex; align-items: center; gap: 6px; flex: none; font-variant-numeric: tabular-nums; }
.lim-amt b { font-size: 15px; font-weight: 600; }
.lim-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 7px; font-size: 12.5px; color: var(--muted); }
.lim-total { display: flex; justify-content: space-between; padding: 12px 0 0; font-weight: 600; }
.lim-list:not(.show-empty) .lim-empty { display: none; }
.lim-more { margin-top: 6px; color: var(--accent); }
.lim-amt input.cell, .bm-row input.cell { text-align: right; border: 1px solid var(--line); background: var(--field); border-radius: var(--radius-sm); font-variant-numeric: tabular-nums; }
.lim-amt input.cell { width: 118px; padding: 6px 9px; }
.lim-amt input.cell:focus, .bm-row input.cell:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

/* Hạn mức trên điện thoại: chọn tháng + danh sách */
.month-chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; margin-bottom: 4px; scrollbar-width: none; }
.month-chips::-webkit-scrollbar { display: none; }
.month-chips .pick { flex: none; }
.bm-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.bm-row .nm { flex: 1; min-width: 0; }
.bm-row input.cell { width: 132px; padding: 7px 9px; }

/* Quản trị trên điện thoại */
.user-row { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-row .d { min-width: 0; }
.user-row .acts { display: flex; gap: 4px; flex: none; }

/* ===== Màn hình lớn: tận dụng bề ngang ===== */
@media (min-width: 1600px) {
  .main { padding: 28px 40px 96px; }
  .grid { gap: 20px; }
  .section { margin-top: 20px; }
  .kpi .value { font-size: 30px; }
  .chart-box { height: 340px; }
  .card { --pad: 24px; padding-top: 20px; padding-bottom: 20px; }
}

/* ===== Máy tính bảng ===== */
@media (max-width: 1280px) {
  .grid.month { grid-template-columns: minmax(0, 1fr); }
  /* Nhật ký dài theo trang. Phải bỏ hẳn overflow + overscroll-behavior — nếu không, khung này vẫn là
     "vùng cuộn" (dù không có gì để cuộn) và nuốt mất cú vuốt, trang không cuộn được trên điện thoại. */
  .journal-scroll { max-height: none; overflow: visible; overscroll-behavior: auto; }
}
@media (max-width: 1100px) {
  .grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two, .grid.two.debt-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ===== Điện thoại ===== */
@media (max-width: 820px) {
  :root { --pad: 14px; }
  body { font-size: 14.5px; }
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: calc(14px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 110px max(16px, env(safe-area-inset-left)); }
  .page-head { margin-bottom: 14px; }
  .page-head h1 { font-size: 19px; }
  .grid.half { grid-template-columns: 1fr; }
  .card { padding: 14px var(--pad); }
  .kpi .value { font-size: 21px; }
  .chart-box { height: 240px; }
  .hide-sm, .card-head .hint { display: none; }
  .only-desk { display: none !important; }
  .only-mob { display: block; }
  /* iOS Safari tự phóng to khi chạm vào ô có chữ nhỏ hơn 16px */
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px; }
  input.input.big { font-size: 26px; }
  .tx { padding: 11px 4px; }
  .menu-nav a { padding: 13px 12px; font-size: 16px; }
  table.t td.name { white-space: normal; min-width: 96px; }
  .budget-grid td.name { white-space: nowrap; }
  table.t td .bar { min-width: 40px; }
  .toasts { bottom: calc(86px + env(safe-area-inset-bottom)); }

  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); z-index: 39; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--ink-2); text-decoration: none; background: none; border: 0; padding: 4px 0; cursor: pointer; }
  .bottom-nav a.active { color: var(--accent); font-weight: 600; }
  .bottom-nav svg { width: 22px; height: 22px; }
  .bottom-nav .add { margin-top: -22px; }
  .bottom-nav .add span.circle { width: 52px; height: 52px; border-radius: 16px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: 0 6px 18px rgba(31, 78, 95, .35); }

  .modal-bg { align-items: end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; width: 100%; max-height: 92dvh; border-bottom: 0; }
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }

  .seg.mob-tabs { display: flex; position: sticky; top: env(safe-area-inset-top); z-index: 5; margin-bottom: 12px; box-shadow: 0 6px 12px -8px rgba(0, 0, 0, .25); }
  .seg.mob-tabs button { padding: 9px 2px; }
  [data-mtabs] [data-msec] { display: none; margin-top: 0; }
  [data-mtabs="journal"] [data-msec="journal"], [data-mtabs="expense"] [data-msec="expense"], [data-mtabs="invest"] [data-msec="invest"],
  [data-mtabs="income"] [data-msec="income"], [data-mtabs="sum"] [data-msec="sum"] { display: block; }

  .grid.kpis.debt-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .debt-kpis .card { padding: 10px; }
  .debt-kpis .kpi .label { font-size: 11.5px; line-height: 1.25; }
  .debt-kpis .kpi .dot { display: none; }
  .debt-kpis .kpi .value { font-size: 16px; }
  .debt-kpis .kpi .value .muted { display: none; }
  .letter { top: env(safe-area-inset-top); }

  .cmp-row { width: 100%; }
  .cmp-row select.input { flex: 1; }
  .cmp-lab { min-width: 64px; }
}
@media (max-width: 420px) {
  .grid.kpis { gap: 10px; }
  .kpi .value { font-size: 18px; }
}
/* Cảm ứng: phản hồi lúc nhấn thay cho hiệu ứng rê chuột */
@media (hover: none) {
  .tx:active, .person:active, .btn:active, .pick:active, .nav a:active { opacity: .65; }
}

/* ===== Bổ sung bố cục máy tính ===== */
/* Tổng quan: mỗi cột tự xếp thẻ, không bị kéo theo chiều cao cột bên kia */
.dash-col { display: grid; gap: inherit; align-content: start; min-width: 0; }
@media (max-width: 1100px) { .dash-col { display: contents; } }
/* Hạn mức 12 tháng: kiểu bảng tính — ô trống để trống, khung chỉ hiện khi rê chuột / đang sửa */
table.t.budget-grid input.cell { background: transparent; }
table.t.budget-grid input.cell:hover { background: var(--field); border-color: var(--line-strong); }
table.t.budget-grid input.cell:focus { background: var(--surface); border-color: var(--accent); }
table.t.budget-grid input.cell:not(:placeholder-shown) { font-weight: 500; }
.budget-grid th.sticky-col, .budget-grid td.sticky-col { width: 240px; min-width: 200px; }
/* So sánh: % nằm cùng dòng với chênh lệch trên màn rộng */
@media (min-width: 821px) { .delta-pct { display: inline-block; min-width: 60px; margin-left: 8px; text-align: right; } }
@media (min-width: 821px) { .grid.kpis.debt-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ===== Nguồn tiền ===== */
.acc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr)); gap: 16px; }
.acc-card { display: flex; flex-direction: column; gap: 4px; padding-top: 14px; padding-bottom: 14px; }
.acc-card.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.acc-card.off { opacity: .7; }
.acc-card.total { background: var(--surface-2); }
.acc-top { display: flex; align-items: center; justify-content: space-between; min-height: 30px; }
.acc-type { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.acc-name { font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-bal { text-align: left; font-size: 24px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.acc-bal .muted { font-size: .55em; font-weight: 500; }
.acc-meta { font-size: 12.5px; color: var(--muted); }
.acc-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.flow-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.flow-kpis .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.flow-kpis .v { text-align: left; font-size: 19px; font-weight: 600; letter-spacing: -0.015em; }
.flow-kpis .muted { font-size: 11.5px; }
.flow-note { font-size: 12.5px; color: var(--ink-2); background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; margin: 0 0 12px; }
table.t tr.group td { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); padding-top: 7px; padding-bottom: 7px; }
@media (max-width: 1100px) { .flow-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 820px) { .acc-grid { gap: 10px; } .acc-bal { font-size: 21px; } }
.ledger-scroll:not(.show-before) tr.before { display: none; }
/* Máy tính: sổ chi tiết cuộn trong khung. Màn hẹp: cuộn theo trang (khung cuộn lồng nhau nuốt cú vuốt trên điện thoại) */
@media (min-width: 1281px) { .ledger-scroll { max-height: max(420px, calc(100vh - 260px)); overflow-y: auto; } }
.acc-row { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.acc-row-top { display: flex; justify-content: space-between; gap: 10px; font-size: 14.5px; margin-bottom: 2px; }
.acc-add { align-items: center; justify-content: center; text-align: center; border: 1.5px dashed var(--line-strong); background: transparent; box-shadow: none; cursor: pointer; color: var(--ink-2); font: inherit; min-height: 150px; }
.acc-add > span:nth-child(2) { font-weight: 600; color: var(--ink); }
.acc-add .muted { font-size: 12px; }
.acc-add-plus { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 4px; }
.acc-add-plus svg { width: 18px; height: 18px; }
@media (hover: hover) { .acc-add:hover { border-color: var(--accent); background: var(--accent-soft); } }

/* ===== Tài sản tích luỹ (Tổng quan) ===== */
.holdings { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(0, 2fr); gap: 24px; align-items: start; }
.hold-sum { display: flex; flex-direction: column; gap: 6px; }
.hold-sum .label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); font-weight: 500; }
.hold-sum .dot { width: 8px; height: 8px; border-radius: 50%; }
.hold-sum .value { text-align: left; font-size: 30px; font-weight: 600; letter-spacing: -0.025em; line-height: 1.15; }
.hold-sum .value .muted { font-size: .5em; font-weight: 500; }
.hold-sum .meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 2px 12px; flex-wrap: wrap; }
.hold-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 4px 24px; }
.hold-row { padding: 6px 0 8px; border-bottom: 1px solid var(--line); }
.hold-top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-size: 13.5px; }
.hold-top .nm { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hold-sub { font-size: 12px; color: var(--muted); margin-top: 5px; }
@media (max-width: 1100px) { .holdings { grid-template-columns: 1fr; gap: 14px; } }
@media (max-width: 820px) { .hold-sum .value { font-size: 24px; } }
/* Thống kê theo loại nguồn tiền (đầu trang Nguồn tiền) */
.type-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 16px; }
.type-stat { display: flex; flex-direction: column; gap: 4px; padding-top: 14px; padding-bottom: 14px; }
.type-stat.total { background: var(--surface-2); }
.type-stat .ts-n { font-size: 13px; color: var(--ink-2); }
.type-stat .ts-n b { font-size: 15px; color: var(--ink); }
.type-stat .ts-bal { text-align: left; font-size: 22px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; }
.type-stat .ts-bal .muted { font-size: .55em; font-weight: 500; }
.type-stat .bar { margin: 4px 0 0; }
@media (max-width: 820px) { .type-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } .type-stat.total { grid-column: 1 / -1; } .type-stat .ts-bal { font-size: 18px; } }

/* Vàng / nhóm theo đơn vị trong Tài sản tích luỹ */
.hold-unit { font-size: 12.5px; color: var(--ink-2); margin-top: 6px; line-height: 1.5; }
.hold-unit .btn { color: var(--accent); }

/* ===== Bảng kê theo người · Danh bạ ===== */
.st-table tr[data-st-person] { cursor: pointer; }
.st-row { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.person-figs { margin: 4px 0 10px; }
.person-figs .v { font-size: 17px; }
.person-kv { margin-bottom: 4px; }
@media (max-width: 820px) {
  [data-mtabs="people"] [data-msec="people"] { display: block; }
  .seg.mob-tabs button { font-size: 12.5px; padding: 9px 1px; }
}

/* ===== Tổng quan: dải "Tiền đang có · Sổ nợ" ===== */
.status-strip { display: flex; padding: 0; overflow: hidden; }
.status-strip .st-item { flex: 1 1 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 12px var(--pad); color: inherit; text-decoration: none; border-left: 1px solid var(--line); }
.status-strip .st-item.wide { flex-grow: 2; }
.status-strip .st-item b.num { text-align: left; }
.status-strip .st-item:first-child { border-left: 0; }
.status-strip .st-item .label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.status-strip .st-item b { font-size: 18px; font-weight: 600; letter-spacing: -0.015em; font-variant-numeric: tabular-nums; }
.status-strip .st-item .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (hover: hover) { .status-strip .st-item:hover { background: var(--surface-2); } }
@media (max-width: 820px) {
  .status-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-strip .st-item { padding: 10px 14px; }
  .status-strip .st-item.wide { grid-column: 1 / -1; }
  .status-strip .st-item:not(.wide) { border-top: 1px solid var(--line); }
  .status-strip .st-item.wide + .st-item { border-left: 0; }
  .status-strip .st-item b { font-size: 16px; }
}
/* Nhật ký vẽ từng đợt */
.more-btn { display: block; width: 100%; margin: 6px 0 2px; color: var(--muted); }
/* Hướng dẫn "Cách dùng" thu gọn */
details.guide { padding: 0; }
details.guide > summary { display: flex; justify-content: space-between; align-items: center; padding: 13px var(--pad); cursor: pointer; list-style: none; font-size: 14px; font-weight: 600; color: var(--ink-2); }
details.guide > summary::-webkit-details-marker { display: none; }
details.guide > summary::after { content: "+"; font-weight: 400; font-size: 18px; line-height: 1; color: var(--muted); }
details.guide[open] > summary::after { content: "−"; }
details.guide > .howto { padding: 0 var(--pad) 8px; }
