:root {
  --bg: #f2f0ea;           /* Kim: trắng bạc */
  --panel: #fdfcf9;
  --ink: #24221d;
  --muted: #6f6a5f;
  --line: #e2ddd1;
  --accent: #8a6416;       /* Thổ: vàng đất — Hoả sinh Thổ, Thổ sinh Kim */
  --accent-ink: #fff8e8;
  --accent-soft: #f3e5c2;
  --danger: #a3372b;
  --radius: 10px;
  font-family: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.45; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; letter-spacing: -0.01em; }

/* Buttons & inputs */
.btn { appearance: none; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 9px 16px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { border-color: #d4c29a; background: #fff; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #6f500f; border-color: #6f500f; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; padding: 12px; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; padding: 2px 4px; }
.link.danger { color: var(--danger); }
.input { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font: inherit; color: var(--ink); }
.input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 500; }
.msg { min-height: 1.2em; font-size: 13px; color: var(--danger); margin: 10px 0 0; }
.msg.inline { margin-left: 10px; color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 36px 28px; text-align: center; box-shadow: 0 12px 40px -20px rgba(90, 64, 14, .3); }
.login-card h1 { margin: 16px 0 4px; font-size: 24px; }
.login-card .input { margin-bottom: 10px; }
.login-card .hint { margin: 18px 0 12px; }
#login-signin { margin-top: 24px; }
.brand-mark { position: relative; display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 12px; background: var(--accent); color: var(--accent-ink); font-family: Georgia, serif; font-size: 22px; }
.brand-mark.sm { width: 36px; height: 36px; font-size: 15px; border-radius: 9px; }

/* Layout */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.side-brand small { display: block; color: var(--muted); font-size: 12px; }
nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item { display: block; padding: 9px 12px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav-item small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.main { padding: 28px 32px 60px; min-width: 0; max-width: 1100px; }
.view-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.view-head h2 { margin: 2px 0 0; font-size: 26px; }
.eyebrow { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.export { display: flex; gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }

.period { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.period label { min-width: 120px; }
.entry { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; border-left: 3px solid var(--accent); }
.entry .grow { flex: 1; min-width: 220px; }
.entry label:last-of-type { width: 170px; }
.entry-actions { display: flex; gap: 6px; }
.col { display: inline-block; font-size: 11px; background: var(--bg); border: 1px solid var(--line); padding: 0 5px; border-radius: 4px; margin-left: 4px; color: var(--muted); }

/* Ledger */
.table-card { padding: 0; overflow-x: auto; }
.ledger { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.ledger th, .ledger td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.ledger thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #f7f4ec; }
.ledger tr.colcode th { font-size: 11px; padding-top: 0; padding-bottom: 6px; letter-spacing: 0; font-family: Georgia, serif; text-transform: none; }
.ledger .c-date { width: 120px; white-space: nowrap; }
.ledger .c-num { text-align: right; width: 170px; white-space: nowrap; }
.ledger .c-act { width: 110px; text-align: right; white-space: nowrap; }
.ledger tbody tr:hover { background: #faf8f2; }
.ledger tbody tr.editing { background: var(--accent-soft); }
.ledger tfoot td { border-bottom: 0; background: #f7f4ec; font-size: 16px; }
.empty { text-align: center; color: var(--muted); padding: 28px; margin: 0; }

/* Settings */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }

/* Passkeys */
.pk-list { list-style: none; margin: 0 0 16px; padding: 0; }
.pk-list li { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.pk-list small { color: var(--muted); display: block; }
.pk-add { display: flex; gap: 8px; flex-wrap: wrap; }
.pk-add .input { flex: 1; min-width: 200px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 10; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; gap: 10px; }
  nav { flex-direction: row; order: 3; flex: 1 1 100%; overflow-x: auto; }
  .nav-item { white-space: nowrap; padding: 7px 10px; }
  .side-brand { flex: 1; }
  .main { padding: 18px 16px 40px; }
  .entry label:last-of-type, .entry .grow { width: 100%; }
  .entry label { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .ledger { font-size: 14px; }
  .ledger th, .ledger td { padding: 9px 8px; }
  .ledger .c-date { width: 86px; white-space: normal; }
  .ledger .c-num { width: auto; }
  .ledger .c-act { width: 44px; }
  .ledger .c-act .link { display: block; margin-left: auto; padding: 2px 0; }
}

/* --- Tổng quan & chi phí --- */
:root { --rev: #2f6fa3; --exp: #a8781a; --fire: #c2410c; } /* Thuỷ = tài lộc → doanh thu; Hoả: điểm nhấn nhỏ */
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw.rev { background: var(--rev); }
.sw.exp { background: var(--exp); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 0; }
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi b { font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.kpi b.neg { color: var(--danger); }
.kpi small { color: var(--muted); font-size: 12px; }
.chart-card { position: relative; }
.chart-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chart-head h3, .card-title { margin: 0; font-size: 15px; font-family: inherit; font-weight: 600; }
.card-title { margin-bottom: 12px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; }
.chart .grid { stroke: #efe4c9; stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover, .chart .hit.on { fill: rgba(138, 100, 22, .08); }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; padding: 8px 10px; border-radius: 8px; line-height: 1.5; white-space: nowrap; z-index: 2; font-variant-numeric: tabular-nums; }
.chart-tip b { display: block; margin-bottom: 2px; }
.data-table { margin-top: 10px; font-size: 13px; }
.data-table summary { cursor: pointer; color: var(--accent); }
.data-table table { width: 100%; border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.data-table th, .data-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.cat-bars { display: flex; flex-direction: column; gap: 10px; }
.cat-row { display: grid; grid-template-columns: minmax(110px, 200px) 1fr auto; gap: 12px; align-items: center; font-size: 14px; }
.cat-track { height: 10px; background: #f1e7cf; border-radius: 0 4px 4px 0; overflow: hidden; }
.cat-fill { height: 100%; background: var(--exp); border-radius: 0 4px 4px 0; }
.cat-row .v { font-variant-numeric: tabular-nums; text-align: right; min-width: 110px; }
.cat-row .v small { color: var(--muted); margin-left: 6px; }
.entry.exp { border-left-color: var(--exp); }
.entry.rev { border-left-color: var(--rev); }
.entry.book label { width: 170px; }
.entry.book label.grow { flex: 1 1 340px; min-width: 220px; width: auto; }
.entry.book label.filebox { width: 260px; }
.filebox .input { padding: 6px 8px; font-size: 13px; }
.files { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; }
.file { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; }
.file a { color: var(--accent); text-decoration: none; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file a:hover { text-decoration: underline; }
.tag.rev { background: #e4edf6; color: #24557f; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: #f4ead0; color: #6f500f; white-space: nowrap; }
.sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
@media (max-width: 760px) {
  .kpis { grid-template-columns: 1fr; gap: 0; }
  .kpi b { font-size: 22px; }
  .entry.book label, .entry.book label.grow, .entry.book label.filebox { width: 100%; }
  .cat-row { grid-template-columns: 1fr auto; }
  .cat-row .cat-track { grid-column: 1 / -1; order: 3; }
}

/* Hoả (Minh): chấm nhỏ trên logo — Hoả sinh Thổ */
.brand-mark::after { content: ''; position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--fire); box-shadow: 0 0 0 1.5px var(--accent); }
.brand-mark.sm::after { top: 3px; right: 3px; width: 5px; height: 5px; }
