/*
 * luoi.css — bảng và lưới dữ liệu dùng chung (giao diện 2026-10, chuyển thể từ smart-grid.css của saas-thue-to-khai).
 * Phần 1 áp cho MỌI <table class="table">; phần 2 chỉ áp khi js/luoi.js đã gắn lưới (lớp .ag-table).
 */
:root { --ag-bg: #fff; --ag-head: #F8FAFC; --ag-line: #E2E8F0; --ag-line-2: #F1F5F9; --ag-text: #0F172A; --ag-muted: #475569; --ag-hover: #F8FAFC; --ag-selected: #EEF0FA; --ag-accent: #252D6D; --ag-ctl: #CBD5E1; }

/* ---------- 1. Mọi bảng ---------- */
.table { --bs-table-color: var(--ag-text); --bs-table-bg: var(--ag-bg); --bs-table-border-color: var(--ag-line-2); --bs-table-hover-bg: var(--ag-hover); --bs-table-hover-color: var(--ag-text); --bs-table-striped-bg: #FBFCFE; --bs-table-active-bg: var(--ag-selected);
  font-size: 13px; line-height: 18px; font-variant-numeric: tabular-nums; }
.table > :not(caption) > * > * { padding: 7px 10px; }
.table-sm > :not(caption) > * > * { padding: 5px 10px; }
.table-light { --bs-table-bg: var(--ag-head); --bs-table-color: var(--ag-muted); --bs-table-border-color: var(--ag-line); }
.table > thead > tr > th { background-color: var(--ag-head); color: var(--ag-muted); font-size: 12px !important; font-weight: 600 !important; letter-spacing: 0; text-transform: none; white-space: nowrap; vertical-align: middle; border-bottom: 1px solid var(--ag-line); }
/* Dòng đang tick ở cột chọn: tô nền như dòng được chọn của lưới mẫu */
.table > tbody > tr:has(> td:first-child input[type="checkbox"]:checked) > * { --bs-table-bg-state: var(--ag-selected); }

/* Cột sắp xếp phía máy chủ (th[data-sx]) khi lưới chưa gắn: vẫn có mũi tên chỉ hướng */
.table th[data-sx] { cursor: pointer; user-select: none; }
.table th[data-sx]:hover { color: var(--ag-text); }
.table th[data-sx]:not(.ag-co)::after { content: '⇅'; margin-left: 4px; font-size: 10px; line-height: 1; opacity: .35; }
.table th[data-sx][aria-sort="ascending"], .table th[data-sx][aria-sort="descending"] { color: var(--ag-accent); }
.table th[data-sx][aria-sort="ascending"]:not(.ag-co)::after { content: '▲'; opacity: 1; }
.table th[data-sx][aria-sort="descending"]:not(.ag-co)::after { content: '▼'; opacity: 1; }

/* ---------- 2. Lưới (js/luoi.js) ---------- */
.table-responsive.ag-scroll { max-height: 68vh; overflow: auto; }
.ag-table { margin-bottom: 0; }
.ag-table > thead { position: sticky; top: 0; z-index: 2; }
.ag-table.ag-cua-so > thead { top: 52px; }
.ag-table > thead > tr > th { position: relative; height: 36px; padding-top: 0; padding-bottom: 0; border: 0; box-shadow: inset -1px 0 0 var(--ag-line), inset 0 -1px 0 var(--ag-line); }
.ag-table > thead > tr > th:last-child { box-shadow: inset 0 -1px 0 var(--ag-line); }
.ag-table > tbody > tr > td { border-right: 1px solid var(--ag-line-2); }
.ag-table > tbody > tr > td:last-child { border-right: 0; }
.ag-table.ag-co-dinh { table-layout: fixed; min-width: 100%; }
.ag-table.ag-co-dinh > thead > tr > th, .ag-table.ag-co-dinh > tbody > tr > td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-table.ag-co-dinh > tbody > tr > td:has(.dropdown-menu.show) { overflow: visible; }
.ag-table .ag-an { display: none !important; }
/* Cột ghim bên phải (nút xử lý): luôn thấy dù bảng rộng phải cuộn ngang */
.table-responsive .ag-dinh-phai { position: sticky; right: 0; z-index: 1; background: var(--ag-bg); box-shadow: inset 1px 0 0 var(--ag-line), -6px 0 8px -6px rgba(15, 23, 42, .18); }
.table > thead > tr > th.ag-dinh-phai { background: var(--ag-head); z-index: 3; }
.table > tbody > tr:hover > td.ag-dinh-phai { background: var(--ag-hover); }

/* Tiêu đề: [nhãn + mũi tên sắp xếp] [kính lúp tìm trong cột, hiện khi rê chuột] | tay kéo đổi độ rộng */
.ag-th { display: flex; align-items: center; gap: 2px; min-width: 0; height: 100%; }
th.text-end > .ag-th, th.num > .ag-th { justify-content: flex-end; }
.ag-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-sort { display: flex; flex: 0 1 auto; min-width: 0; align-items: center; gap: 4px; height: 28px; margin: 0; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; box-shadow: none; }
button.ag-sort, .ag-sort.ag-sx { cursor: pointer; }
.ag-sort::after { content: '⇅'; flex: none; font-size: 10px; line-height: 1; opacity: .35; }
.ag-sort:hover { color: var(--ag-text); }
.ag-sort:hover::after { opacity: .8; }
[aria-sort="ascending"] > .ag-th .ag-sort, [aria-sort="descending"] > .ag-th .ag-sort { color: var(--ag-accent); }
[aria-sort="ascending"] > .ag-th .ag-sort::after { content: '▲'; opacity: 1; }
[aria-sort="descending"] > .ag-th .ag-sort::after { content: '▼'; opacity: 1; }
.ag-find { position: absolute; top: 50%; right: 7px; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; margin: -11px 0 0; padding: 0; border: 0; border-radius: 4px; background: var(--ag-head); color: var(--ag-muted); opacity: 0; cursor: pointer; box-shadow: -6px 0 6px var(--ag-head); }
th:hover > .ag-th > .ag-find, .ag-find:focus-visible { opacity: 1; }
.ag-find:hover { background: var(--ag-line); color: var(--ag-text); box-shadow: none; }
.ag-find[aria-expanded="true"], .ag-find.is-active { opacity: 1; background: var(--ag-selected); color: var(--ag-accent); box-shadow: none; }
.ag-handle { position: absolute; top: 0; right: 0; bottom: 0; width: 6px; cursor: col-resize; touch-action: none; z-index: 3; }
.ag-handle:hover, .ag-handle.ag-active { background: var(--ag-accent); }
body.ag-resizing { cursor: col-resize !important; user-select: none !important; }

/* Hàng tìm theo cột: chỉ hiện khi có cột đang mở ô tìm */
.ag-table > thead > tr.ag-filters > th { height: auto; padding: 4px 6px 5px; }
.ag-filters input { display: block; width: 100%; min-width: 0; height: 26px; margin: 0; padding: 0 6px; border: 1px solid var(--ag-ctl); border-radius: 4px; background: var(--ag-bg); color: var(--ag-text); font-size: 12px; font-weight: 400; line-height: 1; box-shadow: none; }
.ag-filters input:focus { outline: 2px solid var(--ag-accent); outline-offset: 0; border-color: var(--ag-accent); }
.ag-filters input::placeholder { color: var(--ag-muted); opacity: .8; }

/* Thanh trạng thái dưới lưới */
.ag-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 34px; padding: 4px 12px; border-top: 1px solid var(--ag-line); background: var(--ag-bg); font-size: 12px; line-height: 16px; color: var(--ag-muted); }
.ag-toolbar:last-child { border-radius: 0 0 8px 8px; }
.ag-count { font-variant-numeric: tabular-nums; font-weight: 500; }
.ag-tip { margin-left: auto; opacity: .85; }
.ag-toolbar button, .ag-empty button { height: 26px; margin: 0; padding: 0 8px; border: 1px solid var(--ag-ctl); border-radius: 6px; background: var(--ag-bg); color: var(--ag-text); font-size: 12px; font-weight: 500; line-height: 1; cursor: pointer; }
.ag-toolbar button:hover, .ag-empty button:hover { border-color: var(--ag-accent); color: var(--ag-accent); }
.ag-empty { padding: 20px; color: var(--ag-muted); text-align: center; font-size: 13px; line-height: 18px; }
.ag-table :focus-visible, .ag-toolbar :focus-visible { outline: 2px solid var(--ag-accent); outline-offset: 1px; }

@media (max-width: 860px) { .ag-tip { display: none; } }
@media print {
  .ag-toolbar, .ag-filters, .ag-handle, .ag-find { display: none !important; }
  .table-responsive.ag-scroll { max-height: none; overflow: visible; }
  .ag-table > thead { position: static; }
}
