:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #dfe3e8;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --ok: #16a34a;
  --suspect: #d97706;
  --wrong: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}

.login-card h1 { font-size: 1.2rem; margin: 0; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type=text], input[type=password], input[type=search] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.9rem;
  background: var(--primary);
  color: white;
  transition: background 0.15s;
}
button:hover { background: var(--primary-dark); }
button:disabled { background: #b6c2d9; cursor: not-allowed; }

.btn-secondary { background: #475569; }
.btn-secondary:hover { background: #334155; }
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  text-decoration: none;
  display: inline-block;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-ghost:hover { background: #eef0f3; }

.error-text { color: var(--wrong); font-size: 0.85rem; margin: 0; }
.muted { color: var(--muted); font-size: 0.85rem; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}
.topbar h1::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: var(--primary);
  flex: none;
}
.topbar-right { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.topbar-right #whoami {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  margin-right: 8px;
  background: #eef2ff;
  color: var(--primary-dark);
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.78rem;
  white-space: nowrap;
}
.topbar-right #whoami::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  flex: none;
}

/* Nav links: a visible (if faint) border by default so they read as
   distinct clickable buttons, not just colored text -- hover/focus fill in
   a stronger tint for a clear, quick response ("de bam, muot ma"). */
.topbar-right .btn-ghost {
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
}
.topbar-right .btn-ghost:hover { background: #eef2ff; border-color: #c7d5ff; color: var(--primary-dark); }
.topbar-right .btn-ghost:active { background: #e0e9ff; }
.topbar-right .btn-ghost:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.topbar-right #logoutBtn {
  margin-left: 8px;
  color: var(--wrong);
  font-weight: 600;
}
.topbar-right #logoutBtn:hover { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.topbar-right #logoutBtn:active { background: #fee2e2; }

.container {
  max-width: 1800px;
  margin: 20px auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Quá hạn page has an unusually wide table (13 cols) plus 2 config
   panels -- give it the full viewport instead of the 1800px cap used
   elsewhere. */
.container-wide { max-width: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}

.panel-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Collapsible section header (Khai bao... panels on trang Qua han) --
   default state is collapsed; JS toggles the sibling .collapsible-body's
   `hidden` attribute and flips the caret + aria-expanded. */
.collapsible-header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.collapsible-header h2 { margin: 0; }
.collapsible-header .collapse-icon {
  color: var(--muted);
  font-size: 0.8rem;
  transition: transform 0.15s;
  flex: none;
}
.collapsible-header[aria-expanded="true"] .collapse-icon { transform: rotate(90deg); }
.collapsible-body { margin-top: 14px; }

.file-picker {
  display: inline-flex;
  align-items: center;
  padding: 9px 16px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--muted);
}
.file-picker:hover { border-color: var(--primary); color: var(--text); }

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.stat-tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  min-width: 130px;
  flex: 0 1 auto;
}
.stat-tile .num { font-size: 1.4rem; font-weight: 600; }
.stat-tile .label { font-size: 0.78rem; color: var(--muted); }

.filter-group { padding: 14px 0; border-bottom: 1px solid var(--border); }
.filter-group:first-child { padding-top: 0; }
.filter-group-title { font-size: 0.92rem; margin: 0 0 10px; }
.filter-group-title .muted { font-size: 0.8rem; font-weight: 400; }
#filterChips .stats-bar { margin-bottom: 10px; }
#filterChips #searchInput { margin-top: 14px; width: 100%; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  background: #eef0f3;
  color: var(--text);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
}
.chip:hover { background: #e2e6ec; }
.chip.active { background: var(--primary); color: white; }

/* Trang Qua han only: turn the stat tiles + their matching filter chips
   into 2 grids with the SAME column count, so each chip sits directly
   under its stat tile. Scoped to #filterChips -- .stats-bar/.chip are
   reused on trang chinh (index.html) with different tile counts per row,
   where the flex-wrap layout above must stay untouched. */
#filterChips .stats-bar,
#filterChips .chips-aligned {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 10px;
}
#filterChips .chips-aligned { margin: 8px 0 10px; }
#filterChips .chips-aligned .chip {
  width: 100%;
  text-align: center;
  justify-content: center;
  border-radius: 8px;
  padding: 8px 6px;
}
#filterChips .chip-all-row { margin-bottom: 10px; }
@media (max-width: 1100px) {
  #filterChips .stats-bar, #filterChips .chips-aligned { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 640px) {
  #filterChips .stats-bar, #filterChips .chips-aligned { grid-template-columns: repeat(2, 1fr); }
}

/* Mau rieng cho tung loai so lieu -- lam bang so lieu sinh dong hon va giup
   nhin la lien he ngay duoc voi nut loc mau tuong ung ben duoi no. */
#filterChips .stat-tile { border-left: 4px solid transparent; }
#filterChips .stat-tile[data-stat="dung_han"] { background: #dcfce7; border-left-color: #16a34a; }
#filterChips .stat-tile[data-stat="dung_han"] .num { color: #16a34a; }
#filterChips .stat-tile[data-stat="qua_han"] { background: #fee2e2; border-left-color: #dc2626; }
#filterChips .stat-tile[data-stat="qua_han"] .num { color: #dc2626; }
#filterChips .stat-tile[data-stat="chua_du_du_lieu"] { background: #e5e7eb; border-left-color: #4b5563; }
#filterChips .stat-tile[data-stat="chua_du_du_lieu"] .num { color: #4b5563; }
#filterChips .stat-tile[data-stat="chua_co_chinh_sach"] { background: #e0e7ff; border-left-color: #4338ca; }
#filterChips .stat-tile[data-stat="chua_co_chinh_sach"] .num { color: #4338ca; }
#filterChips .stat-tile[data-stat="needs_giai_trinh"] { background: #fef3c7; border-left-color: #b45309; }
#filterChips .stat-tile[data-stat="needs_giai_trinh"] .num { color: #b45309; }
#filterChips .stat-tile[data-stat="needs_qc"] { background: #ede9fe; border-left-color: #7c3aed; }
#filterChips .stat-tile[data-stat="needs_qc"] .num { color: #7c3aed; }
#filterChips .stat-tile[data-stat="bh30_total"] { background: #dbeafe; border-left-color: #2563eb; }
#filterChips .stat-tile[data-stat="bh30_total"] .num { color: #2563eb; }
#filterChips .stat-tile[data-stat="needs_bh30_giai_trinh"] { background: #ffedd5; border-left-color: #c2410c; }
#filterChips .stat-tile[data-stat="needs_bh30_giai_trinh"] .num { color: #c2410c; }
#filterChips .stat-tile[data-stat="needs_bh30_qc"] { background: #ccfbf1; border-left-color: #0d9488; }
#filterChips .stat-tile[data-stat="needs_bh30_qc"] .num { color: #0d9488; }

#filterChips .chips-aligned .chip[data-filter="dung_han"] { background: #dcfce7; color: #15803d; }
#filterChips .chips-aligned .chip[data-filter="dung_han"].active { background: #16a34a; color: #fff; }
#filterChips .chips-aligned .chip[data-filter="qua_han"] { background: #fee2e2; color: #b91c1c; }
#filterChips .chips-aligned .chip[data-filter="qua_han"].active { background: #dc2626; color: #fff; }
#filterChips .chips-aligned .chip[data-filter="chua_du_du_lieu"] { background: #e5e7eb; color: #374151; }
#filterChips .chips-aligned .chip[data-filter="chua_du_du_lieu"].active { background: #4b5563; color: #fff; }
#filterChips .chips-aligned .chip[data-filter="chua_co_chinh_sach"] { background: #e0e7ff; color: #3730a3; }
#filterChips .chips-aligned .chip[data-filter="chua_co_chinh_sach"].active { background: #4338ca; color: #fff; }
#filterChips .chips-aligned .chip[data-filter="needs_giai_trinh"] { background: #fef3c7; color: #92400e; }
#filterChips .chips-aligned .chip[data-filter="needs_giai_trinh"].active { background: #b45309; color: #fff; }
#filterChips .chips-aligned .chip[data-filter="needs_qc"] { background: #ede9fe; color: #6d28d9; }
#filterChips .chips-aligned .chip[data-filter="needs_qc"].active { background: #7c3aed; color: #fff; }
#filterChips .chips-aligned .chip[data-filter="bh30_total"] { background: #dbeafe; color: #1d4ed8; }
#filterChips .chips-aligned .chip[data-filter="bh30_total"].active { background: #2563eb; color: #fff; }
#filterChips .chips-aligned .chip[data-filter="needs_bh30_giai_trinh"] { background: #ffedd5; color: #9a3412; }
#filterChips .chips-aligned .chip[data-filter="needs_bh30_giai_trinh"].active { background: #c2410c; color: #fff; }
#filterChips .chips-aligned .chip[data-filter="needs_bh30_qc"] { background: #ccfbf1; color: #0f766e; }
#filterChips .chips-aligned .chip[data-filter="needs_bh30_qc"].active { background: #0d9488; color: #fff; }
#filterChips .chips-aligned .chip:hover:not(.active) { filter: brightness(0.95); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
td.wrap { max-width: 340px; white-space: pre-wrap; }

/* Long tables (VD: Bao cao tong hop theo lo) -- pin the header while the
   body scrolls, so column names stay visible instead of scrolling away. */
.table-scroll { max-height: 560px; overflow-y: auto; }
.table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #334155;
  color: #fff;
  border-bottom: 2px solid #1e293b;
}
/* Trang Qua han's main table is the page's whole point -- give it most of
   the viewport instead of the modest default height. */
.table-scroll.table-scroll-tall { max-height: calc(100vh - 220px); }

/* Natural column sizing (table-wrap already scrolls horizontally) -- the
   accordion redesign (see below) dropped the old <colgroup> in favor of
   per-column min-width hints, closer to what the columns actually need. */
#overdueRowsTable { table-layout: auto; }
#overdueRowsTable td, #overdueRowsTable th { overflow-wrap: break-word; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.badge-K { background: #dcfce7; color: var(--ok); }
.badge-N { background: #fef3c7; color: var(--suspect); }
.badge-S { background: #fee2e2; color: var(--wrong); }
.badge-pending { background: #e5e7eb; color: var(--muted); }
.badge-warn { background: #fde68a; color: #92400e; margin-left: 4px; cursor: help; }
.ai-reason { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

.btn-mini { padding: 2px 8px; font-size: 0.72rem; background: #475569; border-radius: 6px; vertical-align: middle; }
.btn-mini:hover { background: #334155; }

/* width:100% (not a fixed min-width) so this box never forces itself wider
   than whatever column/panel currently holds it. */
.qc-cell { display: flex; flex-direction: column; gap: 4px; width: 100%; min-width: 0; }
.qc-cell select, .qc-cell input[type=text] {
  width: 100%;
  padding: 5px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.82rem;
}
.qc-cell .saved-tag { font-size: 0.75rem; color: var(--ok); }
.qc-cell .saved-summary { font-size: 0.78rem; color: var(--text); }
.qc-cell .saved-summary b { font-weight: 600; }
.qc-cell button { padding: 5px 10px; font-size: 0.78rem; align-self: flex-start; }

/* ============================================================
   "Theo doi, giai trinh may qua han sua chua" -- accordion redesign.
   Design ref: mockup-theo-doi-phieu-bao-hanh.html + spec-bang-theo-doi-
   phieu-bao-hanh.md. The main table row stays compact/scannable (1 summary
   chip per task instead of a full form inline); clicking a row expands a
   detail panel below it with the same forms as before, just relocated.
   Presentation only -- every data-* hook below matches what quahan.js's
   existing save/clear/picker functions already query, so none of those
   functions needed to change.
   ============================================================ */
#overdueRowsTable tbody tr.row { cursor: pointer; }
#overdueRowsTable tbody tr.row:hover td { background: #fafbfc; }
#overdueRowsTable tbody tr.row.active td { background: #f4f7fd; }
#overdueRowsTable tbody td { vertical-align: top; }

/* First column stays visible while scrolling the wide table horizontally. */
#overdueRowsTable thead th:first-child,
#overdueRowsTable tbody td:first-child { position: sticky; left: 0; z-index: 6; }
#overdueRowsTable tbody td:first-child { background: #fff; box-shadow: 1px 0 0 var(--border); }
#overdueRowsTable tbody tr.row:hover td:first-child { background: #fafbfc; }
#overdueRowsTable tbody tr.row.active td:first-child { background: #f4f7fd; }

.rowid { display: flex; align-items: center; gap: 6px; }
.rowid .so { font-weight: 600; }
.rowid .imei { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 0.78rem; }
.chev { width: 14px; height: 14px; color: var(--muted); flex-shrink: 0; transition: transform 0.15s; }
tr.row.active .chev { transform: rotate(90deg); color: var(--primary); }

/* "Cach sua" moved into the detail panel's mo-ta box (see quahan.js), which
   freed up a column -- give the remaining ones (VD: Ten hang, KTV, Khach
   hang, often long text) more breathing room instead of staying cramped. */
#overdueRowsTable td:nth-child(2), #overdueRowsTable th:nth-child(2) { min-width: 170px; }
#overdueRowsTable td:nth-child(3), #overdueRowsTable th:nth-child(3) { min-width: 140px; }
#overdueRowsTable td:nth-child(4), #overdueRowsTable th:nth-child(4) { min-width: 130px; }
#overdueRowsTable td:nth-child(5), #overdueRowsTable th:nth-child(5) { min-width: 190px; }

.barwrap { width: 80px; }
.bar { height: 5px; border-radius: 4px; background: #edeef1; overflow: hidden; margin-bottom: 3px; }
.bar i { display: block; height: 100%; border-radius: 4px; }
.bar i.danger { background: #dc2626; }
.bar i.ok { background: #16a34a; }
.barlabel { font-size: 0.72rem; color: var(--muted); }

.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; display: inline-block; }
.badge { display: inline-flex; align-items: center; gap: 5px; }
.badge.ok { background: #e9f7ee; color: #1e6b3c; border: 1px solid #a9dcbc; }
.badge.danger { background: #fdecec; color: #a12626; border: 1px solid #f3b9b9; }
.badge.gray { background: #f1f2f4; color: #5c6270; border: 1px solid #dcdee3; }
.badge.amber2 { background: #fef3e2; color: #8a5a05; border: 1px solid #f0cf8f; }

.taskcell { min-width: 190px; }
.taskchip { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.taskchip .badge { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.taskchip .muted { font-size: 0.72rem; }
.na { color: var(--muted); font-size: 0.78rem; }
.expand-hint { display: flex; align-items: center; gap: 4px; font-size: 0.72rem; color: var(--primary); font-weight: 500; margin-top: 6px; }
.expand-hint svg { width: 12px; height: 12px; transition: transform 0.15s; }
tr.row.active .expand-hint svg { transform: rotate(180deg); }

/* Detail panel row -- hidden by default so a full re-render (after any
   Luu) naturally collapses it; explicit display:none for the same
   `[hidden]`-specificity-tie reason documented elsewhere in this file (the
   .open class swap here plays the same role as the hidden attribute). */
.detail-row { display: none; }
.detail-row.open { display: table-row; }
.detail-row td { background: #f8f9fb; padding: 0 !important; }
.detail-wrap { padding: 16px 20px 20px; }
.detail-desc {
  font-size: 0.82rem; color: var(--text); line-height: 1.7; white-space: pre-wrap;
  background: #fff; border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; margin-bottom: 14px;
}

.task-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.task-panel { background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.task-panel-head { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.task-panel-title { font-size: 0.82rem; font-weight: 600; }
.task-panel-body { padding: 14px; }
.task-panel-body.disabled { color: var(--muted); font-size: 0.78rem; padding: 20px 14px; text-align: center; }

.subsec { margin-bottom: 14px; }
.subsec:last-child { margin-bottom: 0; }
.subsec-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.subsec-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; color: var(--muted); }
.add-toggle {
  display: flex; align-items: center; gap: 4px; font-size: 0.72rem; color: var(--primary); cursor: pointer;
  font-weight: 500; background: none; border: none; padding: 2px 4px;
}
.add-toggle:hover { text-decoration: underline; }

.current .entry { position: relative; }
.current .meta { font-size: 0.7rem; color: var(--muted); margin-top: 3px; }
.empty-value { font-size: 0.78rem; color: var(--muted); padding: 2px 0; }

/* display:none by default -- see .xfilter-panel above for why a bare
   `display` here would fight the .open class the same way it fights
   `[hidden]` (same specificity, author rule wins the tie either way). */
.addform { display: none; margin-top: 10px; padding: 10px; background: var(--bg); border-radius: 8px; }
.addform.open { display: block; }
.addform select, .addform textarea, .addform .ktv-picker-btn {
  width: 100%; font-size: 0.78rem; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 7px; background: #fff;
}
.addform textarea { min-height: 40px; resize: vertical; font-family: inherit; }
.addform .save {
  width: 100%; background: #0f172a; color: #fff; border: none; border-radius: 6px; padding: 7px;
  font-size: 0.78rem; font-weight: 600; cursor: pointer;
}
.addform .save:hover { background: #1e293b; }

.bh30-analysis-block h3 { font-size: 0.92rem; }
#bh30AnalysisPanel .panel-row { justify-content: space-between; }

.totals-row td { border-top: 2px solid var(--border); font-weight: 600; background: #f9fafb; }

/* Bao cao theo KTV: 2-level table (Chuc danh nhom cha > KTV dong con). */
#ktvReportTable .ktv-group-row td { background: #f5f6f8; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
#ktvReportTable .ktv-name-cell { padding-left: 24px; }

/* A number in the KTV report that drills into the rows behind it. */
.ktv-metric-link {
  background: none;
  border: none;
  padding: 2px 6px;
  margin: -2px -6px;
  border-radius: 6px;
  font: inherit;
  font-weight: inherit;
  color: var(--primary-dark);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  transition: background 0.15s ease, text-decoration-color 0.15s ease;
}
.ktv-metric-link:hover { background: #eef2ff; text-decoration-color: var(--primary-dark); }

/* Drilldown popup: as wide as the viewport allows, scrollable body with a
   pinned header (reuses .table-scroll's sticky/contrast header). Explicit
   display:none by default -- an unconditional `display` here at the same
   specificity as the browser's own `[hidden]{display:none}` would win the
   cascade tie and keep the overlay visible regardless of the attribute. */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  align-items: flex-start;
  justify-content: center;
  padding: 32px 24px;
  overflow-y: auto;
  z-index: 200;
}
.modal-overlay:not([hidden]) { display: flex; }
.modal-box {
  background: var(--panel);
  border-radius: 12px;
  padding: 20px 24px 24px;
  width: 100%;
  max-width: calc(100vw - 48px);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.35);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-table-scroll { max-height: 65vh; }
/* Narrower variant for small pickers (VD: chon KTV khac) that don't need
   the full-viewport width the drilldown table modal uses. */
.modal-box-narrow { max-width: 420px; display: flex; flex-direction: column; gap: 10px; }
.modal-box-narrow #ktvPickerSearch { width: 100%; padding: 8px 10px; }
.modal-box-narrow .xfilter-list { max-height: 50vh; }

/* KTV picker: same "row, hover highlight" look as .xfilter-item but a plain
   clickable button (single-select) instead of a checkbox label. */
.ktv-picker-item {
  /* Explicit background/color overrides -- this is a <button>, and the
     global `button { background: var(--primary); color: white; }` rule
     wins on any property left unset here (cascade is per-property), which
     previously left the text white-on-white and invisible in the modal. */
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.88rem;
  background: none;
  color: var(--text);
  border: none;
  cursor: pointer;
}
.ktv-picker-item:hover, .ktv-picker-item:focus-visible { background: #f5f6f8; }
.ktv-picker-item .picker-name { font-weight: 600; }
.ktv-picker-item .picker-meta { color: var(--muted); font-size: 0.8rem; }

/* Button that stands in for the old <input list> -- looks like a form
   field but opens the picker modal on click instead of typing inline. */
.ktv-picker-btn {
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}
.ktv-picker-btn:hover { background: #f5f6f8; }
.ktv-picker-btn.placeholder { color: var(--muted); }

#departmentsTable td.perm-cell, #departmentsTable th.perm-cell { text-align: center; }

/* Excel-style column filter: a button that opens a searchable checklist
   dropdown (with a staged "Dong y"/"Xoa loc" apply, like Excel's AutoFilter)
   used on the "Bao cao tong hop theo KTV" filters. */
.xfilters-row { align-items: flex-start; position: relative; z-index: 25; }
.xfilter { position: relative; }
.xfilter-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.xfilter-btn:hover { background: #f5f6f8; }
.xfilter.active .xfilter-btn { border-color: var(--primary); background: #eef2ff; color: var(--primary-dark); }
.xfilter-btn .xfilter-label-text { font-weight: 600; }
.xfilter.active .xfilter-btn .xfilter-label-text { font-weight: 700; }
.xfilter-btn .xfilter-caret { color: var(--muted); font-size: 0.7rem; }

.xfilter-panel {
  /* display:none by default so the `hidden` attribute JS toggles actually
     hides it -- an explicit `display` here at the same specificity as the
     browser's built-in `[hidden]{display:none}` would win the cascade tie
     and keep the panel visible regardless of the attribute. */
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  width: 280px;
  max-width: min(280px, 90vw);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.16);
  padding: 10px;
  flex-direction: column;
  gap: 8px;
}
.xfilter-panel:not([hidden]) { display: flex; }
.xfilter-panel input[type=search] { width: 100%; padding: 7px 9px; font-size: 0.85rem; }
.xfilter-list { max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; }
.xfilter-item {
  /* .xfilter-item is a <label>, and the global `label` rule sets
     flex-direction:column (for the login form's stacked field labels) --
     without an explicit row here that leaks in and stacks the checkbox
     above the text instead of side by side. */
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  gap: 8px;
  padding: 6px 4px;
  font-size: 0.85rem;
  border-radius: 6px;
  cursor: pointer;
}
.xfilter-item:hover { background: #f5f6f8; }
.xfilter-item input { flex: none; margin: 0; }
.xfilter-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xfilter-item.xfilter-selectall {
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
  padding-bottom: 8px;
}
.xfilter-empty { font-size: 0.8rem; color: var(--muted); padding: 6px 4px; }

.xfilter-footer { display: flex; justify-content: space-between; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.xfilter-footer button { padding: 6px 14px; font-size: 0.8rem; border-radius: 6px; }
.xfilter-footer .xfilter-clear { background: #eef0f3; color: var(--text); }
.xfilter-footer .xfilter-clear:hover { background: #e2e6ec; }
.xfilter-footer .xfilter-apply { background: var(--primary); color: #fff; }
.xfilter-footer .xfilter-apply:hover { background: var(--primary-dark); }

.suggestion-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 10px;
}
.suggestion-card .rule { font-weight: 600; margin-bottom: 4px; }
.suggestion-card .reason { color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; }
.suggestion-card .actions { display: flex; gap: 8px; align-items: center; }
.suggestion-card .status-tag { font-size: 0.78rem; padding: 2px 8px; border-radius: 999px; }
.suggestion-card .status-tag.accepted { background: #dcfce7; color: var(--ok); }
.suggestion-card .status-tag.rejected { background: #e5e7eb; color: var(--muted); }

textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.5;
  resize: vertical;
}
.settings-meta { margin: 8px 0 16px; }
.settings-actions { display: flex; gap: 10px; margin-top: 12px; }

/* Trang Qua han: per-column filter (funnel icon) in each main-table header.
   The panel is position:fixed (see createXFilter's isFixed) so the table's
   scroll box can't clip it; it sits inside a white-on-slate sticky <th>, so
   reset the header's inherited text styles back to the normal panel look. */
.th-inner { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.th-filter-btn {
  padding: 3px 4px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.55);
  gap: 0;
}
.th-filter-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.xfilter.th-filter.active .th-filter-btn { background: #fbbf24; border-color: #fbbf24; color: #1e293b; }
.th-filter .xfilter-panel {
  position: fixed;
  text-transform: none;
  color: var(--text);
  font-weight: 400;
  font-size: 0.85rem;
}
/* An open panel must stack above the sticky first column of the body rows. */
#overdueRowsTable thead th:has(.xfilter-panel:not([hidden])) { z-index: 30; }
.col-filter-bar { margin-bottom: 8px; justify-content: space-between; }
