:root {
  --blue: #2d7ff9;
  --blue-d: #1f6fe5;
  --blue-grad: linear-gradient(135deg, #3a8bff, #2d7ff9);
  --bg: #eef3fb;
  --card: #ffffff;
  --text: #1f2a44;
  --muted: #8a96a8;
  --border: #eef1f6;
  --border-2: #e3e9f2;
  --danger: #e5484d;
  --ok: #29a36a;
  --shadow: 0 10px 30px rgba(45, 127, 249, 0.10);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, Arial, sans-serif;
  background: linear-gradient(160deg, #cfe2ff 0%, #eef3fb 45%, #eef3fb 100%);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
a { text-decoration: none; color: inherit; cursor: pointer; }

/* ===== Login ===== */
.login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
}
.login-card {
  width: 380px; background: var(--card); border-radius: 18px; padding: 32px;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-card h2 { margin: 0 0 4px; }
.login-hint { color: var(--muted); margin: 0 0 18px; font-size: 13px; }
.login-card label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.login-card input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border-2); border-radius: 10px;
  font-size: 14px; margin-bottom: 16px; outline: none;
}
.login-card input:focus { border-color: var(--blue); }
.btn-block { width: 100%; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* OTP đăng nhập */
#login-otp { text-align: center; letter-spacing: 8px; font-size: 20px; font-weight: 700; }
.login-otp-actions { display: flex; justify-content: space-between; margin-top: 4px; }
.btn-link {
  background: none; border: none; color: var(--blue); font-weight: 600; font-size: 13px;
  cursor: pointer; padding: 4px 2px;
}
.btn-link:hover { text-decoration: underline; }
.btn-link:disabled { color: var(--muted); cursor: default; text-decoration: none; }

/* Modal người dùng (form xếp dọc) */
#user-form .form-row label { display: block; margin-bottom: 5px; }
#user-form input[type="text"], #user-form select { width: 100%; box-sizing: border-box; }
#users-table td { vertical-align: middle; }

/* Phân quyền: ẩn control ghi với viewer, ẩn control admin với non-admin */
/* Ẩn mọi nút thao tác trong bảng (sửa/xóa nguồn & đấu nối) trừ nút Lịch sử (🕑 .hist) */
body.cannot-edit .js-edit-only,
body.cannot-edit .row-btn:not(.hist):not(.map2d),
body.cannot-edit .trash-acts,
body:not(.is-admin) .js-admin-only { display: none !important; }

/* Phân quyền theo KHU VỰC dữ liệu (bậc thang — xem ROLE_LEVEL trong server/index.js):
   admin > editor_source > editor_conn > editor_vtdp > viewer */
body:not(.can-edit-conn) .js-edit-conn,
body:not(.can-edit-source) .js-edit-source,
body:not(.can-edit-vtdp) .js-edit-vtdp { display: none !important; }

/* Nút thao tác trong bảng — luôn GIỮ nút chỉ xem: lịch sử 🕑 và sơ đồ 2D 🗺️ */
body:not(.can-edit-conn) #table-body .row-btn:not(.hist):not(.map2d),
body:not(.can-edit-source) #devices-body .row-btn:not(.map2d),
body:not(.can-edit-source) #odfs-body .row-btn:not(.map2d) { display: none !important; }
.role-badge { padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.role-admin { background: #dbeafe; color: #1e40af; }
.role-editor { background: #fef3c7; color: #92400e; }
.role-viewer { background: #f1f5f9; color: #475569; }

/* Trang Cài đặt: 2 cột — cấu hình bot trái, danh sách user phải */
.settings-grid { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.settings-grid #bot-config-card { flex: 0 0 640px; max-width: 640px; }
.settings-grid #users-card { flex: 1 1 520px; min-width: 0; }
@media (max-width: 1100px) {
  .settings-grid #bot-config-card,
  .settings-grid #users-card { flex: 1 1 100%; max-width: 100%; }
}

/* Bảng người dùng: khung cuộn cao cố định -> thanh cuộn NGANG luôn ở đáy khung (thấy ngay,
   không phải kéo xuống cuối bảng). Header dính trên, 2 cột đầu (Mã NV + Họ tên) khóa cứng.
   Chỉ áp dụng desktop — mobile (≤820px) đổi sang chế độ thẻ nên không khóa cột. */
@media (min-width: 821px) {
  #users-card .table-wrap { max-height: 60vh; overflow: auto; }
  #users-table th:nth-child(1), #users-table td:nth-child(1),
  #users-table th:nth-child(2), #users-table td:nth-child(2) {
    position: sticky; z-index: 2; box-sizing: border-box;
  }
  #users-table th:nth-child(1), #users-table td:nth-child(1) { left: 0;     width: 90px;  min-width: 90px;  max-width: 90px; }
  #users-table th:nth-child(2), #users-table td:nth-child(2) { left: 90px;  width: 200px; min-width: 200px; max-width: 200px; white-space: normal; border-right: 1px solid var(--border-2); }
  /* nền đục cho ô khóa cứng (che nội dung cuộn phía sau), khớp màu sọc + hover */
  #users-table tbody td:nth-child(1), #users-table tbody td:nth-child(2) { background: #fff; }
  #users-table tbody tr:nth-child(even) td:nth-child(1),
  #users-table tbody tr:nth-child(even) td:nth-child(2) { background: #f7fafe; }
  #users-table tbody tr:hover td:nth-child(1),
  #users-table tbody tr:hover td:nth-child(2) { background: #eef5ff; }
  /* góc trên-trái (2 ô header đầu) phải nằm trên cùng + giữ nền header */
  #users-table thead th:nth-child(1), #users-table thead th:nth-child(2) { z-index: 6; background: #f4f8ff; }
}

/* Thanh phân trang bảng user */
.users-pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; flex-wrap: wrap; font-size: 13px; color: #475569; }
.users-pager select { padding: 5px 8px; border: 1px solid var(--border-2); border-radius: 8px; margin: 0 4px; }
.users-pager-nav { display: flex; align-items: center; gap: 10px; }

/* ===== Brand / logo ===== */
.logo-badge {
  width: 38px; height: 38px; border-radius: 10px; background: var(--blue-grad);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; flex: 0 0 auto;
}
.brand-title { font-weight: 800; letter-spacing: .3px; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 12px; margin-top: 1px; }

/* ===== App layout ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 78px; background: var(--card); padding: 22px 16px; display: flex; flex-direction: column;
  gap: 18px; border-right: 1px solid var(--border);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-x: hidden;
  overflow-y: auto;
  white-space: nowrap;
  flex-shrink: 0;
  /* Ghim cứng sidebar khi cuộn trang (desktop) — mobile dùng position:fixed riêng bên dưới */
  position: sticky;
  top: 0;
  height: 100vh;
  align-self: flex-start;
}
.sidebar:hover {
  width: 250px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px; overflow: hidden; }
.nav { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 12px 14px; border-radius: 12px;
  color: #5b677d; font-weight: 600;
  overflow: hidden;
}
.nav-item:hover { background: #f3f7ff; }
.nav-item.active { background: var(--blue-grad); color: #fff; box-shadow: 0 8px 18px rgba(45,127,249,.32); }
.nav-ico { font-size: 16px; }
.sidebar-footer { margin-top: auto; color: var(--muted); font-size: 12px; padding: 0 6px; line-height: 1.5; }
.login-copyright { margin-top: 16px; text-align: center; color: var(--muted); font-size: 12px; }

/* Nút thao tác trong Thùng rác */
.trash-acts .btn { white-space: nowrap; }
.trash-acts .btn + .btn { margin-left: 8px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px;
  /* Ghim cứng topbar ở trên cùng khi cuộn (nền mờ + đổ bóng nhẹ để tách khỏi nội dung) */
  position: sticky; top: 0; z-index: 40;
  background: rgba(238, 243, 251, 0.88);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgba(30, 42, 68, 0.05);
}
.page-title { font-size: 22px; font-weight: 800; }
.app-copyright { color: var(--muted); font-size: 12px; white-space: nowrap; margin-left: auto; margin-right: 18px; }
.last-update { color: var(--muted); }
.user-box { display: flex; align-items: center; gap: 12px; }
.user-greet { font-size: 14px; color: #4a5667; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--blue-grad); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}

.content { padding: 6px 28px 32px; flex: 1; }

/* ===== Card ===== */
.card { background: var(--card); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 18px 20px; flex-wrap: wrap;
}
.card-tabs .tab { font-weight: 700; color: var(--text); }
.card-tabs .tab.active { color: var(--text); }
.card-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ===== Buttons / inputs ===== */
.btn {
  border: none; border-radius: 10px; padding: 9px 16px; font-weight: 600; cursor: pointer;
  font-size: 13.5px; transition: .15s;
}
.btn-primary { background: var(--blue-grad); color: #fff; box-shadow: 0 8px 16px rgba(45,127,249,.28); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: #f1f5fc; color: #4a5667; }
.btn-ghost:hover { background: #e7eefb; }
.btn-danger { background: #fdecec; color: var(--danger); }
.btn-danger:hover { background: #fbdcdc; }
.btn-outline { background: #fff; border: 1px solid var(--border-2); color: #4a5667; }
.btn-outline:hover { background: #f7f9fc; border-color: var(--blue); color: var(--blue-d); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
/* Thẻ <a> dùng làm nút (vd Export): canh giữa + bỏ gạch chân, giống <button> */
a.btn { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; vertical-align: middle; }
.search-input {
  padding: 9px 13px; border: 1px solid var(--border-2); border-radius: 10px; outline: none; min-width: 180px;
  font-size: 13.5px;
}
.search-input:focus { border-color: var(--blue); }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.data-table thead th {
  background: #f4f8ff; color: #59647a; font-weight: 700; text-align: left;
  padding: 13px 12px; font-size: 12.5px; position: sticky; top: 0; z-index: 5; border-bottom: 1px solid var(--border-2);
  cursor: pointer; user-select: none;
}
.data-table thead th.no-sort { cursor: default; }
.data-table th .sort-ind { color: var(--blue); margin-left: 4px; font-size: 11px; }
.data-table tbody td {
  padding: 12px 12px; border-bottom: 1px solid var(--border); font-size: 13px; color: #2b3550;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis;
}
.data-table tbody tr:nth-child(even) { background: #f7fafe; }
.data-table tbody tr:hover { background: #eef5ff; }
/* Dòng lọc dính ngay DƯỚI hàng tên cột — top = chiều cao thật của hàng tên cột (đặt qua JS),
   z-index cao hơn để phủ gọn viền; cả hai hàng đều nằm trên thân bảng khi cuộn. */
.filter-row th { padding: 6px 8px; background: #fff; position: sticky; top: var(--conn-head-h, 44px); z-index: 6; }
.filter-row input, .filter-row select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border-2); border-radius: 7px; font-size: 12.5px;
  outline: none; background: #fff;
}
.filter-row input:focus, .filter-row select:focus { border-color: var(--blue); }
.col-actions { white-space: nowrap; }
.row-btn {
  border: none; background: #f1f5fc; color: #5b677d; border-radius: 8px; cursor: pointer;
  font-size: 15px; line-height: 1; margin-right: 5px; width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
}
.row-btn:hover { background: #e7eefb; }
.row-btn.del:hover { background: #fbdcdc; color: var(--danger); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.card-foot {
  display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; flex-wrap: wrap; gap: 10px;
}
.page-size select { padding: 6px 8px; border: 1px solid var(--border-2); border-radius: 8px; }
.pager { display: flex; gap: 6px; align-items: center; }
.pager button {
  border: 1px solid var(--border-2); background: #fff; border-radius: 8px; padding: 6px 11px; cursor: pointer;
}
.pager button.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.pager button:disabled { opacity: .45; cursor: default; }

/* ===== Bảng đấu nối: giữ tiêu đề + bộ lọc cố định, chỉ cuộn phần thân ===== */
@media (min-width: 821px) {
  /* Card cao tối đa bằng màn hình -> card-head (tiêu đề + tìm kiếm + nút) và thead (tên cột +
     bộ lọc, đều position:sticky) đứng yên, chỉ thân bảng cuộn. Thanh cuộn ngang dưới luôn thấy. */
  #view-connections .card { display: flex; flex-direction: column; max-height: calc(100vh - 96px); }
  #view-connections .table-wrap { flex: 1 1 auto; min-height: 0; overflow: auto; }
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(30,42,68,.45); display: flex; align-items: center;
  justify-content: center; z-index: 50; padding: 20px;
}
.modal { background: #fff; border-radius: 16px; width: 720px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-close { border: none; background: none; font-size: 26px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 20px 22px; overflow-y: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-body .field { display: flex; flex-direction: column; gap: 5px; }
.modal-body .field.full { grid-column: 1 / -1; }
.modal-body label { font-weight: 600; font-size: 12.5px; color: #5b677d; }
.modal-body input, .modal-body textarea {
  padding: 9px 11px; border: 1px solid var(--border-2); border-radius: 9px; font-size: 13.5px; outline: none;
  font-family: inherit;
}
.modal-body input:focus, .modal-body textarea:focus { border-color: var(--blue); }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }

/* ===== Logs ===== */
.badge { padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge.CREATE { background: #e6f7ee; color: var(--ok); }
.badge.UPDATE { background: #e7f0ff; color: var(--blue-d); }
.badge.DELETE { background: #fdecec; color: var(--danger); }
/* Key trong Lịch sử: XANH = còn đúng với log; XÁM = bản ghi đã xóa (Key có thể đã đổi chủ) */
.key-tag { display: inline-block; min-width: 24px; text-align: center; padding: 2px 8px; border-radius: 20px; font-weight: 700; font-size: 12.5px; }
.key-tag.key-live { background: #e6f7ee; color: var(--ok); }
.key-tag.key-stale { background: #eceff3; color: #97a0ad; }
.key-na { color: #b4bcc7; }
.changes-cell { white-space: normal; font-size: 12.5px; color: #4a5667; }
.changes-cell .chg { margin: 2px 0; }
.changes-cell .fname { font-weight: 700; }
.changes-cell .old { color: var(--danger); text-decoration: line-through; }
.changes-cell .new { color: var(--ok); }

/* ===== Toast ===== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2a44; color: #fff; padding: 12px 20px; border-radius: 10px; z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 13.5px;
}
.toast.ok { background: #1c7a4c; }
.toast.err { background: #c23a3f; }

/* ===== Dashboard ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}
.dashboard-grid.col-2 {
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
}
.mt-20 { margin-top: 20px; }
.dash-card {
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 24px;
  position: relative;
  overflow: hidden;
}
.dash-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; width: 100%; height: 6px;
}
.dash-card:nth-child(1)::before { background: linear-gradient(90deg, #ff7a18, #af002d 30%, #319197 60%, #ff7a18); background-size: 200% 100%; animation: gradientPan 4s linear infinite; }
.dash-card:nth-child(2)::before { background: linear-gradient(90deg, #00d2ff 0%, #3a7bd5 100%); }

.summary-card {
  display: flex;
  align-items: center;
  gap: 20px;
}
.summary-card.gradient-blue {
  background: linear-gradient(135deg, #3a8bff, #2d7ff9);
  color: white;
}
.summary-card.gradient-green {
  background: linear-gradient(135deg, #1ddb9a, #10b981);
  color: white;
}
.summary-card.gradient-blue .dash-title, .summary-card.gradient-green .dash-title {
  color: rgba(255, 255, 255, 0.85);
}
.dash-icon {
  font-size: 42px;
  background: rgba(255,255,255,0.2);
  width: 80px; height: 80px;
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
.dash-info { flex: 1; }
.dash-title {
  font-size: 15px; font-weight: 600; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px;
}
.dash-value {
  font-size: 38px; font-weight: 800; line-height: 1;
}

.dash-card-title {
  margin: 0 0 20px 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border-2);
  padding-bottom: 12px;
}

@keyframes gradientPan {
  0% { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}

/* ===== Dashboard: donut phòng máy + chú thích dùng chung ===== */
.dash-legend {
  display: flex; flex-wrap: wrap; gap: 8px 20px;
  justify-content: center; margin-bottom: 18px;
}
.dash-legend .lg {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 13.5px; font-weight: 600; color: #475569;
}
.dash-legend .sw { width: 13px; height: 13px; border-radius: 4px; flex: none; }

.donut-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px;
}
.donut-box {
  display: flex; flex-direction: column; align-items: center;
  padding: 14px 8px; border-radius: 16px;
  background: linear-gradient(180deg, #fafcff, #f3f6fc);
  border: 1px solid var(--border-2);
  transition: transform .18s ease, box-shadow .18s ease;
}
.donut-box:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(45,127,249,.12); }
.donut-wrap { position: relative; width: 100%; max-width: 220px; height: 200px; margin: 0 auto; }
.donut-wrap canvas { max-width: 100% !important; }
.donut-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; color: #aab4c2; font-weight: 600; font-size: 13px; line-height: 1.4;
}
.donut-room {
  margin-top: 12px; font-weight: 800; font-size: 15px; color: var(--text);
  letter-spacing: .3px;
}

/* Viền màu trên các card biểu đồ ở Dashboard (cho đồng bộ, đẹp) */
#view-dashboard > .dash-card::before { background: linear-gradient(90deg, #3a8bff, #1ddb9a); }

@media (max-width: 980px) { .donut-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .donut-grid { grid-template-columns: 1fr; } }

/* ===== Mobile: nút menu + lớp phủ (ẩn trên desktop) ===== */
.hamburger {
  display: none; background: #f1f5fc; border: none; border-radius: 10px;
  width: 40px; height: 40px; font-size: 20px; cursor: pointer; color: #4a5667;
}
.sidebar-overlay { display: none; }
.logout-ico { display: none; }

/* =========================================================
   RESPONSIVE — tối ưu cho điện thoại (<= 820px)
   ========================================================= */
@media (max-width: 820px) {
  /* Sidebar trượt từ trái */
  .hamburger { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 260px; z-index: 60;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.25);
  }
  .sidebar:hover { width: 260px; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show {
    display: block; position: fixed; inset: 0; background: rgba(30,42,68,.45); z-index: 55;
  }

  /* Topbar gọn */
  .topbar { padding: 11px 12px; gap: 10px; }
  .app-copyright { display: none; } /* ẩn trên mobile cho gọn */
  .page-title { font-size: 18px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .user-box { gap: 8px; }
  .user-greet { font-size: 12px; max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .avatar { display: none; }
  .logout-text { display: none; }
  .logout-ico { display: inline; font-size: 16px; }
  #logout-btn { padding: 8px 11px; }

  .content { padding: 8px 10px 24px; }

  /* Thanh công cụ của card: tìm kiếm full, nút chia hàng */
  .card-head { padding: 12px; gap: 10px; }
  .card-actions { width: 100%; flex-wrap: wrap; gap: 8px; }
  .card-actions .search-input { flex: 1 1 100%; min-width: 0; }
  .card-actions .btn { flex: 1; }
  #toggle-filter { display: none; } /* lọc theo cột không dùng ở chế độ thẻ */

  /* Bảng -> thẻ (mỗi dòng là 1 thẻ "Nhãn: giá trị") */
  .table-wrap { overflow-x: visible; }
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tbody tr {
    margin: 0 0 16px; border: 1px solid var(--border-2); border-radius: 12px;
    overflow: hidden; background: #fff; box-shadow: 0 3px 10px rgba(45,127,249,.07);
  }
  .data-table tbody td {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
    padding: 9px 13px; border-bottom: 1px solid var(--border);
    white-space: normal; max-width: none; text-align: right; word-break: break-word;
  }
  .data-table tbody td::before {
    content: attr(data-label); font-weight: 700; color: #59647a; text-align: left;
    flex: 0 0 42%;
  }
  .data-table tbody td:last-child { border-bottom: none; }
  /* Thùng rác: 2 nút Khôi phục / Xóa hẳn nằm cạnh nhau, đều bề rộng, không xuống dòng */
  .data-table tbody td.trash-acts { gap: 10px; padding: 12px 13px; }
  .data-table tbody td.trash-acts::before { display: none; }
  .data-table tbody td.trash-acts .btn { flex: 1; margin: 0; padding: 11px 8px; }
  /* Phân biệt GIỮA CÁC THẺ: xen kẽ màu nền theo từng bản ghi */
  .data-table tbody tr:nth-child(odd)  { background: #ffffff; }
  .data-table tbody tr:nth-child(even) { background: #eef4fc; }
  .data-table tbody td { background: transparent; } /* ô trong suốt để lộ nền thẻ */
  /* Ô STT = "đầu thẻ", nổi bật để thấy rõ chỗ bắt đầu mỗi bản ghi */
  .data-table tbody td:first-child {
    background: rgba(45,127,249,.12); font-weight: 700; color: var(--blue-d);
  }
  /* Ô "Thay đổi" trong log: xếp dọc cho dễ đọc */
  .data-table tbody td.changes-cell { flex-direction: column; text-align: left; }
  .data-table tbody td.changes-cell::before { flex: none; margin-bottom: 4px; }

  /* Nút thao tác trên thẻ: to hơn cho dễ bấm */
  .col-actions { justify-content: flex-end; }
  .row-btn { width: 38px; height: 38px; font-size: 17px; }

  /* Phân trang */
  .card-foot { flex-direction: column; align-items: stretch; gap: 12px; }
  .pager { justify-content: center; flex-wrap: wrap; }
  .pager button { padding: 9px 13px; }

  /* Modal kiểu bottom-sheet, 1 cột */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { width: 100%; max-width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; }
  .modal-body { grid-template-columns: 1fr; padding: 16px; }

  /* Trang quản lý nguồn: dùng TAB để chuyển giữa 2 danh sách (tránh lướt dài) */
  .source-tabs { display: flex !important; gap: 8px; margin-bottom: 12px; }
  .source-tabs button {
    flex: 1; padding: 11px 8px; border: 1px solid var(--border-2); background: #fff;
    border-radius: 10px; font-weight: 600; font-size: 14px; color: #64748b; cursor: pointer;
  }
  .source-tabs button.active { background: var(--blue); color: #fff; border-color: var(--blue); }
  .source-grid.tab-devices .source-card[data-source="odfs"] { display: none; }
  .source-grid.tab-odfs .source-card[data-source="devices"] { display: none; }
  .source-grid { gap: 14px; }
  .source-card { min-width: 0 !important; flex: 1 1 100% !important; }
  .source-card .card-head { padding: 12px; }
  .source-card .table-wrap { max-height: none !important; overflow: visible !important; }
  /* Ô đầu mỗi thẻ nguồn là "Thao tác": nhãn bên trái, 2 nút gom sát nhau bên phải */
  #devices-body td.col-actions, #odfs-body td.col-actions { justify-content: flex-end; gap: 8px; }
  #devices-body td.col-actions::before, #odfs-body td.col-actions::before { flex: 0 0 auto; margin-right: auto; }
  /* Giữ DÒNG LỌC của bảng nguồn (ẩn hàng tiêu đề), xếp các ô lọc gọn 2/hàng */
  .source-card .data-table thead { display: block; }
  .source-card .data-table thead tr:not(.filter-row) { display: none; }
  .source-card .filter-row { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; background: #f6f9fe; }
  .source-card .filter-row th { display: block; flex: 1 1 44%; padding: 0; }
  .source-card .filter-row th:empty { display: none; }
  .source-card .filter-row input, .source-card .filter-row select { width: 100%; box-sizing: border-box; }

  /* Đăng nhập */
  .login-card { width: auto; margin: 0 16px; }
}

/* Print Dropdown */
.print-dropdown { position: relative; display: inline-block; }
.print-dropdown-menu {
  position: absolute; top: 100%; right: 0; margin-top: 5px;
  background: white; border: 1px solid var(--border-2); border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  display: flex; flex-direction: column; z-index: 100;
  min-width: 140px; overflow: hidden;
}
.print-dropdown-menu.hidden { display: none; }
.print-dropdown-menu .dropdown-item {
  padding: 10px 16px; background: none; border: none; text-align: left;
  cursor: pointer; font-size: 13.5px; color: var(--text);
  border-bottom: 1px solid var(--border);
}
.print-dropdown-menu .dropdown-item:last-child { border-bottom: none; }
.print-dropdown-menu .dropdown-item:hover { background: #f1f5fc; color: var(--blue); }

/* ===== Trang quản lý nguồn (thiết bị & ODF) ===== */
.src-badge { padding: 4px 8px; border-radius: 4px; font-size: 0.85rem; font-weight: 500; color: #fff; white-space: nowrap; }
.src-badge.used { background: #ef4444; }
.src-badge.unused { background: #10b981; }
.source-tabs { display: none; } /* chỉ hiện trên mobile */
.source-grid { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.source-card { flex: 1 1 420px; min-width: 420px; }
/* Chia layout 65% (bảng thiết bị nhiều cột) — 35% (bảng ODF ít cột) trên desktop.
   basis 0 + min-width 0 để tỉ lệ grow quyết định bề ngang; mobile có rule !important đè lại. */
.source-card[data-source="devices"] { flex: 65 1 0; min-width: 0; }
.source-card[data-source="odfs"] { flex: 35 1 0; min-width: 0; }
.source-card .card-head { padding: 12px 20px; }
/* Cao gần gấp đôi (lấp khoảng trống dưới): co theo chiều cao màn hình, tối đa 1000px.
   min() để màn hình thấp không tràn ra ngoài khung nhìn. */
.source-card .table-wrap { max-height: min(1000px, calc(100vh - 250px)); overflow-y: auto; }

/* ===== Sơ đồ 2D phòng máy (tra cứu vị trí + vẽ line) ===== */
.fm-info { padding: 0 4px 10px; font-size: 13.5px; color: var(--text); }
.fm-result-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.fm-result { margin: 0; font-size: 12px; white-space: nowrap; }
.fm-result th, .fm-result td { padding: 5px 8px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
/* Card sơ đồ 2D là flex-column chiếm hết chiều cao màn hình → vùng lưới (.fm-wrap) tự co
   theo phần còn lại sau khi .fm-info (kết quả tìm kiếm) hiện ra, nên thanh kéo NGANG ở
   đáy lưới luôn nằm trong khung nhìn (trước đây fix-cứng max-height nên search xong là
   lưới bị đẩy xuống dưới màn hình, mất thanh kéo ngang). */
#view-floormap .card { display: flex; flex-direction: column; max-height: calc(100vh - 96px); }
#view-floormap .card-head, #floormap-info { flex: 0 0 auto; }
.fm-wrap { position: relative; overflow: auto; flex: 1 1 auto; min-height: 0; padding: 0; }
.fm-svg { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 5; overflow: visible; }
.fm-rooms { display: flex; flex-direction: column; gap: 40px; align-items: flex-start; width: max-content; padding: 48px 12px 12px; }
/* stretch: 2 phòng cùng hàng cao bằng nhau (theo phòng cao nhất) → tên phòng (watermark
   căn giữa theo chiều cao) NẰM THẲNG HÀNG với nhau dù số dòng lưới khác nhau. */
.fm-room-row { display: flex; gap: 36px; align-items: stretch; }
.fm-room { position: relative; }
/* Tên phòng máy to ở GIỮA phòng (phía sau lưới) — xanh lá neon nổi bật */
.fm-room-watermark {
  position: absolute; top: 50%; left: 0; right: 0; transform: translateY(-50%);
  text-align: center; z-index: 0; pointer-events: none;
  font-weight: 900; font-size: 416px; line-height: .92; letter-spacing: 2px;
  color: rgba(57,255,20,.5);
}
.fm-grid { display: grid; column-gap: 38px; row-gap: 2px; position: relative; z-index: 1; } /* khe cột 38px ≈ ½ rack = lối đi dọc */
/* Hàng lối đi trên cùng (hành lang ngang nối tên cột ↔ rack) */
.fm-grid { display: grid; column-gap: 38px; row-gap: 2px; } /* khe cột 38px ≈ ½ rack = lối đi dọc */
/* Hàng lối đi trên cùng (hành lang ngang nối tên cột ↔ rack) */
.fm-aisle { min-height: 20px; max-height: 20px; background: transparent; border: 0; padding: 0; }
.fm-aisle-corner { min-width: 34px; max-width: 34px; }
.fm-cell {
  min-width: 78px; max-width: 78px; min-height: 46px; border-radius: 5px; padding: 3px 4px;
  font-size: 9.5px; line-height: 1.15; overflow: hidden; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; text-align: center; word-break: break-word;
  background: rgba(241,245,249,.68); color: #475569;
}
.fm-axis { background: #1f2a44; color: #fff; font-weight: 700; min-height: 24px; font-size: 11px; border-color: #1f2a44; }
.fm-axis-x { position: sticky; top: 0; z-index: 2; }
.fm-axis-y { position: sticky; left: 0; z-index: 2; min-width: 34px; max-width: 34px; }
.fm-corner { background: #0f1729; position: sticky; left: 0; top: 0; z-index: 3; border-color: #0f1729; min-width: 34px; max-width: 34px; }
.fm-empty { background: transparent; border-color: transparent; }
.fm-cell.fm-hl-device { background: #2d7ff9; color: #fff; font-weight: 700; box-shadow: 0 0 0 2px #1f2a44; }
.fm-cell.fm-hl-odf { background: #f59e0b; color: #fff; font-weight: 700; box-shadow: 0 0 0 2px #1f2a44; }
/* Ô 2 rack / 1 tọa độ (PM3.1/3.2): viền xanh nhạt báo hiệu */
/* Hàng đường đi link nội bộ — trắng trống trơn */
.fm-cell.fm-pathrow { background: #fff; border-color: transparent; }
.fm-cell.fm-tworack { background: #e0f2fe; border-color: #38bdf8; }
/* Ô ODF liên phòng máy (PM4.1/4.2): nền cam nhạt */
.fm-cell.fm-inter-odf { background: #ffedd5; border-color: #fb923c; color: #9a3412; font-weight: 600; }
.fm-dim { opacity: 0.4; }
.fm-legend { display: inline-flex; align-items: center; gap: 5px; margin-right: 14px; font-size: 12.5px; color: #475569; }
.fm-legend i { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }

/* ===== Trang Cài đặt ===== */
.settings-body { padding: 18px 22px; }
.settings-note { color: #64748b; font-size: 13.5px; margin: 0 0 18px; line-height: 1.5; }
.set-row { margin-bottom: 18px; }
.set-row > label { display: block; font-weight: 600; color: #1f2a44; margin-bottom: 7px; font-size: 14px; }
.set-row input[type="number"], .set-row select, .set-row textarea {
  width: 100%; max-width: 420px; padding: 9px 11px; border: 1px solid var(--border-2);
  border-radius: 8px; font-size: 14px; font-family: inherit; box-sizing: border-box;
}
.set-row textarea { max-width: 560px; resize: vertical; }
.set-checks { display: flex; flex-wrap: wrap; gap: 10px 22px; }
.set-chk { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; cursor: pointer; }
.set-chk input { width: 17px; height: 17px; }
.set-actions { display: flex; align-items: center; gap: 14px; margin-top: 8px; border-top: 1px solid var(--border); padding-top: 16px; }
.settings-status { font-size: 13.5px; font-weight: 600; }
.settings-status.ok { color: #10b981; }
.settings-status.err { color: #d32f2f; }

.set-section { font-weight: 700; color: #1f2a44; font-size: 15px; margin: 6px 0 14px; padding-bottom: 7px; border-bottom: 2px solid var(--border-2); }
.set-section:not(:first-child) { margin-top: 26px; }
.set-section-warn { font-weight: 500; font-size: 12.5px; color: #b45309; }
.set-section-ok { font-weight: 500; font-size: 12.5px; color: #10b981; }
.set-row input[type="text"], .set-row input[type="password"] {
  width: 100%; max-width: 420px; padding: 9px 11px; border: 1px solid var(--border-2);
  border-radius: 8px; font-size: 14px; font-family: inherit; box-sizing: border-box;
}

/* ===== Thanh TAB dùng chung (luôn hiển thị, khác .source-tabs vốn chỉ cho mobile) ===== */
.tab-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tab-bar button {
  padding: 9px 18px; border-radius: 10px; border: 1px solid var(--border-2);
  background: var(--card); color: #5b677d; font-size: 13.5px; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: all .12s;
  box-shadow: 0 2px 6px rgba(45,127,249,.05);
}
.tab-bar button:hover { border-color: var(--blue); color: var(--blue); }
.tab-bar button.active {
  background: var(--blue-grad); color: #fff; border-color: var(--blue);
  box-shadow: 0 4px 12px rgba(45,127,249,.28);
}

/* ===== Module VẬT TƯ DỰ PHÒNG (VTDP) ===== */
.mono { font-family: "Consolas", "SF Mono", monospace; font-size: 12.5px; }
td.acts { white-space: nowrap; }
.req { color: var(--danger); }
.modal-err { display: block; margin: 0 24px 8px; padding: 8px 12px; border-radius: 8px;
  background: #fdecea; color: #b42318; font-size: 13px; }

.vtdp-panel { animation: vfade .15s ease; }
@keyframes vfade { from { opacity: .4; } to { opacity: 1; } }

/* Tổng quan: thẻ số liệu */
.vtdp-stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.vtdp-stat-card { background: var(--card); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow);
  transition: transform .1s; }
.vtdp-stat-card[data-jump] { cursor: pointer; }
.vtdp-stat-card[data-jump]:hover { transform: translateY(-2px); }
.vtdp-stat-num { font-size: 26px; font-weight: 700; line-height: 1.1; }
.vtdp-stat-title { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

/* Tổng quan: bar chủng loại */
.vtdp-bars { padding: 14px 18px; display: flex; flex-direction: column; gap: 7px; }
.vtdp-bar-row { display: grid; grid-template-columns: 160px 1fr 44px; align-items: center; gap: 10px; }
.vtdp-bar-label { font-size: 12.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vtdp-bar-track { background: var(--border); border-radius: 6px; height: 14px; overflow: hidden; }
.vtdp-bar-fill { display: block; height: 100%; background: var(--blue-grad); border-radius: 6px; }
.vtdp-bar-num { font-size: 12.5px; font-weight: 600; text-align: right; color: var(--muted); }

/* Thanh lọc */
.vtdp-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 16px 4px; }
.vtdp-filters input[type="text"], .vtdp-filters select, .vtdp-filters input[type="date"] {
  padding: 8px 11px; border: 1px solid var(--border-2); border-radius: 8px; font-size: 13.5px; font-family: inherit; }
.vtdp-filters input[type="text"] { min-width: 260px; }
.vtdp-count { color: var(--muted); font-size: 13px; margin-left: auto; font-weight: 600; }
.vtdp-date { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

/* Badge trạng thái */
.vtdp-badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }

/* Form trong modal */
.vtdp-form { padding: 16px 24px; }
.vtdp-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.vtdp-form-grid label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
.vtdp-form-grid .vf-full { grid-column: 1 / -1; }
.vtdp-form-grid .vf-check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.vtdp-form-grid input[type="text"], .vtdp-form-grid select, .vtdp-form-grid textarea {
  padding: 8px 10px; border: 1px solid var(--border-2); border-radius: 8px; font-size: 13.5px; font-family: inherit; width: 100%; }
.vtdp-info-box { background: var(--bg); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; font-size: 13px; line-height: 1.5; }
.vtdp-hh-info { background: #eef4ff; border: 1px solid #d6e4ff; border-radius: 8px; padding: 8px 12px; font-size: 12.5px; line-height: 1.55; color: #334155; }

/* Combobox tìm-kiếm */
.vcombo { position: relative; display: flex; flex-direction: column; }
.vcombo-native { display: none !important; }
.vcombo-input { padding: 8px 10px; border: 1px solid var(--border-2); border-radius: 8px; font-size: 13.5px;
  font-family: inherit; width: 100%; background: #fff; }
.vcombo-input:focus { border-color: var(--blue); outline: none; }
.vcombo-list { margin-top: 4px; border: 1px solid var(--border-2); border-radius: 8px; max-height: 240px;
  overflow-y: auto; background: #fff; box-shadow: 0 6px 18px rgba(45,127,249,.12); }
.vcombo-item { padding: 7px 11px; font-size: 13px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vcombo-item:hover { background: #eef4ff; }
.vcombo-item.sel { background: #dbe8ff; font-weight: 600; }
.vcombo-empty { padding: 9px 11px; font-size: 13px; color: var(--muted); }

@media (max-width: 820px) { .vtdp-form-grid { grid-template-columns: 1fr; } .vtdp-bar-row { grid-template-columns: 110px 1fr 38px; } }
