/* =====================================================================
   GARAZ UI · bộ giao diện dùng chung · v1.0
   ---------------------------------------------------------------------
   1. Token (màu, chữ, kích thước) — sửa ở đây để đổi thương hiệu
   2. Nền tảng (reset, chữ, focus)
   3. Khung ứng dụng (sidebar, thanh trên, trang)
   4. Thành phần (nút, ô nhập, lựa chọn, công tắc, thẻ, bảng, nhãn trạng thái,
      thông báo, tab, hộp thoại, menu, phân trang, dòng thời gian…)
   5. Khuôn màn (danh sách, form, hồ sơ, chứng từ)
   6. Tiện ích
   Ô nhập/chọn được style theo thẻ HTML, nên form Django render mặc định
   dùng được ngay, không cần thêm class cho widget.
   ===================================================================== */

/* ---------- 1. TOKEN ---------- */
:root {
  --bg: #F1F4F3;
  --surface: #FFFFFF;
  --surface-2: #F7F9F8;
  --surface-3: #EDF1EF;
  --ink: #14201E;
  --muted: #55625E;
  --line: #D8DFDC;
  --line-strong: #B4BFBB;
  --accent: #0C626B;
  --accent-hover: #094F57;
  --accent-ink: #FFFFFF;
  --accent-soft: #E0EFEF;
  --warn: #84480A;  --warn-bg: #FFF4E2; --warn-line: #EDC688;
  --err: #B3261E;   --err-bg: #FDEFED;  --err-line: #EFB3AC;
  --ok: #1C6A39;    --ok-bg: #E5F3EA;   --ok-line: #A9D6B8;
  --info: #1F4E8C;  --info-bg: #E7EFFA; --info-line: #B3C9E8;
  --vip: #6E4A06;   --vip-bg: #FBF0D9;  --vip-line: #E8C77E;
  --side-bg: #11282A;
  --side-ink: #D3E2E0;
  --side-muted: #8FA9A6;
  --side-hover: #1A3638;
  --side-active: #21474A;
  --side-mark: #5BBFC6;
  --shadow-sm: 0 1px 2px rgba(20, 32, 30, .06);
  --shadow: 0 1px 2px rgba(20, 32, 30, .06), 0 6px 20px rgba(20, 32, 30, .06);
  --shadow-lg: 0 10px 40px rgba(20, 32, 30, .18);
  --f-body: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --fs-xs: 12px; --fs-sm: 13.5px; --fs: 15px; --fs-md: 16px; --fs-lg: 19px; --fs-xl: 24px;
  --r: 6px; --r-lg: 10px;
  --h-control: 44px;
  --side-w: 248px;
  --top-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1514; --surface: #162020; --surface-2: #1B2726; --surface-3: #22302F; --ink: #E4ECEA; --muted: #9BADA8;
    --line: #2A3836; --line-strong: #41524F; --accent: #5BBFC6; --accent-hover: #7FD0D5; --accent-ink: #062226; --accent-soft: #173A3D;
    --warn: #F2B866; --warn-bg: #2E2311; --warn-line: #6B4E1F;
    --err: #FF9A8F; --err-bg: #331917; --err-line: #7A2E27;
    --ok: #7FD39B; --ok-bg: #15301F; --ok-line: #2E6A43;
    --info: #9CC2F5; --info-bg: #17263A; --info-line: #2F4D75;
    --vip: #F0C870; --vip-bg: #33270F; --vip-line: #6F5420;
    --side-bg: #0A1211; --side-ink: #D3E2E0; --side-muted: #8299A0; --side-hover: #142221; --side-active: #1B3436; --side-mark: #5BBFC6;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1514; --surface: #162020; --surface-2: #1B2726; --surface-3: #22302F; --ink: #E4ECEA; --muted: #9BADA8;
  --line: #2A3836; --line-strong: #41524F; --accent: #5BBFC6; --accent-hover: #7FD0D5; --accent-ink: #062226; --accent-soft: #173A3D;
  --warn: #F2B866; --warn-bg: #2E2311; --warn-line: #6B4E1F;
  --err: #FF9A8F; --err-bg: #331917; --err-line: #7A2E27;
  --ok: #7FD39B; --ok-bg: #15301F; --ok-line: #2E6A43;
  --info: #9CC2F5; --info-bg: #17263A; --info-line: #2F4D75;
  --vip: #F0C870; --vip-bg: #33270F; --vip-line: #6F5420;
  --side-bg: #0A1211; --side-ink: #D3E2E0; --side-muted: #8299A0; --side-hover: #142221; --side-active: #1B3436; --side-mark: #5BBFC6;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
  color-scheme: dark;
}

/* ---------- 2. NỀN TẢNG ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: var(--fs); line-height: 1.5; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
h1, h2, h3, h4 { text-wrap: balance; margin: 0; line-height: 1.25; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.mono { font-family: var(--f-mono); font-size: .9em; letter-spacing: .01em; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.nowrap { white-space: nowrap; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
svg.i.sm { width: 16px; height: 16px; }
svg.i.lg { width: 22px; height: 22px; }
kbd { font-family: var(--f-mono); font-size: 12px; padding: 1px 6px; border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface-2); color: var(--ink); }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }

/* ---------- 3. KHUNG ỨNG DỤNG ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--side-bg); color: var(--side-ink);
  display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom, 0px); z-index: 40;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 18px; height: var(--top-h); flex: none; text-decoration: none; color: #fff; font-weight: 700; letter-spacing: .1em; font-size: 15px; }
.brand-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--side-mark); color: #062226; display: grid; place-items: center; flex: none; }
.brand-mark svg.i { width: 18px; height: 18px; }
.side-ws { margin: 4px 12px 8px; padding: 10px 12px; border-radius: var(--r); background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08); }
.side-ws b { display: block; color: #fff; font-weight: 600; font-size: 14px; line-height: 1.3; }
.side-ws span { color: var(--side-muted); font-size: 12px; font-family: var(--f-mono); }
.nav { padding: 8px 10px 16px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-label { margin: 14px 10px 6px; font-size: 11.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--side-muted); }
.nav a, .nav button.nav-item {
  display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 12px; border-radius: var(--r); color: var(--side-ink);
  text-decoration: none; font-size: 14.5px; font-weight: 500; position: relative; border: 0; background: none; font-family: inherit; width: 100%; text-align: left; cursor: pointer;
}
.nav a:hover, .nav button.nav-item:hover { background: var(--side-hover); color: #fff; }
.nav a[aria-current="page"] { background: var(--side-active); color: #fff; }
.nav a[aria-current="page"]::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--side-mark); }
.nav a svg.i { color: var(--side-muted); }
.nav a[aria-current="page"] svg.i, .nav a:hover svg.i { color: var(--side-mark); }
.nav .soon { margin-left: auto; font-size: 10.5px; font-weight: 600; letter-spacing: .04em; color: var(--side-muted); border: 1px solid rgba(255,255,255,.14); padding: 0 6px; border-radius: 99px; line-height: 18px; }
.nav a.is-soon { color: var(--side-muted); }
.nav .sub { display: flex; flex-direction: column; gap: 2px; margin: 2px 0 4px 30px; }
.nav .sub a { min-height: 34px; font-size: 13.5px; padding: 0 10px; }
.nav .sub a[aria-current="page"]::before { left: -40px; }
.side-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: var(--side-muted); }
.side .side-close { display: none; }
.side-brand:hover { color: #fff; }
.nav a > span:not(.soon) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav .soon { white-space: nowrap; flex: none; }
.backdrop { position: fixed; inset: 0; background: rgba(5, 12, 12, .5); z-index: 35; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--top-h); background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.topbar .burger.btn { display: none; }
.topsearch { flex: 1; max-width: 520px; position: relative; }
.topsearch svg.i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.topsearch input { padding-left: 40px !important; min-height: 40px !important; background: var(--surface-2) !important; border-color: var(--line) !important; }
.topsearch kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.usermenu-btn { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 4px 8px 4px 4px; border-radius: 99px; border: 1px solid transparent; background: none; color: var(--ink); font: inherit; cursor: pointer; }
.usermenu-btn:hover { background: var(--surface-2); border-color: var(--line); }
.usermenu-btn .who { display: flex; flex-direction: column; text-align: left; line-height: 1.2; }
.usermenu-btn .who b { font-size: 14px; font-weight: 600; }
.usermenu-btn .who span { font-size: 12px; color: var(--muted); }
@media (max-width: 720px) { .usermenu-btn .who, .topsearch kbd { display: none; } }

.page {
  width: 100%; max-width: 1240px; margin: 0 auto; padding-block: 24px 64px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; flex-direction: column; gap: 20px;
}
.page.has-actionbar { padding-bottom: 140px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13.5px; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--ink); text-decoration: underline; }
.crumbs [aria-current] { color: var(--ink); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; }
.page-head .titles { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.page-head h1 { font-size: var(--fs-xl); font-weight: 700; }
.page-head .sub { color: var(--muted); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

@media (max-width: 991px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: min(300px, 86vw); height: auto; transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow-lg); padding-left: env(safe-area-inset-left, 0px); }
  .side.open { transform: none; }
  .side .side-close { display: grid; margin-left: auto; color: var(--side-ink); }
  .topbar .burger.btn { display: grid; }
}

/* ---------- 4. THÀNH PHẦN ---------- */
/* Nút */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--h-control); padding: 0 18px; border-radius: var(--r); border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; line-height: 1.2; }
.btn:hover { background: var(--surface-2); border-color: var(--muted); color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; color: var(--ink); }
.btn-danger { background: var(--err); border-color: var(--err); color: var(--surface); }
.btn-danger:hover { background: var(--err); border-color: var(--err); color: var(--surface); filter: brightness(.94); }
.btn-danger-quiet { color: var(--err); border-color: var(--err-line); }
.btn-danger-quiet:hover { background: var(--err-bg); color: var(--err); border-color: var(--err); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: var(--fs-sm); }
.btn-icon { width: 40px; min-height: 40px; padding: 0; }
.btn-icon.btn-sm { width: 36px; min-height: 36px; }
.btn-block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn[aria-busy="true"] { cursor: progress; opacity: .8; }
.btn .spinner { border-color: currentColor; border-top-color: transparent; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Ô nhập — style theo thẻ để form Django dùng được ngay */
input[type="text"], input[type="tel"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], input[type="date"], input[type="datetime-local"], input[type="url"], select, textarea {
  width: 100%; min-height: var(--h-control); padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--surface); color: var(--ink); font: inherit; font-size: var(--fs);
}
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2378847F' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .7; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[readonly], textarea[readonly] { background: var(--surface-2); color: var(--muted); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-3); color: var(--muted); cursor: not-allowed; opacity: 1; }
[aria-invalid="true"] { border-color: var(--err) !important; }
[aria-invalid="true"]:focus { outline-color: var(--err); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; flex: none; }

.form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label, legend.label { font-size: 14px; font-weight: 500; color: var(--ink); padding: 0; }
.req { color: var(--err); margin-left: 2px; }
.opt { color: var(--muted); font-weight: 400; font-size: 13px; }
.hint { color: var(--muted); font-size: var(--fs-sm); }
.msg-err { color: var(--err); font-size: var(--fs-sm); display: flex; gap: 6px; align-items: flex-start; }
.msg-err svg.i { width: 16px; height: 16px; margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 860px) { .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); } }
.span-2 { grid-column: span 2; }
@media (max-width: 640px) { .span-2 { grid-column: auto; } }
fieldset.plain { border: 0; margin: 0; padding: 0; min-width: 0; }
.input-icon { position: relative; }
.input-icon > svg.i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > input { padding-left: 40px; }
.input-action { position: relative; }
.input-action > input { padding-right: 48px; }
.input-action > button { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); border-radius: var(--r); cursor: pointer; }
.input-action > button:hover { color: var(--ink); background: var(--surface-2); }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: var(--fs); }
.check input { margin-top: 3px; }
.check span small { display: block; color: var(--muted); font-size: var(--fs-sm); }

/* Lựa chọn dạng ô và nhóm nút */
.choice-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 460px) { .choice-row { grid-template-columns: minmax(0, 1fr); } }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; inset: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.choice label { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border: 1px solid var(--line-strong); border-radius: var(--r-lg); cursor: pointer; min-height: 64px; background: var(--surface); }
.choice label .ic { width: 36px; height: 36px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); flex: none; }
.choice label b { display: block; font-weight: 600; }
.choice label .d { display: block; color: var(--muted); font-size: 13px; }
.choice input:checked + label { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-soft); }
.choice input:checked + label .ic { background: var(--accent); color: var(--accent-ink); }
.choice input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.seg-item { position: relative; }
.seg-item input { position: absolute; opacity: 0; inset: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; }
.seg-item label { display: flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 500; font-size: 14px; }
.seg-item input:checked + label { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line-strong), var(--shadow-sm); font-weight: 600; }
.seg-item input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Công tắc (checkbox role=switch) */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 44px; height: 26px; margin: 0; cursor: pointer; }
.switch .track { width: 44px; height: 26px; border-radius: 99px; background: var(--line-strong); position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .45; }
.switch input:disabled ~ * { color: var(--muted); }

/* Thẻ và khối */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); min-width: 0; }
.card-pad { padding: 20px 24px; }
@media (max-width: 560px) { .card-pad { padding: 16px; } }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2, .card-head h3 { font-size: var(--fs-md); font-weight: 600; }
.card-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.card-foot { padding: 14px 24px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
@media (max-width: 560px) { .card-head, .card-body, .card-foot { padding-left: 16px; padding-right: 16px; } }
.section { display: flex; flex-direction: column; gap: 16px; padding-block: 22px; border-top: 1px solid var(--line); }
.section:first-child { border-top: 0; padding-top: 4px; }
.section-head { display: flex; flex-direction: column; gap: 2px; }
.section-head h2, .section-head h3 { font-size: var(--fs-md); font-weight: 600; }
.section-head p { color: var(--muted); font-size: var(--fs-sm); }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }

/* Danh sách nhãn–giá trị */
.kv { margin: 0; display: grid; grid-template-columns: minmax(120px, auto) minmax(0, 1fr); gap: 10px 20px; font-size: 14.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv.right dd { text-align: right; }
@media (max-width: 480px) { .kv:not(.keep) { grid-template-columns: minmax(0, 1fr); gap: 2px; } .kv:not(.keep) dd { margin-bottom: 8px; } }

/* Nhãn, trạng thái, chip */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; line-height: 18px; }
.badge.vip { background: var(--vip-bg); border-color: var(--vip-line); color: var(--vip); }
.badge.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; padding: 3px 10px 3px 8px; border-radius: 99px; white-space: nowrap; line-height: 18px; border: 1px solid transparent; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.status.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.status.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.status.err { background: var(--err-bg); color: var(--err); border-color: var(--err-line); }
.status.info { background: var(--info-bg); color: var(--info); border-color: var(--info-line); }
.status.neutral { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.status.draft { background: var(--surface); color: var(--muted); border: 1px dashed var(--line-strong); }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px 0 12px; border-radius: 99px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 13.5px; color: var(--ink); }
.chip button { border: 0; background: none; color: var(--muted); width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; padding: 0; }
.chip button:hover { background: var(--surface-3); color: var(--ink); }
.lock-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.lock-tag svg.i { width: 14px; height: 14px; }

/* Ảnh đại diện */
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none; overflow: hidden; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.avatar.xl { width: 88px; height: 88px; font-size: 30px; }
.person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.person .nm { font-weight: 600; overflow-wrap: anywhere; }
.person .meta { color: var(--muted); font-size: 13px; }

/* Thông báo trong trang */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r-lg); border: 1px solid; font-size: 14.5px; }
.alert > svg.i { margin-top: 2px; }
.alert .alert-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.alert h2, .alert h3, .alert .alert-title { font-size: 15px; font-weight: 600; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.alert.err { background: var(--err-bg); border-color: var(--err-line); }
.alert.err > svg.i, .alert.err .alert-title { color: var(--err); }
.alert.err a { color: var(--err); font-weight: 500; }
.alert.warn { background: var(--warn-bg); border-color: var(--warn-line); }
.alert.warn > svg.i, .alert.warn .alert-title { color: var(--warn); }
.alert.ok { background: var(--ok-bg); border-color: var(--ok-line); }
.alert.ok > svg.i, .alert.ok .alert-title { color: var(--ok); }
.alert.info { background: var(--info-bg); border-color: var(--info-line); }
.alert.info > svg.i, .alert.info .alert-title { color: var(--info); }
.alert.neutral { background: var(--surface-2); border-color: var(--line); }
.alert:focus { outline: 2px solid var(--err); outline-offset: 2px; }

/* Thông báo nổi */
.toasts { position: fixed; z-index: 90; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(520px, calc(100vw - 32px)); pointer-events: none; }
.has-actionbar-body .toasts { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
.toast { pointer-events: auto; background: var(--ink); color: var(--bg); padding: 12px 14px 12px 16px; border-radius: var(--r); box-shadow: var(--shadow-lg); font-size: 14px; display: flex; gap: 10px; align-items: center; width: 100%; }
.toast svg.i { color: var(--bg); }
.toast.ok svg.i { color: #7FD39B; }
.toast.err svg.i { color: #FF9A8F; }
:root[data-theme="dark"] .toast.ok svg.i { color: var(--ok-bg); }

/* Bảng */
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.card > .table-wrap { border: 0; border-radius: 0; }
table.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 12.5px; font-weight: 600; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; }
.table td.act { text-align: right; white-space: nowrap; width: 1%; }
.table .row-link { color: var(--ink); text-decoration: none; font-weight: 600; }
.table .row-link:hover { color: var(--accent); text-decoration: underline; }
.table tr.is-muted td { color: var(--muted); }
.table-min { min-width: 760px; }
@media (max-width: 720px) { .table th, .table td { padding: 10px 12px; } }

/* Thanh công cụ, lọc */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.toolbar .grow { flex: 1 1 260px; min-width: 0; }
.toolbar select { width: auto; min-width: 150px; }
@media (max-width: 640px) { .toolbar select { flex: 1 1 140px; } }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--line); align-items: center; }
.result-count { font-size: 13.5px; color: var(--muted); }

/* Phân trang */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.pager nav { display: flex; gap: 4px; }
.pager a, .pager span.cur { min-width: 36px; height: 36px; display: grid; place-items: center; border-radius: var(--r); text-decoration: none; color: var(--ink); border: 1px solid var(--line); background: var(--surface); padding: 0 8px; }
.pager a:hover { border-color: var(--muted); }
.pager span.cur { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pager a[aria-disabled="true"] { opacity: .4; pointer-events: none; }

/* Trạng thái rỗng */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 48px 20px; }
.empty .empty-ic { width: 56px; height: 56px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); display: grid; place-items: center; }
.empty h3 { font-size: var(--fs-md); }
.empty p { color: var(--muted); max-width: 46ch; }

/* Tab */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: thin; }
.tabs [role="tab"] { min-height: 44px; padding: 0 14px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 500; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.tabs [role="tab"]:hover { color: var(--ink); }
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .count { font-size: 12px; background: var(--surface-3); color: var(--muted); padding: 0 7px; border-radius: 99px; line-height: 18px; font-weight: 600; }
[role="tabpanel"]:focus-visible { outline-offset: 4px; }

/* Hộp thoại (dialog gốc của trình duyệt) */
dialog.dialog { border: 0; padding: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.dialog.wide { width: min(760px, calc(100vw - 32px)); }
dialog.dialog::backdrop { background: rgba(5, 12, 12, .55); }
.dialog-form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dialog-head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 24px 12px; }
.dialog-head h2 { font-size: var(--fs-lg); font-weight: 600; }
.dialog-head p { color: var(--muted); font-size: var(--fs-sm); margin-top: 4px; }
.dialog-head .btn-icon { margin-left: auto; margin-top: -6px; margin-right: -10px; }
.dialog-body { padding: 8px 24px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.dialog-foot { padding: 14px 24px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.danger-ic { width: 40px; height: 40px; border-radius: 50%; background: var(--err-bg); color: var(--err); display: grid; place-items: center; flex: none; }
@media (max-width: 560px) { .dialog-head, .dialog-body, .dialog-foot { padding-left: 16px; padding-right: 16px; } .dialog-foot .btn { flex: 1 1 auto; } }

/* Menu thả xuống */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); padding: 6px; z-index: 50; display: flex; flex-direction: column; }
.menu a, .menu button { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 12px; border-radius: var(--r); color: var(--ink); text-decoration: none; border: 0; background: none; font: inherit; font-size: 14.5px; cursor: pointer; text-align: left; width: 100%; }
.menu a:hover, .menu button:hover, .menu a:focus-visible, .menu button:focus-visible { background: var(--surface-2); outline: none; }
.menu .danger { color: var(--err); }
.menu hr { border: 0; height: 1px; background: var(--line); margin: 6px 0; }
.menu .menu-head { padding: 8px 12px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu .menu-head b { display: block; }
.menu .menu-head span { font-size: 12.5px; color: var(--muted); }

/* Thanh thao tác cố định đáy */
.actionbar { position: fixed; left: var(--side-w); right: 0; bottom: 0; z-index: 25; background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(20, 32, 30, .06); padding-top: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.actionbar.full { left: 0; }
.actionbar-in { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.actionbar .note { color: var(--muted); font-size: 13px; margin-right: auto; }
.actionbar .btns { display: flex; gap: 10px; flex-wrap: wrap; margin-left: auto; }
@media (max-width: 991px) { .actionbar { left: 0; } }
@media (max-width: 640px) { .actionbar .note { display: none; } .actionbar .btns { width: 100%; } .actionbar .btns .btn { flex: 1 1 auto; } .actionbar .btns .btn-primary { flex-basis: 100%; order: -1; } }

/* Dòng thời gian lịch sử */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.tl-day { font-size: 12.5px; font-weight: 600; color: var(--muted); letter-spacing: .04em; padding: 14px 0 8px; text-transform: uppercase; }
.tl-item { display: grid; grid-template-columns: 36px minmax(0, 1fr); gap: 12px; position: relative; padding-bottom: 16px; }
.tl-item::before { content: ""; position: absolute; left: 17px; top: 36px; bottom: 0; width: 2px; background: var(--line); }
.tl-item:last-child::before { display: none; }
.tl-dot { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); }
.tl-dot.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tl-dot.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.tl-dot.err { background: var(--err-bg); color: var(--err); border-color: var(--err-line); }
.tl-dot.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-line); }
.tl-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; padding-top: 6px; }
.tl-title { font-size: 14.5px; }
.tl-title b { font-weight: 600; }
.tl-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.tl-reason { font-size: 13.5px; padding: 8px 12px; border-left: 3px solid var(--line-strong); background: var(--surface-2); border-radius: 0 var(--r) var(--r) 0; color: var(--ink); }
.diff { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-top: 4px; }
.diff th, .diff td { text-align: left; padding: 7px 10px; border: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.diff th { background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: 12px; }
.diff .before { color: var(--err); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--err) 50%, transparent); }
.diff .after { color: var(--ok); }
.diff .hidden-val { color: var(--muted); font-style: italic; }

/* Spinner */
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: g-spin .8s linear infinite; flex: none; display: inline-block; }
@keyframes g-spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: g-shimmer 1.2s infinite; border-radius: 4px; height: 14px; }
@keyframes g-shimmer { to { background-position: -200% 0; } }

/* Trang trạng thái hệ thống (403/404/500/phiên hết hạn) */
.state-page { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; padding: 72px 20px; max-width: 520px; margin: 0 auto; }
.state-page .code { font-family: var(--f-mono); font-size: 13px; color: var(--muted); letter-spacing: .1em; }
.state-page h1 { font-size: 26px; }
.state-page p { color: var(--muted); }
.state-ic { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); color: var(--muted); box-shadow: var(--shadow-sm); }
.state-ic svg.i { width: 30px; height: 30px; }

/* Quyền trên giao diện */
.perm-note { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.perm-note svg.i { width: 15px; height: 15px; }
.admin-only { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; letter-spacing: .02em; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 99px; }
.admin-only svg.i { width: 13px; height: 13px; }

/* ---------- 5. KHUÔN MÀN ---------- */
/* Danh sách: .card > .toolbar + .table-wrap + .pager */
/* Form: bố cục 2 cột (form + cột phụ) */
.form-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.form-layout > aside { position: sticky; top: calc(var(--top-h) + 16px); display: flex; flex-direction: column; gap: 16px; }
@media (max-width: 1080px) { .form-layout { grid-template-columns: minmax(0, 1fr); } .form-layout > aside { position: static; } }
/* Hồ sơ: đầu hồ sơ + tab + nội dung 2 cột */
.profile-head { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; padding: 20px 24px; }
.profile-head .info { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1 1 260px; }
.profile-head h1 { font-size: 22px; font-weight: 700; }
.profile-head .facts { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 14px; }
.profile-head .facts span { display: inline-flex; align-items: center; gap: 6px; }
.profile-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.profile-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
@media (max-width: 1080px) { .profile-grid { grid-template-columns: minmax(0, 1fr); } }
/* Chứng từ: thanh trạng thái */
.doc-steps { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; }
.doc-steps .step { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.doc-steps .step .n { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--line-strong); display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.doc-steps .step.done { color: var(--ok); }
.doc-steps .step.done .n { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.doc-steps .step.cur { color: var(--ink); font-weight: 600; }
.doc-steps .step.cur .n { border-color: var(--accent); color: var(--accent); }
.doc-steps .sep { width: 24px; height: 1.5px; background: var(--line-strong); }
.lines td input, .lines td select { min-height: 38px; padding: 6px 10px; font-size: 14.5px; }
.lines td { padding: 8px 10px; }
.totals { margin-left: auto; width: min(360px, 100%); display: grid; grid-template-columns: 1fr auto; gap: 8px 20px; font-size: 14.5px; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; font-weight: 500; }
.totals .grand { font-size: 18px; font-weight: 700; color: var(--ink); padding-top: 8px; border-top: 1px solid var(--line); }

/* Danh sách dạng thẻ cho điện thoại (thay bảng dưới 640px) */
.m-list { list-style: none; margin: 0; padding: 0; display: none; }
.m-list li { border-bottom: 1px solid var(--line); }
.m-list li:last-child { border-bottom: 0; }
.m-list a.m-item { display: flex; gap: 12px; align-items: center; padding: 14px 16px; text-decoration: none; color: var(--ink); min-height: 64px; }
.m-list a.m-item:hover { background: var(--surface-2); }
.m-item .m-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.m-item .m-main b { font-weight: 600; overflow-wrap: anywhere; }
.m-item .m-sub { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.m-item > svg.i { color: var(--muted); }
@media (max-width: 640px) { .table-wrap.has-mlist { display: none; } .m-list { display: block; } }

/* Trang đăng nhập (không có khung ứng dụng) */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 44%) minmax(0, 1fr); }
.auth-brand { background: var(--side-bg); color: var(--side-ink); padding: 40px 48px; display: flex; flex-direction: column; gap: 28px; position: relative; overflow: hidden; }
.auth-brand .side-brand { padding: 0; height: auto; font-size: 17px; }
.auth-brand h1 { color: #fff; font-size: clamp(26px, 3vw, 36px); font-weight: 700; line-height: 1.2; max-width: 16ch; }
.auth-brand p { color: var(--side-muted); max-width: 42ch; }
.auth-brand .facts { list-style: none; margin: auto 0 0; padding: 0; display: flex; flex-direction: column; gap: 14px; position: relative; z-index: 1; }
.auth-brand .facts li { display: flex; gap: 12px; align-items: flex-start; font-size: 14.5px; }
.auth-brand .facts svg.i { color: var(--side-mark); margin-top: 2px; }
.auth-brand .road { position: absolute; right: -60px; bottom: -40px; width: 340px; height: 340px; border-radius: 50%; border: 1px solid rgba(255,255,255,.06); box-shadow: 0 0 0 40px rgba(255,255,255,.02), 0 0 0 80px rgba(255,255,255,.015); pointer-events: none; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding-block: 40px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); position: relative; }
.auth-tools { position: absolute; top: 16px; right: max(16px, env(safe-area-inset-right, 0px)); }
.auth-card { width: min(420px, 100%); display: flex; flex-direction: column; gap: 22px; }
.auth-card h2 { font-size: 24px; font-weight: 700; }
.auth-card .lead { color: var(--muted); margin-top: 6px; }
.auth-foot { font-size: 13.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: space-between; }
.ws-remembered { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.ws-remembered .ic { width: 40px; height: 40px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.ws-remembered b { display: block; }
.ws-remembered span { font-size: 13px; color: var(--muted); }
.pw-rules { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; }
.pw-rules li { display: flex; gap: 8px; align-items: center; color: var(--muted); }
.pw-rules li .dot { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--line-strong); display: grid; place-items: center; flex: none; }
.pw-rules li.ok { color: var(--ok); }
.pw-rules li.ok .dot { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.pw-rules li.ok .dot svg.i { width: 12px; height: 12px; stroke-width: 3; }
.auth.platform .auth-brand { background: #1B1A12; }
.auth.platform .brand-mark { background: #E3A646; color: #2A1D05; }
.auth.platform .auth-brand .facts svg.i { color: #E3A646; }
.platform-band { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-lg); background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn); font-size: 13.5px; }
@media (max-width: 860px) {
  .auth { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .auth-brand { padding: 20px 16px; gap: 10px; }
  .auth-brand h1, .auth-brand p, .auth-brand .facts, .auth-brand .road { display: none; }
  .auth-panel { align-items: flex-start; padding-top: 28px; }
}

/* ---------- 6. TIỆN ÍCH ---------- */
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.mt-0 { margin-top: 0 !important; }
.w-auto { width: auto !important; }
