/* =========================================================================
   assign-picker.css — Dropdown ĐỔI công ty / trạm (AssignPicker, assign-picker.js).
   Dùng ở: chi tiết cột trang Chủ (tab Thông tin), form cột /Pumphose, form nhân viên /User.
   Cùng ngôn ngữ hình với công cụ chọn phạm vi trên topbar (scope-picker.css): ô tìm viền cam khi
   focus, nút sắp xếp Tên/Tỉnh, dòng có icon + tên đậm + dòng phụ, nhấn XANH LÁ cho công ty, XANH
   DƯƠNG cho trạm, dấu ✓ ở mục đang chọn, mobile (≤991.98px) = bottom sheet.
   Tiền tố `ap-` (assign picker) — `sp-` thuộc scope-picker, `yc-` thuộc trang Yêu cầu hỗ trợ.
   Màu khai báo bằng token --ap-* trên từng gốc (ô, panel, sheet, thông báo); DARK đè token qua
   [data-theme="dark"] / [data-layout-mode="dark"] — bảng màu tối lấy theo bản thiết kế đã duyệt.
   ========================================================================= */

.ap-field, .ap-panel, .ap-sheet, .ap-ov, .ap-notice {
  --ap-bg: #fff;
  --ap-field-bg: #fff;
  --ap-field-bg-on: #fbfdfc;
  --ap-line: #dfe5e1;
  --ap-line-hover: #c3cdc6;
  --ap-text: #16241c;
  --ap-muted: #5f7266;
  --ap-faint: #8a9a90;
  --ap-input-bg: #f7f8f7;
  --ap-c: #1f9a58;          /* nhấn công ty (icon, viền) */
  --ap-c-text: #17804a;     /* chữ tên công ty đang chọn — đậm hơn để đạt 4.5:1 trên nền trắng */
  --ap-c-tint: rgba(31,154,88,.08);
  --ap-c-tint-on: rgba(31,154,88,.14);
  --ap-s: #1f7fb8;
  --ap-s-text: #1a6c9e;
  --ap-s-tint: rgba(31,127,184,.08);
  --ap-s-tint-on: rgba(31,127,184,.15);
  --ap-focus: #FE9F43;
  --ap-shadow: 0 12px 32px rgba(20,40,28,.18);
  /* Chip hãng hóa đơn — bản sáng: mọi màu chữ ≥ 4.5:1 trên nền trắng */
  --ap-chip-misa: #0b66ad;
  --ap-chip-viettel: #c62828;
  --ap-chip-vnpt: #2f55c4;
  --ap-chip-easy: #0b7a62;
  --ap-chip-minv: #7344c4;
  --ap-chip-bkav: #8a5a00;
  --ap-chip-mobi: #b0287a;
  --ap-chip-fpt: #a84700;
  --ap-chip-none: #a85400;
  --ap-warn-text: #8a4b00;
  --ap-warn-bg: rgba(254,159,67,.11);
  --ap-warn-line: rgba(254,159,67,.55);
}
[data-theme="dark"] .ap-field, [data-layout-mode="dark"] .ap-field,
[data-theme="dark"] .ap-panel, [data-layout-mode="dark"] .ap-panel,
[data-theme="dark"] .ap-sheet, [data-layout-mode="dark"] .ap-sheet,
[data-theme="dark"] .ap-ov, [data-layout-mode="dark"] .ap-ov,
[data-theme="dark"] .ap-notice, [data-layout-mode="dark"] .ap-notice {
  --ap-bg: #1a221e;
  /* Ô (khi đóng) sáng hơn nền thẻ một nấc: nền gần đen #0e1311 cũ chìm hẳn, khó nhìn (KhacPM 22/10/2026).
     Dùng lớp trắng trong suốt thay vì hex cứng ⇒ hợp mọi skin tối (xanh lá, mặc định #1a1a2e…). */
  --ap-field-bg: rgba(255,255,255,.065);
  --ap-field-bg-on: rgba(255,255,255,.09);
  --ap-line: rgba(255,255,255,.13);
  --ap-line-hover: rgba(255,255,255,.24);
  /* Chữ sáng thêm một nấc trên nền tối (KhacPM 22/10/2026): dòng phụ MST/tỉnh/số cột trước #8fa398 hơi chìm. */
  --ap-text: #f4faf6;
  --ap-muted: #b6c6bd;
  --ap-faint: #93a59b;
  --ap-input-bg: #0e1311;
  --ap-c: #3ddc84;
  --ap-c-text: #3ddc84;
  --ap-c-tint: rgba(61,220,132,.08);
  --ap-c-tint-on: rgba(61,220,132,.14);
  --ap-s: #46b8f0;
  --ap-s-text: #46b8f0;
  --ap-s-tint: rgba(70,184,240,.09);
  --ap-s-tint-on: rgba(70,184,240,.16);
  --ap-shadow: 0 18px 44px rgba(0,0,0,.55);
  --ap-chip-misa: #7cc4ff;
  --ap-chip-viettel: #ff8f8f;
  --ap-chip-vnpt: #8fb4ff;
  --ap-chip-easy: #7fe0c4;
  --ap-chip-minv: #c9a7ff;
  --ap-chip-bkav: #ffd27a;
  --ap-chip-mobi: #ff9fd0;
  --ap-chip-fpt: #ffb27a;
  --ap-chip-none: #FE9F43;
  --ap-warn-text: #f5c48f;
  --ap-warn-bg: rgba(254,159,67,.08);
  --ap-warn-line: rgba(254,159,67,.45);
}

/* <select> gốc vẫn là nơi giữ giá trị (form post / code cũ đọc .value) — chỉ ẩn đi. */
select.ap-native { display: none !important; }
/* form-validator.js đánh dấu lỗi lên <select> ẩn (đứng ngay SAU ô vẽ) ⇒ tô viền đỏ cho ô */
.ap-field:has(+ select.input-validation-error) .ap-trigger { border-color: #dc3545; }

/* ---------------- Ô đã đóng (trigger) ---------------- */
.ap-field { position: relative; width: 100%; min-width: 0; }
.ap-trigger {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 50px; box-sizing: border-box;
  padding: 6px 11px 6px 12px; border: 1px solid var(--ap-line); border-radius: 11px;
  background: var(--ap-field-bg); color: var(--ap-text); font: inherit; text-align: left; cursor: pointer;
  transition: border-color .12s ease, background .12s ease, box-shadow .12s ease;
}
.ap-trigger:hover { border-color: var(--ap-line-hover); }
.ap-trigger:focus-visible { outline: 2px solid var(--ap-focus); outline-offset: 2px; }
.ap-k-company .ap-trigger.ap-open { border-color: var(--ap-c); background: var(--ap-field-bg-on); box-shadow: 0 0 0 3px var(--ap-c-tint); }
.ap-k-station .ap-trigger.ap-open { border-color: var(--ap-s); background: var(--ap-field-bg-on); box-shadow: 0 0 0 3px var(--ap-s-tint); }
/* Ô bị khoá (vd form sửa phiếu Nhập xuất, công ty bị buộc): KHÔNG làm mờ chữ — đây là thông tin cần đọc được
   (KhacPM 22/10/2026: MST/tỉnh mờ khó nhìn). Báo "không đổi được" bằng viền đứt + nền trong + ẩn mũi tên. */
.ap-trigger:disabled { cursor: default; background: transparent; border-style: dashed; }
.ap-trigger:disabled:hover { border-color: var(--ap-line); }
.ap-trigger .ap-tic { width: 18px; height: 18px; flex: none; }
.ap-k-company .ap-tic { color: var(--ap-c); }
.ap-k-station .ap-tic { color: var(--ap-s); }
.ap-ttx { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; gap: 1px; }
.ap-tn { font-size: 14px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-tn.ap-ph { color: var(--ap-muted); font-weight: 600; }
.ap-ts { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 11.5px; color: var(--ap-muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }
.ap-ts > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* MST giữ nguyên (số phải đọc được trọn), tỉnh co lại trước */
.ap-ts > .ap-tmst { flex: none; }
.ap-ts .ap-chip { flex: none; }
.ap-tail { width: 16px; height: 16px; flex: none; color: var(--ap-muted); transition: transform .18s ease; }
.ap-trigger.ap-open .ap-tail { transform: rotate(180deg); }
.ap-trigger:disabled .ap-tail { display: none; }
@media (prefers-reduced-motion: reduce) { .ap-trigger, .ap-tail { transition: none; } }

.ap-muted { color: var(--ap-faint) !important; }

/* ---------------- Chip hãng hóa đơn ---------------- */
.ap-chip { display: inline-flex; align-items: center; padding: 0 7px; height: 18px; border-radius: 99px; border: 1px solid currentColor;
  font-size: 10.5px; font-weight: 650; line-height: 1; white-space: nowrap; flex: none; }
.ap-chip-misa { color: var(--ap-chip-misa); }
.ap-chip-viettel { color: var(--ap-chip-viettel); }
.ap-chip-vnpt { color: var(--ap-chip-vnpt); }
.ap-chip-easy { color: var(--ap-chip-easy); }
.ap-chip-minv { color: var(--ap-chip-minv); }
.ap-chip-bkav { color: var(--ap-chip-bkav); }
.ap-chip-mobi { color: var(--ap-chip-mobi); }
.ap-chip-fpt { color: var(--ap-chip-fpt); }
.ap-chip-none { color: var(--ap-chip-none); border-style: dashed; }
/* Viền chip nhạt hơn chữ (giống bản thiết kế) — trộn màu chữ với trong suốt */
@supports (border-color: color-mix(in srgb, red 50%, transparent)) {
  .ap-chip { border-color: color-mix(in srgb, currentColor 50%, transparent); }
  .ap-chip-none { border-color: color-mix(in srgb, currentColor 70%, transparent); }
}

/* ---------------- Panel desktop (PORTAL gắn vào <body>, position:fixed — thoát overflow của
   panel chi tiết cột / card expand; toạ độ do JS đặt theo rect của ô) ---------------- */
.ap-panel {
  position: fixed; z-index: 1260; box-sizing: border-box; background: var(--ap-bg); color: var(--ap-text);
  border: 1px solid var(--ap-line); border-radius: 13px; box-shadow: var(--ap-shadow); overflow: hidden;
  display: flex; flex-direction: column;
}
.ap-ctx { display: flex; align-items: center; gap: 6px; padding: 10px 13px 0; font-size: 11.5px; color: var(--ap-muted); min-width: 0; }
.ap-ctx b { color: var(--ap-c-text); font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.ap-srow { display: flex; align-items: stretch; gap: 6px; padding: 9px; flex: none; }
.ap-search { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 36px; box-sizing: border-box; padding: 0 10px;
  border: 1.5px solid var(--ap-line); border-radius: 9px; background: var(--ap-input-bg); }
.ap-search:focus-within { border-color: var(--ap-focus); }
.ap-search svg { width: 14px; height: 14px; color: var(--ap-muted); flex: none; }
.ap-search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; color: var(--ap-text); font: inherit; font-size: 13px; }
.ap-search input::placeholder { color: var(--ap-faint); }
.ap-sort { display: inline-flex; align-items: center; gap: 3px; padding: 0 9px; border: 1.5px solid var(--ap-line); border-radius: 9px;
  background: var(--ap-input-bg); color: var(--ap-muted); font: inherit; font-size: 11.5px; font-weight: 650; line-height: 1; cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s, color .12s; }
.ap-sort:hover { border-color: var(--ap-line-hover); color: var(--ap-text); }
.ap-sort:focus-visible { outline: 2px solid var(--ap-focus); outline-offset: 1px; }
.ap-p-company .ap-sort.ap-son { background: var(--ap-c-tint-on); border-color: color-mix(in srgb, var(--ap-c) 50%, transparent); color: var(--ap-c-text); }
.ap-p-station .ap-sort.ap-son { background: var(--ap-s-tint-on); border-color: color-mix(in srgb, var(--ap-s) 50%, transparent); color: var(--ap-s-text); }
.ap-sort .ap-sarr { display: none; }
.ap-sort.ap-son .ap-sarr { display: inline-flex; }
.ap-sort .ap-sarr svg { width: 12px; height: 12px; transition: transform .15s; }
.ap-sort.ap-desc .ap-sarr svg { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) { .ap-sort, .ap-sort .ap-sarr svg { transition: none; } }

.ap-list { overflow-y: auto; overscroll-behavior: contain; padding-bottom: 6px; flex: 1 1 auto; min-height: 0; }
.ap-list::-webkit-scrollbar { width: 8px; }
.ap-list::-webkit-scrollbar-thumb { background: var(--ap-line); border-radius: 8px; }

.ap-opt { display: flex; align-items: flex-start; gap: 11px; width: 100%; box-sizing: border-box; padding: 8px 13px; border: 0; background: transparent;
  color: var(--ap-text); font: inherit; text-align: left; cursor: pointer; transition: background .1s; }
.ap-opt:focus-visible { outline: 2px solid var(--ap-focus); outline-offset: -2px; }
.ap-p-company .ap-opt:hover { background: var(--ap-c-tint); }
.ap-p-station .ap-opt:hover { background: var(--ap-s-tint); }
.ap-p-company .ap-opt.ap-cur { background: var(--ap-c-tint-on); }
.ap-p-station .ap-opt.ap-cur { background: var(--ap-s-tint-on); }
/* Dòng đang trỏ bằng bàn phím ↑/↓ — viền trái cam để phân biệt với dòng đang chọn (nền tint). */
.ap-opt.ap-active { box-shadow: inset 3px 0 0 var(--ap-focus); }
.ap-p-company .ap-opt.ap-active:not(.ap-cur) { background: var(--ap-c-tint); }
.ap-p-station .ap-opt.ap-active:not(.ap-cur) { background: var(--ap-s-tint); }
.ap-oic { width: 17px; height: 17px; flex: none; margin-top: 2px; }
.ap-p-company .ap-oic { color: var(--ap-c); }
.ap-p-station .ap-oic { color: var(--ap-s); }
.ap-otx { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 3px; }
.ap-on { font-size: 13.5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-p-company .ap-opt.ap-cur .ap-on { color: var(--ap-c-text); }
.ap-p-station .ap-opt.ap-cur .ap-on { color: var(--ap-s-text); }
.ap-os { display: flex; align-items: center; gap: 10px; min-width: 0; font-size: 11.5px; color: var(--ap-muted); font-variant-numeric: tabular-nums; }
.ap-os .ap-mst { flex: none; }
.ap-co { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--ap-c-text); font-weight: 600; }
/* Có tên công ty đứng trước ⇒ tên công ty co lại trước, tỉnh giữ nguyên (ngắn, cần đọc trọn) */
.ap-co + .ap-prov { flex-shrink: 0; }
.ap-prov { display: inline-flex; align-items: center; gap: 4px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ap-prov svg { width: 12px; height: 12px; flex: none; }
.ap-cnt { margin-left: auto; flex: none; padding-left: 6px; }
.ap-chk { width: 16px; height: 16px; flex: none; margin-top: 3px; opacity: 0; }
.ap-opt.ap-cur .ap-chk { opacity: 1; }
.ap-p-company .ap-chk { color: var(--ap-c); }
.ap-p-station .ap-chk { color: var(--ap-s); }
.ap-opt.ap-none-opt .ap-on { color: var(--ap-muted); font-weight: 600; }
.ap-opt.ap-none-opt .ap-oic { color: var(--ap-faint); }

.ap-empty { padding: 20px 14px; text-align: center; color: var(--ap-muted); font-size: 12.5px; }
.ap-foot { padding: 7px 13px; border-top: 1px solid var(--ap-line); font-size: 11px; color: var(--ap-muted); flex: none; }

/* ---------------- Thông báo "cột sẽ chuyển…" (trên nút Lưu) ---------------- */
.ap-notice { display: flex; gap: 9px; align-items: flex-start; margin: 4px 0 8px; padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--ap-warn-line); background: var(--ap-warn-bg); color: var(--ap-warn-text); font-size: 12.5px; line-height: 1.45; }
.ap-notice[hidden] { display: none; }
.ap-notice svg { width: 16px; height: 16px; flex: none; margin-top: 1px; color: var(--ap-focus); }
.ap-notice b { font-weight: 700; }

/* ---------------- Mobile: bottom sheet (gắn vào <body>) ---------------- */
.ap-ov { position: fixed; inset: 0; z-index: 3000; background: rgba(10,20,14,.44); opacity: 0; pointer-events: none; transition: opacity .25s ease; }
[data-theme="dark"] .ap-ov, [data-layout-mode="dark"] .ap-ov { background: rgba(5,10,7,.6); }
.ap-ov.ap-show { opacity: 1; pointer-events: auto; }
.ap-sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3001; max-height: 85vh; display: flex; flex-direction: column;
  background: var(--ap-bg); color: var(--ap-text); border-radius: 20px 20px 0 0; box-shadow: 0 -12px 34px rgba(0,0,0,.3);
  transform: translateY(103%); transition: transform .3s cubic-bezier(.16,1,.3,1); padding-bottom: env(safe-area-inset-bottom, 0); }
.ap-sheet.ap-show { transform: translateY(0); }
@media (prefers-reduced-motion: reduce) { .ap-sheet, .ap-ov { transition: none; } }
.ap-handle { width: 40px; height: 5px; border-radius: 99px; background: var(--ap-line); margin: 10px auto 4px; flex: none; }
.ap-head { display: flex; align-items: center; gap: 10px; padding: 4px 16px 12px; border-bottom: 1px solid var(--ap-line); flex: none; }
.ap-htx { flex: 1; min-width: 0; }
.ap-title { font-size: 16px; font-weight: 750; }
.ap-hsub { font-size: 12px; color: var(--ap-c-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-x { width: 44px; height: 44px; border: 0; border-radius: 99px; background: var(--ap-input-bg); color: var(--ap-muted); display: grid; place-items: center; cursor: pointer; flex: none; }
.ap-x svg { width: 18px; height: 18px; }
.ap-x:focus-visible { outline: 2px solid var(--ap-focus); outline-offset: 2px; }
.ap-sheet .ap-srow { padding: 12px 16px 6px; gap: 8px; }
.ap-sheet .ap-search { height: 46px; border-radius: 12px; }
/* ⚠️ KHÔNG hạ font-size input mobile xuống dưới 16px — iOS Safari tự phóng to trang khi focus. */
.ap-sheet .ap-search input { font-size: 16px; }
.ap-sheet .ap-sort { padding: 0 12px; border-radius: 12px; font-size: 13px; min-height: 46px; }
.ap-sheet .ap-list { padding: 4px 0 20px; }
.ap-sheet .ap-opt { min-height: 64px; padding: 11px 16px; gap: 12px; }
.ap-sheet .ap-on { font-size: 15px; }
.ap-sheet .ap-os { font-size: 12.5px; }
