/* =====================================================================
   1102 · Design system
   ---------------------------------------------------------------------
   Một file duy nhất: token → base → component → layout → dark mode.
   Giữ nguyên tên class cũ để markup không phải sửa.
   ===================================================================== */

/* ---------- 1. TOKENS ---------- */

:root {
  /* nền & bề mặt */
  --bg: #f7f8fa;
  --bg-elevated: #ffffff;
  --surface: #ffffff;
  --surface-2: #fbfbfd;
  --surface-3: #f3f4f7;

  /* đường kẻ */
  --line: #e7e9ee;
  --line-strong: #d5d8e0;
  --line-soft: #f0f2f6;

  /* chữ */
  --ink: #0e0e10;
  --ink-2: #4d5561;
  --ink-3: #8b93a1;
  --ink-inverse: #ffffff;

  /* màu nhấn */
  --accent: #e11d48;
  --accent-hover: #be123c;
  --accent-soft: #fff1f4;
  --accent-line: #fecdd3;

  /* trạng thái */
  --ok: #0f7a4d;
  --ok-soft: #ecfdf3;
  --ok-line: #bbf7d0;
  --warn: #9a6700;
  --warn-soft: #fffbeb;
  --warn-line: #fde68a;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --danger-line: #fecdca;
  --info: #1d4ed8;
  --info-soft: #eff6ff;
  --info-line: #bfdbfe;

  /* hình học */
  --radius-sm: 7px;
  --radius: 11px;
  --radius-lg: 15px;
  --radius-pill: 999px;

  /* đổ bóng — rất nhẹ, hiện đại */
  --shadow-xs: 0 1px 2px rgba(13, 15, 19, .04);
  --shadow: 0 1px 3px rgba(13, 15, 19, .05), 0 1px 2px rgba(13, 15, 19, .03);
  --shadow-md: 0 4px 12px rgba(13, 15, 19, .07), 0 1px 3px rgba(13, 15, 19, .04);
  --shadow-lg: 0 16px 40px rgba(13, 15, 19, .14), 0 2px 8px rgba(13, 15, 19, .06);
  --ring: 0 0 0 3px rgba(225, 29, 72, .16);

  /* chữ */
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
          system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, monospace;

  /* nhịp */
  --ease: cubic-bezier(.2, .8, .3, 1);
  --dur: 160ms;
}

/* ---------- 2. BASE ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--accent-soft); color: var(--accent-hover); }

h1, h2, h3 { margin: 0; letter-spacing: -.018em; font-weight: 650; }
h2 { font-size: 14.5px; }
p { margin: 0; }

a { color: inherit; text-decoration: none; }

/* số liệu luôn thẳng cột */
.kpi-value, table.grid td, table.grid th, .count-row, .kv strong,
.dialog-total strong, .money { font-variant-numeric: tabular-nums; }

/* thanh cuộn mảnh */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: var(--radius-pill);
  border: 2px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--ink-3); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

/* ---------- 3. RAIL (sidebar tự mở như Valixa) ---------- */

/* biến bề rộng: 64px thu gọn · 240px khi ghim */
.shell {
  --rail: 64px;
  --rail-open: 240px;
  min-height: 100vh;
  padding-left: var(--rail);
  transition: padding-left .2s var(--ease);
}
.shell.is-pinned { --rail: var(--rail-open); }
.shell > .content { min-width: 0; }

.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 60;
  width: var(--rail);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 14px 10px 12px;
  overflow: hidden;
  transition: width .2s var(--ease), box-shadow .2s var(--ease);
}
/* tự mở rộng khi rê chuột */
.sidebar:hover { width: var(--rail-open); box-shadow: var(--shadow-lg); }
.shell.is-pinned .sidebar { width: var(--rail-open); box-shadow: none; }

/* nhãn chỉ hiện khi mở — thu bằng max-width để icon luôn căn giữa */
.sidebar .label,
.sidebar .brand-text,
.sidebar .nav-group-label,
.sidebar .sidebar-user .name,
.sidebar .icon-action > span {
  opacity: 0; max-width: 0; overflow: hidden; white-space: nowrap;
  transition: opacity .12s var(--ease), max-width .16s var(--ease);
}
.sidebar:hover .label,
.sidebar:hover .brand-text,
.sidebar:hover .nav-group-label,
.sidebar:hover .sidebar-user .name,
.sidebar:hover .icon-action > span,
.shell.is-pinned .label,
.shell.is-pinned .brand-text,
.shell.is-pinned .nav-group-label,
.shell.is-pinned .sidebar-user .name,
.shell.is-pinned .icon-action > span {
  opacity: 1; max-width: 180px;
}
/* nhóm nhãn chiếm cả dòng: cần giãn hết bề rộng khi mở */
.shell.is-pinned .nav-group-label,
.sidebar:hover .nav-group-label { max-width: 100%; }
.shell.is-pinned .nav-item .label,
.sidebar:hover .nav-item .label { flex: 1; max-width: none; }
.shell.is-pinned .sidebar-user .name,
.sidebar:hover .sidebar-user .name { flex: 1; max-width: none; }

/* thương hiệu */
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 2px 4px 14px; }
.sidebar-brand .mark {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  background: linear-gradient(145deg, var(--accent), var(--accent-hover));
  color: #fff; font-size: 11px; font-weight: 750; letter-spacing: -.03em;
  display: grid; place-items: center;
  box-shadow: 0 2px 8px rgba(225, 29, 72, .28);
}
.sidebar-brand .brand-text { white-space: nowrap; overflow: hidden; min-width: 0; }
.sidebar-brand .title { font-size: 13px; font-weight: 680; line-height: 1.25; white-space: nowrap; }
.sidebar-brand .sub {
  font-size: 10px; color: var(--ink-3); letter-spacing: .05em;
  text-transform: uppercase; white-space: nowrap;
}

/* nhóm + mục */
.sidebar-scroll {
  flex: 1; min-height: 0;            /* cần min-height:0 thì flex item mới co lại được */
  overflow-y: auto; overflow-x: hidden;
  margin: 0 -4px; padding: 0 4px;
}
.nav-group { margin-top: 10px; }
.nav-group:first-child { margin-top: 0; }
.nav-group-label {
  font-size: 10px; font-weight: 650; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3);
  padding: 0 8px 5px; white-space: nowrap;
}
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  height: 38px; padding: 0 9px; margin-bottom: 2px;
  border-radius: 9px;
  font-size: 13px; font-weight: 520; color: var(--ink-2);
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  /* reset mặc định của <button> */
  border: 0; background: none; width: 100%; text-align: left;
  font-family: inherit; line-height: inherit; -webkit-appearance: none; appearance: none;
}
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 620; }
.nav-item.is-active .nav-icon { color: var(--accent); }
.nav-icon { width: 18px; height: 18px; flex: none; color: var(--ink-3); }
/* khi rail thu gọn: icon to và rõ hơn để không trông như menu trống */
.shell:not(.is-pinned) .sidebar:not(:hover) .nav-icon {
  width: 20px; height: 20px; color: var(--ink-2);
}
.nav-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-item .badge {
  font-size: 10px; font-weight: 650; background: var(--accent); color: #fff;
  border-radius: var(--radius-pill); padding: 1px 6px; min-width: 17px; text-align: center;
}

/* nút ghim */
.sidebar-toggle {
  margin-left: auto; width: 24px; height: 24px; flex: none;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 6px; color: var(--ink-3);
  display: grid; place-items: center; cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
}
.sidebar-toggle:hover { background: var(--surface-3); color: var(--ink); border-color: var(--line-strong); }
.sidebar-toggle svg { width: 13px; height: 13px; }
.shell.is-pinned .sidebar-toggle { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }

.pin-action { width: 100%; flex: none; }
.shell.is-pinned .pin-action {
  color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft);
}

/* chân rail */
.sidebar-foot {
  margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px;
}
.sidebar-user {
  display: flex; align-items: center; gap: 9px;
  padding: 6px; border-radius: 9px;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  overflow: hidden;
  width: 100%; font-family: inherit; text-align: left; cursor: pointer;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
button.sidebar-user:hover { background: var(--surface-3); border-color: var(--line-strong); }
.sidebar-user .name { min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; }
.sidebar-user .u-name { font-size: 12.5px; font-weight: 620; line-height: 1.25;
                        overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .u-role { font-size: 10.5px; color: var(--ink-3);
                        overflow: hidden; text-overflow: ellipsis; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: linear-gradient(145deg, var(--surface-3), var(--surface-2));
  color: var(--ink-2); display: grid; place-items: center;
  font-size: 11px; font-weight: 700; border: 1px solid var(--line);
}
.sidebar-actions { display: flex; gap: 6px; flex-direction: column; }
.sidebar:hover .sidebar-actions,
.shell.is-pinned .sidebar-actions { flex-direction: row; }
.icon-action {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 8px; overflow: hidden;
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 9px; color: var(--ink-2);
  font-family: inherit; font-size: 11.5px; font-weight: 560;
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease);
}
.icon-action:hover { background: var(--surface-3); border-color: var(--line-strong); color: var(--ink); }
.icon-action svg { width: 15px; height: 15px; flex: none; }
.icon-action > span { white-space: nowrap; }
/* trong chân rail (cột dọc) không được co theo flex, giữ đúng 34px */
.sidebar-foot .icon-action { flex: none; height: 34px; }
.icon-action.danger:hover { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }

/* nút mở rail trên mobile */
.sidebar-open-btn {
  display: none; width: 32px; height: 32px; flex: none;
  border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: var(--radius-sm); color: var(--ink-2);
  place-items: center; cursor: pointer;
}
.sidebar-open-btn:hover { color: var(--ink); border-color: var(--ink-3); }
.sidebar-open-btn svg { width: 16px; height: 16px; }

/* ---------- 4. LAYOUT ---------- */

/* thông tin người dùng đã có ở chân sidebar */
.shell #who { display: none; }

/* khi có sidebar thì bỏ thương hiệu trùng ở đầu trang */
.shell .topbar .brand,
.shell .head .brand { display: none; }

/* trang phụ dùng .head — cho nó giống topbar để đồng bộ */
.shell .head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 22px; background: var(--surface);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
@media (max-width: 1080px) { .shell .head { padding: 10px 14px; } }

main { max-width: 1560px; margin: 0 auto; padding: 18px 22px 80px; }

/* tiêu đề trang (dùng cho các trang con) */
.page-title {
  font-size: 19px; font-weight: 700; letter-spacing: -.02em;
  margin: 0 0 14px; color: var(--ink);
}
.empty-state {
  padding: 46px 20px; text-align: center;
  color: var(--ink-3); font-size: 13px; line-height: 1.6;
}

/* khung đối chiếu tiền mặt: hai cột tự co */
.close-grid { align-items: start; }
.close-grid > * { min-height: 0; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 22px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: saturate(180%) blur(8px);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark { font-size: 16px; font-weight: 750; letter-spacing: -.025em; color: var(--accent); }
.brand-sub { font-size: 10.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .08em; }

.datebar { display: flex; align-items: center; gap: 6px; }
.date-input {
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 6px 9px; font: inherit; font-size: 13px; color: var(--ink);
  background: var(--surface); font-variant-numeric: tabular-nums;
}
.date-input:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }

/* tab dạng viên thuốc — theo mẫu Valixa */
.tabs {
  display: flex; gap: 6px; justify-self: center; background: none; padding: 0;
}
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 15px;
  border: 1px solid var(--line-strong); background: transparent;
  border-radius: var(--radius-pill);
  font-family: inherit; font-size: 12.5px; font-weight: 560; color: var(--ink-3);
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
}
.tab:hover { color: var(--ink); border-color: var(--ink-3); }
.tab.is-active {
  background: var(--accent-soft); border-color: var(--accent-line);
  color: var(--accent-hover); font-weight: 620;
}
[data-theme="dark"] .tab.is-active {
  background: rgba(251, 113, 133, .14); border-color: rgba(251, 113, 133, .3);
  color: #fda4af;
}

.topbar-actions { display: flex; gap: 8px; margin-left: auto; }

.view { display: none; }
.view.is-active { display: block; animation: fade .18s var(--ease); }

@keyframes fade {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 5. BUTTONS ---------- */

button { cursor: pointer; font: inherit; }

.primary-btn {
  border: 1px solid transparent;
  background: linear-gradient(180deg, #202024, #0e0e10);
  color: #fff; padding: 7px 15px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 13px; letter-spacing: -.005em;
  box-shadow: var(--shadow-xs);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              background var(--dur) var(--ease);
}
.primary-btn:hover { background: #000; box-shadow: var(--shadow); }
.primary-btn:active { transform: translateY(1px); }
.primary-btn:disabled { background: var(--surface-3); color: var(--ink-3);
                        box-shadow: none; cursor: not-allowed; }

.ghost-btn {
  border: 1px solid var(--line-strong); background: var(--surface);
  padding: 7px 13px; border-radius: var(--radius-sm); font-size: 13px;
  color: var(--ink-2); font-weight: 550;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease),
              background var(--dur) var(--ease);
}
.ghost-btn:hover { border-color: var(--ink-3); color: var(--ink); background: var(--surface-2); }
.ghost-btn.danger { color: var(--danger); border-color: var(--danger-line); }
.ghost-btn.danger:hover { background: var(--danger-soft); }

.icon-btn {
  border: 1px solid var(--line-strong); background: var(--surface);
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  font-size: 15px; color: var(--ink-2); display: grid; place-items: center;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { border-color: var(--ink-3); color: var(--ink); }

/* ---------- 6. SURFACES ---------- */

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-xs);
  margin-bottom: 16px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 { font-size: 13.5px; font-weight: 650; }

.muted { color: var(--ink-3); font-size: 12.5px; }
.small { font-size: 12px; }
.muted-sm { color: var(--ink-3); font-size: 12px; }
.empty { padding: 34px 16px; text-align: center; color: var(--ink-3); font-size: 13px; }
.empty[hidden] { display: none; }

/* ---------- 7. KPI ---------- */

.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
  box-shadow: var(--shadow-xs);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.kpi:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.kpi-label {
  font-size: 10.5px; color: var(--ink-3); text-transform: uppercase;
  letter-spacing: .065em; font-weight: 600;
}
.kpi-value {
  font-size: 21px; font-weight: 700; letter-spacing: -.028em;
  margin-top: 5px; line-height: 1.12;
}
.kpi.accent .kpi-value { color: var(--accent); }
.kpi.ok .kpi-value { color: var(--ok); }
.kpi.warn { background: var(--warn-soft); border-color: var(--warn-line); }
.kpi.warn .kpi-value { color: var(--warn); }

/* biến động so với trước */
.kpi-delta { font-size: 11.5px; font-weight: 600; margin-top: 4px; display: flex;
             align-items: center; gap: 4px; }
.kpi-delta.up { color: var(--ok); }
.kpi-delta.down { color: var(--danger); }
.kpi-delta.flat { color: var(--ink-3); }

/* ---------- 8. BANNER ---------- */

.close-banner {
  display: none; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: var(--radius); margin-bottom: 16px;
  font-size: 13px; border: 1px solid; font-weight: 500;
}
.close-banner.show { display: flex; }
.close-banner.ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok); }
.close-banner.warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.close-banner.danger { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.close-banner.info { background: var(--info-soft); border-color: var(--info-line); color: var(--info); }

/* ---------- 9. TABLE ---------- */

.table-wrap { overflow: auto; }
table.grid {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 13px;
}
table.grid th {
  text-align: left; font-size: 10.5px; font-weight: 650; text-transform: uppercase;
  letter-spacing: .06em; color: var(--ink-3); padding: 9px 11px;
  border-bottom: 1px solid var(--line); white-space: nowrap;
  background: var(--surface-2);
  position: sticky; top: 0; z-index: 2;
}
table.grid td {
  padding: 9px 11px; border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
table.grid tbody tr { transition: background var(--dur) var(--ease); }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid td.num, table.grid th.num { text-align: right; }
table.grid tfoot td {
  font-weight: 680; background: var(--surface-3);
  border-top: 1px solid var(--line-strong); border-bottom: none; padding: 11px;
  position: sticky; bottom: 0;
}

.c-table { width: 1%; }
.c-no { font-family: var(--mono); font-size: 12px; letter-spacing: -.01em; }
.c-time { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.c-note { max-width: 220px; overflow: hidden; text-overflow: ellipsis;
          color: var(--ink-2); font-size: 12.5px; }
.c-act { width: 1%; }
.c-state { width: 1%; }

.zero { color: var(--ink-3); }
.comp-row td { color: var(--ink-3); }
.comp-row .c-no::after {
  content: "FOC"; font-family: var(--font); font-size: 9.5px; font-weight: 700;
  color: var(--accent); background: var(--accent-soft); border-radius: 4px;
  padding: 1px 4px; margin-left: 5px; letter-spacing: .04em;
}

/* ---------- 10. BADGES ---------- */

.tag {
  display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 620; white-space: nowrap; letter-spacing: -.005em;
}
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.info { background: var(--info-soft); color: var(--info); }
.tag.mute { background: var(--surface-3); color: var(--ink-3); }

.row-btn {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: var(--radius-sm); width: 27px; height: 27px;
  font-size: 12px; color: var(--ink-3); display: inline-grid; place-items: center;
  transition: border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.row-btn:hover { border-color: var(--ink-3); color: var(--ink); }
.row-btn + .row-btn { margin-left: 4px; }

/* ---------- 11. CLOSE DAY ---------- */

.close-grid { display: grid; grid-template-columns: 1.15fr .85fr; }
.close-grid > * { padding: 16px; }
.close-grid > :first-child { border-right: 1px solid var(--line-soft); }

.count-head, .count-row, .count-total {
  display: grid; grid-template-columns: 1fr 110px 140px; align-items: center; gap: 10px;
}
.count-head {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); padding-bottom: 7px; font-weight: 600;
}
.count-head :last-child { text-align: right; }
.count-row { padding: 3px 0; }
.count-row span:first-child { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.count-row input {
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 5px 8px; text-align: right; width: 100%;
  font: inherit; font-size: 13px; font-variant-numeric: tabular-nums;
  background: var(--surface);
}
.count-row input:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }
.count-row .amt { text-align: right; font-variant-numeric: tabular-nums;
                  color: var(--ink-2); font-size: 13px; }
.count-total {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line);
  grid-template-columns: 1fr 250px;
}
.count-total strong { text-align: right; font-size: 18px; letter-spacing: -.02em; }

.close-summary { display: flex; flex-direction: column; gap: 13px; }
.kv { display: flex; justify-content: space-between; align-items: baseline; }
.kv span { color: var(--ink-2); font-size: 12.5px; }
.kv strong { font-size: 15px; letter-spacing: -.015em; }
.kv-variance { padding-top: 11px; border-top: 1px solid var(--line); }
.kv-variance.zero strong { color: var(--ok); }
.kv-variance.nonzero strong { color: var(--danger); }

/* ---------- 12. FORM ---------- */

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; color: var(--ink-2); font-weight: 550; }
.field em { font-style: normal; color: var(--danger); font-size: 11px; }
.field textarea, .field input, .field select {
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 8px 10px; width: 100%; background: var(--surface);
  font: inherit; font-size: 13px; color: var(--ink); resize: vertical;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.field textarea:focus, .field input:focus, .field select:focus {
  border-color: var(--accent); box-shadow: var(--ring); outline: none;
}
.field textarea::placeholder, .field input::placeholder { color: var(--ink-3); }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .field { flex: 1 1 150px; }
.form-row .field.narrow { flex: 0 0 110px; }
.form-row .field.chips-field { flex: 0 0 190px; }
.readonly { background: var(--surface-3); color: var(--ink-2); }

.close-actions { display: flex; gap: 8px; margin-top: 4px; }

/* ---------- 13. TIERS ---------- */

.tier-box { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.tier-head, .tier-row {
  display: grid; grid-template-columns: 1fr 128px 96px; align-items: center; gap: 10px;
}
.tier-head {
  background: var(--surface-2); border-bottom: 1px solid var(--line);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-3); padding: 8px 12px; font-weight: 600;
}
.tier-head :nth-child(2), .tier-head :nth-child(3) { text-align: center; }
.tier-row { padding: 8px 12px; border-bottom: 1px solid var(--line-soft); }
.tier-row:last-child { border-bottom: none; }
.tier-name { font-weight: 600; font-size: 13px; }
.tier-name small { display: block; font-weight: 400; color: var(--ink-3); font-size: 11.5px; }
.stepper { display: flex; align-items: center; gap: 5px; justify-content: center; }
.stepper button {
  border: 1px solid var(--line-strong); background: var(--surface);
  width: 25px; height: 25px; border-radius: 6px; font-size: 14px;
  color: var(--ink-2); display: grid; place-items: center; line-height: 1;
}
.stepper button:hover { border-color: var(--ink-3); color: var(--ink); }
.stepper input {
  width: 48px; text-align: center; border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 4px 2px; font: inherit; font-size: 13px;
  font-variant-numeric: tabular-nums; background: var(--surface);
}
.tier-amt { text-align: right; font-variant-numeric: tabular-nums;
            color: var(--ink-2); font-size: 13px; }

/* ---------- 14. CHIPS ---------- */

.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface);
  padding: 4px 9px; border-radius: var(--radius-pill); font-size: 12px;
  color: var(--ink-2); font-weight: 550; transition: all var(--dur) var(--ease);
}
.chip:hover { border-color: var(--ink-3); }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 620; }

/* ---------- 15. GATE / LOGIN ---------- */

.gate {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(225, 29, 72, .07), transparent 60%),
    var(--bg);
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(384px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 26px 24px; box-shadow: var(--shadow-lg);
}
.form-error {
  color: var(--danger); font-size: 12.5px; margin-top: 10px;
  background: var(--danger-soft); border: 1px solid var(--danger-line);
  border-radius: var(--radius-sm); padding: 8px 10px;
}
.form-error[hidden] { display: none; }

/* ---------- 16. DIALOG ---------- */

.dialog {
  border: 0; border-radius: var(--radius-lg); padding: 0;
  width: min(720px, calc(100vw - 24px));
  box-shadow: var(--shadow-lg); background: var(--surface);
}
.dialog::backdrop { background: rgba(0, 0, 0, .58); backdrop-filter: blur(2px); }
.dialog-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 15px 18px; border-bottom: 1px solid var(--line-soft);
}
.dialog-body {
  padding: 16px 18px; display: flex; flex-direction: column; gap: 14px;
  max-height: 66vh; overflow-y: auto;
}
.dialog-foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 13px 18px; border-top: 1px solid var(--line-soft);
  background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.dialog-total { display: flex; align-items: baseline; gap: 10px; }
.dialog-total span { color: var(--ink-3); font-size: 12px; }
.dialog-total strong { font-size: 22px; letter-spacing: -.028em; }
.dialog-btns { display: flex; gap: 8px; }

/* ---------- 17. ISSUES / MISC ---------- */

.issue-list { list-style: none; margin: 0; padding: 0; }
.issue-list li {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 16px; border-bottom: 1px solid var(--line-soft); font-size: 13px;
}
.issue-list li:last-child { border-bottom: none; }
.issue-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; flex: none; }
.issue-dot.error { background: var(--danger); }
.issue-dot.warn { background: #eab308; }
.issue-meta { color: var(--ink-3); font-size: 12px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 16px 8px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: #17171a; color: #fff; padding: 11px 18px; border-radius: var(--radius);
  font-size: 13px; font-weight: 500; z-index: 9999;
  box-shadow: var(--shadow-lg); max-width: min(560px, calc(100vw - 32px));
  animation: toast-in .2s var(--ease);
}
.toast[hidden] { display: none; }
.toast.toast-error { background: var(--danger); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- 18. CHARTS ---------- */

.chart { width: 100%; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line-soft); stroke-width: 1; }
.chart .axis-label { fill: var(--ink-3); font-size: 10.5px; font-family: var(--font); }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-accent { stroke: var(--accent); }
.chart .area-accent { fill: url(#gradAccent); }
.chart .dot { fill: var(--surface); stroke-width: 2; }
.chart .bar { fill: var(--accent); opacity: .85; }
.chart .bar:hover { opacity: 1; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; }
.legend-row { display: flex; align-items: center; gap: 8px; padding: 7px 0;
              border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; min-width: 0; }
.legend-row .lbl { flex: 1 1 90px; min-width: 0; font-size: 12.5px; }
.legend-row .pct { color: var(--ink-3); font-size: 12px; }
.legend-row .amt { font-size: 12.5px; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .legend-row .amt { flex-basis: 100%; text-align: right; color: var(--ink-2); }
}
.chart-legend .item { display: flex; align-items: center; gap: 6px; font-size: 12px;
                      color: var(--ink-2); }
.chart-legend .swatch { width: 9px; height: 9px; border-radius: 3px; flex: none; }

/* ---------- 19. DARK MODE ---------- */

[data-theme="dark"] {
  /* ĐEN trung tính — bản sắc riêng của 1102, không phải navy */
  --bg: #0a0a0b;
  --bg-elevated: #101012;
  --surface: #131315;
  --surface-2: #18181b;
  --surface-3: #1f1f23;

  --line: #26262b;
  --line-strong: #34343a;
  --line-soft: #1c1c20;

  --ink: #f2f2f4;
  --ink-2: #a3a3ab;
  --ink-3: #6b6b73;

  --accent: #fb7185;
  --accent-hover: #f43f5e;
  --accent-soft: rgba(251, 113, 133, .13);
  --accent-line: rgba(251, 113, 133, .3);

  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, .1);
  --ok-line: rgba(74, 222, 128, .24);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, .1);
  --warn-line: rgba(251, 191, 36, .24);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .1);
  --danger-line: rgba(248, 113, 113, .24);
  --info: #c7d3ff;
  --info-soft: rgba(199, 211, 255, .1);
  --info-line: rgba(199, 211, 255, .24);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .45);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, .6);
  --ring: 0 0 0 3px rgba(251, 113, 133, .22);
}

[data-theme="dark"] .primary-btn {
  background: linear-gradient(180deg, #f43f5e, #be123c);
  color: #fff;
  border-color: rgba(255, 255, 255, .08);
}
[data-theme="dark"] .primary-btn:hover {
  background: linear-gradient(180deg, #fb7185, #e11d48);
}
[data-theme="dark"] .primary-btn:disabled {
  background: var(--surface-3); color: var(--ink-3); border-color: var(--line);
}
[data-theme="dark"] .toast { background: #1a1a1d; border: 1px solid var(--line-strong); }
[data-theme="dark"] .toast.toast-error { background: #7f1d1d; border-color: #991b1b; }
[data-theme="dark"] .sidebar-brand .mark { box-shadow: 0 2px 10px rgba(251, 113, 133, .3); }

/* ---------- 20. RESPONSIVE ---------- */

/* ---------- 20a. RAIL TRÊN MOBILE ---------- */

@media (max-width: 1080px) {
  .shell { padding-left: 0; }
  .sidebar {
    width: 268px; max-width: 84vw;
    transform: translateX(-100%);
    transition: transform .24s var(--ease);
    box-shadow: var(--shadow-lg);
    padding-top: max(14px, env(safe-area-inset-top));
  }
  .shell.is-open .sidebar { transform: none; }
  /* trên mobile luôn hiện nhãn (không có hover) */
  .sidebar .label, .sidebar .brand-text, .sidebar .nav-group-label,
  .sidebar .sidebar-user .name, .sidebar .icon-action > span {
    opacity: 1; pointer-events: auto;
  }
  .sidebar-toggle { display: none; }
  .sidebar-scrim {
    position: fixed; inset: 0; z-index: 55;
    background: rgba(0, 0, 0, .55);
    opacity: 0; pointer-events: none;
    transition: opacity .2s var(--ease);
    backdrop-filter: blur(1.5px);
  }
  .shell.is-open .sidebar-scrim { opacity: 1; pointer-events: auto; }
  .sidebar-open-btn { display: grid; }
  main { padding: 14px 14px 70px; }
  .topbar { padding: 10px 14px; flex-wrap: wrap; }
  .shell .head { padding: 10px 14px; }
}

@media (max-width: 720px) {
  .close-grid { grid-template-columns: 1fr; }
  .close-grid > :first-child { border-right: 0; border-bottom: 1px solid var(--line-soft); }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .kpi { padding: 10px 11px; }
  .kpi-label { font-size: 9.5px; letter-spacing: .05em; }
  .kpi-value { font-size: 17px; margin-top: 4px; }
  .count-total { grid-template-columns: 1fr 150px; }
  .tier-head, .tier-row { grid-template-columns: 1fr 108px 78px; }

  /* banner xếp dọc cho dễ đọc */
  .close-banner { flex-direction: column; align-items: flex-start; gap: 3px; }
  .close-banner strong { font-weight: 650; }

  .panel-head { padding: 11px 13px; }
  .panel-head h2 { font-size: 13px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }

  /* header gọn để nút menu, chọn tháng và nút tải nằm cùng một hàng */
  .shell .head { gap: 8px; padding: 9px 12px; }
  .shell .head .ghost-btn { padding: 6px 9px; font-size: 12px; }
  .shell .head input[type="month"] { padding: 6px 8px; font-size: 12px; max-width: 150px; }
}

/* ---------- 21. TIỆN ÍCH ---------- */

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

/* ---------- vùng in BCDT (khổ A4) ---------- */
.print-area { display: none; }

@media print {
  /* chỉ in vùng BCDT, không in giao diện app */
  .sidebar, .topbar, .head, .kpis, .tabs, .src-filter,
  .panel, .alert, .toast, .dialog, .gate, .row-btn, .close-actions,
  .close-banner, .close-grid, #day-empty
    { display: none !important; }
  .shell { grid-template-columns: 1fr; padding-left: 0; }
  main { max-width: none; padding: 0; }
  body { background: #fff !important; color: #000 !important; }

  .print-area {
    display: block !important;
    color: #000; font-size: 11px;
  }
  .print-area h2 {
    font-size: 15px; margin: 0 0 8px; letter-spacing: -.01em;
  }
  .print-area table {
    width: 100%; border-collapse: collapse; font-size: 10.5px;
  }
  .print-area th, .print-area td {
    border: 1px solid #bbb; padding: 3px 5px; text-align: left;
  }
  .print-area th { background: #f0f0f0; font-weight: 600; }
  .print-area td.num, .print-area th.num { text-align: right; }
  .print-area tfoot td { font-weight: 700; background: #f7f7f7; }

  /* hai dòng tổng kết: mỗi chỉ số một cụm, không dính chữ */
  .print-area .totals {
    display: flex; flex-wrap: wrap;
    gap: 4px 22px; margin: 8px 0 0;
  }
  .print-area .totals span { white-space: nowrap; }
  .print-area .totals strong { font-weight: 700; }

  @page { size: A4 landscape; margin: 10mm; }
}

/* ---------- nguồn hoá đơn (iPOS / nhập tay / gộp) ---------- */
.src-filter { display: flex; gap: 5px; margin-right: 10px; }
.src-btn {
  height: 26px; padding: 0 11px; border-radius: var(--radius-pill);
  border: 1px solid var(--line-strong); background: transparent;
  color: var(--ink-3); font-family: inherit; font-size: 11.5px; font-weight: 560;
  cursor: pointer; transition: background .15s var(--ease), color .15s var(--ease),
              border-color .15s var(--ease);
}
.src-btn:hover { color: var(--ink); border-color: var(--ink-3); }
.src-btn.is-active {
  background: var(--accent-soft); border-color: var(--accent-line);
  color: var(--accent-hover); font-weight: 620;
}
.c-src { width: 78px; }
.src-badge {
  display: inline-block; padding: 1px 8px; border-radius: var(--radius-pill);
  font-size: 10.5px; font-weight: 650; letter-spacing: .02em;
}
.src-ipos  { background: var(--info-soft); color: var(--info); }
.src-manual{ background: var(--warn-soft); color: var(--warn); }
.src-mixed { background: var(--ok-soft);   color: var(--ok); }
[data-theme="dark"] .src-ipos  { color: #c7d3ff; }
[data-theme="dark"] .src-manual{ color: #fbbf24; }
[data-theme="dark"] .src-mixed { color: #4ade80; }

/* ---------- chọn cách nhập hoá đơn ---------- */
.mode-switch {
  display: flex; gap: 8px; margin-bottom: 14px;
  padding-bottom: 12px; border-bottom: 1px solid var(--line-soft);
}
.mode-btn {
  flex: 1; height: 38px; border-radius: 9px;
  border: 1px solid var(--line-strong); background: transparent;
  color: var(--ink-3); font-family: inherit; font-size: 13px; font-weight: 560;
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
}
.mode-btn:hover { color: var(--ink); border-color: var(--ink-3); }
.mode-btn.is-active {
  background: var(--accent-soft); border-color: var(--accent-line);
  color: var(--accent-hover); font-weight: 620;
}
.ipos-list { margin-top: 8px; max-height: 210px; overflow: auto; }
.ipos-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  margin-bottom: 6px; cursor: pointer; font-size: 12.5px;
  transition: border-color .15s, background .15s;
}
.ipos-item:hover { border-color: var(--ink-3); background: var(--surface-2); }
.ipos-item.on { border-color: var(--accent); background: var(--accent-soft); }
.ipos-item .no { font-weight: 650; font-variant-numeric: tabular-nums; }
.ipos-item .meta { color: var(--ink-3); font-size: 11.5px; }
.ipos-item .amt { margin-left: auto; font-variant-numeric: tabular-nums; }
.ipos-item .has-ball { color: var(--ok); font-size: 11px; }

/* chưa đăng nhập: màn hình đăng nhập chiếm trọn, không có sidebar */
body.not-authed .gate { min-height: 100vh; }
body.not-authed .shell { padding-left: 0; }

/* ---------- thương hiệu: logo 1102 Central Club ---------- */
.sidebar-brand .mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(150deg, #f43f5e, #be123c);
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 3px 12px rgba(190,18,60,.35);
  overflow: hidden; display: grid; place-items: center;
}
.sidebar-brand .mark img { display: block; width: 24px; height: 24px; object-fit: contain; }


.gate-brand {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; margin-bottom: 20px;
}
.gate-brand img {
  width: 92px; height: 92px; object-fit: contain;
  filter: drop-shadow(0 4px 18px rgba(0,0,0,.5));
}
.gate-name {
  font-size: 17px; font-weight: 700; letter-spacing: -.02em;
}


/* in BCDT: tiêu đề có tên quán */
.print-area h2 small { font-weight: 400; font-size: 12px; }
