/* ============================================================
   Theme "Dòng Tiền" — fintech sáng, hiện đại
   (áp dụng từ bản thiết kế Claude Design)
   ============================================================ */
:root {
  --bg: #EEF1F6;
  --panel: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --muted2: #98A2B3;
  --line: #EAECF0;
  --line2: #E6E9F0;
  --tile: #F8FAFC;
  --brand: #1B59E3;
  --brand2: #3B82F6;
  --brand-soft: #EAF0FE;
  --green: #15A36E;
  --green2: #22C55E;
  --red: #E5484D;
  --red2: #F87171;
  --shadow: 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 6px 16px rgba(27,89,227,.25);
  --radius: 16px;
  --radius-lg: 18px;
  --radius-sm: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px;
  -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cfd6e4; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.num { text-align: right; }
button { cursor: pointer; font-family: inherit; }
input, select, button { font-size: 14px; font-family: inherit; }
input, select {
  padding: 8px 11px; border: 1px solid var(--line2); border-radius: var(--radius-sm);
  background: #fff; color: var(--ink);
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(27,89,227,.12); }

/* ---------- Login ---------- */
.login-screen { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); }
.login-box {
  background: var(--panel); padding: 34px; border-radius: var(--radius-lg);
  box-shadow: var(--shadow); width: 330px; text-align: center; border: 1px solid var(--line);
}
.login-box h1 { margin: 0 0 4px; font-size: 22px; }
.login-box input { width: 100%; margin: 14px 0; }
.login-box button {
  width: 100%; padding: 11px; background: linear-gradient(135deg,var(--brand),var(--brand2));
  color: #fff; border: none; border-radius: var(--radius-sm); font-weight: 700;
}
.error-msg { color: var(--red); margin-top: 8px; min-height: 18px; }
.success-msg { color: var(--green); margin-top: 8px; }

/* ---------- App layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: #fff; border-right: 1px solid var(--line2);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 22px 22px 16px; font-weight: 800; font-size: 15.5px; letter-spacing: -0.2px; color: var(--ink);
}
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  background: linear-gradient(135deg,var(--brand),var(--brand2));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 17px;
}
.nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; overflow-y: auto; flex: 1; }
.nav-item {
  background: transparent; border: none; text-align: left;
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 600; color: #475467;
}
.nav-item:hover { background: #F1F4FA; }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--bg); }
.sidebar-foot .nav-item {
  justify-content: center; background: #F1F4FA; color: #344054; font-weight: 600; font-size: 13px;
}
.sidebar-foot .nav-item:hover { background: #E7ECF6; }

.content { overflow-y: auto; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 28px; background: rgba(238,241,246,0.85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line2);
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar h2 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.3px; }
#view-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.nav-toggle { display: none; background: #fff; border: 1px solid var(--line2); border-radius: 10px; padding: 6px 11px; font-size: 16px; line-height: 1; color: var(--ink); }
.period-pills { display: flex; align-items: center; gap: 4px; background: #fff; border: 1px solid var(--line2); border-radius: 12px; padding: 4px; }
.period-pills button {
  border: none; background: transparent; padding: 6px 12px; border-radius: 9px;
  font-size: 12.5px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.period-pills button.active { background: var(--brand); color: #fff; font-weight: 700; }

.view-wrap { padding: 24px 28px 64px; }
.view { display: none; }
.view.active { display: block; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.panel h3 { margin: 0 0 14px; font-size: 15px; font-weight: 700; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-cashflow { grid-template-columns: 1.6fr 1fr; }
/* ===== Tablet & mobile ===== */
@media (max-width: 980px) {
  .grid-2, .grid-cashflow { grid-template-columns: 1fr; }
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .app.nav-open .sidebar {
    display: flex; position: fixed; top: 0; left: 0; z-index: 40;
    width: 248px; height: 100vh; box-shadow: 0 10px 40px rgba(16,24,40,.28);
  }
  .app.nav-open::after {
    content: ""; position: fixed; inset: 0; z-index: 39; background: rgba(16,24,40,.35);
  }
  .nav-toggle { display: block; }
  .view-wrap { padding: 16px 14px 48px; }
  .topbar { flex-wrap: wrap; padding: 14px 16px; gap: 10px; }
  .period-pills { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  /* form/filter: cho input & select tu gian, khong bi cat */
  .toolbar input, .toolbar select { flex: 1 1 140px; min-width: 0; }
  .toolbar input[type="search"] { flex-basis: 100%; }
  .row input, .row select { flex: 1 1 140px; min-width: 0; }
  .panel { padding: 16px; }
}

/* ===== Mobile nho ===== */
@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card .value { font-size: 18px; }
  .card.featured { grid-column: 1 / -1; }
  .view-wrap { padding: 14px 12px 48px; }
  .topbar h2 { font-size: 17px; }
  .panel { padding: 14px; border-radius: 14px; }
  /* Bang giao dich chinh: an cot it quan trong tren man hinh rat hep */
  .tx-main th:nth-child(1), .tx-main td:nth-child(1),
  .tx-main th:nth-child(4), .tx-main td:nth-child(4) { display: none; }
  .txn-table th, .txn-table td { padding: 9px 10px; }
  .donut-wrap { flex-direction: column; align-items: flex-start; }
  .bd-chips { padding-left: 0; }
  .modal-box { padding: 18px; }
}

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.row label { font-size: 13px; color: var(--muted); }

/* ---------- KPI cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card .label { color: var(--muted); font-size: 12px; font-weight: 600; }
.card .value { font-size: 21px; font-weight: 800; margin-top: 7px; letter-spacing: -0.4px; }
.card .value.pos { color: var(--green); }
.card .value.neg { color: var(--red); }
.card .value.brand { color: var(--brand); }
.card.featured {
  background: linear-gradient(135deg,var(--brand),var(--brand2));
  border: none; box-shadow: var(--shadow-lg);
}
.card.featured .label { color: #DCE7FF; }
.card.featured .value { color: #fff; }

/* ---------- Buttons ---------- */
.btn { background: linear-gradient(135deg,var(--brand),var(--brand2)); color: #fff; border: none; padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 700; }
.btn-sm { background: #F1F4FA; color: #344054; border: 1px solid var(--line2); padding: 7px 12px; border-radius: var(--radius-sm); font-weight: 600; }
.btn-sm:hover { background: #E7ECF6; }
.btn-danger { background: #FEF3F2; color: var(--red); border: 1px solid #FECDCA; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1; min-width: 180px; }
.bulkbar {
  display: flex; gap: 8px; align-items: center; background: var(--brand-soft);
  padding: 9px 12px; border-radius: var(--radius-sm); margin-bottom: 10px; font-size: 13px; color: #344054;
}
.txn-summary { display: flex; gap: 18px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.txn-summary b.pos { color: var(--green); }
.txn-summary b.neg { color: var(--red); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
table.txn-table { width: 100%; border-collapse: collapse; }
.txn-table th, .txn-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); }
.txn-table th { font-size: 11.5px; color: var(--muted2); font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.txn-table tr:last-child td { border-bottom: none; }
.txn-table tr:hover { background: var(--tile); }
.txn-table td.num, .txn-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.amt-pos { color: var(--green); font-weight: 700; }
.amt-neg { color: var(--red); font-weight: 700; }
.row-excluded { opacity: .5; }
.cat-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--tile);
  border: 1px solid var(--line); cursor: pointer; color: #475467;
}
.cat-pill::before { content: ""; width: 8px; height: 8px; border-radius: 3px; background: var(--dot, #CBD5E1); }
.cat-pill.none { color: var(--muted2); border-style: dashed; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: #EEF1F6; color: var(--muted); margin-left: 6px; font-weight: 600; }

.pager { text-align: center; margin: 16px 0; }

/* ---------- Import mapping ---------- */
.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin-bottom: 12px; }
.map-grid label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.map-grid select { width: 100%; }

/* ---------- Category tree ---------- */
.cat-l1 { font-weight: 700; margin-top: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.cat-l2 { margin-left: 20px; padding: 5px 0; display: flex; align-items: center; gap: 8px; color: #475467; }
.swatch { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
/* Nut thao tac tren tung dong: vung cham du lon, cach nhau de tranh bam nham. */
.del-x, .edit-x, .rule-x, .split-x {
  cursor: pointer; background: none; border: none; font-size: 15px;
  padding: 6px 8px; border-radius: 8px; line-height: 1; margin: 0 1px;
}
.edit-x { color: var(--brand); }
.rule-x { color: var(--brand2); }
.split-x { color: var(--muted); }
.edit-x:hover, .rule-x:hover, .split-x:hover { background: var(--soft, rgba(16,24,40,.06)); }
/* Xoa: lam mo di mac dinh, chi do len khi di chuot vao -> kho bam nham. */
.del-x { color: var(--muted); opacity: .65; }
.del-x:hover { color: var(--red); opacity: 1; background: rgba(240, 68, 56, .1); }
/* Nut xoa trong hop thoai: tach han sang trai, vien do nhe, ro chu dich. */
.btn-danger {
  margin-right: auto; cursor: pointer; font-size: 14px; padding: 8px 14px;
  border-radius: 10px; border: 1px solid rgba(240, 68, 56, .4);
  background: #fff; color: var(--red);
}
.btn-danger:hover { background: rgba(240, 68, 56, .1); }

/* ---------- Dashboard: biểu đồ tự vẽ ---------- */
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.barchart { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; height: 200px; }
.barchart .bcol { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.barchart .bpair { display: flex; align-items: flex-end; gap: 5px; height: 100%; width: 100%; justify-content: center; }
.barchart .bar { width: 42%; max-width: 26px; border-radius: 6px 6px 2px 2px; min-height: 2px; }
.barchart .bar.inc { background: linear-gradient(180deg,var(--green2),var(--green)); }
.barchart .bar.exp { background: linear-gradient(180deg,var(--red2),var(--red)); }
.barchart .blabel { font-size: 12px; color: var(--muted2); font-weight: 600; }

.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { width: 120px; height: 120px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.donut .hole { width: 72px; height: 72px; border-radius: 50%; background: #fff; }
.donut-legend { flex: 1; display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.donut-legend .lg { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.donut-legend .lg i { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.donut-legend .lg .nm { flex: 1; color: #475467; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.donut-legend .lg .pc { color: var(--muted2); font-weight: 700; }

/* ---------- Breakdown cấp 1 → cấp 2 ---------- */
.bd-group { margin-bottom: 18px; }
.bd-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.bd-head .dot { width: 11px; height: 11px; border-radius: 4px; }
.bd-head .nm { font-weight: 700; font-size: 14px; }
.bd-head .ct { font-size: 12px; color: var(--muted2); }
.bd-head .amt { margin-left: auto; font-weight: 800; font-size: 14px; }
.bd-head .pct { font-size: 12px; color: var(--muted2); font-weight: 700; width: 38px; text-align: right; }
.bd-bar { height: 8px; border-radius: 6px; background: #F1F4FA; overflow: hidden; margin-bottom: 10px; }
.bd-bar > span { display: block; height: 100%; border-radius: 6px; }
.bd-chips { display: flex; flex-wrap: wrap; gap: 8px; padding-left: 21px; }
.bd-chip { display: flex; align-items: center; gap: 8px; background: var(--tile); border: 1px solid #EEF1F6; border-radius: var(--radius-sm); padding: 7px 11px; font-size: 12.5px; }
.bd-chip .nm { color: #475467; font-weight: 600; }
.bd-chip .ct { color: var(--muted2); }
.bd-chip .amt { font-weight: 700; color: var(--ink); }

/* ---------- Empty state ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 80px 20px; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius-lg); color: var(--muted);
}
.empty .ico { font-size: 40px; margin-bottom: 10px; }
.empty .ttl { font-weight: 700; color: var(--ink); font-size: 16px; }

/* ---------- Progress (goals/debts) ---------- */
.prog { height: 10px; background: #F1F4FA; border-radius: 6px; overflow: hidden; margin: 6px 0; }
.prog > span { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
.item-row { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.item-row:last-child { border-bottom: none; }
.item-row .meta { color: var(--muted); font-size: 12px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(16,24,40,.5); display: grid; place-items: center; z-index: 50; }
.modal-box { background: #fff; border-radius: var(--radius-lg); padding: 24px; width: min(440px, 92vw); box-shadow: 0 20px 48px rgba(16,24,40,.2); }
.modal-box h3 { margin-top: 0; }
.modal-box .row { margin-bottom: 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* ---------- Chips chọn nhanh trong form ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 10px; }
.chips .qchip { padding: 5px 11px; font-size: 12px; font-weight: 600; }

/* ---------- Nút "+" nổi (FAB) ---------- */
.fab {
  position: fixed; right: 18px; bottom: 24px; z-index: 50;
  width: 54px; height: 54px; border-radius: 50%; border: none; color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand2));
  font-size: 30px; font-weight: 300; line-height: 1;
  box-shadow: 0 8px 20px rgba(27,89,227,.4);
}
.fab:active { transform: scale(.94); }
@media (max-width: 980px) { .fab { bottom: 80px; } } /* nam tren bottom-nav */

/* ---------- Bottom nav (mobile, cuộn ngang) ---------- */
.bottom-nav { display: none; }
@media (max-width: 980px) {
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 35;
    background: #fff; border-top: 1px solid var(--line2);
    overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 2px; padding: 6px 6px;
    box-shadow: 0 -2px 10px rgba(16,24,40,.06);
  }
  .bottom-nav::-webkit-scrollbar { height: 0; }
  .bn-item {
    flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 2px;
    border: none; background: transparent; color: var(--muted); font-size: 11px; font-weight: 600;
    padding: 5px 11px; border-radius: 12px; white-space: nowrap;
  }
  .bn-item .bn-ico { font-size: 19px; line-height: 1; }
  .bn-item.active { color: var(--brand); background: var(--brand-soft); }
  .view-wrap { padding-bottom: 86px; } /* chua bottom-nav che noi dung */
}

/* ---------- Thanh chọn nhanh số tiền ---------- */
.quick-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px;
  background: #fff; border-top: 1px solid var(--line2);
  box-shadow: 0 -4px 14px rgba(16,24,40,.12);
}
.quick-bar::-webkit-scrollbar { height: 0; }
.qchip {
  flex: 0 0 auto; border: 1px solid var(--line2); background: var(--tile); color: var(--ink);
  border-radius: 999px; padding: 9px 14px; font-size: 13px; font-weight: 700; white-space: nowrap;
}
.qchip:active { transform: scale(.96); }
.qchip.alt { background: var(--brand-soft); color: var(--brand); border-color: #c7d2fe; }
.qchip.lbl { background: transparent; border: none; color: var(--muted); font-weight: 600; padding-left: 2px; padding-right: 2px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: var(--radius-sm);
  box-shadow: 0 10px 24px rgba(16,24,40,.25); z-index: 60; font-weight: 600;
}
