﻿/* =====================================================================================
   LỚP GIAO DIỆN MỚI (bản thử) — nạp SAU site.css, chỉ CỘNG THÊM, không sửa file cũ.
   Gồm 7 hạng mục nâng cấp theo chuẩn phòng điều khiển hạng nhất (High-Performance HMI):
     1. Kỷ luật màu: bình thường = trầm/xám; màu mạnh (đỏ/hổ phách) chỉ cho BẤT THƯỜNG.
     2. Thanh cảnh báo thường trực (CSS ở đây, HTML ở _ThanhCanhBao, JS ở giao-dien-moi.js).
     3. Chế độ "xem dày" cho trang Điều khiển.
     4. Xu hướng tại chỗ (sparkline — CSS hỗ trợ, dữ liệu ở view).
     5. An toàn mù màu (hình + màu) và Chế độ tối.
     6. Menu gọn hơn (giữ phẳng theo ý người dùng, chỉ làm nhẹ thị giác).
     7. Bộ token dùng chung (biến CSS) để nhất quán.

   Muốn tắt hẳn lớp này: bỏ 2 dòng <link>/<script> giao-dien-moi trong _Layout.
   ===================================================================================== */

/* ---------- 7) BỘ TOKEN DÙNG CHUNG ---------- */
:root {
    --gd-nen:        #eceff3;   /* nền vùng làm việc — xám trung tính, đỡ chói */
    --gd-the:        #ffffff;   /* nền thẻ/bảng */
    --gd-vien:       #d7dde3;
    --gd-chu:        #1f2933;
    --gd-chu-mo:     #6b7681;
    --gd-nhan:       #0f6b6b;   /* xanh cổ vịt — GIỮ làm màu thương hiệu, dùng CÓ CHỪNG MỰC */

    /* Màu trạng thái — bình thường TRẦM, bất thường MẠNH */
    --gd-ok:      #2f7d5b;      /* đang chạy tốt — lục trầm (không chói) */
    --gd-ok-nen:  #e7f1ec;
    --gd-tat:     #7b848d;      /* tắt/nghỉ — xám */
    --gd-tat-nen: #eceef1;
    --gd-canhbao: #b9770b;      /* cảnh báo — hổ phách */
    --gd-canhbao-nen:#fbf1df;
    --gd-loi:     #c0392b;      /* lỗi/mất kết nối — đỏ (màu ĐƯỢC PHÉP nổi nhất) */
    --gd-loi-nen: #f8e6e3;
}

/* ---------- 1) KỶ LUẬT MÀU: làm dịu nền, giữ dữ liệu gần đơn sắc ---------- */
body:not(.login-body) { background-color: var(--gd-nen); }

/* Huy hiệu trạng thái: bình thường TRẦM lại, lỗi/cảnh báo GIỮ mạnh + IN ĐẬM để nổi.
   (Ghi đè các badge Bootstrap đang dùng cho trạng thái trên toàn hệ thống.) */
.badge.bg-success { background-color: var(--gd-ok) !important; }
.badge.bg-secondary { background-color: var(--gd-tat) !important; }
/* GD12-5: chữ trắng trên hổ phách --gd-canhbao #b9770b chỉ 3,68:1 (huy hiệu cỡ ~0,75rem, ngưỡng 4,5). Huy hiệu dùng sắc
   trầm hơn #9a630a (5,04:1) ở CẢ HAI chế độ, như luật tối bên dưới; token --gd-canhbao giữ nguyên cho viền/biểu tượng. */
.badge.bg-warning { background-color: #9a630a !important; color: #fff !important; }
.badge.bg-danger  { background-color: var(--gd-loi) !important; font-weight: 700; }

/* ---------- 5a) AN TOÀN MÙ MÀU: trạng thái phân biệt bằng HÌNH, không chỉ bằng màu ----------
   Thêm một dấu hình học nhỏ trước chữ trong huy hiệu trạng thái. Người mù màu đỏ–lục vẫn
   phân biệt được: ● đang chạy · ○ tắt · ■ cảnh báo · ▲ lỗi. */
.badge.bg-success::before { content: "\25CF\00A0"; }  /* ● */
.badge.bg-secondary::before { content: "\25CB\00A0"; } /* ○ */
.badge.bg-warning::before { content: "\25A0\00A0"; }   /* ■ */
.badge.bg-danger::before  { content: "\25B2\00A0"; }   /* ▲ */
/* Không thêm hình cho huy hiệu ĐẾM SỐ (chỉ là con số, không phải trạng thái). */
.badge.badge-so::before, .badge.khong-hinh::before { content: none !important; }

/* ---------- 2) HUY HIỆU CẢNH BÁO nhỏ gọn ở GÓC DƯỚI PHẢI ----------
   Gọn, không che nội dung. Chỉ hiện SỐ sự cố; bấm sang trang xử lý; rê chuột hiện tóm tắt.
   Không "hét" cả một dải ngang như trước, nhưng vẫn nhấp nháy đủ để chú ý. */
#thanhCanhBao {
    display: none;                 /* JS bật khi có sự cố */
    position: fixed;
    right: 18px; bottom: 18px;
    /* 1035 chứ không phải 1050: 1050 đúng bằng lớp phủ mờ của modal, nên badge lúc thì nổi trên
       lúc thì chìm dưới tuỳ thứ tự vẽ; và nó nổi trên cả khung chat trợ lý (1041) dù hai thứ chồng
       lên nhau ở góc phải dưới. 1035 vẫn trên thanh điều hướng (1030) và dưới mọi hộp thoại. */
    z-index: 1035;
    background: var(--gd-loi);
    color: #fff;
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(0,0,0,.28);
    overflow: hidden;
    font-weight: 600;
}
#thanhCanhBao.hien { display: inline-flex; align-items: stretch; }
#thanhCanhBao .tcb-chinh {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .5rem .9rem;
    color: #fff; text-decoration: none; white-space: nowrap;
}
#thanhCanhBao .tcb-chinh:hover { background: rgba(0,0,0,.12); }
#thanhCanhBao .tcb-so { font-size: 1.05rem; font-weight: 800; line-height: 1; }
#thanhCanhBao .tcb-nhan { opacity: .95; }
#thanhCanhBao .tcb-nhipnhay { animation: tcb-nhay 1.4s ease-in-out infinite; }
@keyframes tcb-nhay { 0%,100%{opacity:1} 50%{opacity:.35} }
#thanhCanhBao .tcb-an {
    background: rgba(0,0,0,.16); border: 0; color: #fff;
    width: 28px; cursor: pointer; opacity: .85;
}
#thanhCanhBao .tcb-an:hover { opacity: 1; background: rgba(0,0,0,.32); }

/* ---------- 4) SPARKLINE (xu hướng tại chỗ) ---------- */
.sparkline { display: inline-block; vertical-align: middle; }
.sparkline svg { display: block; }

/* ---------- 6) MENU GỌN HƠN (giữ phẳng, chỉ làm NHẸ thị giác) ----------
   Không đổi sang menu thả xuống (người dùng đã chọn menu phẳng). Chỉ giảm "độ ồn":
   thanh menu bớt bóng, khoảng cách chữ đều hơn. */
.navbar.bg-primary { box-shadow: 0 1px 0 rgba(0,0,0,.15) !important; }

/* ===================================================================================
   5b) CHẾ ĐỘ TỐI (dark HMI) — cho ca đêm, đỡ mỏi mắt. Bật bằng nút; nhớ trong localStorage.
   Ưu tiên: nút bấm data-theme trên <html> thắng; nếu chưa chọn thì theo hệ điều hành.
   =================================================================================== */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --gd-nen: #12161b; --gd-the: #1b2129; --gd-vien: #2c343d;
        --gd-chu: #e6eaee; --gd-chu-mo: #9aa4ae;
    }
}
:root[data-theme="dark"] {
    --gd-nen: #12161b; --gd-the: #1b2129; --gd-vien: #2c343d;
    --gd-chu: #e6eaee; --gd-chu-mo: #9aa4ae;
}

/* Áp token tối lên các bề mặt chính. Nền body đã tự theo --gd-nen (rule body ở đầu file),
   nên chỉ cần khai màu chữ + các bề mặt. Dùng !important vì phải thắng site.css. */
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-theme="dark"] body { color: var(--gd-chu); }
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .modal-content,
:root[data-theme="dark"] .dropdown-menu,
:root[data-theme="dark"] .list-group-item {
    background-color: var(--gd-the) !important;
    color: var(--gd-chu);
    border-color: var(--gd-vien) !important;
}
:root[data-theme="dark"] .table { color: var(--gd-chu); border-color: var(--gd-vien); }
:root[data-theme="dark"] .table > :not(caption) > * > * { background-color: transparent; color: var(--gd-chu); border-color: var(--gd-vien) !important; }
:root[data-theme="dark"] .table-light > :not(caption) > * > *,
:root[data-theme="dark"] thead.table-light th { background-color: #232b34 !important; color: var(--gd-chu) !important; }
:root[data-theme="dark"] .table-hover > tbody > tr:hover > * { background-color: #232b34 !important; }
:root[data-theme="dark"] .bg-light { background-color: #232b34 !important; color: var(--gd-chu); }
:root[data-theme="dark"] .text-muted { color: var(--gd-chu-mo) !important; }
/* "-" xám của thiết bị mất kết nối (control-menu.js) dùng text-body-tertiary = màu chữ Bootstrap
   SÁNG-nền ở 50%: trên nền tối ra gần như đen trên đen, ô số liệu trông như TRỐNG (đo 14/10/2026 ở
   trang Chi tiết tủ, chế độ tối). Người trực đọc "trống" thành "chưa nạp xong" chứ không phải
   "mất kết nối". */
/* Lần 12 (22/10/2026): #7a848e cũ chỉ đạt 4,26:1 trên nền thẻ #1b2129 và 3,76:1 trên #232b34 (ô số của
   Chi tiết tủ). #8c96a0 đạt 6,04 / 5,39 / 4,76:1 trên #12161b / #1b2129 / #232b34, vẫn mờ hơn
   --gd-chu-mo (#9aa4ae) nên "mất kết nối" còn khác "đọc được". */
:root[data-theme="dark"] .text-body-tertiary { color: #8c96a0 !important; }
/* Chữ màu trạng thái ở chế độ tối (lần 12, 22/10/2026). Màu Bootstrap #dc3545 / #198754 / #6c757d dành
   cho nền sáng: trên ba nền tối #12161b / #1b2129 / #232b34 chỉ được 4,01 / 3,58 / 3,16:1 (đỏ, lục) và
   ~3,9 / 3,46 / ~3,1:1 (xám). Thấp nhất là nhãn phạm vi "Tất cả khu vực" ở thanh lệnh hàng loạt của
   /Control và Tổng quan (đỏ trên .bg-light #232b34, 3,16:1) — đúng chữ báo lệnh đi xa nhất. Dùng màu
   Bootstrap tự dùng cho chế độ tối như GD10-4: #ea868f 5,66:1, #75b798 6,13:1, xám theo --gd-chu-mo 5,66:1
   ở nền khó nhất. CHỪA nền nhạt (bg-*-subtle, .alert): các nền đó không đổi ở chế độ tối nên chữ đậm cũ
   mới đúng (biểu tượng tròn ở thẻ Tổng quan là bg-danger-subtle text-danger). */
:root[data-theme="dark"] .text-danger:not([class*="-subtle"]):not(.alert *):not([class*="-subtle"] *) { color: #ea868f !important; }
:root[data-theme="dark"] .text-success:not([class*="-subtle"]):not(.alert *):not([class*="-subtle"] *) { color: #75b798 !important; }
:root[data-theme="dark"] .text-secondary:not([class*="-subtle"]):not(.alert *):not([class*="-subtle"] *),
:root[data-theme="dark"] .stat-label { color: var(--gd-chu-mo) !important; }
/* Huy hiệu xám (bg-secondary: "0/4 sáng", số đếm, cờ quyền): chữ trắng trên --gd-tat #7b848d chỉ 3,80:1.
   Ở chế độ tối nền trầm xuống #656e77 → 5,19:1; vẫn tách khỏi nền thẻ (3,12:1) nên huy hiệu không chìm. */
:root[data-theme="dark"] .badge.bg-secondary { background-color: #656e77 !important; }
/* Huy hiệu hổ phách (bg-warning: "thiếu dung lượng ắc quy" ở Cân đối pin, "GW cũ", "Nháp"): chữ trắng trên
   --gd-canhbao #b9770b chỉ 3,68:1 (đo 29/10/2026, rà soát lần 3 B L3B-1). Cùng cách huy hiệu xám ngay trên: ở chế độ
   tối trầm nền xuống #9a630a → 5,04:1, vẫn tách khỏi nền thẻ #1b2129 (3,21:1). */
:root[data-theme="dark"] .badge.bg-warning { background-color: #9a630a !important; }
:root[data-theme="dark"] .form-control,
:root[data-theme="dark"] .form-select {
    background-color: #232b34; color: var(--gd-chu); border-color: var(--gd-vien);
}
:root[data-theme="dark"] .form-control::placeholder { color: #7a848e; }
/* Ô bị KHOÁ phải trông khác ô mở (GD10-2, 22/10/2026). Luật nền #232b34 ở trên bắt cả :disabled nên
   ở chế độ tối 5 ô mốc khoá (ĐK9-2), ô khu vực khoá khi Sửa tủ (BM9-1), ô nhịp FW 25 có nền y hệt
   ô gõ được. Ô [readonly] (tên/ghi chú kịch bản tủ có phần ẩn, BM9-2) thì ở CẢ HAI chế độ trông như
   ô mở: bấm vào gõ không ra chữ, người dùng tưởng phần mềm treo. Bootstrap cố ý để readonly giống ô
   thường, nhưng ở đây readonly luôn có nghĩa "bị khoá theo quyền", nên cho dáng như disabled.
   Tối: nền #171c22 chìm dưới nền thẻ #1b2129 (ô mở nổi lên #232b34), viền #262d35 mờ hơn viền ô mở
   #2c343d, chữ #9aa4ae vẫn đọc được 6,77:1. flatpickr chạy allowInput nên ô ngày không mang readonly. */
.form-control[readonly] { background-color: var(--bs-secondary-bg); cursor: not-allowed; }
:root[data-theme="dark"] .form-control:disabled,
:root[data-theme="dark"] .form-select:disabled,
:root[data-theme="dark"] .form-control[readonly] {
    background-color: #171c22; color: var(--gd-chu-mo); border-color: #262d35; cursor: not-allowed;
}
/* Tom Select chỉ đọc trạng thái disabled của <select> LÚC DỰNG; mã trang khoá ô sau đó bằng
   sel.disabled = true (t_RegionId ở Sửa tủ, ô loại/mốc kịch bản tủ có phần ẩn) thì khung Tom Select
   vẫn mở, chọn được, mà giá trị rơi vào <select> bị khoá nên không được gửi. Khung nằm NGAY SAU
   <select> gốc, nên bắt theo trạng thái thật của <select> và chặn bấm. Nền ở chế độ sáng bằng đúng
   nền Bootstrap tô cho <select> disabled khi chưa bị Tom Select che. */
select.tomselected:disabled + .ts-wrapper { pointer-events: none; background-color: var(--bs-secondary-bg); }
:root[data-theme="dark"] select.tomselected:disabled + .ts-wrapper,
:root[data-theme="dark"] .ts-wrapper.disabled { background-color: #171c22; border-color: #262d35; }
:root[data-theme="dark"] select.tomselected:disabled + .ts-wrapper .ts-control,
:root[data-theme="dark"] .ts-wrapper.disabled .ts-control { background-color: #171c22; border-color: #262d35; color: var(--gd-chu-mo); opacity: 1; }
:root[data-theme="dark"] select.tomselected:disabled + .ts-wrapper .ts-control .item,
:root[data-theme="dark"] .ts-wrapper.disabled .ts-control .item { color: var(--gd-chu-mo); }
:root[data-theme="dark"] .input-group-text { background-color: #2a323b; color: var(--gd-chu-mo); border-color: var(--gd-vien); }
:root[data-theme="dark"] .modal-header, :root[data-theme="dark"] .modal-footer { border-color: var(--gd-vien); }
:root[data-theme="dark"] .border, :root[data-theme="dark"] .border-top,
:root[data-theme="dark"] .border-bottom { border-color: var(--gd-vien) !important; }
:root[data-theme="dark"] .btn-outline-secondary { color: #c7ccd2; border-color: #3a434d; }
/* Nút viền đỏ / xanh lá ở chế độ tối (GD10-4, 22/10/2026). Màu Bootstrap #dc3545 và #198754 dành cho
   nền sáng: trên nền tối chỉ đạt 4,01:1 (#12161b), 3,58:1 (#1b2129), 3,16:1 (#232b34). Thẻ <a> trước
   lần 10 ăn ké màu cổ vịt của luật `a`, nay chừa .btn nên rơi về màu này ("Khoá vận hành", "Xuất Excel",
   "Nhập Excel", "Tải tệp mẫu"). Dùng màu Bootstrap tự dùng cho chế độ tối của nó: #ea868f đạt
   7,18 / 6,41 / 5,66:1, #75b798 đạt 7,77 / 6,93 / 6,13:1 trên ba nền trên. Đặt bằng biến nên áp
   chung cho <a> và <button>. Rê chuột / đang bấm giữ nền đặc Bootstrap, chữ trắng 4,53:1. */
:root[data-theme="dark"] .btn-outline-danger {
    --bs-btn-color: #ea868f; --bs-btn-border-color: #ea868f;
    --bs-btn-disabled-color: #ea868f; --bs-btn-disabled-border-color: #ea868f;
}
:root[data-theme="dark"] .btn-outline-success {
    --bs-btn-color: #75b798; --bs-btn-border-color: #75b798;
    --bs-btn-disabled-color: #75b798; --bs-btn-disabled-border-color: #75b798;
}
:root[data-theme="dark"] .alert-secondary { background-color: #232b34; color: var(--gd-chu); border-color: var(--gd-vien); }
/* Liên kết chữ trên nền thẻ tối: xanh cổ vịt sáng. CHỪA mọi thẻ <a> đã có NỀN MÀU riêng (GD9-1,
   GD9-2, 22/10/2026). Luật `a` trơn (đặc hiệu 0,2,1) đè màu chữ của Bootstrap (0,1,0) nên:
   - menu chính (.navbar .nav-link, .navbar-brand) ra #4bb3b3 trên nền #0b4f4f = 3,74:1, cả thanh
     menu nhoè ở MỌI trang khi bật chế độ tối (chế độ sáng là chữ trắng);
   - nút đặc là thẻ <a> (.btn-primary "Đi tới trang báo cáo", nút VI/EN trang đăng nhập quản trị)
     ra #4bb3b3 trên #0f6b6b = 2,52:1;
   - huy hiệu và mục .active (dropdown/list-group/phân trang) cũng tự tô nền màu.
   :where() giữ đặc hiệu đúng 0,2,1 như cũ: viết :not() trần thì mỗi lớp trong đó cộng thêm đặc hiệu,
   luật này sẽ thắng cả các luật riêng như `.phan-trang .page-link` (site.css) vốn đang đúng.
   Chừa cả nút +/− của bản đồ (.leaflet-bar a, GD10-5): nền Leaflet vẫn trắng ở chế độ tối, #4bb3b3 trên
   #fff chỉ 2,50:1; trả về chữ đen của Leaflet, 21:1. */
:root[data-theme="dark"] a:where(:not(.btn, .badge, .active, .navbar .nav-link, .navbar-brand, .leaflet-bar a)) { color: #4bb3b3; }
/* Chữ ghi nguồn bản đồ ("Leaflet", "OpenStreetMap", "CARTO", GD10-5): nền rgba(255,255,255,.8) phủ lên
   ảnh bản đồ. #4bb3b3 ra 2,36:1 trên #f8f8f8; màu gốc Leaflet #0078a8 đạt 4,65:1 trên nền sáng nhưng
   chỉ 3,08:1 khi ảnh nền phía dưới tối (nền ô xuống #ccc). #00567a đạt 7,57:1 trên #f8f8f8 và 5,01:1
   trên #ccc. Đặc hiệu 0,3,1 thắng luật `a` ở trên (0,2,1). */
:root[data-theme="dark"] .leaflet-control-attribution a { color: #00567a; }
/* Chữ "đang chờ / chưa thành công" (.text-warning-emphasis) là màu Bootstrap dành cho nền SÁNG
   (#664d03); phần mềm dùng data-theme riêng chứ không data-bs-theme nên Bootstrap không đổi biến
   này: trên nền thẻ tối ra 2,03:1 (/Monitor/LenhDaGui "Chưa thành công", /BaoTri "chờ bảo hành",
   /CanDoiPin, kết quả ở /Report). Chừa huy hiệu nền nhạt (bg-*-subtle) — nền đó vẫn sáng ở chế độ
   tối nên chữ đậm cũ mới đúng. #ffda6a là màu Bootstrap tự dùng cho chế độ tối của nó. */
:root[data-theme="dark"] .text-warning-emphasis:not([class*="-subtle"]) { color: #ffda6a !important; }
/* Thanh menu giữ nền xanh cổ vịt cả ở chế độ tối (nhận diện thương hiệu), chỉ đậm hơn chút. */
:root[data-theme="dark"] .navbar.bg-primary { background-color: #0b4f4f !important; }
/* Bản đồ nền tối: hơi giảm sáng ảnh nền cho đỡ chói ban đêm. */
:root[data-theme="dark"] .leaflet-tile { filter: brightness(.85) contrast(1.02); }

/* Nút bật/tắt chế độ tối và xem dày trên thanh menu */
.gd-nut { }
.navbar .gd-nut.btn { padding: .2rem .5rem; }

/* =========================================================================
   Ô CHỌN CÓ TÌM KIẾM (Tom Select) — DÁNG cho gọn đẹp, dễ nhập.
   Sửa lỗi: chữ đã chọn bị XUỐNG DÒNG khi ô hẹp -> cho MỘT DÒNG, thừa thì cắt "…".
   ========================================================================= */
.ts-wrapper { min-width: 150px; }
.ts-wrapper.single .ts-control { flex-wrap: nowrap; }
.ts-control > .item {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
/* Cỡ nhỏ (form-select-sm): cao & chữ khớp các ô nhập cạnh bên cho hàng lọc thẳng đều. */
.ts-wrapper.form-select-sm .ts-control {
    min-height: calc(1.5em + .5rem + 2px);
    padding-top: .15rem; padding-bottom: .15rem; font-size: .875rem;
}
/* Con trỏ gõ tìm: rõ ràng, không đội chữ đã chọn. */
.ts-wrapper.single.input-active .ts-control { cursor: text; }
.ts-control input::placeholder { color: #98a1ab; }
.ts-dropdown .option { padding: .35rem .65rem; }
.ts-dropdown .active { background: #0f6b6b; color: #fff; }

/* =========================================================================
   CHẾ ĐỘ TỐI — BỔ SUNG cho các thành phần TỰ ĐẶT MÀU (không theo Bootstrap)
   và 2 thư viện mới (Tom Select, flatpickr). Trước đây các chỗ này để nền
   trắng/xám sáng cố định nên bị chìm khi bật chế độ tối.
   ========================================================================= */

/* --- Tom Select (ô chọn có tìm kiếm) --- */
:root[data-theme="dark"] .ts-control { background-color: #232b34; color: var(--gd-chu); border-color: var(--gd-vien); }
:root[data-theme="dark"] .ts-control .item { color: var(--gd-chu); }
:root[data-theme="dark"] .ts-control input,
:root[data-theme="dark"] .ts-control input::placeholder { color: var(--gd-chu) !important; }
:root[data-theme="dark"] .ts-dropdown { background: #232b34; color: var(--gd-chu); border-color: var(--gd-vien); box-shadow: 0 6px 18px rgba(0,0,0,.5); }
:root[data-theme="dark"] .ts-dropdown .option { color: var(--gd-chu); }
:root[data-theme="dark"] .ts-dropdown .active { background: #0f6b6b; color: #fff; }
:root[data-theme="dark"] .ts-dropdown .no-results,
:root[data-theme="dark"] .ts-dropdown .optgroup-header { color: var(--gd-chu-mo); background: #232b34; }
:root[data-theme="dark"] .ts-dropdown .dropdown-input-wrap { border-bottom-color: var(--gd-vien); }
:root[data-theme="dark"] .ts-dropdown .dropdown-input { background: #1b2129; color: var(--gd-chu); border-color: var(--gd-vien); }
:root[data-theme="dark"] .ts-dropdown .dropdown-input::placeholder { color: #7a848e; }
:root[data-theme="dark"] .ts-wrapper.single .ts-control:after { border-color: var(--gd-chu-mo) transparent transparent; }

/* --- flatpickr (lịch chọn ngày) --- */
:root[data-theme="dark"] .flatpickr-calendar { background: #1b2129; color: var(--gd-chu); border: 1px solid var(--gd-vien); box-shadow: 0 6px 18px rgba(0,0,0,.6); }
:root[data-theme="dark"] .flatpickr-calendar.arrowTop:before,
:root[data-theme="dark"] .flatpickr-calendar.arrowTop:after { border-bottom-color: #1b2129; }
:root[data-theme="dark"] .flatpickr-calendar.arrowBottom:before,
:root[data-theme="dark"] .flatpickr-calendar.arrowBottom:after { border-top-color: #1b2129; }
:root[data-theme="dark"] .flatpickr-months .flatpickr-month,
:root[data-theme="dark"] .flatpickr-current-month input.cur-year,
:root[data-theme="dark"] .flatpickr-monthDropdown-months { color: var(--gd-chu); fill: var(--gd-chu); }
:root[data-theme="dark"] .flatpickr-monthDropdown-months { background: #1b2129; }
:root[data-theme="dark"] .flatpickr-weekday { color: var(--gd-chu-mo); }
:root[data-theme="dark"] .flatpickr-day { color: var(--gd-chu); }
:root[data-theme="dark"] .flatpickr-day:hover,
:root[data-theme="dark"] .flatpickr-day:focus { background: #2c343d; border-color: #2c343d; }
:root[data-theme="dark"] .flatpickr-day.today { border-color: #0f6b6b; }
:root[data-theme="dark"] .flatpickr-day.selected { background: #0f6b6b; border-color: #0f6b6b; color: #fff; }
:root[data-theme="dark"] .flatpickr-day.prevMonthDay,
:root[data-theme="dark"] .flatpickr-day.nextMonthDay,
:root[data-theme="dark"] .flatpickr-day.flatpickr-disabled { color: #5b636c; }
:root[data-theme="dark"] .flatpickr-months .flatpickr-prev-month svg,
:root[data-theme="dark"] .flatpickr-months .flatpickr-next-month svg { fill: var(--gd-chu); }
:root[data-theme="dark"] .flatpickr-months .flatpickr-prev-month:hover svg,
:root[data-theme="dark"] .flatpickr-months .flatpickr-next-month:hover svg { fill: #4bb3b3; }
:root[data-theme="dark"] .numInputWrapper span { border-color: var(--gd-vien); }
:root[data-theme="dark"] .numInputWrapper span:hover { background: rgba(255,255,255,.05); }

/* --- Kịch bản: ô "mốc" lịch đóng/cắt (trước để nền trắng nên chìm hẳn) --- */
:root[data-theme="dark"] .kb-moc { background: #232b34 !important; border-color: var(--gd-vien) !important; }
:root[data-theme="dark"] .kb-moc-so { background: #4a535d; color: #fff; }

/* --- Tiện ích Bootstrap còn sót --- */
:root[data-theme="dark"] .bg-white { background-color: var(--gd-the) !important; color: var(--gd-chu); }
/* Chữ "tối" (text-dark) trên nền tối sẽ chìm -> đổi sáng, TRỪ khi nằm trên huy hiệu màu (badge). */
:root[data-theme="dark"] .text-dark:not(.badge) { color: var(--gd-chu) !important; }
/* Huy hiệu nền-sáng + chữ-tối: nền đã hoá tối -> cho chữ sáng lại. */
:root[data-theme="dark"] .badge.bg-light.text-dark { color: var(--gd-chu) !important; }
/* Dải nền vàng nhạt "nghi ngờ lỗi" (Báo cáo) -> vàng trầm cho đỡ chói. */
.nen-vang-nhat { background: #fff3cd; }
:root[data-theme="dark"] .nen-vang-nhat { background: #3a3212 !important; }

/* --- Báo cáo: dòng tiêu đề nhóm tủ (nền xanh nhạt cố định -> tối) --- */
:root[data-theme="dark"] .nhom-tu > td {
    background: #24303f !important; color: #bcd4ff !important;
    border-color: var(--gd-vien) !important; border-top-color: #3b6ea5 !important;
}
:root[data-theme="dark"] .nhom-tu-dem { color: var(--gd-chu-mo) !important; }

/* --- Nhắc cài ứng dụng (PWA) --- */
:root[data-theme="dark"] .pwa-nhac { background: var(--gd-the); border-color: var(--gd-vien); color: var(--gd-chu); }
:root[data-theme="dark"] .pwa-nhac-phu { color: var(--gd-chu-mo); }

/* --- Menu chuột phải trên bản đồ --- */
:root[data-theme="dark"] .scada-context-menu { background: #232b34; border-color: var(--gd-vien); box-shadow: 0 6px 18px rgba(0,0,0,.5); }
:root[data-theme="dark"] .scada-context-menu-item { color: var(--gd-chu); }
:root[data-theme="dark"] .scada-context-menu-item:hover { background: #2c343d; }
:root[data-theme="dark"] .scada-context-menu-item.disabled { color: #5b636c; }
:root[data-theme="dark"] .scada-context-menu-sep { background: var(--gd-vien); }
:root[data-theme="dark"] .cabinet-node-row:hover { background: #232b34; }

/* --- Modal "Chi tiết tủ" --- */
:root[data-theme="dark"] .cabinet-section-title { color: #6ea8fe; border-bottom-color: var(--gd-vien); }
:root[data-theme="dark"] .cabinet-info-box { background: #232b34; }
:root[data-theme="dark"] .cabinet-info-box .label { color: var(--gd-chu-mo); }
:root[data-theme="dark"] .cabinet-info-box .value { color: var(--gd-chu); }

/* --- Khung lịch (trong modal) --- */
:root[data-theme="dark"] .lich-khung { background: #1f2a37; border-color: #2f4055; }
:root[data-theme="dark"] .lich-tieu-de { color: #8fb4ea; }
:root[data-theme="dark"] .lich-moc { background: #232b34; border-color: var(--gd-vien); }
:root[data-theme="dark"] .lich-gio { color: var(--gd-chu); }
:root[data-theme="dark"] .lich-mo-ta { color: var(--gd-chu-mo); }
:root[data-theme="dark"] .lich-chu-thich { color: var(--gd-chu-mo); }

/* --- Mũi tên sắp xếp + hover tiêu đề cột --- */
:root[data-theme="dark"] .th-arrow { color: #5b636c; }
:root[data-theme="dark"] .js-sort thead th:hover { background: #232b34 !important; }

/* --- Nhãn tên tủ trên bản đồ --- */
:root[data-theme="dark"] .leaflet-tooltip.nhan-tu { background: rgba(27,33,41,.92); color: var(--gd-chu); border-color: rgba(255,255,255,.18); }

/* --- Bong bóng thông tin thiết bị trên bản đồ (Leaflet popup) --- */
:root[data-theme="dark"] .leaflet-popup-content-wrapper,
:root[data-theme="dark"] .leaflet-popup-tip { background: #1b2129; color: var(--gd-chu); box-shadow: 0 3px 14px rgba(0,0,0,.6); }
:root[data-theme="dark"] .mp-dau { background: #232b34; border-left-color: #4a535d; }
:root[data-theme="dark"] .mp-phu,
:root[data-theme="dark"] .mp-o-nhan,
:root[data-theme="dark"] .mp-o-so span,
:root[data-theme="dark"] .mp-cap-m,
:root[data-theme="dark"] .mp-cap-nhan,
:root[data-theme="dark"] .mp-tong,
:root[data-theme="dark"] .mp-mo { color: var(--gd-chu-mo); }
:root[data-theme="dark"] .mp-o-item { background: #232b34; border-color: var(--gd-vien); }
:root[data-theme="dark"] .mp-cap-dong { border-left-color: var(--gd-vien); }

/* =====================================================================================
   Rà soát lần 12–13 (GD12-1/2/3/5, KT4-HT-4; sửa 16/11/2026). Gốc chung: chế độ tối bật bằng data-theme="dark", KHÔNG
   phải data-bs-theme, nên mọi biến --bs-* của Bootstrap vẫn là bản sáng. Chỗ nào Bootstrap đọc biến (menu thả, .form-text,
   tab, .alert) hay trang tự đặt nền sáng cứng thì ở chế độ tối ra chữ sáng trên nền trắng, hoặc chữ tối trên nền tối.
   ===================================================================================== */

/* GD12-1: menu "Đóng/cắt tủ" (/Control, Tổng quan): nền menu đã tối (#1b2129) nhưng chữ mục vẫn #212529 = 1,05:1, hai dòng
   "Đóng khởi 1/2" trông như hai dòng trống, người trực đêm không thấy lối đóng riêng một khởi. */
:root[data-theme="dark"] .dropdown-menu {
    --bs-dropdown-link-color: var(--gd-chu);
    --bs-dropdown-link-hover-color: var(--gd-chu);
    --bs-dropdown-link-hover-bg: #232b34;
    --bs-dropdown-header-color: var(--gd-chu-mo);
    --bs-dropdown-divider-bg: var(--gd-vien);
    --bs-dropdown-link-disabled-color: #5b636c;
}
/* Nút xám viền khi menu đang mở: chữ #c7ccd2 trên nền #6c757d chỉ 2,90:1; trắng đạt 4,69:1. */
:root[data-theme="dark"] .btn-outline-secondary.show,
:root[data-theme="dark"] .btn-outline-secondary:active { color: #fff !important; }

/* GD12-2: dòng gợi ý dưới ô nhập trong hộp thoại = --bs-secondary-color bản sáng rgba(33,37,41,.75) trên #1b2129 = 1,04:1
   ("Bỏ trống = phần mềm tự sinh mật khẩu." ở hộp người dùng chìm hẳn). --gd-chu-mo đạt 6,8:1. Chữ báo đỏ dùng chung lớp
   (form-text text-danger ở hộp giờ mặt trời) vẫn theo luật .text-danger !important ở trên. */
:root[data-theme="dark"] .form-text { color: var(--gd-chu-mo); }

/* GD12-3: khung "Đặt điểm sáng trên tuyến" ở /Map (nền #fff / #f8f9fa cứng trong Views/Map/Index.cshtml) và đầu ba cột
   của hộp "Tạo kịch bản khu vực điểm sáng" (/KichBan, var(--bs-tertiary-bg) bản sáng): chữ #e6eaee trên nền trắng
   1,15–1,21:1. Hộp chọn lớp nền bản đồ của Leaflet cùng bệnh. */
:root[data-theme="dark"] .rd-panel { background: var(--gd-the) !important; border-color: var(--gd-vien) !important; }
:root[data-theme="dark"] .rd-head { background: #232b34 !important; border-bottom-color: var(--gd-vien) !important; }
:root[data-theme="dark"] .kv-cot-dau { background: #232b34 !important; border-bottom-color: var(--gd-vien) !important; }
:root[data-theme="dark"] .leaflet-control-layers { background: var(--gd-the); color: var(--gd-chu); }
:root[data-theme="dark"] .leaflet-control-layers-separator { border-top-color: var(--gd-vien); }

/* KT4-HT-4: tab đang chọn nền trắng giữa màn hình tối (/Monitor, /Report, /Help, /KichBan, /Catalog, /VatTu, /BaoTri…),
   chói mắt ca đêm. Đưa về nền thẻ, chữ cổ vịt sáng như tab chưa chọn nhưng giữ đường viền để vẫn thấy tab nào đang mở.
   #4fb3b3 trên #1b2129 = 6,5:1. Biểu tượng text-primary trong tab đang mở trước để cổ vịt đậm vì nền trắng (site.css),
   nay nền tối nên trả về sắc sáng; luật này nạp sau site.css, cùng đặc hiệu nên thắng. */
:root[data-theme="dark"] .nav-tabs { --bs-nav-tabs-border-color: var(--gd-vien); --bs-nav-tabs-link-hover-border-color: var(--gd-vien); }
:root[data-theme="dark"] .nav-tabs .nav-link.active {
    background-color: var(--gd-the); color: var(--scada-chinh-chu-toi);
    border-color: var(--gd-vien) var(--gd-vien) var(--gd-the);
}
:root[data-theme="dark"] .nav-tabs .nav-link.active .text-primary { color: var(--scada-chinh-chu-toi) !important; }

/* KT4-HT-4: hộp .alert nền vàng/hồng/xanh nhạt (/KhoaVanHanh, /Control khi đang lọc, /Energy). Dùng đúng bộ màu Bootstrap
   tự dùng cho chế độ tối: nền trầm, chữ sáng cùng sắc (đều ≥ 7:1). .alert-secondary đã có luật riêng ở trên. */
:root[data-theme="dark"] .alert-warning { --bs-alert-bg: #332701; --bs-alert-color: #ffda6a; --bs-alert-border-color: #997404; --bs-alert-link-color: #ffe69c; }
:root[data-theme="dark"] .alert-danger  { --bs-alert-bg: #2c0b0e; --bs-alert-color: #ea868f; --bs-alert-border-color: #842029; --bs-alert-link-color: #f1aeb5; }
:root[data-theme="dark"] .alert-success { --bs-alert-bg: #051b11; --bs-alert-color: #75b798; --bs-alert-border-color: #0f5132; --bs-alert-link-color: #a3cfbb; }
:root[data-theme="dark"] .alert-info    { --bs-alert-bg: #032830; --bs-alert-color: #6edff6; --bs-alert-border-color: #087990; --bs-alert-link-color: #9eeaf9; }
:root[data-theme="dark"] .alert-primary { --bs-alert-bg: #031633; --bs-alert-color: #6ea8fe; --bs-alert-border-color: #084298; --bs-alert-link-color: #9ec5fe; }
:root[data-theme="dark"] .alert-light   { --bs-alert-bg: #232b34; --bs-alert-color: var(--gd-chu); --bs-alert-border-color: var(--gd-vien); --bs-alert-link-color: var(--gd-chu); }
/* Luật chữ trạng thái ở trên CHỪA .alert vì nền alert trước đây vẫn sáng. Nay nền alert đã tối, chữ đỏ/lục/xám đậm của
   Bootstrap trong alert (#dc3545 trên #332701 ≈ 3:1) phải đổi sang sắc sáng như ngoài alert. */
:root[data-theme="dark"] .alert .text-danger { color: #ea868f !important; }
:root[data-theme="dark"] .alert .text-success { color: #75b798 !important; }
:root[data-theme="dark"] .alert .text-secondary { color: var(--gd-chu-mo) !important; }

/* KT5-HT-3 (16/11/2026): khung "Đặt điểm sáng trên tuyến" (/Map) đã về nền tối ở GD12-3, nhưng Views/Map/Index.cshtml còn
   đặt cứng chữ gợi ý (.rd-mo), nhãn ô (.rd-o .form-label) = #6c757d (3,46:1 trên #1b2129) và dòng trạng thái (.rd-tt)
   = #212529 (gần như vô hình). Đặc hiệu 0,3,0 / 0,4,0 thắng luật trong trang. --gd-chu-mo đạt 6,4:1. */
:root[data-theme="dark"] .rd-mo,
:root[data-theme="dark"] .rd-o .form-label { color: var(--gd-chu-mo); }
:root[data-theme="dark"] .rd-tt { color: var(--gd-chu); }

/* KT5-HT-4: đường dẫn (.breadcrumb, /Control/DiemSang) đọc --bs-secondary-color bản sáng rgba(33,37,41,.75): mục cuối và
   dấu "/" ra 1,12:1 trên nền #12161b; --gd-chu-mo đạt 7,2:1. Cùng gốc GD12-2 (.form-text). */
:root[data-theme="dark"] .breadcrumb {
    --bs-breadcrumb-divider-color: var(--gd-chu-mo);
    --bs-breadcrumb-item-active-color: var(--gd-chu-mo);
}

/* KT5-HT-5: chế độ SÁNG, chữ vàng/xanh nhạt Bootstrap trên nền trắng: .text-warning #ffc107 1,63:1 (số đếm /Monitor/Transducer,
   /ThongKe/BatThuong, /Control/Tu NLMT), .text-info #0dcaf0 1,96:1 (kWh /ThongKe), nút viền vàng "Cân đối pin" 1,55:1.
   Đổi sang sắc trầm cùng màu: #856404 đạt 5,49:1 trên trắng, #0a7489 đạt 5,42:1. Chừa biểu tượng (<i>, vòng quay, ô biểu
   tượng thẻ số): ngưỡng đồ hoạ là 3:1 và màu vàng sáng ở đó là nhận diện, không phải chữ. Chế độ tối giữ nguyên màu
   Bootstrap (#ffc107 trên #1b2129 đã đạt 9,9:1). */
:root:not([data-theme="dark"]) .text-warning:not(i, .spinner-border, .stat-icon) { color: #856404 !important; }
:root:not([data-theme="dark"]) .text-info:not(i, .spinner-border, .stat-icon) { color: #0a7489 !important; }
:root:not([data-theme="dark"]) .btn-outline-warning { --bs-btn-color: #856404; --bs-btn-disabled-color: #856404; }

/* Ô chọn tệp của phần mềm (giao-dien-moi.js, ganChonTep): ô gốc vẫn nằm trong khung để required, .files, change và
   bóng báo lỗi của trình duyệt chạy như cũ, chỉ không vẽ ra; nút và dòng chữ là nhãn trỏ vào nó. */
.gd-chon-tep { position: relative; flex-wrap: nowrap; }
.gd-chon-tep > .gd-chon-tep-goc { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.gd-chon-tep > .btn, .gd-chon-tep > .gd-chon-tep-chu { cursor: pointer; }
.gd-chon-tep > .gd-chon-tep-chu { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gd-chon-tep:focus-within > .btn { box-shadow: 0 0 0 .2rem rgba(13, 110, 253, .25); }
/* Ô gốc đứng cuối khung nên Bootstrap coi dòng chữ là phần tử giữa và bỏ bo góc phải của nó. */
.gd-chon-tep > .gd-chon-tep-chu:nth-last-child(2) { border-top-right-radius: var(--bs-border-radius); border-bottom-right-radius: var(--bs-border-radius); }
.gd-chon-tep.input-group-sm > .gd-chon-tep-chu:nth-last-child(2) { border-top-right-radius: var(--bs-border-radius-sm); border-bottom-right-radius: var(--bs-border-radius-sm); }

/* Phiếu bảo trì in (/BaoTri/InPhieu) là một TỜ GIẤY: site.css ép chữ đen cho bản in, nhưng ở chế độ tối nền trang tối nên
   "Người lập phiếu", "Mức độ", chữ ký... ra đen trên đen, tương phản 1,16 (vận hành 18/11 V2-15). Trên màn hình tối, khổ
   phiếu luôn nền trắng chữ đen, đúng như tờ sẽ in ra; luật bảng tối chung (chữ sáng, nền trong suốt) không áp vào trong phiếu. */
:root[data-theme="dark"] .phieu-in { background: #fff; color: #000; padding: 1rem; border-radius: .375rem; }
:root[data-theme="dark"] .phieu-in .table { color: #000; border-color: #666; }
:root[data-theme="dark"] .phieu-in .table > :not(caption) > * > * { color: #000; border-color: #666 !important; }
:root[data-theme="dark"] .phieu-in .pi-bang thead th { background-color: #e9ecef !important; }
@media print {
    :root[data-theme="dark"] .phieu-in { padding: 0; }
}
/* Màn 390 px: nhãn cột trái của bảng thông tin không xuống dòng (site.css, đúng cho khổ A4) nên bảng rộng hơn màn
   105 px và cả trang cuộn ngang (vận hành 18/11 V2-12). Chỉ trên màn hẹp, không đổi bản in. */
@media screen and (max-width: 575.98px) {
    .phieu-in .pi-thongtin td:nth-child(odd) { white-space: normal; }
    /* break-word chứ không anywhere: anywhere bẻ giữa chữ ("Ngườ|i", "Thườn|g") dù chữ vừa một dòng. */
    .phieu-in .pi-thongtin td { padding: .3rem .4rem; overflow-wrap: break-word; }
    /* Cột "TT" 5% của khổ A4 chỉ còn ~17 px, chữ "TT" bị tách hai dòng. */
    .phieu-in .pi-bang th:first-child, .phieu-in .pi-bang td:first-child { width: 2.2rem !important; }
    .phieu-in .pi-bang th, .phieu-in .pi-bang td { overflow-wrap: break-word; word-break: normal; }
    /* N6 (van-hanh-web-19-11): khổ A4 dùng table-layout fixed theo phần trăm; ở 390 px mỗi cột còn ~65 px, chữ
       "Reported", "replaced" dài hơn cột nên vẫn bị bẻ giữa chữ ("Repor|ted"). Màn hẹp cho cột co theo chữ dài
       nhất, chữ nhỏ lại một bậc, và gạch nối theo ngôn ngữ trang khi thật sự hết chỗ. Không đổi bản in. */
    .phieu-in .pi-bang { table-layout: auto; }
    .phieu-in .pi-bang th, .phieu-in .pi-bang td { font-size: .8rem; padding: .25rem .3rem; hyphens: auto; }
    .phieu-in .pi-tieude { font-size: 1.25rem; }
    .phieu-in .pi-ky { width: 32%; }
}
/* Bong bóng trợ lý đang nằm trên một nút / ô bấm được (giao-dien-moi.js, nhuongChoTroLy): mờ đi và cho cú bấm
   xuyên qua tới thứ bên dưới. */
.tro-ly-nut.tro-ly-nhuong { opacity: .25; pointer-events: none; }
/* Khung chi tiết tủ/đèn trên Bản đồ (body.md-dang-chon) chiếm đáy màn hình ở mọi khổ: site.css chỉ ẩn bong bóng trợ lý
   dưới 768 px, nên ở 1366 px bong bóng đè cột "Thông tin tủ" (toạ độ) của khung (vận hành 18/11, ảnh map-panel). Ẩn
   bong bóng khi khung đang mở; hộp chat đang mở thì giữ. */
body.md-dang-chon .tro-ly-nut { display: none !important; }

/* "Cắt 100%" trong menu chuột phải của tủ (control-menu.js, 03/12/2026): tắt cả tuyến nên tách khỏi các mục Đóng. */
.scada-context-menu-item.nguy-hiem { color: #b02a37; font-weight: 700; }
:root[data-theme="dark"] .scada-context-menu-item.nguy-hiem { color: #ea868f; }

/* V2-8 (vận hành 18/11, đo lại 18/11 ở 1366 sáng): còn bốn kiểu chữ dưới 4,5:1 ở chế độ SÁNG, cùng hướng chữa với
   KT5-HT-5 ở trên (sắc trầm cùng màu, chế độ tối không đổi):
   - nút viền xám #6c757d trên nền thẻ xám nhạt: 4,07 ("Làm mới", "In danh sách", "Hỏi định vị GPS") -> #565e64, 6,0;
   - nút viền xanh lá #198754: 3,93 ("Nhập Excel", "Tạo hàng loạt", "Xuất Excel") -> #146c43, 6,2;
   - huy hiệu xám ở bảng Báo cáo: 3,80 -> nền #565e64;
   - chữ đỏ .text-danger trên nền xám nhạt: 4,30 (phạm vi "Tất cả khu vực" ở Điều khiển) -> #b02a37, 6,1;
   - nút viền đỏ ("Khoá vận hành"): 4,30 -> #b02a37;
   - mũi tên sắp xếp cột #adb5bd: 1,97 -> #5c636a (trên nền tiêu đề bảng xám nhạt #6c757d chỉ đạt 4,27-4,45). */
:root:not([data-theme="dark"]) .btn-outline-secondary { --bs-btn-color: #565e64; }
:root:not([data-theme="dark"]) .btn-outline-success { --bs-btn-color: #146c43; }
:root:not([data-theme="dark"]) .badge.bg-secondary { background-color: #565e64 !important; }
:root:not([data-theme="dark"]) .text-danger:not(i, .spinner-border) { color: #b02a37 !important; }
:root:not([data-theme="dark"]) .js-sort thead th:not([data-dir]) .th-arrow { color: #5c636a; }
/* Mũi tên của cột đang sắp (#0d6efd) trên nền tiêu đề xám nhạt: 4,27. */
:root:not([data-theme="dark"]) .js-sort thead th[data-dir] .th-arrow { color: #0a58ca; }
:root:not([data-theme="dark"]) .btn-outline-danger { --bs-btn-color: #b02a37; }
/* ===== ĐIỆN THOẠI: DANH SÁCH ĐÈN VÀ KHOÁ VẬN HÀNH THÀNH THẺ (03/12/2026) =====
   Hai bảng này là chỗ thợ ngoài tuyến BẤM: kéo ngang mới tới nút Gửi, và khi tới thì tên đèn đã trôi khỏi màn hình. Dưới 768 px
   mỗi dòng thành một thẻ, đủ nút trong bề ngang màn hình. Bảng ở máy tính không đổi. */
@media (max-width: 767.98px) {
    .trang-diem-sang table, .trang-diem-sang tbody, .kvh-bang, .kvh-bang > tbody { display: block; width: 100% !important; min-width: 0 !important; }
    .trang-diem-sang thead, .kvh-bang > thead { display: none; }
    .trang-diem-sang .table-responsive, .kvh-the { overflow: visible; background: none; }
    /* Không còn cuộn ngang: bỏ dải mờ và mũi tên "vuốt sang phải" (site.css .co-cuon). */
    .trang-diem-sang .table-responsive::before, .trang-diem-sang .table-responsive::after, .kvh-the::before, .kvh-the::after { content: none !important; }
    /* Cột tên đứng yên của bảng cuộn ngang (site.css .cot-ten-dung-yen): thẻ không cuộn, gỡ bề rộng ép và vạch bóng ở mép cột. */
    .trang-diem-sang .table-responsive > table[class] > tbody > tr > td:nth-child(n+2):not([colspan]):not(.x) { width: auto !important; min-width: 0 !important; max-width: none !important; }
    .trang-diem-sang tbody > tr > td::after, .kvh-bang > tbody > tr > td:nth-child(4)::after { content: none !important; }
    .trang-diem-sang tbody > tr::after { content: ""; order: 2; flex: 1 0 100%; }
    .trang-diem-sang tbody > tr { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; padding: 10px 2px; border-bottom: 1px solid var(--bs-border-color); }
    .trang-diem-sang tbody > tr > td, .kvh-bang > tbody > tr > td {
        position: static !important; display: block; border: 0 !important; padding: 0 !important; width: auto !important; min-width: 0 !important;
        max-width: none !important; text-align: left !important; white-space: normal; background: transparent !important; box-shadow: none !important;
    }
    .trang-diem-sang tbody > tr > td[colspan] { flex: 1 0 100%; }
    .trang-diem-sang tbody > tr > td:nth-child(1):not([colspan]) { display: none; }
    .trang-diem-sang tbody > tr > td:nth-child(2) { order: 1; flex: 1 1 0; font-weight: 600; overflow-wrap: anywhere; }
    .trang-diem-sang tbody > tr > td:nth-child(5) { order: 2; }
    .trang-diem-sang tbody > tr > td:nth-child(3) { order: 3; font-size: .8rem; color: var(--bs-secondary-color); }
    .trang-diem-sang tbody > tr > td:nth-child(4) { order: 4; flex: 1 1 55%; font-size: .8rem; color: var(--bs-secondary-color); }
    .trang-diem-sang tbody > tr > td:nth-child(4)::before { content: "· "; }
    .trang-diem-sang tbody > tr > td[data-nhan] { order: 5; font-size: .8rem; }
    .trang-diem-sang tbody > tr > td[data-nhan]::before { content: attr(data-nhan) ": "; color: var(--bs-secondary-color); }
    .trang-diem-sang tbody > tr > td.o-lenh { order: 9; flex: 1 0 100%; margin-top: 6px; }
    .trang-diem-sang td.o-lenh > div { display: flex !important; }
    .trang-diem-sang td.o-lenh select { flex: 1 1 auto; width: auto !important; min-width: 0; }

    .kvh-bang > tbody > tr { display: grid; grid-template-columns: 34px auto 1fr; align-items: baseline; padding: 10px 14px; border-bottom: 1px solid var(--bs-border-color); }
    .kvh-bang > tbody > tr.d-none { display: none !important; }
    .kvh-bang > tbody > tr > td:nth-child(1) { grid-row: 1 / span 2; align-self: center; }
    .kvh-bang > tbody > tr > td:nth-child(1) input { width: 20px; height: 20px; }
    .kvh-bang > tbody > tr > td:nth-child(2) { display: none; }
    .kvh-bang > tbody > tr > td:nth-child(3), .kvh-bang > tbody > tr > td:nth-child(4) { font-weight: 600; }
    .kvh-bang > tbody > tr > td:nth-child(3)::after { content: " ·"; white-space: pre; padding-right: 5px; }
    .kvh-bang > tbody > tr > td:nth-child(5) { grid-column: 2 / 4; font-size: .8rem; color: var(--bs-secondary-color); }
    .kvh-bang > tbody > tr > td:nth-child(6) { grid-column: 2 / 4; }
    /* Nút khoá luôn trong tầm ngón tay: danh sách dài hàng chục tủ, nút ở đầu thẻ trôi mất ngay sau vài dòng. */
    #kvhNut { position: fixed; left: 12px; right: 12px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); z-index: 1035; padding: 10px; font-size: 1rem; box-shadow: 0 2px 10px rgba(0, 0, 0, .3); }
    #kvhNut:disabled { opacity: 1; background: #adb5bd; border-color: #adb5bd; color: #212529; }
    body.modal-open #kvhNut { z-index: 1; }
    /* Bảng "Đang khoá" không có dòng nào: câu báo phải xuống dòng trong màn hình, đầu bảng chín cột chỉ làm nó bị cắt. */
    .kvh-trong, .kvh-trong > tbody, .kvh-trong > tbody > tr, .kvh-trong > tbody > tr > td { display: block; width: 100% !important; min-width: 0 !important; white-space: normal !important; }
    .kvh-trong > thead { display: none; }
}
