:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #1f2937;
  --muted: #667085;
  --line: #d0d5dd;
  --accent: #7a3510;
  --accent-2: #612a0d;
  --good: #137a4c;
  --bad: #b42318;
  --warn: #b54708;
  --shadow: 0 18px 50px rgba(15, 23, 42, .08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, "Segoe UI", Arial, sans-serif;
}
button, input, select { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.auth-view {
  min-height: 100vh;
  background: #fff;
  display: grid;
  place-items: center;
  padding: 32px;
}
.brand-mark {
  position: fixed;
  top: 30px;
  left: 36px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
}
.mark-logo { width: 132px; height: 44px; display: inline-block; }
.auth-card {
  width: min(460px, 100%);
  padding: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0; font-size: 30px; letter-spacing: 0; }
.form { display: grid; gap: 16px; margin-top: 24px; }
.form label { display: grid; gap: 8px; font-weight: 650; }
.form input, .select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.form input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(122, 53, 16, .12); }
.form input[type="color"] { width: 64px; height: 42px; padding: 4px; cursor: pointer; }
.form input[type="file"] { padding: 8px 10px; }
.check { display: flex !important; grid-template-columns: auto 1fr; align-items: center; gap: 10px !important; color: var(--muted); font-weight: 500 !important; }
.check input { width: auto; }
.primary, .ghost, .link {
  border: 0;
  border-radius: 8px;
  padding: 11px 14px;
  cursor: pointer;
}
.primary { background: var(--accent); color: #fff; font-weight: 750; }
.primary:hover { background: var(--accent-2); }
.primary:disabled { opacity: .6; cursor: wait; }
.ghost { border: 1px solid var(--line); background: #fff; color: var(--text); }
.link { background: transparent; color: var(--accent); padding: 4px 0; text-align: left; }
.error { min-height: 18px; margin: 0; color: var(--bad); }
.app { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow: hidden;
}
.side-head { display: flex; align-items: center; gap: 12px; }
.side-logo { width: 112px; height: 36px; flex: 0 0 auto; }
.side-head small, .account small { display: block; color: var(--muted); }
#nav { display: grid; flex: 1 1 auto; align-content: start; gap: 4px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; padding-right: 2px; scrollbar-gutter: stable; }
.nav-group { margin: 14px 0 4px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
.nav-btn {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  cursor: pointer;
}
.nav-btn.active { background: #fff4ed; color: var(--accent); font-weight: 800; }
.account { margin-top: 0; flex: 0 0 auto; border-top: 1px solid var(--line); padding-top: 16px; display: grid; gap: 8px; }
.main { min-width: 0; min-height: 100vh; padding: 26px; overflow-x: hidden; overscroll-behavior: contain; touch-action: pan-y; }
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.topbar h1 { margin: 0; font-size: 28px; letter-spacing: 0; }
.topbar .select { max-width: 280px; margin-left: auto; }
.notice {
  min-height: 22px;
  margin-bottom: 10px;
  color: var(--muted);
}
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px; }
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .04);
}
.metric { grid-column: span 3; }
.metric span { color: var(--muted); }
.metric strong { display: block; margin-top: 8px; font-size: 24px; }
.metric.lead { background: #2f241f; color: #fff; }
.metric.lead span, .metric.lead strong { color: #fff; }
.panel { margin-top: 14px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.toolbar label { display: grid; gap: 6px; color: var(--muted); font-weight: 650; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 14px; border-bottom: 1px solid #edf0f3; text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; background: #fafafa; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.chip { display: inline-flex; border-radius: 999px; padding: 4px 9px; background: #eef2f6; color: var(--muted); font-size: 12px; font-weight: 750; }
.chip.good { background: #ecfdf3; color: var(--good); }
.chip.bad { background: #fef3f2; color: var(--bad); }
.chip.warn { background: #fffaeb; color: var(--warn); }
.two { grid-column: span 6; }
.full { grid-column: 1 / -1; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
}
.tile img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; background: #f2f4f7; }
.tile span { display: block; padding: 9px; }
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .62);
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal-card { position: relative; width: min(1100px, 100%); max-height: 90vh; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; background: #fff; border-radius: 8px; padding: 16px; }
.modal img, .modal video { width: 100%; max-height: 82vh; object-fit: contain; display: block; }
.icon-btn { position: absolute; top: 8px; right: 8px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: #fff; box-shadow: var(--shadow); cursor: pointer; font-size: 24px; }

/* ── Thư viện ảnh: thumbnail, hành động theo dòng, modal QR ─────────────── */
.thumb-wrap {
  display: inline-block; width: 56px; height: 56px;
  border-radius: 8px; overflow: hidden;
  background: #f2f4f7; border: 1px solid var(--line);
}
.thumb { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .15s ease; }
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.qr-card { width: min(360px, 100%); }
.qr-body { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 10px 4px; }
.qr-body img { width: 240px; height: 240px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.qr-link {
  font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px;
  color: var(--muted); text-align: center; word-break: break-all; text-decoration: none;
}
.qr-link:hover { color: var(--accent); }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; max-height: none; overflow: visible; }
  .metric, .two { grid-column: span 6; }
  .topbar { align-items: flex-start; flex-wrap: wrap; }
  .topbar .select { margin-left: 0; max-width: none; }
}
@media (max-width: 560px) {
  .auth-card { padding: 24px; }
  .brand-mark { position: static; margin-bottom: 18px; }
  .auth-view { display: block; }
  .metric, .two { grid-column: 1 / -1; }
}

/* ── Tạo mã chụp / đối soát doanh thu ───────────────────────────────────── */
.required { color: var(--bad); font-weight: 800; }
.quickpick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.quickpick .qp { padding: 6px 9px; font-size: 12px; border-radius: 8px; }
.countdown { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--warn); font-weight: 750; }
.code-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.code-pill { font-family: "Cascadia Mono", Consolas, monospace; font-size: 16px; font-weight: 850; letter-spacing: .08em; }

/* Bảng đối soát kiểu Excel */
.excel-wrap { max-height: 68vh; overflow: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
.excel-table { border-collapse: separate; border-spacing: 0; min-width: 1280px; }
.excel-table th, .excel-table td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background-clip: padding-box; }
.excel-table th:first-child, .excel-table td:first-child { border-left: 1px solid var(--line); }
.excel-table thead th { position: sticky; top: 0; z-index: 2; border-top: 1px solid var(--line); background: #f8fafc; }
.excel-table tbody tr:hover td { background: #fffaf5; }
.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.sortable:hover { color: var(--accent); background: #fff4ed; }
.accounting { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ghost.danger { border-color: #fecdca; color: var(--bad); }
.ghost.danger:hover { background: #fef3f2; }
.sc-row-check, #scSelectAll { width: 16px; height: 16px; cursor: pointer; }

/* ── Nhân viên / phân quyền / ca làm việc ───────────────────────────────── */

/* Nút VÀO CA: cố ý tách khỏi #nav và nằm cuối sidebar — đây là hành động vận
   hành hằng ngày, không phải một mục quản trị. */
.side-foot { margin-top: 0; flex: 0 0 auto; display: grid; gap: 10px; }
.shift-cta {
  width: 100%; border: 0; border-radius: 8px; padding: 13px 14px;
  background: var(--accent); color: #fff; cursor: pointer;
  font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
}
.shift-cta:hover { background: var(--accent-2); }
.shift-box { border: 1px solid var(--accent); border-radius: 8px; padding: 11px 12px; background: #fff4ed; display: grid; gap: 4px; }
.shift-box strong { color: var(--accent); font-size: 13px; }
.shift-box small { color: var(--muted); }
.shift-box .ghost { margin-top: 6px; padding: 8px 10px; }

/* Tab của trang Phân quyền & Người dùng */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tab {
  border: 0; background: transparent; cursor: pointer; padding: 11px 14px;
  color: var(--muted); font-weight: 700; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--accent); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Lưới checkbox phân quyền: nhóm theo module, không đổ một danh sách phẳng. */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 12px; }
.perm-group { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; background: #fff; }
.perm-group header { display: flex; align-items: center; gap: 8px; padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.perm-group header strong { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.perm-group header .link { margin-left: auto; font-size: 12px; padding: 0; }
.perm-item { display: flex; align-items: flex-start; gap: 9px; padding: 5px 0; cursor: pointer; }
.perm-item input { width: 16px; height: 16px; margin-top: 2px; flex: 0 0 auto; cursor: pointer; }
.perm-item span { line-height: 1.35; }
.perm-item code { font-family: "Cascadia Mono", Consolas, monospace; font-size: 11px; color: var(--muted); display: block; }
.perm-item.off span { color: var(--muted); }

/* ── Hộp thoại dùng chung ───────────────────────────────────────────────── */
.dialog-card { width: min(460px, 100%); padding: 22px 24px 18px; }
.dialog-card h2 { margin: 0 0 6px; font-size: 20px; }
.dialog-card .muted { margin: 0; }
.dialog-card .muted:empty { display: none; }
.dialog-card .form { margin-top: 16px; gap: 14px; }
.dialog-card .form:empty { display: none; margin-top: 0; }
.dialog-actions { justify-content: flex-end; margin-top: 4px; }
/* Tiến trình thao tác nhiều bước */
.pg-head { display: flex; align-items: baseline; gap: 12px; margin: 14px 0 8px; }
.pg-head strong { margin-left: auto; font-variant-numeric: tabular-nums; }
.pg-track { height: 8px; border-radius: 999px; background: #eef2f6; overflow: hidden; }
.pg-bar { height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width .18s ease; }
.pg-bar.done { background: var(--good); }
.pg-bar.failed { background: var(--bad); }
.pg-list { list-style: none; margin: 14px 0 0; padding: 0; max-height: 240px; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; touch-action: pan-y; display: grid; gap: 6px; }
.pg-list li { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); }
.pg-list li .pg-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: 0 0 auto; }
.pg-list li .pg-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pg-list li.run { color: var(--text); }
.pg-list li.run .pg-dot { background: var(--accent); }
.pg-list li.ok { color: var(--good); }
.pg-list li.ok .pg-dot { background: var(--good); }
.pg-list li.err { color: var(--bad); }
.pg-list li.err .pg-dot { background: var(--bad); }
.pg-list li small { margin-left: auto; }
@media (prefers-reduced-motion: reduce) { .pg-bar { transition: none; } }

.primary.danger-btn { background: var(--bad); }
.primary.danger-btn:hover { background: #922418; }
.link.danger-link { color: var(--bad); }

/* ── Chi nhánh ──────────────────────────────────────────────────────────── */

/* Cây chi nhánh trên sidebar: nút cha xổ ra 5 mục con thụt lề. */
.branch-head { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.branch-head .caret { width: 12px; flex: 0 0 auto; color: var(--muted); }
.branch-head small { margin-left: auto; color: var(--muted); font-weight: 500; }
.branch-head.active small { color: inherit; }
.branch-tree { display: grid; gap: 2px; margin: 2px 0 8px; padding-left: 14px; border-left: 2px solid var(--line); }
.branch-leaf { padding: 7px 12px; font-size: 13px; }

/* Nhóm sidebar (Cài đặt vận hành / Cài đặt giao diện): dùng lại kiểu cây chi nhánh.
   Nhóm lồng trong cây chi nhánh thu nhỏ theo cỡ mục con. */
.nav-group-head.has-active { color: var(--accent); }
.branch-tree .nav-group-head { padding: 7px 12px; font-size: 13px; }
.branch-tree .branch-tree { margin: 0 0 4px; padding-left: 10px; }

/* Lưới thẻ chi nhánh — dùng riêng thay vì .grid 12 cột để thẻ tự xuống dòng. */
.branch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.branch-card { display: grid; gap: 10px; align-content: start; }
.branch-card header { display: flex; align-items: center; gap: 10px; }
.branch-card header strong { font-size: 17px; }
.branch-card p { margin: 0; }
.branch-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.branch-stats span { display: block; color: var(--muted); font-size: 12px; }
.branch-stats strong { display: block; margin-top: 3px; font-size: 15px; font-variant-numeric: tabular-nums; }

/* ── Thư viện khung ảnh ─────────────────────────────────────────────────── */
.frame-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.frame-card { display: grid; gap: 8px; align-content: start; border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; }
.frame-card strong { font-size: 14px; word-break: break-word; }
.frame-card small { font-variant-numeric: tabular-nums; }
/* Nền ca-rô để thấy rõ vùng trong suốt của khung PNG. */
.frame-thumb {
  display: grid; place-items: center; height: 150px; border-radius: 6px; overflow: hidden;
  border: 1px solid var(--line);
  background-color: #fff;
  background-image: linear-gradient(45deg, #eef1f4 25%, transparent 25%, transparent 75%, #eef1f4 75%),
                    linear-gradient(45deg, #eef1f4 25%, transparent 25%, transparent 75%, #eef1f4 75%);
  background-size: 14px 14px;
  background-position: 0 0, 7px 7px;
}
.frame-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.frame-pick { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); cursor: pointer; }
.frame-pick input { width: 16px; height: 16px; cursor: pointer; }

/* Màn hình báo thiếu quyền — thay vì để nhân viên bấm vào rồi mới báo lỗi. */
.denied { text-align: center; padding: 40px 20px; }
.denied strong { display: block; font-size: 18px; margin-bottom: 6px; }

/* Cài đặt vận hành: Thanh toán / Hình nền / Bộ lọc màu */
.set-note { margin: 0 0 14px; line-height: 1.5; }
.set-card { display: grid; gap: 14px; margin-bottom: 14px; }
.set-card h2 { margin: 0; font-size: 16px; }
.set-card .toolbar { margin-bottom: 0; align-items: center; justify-content: space-between; }
.set-card .set-note { margin: 0; }
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 18px; }
.set-grid.po-grid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.set-field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.set-field .select { width: 100%; box-sizing: border-box; }
.set-field small { font-size: 12px; }
.set-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-weight: 650; }
.set-head .link { padding: 0; font-size: 12px; }
.set-toggle { display: flex; align-items: center; gap: 10px; color: var(--muted); cursor: pointer; }
.set-toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.set-toggle input:disabled { cursor: not-allowed; }
.set-actions { display: flex; justify-content: flex-end; gap: 10px; }
.po-table .table-wrap table { width: 100%; }
.po-table td, .po-table th { padding: 6px 8px; }
.po-table .po-input { width: 100%; max-width: 140px; box-sizing: border-box; text-align: right; }
.po-table tr.po-off td { opacity: .45; }
.bg-card.dim { opacity: .5; }
.bg-card .select { width: 100%; box-sizing: border-box; }
.frame-thumb .muted { padding: 10px; text-align: center; font-size: 12px; }
.lut-canvas { display: block; width: 100%; max-width: 100%; height: auto; aspect-ratio: 8 / 5; border: 1px solid var(--line); border-radius: 6px; background: #f2f4f7; }

.revenue-total-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  background: #fff7ed;
  color: var(--accent-2);
  font-weight: 750;
}
.revenue-total-bar:empty { display: none; }
.revenue-total-bar strong { margin-right: 4px; }
.revenue-total-bar span { white-space: nowrap; }
.excel-table tbody tr.revenue-total td {
  position: sticky;
  /* Chiều cao tiêu đề bảng đo bằng JS (renderRevenueRows); 42px chỉ là dự phòng. */
  top: var(--rev-head-h, 42px);
  z-index: 1;
  background: #fff7ed;
  color: var(--accent-2);
  font-weight: 800;
  box-shadow: inset 0 -1px 0 var(--line);
}
.excel-table tbody tr.revenue-total:hover td { background: #fff7ed; }
.filter-thumb {
  width: 100%;
  aspect-ratio: 8 / 5;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #f2f4f7;
}
.filter-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.filter-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.filter-title strong { min-width: 0; overflow-wrap: anywhere; }
.filter-star {
  flex: 0 0 auto; border: 0; background: transparent; padding: 0 2px;
  font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer;
}
.filter-star.on { color: #d4a017; }
.filter-star:hover:not(:disabled) { transform: scale(1.12); }
.filter-star:disabled { cursor: default; opacity: .55; }
.set-number { display: flex; align-items: center; gap: 8px; }
.set-number input { flex: 1; min-width: 0; }
.set-number .muted { flex: 0 0 auto; font-size: 13px; }