/* ═══════════════════════════════════════════════════════════════════════════
   /tindung — HỆ THỐNG GIAO DIỆN "dark-first fintech"
   Mobile-first: layout 1 cột + thanh tab dưới cùng; ≥900px chuyển sang sidebar.
   Dark là mặc định; light là bộ giá trị ĐƯỢC CHỌN RIÊNG (không đảo màu máy móc).
   Màu series (thẻ) lấy từ bảng categorical đã kiểm định an toàn cho người mù màu.
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: dark;

  /* Mặt phẳng & bề mặt */
  --plane:      #0a0b0e;
  --surface:    #14161c;
  --surface-2:  #1b1e26;
  --surface-3:  #23262f;
  --border:     rgba(255, 255, 255, .09);
  --border-2:   rgba(255, 255, 255, .16);

  /* Mực chữ */
  --ink:        #f2f3f7;
  --ink-2:      #a9adbb;
  --ink-3:      #71768a;

  /* Biểu đồ */
  --grid:       #22242c;
  --axis:       #33363f;

  /* Trạng thái — CỐ ĐỊNH, không đổi theo theme, luôn đi kèm icon + nhãn chữ */
  --good:       #0ca30c;
  --warning:    #fab219;
  --serious:    #ec835a;
  --critical:   #d03b3b;

  /* Series (thẻ) — bước cho bề mặt tối */
  --s1: #3987e5;  --s2: #d95926;  --s3: #199e70;  --s4: #c98500;
  --s5: #d55181;  --s6: #008300;  --s7: #9085e9;  --s8: #e66767;

  --accent:     #3987e5;
  --accent-ink: #ffffff;

  /* Cặp màu gradient của logo / nút FAB / nút thêm — đổi theo tông. */
  --brand-1:    #3987e5;
  --brand-2:    #9085e9;

  --radius:     16px;
  --radius-sm:  11px;
  --shadow:     0 1px 2px rgba(0,0,0,.4), 0 8px 24px -8px rgba(0,0,0,.5);
  --nav-h:      64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

/* ── TÔNG SÁNG ─────────────────────────────────────────────────────────── */
:root[data-theme="light"] {
  color-scheme: light;
  --plane:      #f4f5f8;
  --surface:    #ffffff;
  --surface-2:  #f6f7f9;
  --surface-3:  #eceef2;
  --border:     rgba(11, 11, 11, .10);
  --border-2:   rgba(11, 11, 11, .18);
  --ink:        #0d0f14;
  --ink-2:      #4d525f;
  --ink-3:      #7d838f;
  --grid:       #e6e8ed;
  --axis:       #c9ccd4;
  --s1: #2a78d6;  --s2: #eb6834;  --s3: #1baf7a;  --s4: #eda100;
  --s5: #e87ba4;  --s6: #008300;  --s7: #4a3aa7;  --s8: #e34948;
  --accent:     #2a78d6;
  --brand-1:    #2a78d6;
  --brand-2:    #4a3aa7;
  --shadow:     0 1px 2px rgba(11,11,11,.06), 0 8px 20px -10px rgba(11,11,11,.14);
}

/* ── TÔNG BẠC ──────────────────────────────────────────────────────────────
   Xám lạnh ánh kim, tương phản dịu hơn tông Sáng — dễ chịu khi nhìn lâu.
   Bộ màu series dùng lại bản "light" đã kiểm định trên nền #f1f3f6. */
:root[data-theme="silver"] {
  color-scheme: light;
  --plane:      #dde2e9;
  --surface:    #f1f3f6;
  --surface-2:  #e7ebf1;
  --surface-3:  #d9dfe7;
  --border:     rgba(20, 28, 40, .13);
  --border-2:   rgba(20, 28, 40, .23);
  --ink:        #161c25;
  --ink-2:      #465060;
  --ink-3:      #78828f;
  --grid:       #dee4eb;
  --axis:       #bac2cd;
  --s1: #2a78d6;  --s2: #eb6834;  --s3: #1baf7a;  --s4: #eda100;
  --s5: #e87ba4;  --s6: #008300;  --s7: #4a3aa7;  --s8: #e34948;
  --accent:     #41607f;                  /* xanh thép */
  --accent-ink: #ffffff;
  --brand-1:    #5c7c9d;
  --brand-2:    #3b5470;
  --shadow:     0 1px 2px rgba(20,28,40,.07), 0 8px 22px -12px rgba(20,28,40,.30);
}

/* ── TÔNG ĐỎ SEN TRẮNG ─────────────────────────────────────────────────────
   Nền trắng, điểm nhấn đỏ sen. Màu TRẠNG THÁI giữ nguyên (good/warning/
   serious/critical) và luôn đi kèm icon + nhãn chữ, nên không lẫn với đỏ sen
   của giao diện. */
:root[data-theme="lotus"] {
  color-scheme: light;
  --plane:      #fdf3f6;
  --surface:    #ffffff;
  --surface-2:  #fdf0f4;
  --surface-3:  #f8e3ea;
  --border:     rgba(122, 20, 55, .13);
  --border-2:   rgba(122, 20, 55, .24);
  --ink:        #23101a;
  --ink-2:      #5b414c;
  --ink-3:      #8d7079;
  --grid:       #f3e3e9;
  --axis:       #dcc3cd;
  --s1: #2a78d6;  --s2: #eb6834;  --s3: #1baf7a;  --s4: #eda100;
  --s5: #e87ba4;  --s6: #008300;  --s7: #4a3aa7;  --s8: #e34948;
  --accent:     #c2185b;                  /* đỏ sen */
  --accent-ink: #ffffff;
  --brand-1:    #e0518a;
  --brand-2:    #c2185b;
  --shadow:     0 1px 2px rgba(122,20,55,.07), 0 8px 22px -12px rgba(122,20,55,.26);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 8px);
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* ─────────────────────────── THANH TRÊN ─────────────────────────── */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar .brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 16px; letter-spacing: -.02em; color: var(--ink);
}
.topbar .brand:hover { text-decoration: none; }
.topbar .brand .logo {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  display: grid; place-items: center; font-size: 14px;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: #fff; box-shadow: 0 2px 8px -2px var(--brand-1);
}
.topbar .sp { flex: 1; }

.iconbtn {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  border-radius: 11px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2);
  font-size: 16px; cursor: pointer; position: relative;
  transition: background .15s, color .15s, border-color .15s;
}
.iconbtn:hover { background: var(--surface-3); color: var(--ink); border-color: var(--border-2); }
.iconbtn .dot {
  position: absolute; top: -3px; right: -3px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--critical); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 17px; text-align: center;
  border: 2px solid var(--plane);
}

/* ─────────────────────────── KHUNG TRANG ─────────────────────────── */

.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; min-width: 0; }
.wrap > * + * { margin-top: 16px; }

.page-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.page-title .sub { color: var(--ink-3); font-size: 13px; }

/* ─────────────────────────── THẺ (CARD) NỀN ─────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  margin: -2px 0 14px; flex-wrap: wrap;      /* điện thoại: tiêu đề dài xuống dòng */
}
.panel-head h2 { flex: 1 1 auto; min-width: 0; }
.panel-head .act { display: flex; gap: 6px; align-items: center; }

.muted { color: var(--ink-3); }
.dim { color: var(--ink-2); }
.tnum { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* ─────────────────────────── KPI ─────────────────────────── */

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px 14px;
  display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.kpi .k-label {
  font-size: 11.5px; color: var(--ink-3); text-transform: uppercase;
  letter-spacing: .06em; font-weight: 600;
  display: flex; align-items: center; gap: 5px;
}
.kpi .k-value {
  font-size: 23px; font-weight: 680; letter-spacing: -.02em; line-height: 1.15;
  overflow-wrap: anywhere;              /* số rất dài xuống dòng, không đẩy khung */
}
.kpi .k-value small { font-size: 13px; font-weight: 500; color: var(--ink-3); }
.kpi .k-note { font-size: 12px; color: var(--ink-3); }
.kpi.accent { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

/* ─────────────────────── HÌNH ẢNH THẺ TÍN DỤNG ─────────────────────── */

.card-rail {
  display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory;
  padding: 2px 16px 6px; margin: 0 -16px;
  scrollbar-width: none;
}
.card-rail::-webkit-scrollbar { display: none; }

.ccard {
  flex: none; width: min(310px, 82vw); scroll-snap-align: start;
  border-radius: 18px; padding: 15px 16px 14px;
  position: relative; overflow: hidden; isolation: isolate;
  color: #fff; text-decoration: none;
  border: 1px solid rgba(255, 255, 255, .14);
  background:
    radial-gradient(120% 120% at 88% 8%, rgba(255,255,255,.22), transparent 55%),
    linear-gradient(150deg, var(--c) 0%, color-mix(in srgb, var(--c) 55%, #05070c) 100%);
  box-shadow: 0 10px 30px -14px var(--c), 0 1px 2px rgba(0,0,0,.35);
  display: flex; flex-direction: column; gap: 12px;
  min-height: 172px;
}
.ccard:hover { text-decoration: none; filter: brightness(1.06); }
.ccard::after {                       /* vân chìm kiểu thẻ vật lý */
  content: ""; position: absolute; inset: -40% -10% auto auto;
  width: 220px; height: 220px; border-radius: 50%;
  background: rgba(255, 255, 255, .07); z-index: -1;
}
.ccard .cc-top { display: flex; align-items: flex-start; gap: 8px; }
.ccard .cc-bank { font-size: 12.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; opacity: .95; }
.ccard .cc-name { font-size: 11.5px; opacity: .78; margin-top: 1px; }
.ccard .cc-chip {
  margin-left: auto; font-size: 10.5px; font-weight: 700;
  background: rgba(0,0,0,.28); border: 1px solid rgba(255,255,255,.22);
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}
.ccard .cc-main { margin-top: auto; }
.ccard .cc-lab { font-size: 11px; opacity: .8; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.ccard .cc-amt { font-size: 25px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.ccard .cc-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.ccard .cc-sub { font-size: 12px; opacity: .88; }
.ccard .cc-sub b { font-weight: 700; }
.ccard .bar { background: rgba(0,0,0,.3); }
.ccard .bar > i { background: rgba(255,255,255,.9); }
.ccard .cc-flags { display: flex; gap: 5px; flex-wrap: wrap; }
.ccard .cc-flag {
  font-size: 10.5px; font-weight: 650; padding: 2px 7px; border-radius: 999px;
  background: rgba(0,0,0,.3); border: 1px solid rgba(255,255,255,.2);
  display: inline-flex; align-items: center; gap: 4px;
}

/* ─────────────────────────── THANH TIẾN ĐỘ ─────────────────────────── */

.bar {
  height: 6px; border-radius: 999px; background: var(--surface-3);
  overflow: hidden; width: 100%;
}
.bar > i {
  display: block; height: 100%; border-radius: 999px;
  background: var(--accent); transition: width .35s ease;
}
.bar.tall { height: 9px; }

.meter { display: flex; flex-direction: column; gap: 6px; }
.meter .m-head {
  display: flex; align-items: baseline; gap: 8px; font-size: 13px;
}
.meter .m-head .m-name { font-weight: 600; }
.meter .m-head .m-val {
  margin-left: auto; color: var(--ink-2); font-variant-numeric: tabular-nums;
  white-space: nowrap; font-size: 12px;
}
.meter .m-head .m-name { min-width: 0; overflow-wrap: anywhere; }
.meter .m-note { font-size: 12px; color: var(--ink-3); }
.meter.good  > .bar > i { background: var(--good); }
.meter.warn  > .bar > i { background: var(--warning); }
.meter.crit  > .bar > i { background: var(--critical); }

/* ─────────────────────────── CẢNH BÁO ─────────────────────────── */

.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 11px 13px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--lv, var(--ink-3));
  color: inherit; text-decoration: none;
}
.alert:hover { text-decoration: none; background: var(--surface-2); }
.alert > .ic { color: var(--lv); font-size: 16px; line-height: 1.35; flex: none; }
.alert .a-body { min-width: 0; flex: 1; }
.alert .a-title { font-weight: 650; font-size: 13.5px; display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }
.alert .a-text { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; overflow-wrap: anywhere; }
.alert .tag {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 1px 6px; border-radius: 5px; color: var(--lv);
  border: 1px solid color-mix(in srgb, var(--lv) 45%, transparent);
  background: color-mix(in srgb, var(--lv) 12%, transparent);
}
.lv-critical { --lv: var(--critical); }
.lv-serious  { --lv: var(--serious); }
.lv-warning  { --lv: var(--warning); }
.lv-good     { --lv: var(--good); }
.lv-info     { --lv: var(--s1); }

/* ─────────────────────────── DANH SÁCH GIAO DỊCH ─────────────────────────── */

.txns { display: flex; flex-direction: column; }
.txn {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 2px; border-bottom: 1px solid var(--border);
  color: inherit; text-decoration: none;
}
.txn:last-child { border-bottom: 0; }
.txn:hover { text-decoration: none; }
.txn .t-ic {
  width: 36px; height: 36px; flex: none; border-radius: 11px;
  display: grid; place-items: center; font-size: 15px;
  background: color-mix(in srgb, var(--c, var(--s1)) 16%, var(--surface-2));
  color: var(--c, var(--s1));
  border: 1px solid color-mix(in srgb, var(--c, var(--s1)) 30%, transparent);
}
.txn .t-mid { flex: 1; min-width: 0; }
.txn .t-name {
  font-weight: 600; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.txn .t-meta {
  font-size: 12px; color: var(--ink-3); display: flex; gap: 6px;
  align-items: center; margin-top: 1px;
  /* Giữ MỘT dòng và cắt bớt: danh sách trên điện thoại đều tăm tắp,
     không bị so le vì vài dòng có thêm nhãn "Online". */
  flex-wrap: nowrap; overflow: hidden; white-space: nowrap;
}
.txn .t-meta > * { flex: none; }
.txn .t-right { text-align: right; flex: none; }
.txn .t-amt { font-weight: 650; font-variant-numeric: tabular-nums; font-size: 14.5px; }
.txn .t-amt.neg { color: var(--good); }
.txn .t-cb { font-size: 11.5px; color: var(--good); font-variant-numeric: tabular-nums; }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 1.5px 7px;
  border-radius: 999px; border: 1px solid var(--border-2);
  color: var(--ink-2); background: var(--surface-2); white-space: nowrap;
}
.pill.card { border-color: color-mix(in srgb, var(--c) 45%, transparent);
             color: var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); }
.pill.on  { color: var(--s1); border-color: color-mix(in srgb, var(--s1) 40%, transparent); }
.pill.off { color: var(--ink-2); }

/* ─────────────────────────── FORM ─────────────────────────── */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 13px; }
.field > label { font-size: 12.5px; font-weight: 620; color: var(--ink-2); }
.field .hint { font-size: 11.5px; color: var(--ink-3); }

input[type=text], input[type=number], input[type=date], input[type=password],
input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--border-2);
  border-radius: var(--radius-sm); padding: 11px 12px;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
                    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
  padding-right: 32px;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
textarea { min-height: 72px; resize: vertical; }

.money-input { position: relative; }
.money-input input {
  font-size: 27px; font-weight: 680; letter-spacing: -.02em;
  padding: 14px 46px 14px 14px; text-align: right;
  font-variant-numeric: tabular-nums;
}
.money-input .cur {
  position: absolute; right: 15px; top: 50%; transform: translateY(-50%);
  color: var(--ink-3); font-size: 15px; font-weight: 600; pointer-events: none;
}

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  font-size: 12.5px; font-weight: 600; padding: 7px 12px;
  border-radius: 999px; border: 1px solid var(--border-2);
  background: var(--surface-2); color: var(--ink-2); cursor: pointer;
  transition: all .13s; user-select: none; white-space: nowrap;
}
.chip:hover { border-color: var(--ink-3); color: var(--ink); }
.chip[aria-pressed="true"], .chip.on {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
  border-color: var(--accent); color: var(--ink);
}
.chip.cardchip[aria-pressed="true"] {
  background: color-mix(in srgb, var(--c) 20%, var(--surface));
  border-color: var(--c); color: var(--ink);
}
.chip .sw {
  display: inline-block; width: 9px; height: 9px; border-radius: 3px;
  background: var(--c); margin-right: 6px; vertical-align: -1px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 650; font-size: 14.5px;
  padding: 12px 18px; border-radius: 12px; cursor: pointer;
  border: 1px solid transparent; background: var(--accent); color: var(--accent-ink);
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--surface-2); color: var(--ink); border-color: var(--border-2); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.danger { background: var(--critical); color: #fff; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }

/* ─────────────────────────── GỢI Ý THẺ NÊN QUẸT ─────────────────────────── */

.suggest { display: flex; flex-direction: column; gap: 7px; }
.sug {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2);
}
.sug.best {
  border-color: var(--good);
  background: color-mix(in srgb, var(--good) 10%, var(--surface));
}
.sug .s-rank {
  width: 24px; height: 24px; flex: none; border-radius: 8px;
  display: grid; place-items: center; font-size: 11.5px; font-weight: 700;
  background: var(--surface-3); color: var(--ink-2);
}
.sug.best .s-rank { background: var(--good); color: #fff; }
.sug .s-mid { flex: 1; min-width: 0; }
.sug .s-card { font-weight: 650; font-size: 13.5px; display: flex; align-items: center; gap: 6px; }
.sug .s-rule { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }
.sug .s-cb { text-align: right; flex: none; }
.sug .s-cb b { font-size: 15px; font-variant-numeric: tabular-nums; color: var(--good); }
.sug .s-cb span { display: block; font-size: 10.5px; color: var(--ink-3); }
.sug.zero .s-cb b { color: var(--ink-3); }

/* ─────────────────────────── BIỂU ĐỒ ─────────────────────────── */

.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 320px; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.legend .lg { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.legend .lg i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; }

/* Biểu đồ ngang tự dựng bằng CSS — dùng cho "chi tiêu theo danh mục" */
.hbars { display: flex; flex-direction: column; gap: 9px; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px 10px; align-items: center; }
.hbar .hb-name { font-size: 13px; display: flex; align-items: center; gap: 7px; min-width: 0; }
.hbar .hb-name i { color: var(--ink-3); font-size: 14px; flex: none; }
.hbar .hb-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .hb-val { font-size: 13px; font-weight: 620; font-variant-numeric: tabular-nums; }
.hbar .hb-track { grid-column: 1 / -1; height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.hbar .hb-track > i { display: block; height: 100%; border-radius: 999px; background: var(--seq, var(--s1)); }

/* Bảng số liệu kèm biểu đồ (bắt buộc để đọc được khi màu không phân biệt nổi) */
details.tableview { margin-top: 12px; }
details.tableview > summary {
  cursor: pointer; font-size: 12.5px; color: var(--ink-2);
  padding: 5px 0; list-style: none; display: flex; align-items: center; gap: 6px;
}
details.tableview > summary::-webkit-details-marker { display: none; }
details.tableview > summary::before { content: "▸"; color: var(--ink-3); }
details.tableview[open] > summary::before { content: "▾"; }

.tblwrap { overflow-x: auto; margin-top: 8px; }
table.data {
  width: 100%; border-collapse: collapse; font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
table.data th, table.data td {
  padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th {
  color: var(--ink-3); font-weight: 620; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em;
  position: sticky; top: 0; background: var(--surface);
}
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td { font-weight: 700; border-top: 1px solid var(--border-2); border-bottom: 0; }

/* ─────────────────────────── THANH TAB DƯỚI ─────────────────────────── */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; height: var(--nav-h); font-size: 10.5px; font-weight: 600;
  color: var(--ink-3); text-decoration: none; position: relative;
}
.tabbar a i { font-size: 20px; line-height: 1; }
.tabbar a[aria-current="page"] { color: var(--accent); }
.tabbar a.fab-slot { color: var(--ink-3); }
.tabbar .fab {
  width: 46px; height: 46px; border-radius: 15px; margin-top: -14px;
  display: grid; place-items: center; font-size: 22px;
  background: linear-gradient(140deg, var(--brand-1), var(--brand-2));
  color: #fff; box-shadow: 0 8px 20px -6px var(--brand-1);
  border: 1px solid rgba(255,255,255,.2);
}

/* ─────────────────────────── ĐĂNG NHẬP ─────────────────────────── */

.lockscreen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(70% 55% at 18% 0%, color-mix(in srgb, var(--brand-1) 22%, transparent), transparent 70%),
    radial-gradient(65% 50% at 88% 12%, color-mix(in srgb, var(--brand-2) 20%, transparent), transparent 70%),
    var(--plane);
}
.lockbox {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 28px 24px;
  box-shadow: 0 24px 60px -20px rgba(0,0,0,.6);
}
.lockbox .lb-logo {
  width: 52px; height: 52px; border-radius: 15px; margin: 0 auto 16px;
  display: grid; place-items: center; font-size: 24px;
  background: linear-gradient(140deg, var(--brand-1), var(--brand-2)); color: #fff;
}
.lockbox h1 { text-align: center; font-size: 19px; }
.lockbox p.lead { text-align: center; color: var(--ink-3); font-size: 13px; margin: 7px 0 20px; }
.lockbox .err {
  background: color-mix(in srgb, var(--critical) 14%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--critical) 40%, transparent);
  color: var(--ink); border-radius: 11px; padding: 10px 12px;
  font-size: 13px; margin-bottom: 14px; display: flex; gap: 8px; align-items: flex-start;
}
.lockbox .err i { color: var(--critical); }
.lockbox .foot { text-align: center; font-size: 11.5px; color: var(--ink-3); margin-top: 16px; line-height: 1.6; }

/* ─── Dropdown gợi ý nơi mua ───────────────────────────────────────────
   Dùng CLASS RIÊNG, không dùng .panel: trong popup có rule bỏ khung .panel
   (background:none) — nếu dùng chung thì dropdown sẽ trong suốt, chữ đè lên
   các ô phía dưới. */
.ac-pop {
  position: absolute; z-index: 60; left: 0; right: 0; top: calc(100% + 4px);
  display: none; padding: 6px; max-height: 252px; overflow-y: auto;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 32px -10px rgba(0, 0, 0, .65), 0 1px 2px rgba(0, 0, 0, .4);
}
.ac-pop .ac-item {
  padding: 9px 10px; border-radius: 9px; cursor: pointer; font-size: 13.5px;
  display: flex; align-items: baseline; gap: 7px;
}
.ac-pop .ac-item:hover, .ac-pop .ac-item.on { background: var(--surface); }
.ac-pop .ac-item b { font-weight: 620; }
.ac-pop .ac-item span { font-size: 11.5px; color: var(--ink-3); }

/* ═══════════════════════════ POPUP (MODAL) ═══════════════════════════
   Điện thoại: tấm trượt lên từ đáy (bottom sheet) — ngón cái với tới nút Lưu.
   Từ 700px trở lên: hộp thoại canh giữa. Mọi form thêm/sửa đều dùng khung này. */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(3px);
  opacity: 0; transition: opacity .18s ease;
}
.modal-backdrop.on { opacity: 1; }

.modal {
  position: fixed; z-index: 101;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex; flex-direction: column;
  box-shadow: 0 -12px 40px -12px rgba(0, 0, 0, .6);
  /* mobile: dán đáy màn hình */
  left: 0; right: 0; bottom: 0;
  max-height: 92vh;
  border-radius: 22px 22px 0 0;
  transform: translateY(100%);
  transition: transform .24s cubic-bezier(.32, .72, 0, 1);
}
.modal.on { transform: translateY(0); }

.modal .m-grip {                       /* thanh kéo, gợi ý vuốt xuống để đóng */
  width: 38px; height: 4px; border-radius: 99px; background: var(--border-2);
  margin: 9px auto 0; flex: none;
}
.modal .m-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px 10px; flex: none;
  border-bottom: 1px solid var(--border);
}
.modal .m-head h2 { flex: 1; min-width: 0; font-size: 16.5px; }
.modal .m-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
.modal .m-body .panel {              /* form nhúng vào modal thì bỏ khung riêng */
  background: none; border: 0; box-shadow: none; padding: 0;
}
.modal .m-body .panel > .panel-head { display: none; }

.modal .m-loading {
  padding: 46px 16px; text-align: center; color: var(--ink-3); font-size: 13.5px;
}

@media (min-width: 700px) {
  .modal {
    left: 50%; right: auto; bottom: auto; top: 50%;
    width: min(640px, 94vw); max-height: 88vh;
    border-radius: 18px;
    transform: translate(-50%, -46%) scale(.98);
    opacity: 0;
    transition: transform .18s ease, opacity .18s ease;
  }
  .modal.on { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  .modal .m-grip { display: none; }
  .modal .m-head { padding: 15px 18px 13px; }
  .modal .m-body { padding: 18px; }
}

body.modal-open { overflow: hidden; }

/* ─────────────────────── BẢNG CHỌN TÔNG MÀU ─────────────────────── */

.theme-menu {
  position: fixed; z-index: 120;
  min-width: 190px; padding: 6px;
  background: var(--surface-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  box-shadow: 0 14px 36px -12px rgba(0, 0, 0, .55), 0 1px 2px rgba(0, 0, 0, .3);
}
.theme-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: 9px;
  background: none; color: var(--ink); font: inherit; font-size: 13.5px;
  cursor: pointer; text-align: left;
}
.theme-menu button:hover { background: var(--surface); }
.theme-menu button .sw {
  width: 20px; height: 20px; border-radius: 7px; flex: none;
  border: 1px solid var(--border-2);
}
.theme-menu button .ck { margin-left: auto; color: var(--accent); font-size: 14px; }
.theme-menu button[aria-checked="false"] .ck { visibility: hidden; }

/* ─────────────────────────── PHỤ TRỢ ─────────────────────────── */

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.grow { flex: 1; min-width: 0; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.sep { height: 1px; background: var(--border); margin: 14px 0; }
.empty {
  text-align: center; padding: 30px 16px; color: var(--ink-3); font-size: 13.5px;
}
.empty i { font-size: 30px; display: block; margin-bottom: 10px; opacity: .55; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom, 0px));
  z-index: 90; max-width: min(420px, 92vw);
  background: var(--surface-3); color: var(--ink);
  border: 1px solid var(--border-2); border-radius: 12px;
  padding: 11px 15px; font-size: 13.5px; box-shadow: var(--shadow);
  display: flex; gap: 9px; align-items: center;
  animation: toastin .22s ease;
}
.toast.ok  { border-color: color-mix(in srgb, var(--good) 50%, transparent); }
.toast.bad { border-color: color-mix(in srgb, var(--critical) 50%, transparent); }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 12px); } }

.spin { display: inline-block; animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ═══════════════════════ MÀN HÌNH LỚN (≥900px) ═══════════════════════ */

@media (min-width: 900px) {
  body { padding-bottom: 24px; }
  .tabbar { display: none; }

  .shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); align-items: start; }
  .sidebar {
    position: sticky; top: 0; height: 100vh; padding: 18px 14px;
    border-right: 1px solid var(--border); background: var(--surface);
    display: flex; flex-direction: column; gap: 4px;
  }
  .sidebar .brand { margin: 2px 4px 16px; }
  .sidebar a.nv {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: 11px;
    color: var(--ink-2); font-size: 14px; font-weight: 580; text-decoration: none;
  }
  .sidebar a.nv i { font-size: 17px; width: 20px; text-align: center; flex: none; }
  .sidebar a.nv:hover { background: var(--surface-2); color: var(--ink); }
  .sidebar a.nv[aria-current="page"] {
    background: color-mix(in srgb, var(--accent) 16%, var(--surface));
    color: var(--ink);
  }
  .sidebar a.nv .cnt {
    margin-left: auto; font-size: 11px; font-weight: 700;
    background: var(--critical); color: #fff; border-radius: 8px; padding: 1px 6px;
  }
  .sidebar .grow { flex: 1; }
  .sidebar .add {
    margin: 8px 0 12px; background: linear-gradient(140deg, var(--brand-1), var(--brand-2));
    color: #fff; justify-content: center; font-weight: 680;
  }
  .sidebar .add:hover { filter: brightness(1.08); }

  .topbar { display: none; }
  .topbar.desk { display: flex; background: transparent; border: 0; backdrop-filter: none; }

  .wrap { padding: 22px 26px 40px; }
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  .card-rail { padding: 2px 0 6px; margin: 0; flex-wrap: wrap; overflow: visible; }
  .ccard { width: calc((100% - 24px) / 3); min-width: 260px; }
  .grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
  .grid2 > * { margin: 0 !important; }
  .grid-2-1 { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 16px; align-items: start; }
  .grid-2-1 > * { margin: 0 !important; }
  h1 { font-size: 24px; }
}

@media (max-width: 899px) {
  .sidebar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* In ấn / forced-colors: bỏ nền màu, dựa vào chữ */
@media print {
  .tabbar, .sidebar, .topbar, .iconbtn { display: none !important; }
  body { background: #fff; color: #000; padding: 0; }
  .panel, .kpi { border-color: #999; box-shadow: none; }
}
