:root {
  --header: #1e88e5;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --text: #1a2330;
  --muted: #5c6b7a;
  --line: #d7dee7;
  --drop: #ffffff;
  --drop-text: #1a2330;
  --drop-hover: #e8f3fc;
  --ok: #43a047;
  --warn: #fb8c00;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Be Vietnam Pro", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.topbar {
  position: sticky; top: 0; z-index: 1000;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 0 12px;
  background: var(--header);
  box-shadow: 0 2px 10px rgba(0,0,0,.18);
  overflow: visible;
}
.logo { display: flex; align-items: center; line-height: 0; text-decoration: none; flex: 0 0 auto; }
.logo img { height: 40px; width: auto; display: block; object-fit: contain; }
.main-nav { display: flex; align-items: stretch; gap: 2px; flex: 1; min-width: 0; overflow: visible; }
.nav-item { position: relative; flex: 0 0 auto; z-index: 1001; }
.nav-btn {
  border: 0; background: transparent; color: #fff; font: inherit; font-weight: 600;
  font-size: .9rem; padding: 16px 11px; cursor: pointer; white-space: nowrap; border-radius: 8px;
}
.nav-btn:hover, .nav-item.open > .nav-btn { background: rgba(255,255,255,.16); }
.dropdown {
  position: absolute; top: calc(100% - 2px); left: 0; min-width: 230px;
  padding: 8px; border-radius: 10px; background: var(--drop); color: var(--drop-text);
  box-shadow: 0 14px 34px rgba(0,0,0,.22); display: none; z-index: 1100;
  border: 1px solid var(--line);
}
.nav-item.open > .dropdown { display: block; }
.dropdown button, .dropdown a {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 10px 12px; border-radius: 8px; color: var(--drop-text); font: inherit;
  font-weight: 600; font-size: .9rem; cursor: pointer; text-decoration: none;
}
.dropdown button:hover, .dropdown a:hover { background: var(--drop-hover); }
.right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.mail {
  position: relative; width: 38px; height: 38px; border: 0; border-radius: 8px;
  background: transparent; color: #fff; cursor: pointer; font-size: 1.1rem;
}
.mail:hover { background: rgba(255,255,255,.14); }
.badge {
  position: absolute; top: 6px; right: 6px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--ok); border: 2px solid var(--header);
}
.user { position: relative; display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 600; font-size: .9rem; cursor: pointer; border-radius: 8px; padding: 4px 6px; }
.user:hover, .user.open { background: rgba(255,255,255,.14); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(255,255,255,.55);
  background: #90caf9;
}
.user-menu {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 200px;
  padding: 8px; border-radius: 10px; background: var(--drop); color: var(--drop-text);
  box-shadow: 0 14px 34px rgba(0,0,0,.22); display: none; z-index: 1200;
  border: 1px solid var(--line);
}
.user.open > .user-menu { display: block; }
.user-menu button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 10px 12px; border-radius: 8px; color: var(--drop-text); font: inherit;
  font-weight: 600; font-size: .9rem; cursor: pointer;
}
.user-menu button:hover { background: var(--drop-hover); }
.user-lang-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 12px; margin-bottom: 4px; font-size: .9rem; font-weight: 600; color: var(--drop-text);
}
.user-lang-row select {
  min-width: 110px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line);
  font: inherit; font-weight: 600; background: #fff; color: var(--drop-text);
}
.profile-view { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px 18px; }
.profile-view .field { display: grid; gap: 4px; }
.profile-view .field span { font-size: .78rem; color: var(--muted); }
.profile-view .field strong { font-size: .92rem; font-weight: 600; color: var(--text); }
.profile-view .full { grid-column: 1 / -1; }
.pwd-form { display: grid; gap: 10px; max-width: 360px; }
.pwd-form label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); }
.pwd-form input {
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
.pwd-err { color: #c62828; font-size: .85rem; min-height: 1.2em; }
.btn-logout {
  border: 1px solid rgba(255,255,255,.35); background: transparent; color: #fff;
  border-radius: 8px; padding: 7px 10px; font: inherit; font-weight: 600; cursor: pointer;
}
.content { padding: 16px; min-height: calc(100vh - 56px); position: relative; z-index: 1; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
.panel h2 { margin: 0 0 12px; font-size: 1.15rem; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.panel-title-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0;
}
.panel-title-row h2 { margin: 0; }
.emp-search-wrap {
  position: relative; display: inline-flex; align-items: center; width: min(280px, 52vw);
}
.emp-search {
  width: 100%; padding: 7px 36px 7px 10px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; font-size: .85rem; background: #fff; color: var(--text);
}
.emp-search:focus { outline: 0; border-color: var(--header); }
.emp-search-btn {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  width: 32px; height: 30px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.emp-search-btn:hover { color: var(--header); background: #eef6fd; }
.panel-head h2 { margin: 0; }
.panel-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; align-items: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.toolbar input, .toolbar select, .modal input, .modal select, .modal textarea {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font: inherit;
}
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 8px; padding: 8px 12px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { background: #f3f6f9; }
.btn.primary { background: var(--header); border-color: var(--header); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: #c62828; border-color: #c62828; color: #fff; }
.hint { color: var(--muted); font-size: .85rem; }
.table-wrap {
  overflow-x: auto; overflow-y: auto; max-height: calc(100vh - 180px);
  border: 1px solid var(--line); border-radius: 10px; -webkit-overflow-scrolling: touch;
}
table.data {
  width: max-content; min-width: 100%; border-collapse: collapse;
  font-size: .78rem; background: #fff; table-layout: auto;
}
table.data th, table.data td {
  border-bottom: 1px solid var(--line); padding: 4px 5px; text-align: left; white-space: nowrap;
  vertical-align: middle;
}
table.data th {
  position: sticky; top: 0; background: #e8f1fb; z-index: 2; color: #123; font-weight: 700;
  text-align: center; overflow: hidden;
}
table.data th .th-inner {
  display: inline-flex; align-items: center; justify-content: center; gap: 3px;
  max-width: 100%; margin: 0 auto;
}
table.data th .sort-label {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
table.data tr:nth-child(even) td { background: #fafbfc; }
table.data tr:hover td { background: #eef6fd; }
table.data th.col-actions, table.data td.col-actions {
  position: sticky; right: 0; z-index: 1;
  background: #fff; box-shadow: -6px 0 8px rgba(16,24,40,.06);
}
table.data th.col-actions { z-index: 3; background: #e8f1fb; }
table.data tr:nth-child(even) td.col-actions { background: #fafbfc; }
table.data tr:hover td.col-actions { background: #eef6fd; }
table.data .col-actions .btn { padding: 4px 8px; min-width: 28px; font-size: .75rem; }
table.data td.col-actions { white-space: nowrap; }
.rate-timeline-modal { width: min(520px, calc(100vw - 32px)) !important; }
.rate-timeline {
  display: flex; flex-direction: column; gap: 8px;
  max-height: min(480px, 55vh); overflow: auto; padding: 4px 2px;
}
.rate-seg {
  display: grid;
  grid-template-columns: 92px 92px 108px 36px;
  gap: 8px; align-items: center;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #f7f9fc;
}
.rate-time {
  width: 100%; padding: 8px 8px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-weight: 700; color: var(--header); text-align: center; background: #fff;
  box-sizing: border-box;
}
.rate-type {
  width: 100%; padding: 6px 6px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: .85rem; font-weight: 600; background: #fff; box-sizing: border-box;
}
table.data input.cell, table.data select.cell, table.data textarea.cell {
  width: 100%; min-width: 0; max-width: 100%; padding: 3px 4px;
  border: 1px solid transparent; border-radius: 4px; background: transparent;
  color: var(--text); font: inherit; font-size: .78rem;
}
table.data textarea.cell { min-width: 0; max-width: none; min-height: 28px; width: 100%; resize: vertical; }
table.data td.note-cell {
  white-space: normal; vertical-align: top; min-width: 200px;
}
table.data td.note-cell textarea.cell {
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
  min-height: 48px; max-width: none; width: 100%; box-sizing: border-box;
}
table.data input.cell:focus, table.data select.cell:focus, table.data textarea.cell:focus {
  outline: 0; border-color: var(--header); background: #fff; box-shadow: 0 0 0 2px rgba(30,136,229,.15);
}
table.data input.cell.saving, table.data select.cell.saving { opacity: .7; }
table.data td.readonly { color: var(--muted); background: #f7f9fb; text-align: center; padding: 4px 6px; }
table.data .cell-xs { width: 52px; max-width: 56px; }
table.data .cell-sm { width: 68px; max-width: 78px; }
table.data .cell-md { width: 88px; max-width: 100px; }
table.data .cell-lg { width: 120px; max-width: 140px; }
table.data .cell-xl { width: 150px; max-width: 180px; }
table.data .cell-narrow { width: 56px; max-width: 64px; }
table.data .cell-mid { width: 90px; max-width: 110px; }
table.data .cell-wide { width: 130px; max-width: 160px; }
table.data th.sortable {
  cursor: pointer; user-select: none; white-space: nowrap;
}
table.data th.sortable .sort-label { margin-right: 2px; }
table.data th.sortable .sort-arrows {
  display: inline-flex; flex-direction: column; vertical-align: middle;
  line-height: .7; font-size: .65rem; color: #9aa8b6; margin-left: 2px;
}
table.data th.sortable .sort-arrows .up,
table.data th.sortable .sort-arrows .down { display: block; opacity: .35; }
table.data th.sortable.asc .sort-arrows .up { opacity: 1; color: var(--header); }
table.data th.sortable.desc .sort-arrows .down { opacity: 1; color: var(--header); }
table.data th.sortable:hover { color: var(--header); }
table.data td.stt { text-align: center; color: var(--muted); width: 40px; }
table.data.col-sized { table-layout: fixed; width: max-content; }
table.data th { overflow: hidden; text-overflow: ellipsis; }
table.data.admin-resize th { position: sticky; }
table.data .col-resizer {
  position: absolute; top: 0; right: -3px; width: 8px; height: 100%;
  cursor: col-resize; z-index: 6; user-select: none;
}
table.data .col-resizer::after {
  content: ""; position: absolute; top: 20%; bottom: 20%; left: 3px;
  width: 2px; background: transparent; border-radius: 1px;
}
table.data.admin-resize th:hover .col-resizer::after { background: rgba(30,136,229,.45); }
table.data.admin-resize.resizing { cursor: col-resize; user-select: none; }
table.data.admin-resize.resizing .col-resizer::after { background: var(--header); }
.combo { position: relative; width: 100%; max-width: 100%; }
.combo-input {
  width: 100%; padding: 3px 4px; border: 1px solid transparent; border-radius: 4px;
  background: transparent; color: var(--text); font: inherit; font-size: .78rem;
}
.combo-input:focus { outline: 0; border-color: var(--header); background: #fff; }
.combo-list {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 2px);
  max-height: 220px; overflow: auto; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 10px 24px rgba(16,24,40,.14);
}
.combo-list button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px 10px; font: inherit; font-size: .84rem; cursor: pointer; color: var(--text);
}
.combo-list button:hover, .combo-list button.active { background: #e8f3fc; }
.toast-save {
  position: fixed; right: 16px; bottom: 16px; z-index: 3000;
  background: #1b5e20; color: #fff; padding: 8px 12px; border-radius: 8px;
  font-size: .85rem; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.pager {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  margin-top: 10px; flex-wrap: wrap; font-size: .82rem; color: var(--muted);
}
.pager .btn { padding: 5px 10px; }
.pager strong { color: var(--text); }
.month-nav { align-items: center; display: inline-flex; gap: 6px; }
.month-nav.compact { display: inline-flex; align-items: center; gap: 6px; }
.month-nav .month-label {
  min-width: 130px; text-align: center; color: var(--text);
  background: #e8f1fb; border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; font-size: .9rem;
  white-space: nowrap;
}
.panel-actions.month-nav .month-label { color: var(--text); background: #e8f1fb; border: 1px solid var(--line); }
.auto-assign-wrap {
  overflow: visible;
  flex: 0 0 auto;
  min-height: 0;
  max-height: none;
  width: 100%;
  border: 0;
  background: transparent;
}
.auto-assign-table { width: 100%; table-layout: fixed; }
.auto-assign-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}
.auto-assign-table td {
  overflow: visible;
  white-space: normal;
}
.auto-assign-table th { overflow: hidden; }
.auto-assign-table td.center { text-align: center; vertical-align: middle; }
.auto-assign-table td[data-col="dept"] {
  position: relative;
  z-index: 1;
  overflow: visible;
}
.auto-assign-table tr:focus-within td[data-col="dept"],
.auto-assign-table td[data-col="dept"]:has(.rpt-dept-panel:not([hidden])) {
  z-index: 50;
}
.auto-assign-table .rpt-dept-wrap {
  width: 100%;
  max-width: 100%;
  position: relative;
  z-index: 1;
}
.auto-assign-table .rpt-dept-toggle,
.auto-assign-table select.auto-shift {
  width: 100%; max-width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: .85rem; background: #fff; text-align: left; box-sizing: border-box;
}
.auto-assign-table .rpt-dept-panel {
  z-index: 100;
  max-height: min(320px, 40vh);
  position: absolute;
  left: 0;
  right: auto;
  min-width: 100%;
  width: max(100%, 280px);
}
.auto-manual-btns {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: nowrap;
}
.auto-drag-cell { width: 36px; padding-left: 2px !important; padding-right: 2px !important; }
.auto-drag-handle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; cursor: grab; user-select: none;
  color: var(--muted); letter-spacing: -2px; font-size: .9rem;
  border-radius: 6px;
}
.auto-drag-handle:hover { color: var(--header); background: #eef6fd; }
.auto-drag-handle:active { cursor: grabbing; }
.auto-assign-table tr.dragging { opacity: .45; }
.auto-assign-table tr.drop-before td { box-shadow: inset 0 3px 0 0 var(--header); }
.auto-assign-table tr.drop-after td { box-shadow: inset 0 -3px 0 0 var(--header); }
.auto-assign-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.auto-add-row {
  margin-top: 8px;
  flex: 0 0 auto;
  align-self: flex-start;
}
.auto-add-row .btn { min-width: 36px; font-weight: 700; }
.auto-assign-hint {
  flex: 0 0 auto;
  margin: auto 0 0;
  padding-top: 12px;
  font-size: .78rem;
  font-style: italic;
  color: var(--muted);
  line-height: 1.4;
}
.modal-back .modal { width: min(920px, 100%); }
.modal-back.modal-back-top {
  align-items: flex-start;
  padding-top: 56px;
}
.modal.modal-top { margin-top: 0; }
.modal.auto-assign-modal {
  width: min(760px, calc(100vw - 32px));
  height: min(760px, calc(100vw - 32px), calc(100vh - 80px));
  max-width: 760px;
  max-height: calc(100vh - 80px);
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
}
.modal.auto-assign-modal h3 { flex: 0 0 auto; margin-bottom: 10px; }
.tree { overflow: auto; max-height: calc(100vh - 180px); }
.tree ul { list-style: none; margin: 0; padding-left: 22px; border-left: 1px solid #e2e8f0; margin-left: 10px; }
.tree > ul { padding-left: 0; border-left: 0; margin-left: 0; }
.tree li { margin: 3px 0; }
.tree .node {
  display: flex; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px;
  border: 1px solid transparent; flex-wrap: wrap; cursor: grab; background: #fff;
}
.tree .node:active { cursor: grabbing; }
.tree .node:hover { background: #f3f8fd; border-color: var(--line); }
.tree .node.dragging { opacity: .45; }
.tree .node.drop-before { box-shadow: inset 0 3px 0 0 var(--header); }
.tree .node.drop-after { box-shadow: inset 0 -3px 0 0 var(--header); }
.tree .node.drop-into { background: #e3f2fd; border-color: var(--header); }
.tree .drag-handle {
  color: var(--muted); font-size: .85rem; letter-spacing: -2px; user-select: none; cursor: grab;
}
.tree .code { color: var(--muted); font-size: .82rem; }
.tree .node-label { flex: 1; min-width: 120px; }

/* Bộ phận — layout trái/phải */
.dept-layout-panel {
  display: flex; flex-direction: column;
  height: calc(100vh - 88px); max-height: calc(100vh - 88px);
  min-height: 0; overflow: hidden;
}
.dept-layout-panel > .panel-head { flex: 0 0 auto; }
.dept-split {
  display: flex; gap: 0; flex: 1; min-height: 0;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff;
}
.dept-tree-pane {
  width: 220px; flex: 0 0 220px; min-width: 140px; max-width: none;
  border-right: 0; background: #fafbfc;
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.dept-split-resizer {
  flex: 0 0 5px; width: 5px; cursor: col-resize; background: #e2e8f0;
  position: relative; z-index: 2; align-self: stretch;
}
.dept-split-resizer:hover,
.dept-split.resizing .dept-split-resizer { background: var(--header); }
.dept-split-resizer.disabled { cursor: default; background: #e2e8f0; }
.dept-split.resizing { cursor: col-resize; user-select: none; }
.dept-emp-pane {
  flex: 1 1 auto; width: auto; min-width: 0; display: flex; flex-direction: column;
  padding: 8px 10px; background: #fff; min-height: 0; overflow: hidden;
}
.dept-emp-pane .panel-head { margin-bottom: 8px; }
.dept-emp-table-wrap {
  flex: 1; min-height: 0; min-width: 0;
  overflow-x: auto; overflow-y: auto;
  border: 1px solid var(--line); border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}
.dept-emp-table-wrap table.data {
  width: max-content; min-width: 100%; table-layout: fixed;
}
.dept-tree {
  flex: 1; min-height: 0;
  overflow-x: auto; overflow-y: auto;
  max-height: none; padding: 8px 6px 16px;
  -webkit-overflow-scrolling: touch;
}
.dept-tree .dept-tree-ul {
  list-style: none; margin: 0; padding: 0; position: relative;
}
.dept-tree .dept-tree-ul .dept-tree-ul {
  padding-left: 18px; margin-left: 12px;
  border-left: 1px solid #cfd8e3;
}
.dept-tree .dept-tree-li {
  position: relative; margin: 0; list-style: none;
}
.dept-tree .dept-tree-li.collapsed > .dept-tree-ul,
.dept-tree .dept-tree-li.collapsed > .dept-tree-children,
.dept-tree .dept-tree-children[hidden] { display: none !important; }
.dept-tree .dept-tree-children > .dept-tree-ul {
  padding-left: 18px; margin-left: 12px;
  border-left: 1px solid #cfd8e3;
}
.dept-tree .node {
  display: flex; align-items: center; gap: 6px; flex-wrap: nowrap;
  padding: 5px 8px; margin: 1px 4px; border-radius: 6px;
  border: 1px solid transparent; cursor: pointer; background: transparent;
  min-height: 30px;
}
.dept-tree .node:hover { background: #eef5fc; border-color: #d7e6f5; }
.dept-tree .node.selected {
  background: #e3f2fd; border-color: #90caf9;
}
.dept-tree .node.selected .node-label { color: #0d47a1; }
.dept-tree .node-label {
  flex: 0 1 auto; min-width: 0; font-weight: 600; font-size: .86rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dept-tree .dept-count {
  font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums;
}
.dept-tree .tree-toggle {
  flex: 0 0 20px; width: 20px; height: 20px; padding: 0; margin: 0;
  border: 1px solid #b0bec5; border-radius: 4px; background: #fff;
  color: #455a64; font-size: 14px; line-height: 18px; font-weight: 700;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  user-select: none;
}
.dept-tree .tree-toggle:hover { border-color: var(--header); color: var(--header); background: #e3f2fd; }
.dept-tree .tree-toggle.spacer {
  border: 0; background: transparent; cursor: default; visibility: hidden;
}
.dept-tree .drag-handle {
  flex: 0 0 auto; opacity: .45; font-size: .75rem; cursor: grab;
}
.dept-tree .node:hover .drag-handle { opacity: .85; }
.dept-emp-pane td.empty-cell {
  text-align: center; color: var(--muted); padding: 28px 12px; border: 0;
}
@media (max-width: 900px) {
  .dept-split { flex-direction: column; }
  .dept-tree-pane, .dept-emp-pane { width: 100%; max-width: none; }
  .dept-tree-pane { border-right: 0; border-bottom: 1px solid var(--line); max-height: 42vh; }
}
.empty { color: var(--muted); padding: 24px; text-align: center; }
.matrix-wrap { overflow: auto; max-height: calc(100vh - 220px); border: 1px solid var(--line); border-radius: 10px; background: #fff; }
table.matrix { border-collapse: collapse; font-size: .78rem; min-width: 100%; }
table.matrix th, table.matrix td {
  border: 1px solid var(--line); padding: 4px; text-align: center; min-width: 34px;
}
table.matrix th { position: sticky; top: 0; background: #e8f1fb; z-index: 2; }
table.matrix .sticky {
  position: sticky; left: 0; background: #fff; z-index: 1; text-align: left; min-width: 120px;
}
table.matrix .sticky.col-emp { left: 140px; min-width: 160px; box-shadow: 4px 0 6px rgba(16,24,40,.06); }
table.matrix .sticky.col-dept { left: 0; min-width: 140px; z-index: 2; }
table.matrix th.sticky { z-index: 3; background: #e8f1fb; }
table.matrix th.sortable { cursor: pointer; user-select: none; }
table.matrix th.sortable.asc .up, table.matrix th.sortable.desc .down { opacity: 1; color: var(--header); }
table.matrix .emp-name { font-weight: 700; line-height: 1.2; }
table.matrix .emp-sub { color: var(--muted); font-size: .72rem; line-height: 1.2; margin-top: 2px; }
table.matrix td.cell { cursor: cell; user-select: none; }
table.matrix td.cell.selected { outline: 2px solid var(--warn); outline-offset: -2px; background: #fff8e1; }
table.matrix td.cell.has { background: #e8f5e9; font-weight: 700; }
table.matrix td.cell.has.selected { background: #ffe0b2; }
table.matrix.ctrl-selecting { cursor: cell; }
.modal-back {
  position: fixed; inset: 0; background: rgba(15,23,42,.45); display: none;
  align-items: center; justify-content: center; z-index: 2000; padding: 16px;
}
.modal-back.show { display: flex; }
.modal {
  width: min(860px, 100%); max-height: 90vh; overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 16px;
}
.modal h3 { margin: 0 0 12px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.form-grid label { display: grid; gap: 4px; font-size: .82rem; color: var(--muted); }
.form-grid .full { grid-column: 1 / -1; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.map-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.map-table th, .map-table td { border-bottom: 1px solid var(--line); padding: 8px; text-align: left; }
.roles-assign { display: grid; gap: 12px; margin-bottom: 18px; }
.role-block {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fafcfe;
}
.role-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.role-name {
  margin: 0; min-width: 120px; font-size: .92rem; font-weight: 700; color: var(--header);
}
.role-members {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.role-member-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 8px 4px 10px;
  border-radius: 999px;
  background: #e8f1fb;
  border: 1px solid #c5daf0;
  font-size: .8rem;
  white-space: nowrap;
}
.role-member-row .btn {
  padding: 0 4px; min-width: 0; line-height: 1;
  color: #c62828; border: 0; background: transparent; cursor: pointer; font-size: .95rem;
}
.role-search { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.role-search input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: .85rem;
}
.role-suggest {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 2px);
  max-height: 240px; overflow: auto; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 10px 24px rgba(16,24,40,.14);
}
.role-suggest button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px 10px; font: inherit; font-size: .84rem; cursor: pointer;
}
.role-suggest button:hover { background: #e8f3fc; }
.role-suggest .muted { color: var(--muted); font-size: .75rem; }
.perm-matrix-head { margin: 4px 0 10px; }
.perm-matrix-head h3 { margin: 0; font-size: 1rem; }
table.perm-matrix { width: max-content; min-width: 100%; }
table.perm-matrix th.role-col, table.perm-matrix td.role-col { text-align: center; width: 110px; }
table.perm-matrix td.feat-label { white-space: nowrap; }
table.perm-matrix td.feat-child {
  padding-left: 28px; font-weight: 500;
  background-image: linear-gradient(transparent, transparent);
}
table.perm-matrix td.feat-child::before {
  content: "└ ";
  color: var(--muted);
  margin-right: 2px;
}
table.perm-matrix .feat-group {
  background: #eef3f8; font-weight: 700; color: var(--text); font-size: .88rem;
  padding-top: 10px; padding-bottom: 10px;
}
table.perm-matrix input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.agent-banner {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 8px; font-size: .85rem;
  border: 1px solid var(--line); background: #f3f6f9;
}
.agent-banner.on { background: #e8f5e9; border-color: #a5d6a7; color: #1b5e20; }
.agent-banner.off { background: #ffebee; border-color: #ef9a9a; color: #b71c1c; }
.badge-status {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .75rem; font-weight: 700;
}
.badge-status.on { background: #e8f5e9; color: #2e7d32; }
.badge-status.off { background: #ffebee; color: #c62828; }
.section-block { margin-top: 18px; }
.section-block h3 { margin: 0 0 8px; font-size: .98rem; }
.dl-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 10px;
}
.dl-bar label { display: grid; gap: 4px; font-size: .78rem; color: var(--muted); }
.dl-bar input[type="date"] {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit;
}
.dl-bar-inline {
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  margin: 0 0 10px;
}
.dl-bar-inline label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.dl-sep { color: var(--muted); padding: 0 2px; }
.compact-wrap { width: fit-content; max-width: 100%; }
table.data.compact-table {
  width: auto;
  table-layout: auto;
}
table.data.compact-table th,
table.data.compact-table td {
  padding: 4px 8px;
  white-space: nowrap;
  font-size: .82rem;
}
table.data.compact-table .cell {
  width: auto;
  min-width: 0;
  max-width: 160px;
  padding: 3px 6px;
  font-size: .82rem;
}
table.data.compact-table .cell-name { max-width: 140px; }
table.data.compact-table .cell-ip { max-width: 120px; }
table.data.compact-table .cell-port { width: 64px; max-width: 72px; }
table.data.compact-table .key-mask { font-size: .75rem; }
table.data.compact-table .nowrap { white-space: nowrap; }
.btn.icon-btn {
  min-width: 28px;
  padding: 4px 8px;
  line-height: 1.1;
}
.ico-key {
  display: inline-block;
  width: 14px;
  height: 14px;
  vertical-align: -2px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M7 14a5 5 0 1 1 4.9-6H22v3h-2v2h-2v2h-2v2h-3.1A5 5 0 0 1 7 14zm0-2a3 3 0 1 0 0-6 3 3 0 0 0 0 6z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M7 14a5 5 0 1 1 4.9-6H22v3h-2v2h-2v2h-2v2h-3.1A5 5 0 0 1 7 14zm0-2a3 3 0 1 0 0-6 3 3 0 0 0 0 6z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.table-add-row {
  margin-top: 6px;
  display: flex;
  justify-content: flex-start;
}
.devices-log {
  margin: 0;
  padding: 10px 12px;
  min-height: 120px;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fb;
  font-family: ui-monospace, Consolas, monospace;
  font-size: .8rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: #334;
}
table.data tr.row-disabled td { opacity: .55; }
td.center { text-align: center; }
.nav-item.nav-hidden { display: none !important; }
.dropdown button.perm-hidden { display: none !important; }
@media (max-width: 900px) {
  .logo img { height: 34px; width: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .user span { max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
}

/* Bao cao: title + bo loc cung 1 hang */
.rpt-panel { padding: 10px 12px; }
.rpt-panel .rpt-head {
  margin-bottom: 8px; gap: 10px 14px; align-items: center; flex-wrap: nowrap;
}
.rpt-panel .rpt-head h2 {
  margin: 0; flex: 0 0 auto; white-space: nowrap; font-size: 1.05rem;
}
.rpt-filters {
  display: flex; flex-wrap: nowrap; align-items: center; gap: 8px 10px;
  margin: 0; margin-left: auto; min-width: 0; flex: 1 1 auto;
  justify-content: flex-end;
}
.rpt-filters > label,
.rpt-filters .rpt-field {
  display: inline-flex; align-items: center; gap: 6px; margin: 0;
  font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap;
  min-width: 0;
}
.rpt-filters .rpt-field-lab { flex: 0 0 auto; }
.rpt-filters select,
.rpt-filters input[type="month"] {
  min-width: 0; width: 140px; padding: 5px 8px; border-radius: 6px; font-size: .82rem;
}
.rpt-filters #rpt-run { flex: 0 0 auto; padding: 6px 12px; white-space: nowrap; }
.rpt-filters #rpt-print {
  flex: 0 0 auto; padding: 5px 10px; font-size: 1.05rem; line-height: 1;
  min-width: 36px;
}
.rpt-filters .ms-wrap {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  min-width: 0; max-width: 240px;
}
.rpt-filters .ms-toggle {
  text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 6px;
  padding: 5px 8px; font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer;
  min-width: 140px; max-width: 200px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rpt-filters .ms-toggle:hover { background: #f3f6f9; }
.rpt-filters .rpt-dept-wrap { position: relative; width: min(200px, 28vw); flex: 0 1 200px; }
.rpt-filters .rpt-dept-toggle {
  width: 100%; text-align: left; padding: 5px 26px 5px 8px; border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 8px center;
  font: inherit; font-size: .82rem; color: var(--text); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ms-wrap { position: relative; display: grid; gap: 4px; min-width: 220px; }
.ms-wrap > label { font-size: .82rem; color: var(--muted); font-weight: 600; }
.ms-toggle {
  text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 8px 10px; font: inherit; font-weight: 600; cursor: pointer; min-width: 220px;
}
.ms-toggle:hover { background: #f3f6f9; }
.ms-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 40;
  width: min(360px, 90vw); max-height: 280px; overflow: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 28px rgba(16,24,40,.16); padding: 8px;
}
.ms-item { display: flex; gap: 8px; align-items: flex-start; padding: 6px 4px; font-size: .85rem; font-weight: 500; cursor: pointer; }
.ms-item:hover { background: #eef6fd; border-radius: 6px; }
.ms-all { border-bottom: 1px solid var(--line); margin-bottom: 4px; padding-bottom: 8px; font-weight: 700; }
.ms-list { display: grid; }
.rpt-dept-label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; min-width: 220px; }
.rpt-dept-wrap { position: relative; width: min(320px, 70vw); }
.rpt-dept-toggle {
  width: 100%; text-align: left; padding: 7px 28px 7px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E") no-repeat right 10px center;
  font: inherit; font-size: .85rem; color: var(--text); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rpt-dept-toggle:hover { border-color: var(--header); }
.rpt-dept-panel {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 40;
  max-height: min(360px, 50vh); overflow: auto; padding: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15,23,42,.12);
}
.rpt-dept-ul { list-style: none; margin: 0; padding: 0; }
.rpt-dept-ul .rpt-dept-ul {
  padding-left: 12px; margin-left: 10px;
  border-left: 1px solid #c5d0dc;
}
.rpt-dept-li { margin: 0; list-style: none; position: relative; }
.rpt-dept-item {
  display: flex; align-items: center; width: 100%;
  border: 0; background: transparent; text-align: left;
  padding: 5px 8px; margin: 1px 0; border-radius: 6px;
  font: inherit; font-size: .84rem; font-weight: 600; color: var(--text);
  cursor: pointer;
}
.rpt-dept-item:hover { background: #eef5fc; }
.rpt-dept-item.selected { background: #e3f2fd; color: #0d47a1; }
.rpt-dept-name {
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.settings-block { max-width: 640px; padding: 4px 2px 12px; }
.settings-lang {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 14px; font-size: .9rem; font-weight: 600;
}
.settings-lang-lab { color: var(--text); min-width: 88px; }
.settings-lang select {
  min-width: 180px; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; background: #fff;
}
.settings-check {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfc;
  cursor: pointer; font-size: .9rem;
}
.settings-check input { margin-top: 3px; width: 18px; height: 18px; flex: 0 0 auto; }
.settings-check .hint { display: block; margin-top: 4px; font-weight: 500; line-height: 1.35; }
.rpt-wrap {
  max-height: calc(100vh - 148px);
  overflow: auto;
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 8px;
}
@media (max-width: 1100px) {
  .rpt-panel .rpt-head { flex-wrap: wrap; }
  .rpt-filters { margin-left: 0; flex-wrap: wrap; justify-content: flex-start; width: 100%; }
}
table.rpt-detail {
  border-collapse: collapse;
  border: 1px solid #90a4ae;
  width: max-content;
  min-width: 100%;
}
table.rpt-detail th,
table.rpt-detail td {
  border: 1px solid #90a4ae;
  vertical-align: middle;
}
table.rpt-detail th { white-space: nowrap; background: #e3f2fd; }
table.rpt-detail th.rpt-metric-h {
  font-size: .68rem;
  font-weight: 700;
  line-height: 1.15;
  white-space: normal;
  max-width: 56px;
  padding: 4px 3px;
  text-align: center;
  vertical-align: bottom;
}
table.rpt-detail th.rpt-punch-h { font-size: .8rem; }
table.rpt-detail .rpt-date,
table.rpt-detail .rpt-name { white-space: nowrap; }
table.rpt-detail .rpt-time {
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  padding-bottom: 1px;
}
table.rpt-detail .rpt-dev {
  text-align: center;
  font-size: .72rem;
  color: var(--muted);
  padding-top: 1px;
}
table.rpt-detail .rpt-metric {
  text-align: center;
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
  padding: 2px 3px;
  white-space: nowrap;
}
/* 2 dòng giờ + máy: không kẻ ngang giữa chúng */
table.rpt-detail tr.rpt-main td.rpt-time,
table.rpt-detail tr.rpt-main td.rpt-dev {
  border-bottom: none;
}
table.rpt-detail tr.rpt-sub td.rpt-time,
table.rpt-detail tr.rpt-sub td.rpt-dev {
  border-top: none;
}
table.rpt-detail tr.rpt-main td[rowspan] {
  border-bottom: 1px solid #90a4ae;
}
table.rpt-detail .rpt-other { background: #fff8e1; }
table.rpt-detail tr.rpt-sub td.rpt-other { background: #fff8e1; }
table.rpt-detail tr.rpt-main:hover td,
table.rpt-detail tr.rpt-sub:hover td { background: #eef6fd; }

/* Bao cao tong hop */
table.rpt-summary {
  border-collapse: collapse;
  border: 1px solid #90a4ae;
  width: max-content;
  min-width: 100%;
  font-size: .78rem;
}
table.rpt-summary th,
table.rpt-summary td {
  border: 1px solid #90a4ae;
  padding: 2px 3px;
  vertical-align: middle;
  text-align: center;
}
table.rpt-summary thead th {
  background: #e3f2fd;
  font-weight: 700;
  white-space: nowrap;
  position: sticky; top: 0; z-index: 2;
}
table.rpt-summary th.sum-mnv,
table.rpt-summary td.sum-mnv {
  position: sticky; left: 0; z-index: 3; background: #fff; min-width: 52px;
}
table.rpt-summary thead th.sum-mnv { z-index: 4; background: #e3f2fd; }
table.rpt-summary th.sum-info,
table.rpt-summary td.sum-info {
  position: sticky; left: 52px; z-index: 3; background: #fff;
  min-width: 140px; max-width: 180px; text-align: left; white-space: normal;
  line-height: 1.25; font-size: .76rem;
}
table.rpt-summary thead th.sum-info { z-index: 4; background: #e3f2fd; text-align: center; }
table.rpt-summary .sum-pos,
table.rpt-summary .sum-bp { color: var(--muted); font-weight: 500; }
table.rpt-summary th.sum-day {
  min-width: 28px; max-width: 36px; font-size: .72rem; line-height: 1.1;
  vertical-align: bottom; padding: 3px 1px;
}
table.rpt-summary .sum-cn {
  display: block; color: #c62828; font-weight: 800; font-size: .65rem;
}
table.rpt-summary td.sum-val {
  font-variant-numeric: tabular-nums; font-weight: 600; min-width: 28px;
}
table.rpt-summary .sum-sun { background: #fff5f5; }
table.rpt-summary thead th.sum-sun { background: #ffebee; }
table.rpt-summary td.sum-rate,
table.rpt-summary th.sum-rate { font-weight: 700; min-width: 48px; background: #f7fafc; }
table.rpt-summary td.sum-total,
table.rpt-summary th.sum-total { font-weight: 700; min-width: 56px; }
table.rpt-summary td.sum-count,
table.rpt-summary th.sum-count { min-width: 52px; }
table.rpt-summary td.sum-leave,
table.rpt-summary th.sum-leave {
  min-width: 56px; max-width: 72px; font-size: .68rem; line-height: 1.15;
  white-space: normal; vertical-align: bottom; background: #fafbfc;
}
table.rpt-summary td.sum-workdays,
table.rpt-summary th.sum-workdays {
  font-weight: 700; min-width: 72px; background: #f0f7ff;
}
table.rpt-summary tr.sum-emp-end td { border-bottom: 2px solid #607d8b; }
table.rpt-summary tr.sum-row:not(.sum-emp-end) td.sum-val,
table.rpt-summary tr.sum-row:not(.sum-emp-end) td.sum-rate,
table.rpt-summary tr.sum-row:not(.sum-emp-end) td.sum-total,
table.rpt-summary tr.sum-row:not(.sum-emp-end) td.sum-count {
  border-bottom-style: dashed;
}
