/* Sổ Thu Chi Gia Đình — kiểu dáng. Màu chỉ để chở dữ liệu; nút & khung dùng mực trung tính. */
:root {
  color-scheme: light;
  --nen: #f4f3ef;
  --the: #ffffff;
  --the-2: #f9f8f5;
  --muc: #1b1b19;
  --muc-2: #55544f;
  --muc-3: #86857f;
  --vien: #e5e3db;
  --vien-dam: #cfcdc3;
  --luoi: #eceae3;
  --nut: #1b1b19;
  --nut-chu: #ffffff;
  --chon: #1b1b19;
  --chon-nen: #efeee9;
  /* dữ liệu */
  --thu: #2a78d6;
  --chi: #eb6834;
  --tot: #006300;
  --tot-nen: #e7f3e7;
  --canh-bao: #b77900;
  --canh-bao-thanh: #fab219;
  --nguy: #c62f2f;
  --nguy-thanh: #d03b3b;
  --nguy-nen: #fbeaea;
  --dong-ho: #2a78d6;
  --bong: 0 1px 2px rgba(20, 20, 15, 0.04), 0 2px 10px rgba(20, 20, 15, 0.04);
  --bong-cao: 0 10px 40px rgba(20, 20, 15, 0.18);
  --bo: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Segoe UI Emoji", "Apple Color Emoji", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --nen: #0f0f0e;
    --the: #1a1a19;
    --the-2: #222220;
    --muc: #f5f5f2;
    --muc-2: #c3c2b7;
    --muc-3: #8f8e87;
    --vien: #2e2e2b;
    --vien-dam: #3d3d39;
    --luoi: #2a2a28;
    --nut: #f5f5f2;
    --nut-chu: #121211;
    --chon: #f5f5f2;
    --chon-nen: #2a2a27;
    --thu: #3987e5;
    --chi: #d95926;
    --tot: #3dbb4a;
    --tot-nen: #15301a;
    --canh-bao: #f0b43a;
    --nguy: #ef7b7b;
    --nguy-nen: #3a1b1b;
    --bong: none;
    --bong-cao: 0 10px 40px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --nen: #0f0f0e; --the: #1a1a19; --the-2: #222220; --muc: #f5f5f2; --muc-2: #c3c2b7; --muc-3: #8f8e87;
  --vien: #2e2e2b; --vien-dam: #3d3d39; --luoi: #2a2a28; --nut: #f5f5f2; --nut-chu: #121211; --chon: #f5f5f2;
  --chon-nen: #2a2a27; --thu: #3987e5; --chi: #d95926; --tot: #3dbb4a; --tot-nen: #15301a; --canh-bao: #f0b43a;
  --nguy: #ef7b7b; --nguy-nen: #3a1b1b; --bong: none; --bong-cao: 0 10px 40px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--nen); color: var(--muc); font: 15px/1.45 var(--font);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
.so { font-variant-numeric: tabular-nums; }
.phu { color: var(--muc-2); }
.mo { color: var(--muc-3); }
.nho { font-size: 13px; }
.rat-nho { font-size: 12px; }
.dam { font-weight: 600; }
.thu-chu { color: var(--tot); }
.nguy-chu { color: var(--nguy); }
.canh-bao-chu { color: var(--canh-bao); }

/* ---------- khung ---------- */
.khung { min-height: 100vh; }
.thanh-tren {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--nen) 88%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
}
.thanh-tren h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nut-tron {
  width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--vien); background: var(--the);
  display: inline-grid; place-items: center; cursor: pointer; font-size: 18px; flex: none;
}
.noi-dung { padding: 4px 16px 110px; max-width: 1080px; margin: 0 auto; }

.thanh-duoi {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--the); border-top: 1px solid var(--vien); padding-bottom: env(safe-area-inset-bottom);
}
.thanh-duoi a {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; text-decoration: none;
  font-size: 11px; color: var(--muc-3);
}
.thanh-duoi a .bt { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: 0.75; }
.thanh-duoi a.dang { color: var(--muc); font-weight: 600; }
.thanh-duoi a.dang .bt { filter: none; opacity: 1; }
.thanh-duoi .ghi-giua { position: relative; }
.thanh-duoi .ghi-giua span.cong {
  width: 52px; height: 52px; margin-top: -22px; border-radius: 50%; background: var(--nut); color: var(--nut-chu);
  display: grid; place-items: center; font-size: 30px; font-weight: 300; box-shadow: var(--bong-cao);
}

.thanh-ben { display: none; }

@media (min-width: 900px) {
  .khung { display: grid; grid-template-columns: 240px 1fr; }
  .thanh-duoi { display: none; }
  .thanh-ben {
    display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; padding: 18px 12px;
    border-right: 1px solid var(--vien); background: var(--the);
  }
  .thanh-ben .ten-so { font-weight: 700; font-size: 16px; padding: 4px 10px 14px; display: flex; gap: 8px; align-items: center; }
  .thanh-ben a { padding: 9px 12px; border-radius: 10px; text-decoration: none; color: var(--muc-2); display: flex; gap: 10px; }
  .thanh-ben a:hover { background: var(--chon-nen); }
  .thanh-ben a.dang { background: var(--chon-nen); color: var(--muc); font-weight: 600; }
  .thanh-ben .nut-ghi { margin: 0 0 12px; justify-content: center; }
  .thanh-ben .cuoi { margin-top: auto; }
  .noi-dung { padding: 8px 28px 60px; }
  .thanh-tren { padding: 14px 28px; }
}

/* ---------- thẻ & lưới ---------- */
.the {
  background: var(--the); border: 1px solid var(--vien); border-radius: var(--bo); padding: 16px; box-shadow: var(--bong);
  margin-bottom: 14px; min-width: 0;
}
.the > h2, .muc-tieu-de { font-size: 15px; margin: 0 0 12px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.muc-tieu-de .phai, .the > h2 .phai { margin-left: auto; font-weight: 500; font-size: 13px; color: var(--muc-2); text-decoration: none; }
.luoi-2 { display: grid; grid-template-columns: minmax(0, 1fr); column-gap: 14px; }
.luoi-2 > * { min-width: 0; }
@media (min-width: 900px) { .luoi-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; } }
.cot-chinh { min-width: 0; }
.hang { display: flex; align-items: center; gap: 10px; }
.hang.giua { justify-content: space-between; }
.xuong-dong { flex-wrap: wrap; }
.co-gian { flex: 1; min-width: 0; }

/* ---------- số lớn ---------- */
.hero-nhan { font-size: 13px; color: var(--muc-2); }
.hero-so { font-size: 40px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; margin: 2px 0 12px; word-break: break-word; }
@media (min-width: 600px) { .hero-so { font-size: 48px; } }
.o-so { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.o-so > div { background: var(--the-2); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.o-so .nhan { font-size: 12.5px; color: var(--muc-2); display: flex; align-items: center; gap: 6px; }
.o-so .gia-tri { font-size: 19px; font-weight: 600; margin-top: 2px; word-break: break-word; }
.cham { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.cham.thu { background: var(--thu); }
.cham.chi { background: var(--chi); }

/* ---------- đồng hồ ngân sách ---------- */
.dong-ho { height: 8px; border-radius: 99px; background: color-mix(in srgb, var(--dong-ho) 18%, var(--the)); overflow: hidden; }
.dong-ho > i { display: block; height: 100%; border-radius: 99px; background: var(--dong-ho); }
.dong-ho.canh-bao { --dong-ho: var(--canh-bao-thanh); }
.dong-ho.vuot { --dong-ho: var(--nguy-thanh); }
.ngan-sach-dong { padding: 9px 0; border-top: 1px solid var(--luoi); }
.ngan-sach-dong:first-of-type { border-top: 0; padding-top: 0; }
.ngan-sach-dong .hang { margin-bottom: 6px; }

/* ---------- danh sách giao dịch ---------- */
.ds-gd { list-style: none; margin: 0; padding: 0; }
.ngay-nhom { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muc-2); padding: 14px 2px 6px; font-weight: 600; }
.gd {
  display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--luoi); cursor: pointer;
}
.ds-gd > .gd:first-child, .ngay-nhom + .gd { border-top: 0; }
.gd:hover { background: var(--the-2); }
.gd .bieu { width: 40px; height: 40px; border-radius: 12px; background: var(--the-2); display: grid; place-items: center; font-size: 20px; flex: none; }
.gd .giua { flex: 1; min-width: 0; }
.gd .ten { display: block; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gd .chi-tiet { display: block; font-size: 12.5px; color: var(--muc-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gd .tien { font-weight: 600; white-space: nowrap; text-align: right; }
.gd .tien .rat-nho { display: block; font-weight: 400; }
.khoi-so { background: var(--the); border: 1px solid var(--vien); border-radius: var(--bo); padding: 0 14px 6px; margin-bottom: 14px; }

/* ---------- nút ---------- */
.nut {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px;
  border-radius: 11px; border: 1px solid var(--vien-dam); background: var(--the); cursor: pointer; font-weight: 550;
  text-decoration: none; white-space: nowrap;
}
.nut:hover { background: var(--the-2); }
.nut.chinh { background: var(--nut); color: var(--nut-chu); border-color: var(--nut); }
.nut.chinh:hover { opacity: 0.9; }
.nut.nguy { color: var(--nguy); border-color: color-mix(in srgb, var(--nguy) 40%, var(--vien)); }
.nut.nho { min-height: 34px; padding: 0 11px; font-size: 13.5px; border-radius: 9px; }
.nut.rong { width: 100%; }
.nut.trong { border-color: transparent; background: transparent; }
.nut:disabled { opacity: 0.5; cursor: default; }

/* ---------- chọn tháng ---------- */
.chon-thang { display: inline-flex; align-items: center; gap: 2px; background: var(--the); border: 1px solid var(--vien); border-radius: 99px; padding: 2px; }
.chon-thang button { border: 0; background: transparent; width: 34px; height: 32px; border-radius: 99px; cursor: pointer; font-size: 17px; }
.chon-thang button:hover { background: var(--chon-nen); }
.chon-thang span { min-width: 96px; text-align: center; font-weight: 600; font-size: 14px; }

/* ---------- đoạn chọn (segmented) & chip ---------- */
.doan { display: flex; background: var(--chon-nen); border-radius: 11px; padding: 3px; gap: 3px; }
.doan button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 8px 6px; cursor: pointer; font-weight: 550; color: var(--muc-2); white-space: nowrap; }
.doan button.dang { background: var(--the); color: var(--muc); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1px solid var(--vien-dam); background: var(--the); border-radius: 99px; padding: 6px 12px; cursor: pointer;
  font-size: 14px; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap;
}
.chip.dang { background: var(--chon); color: var(--nen); border-color: var(--chon); }
.chips.cuon { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: -16px; padding-right: 16px; }
.chips.cuon::-webkit-scrollbar { display: none; }
.chips.cuon .chip { padding: 5px 11px; font-size: 13.5px; flex: none; }
.luoi-dm { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 7px; }
.o-dm {
  border: 1px solid var(--vien); background: var(--the); border-radius: 12px; padding: 8px 4px 7px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; line-height: 1.2; text-align: center; min-height: 68px;
}
.o-dm .bt { font-size: 22px; }
.o-dm.dang { border-color: var(--chon); box-shadow: inset 0 0 0 1.5px var(--chon); background: var(--chon-nen); font-weight: 600; }

/* ---------- form ---------- */
.truong { margin-bottom: 14px; }
.truong > label, .nhan-truong { display: block; font-size: 13px; color: var(--muc-2); margin-bottom: 6px; font-weight: 550; }
.o-nhap, select.o-nhap, textarea.o-nhap {
  width: 100%; min-height: 44px; border: 1px solid var(--vien-dam); background: var(--the); border-radius: 11px; padding: 9px 12px;
  outline: none; font-size: 16px;
}
.o-nhap:focus { border-color: var(--muc); box-shadow: 0 0 0 3px color-mix(in srgb, var(--muc) 12%, transparent); }
.o-tien { font-size: 30px; font-weight: 650; text-align: right; padding: 8px 14px; min-height: 60px; letter-spacing: -0.01em; }
.goi-y-tien { font-size: 13px; color: var(--muc-2); text-align: right; min-height: 18px; margin-top: 4px; }
.hang-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bao-loi { background: var(--nguy-nen); color: var(--nguy); border-radius: 10px; padding: 9px 12px; font-size: 14px; margin-bottom: 12px; }
.hop-kiem { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--vien); border-radius: 11px; cursor: pointer; margin-bottom: 8px; }
.hop-kiem input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--muc); }
.hop-kiem.dang { border-color: var(--muc); background: var(--chon-nen); }

/* ---------- tấm trượt (sheet) ---------- */
.man-che { position: fixed; inset: 0; background: rgba(10, 10, 8, 0.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: hien 0.15s ease; }
.tam {
  background: var(--nen); width: 100%; max-width: 560px; max-height: 94vh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(18px + env(safe-area-inset-bottom)); animation: truot 0.2s ease; overscroll-behavior: contain;
}
.tam .dau-tam { display: flex; align-items: center; gap: 8px; position: sticky; top: -8px; background: var(--nen); padding: 12px 0 10px; z-index: 2; }
.tam .dau-tam h3 { margin: 0; font-size: 17px; flex: 1; }
.tam .chan-tam { display: flex; gap: 8px; position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); background: var(--nen); padding: 10px 0 4px; margin-top: 6px; }
.tam .chan-tam .nut { flex: 1; }
@media (min-width: 700px) {
  .man-che { align-items: center; }
  .tam { border-radius: 20px; max-height: 90vh; padding-bottom: 18px; }
  .tam .chan-tam { bottom: -18px; }
}
@keyframes hien { from { opacity: 0; } }
@keyframes truot { from { transform: translateY(24px); opacity: 0.6; } }

/* ---------- thông báo nổi ---------- */
.thong-bao {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 80;
  background: var(--muc); color: var(--nen); border-radius: 12px; padding: 10px 14px; display: flex; gap: 14px; align-items: center;
  box-shadow: var(--bong-cao); max-width: calc(100vw - 24px); font-size: 14px; animation: hien 0.2s ease;
}
.thong-bao button { background: transparent; border: 0; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0; }
@media (min-width: 900px) { .thong-bao { bottom: 24px; } }

/* ---------- đăng nhập ---------- */
.man-dang-nhap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.man-dang-nhap .the { width: 100%; max-width: 400px; padding: 26px 22px; }
.logo-lon { font-size: 44px; text-align: center; }
.man-dang-nhap h1 { text-align: center; font-size: 22px; margin: 6px 0 4px; }
.man-dang-nhap .phu { text-align: center; margin: 0 0 20px; }
.o-pin { letter-spacing: 0.4em; text-align: center; font-size: 22px; }

/* ---------- biểu đồ ---------- */
.bieu-do { position: relative; width: 100%; }
.bieu-do svg { display: block; width: 100%; height: auto; overflow: visible; }
.bieu-do .truc { font-size: 11px; fill: var(--muc-3); font-variant-numeric: tabular-nums; }
.bieu-do .luoi-ngang { stroke: var(--luoi); stroke-width: 1; }
.bieu-do .day { stroke: var(--vien-dam); stroke-width: 1; }
.bieu-do .vung-cham { fill: transparent; cursor: pointer; }
.bieu-do .vung-cham:hover { fill: color-mix(in srgb, var(--muc) 5%, transparent); }
.chu-giai { display: flex; gap: 14px; font-size: 13px; color: var(--muc-2); margin-bottom: 8px; flex-wrap: wrap; }
.chu-giai span { display: inline-flex; align-items: center; gap: 6px; }
.meo {
  position: absolute; pointer-events: none; background: var(--the); border: 1px solid var(--vien); border-radius: 10px; padding: 8px 10px;
  box-shadow: var(--bong-cao); font-size: 13px; white-space: nowrap; z-index: 5; transform: translate(-50%, -100%);
}
.meo b { display: block; margin-bottom: 3px; }
.meo .hang { gap: 6px; }
.thanh-ngang { display: grid; gap: 10px; }
.thanh-ngang .dong { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; }
.thanh-ngang .ten { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.thanh-ngang .gt { font-size: 13.5px; font-weight: 600; text-align: right; white-space: nowrap; }
.thanh-ngang .ray { grid-column: 1 / -1; height: 10px; position: relative; }
.thanh-ngang .ray > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--chi); min-width: 2px; }
.thanh-ngang .ray > i.thu { background: var(--thu); }
.thanh-ngang .dong .phu-dong { grid-column: 1 / -1; font-size: 12px; color: var(--muc-3); margin-top: -1px; }
.bang-cuon { overflow-x: auto; }
table.bang { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.bang th, table.bang td { padding: 7px 8px; border-bottom: 1px solid var(--luoi); text-align: left; white-space: nowrap; }
table.bang th { font-weight: 600; color: var(--muc-2); font-size: 12.5px; }
table.bang td.so, table.bang th.so { text-align: right; }

/* ---------- mục menu Thêm ---------- */
.menu { display: grid; gap: 0; }
.menu a, .menu button.dong-menu {
  display: flex; align-items: center; gap: 12px; padding: 13px 4px; border: 0; border-top: 1px solid var(--luoi); background: none;
  text-decoration: none; text-align: left; cursor: pointer; width: 100%;
}
.menu > :first-child { border-top: 0; }
.menu .bt { width: 36px; height: 36px; border-radius: 10px; background: var(--the-2); display: grid; place-items: center; font-size: 19px; flex: none; }
.menu .mui { margin-left: auto; color: var(--muc-3); }

.the-vi { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--luoi); }
.the-vi:first-of-type { border-top: 0; }
.nhan-nho { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 99px; background: var(--chon-nen); color: var(--muc-2); font-weight: 550; }
.nhan-nho.nguy { background: var(--nguy-nen); color: var(--nguy); }
.nhan-nho.tot { background: var(--tot-nen); color: var(--tot); }
.trong-rong { text-align: center; padding: 26px 10px; color: var(--muc-2); }
.trong-rong .bt { font-size: 34px; display: block; margin-bottom: 6px; }
.loc { display: grid; gap: 8px; margin-bottom: 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.loc .doan, .loc input[type="search"] { grid-column: 1 / -1; }
.loc select { min-height: 38px; font-size: 13.5px; padding: 6px 8px; }
.loc input { min-height: 40px; font-size: 15px; }
.loc select:only-of-type { grid-column: span 3; }
@media (min-width: 700px) { .loc { grid-template-columns: 2fr 1fr 1fr 1fr; } .loc input[type="search"] { grid-column: auto; } }
.dang-tai { padding: 40px; text-align: center; color: var(--muc-3); }
.chon-bt { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 4px; }
.chon-bt button { border: 1px solid transparent; background: var(--the-2); border-radius: 9px; font-size: 20px; height: 40px; cursor: pointer; }
.chon-bt button.dang { border-color: var(--muc); }
.ban-giao { background: var(--the-2); border: 1px dashed var(--vien-dam); border-radius: 12px; padding: 12px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }

@media print {
  .thanh-duoi, .thanh-ben, .thanh-tren .nut-tron { display: none !important; }
  body { background: #fff; }
}
