/* Nhịp Chi — một mặt giấy, chia vùng bằng đường mảnh và khoảng trắng.
   Màu chỉ để báo trạng thái (đỏ gạch, vàng đất, xanh lá tiền vào) và cho nút chính (xanh ngọc tờ 500k). */

@font-face { font-family: "Be Vietnam Pro"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/bvp-vi-400.woff2) format("woff2"); 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; }
@font-face { font-family: "Be Vietnam Pro"; font-style: normal; font-weight: 400; font-display: swap; src: url(fonts/bvp-latin-400.woff2) format("woff2"); 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: "Be Vietnam Pro"; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/bvp-vi-500.woff2) format("woff2"); 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; }
@font-face { font-family: "Be Vietnam Pro"; font-style: normal; font-weight: 500; font-display: swap; src: url(fonts/bvp-latin-500.woff2) format("woff2"); 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: "Be Vietnam Pro"; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/bvp-vi-600.woff2) format("woff2"); 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; }
@font-face { font-family: "Be Vietnam Pro"; font-style: normal; font-weight: 600; font-display: swap; src: url(fonts/bvp-latin-600.woff2) format("woff2"); 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: "Literata"; font-style: normal; font-weight: 200 900; font-display: swap; src: url(fonts/lit-vi.woff2) format("woff2"); 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; }
@font-face { font-family: "Literata"; font-style: normal; font-weight: 200 900; font-display: swap; src: url(fonts/lit-latin.woff2) format("woff2"); 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; }
/* Chữ số: lấy riêng các chữ số (có số đều hàng) để cột tiền thẳng hàng */
@font-face { font-family: "NC So"; font-style: normal; font-weight: 400 500; font-display: swap; src: url(fonts/num-500.woff2) format("woff2"); unicode-range: U+0025,U+002B-002E,U+0030-003A,U+2013,U+2212; }
@font-face { font-family: "NC So"; font-style: normal; font-weight: 600 700; font-display: swap; src: url(fonts/num-600.woff2) format("woff2"); unicode-range: U+0025,U+002B-002E,U+0030-003A,U+2013,U+2212; }

/* Bố cục: điện thoại = một cột + thanh tab dưới; máy tính = thanh trái + hai cột. */
:root {
  --canvas: #F3F6F7;
  --paper: #FFFFFF;
  --ink: #1C2A33;
  --ink-2: #55666F;
  --rule: #DCE3E6;
  --line-ui: #73848D;
  --accent: #00789A;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3F1F5;
  --accent-strong: #005F7A;
  --chi: #00789A;
  --chi-track: #D7EBF1;
  --thu: #3F9A4E;
  --thu-ink: #2E7A3E;
  --alert: #B23A1E;
  --alert-soft: #FBEDE9;
  --warn: #8A5A00;
  --warn-mark: #B97A00;
  --warn-soft: #FFF4DE;
  --band: rgba(85, 102, 111, 0.15);
  --grid: #E6ECEE;
  --hover: rgba(28, 42, 51, 0.05);
  --shadow-sheet: 0 -10px 40px rgba(16, 32, 40, 0.18);
  --scrim: rgba(16, 28, 34, 0.38);

  --font-ui: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: "NC So", "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-title: "Literata", Georgia, "Times New Roman", serif;

  --t-xs: 0.8125rem;
  --t-sm: 0.875rem;
  --t-md: 1rem;
  --t-lg: 1.125rem;
  --t-xl: 1.375rem;
  --t-title: 1.75rem;
  --t-hero: 2.75rem;

  --gutter: max(16px, env(safe-area-inset-left, 0px));
  --tabbar-h: 62px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 20px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas: #0E1A1F; --paper: #13232A; --ink: #E4ECEF; --ink-2: #A3B4BC; --rule: #24363E; --line-ui: #5E737D;
    --accent: #3AAFCB; --accent-ink: #0E1A1F; --accent-soft: #163C47; --accent-strong: #7FD0E2;
    --chi: #1C93B4; --chi-track: #183A45; --thu: #5AA94F; --thu-ink: #6CC487;
    --alert: #F08A6E; --alert-soft: #3A2019; --warn: #E2B04A; --warn-mark: #D9A23A; --warn-soft: #33290F;
    --band: rgba(163, 180, 188, 0.17); --grid: #1F3038; --hover: rgba(228, 236, 239, 0.06);
    --shadow-sheet: 0 -10px 40px rgba(0, 0, 0, 0.5); --scrim: rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --canvas: #0E1A1F; --paper: #13232A; --ink: #E4ECEF; --ink-2: #A3B4BC; --rule: #24363E; --line-ui: #5E737D;
  --accent: #3AAFCB; --accent-ink: #0E1A1F; --accent-soft: #163C47; --accent-strong: #7FD0E2;
  --chi: #1C93B4; --chi-track: #183A45; --thu: #5AA94F; --thu-ink: #6CC487;
  --alert: #F08A6E; --alert-soft: #3A2019; --warn: #E2B04A; --warn-mark: #D9A23A; --warn-soft: #33290F;
  --band: rgba(163, 180, 188, 0.17); --grid: #1F3038; --hover: rgba(228, 236, 239, 0.06);
  --shadow-sheet: 0 -10px 40px rgba(0, 0, 0, 0.5); --scrim: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

/* ---------- nền ---------- */
:root { padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
[hidden] { display: none !important; }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--t-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--paper); }
html.has-sheet, html.is-locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3, p, dl, dd, ol, ul { margin: 0; }
ul, ol { padding: 0; list-style: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.num, .money { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.ic { flex: none; }

/* ---------- khung ---------- */
.shell { min-height: 100%; }
.rail { display: none; }
.main {
  padding-left: var(--gutter);
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 4px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 28px);
  max-width: 760px;
  margin: 0 auto;
}
.demo-note {
  display: flex; align-items: center; gap: 8px;
  margin: 10px 0 0; padding: 8px 12px;
  font-size: var(--t-xs); color: var(--ink-2);
  background: var(--canvas); border-radius: var(--r-sm);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 4px max(4px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px) max(4px, env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--rule);
}
.tab {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 54px; padding: 4px 2px;
  font-size: 0.6875rem; font-weight: 500; line-height: 1.2;
  color: var(--ink-2); text-decoration: none; border-radius: var(--r-sm);
}
.tab.is-on { color: var(--accent-strong); }
.tab.is-on .ic { stroke-width: 2.1; }
.tab .badge { position: absolute; top: 2px; left: calc(50% + 6px); }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center;
  font-size: 0.6875rem; font-weight: 600; line-height: 1;
  color: #FFFFFF; background: var(--alert); border-radius: 999px;
}
:root[data-theme="dark"] .badge { color: #13232A; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge { color: #13232A; } }

/* ---------- tiêu đề màn ---------- */
.view-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 18px 0 6px;
}
.view-title {
  font-family: var(--font-title);
  font-size: var(--t-title); font-weight: 560; line-height: 1.2; letter-spacing: -0.01em;
  text-wrap: balance;
}
.view-title:focus { outline: none; }
.view-actions { display: flex; align-items: center; gap: 8px; }
.head-month { font-size: var(--t-sm); color: var(--ink-2); }
.month-nav { display: flex; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; padding: 0;
  color: var(--ink); background: transparent; border: 1px solid var(--rule); border-radius: 999px;
}
.icon-btn:hover:not(:disabled) { background: var(--hover); }
.icon-btn:disabled { color: var(--ink-2); opacity: 0.45; cursor: default; }
.icon-btn.small { width: 36px; height: 36px; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-title { display: flex; align-items: center; gap: 8px; font-size: var(--t-lg); font-weight: 600; line-height: 1.3; }
.count {
  display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 7px;
  font-size: var(--t-xs); font-weight: 600; color: var(--alert); background: var(--alert-soft); border-radius: 999px;
}
.link-btn {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 44px; padding: 0 2px;
  font-size: var(--t-sm); font-weight: 500;
  color: var(--accent-strong); background: none; border: 0;
}
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }
.block { padding-top: 24px; margin-top: 24px; border-top: 1px solid var(--rule); }
.empty { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: var(--t-sm); padding: 6px 0; }
.empty.big { flex-direction: column; text-align: center; gap: 12px; padding: 48px 12px; }
.empty.big p { max-width: 34ch; }

/* ---------- nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px;
  font-size: var(--t-sm); font-weight: 600; line-height: 1.2;
  border-radius: var(--r-md); border: 1px solid transparent;
}
.btn-primary { color: var(--accent-ink); background: var(--accent); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-quiet { color: var(--ink); background: var(--paper); border-color: var(--line-ui); }
.btn-quiet:hover { background: var(--hover); }
.btn-danger { color: var(--alert); background: var(--paper); border-color: var(--alert); }
.btn-danger:hover { background: var(--alert-soft); }
.btn.small { min-height: 36px; padding: 0 12px; }
.btn-big { min-height: 56px; padding: 0 24px; font-size: var(--t-md); border-radius: 16px; }
.btn:disabled { opacity: 0.6; cursor: default; }

/* ---------- số tiền ---------- */
.money { white-space: nowrap; font-weight: 500; }
.money .cur { font-family: var(--font-ui); font-size: 0.85em; color: var(--ink-2); font-weight: 400; }
.money.in { color: var(--thu-ink); }
.money.in .cur { color: inherit; opacity: 0.8; }

/* ---------- tổng quan ---------- */
.hero { padding-top: 6px; }
.hero-label { font-size: var(--t-sm); color: var(--ink-2); }
.hero-amount {
  font-family: var(--font-num); font-size: var(--t-hero); font-weight: 600;
  line-height: 1.1; letter-spacing: -0.02em; margin-top: 2px;
}
.hero-cur { font-family: var(--font-ui); font-size: 0.5em; font-weight: 500; color: var(--ink-2); letter-spacing: 0; }
.pace-status { display: flex; flex-wrap: wrap; align-items: center; column-gap: 6px; row-gap: 0; margin: 8px 0 14px; font-weight: 600; font-size: var(--t-md); }
.pace-note { flex-basis: 100%; font-weight: 400; font-size: var(--t-sm); color: var(--ink-2); padding-left: 22px; }
.tone-warn { color: var(--warn); }
.tone-alert { color: var(--alert); }
.tone-good { color: var(--thu-ink); }
.tone-flat { color: var(--ink-2); }

.chart { position: relative; width: 100%; }
.chart:focus-visible { outline-offset: 4px; }
.chart-svg { display: block; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis { fill: var(--ink-2); font-family: var(--font-num); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .axis.strong { fill: var(--ink); font-weight: 600; }
.chart .band { fill: var(--band); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line-chi { stroke: var(--chi); }
.chart .dot { stroke: var(--paper); stroke-width: 2; }
.chart .dot-chi { fill: var(--chi); }
.chart .dot-alert { fill: var(--alert); }
.chart .dot-sample { fill: var(--ink-2); opacity: 0.28; }
.chart .crosshair { stroke: var(--ink-2); stroke-width: 1; }
.chart .bar-chi { fill: var(--chi); }
.chart .bar-thu { fill: var(--thu); }
.chart .hover-col { fill: var(--hover); }
.chart .draw { stroke-dasharray: 1; stroke-dashoffset: 0; animation: draw 1.1s cubic-bezier(.3,.7,.2,1) both; }
.chart .pop { animation: pop .35s ease-out 1s both; transform-box: fill-box; transform-origin: center; }
@keyframes draw { from { stroke-dashoffset: 1; } }
@keyframes pop { from { transform: scale(0); } }
.chart-tip {
  position: absolute; top: 4px; z-index: 2; min-width: 168px; pointer-events: none;
  padding: 8px 10px; font-size: var(--t-xs);
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--rule); border-radius: var(--r-sm);
  box-shadow: 0 4px 16px rgba(16, 32, 40, 0.12);
}
.tip-title { font-weight: 600; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 8px; }
.tip-label { color: var(--ink-2); }
.tip-value { margin-left: auto; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 8px; font-size: var(--t-xs); color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; flex: none; width: 14px; }
.key-line { height: 2px; border-radius: 2px; }
.key-box { height: 10px; border-radius: 3px; }
.key.k-chi { background: var(--chi); }
.key.k-thu { background: var(--thu); }
.key.k-band { background: var(--band); outline: 1px solid var(--rule); outline-offset: -1px; }
.table-toggle { margin-top: 10px; font-size: var(--t-sm); }
.table-toggle summary { cursor: pointer; color: var(--accent-strong); font-weight: 500; min-height: 36px; display: inline-flex; align-items: center; }
.table-toggle[open] summary { margin-bottom: 6px; }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--t-sm); }
.data-table th, .data-table td { padding: 6px 4px; border-bottom: 1px solid var(--rule); text-align: right; }
.data-table th:first-child { text-align: left; font-weight: 500; }
.data-table thead th { font-weight: 500; color: var(--ink-2); font-size: var(--t-xs); }

.facts { display: grid; margin-top: 20px; border-top: 1px solid var(--rule); }
.fact { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--rule); min-width: 0; }
.fact dt { font-size: var(--t-sm); color: var(--ink-2); }
.fact dd { font-size: var(--t-md); font-weight: 600; }
.fact .money { font-weight: 600; }

/* ngân sách */
.meters { display: grid; gap: 16px; }
.meter-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; font-size: var(--t-sm); }
.meter-name { font-weight: 500; }
.meter-nums { font-weight: 600; }
.meter { position: relative; display: block; height: 8px; margin: 6px 0 4px; background: var(--chi-track); border-radius: 999px; }
.meter-fill { position: absolute; inset: 0 auto 0 0; background: var(--chi); border-radius: 999px; }
.is-warn .meter-fill { background: var(--warn-mark); }
.is-over .meter-fill { background: var(--alert); }
.is-warn .meter { background: var(--warn-soft); }
.is-over .meter { background: var(--alert-soft); }
.meter-tick { position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--ink); border-radius: 1px; box-shadow: 0 0 0 2px var(--paper); }
.meter-note { display: inline-flex; align-items: center; gap: 4px; font-size: var(--t-xs); color: var(--ink-2); }
.meter-note.tone-alert { color: var(--alert); font-weight: 500; }
.meter-note.tone-warn { color: var(--warn); font-weight: 500; }

/* chưa phân loại */
.uncat {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 12px;
  padding: 14px; margin-bottom: 14px; background: var(--canvas); border-radius: var(--r-md);
}
.uncat-icon { color: var(--accent-strong); grid-row: span 2; align-self: start; padding-top: 2px; }
.uncat-text { display: grid; font-size: var(--t-sm); }
.uncat-text span { color: var(--ink-2); }
.uncat .btn { grid-column: 2; justify-self: start; margin-top: 6px; }

/* ---------- thẻ bất thường ---------- */
.cards { display: grid; gap: 12px; }
.card.alert-card {
  position: relative;
  padding: 14px 14px 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
}
.alert-card.is-seen { background: transparent; }
.alert-card.is-seen .card-icon { color: var(--ink-2); }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-icon { color: var(--ink-2); display: inline-grid; }
.sev-cao .card-icon { color: var(--alert); }
.sev-vua .card-icon { color: var(--warn); }
.card-title { flex: 1; min-width: 0; font-size: var(--t-md); font-weight: 600; line-height: 1.35; }
.sev { display: inline-flex; align-items: center; gap: 4px; flex: none; padding: 2px 8px; font-size: var(--t-xs); font-weight: 600; border-radius: 999px; }
.sev-cao.sev { color: var(--alert); background: var(--alert-soft); }
.sev-vua.sev { color: var(--warn); background: var(--warn-soft); }
.sev-thap.sev { color: var(--ink-2); background: var(--canvas); }
.card-body { display: grid; gap: 4px; margin-top: 8px; font-size: var(--t-sm); }
.card-amount { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.card-open {
  position: relative; width: calc(100% + 12px); margin: -4px -6px 0; padding: 4px 30px 4px 6px;
  text-align: left; background: none; border: 0; border-radius: var(--r-sm);
}
.card-open:hover { background: var(--hover); }
.card-chev { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); color: var(--ink-2); }
.card-amount .money { font-size: var(--t-lg); font-weight: 600; }
.card-who { font-weight: 500; overflow-wrap: anywhere; }
.card-meta { color: var(--ink-2); overflow-wrap: anywhere; }
.card-reason { color: var(--ink); }
.card-reason.also { display: flex; gap: 6px; align-items: flex-start; color: var(--ink-2); }
.card-reason.also .ic { margin-top: 3px; }
.card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.card-actions .link-btn { margin-left: auto; }
.card-done { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: var(--t-sm); }
.chart-strip { margin-top: 6px; }

/* ---------- danh sách giao dịch ---------- */
.tx-list { display: grid; }
.tx-row + .tx-row { border-top: 1px solid var(--rule); }
.tx-btn {
  display: grid; grid-template-columns: 3.1rem minmax(0, 1fr) auto; align-items: start; gap: 2px 10px;
  width: 100%; min-height: 56px; padding: 10px 6px; margin: 0 -6px; width: calc(100% + 12px);
  text-align: left; background: none; border: 0; border-radius: var(--r-sm);
}
.tx-btn:hover { background: var(--hover); }
.tx-time { font-size: var(--t-sm); color: var(--ink-2); padding-top: 1px; }
.tx-main { display: grid; gap: 2px; min-width: 0; }
.tx-title { display: flex; align-items: center; gap: 6px; font-weight: 500; overflow-wrap: anywhere; }
.tx-flag { display: inline-grid; color: var(--warn); }
.tx-flag.sev-cao { color: var(--alert); }
.tx-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: var(--t-xs); color: var(--ink-2); }
.tx-party { overflow-wrap: anywhere; }
.tag { display: inline-flex; align-items: center; padding: 1px 8px; font-size: var(--t-xs); font-weight: 500; color: var(--ink-2); border: 1px solid var(--rule); border-radius: 999px; white-space: nowrap; }
.tag-empty { color: var(--accent-strong); border-color: var(--accent); border-style: dashed; }
.tag-off { text-decoration: line-through; }
.tx-amt { text-align: right; font-weight: 600; padding-top: 1px; }

.toolbar { display: grid; gap: 10px; padding-top: 6px; }
.search { position: relative; display: flex; align-items: center; }
.search .ic { position: absolute; left: 12px; color: var(--ink-2); pointer-events: none; }
.input {
  width: 100%; min-height: 44px; padding: 10px 12px;
  font-size: var(--t-md); color: var(--ink);
  background: var(--paper); border: 1px solid var(--line-ui); border-radius: var(--r-md);
}
.input::placeholder { color: var(--ink-2); opacity: 1; }
.search-input { padding-left: 40px; }
textarea.input { resize: vertical; min-height: 64px; }
.select {
  min-height: 40px; padding: 0 30px 0 12px; font-size: var(--t-sm);
  background: var(--paper); border: 1px solid var(--line-ui); border-radius: 999px;
}
.filter-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; margin: 0 calc(-1 * var(--gutter)); padding-inline: var(--gutter); }
.filter-row::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  min-height: 40px; padding: 0 14px;
  font-size: var(--t-sm); font-weight: 500;
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--line-ui); border-radius: 999px;
}
.chip:hover { background: var(--hover); }
.chip.is-on { color: var(--accent-strong); background: var(--accent-soft); border-color: var(--accent); }
.chip-count { font-size: var(--t-xs); font-weight: 600; color: var(--ink-2); }
.chip.is-on .chip-count { color: var(--accent-strong); }
.list-summary { display: flex; justify-content: space-between; gap: 12px; padding: 14px 0 4px; font-size: var(--t-sm); color: var(--ink-2); }
.list-summary .money { color: var(--ink); font-weight: 600; }
.days { display: grid; gap: 18px; margin-top: 6px; }
.day-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--ink); }
.day-title { font-size: var(--t-sm); font-weight: 600; }
.day-total { font-size: var(--t-sm); color: var(--ink-2); }

/* ---------- bất thường ---------- */
.segmented { display: inline-flex; gap: 4px; padding: 4px; margin: 8px 0 16px; background: var(--canvas); border-radius: 999px; }
.seg { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 16px; font-size: var(--t-sm); font-weight: 500; color: var(--ink-2); background: transparent; border: 0; border-radius: 999px; }
.seg.is-on { color: var(--ink); background: var(--paper); box-shadow: 0 1px 3px rgba(16, 32, 40, 0.12); }
.seg-count { font-size: var(--t-xs); font-weight: 600; }
.rules { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--rule); font-size: var(--t-sm); }
.rules summary { cursor: pointer; font-weight: 600; min-height: 40px; display: inline-flex; align-items: center; }
.rule-list { display: grid; gap: 12px; margin-top: 10px; }
.rule { display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.rule-icon { color: var(--ink-2); padding-top: 1px; }
.rule p { color: var(--ink-2); }

/* ---------- báo cáo ---------- */
.note-line { display: flex; align-items: center; gap: 6px; font-size: var(--t-sm); color: var(--ink-2); margin-top: 4px; }
.stats { display: grid; grid-template-columns: 1fr; margin-top: 16px; border-top: 1px solid var(--rule); }
.stat { display: grid; gap: 2px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.stat dt { font-size: var(--t-sm); color: var(--ink-2); }
.stat dd { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.stat dd > .money { font-size: var(--t-xl); font-weight: 600; }
.stat-delta, .stat-note { display: inline-flex; align-items: center; gap: 4px; font-size: var(--t-xs); font-weight: 500; color: var(--ink-2); }
.stat-delta.tone-warn, .stat-note.tone-warn { color: var(--warn); }
.stat-delta.tone-good { color: var(--thu-ink); }
.rp-grid { display: grid; }
.cat-bars { display: grid; gap: 2px; }
.cat-bar {
  display: grid; grid-template-columns: minmax(6.5rem, 9rem) minmax(0, 1fr) auto 3.4rem; align-items: center; gap: 10px;
  width: 100%; min-height: 44px; padding: 4px 6px; margin: 0 -6px; width: calc(100% + 12px);
  text-align: left; background: none; border: 0; border-radius: var(--r-sm);
}
.cat-bar:hover { background: var(--hover); }
.cat-name { font-size: var(--t-sm); font-weight: 500; overflow-wrap: anywhere; }
.cat-track { display: block; height: 14px; }
.cat-fill { display: block; height: 100%; min-width: 2px; background: var(--chi); border-radius: 0 4px 4px 0; }
.cat-amt { font-size: var(--t-sm); font-weight: 600; text-align: right; }
.chg { display: inline-flex; align-items: center; justify-content: flex-end; gap: 2px; font-size: var(--t-xs); font-weight: 600; }
.chg.muted { font-weight: 500; }
.rank { display: grid; }
.rank-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.rank-main { display: grid; min-width: 0; }
.rank-name { font-weight: 500; font-size: var(--t-sm); overflow-wrap: anywhere; }
.rank-sub { font-size: var(--t-xs); color: var(--ink-2); }
.rank-amt { font-weight: 600; font-size: var(--t-sm); white-space: nowrap; }
.export { margin-top: 28px; }
.chart-months { margin-top: 4px; }

/* ---------- cài đặt ---------- */
.set-group { margin-top: 20px; }
.set-group .section-title { font-size: var(--t-sm); color: var(--ink-2); font-weight: 500; margin-bottom: 4px; }
.set-list { border-top: 1px solid var(--rule); }
.set-list li { border-bottom: 1px solid var(--rule); }
.set-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 12px;
  width: 100%; min-height: 64px; padding: 10px 6px; margin: 0 -6px; width: calc(100% + 12px);
  text-align: left; background: none; border: 0; border-radius: var(--r-sm);
}
.set-item:hover { background: var(--hover); }
.set-icon { display: inline-grid; place-items: center; width: 36px; height: 36px; color: var(--accent-strong); background: var(--accent-soft); border-radius: 10px; }
.set-text { display: grid; gap: 1px; min-width: 0; }
.set-title { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.set-sub { font-size: var(--t-xs); color: var(--ink-2); overflow-wrap: anywhere; }
.set-chev { color: var(--ink-2); }
.status-ok { display: inline-flex; align-items: center; gap: 4px; font-size: var(--t-xs); font-weight: 600; color: var(--thu-ink); white-space: nowrap; }
.quota { margin-top: 24px; padding: 14px; background: var(--canvas); border-radius: var(--r-md); }
.quota-title { display: flex; justify-content: space-between; font-size: var(--t-sm); font-weight: 600; }
.quota .meter { margin: 10px 0 8px; }
.danger-zone { display: grid; gap: 8px; justify-items: start; margin-top: 24px; }
.back-btn { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; margin-top: 8px; padding: 0 8px 0 0; font-size: var(--t-sm); font-weight: 500; color: var(--accent-strong); background: none; border: 0; }
.lead { color: var(--ink-2); font-size: var(--t-sm); max-width: 62ch; margin: 4px 0 16px; }
.sub-title { font-size: var(--t-md); font-weight: 600; margin: 20px 0 8px; }
.bullets { display: grid; gap: 8px; font-size: var(--t-sm); }
.bullets li { position: relative; padding-left: 16px; }
.bullets li::before { content: ""; position: absolute; left: 2px; top: 0.6em; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.budget-edit { display: grid; border-top: 1px solid var(--rule); }
.budget-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(9rem, 12rem); align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--rule); }
.budget-row label { font-weight: 500; }
.input-money { position: relative; display: flex; align-items: center; }
.input-money .input { text-align: right; padding-right: 30px; }
.input-suffix { position: absolute; right: 12px; color: var(--ink-2); pointer-events: none; }
.kw-list, .kw-groups { display: grid; gap: 10px; }
.kw-groups li { display: grid; gap: 6px; padding-bottom: 10px; border-bottom: 1px solid var(--rule); }
.kw-cat { font-weight: 600; font-size: var(--t-sm); }
.kw-words { display: flex; flex-wrap: wrap; gap: 6px; }
.kw { display: inline-block; padding: 2px 8px; font-size: var(--t-xs); background: var(--canvas); border-radius: 6px; }
.kw-list li { display: flex; justify-content: space-between; align-items: center; }
.people, .devices, .log { display: grid; border-top: 1px solid var(--rule); }
.person, .device, .log-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.person-main { display: grid; flex: 1; min-width: 0; }
.person-name { font-weight: 500; }
.person-sub { font-size: var(--t-xs); color: var(--ink-2); overflow-wrap: anywhere; }
.device .set-text { flex: 1; }
.log-row { align-items: flex-start; }
.log-time { width: 3.2rem; flex: none; font-size: var(--t-xs); color: var(--ink-2); }
.log-main { display: grid; }
.log-what { font-weight: 500; font-size: var(--t-sm); }
.log-where { font-size: var(--t-xs); color: var(--ink-2); }
.log-row.is-warn .log-what { color: var(--alert); }
.prose .fields { margin-top: 4px; }

/* ---------- tấm trượt ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: var(--scrim); opacity: 0; transition: opacity .2s ease; }
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  display: flex; flex-direction: column;
  max-height: calc(100% - 24px - env(safe-area-inset-top, 0px));
  background: var(--paper); border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: var(--shadow-sheet);
  transform: translateY(104%); transition: transform .26s cubic-bezier(.2,.8,.2,1);
  overscroll-behavior: contain;
}
.sheet.open { transform: none; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--rule);
}
.sheet-head::before { content: ""; position: absolute; top: 6px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--rule); }
.sheet-title { font-size: var(--t-lg); font-weight: 600; }
.sheet-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 16px max(16px, env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
}
.sheet-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.sheet-actions.left { justify-content: flex-start; }
.txd { display: grid; gap: 16px; }
.txd-amount .money { font-size: 2.125rem; font-weight: 600; letter-spacing: -0.01em; }
.txd-when { margin-top: -12px; color: var(--ink-2); font-size: var(--t-sm); }
.fields { display: grid; border-top: 1px solid var(--rule); }
.field { display: grid; grid-template-columns: minmax(7.5rem, 38%) minmax(0, 1fr); gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--rule); font-size: var(--t-sm); }
.field dt { color: var(--ink-2); }
.field dd { font-weight: 500; overflow-wrap: anywhere; }
.form-row { display: grid; gap: 6px; }
.form-group { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; min-width: 0; }
.form-label { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; width: 100%; font-weight: 600; font-size: var(--t-sm); padding: 0; }
.form-hint { font-size: var(--t-xs); color: var(--ink-2); font-weight: 400; }
.form-hint.center { text-align: center; }
.radio-row { display: grid; gap: 4px; }
.radio { display: flex; align-items: center; gap: 10px; min-height: 40px; font-size: var(--t-sm); cursor: pointer; }
.radio input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--rule); cursor: pointer; }
.switch-row > span { display: grid; gap: 2px; }
.switch-title { font-weight: 600; font-size: var(--t-sm); }
.switch {
  appearance: none; -webkit-appearance: none; flex: none; position: relative;
  width: 48px; height: 28px; margin: 0; border-radius: 999px; background: var(--line-ui); transition: background .15s;
}
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #FFFFFF; transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.notme .lead { color: var(--ink); font-size: var(--t-md); }
.steps { counter-reset: s; display: grid; gap: 14px; }
.steps li { counter-increment: s; position: relative; display: grid; gap: 4px; padding-left: 40px; font-size: var(--t-sm); }
.steps li::before { content: counter(s); position: absolute; left: 0; top: -2px; display: grid; place-items: center; width: 28px; height: 28px; font-family: var(--font-num); font-weight: 600; color: var(--alert); background: var(--alert-soft); border-radius: 50%; }
.steps strong { font-size: var(--t-md); }
.steps span { color: var(--ink-2); }
.phones { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.phone { display: inline-flex; align-items: center; gap: 6px; }
.phone-num { font-size: var(--t-lg); font-weight: 600; color: var(--ink); text-decoration: none; }

/* ---------- khoá ---------- */
.lock {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(24px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: var(--paper);
}
.lock-inner { display: grid; justify-items: center; gap: 14px; text-align: center; max-width: 340px; }
.lock-brand { font-family: var(--font-title); font-size: 2.75rem; font-weight: 560; letter-spacing: -0.015em; line-height: 1.1; }
.lock-sub { color: var(--ink-2); margin-bottom: 18px; }
.lock-hint { display: inline-flex; align-items: center; gap: 6px; font-size: var(--t-xs); color: var(--ink-2); }

/* ---------- cổng: thiết lập, mở khoá, thêm máy ---------- */
.gate {
  position: fixed; inset: 0; z-index: 60; overflow-y: auto; overscroll-behavior: contain;
  display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(24px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: var(--paper);
}
.gate-inner { display: grid; justify-items: center; gap: 14px; width: 100%; max-width: 440px; text-align: center; padding-block: 24px; }
.gate-form { display: grid; gap: 10px; width: 100%; text-align: left; }
.gate-form .btn-big { margin-top: 8px; }
.gate-form .lock-sub { text-align: center; margin-bottom: 6px; }
.gate-title { font-family: var(--font-title); font-size: var(--t-xl); font-weight: 560; line-height: 1.25; }
.gate-inner > .lead, .gate-form .lead { text-align: left; margin: 0; }
.gate-links { display: grid; justify-items: center; gap: 0; margin-top: 8px; }
.form-error { color: var(--alert); font-size: var(--t-sm); font-weight: 500; text-align: left; }
.mono { font-family: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace; letter-spacing: 0.02em; }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; width: 100%; padding: 14px; background: var(--canvas); border-radius: var(--r-md); counter-reset: c; }
.codes li { font-size: var(--t-md); text-align: left; }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: var(--t-sm); cursor: pointer; text-align: left; }
.check-row input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; flex: none; }
.guide { display: grid; gap: 14px; width: 100%; text-align: left; }
.secret { display: grid; gap: 4px; width: 100%; text-align: left; }
.secret-label { font-size: var(--t-xs); font-weight: 600; color: var(--ink-2); }
.secret-row { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; background: var(--canvas); border-radius: var(--r-md); }
.secret-value { flex: 1; min-width: 0; font-size: var(--t-sm); overflow-wrap: anywhere; word-break: break-all; color: var(--ink); }
.welcome { display: grid; gap: 12px; justify-items: start; padding: 18px 0; }
.pair { display: grid; gap: 6px; padding: 16px; margin-top: 12px; background: var(--canvas); border-radius: var(--r-md); }
.pair-code { font-size: 2rem; font-weight: 600; letter-spacing: 0.08em; }
.async { display: grid; }
.raw-wrap { display: grid; gap: 6px; }
.raw { margin: 0; padding: 12px; max-height: 280px; overflow: auto; font-size: var(--t-xs); white-space: pre-wrap; word-break: break-all; background: var(--canvas); border-radius: var(--r-sm); font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.form-hint.tone-warn { color: var(--warn); }
.sec-list { display: grid; gap: 6px; margin-top: 8px; font-size: var(--t-sm); }
.sec-list li { display: grid; grid-template-columns: 5.6rem minmax(0, 1fr); gap: 8px; overflow-wrap: anywhere; }
.sec-list li.is-warn { color: var(--alert); }
.sec-time { color: var(--ink-2); }
.view-overview > .alert-card { margin-top: 12px; }
.cards + .alert-card, .alert-card + .uncat { margin-top: 12px; }
.quota .meter.is-warn .meter-fill { background: var(--warn-mark); }
.kw-list li { gap: 10px; }
.kw-list .kw-cat { margin-left: auto; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 14px); z-index: 70;
  max-width: min(92vw, 460px); padding: 12px 16px;
  font-size: var(--t-sm); font-weight: 500; color: var(--paper); background: var(--ink);
  border-radius: var(--r-md); box-shadow: 0 8px 24px rgba(16, 32, 40, 0.22);
  transform: translate(-50%, 8px); opacity: 0; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- máy tính ---------- */
@media (min-width: 640px) {
  :root { --t-hero: 3.25rem; }
  .facts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .fact { display: grid; justify-content: start; gap: 2px; padding: 12px 10px 12px 0; }
  .fact + .fact { padding-left: 14px; border-left: 1px solid var(--rule); }
  .fact dt { font-size: var(--t-xs); }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat + .stat { padding-left: 16px; border-left: 1px solid var(--rule); }
  .stat { padding-right: 12px; }
}
@media (min-width: 1000px) {
  body { background: var(--canvas); }
  body::before { background: var(--canvas); }
  .tabbar { display: none; }
  .shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
  .rail {
    position: sticky; top: 0; align-self: start; height: 100vh;
    display: flex; flex-direction: column; gap: 22px;
    padding: 24px 14px 20px max(14px, env(safe-area-inset-left, 0px));
  }
  .brand { font-family: var(--font-title); font-size: 1.5rem; font-weight: 560; padding: 0 12px; }
  .rail-links { display: grid; gap: 2px; }
  .rail-link {
    position: relative; display: flex; align-items: center; gap: 12px;
    min-height: 44px; padding: 0 12px; font-size: var(--t-sm); font-weight: 500;
    color: var(--ink-2); text-decoration: none; border-radius: var(--r-md);
  }
  .rail-link:hover { background: var(--hover); color: var(--ink); }
  .rail-link.is-on { color: var(--ink); background: var(--paper); box-shadow: 0 1px 2px rgba(16, 32, 40, 0.08); }
  .rail-link.is-on .ic { color: var(--accent); }
  .rail-link .badge { margin-left: auto; }
  .rail-foot { margin-top: auto; display: grid; gap: 4px; padding: 0 12px; }
  .rail-sync { display: flex; align-items: center; gap: 6px; font-size: var(--t-xs); color: var(--ink-2); }
  .rail-sync .ic { color: var(--thu-ink); }
  .main {
    max-width: 1180px; width: 100%; margin: 14px 0 14px;
    padding: 6px 36px 40px;
    background: var(--paper); border: 1px solid var(--rule); border-radius: 22px;
    margin-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .view-head { padding-top: 22px; }
  .ov-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 0 44px; align-items: start; }
  .ov-side > .block:first-child { margin-top: 0; border-top: 0; padding-top: 10px; }
  .rp-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 44px; align-items: start; }
  .toast { bottom: 28px; }
  .sheet {
    left: auto; top: 12px; bottom: 12px; right: 12px; width: 440px; max-height: none;
    border-radius: var(--r-lg); transform: translateX(110%);
  }
  .sheet-head::before { display: none; }
  .view-tx .toolbar { grid-template-columns: minmax(0, 340px) minmax(0, 1fr); align-items: center; }
  .filter-row { margin: 0; padding-inline: 0; flex-wrap: wrap; overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .meter-fill, .cat-fill, .key { forced-color-adjust: none; }
  .alert-card::before { background: CanvasText; }
}
