/* CSS organization — ĐÃ SCOPE vào #orghost (sinh tự động từ organization/css/style.css) */
#orghost{
  --bg: #faf9f5; --surface: #ffffff; --surface-1: #f5f4ee;
  --text: #2c2c2a; --text-2: #5f5e5a; --muted: #a09e95;
  --border: #e6e4db; --border-2: #d3d1c7;
  --accent: #185fa5; --accent-bg: #e6f1fb; --accent-border: #378add;
  --danger: #a32d2d; --radius: 8px;
}
#orghost[data-theme="dark"]{
  --bg: #1a1a18; --surface: #232320; --surface-1: #2b2b28;
  --text: #ececea; --text-2: #b4b2a9; --muted: #86847d;
  --border: #34342f; --border-2: #45443e;
  --accent: #6aa9e6; --accent-bg: #1e2c3a; --accent-border: #378add;
  --danger: #e88a7a;
}
#orghost *{ box-sizing: border-box; }
#orghost, #orghost{ margin: 0; height: 100%; }
#orghost{
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text); background: var(--bg); font-size: 14px;
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}

/* ===== App bar ===== */
#orghost .appbar{
  display: flex; align-items: center; gap: 20px;
  padding: 0 16px; height: 52px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
#orghost .brand{ font-size: 15px; font-weight: 500; display: flex; align-items: center; gap: 8px; }
#orghost .brand .ti{ color: var(--accent); }
#orghost .tabs{ display: flex; gap: 4px; }
#orghost .tab{
  background: none; border: none; border-bottom: 2px solid transparent;
  padding: 16px 14px; font-size: 14px; color: var(--muted); cursor: pointer;
  display: flex; align-items: center; gap: 6px;
}
#orghost .tab:hover{ color: var(--text-2); }
#orghost .tab.active{ color: var(--text); border-bottom-color: var(--accent-border); }
#orghost .appbar > .ghost{ margin-left: auto; }

/* ===== Buttons / inputs ===== */
#orghost button{ font-family: inherit; font-size: 14px; cursor: pointer; }
#orghost .primary, #orghost .ghost{
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
}
#orghost .primary{ border-color: var(--accent-border); color: var(--accent); }
#orghost .primary:hover{ background: var(--accent-bg); }
#orghost .ghost:hover{ background: var(--surface-1); }
#orghost button:active{ transform: scale(0.98); }
#orghost input, #orghost select{
  height: 34px; padding: 0 10px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--border-2); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
#orghost input:focus, #orghost select:focus{ outline: none; border-color: var(--accent-border); box-shadow: 0 0 0 3px var(--accent-bg); }

/* ===== Panes ===== */
#orghost .pane{ flex: 1; min-height: 0; display: none; }
#orghost .pane.active{ display: flex; }
#orghost #pane-chart{ flex-direction: column; }

/* ===== Master: sidebar + main ===== */
#orghost .side{ width: 170px; flex-shrink: 0; border-right: 1px solid var(--border); padding: 10px; background: var(--surface); overflow-y: auto; }
#orghost .nav-item{
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  border-radius: var(--radius); color: var(--text-2); cursor: pointer; margin-bottom: 2px;
}
#orghost .nav-item:hover{ background: var(--surface-1); }
#orghost .nav-item.active{ background: var(--accent-bg); color: var(--accent); }
#orghost .main{ flex: 1; min-width: 0; padding: 20px; overflow-y: auto; }
#orghost .main-head{ display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
#orghost .main-head h2{ margin: 0; font-size: 18px; font-weight: 500; }
#orghost .main-head h2 .count{ font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 4px; }
#orghost .head-actions{ display: flex; align-items: center; gap: 14px; }
#orghost .chk-inline{ display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; }
#orghost .chk-inline input{ height: auto; }
#orghost .toggle-chip{
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--border-2); background: var(--surface);
  color: var(--text-2); font-size: 13px; cursor: pointer;
}
#orghost .toggle-chip:hover{ background: var(--surface-1); }
#orghost .toggle-chip.active{ border-color: #1d9e75; color: #1d9e75; background: transparent; }
#orghost table.grid tr.inactive td:not(.rowact){ color: var(--muted); }
#orghost table.grid tr.inactive .idcol{ text-decoration: line-through; }

/* ===== Table ===== */
#orghost .list-wrap{ border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 200px); }
#orghost table.grid{ width: 100%; border-collapse: collapse; font-size: 13px; }
#orghost table.grid th{
  text-align: left; font-weight: 500; color: var(--text-2);
  padding: 10px 12px; background: var(--surface-1); white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
#orghost table.grid th.sortable{ cursor: pointer; user-select: none; }
#orghost table.grid th.sortable:hover{ color: var(--text); }
#orghost table.grid td{ padding: 9px 12px; border-top: 1px solid var(--border); }
#orghost table.grid tr:hover td{ background: var(--surface-1); }
#orghost .idcol{ width: 40px; color: var(--muted); }
#orghost .ctr{ text-align: center; }
#orghost .rowact{ white-space: nowrap; text-align: right; }
#orghost .rowact .ti{ color: var(--muted); cursor: pointer; padding: 4px; font-size: 16px; }
#orghost .rowact .ti:hover{ color: var(--accent); }
#orghost .rowact .ti-trash:hover{ color: var(--danger); }
#orghost .empty{ text-align: center; color: var(--muted); padding: 24px; }
#orghost .star{ color: var(--accent); }
#orghost .vacant{ color: var(--danger); }
#orghost .current{ color: var(--accent); }

/* Inline editing trong bảng */
#orghost table.grid td.ro{ color: var(--muted); }
#orghost tr.editing td{ background: var(--accent-bg); vertical-align: middle; }
#orghost tr.editing input:not([type=checkbox]), #orghost tr.editing select{
  width: 100%; height: 30px; min-width: 80px; padding: 0 8px; font-size: 13px;
}
#orghost tr.editing input.invalid, #orghost tr.editing select.invalid{
  border-color: var(--danger); box-shadow: 0 0 0 3px rgba(163,45,45,0.12);
}
#orghost .mini{
  height: 28px; padding: 0 12px; border-radius: 6px;
  border: 1px solid var(--accent-border); background: var(--surface); color: var(--accent);
}
#orghost .mini:hover{ background: var(--surface); }
#orghost .rowact .ti-x:hover{ color: var(--danger); }

/* ===== Combobox khoá ngoại (nút + menu tìm kiếm 2 cột) ===== */
#orghost .fk-btn{
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  width: 100%; min-width: 110px; height: 30px; padding: 0 8px; font-size: 13px;
  border: 1px solid var(--border-2); border-radius: var(--radius);
  background: var(--surface); color: var(--text); text-align: left;
}
#orghost .fk-btn:focus{ outline: none; border-color: var(--accent-border); box-shadow: 0 0 0 3px var(--accent-bg); }
#orghost .fk-btn .fk-cur{ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#orghost .fk-btn .ti{ color: var(--muted); flex-shrink: 0; }
#orghost .fk-btn.placeholder .fk-cur{ color: var(--muted); }
#orghost .fk-btn.invalid{ border-color: var(--danger); box-shadow: 0 0 0 3px rgba(163,45,45,0.12); }
#orghost .fk-pop{
  position: fixed; z-index: 95; background: var(--surface);
  border: 1px solid var(--border-2); border-radius: 10px; overflow: hidden;
  box-shadow: 0 12px 32px rgba(0,0,0,0.16); display: flex; flex-direction: column;
}
#orghost .fk-pop .fk-search{ display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
#orghost .fk-pop .fk-search .ti{ color: var(--muted); }
#orghost .fk-pop .fk-search input{ flex: 1; height: 26px; padding: 0; border: none; border-radius: 0; font-size: 13px; background: transparent; }
#orghost .fk-pop .fk-search input:focus{ outline: none; box-shadow: none; }
#orghost .fk-cols, #orghost .fk-opt{ display: grid; grid-template-columns: 96px 1fr; gap: 10px; align-items: center; }
#orghost .fk-cols{
  padding: 6px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); background: var(--surface-1); border-bottom: 1px solid var(--border);
}
#orghost .fk-list{ max-height: 260px; overflow-y: auto; }
#orghost .fk-opt{ padding: 7px 12px; font-size: 13px; cursor: pointer; }
#orghost .fk-opt + .fk-opt{ border-top: 1px solid var(--border); }
#orghost .fk-opt:hover, #orghost .fk-opt.active{ background: var(--accent-bg); }
#orghost .fk-opt .fk-id{ color: var(--text-2); font-family: ui-monospace, Consolas, monospace; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#orghost .fk-opt .fk-name{ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#orghost .fk-opt.selected .fk-name{ color: var(--accent); font-weight: 500; }
#orghost .fk-none{ padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }

/* ===== Bộ chọn ngày (popover lịch) ===== */
#orghost .dp-pop{
  position: fixed; z-index: 95; width: 276px; padding: 10px 12px 8px;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 12px;
  box-shadow: 0 14px 36px rgba(0,0,0,0.18);
  opacity: 0; transform: translateY(4px) scale(0.98); transition: opacity .14s, transform .14s;
}
#orghost .dp-pop.show{ opacity: 1; transform: none; }
#orghost .dp-head{ display: flex; align-items: center; gap: 2px; margin-bottom: 6px; }
#orghost .dp-title{ flex: 1; text-align: center; font-size: 13.5px; font-weight: 600; color: var(--text); }
#orghost .dp-nav{
  width: 27px; height: 27px; border: none; background: none; border-radius: 8px;
  color: var(--text-2); display: flex; align-items: center; justify-content: center; font-size: 15px;
}
#orghost .dp-nav:hover{ background: var(--surface-1); color: var(--text); }
#orghost .dp-dow{ display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 2px; }
#orghost .dp-dow span{
  text-align: center; padding: 4px 0; font-size: 10.5px;
  color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em;
}
#orghost .dp-grid{ display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
#orghost .dp-d{
  height: 30px; border: none; background: none; border-radius: 8px; font-size: 12.5px;
  color: var(--text); display: flex; align-items: center; justify-content: center; transition: background .12s;
}
#orghost .dp-d:hover{ background: var(--surface-1); }
#orghost .dp-d.out{ color: var(--muted); }
#orghost .dp-d.today{ box-shadow: inset 0 0 0 1.5px var(--accent-border); }
#orghost .dp-d.sel, #orghost .dp-d.sel:hover{ background: var(--accent); color: #fff; font-weight: 600; }
#orghost .dp-foot{
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border);
}
#orghost .dp-link{
  border: none; background: none; font-size: 12.5px; color: var(--accent);
  padding: 4px 6px; border-radius: 6px;
}
#orghost .dp-link:hover{ background: var(--accent-bg); }
#orghost .dp-apply{
  margin-left: auto; border: none; background: var(--accent); color: #fff;
  font-size: 12.5px; font-weight: 600; padding: 5px 14px; border-radius: 7px; cursor: pointer;
}
#orghost .dp-apply:hover{ filter: brightness(.94); }
#orghost .dp-clear{ color: var(--danger); }
#orghost .dp-clear:hover{ background: transparent; text-decoration: underline; }

/* ===== Form card ===== */
#orghost .form-card{
  margin-top: 18px; border: 1px solid var(--border-2); border-radius: 12px;
  background: var(--surface-1); padding: 16px; display: none;
}
#orghost .form-card.open{ display: block; }
#orghost .form-head{ font-size: 15px; margin-bottom: 14px; }
#orghost .form-grid{ display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
#orghost .fld{ display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-2); }
#orghost .fld input:not([type=checkbox]), #orghost .fld select{ width: 100%; }
#orghost .fld.chk{ flex-direction: row; align-items: center; gap: 8px; align-self: end; height: 34px; }
#orghost .fld.chk input{ width: auto; height: auto; }
#orghost .form-foot{ display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ===== Dashboard ===== */
#orghost .dash{ flex: 1; min-width: 0; overflow-y: auto; padding: 24px; }
#orghost .kpi-grid{ display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
#orghost .kpi{ background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
#orghost .kpi[data-goto]{ cursor: pointer; }
#orghost .kpi[data-goto]:hover{ border-color: var(--border-2); }
#orghost .kpi-top{ display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; }
#orghost .kpi-val{ font-size: 26px; font-weight: 500; margin-top: 8px; }
#orghost .kpi.danger .kpi-val{ color: var(--danger); }
#orghost .warn-grid{ display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
#orghost .warn-card{ background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
#orghost .warn-head{ display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 10px; }
#orghost .warn-head .ti{ font-size: 17px; }
#orghost .warn-card.has .warn-head .ti{ color: var(--danger); }
#orghost .warn-card.ok .warn-head .ti{ color: #1d9e75; }
#orghost .wbadge{ margin-left: auto; min-width: 22px; text-align: center; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--surface-1); color: var(--text-2); }
#orghost .warn-card.has .wbadge{ background: #fceceb; color: var(--danger); }
#orghost .warn-card ul{ list-style: none; margin: 0; padding: 0; font-size: 13px; }
#orghost .warn-card li{ padding: 6px 0; border-top: 1px solid var(--border); cursor: pointer; color: var(--text-2); }
#orghost .warn-card li:hover{ color: var(--accent); }
#orghost .warn-card li.more{ cursor: default; color: var(--muted); }
#orghost .warn-ok{ font-size: 13px; color: #1d9e75; display: flex; align-items: center; gap: 6px; }

/* ===== Chart ===== */
#orghost .toolbar{
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0;
}
#orghost .tlabel{ font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 4px; }
#orghost .toolbar .spacer{ flex: 1; }
#orghost .toolbar input, #orghost .toolbar select, #orghost .toolbar button{ height: 32px; }
#orghost .chart-stage{ position: relative; flex: 1; min-height: 0; }
/* cytoscape tự xử lý chạm/chụm để pan-zoom sơ đồ → tắt cử chỉ mặc định của trình duyệt
   trên vùng này, không thì trình duyệt cuộn trang và sơ đồ như bị đơ */
#orghost #cy{ position: absolute; inset: 0; background: var(--bg);
  touch-action: none; -webkit-tap-highlight-color: transparent; }

/* Node vẽ bằng node-html-label */
#orghost .cynode{
  width: 178px; height: 68px; box-sizing: border-box; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 12px 8px 8px; position: relative; text-align: center;
  background: var(--surface); border: 1.5px solid var(--border-2); border-radius: 10px;
  font-family: system-ui, sans-serif;
}
#orghost .cynode.chief{ border-color: var(--accent-border); border-width: 2px; }
#orghost .cynode.vacant{ border-style: dashed; background: var(--surface-1); }
#orghost .cn-badge{
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%);
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: var(--surface-1); border: 1px solid var(--border-2); border-radius: 10px;
  font-size: 10px; padding: 1px 9px; color: var(--text-2);
}
/* chip số người ở góc dưới-phải — chỉ node ĐƠN VỊ */
#orghost .cn-cnt{
  position: absolute; right: 6px; bottom: -9px;
  display: flex; align-items: center; gap: 3px;
  background: var(--surface-1); border: 1px solid var(--border-2); border-radius: 10px;
  font-size: 10px; padding: 1px 7px; color: var(--text-2); white-space: nowrap;
}
#orghost .cn-cnt .ti{ font-size: 11px; }
#orghost .cn-name{ font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.15; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#orghost .cn-name .cn-vacant{ color: var(--danger); font-style: italic; font-weight: 400; }
#orghost .cn-name .cn-asg{ color: var(--text-2); font-style: italic; font-weight: 400; font-size: 11px; }
#orghost .cn-title{ font-size: 10.5px; color: var(--text-2); max-width: 162px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* cặp nút bung/thu gọn nổi dưới mép node — chỉ node đại diện có cấp dưới */
#orghost .cn-tools{
  position: absolute; bottom: -11px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px;
}
#orghost .cn-tg{
  pointer-events: auto; width: 22px; height: 22px; padding: 0; cursor: pointer;
  border: 1px solid var(--border-2); border-radius: 50%;
  background: var(--surface); color: var(--text-2); font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.14); transition: color .12s, background .12s, border-color .12s;
}
#orghost .cn-tg:hover{ color: var(--accent); border-color: var(--accent-border); background: var(--accent-bg); }
#orghost .cy-panel{
  position: absolute; top: 0; right: 0; bottom: 0; width: 300px; z-index: 5;
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: -6px 0 18px rgba(0,0,0,0.06); overflow-y: auto;
  transform: translateX(100%); transition: transform .2s; pointer-events: none;
}
#orghost .cy-panel.open{ transform: none; pointer-events: auto; }
#orghost .panel-head{ display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
#orghost .panel-head .ti{ cursor: pointer; font-size: 18px; }
#orghost .panel-head .ti:hover{ color: var(--danger); }
#orghost .panel-body{ padding: 14px 16px; }
#orghost .panel-body h4{ margin: 0 0 12px; font-size: 15px; font-weight: 500; }
#orghost .psub{ font-size: 12px; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .03em; }
#orghost .pr{ display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-top: 1px solid var(--border); font-size: 13px; }
#orghost .pr span{ color: var(--text-2); flex-shrink: 0; }
#orghost .pr b{ font-weight: 500; text-align: right; }
#orghost .pr .muted, #orghost .muted{ color: var(--muted); font-style: italic; }
#orghost .panel-btn{ margin-top: 16px; width: 100%; justify-content: center; }

/* ===== Dark-mode fixes cho vài nền sáng cứng ===== */
#orghost[data-theme="dark"] .warn-card.has .wbadge{ background: #3a1f1d; }
#orghost[data-theme="dark"] .danger-btn:hover{ background: #3a1f1d; }
#orghost[data-theme="dark"] .toast{ box-shadow: 0 6px 20px rgba(0,0,0,0.4); }

/* ===== Responsive ===== */
@media (max-width: 760px) {
  #orghost .appbar{ flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 10px; }
  #orghost .tab{ padding: 10px 10px; }
  #orghost .side{ width: 132px; }
  #orghost .main{ padding: 14px; }
  #orghost .form-grid, #orghost .modal-grid{ grid-template-columns: 1fr; }
  #orghost .modal-box, #orghost .modal-box.wide{ width: calc(100vw - 24px); }
  #orghost .cy-panel{ width: 82%; }
  #orghost .head-actions{ flex-wrap: wrap; }
}
#orghost .legend{
  display: flex; gap: 18px; flex-wrap: wrap; padding: 9px 14px;
  border-top: 1px solid var(--border); font-size: 12px; color: var(--text-2); background: var(--surface); flex-shrink: 0;
}
#orghost .legend span{ display: flex; align-items: center; gap: 6px; }
#orghost .dash-key::before{
  content: ""; width: 16px; height: 0; border-top: 2px dashed var(--border-2); display: inline-block;
}
#orghost .sw-ou{ width: 14px; height: 14px; border-radius: 3px; background: var(--accent-bg); border: 1.5px solid var(--accent-border); }

/* ===== Overlay ===== */
#orghost #overlay{
  position: absolute; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
#orghost .spin{ color: var(--text-2); display: flex; align-items: center; gap: 8px; }
#orghost .spin .ti{ animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
#orghost .err{ max-width: 460px; display: flex; gap: 12px; padding: 20px; }
#orghost .err .ti{ color: var(--danger); font-size: 24px; }
#orghost .err code{ background: var(--surface-1); padding: 1px 5px; border-radius: 4px; }

/* ===== Toast ===== */
#orghost .toast-c{ position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
#orghost .toast{
  display: flex; align-items: center; gap: 8px; padding: 11px 14px; min-width: 240px; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border-2); border-left: 3px solid var(--muted);
  border-radius: var(--radius); font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,0.10);
  opacity: 0; transform: translateX(16px); transition: opacity .2s, transform .2s;
}
#orghost .toast.show{ opacity: 1; transform: none; }
#orghost .toast .ti{ font-size: 17px; }
#orghost .toast.success{ border-left-color: #1d9e75; } #orghost .toast.success .ti{ color: #1d9e75; }
#orghost .toast.error{ border-left-color: var(--danger); } #orghost .toast.error .ti{ color: var(--danger); }
#orghost .toast.info .ti{ color: var(--accent); }

/* ===== Modal ===== */
#orghost .modal-ov{
  position: fixed; inset: 0; z-index: 90; background: rgba(30,30,28,0.28);
  display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .18s;
}
#orghost .modal-ov.show{ opacity: 1; }
#orghost .modal-box{
  background: var(--surface); border-radius: 12px; border: 1px solid var(--border);
  padding: 20px 22px; width: 380px; max-width: calc(100vw - 32px); box-shadow: 0 12px 40px rgba(0,0,0,0.16);
  transform: translateY(8px); transition: transform .18s;
}
#orghost .modal-ov.show .modal-box{ transform: none; }
#orghost .modal-box.wide{ width: 460px; }
#orghost .modal-box h3{ margin: 0 0 16px; font-size: 16px; font-weight: 500; }
#orghost .modal-msg{ margin: 0 0 18px; font-size: 14px; color: var(--text); line-height: 1.6; }
#orghost .modal-grid{ display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
#orghost .modal-grid label{ display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--text-2); }
#orghost .modal-grid label.full{ grid-column: 1 / -1; }
#orghost .modal-grid select, #orghost .modal-grid input{ width: 100%; }
#orghost .modal-foot{ display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
#orghost .danger-btn{
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: var(--radius); border: 1px solid var(--danger); background: var(--surface); color: var(--danger);
}
#orghost .danger-btn:hover{ background: #fceceb; }
#orghost .rowact .ti-ban:hover{ color: var(--danger); }
#orghost .rowact .ti-arrow-back-up:hover{ color: #1d9e75; }

/* ===== Cột bảng: sắp xếp · lọc · kéo rộng (mô hình Google Sheets) ===== */
/* Bố cục cố định + MỘT cột đệm không đặt bề rộng: phần dư của khung dồn hết vào cột đệm,
   nên kéo rộng một cột chỉ đẩy các cột phía sau chứ không bóp cột nào lại. */
#orghost table.grid.fixed{ table-layout: fixed; width: max-content; min-width: 100%; }
#orghost table.grid col.c-id{ width: 54px; }
#orghost table.grid col.c-act{ width: 96px; }
#orghost table.grid col.c-fill{ width: auto; }
#orghost table.grid th.fillcol, #orghost table.grid td.fillcol{ padding: 0; border-left: none; }
#orghost table.grid th{ position: sticky; top: 0; z-index: 1; }
#orghost table.grid th[data-col]{ padding: 0; }
#orghost table.grid th .th-in{
  display: flex; align-items: center; gap: 5px; padding: 10px 12px; min-width: 0;
}
#orghost table.grid th .th-lb{
  flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer; user-select: none;
}
#orghost table.grid th .th-lb:hover{ color: var(--text); }
#orghost table.grid th .th-ic{ flex: none; font-size: 14px; color: var(--accent); }
#orghost table.grid th.filtered .th-ic.ti-filter-filled{ color: #1d9e75; }
#orghost table.grid th.sorted{ color: var(--text); background: var(--accent-bg); }
#orghost table.grid th.filtered{ background: #eaf6f0; }
/* nút mở menu cột: máy tính chỉ hiện khi rê vào (như Sheets), cảm ứng thì hiện sẵn */
#orghost table.grid th .th-menu{
  flex: none; width: 22px; height: 22px; padding: 0; border: none; border-radius: 6px;
  background: none; color: var(--muted); cursor: pointer; opacity: 0;
  display: flex; align-items: center; justify-content: center; font-size: 14px;
}
#orghost table.grid th:hover .th-menu,
#orghost table.grid th.selcol .th-menu,
#orghost table.grid th.sorted .th-menu,
#orghost table.grid th.filtered .th-menu{ opacity: 1; }
#orghost table.grid th .th-menu:hover{ background: var(--surface); color: var(--text); }
/* ===== cột ĐANG CHỌN: viền bao quanh cả cột (bấm tiêu đề hoặc bấm một ô bất kỳ) ===== */
#orghost table.grid th.selcol, #orghost table.grid td.selcol{
  background: var(--accent-bg);
  box-shadow: inset 1px 0 0 var(--accent), inset -1px 0 0 var(--accent);
}
#orghost table.grid th.selcol{
  color: var(--text);
  box-shadow: inset 1px 1px 0 var(--accent), inset -1px 0 0 var(--accent);
}
#orghost table.grid td.selcol-last{
  box-shadow: inset 1px 0 0 var(--accent), inset -1px 0 0 var(--accent), inset 0 -1px 0 var(--accent);
}
#orghost table.grid tr:hover td.selcol{ background: var(--accent-bg); }

/* tay nắm kéo rộng ở mép phải tiêu đề — ẩn cho tới khi cột được chọn,
   lúc đó hiện icon ↔ để kéo cho dễ (bấm tiêu đề/ô → thấy ngay chỗ kéo) */
#orghost table.grid th .th-rs{
  position: absolute; top: 0; right: -5px; width: 11px; height: 100%;
  display: flex; align-items: center; justify-content: center;
  cursor: col-resize; z-index: 3; touch-action: none;
}
#orghost table.grid th .th-rs::after{
  content: ""; position: absolute; top: 6px; bottom: 6px; width: 2px;
  border-radius: 1px; background: transparent;
}
#orghost table.grid th:hover .th-rs::after{ background: var(--accent-border); }
#orghost table.grid th .th-rs svg{
  display: none; width: 22px; height: 22px; padding: 3px; box-sizing: border-box;
  border-radius: 7px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
/* rê vào tiêu đề là đã thấy chỗ kéo (mờ), chọn cột thì nó đậm hẳn lên */
#orghost table.grid th:hover .th-rs{ width: 26px; right: -13px; }
#orghost table.grid th:hover .th-rs::after{ display: none; }
#orghost table.grid th:hover .th-rs svg{
  display: block; background: #fff; color: var(--text-2);
  border: 1px solid var(--border-2); box-shadow: 0 1px 4px rgba(0,0,0,.14);
}
#orghost table.grid th.selcol .th-rs{ width: 26px; right: -13px; }
#orghost table.grid th.selcol .th-rs::after{ display: none; }
#orghost table.grid th.selcol .th-rs svg{
  display: block; background: var(--accent); color: #fff; border: none;
  box-shadow: 0 1px 5px rgba(0,0,0,.28);
}
#orghost table.grid th .th-rs:hover svg{ transform: scale(1.08); }
/* icon nhô ra ngoài mép cột → phải nổi lên trên ô tiêu đề kế bên, không thì bị che mất nửa */
#orghost table.grid th:hover, #orghost table.grid th.selcol{ z-index: 4; }
/* th đã là sticky → là mốc định vị cho tay nắm kéo; giữ nguyên, không cần relative */
body.col-resizing{ cursor: col-resize; user-select: none; }
body.col-resizing #orghost table.grid th .th-rs::after{ background: var(--accent); }
/* ô dữ liệu: bố cục cố định thì phải tự cắt chữ, không thì vỡ cột */
#orghost table.grid.fixed td{ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== menu cột ===== */
.colmenu{
  position: fixed; z-index: 80; width: 268px; background: #fff;
  border: 1px solid #e2e0d9; border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.18);
  font: 13px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #2c2c2a;
  display: flex; flex-direction: column; max-height: min(70vh, 520px); overflow: hidden;
}
.colmenu .cm-head{
  display: flex; align-items: center; gap: 8px; padding: 10px 8px 8px 12px;
  border-bottom: 1px solid #f1efe8;
}
.colmenu .cm-t{ flex: 1; min-width: 0; font-weight: 600; font-size: 12.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.colmenu .cm-x{ flex: none; width: 26px; height: 26px; border: none; background: none;
  border-radius: 7px; color: #8a8880; cursor: pointer; font-size: 15px; }
.colmenu .cm-x:hover{ background: #f1efe8; color: #2c2c2a; }
.colmenu .cm-sec{ padding: 6px; border-bottom: 1px solid #f1efe8; }
.colmenu .cm-sec:last-of-type{ border-bottom: none; }
.colmenu .cm-it{
  display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 9px;
  border: none; background: none; border-radius: 8px; font: inherit; color: #3a3a37;
  cursor: pointer; text-align: left;
}
.colmenu .cm-it i{ font-size: 15px; color: #8a8880; }
.colmenu .cm-it:hover{ background: #f1efe8; }
.colmenu .cm-it.on{ background: #eef4fb; color: #2f6fb0; font-weight: 600; }
.colmenu .cm-it.on i{ color: #2f6fb0; }
.colmenu .cm-flt{ display: flex; flex-direction: column; min-height: 0; flex: 1; }
.colmenu .cm-lb{ font-size: 10.5px; font-weight: 600; letter-spacing: .6px;
  text-transform: uppercase; color: #b0aea5; padding: 4px 9px 6px; }
.colmenu .cm-q{
  margin: 0 6px 6px; height: 32px; padding: 0 10px; border: 1px solid #e2e0d9;
  border-radius: 8px; font: inherit; font-size: 12.5px; outline: none; background: #faf9f5;
}
.colmenu .cm-q:focus{ border-color: #9cc3f5; background: #fff; }
.colmenu .cm-pick{ display: flex; gap: 6px; padding: 0 6px 6px; }
.colmenu .cm-pick button{
  flex: 1; height: 28px; border: 1px solid #e2e0d9; background: #fff; border-radius: 7px;
  font: inherit; font-size: 11.5px; color: #5f5e5a; cursor: pointer;
}
.colmenu .cm-pick button:hover{ background: #f1efe8; }
.colmenu .cm-list{ flex: 1; min-height: 0; overflow: auto; padding: 0 6px 6px; }
.colmenu .cm-v{
  display: flex; align-items: center; gap: 9px; padding: 7px 9px; border-radius: 8px;
  cursor: pointer; font-size: 12.5px;
}
.colmenu .cm-v:hover{ background: #f4f2ec; }
.colmenu .cm-v input{ flex: none; width: 15px; height: 15px; accent-color: #2f6fb0; margin: 0; }
.colmenu .cm-vn{ flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.colmenu .cm-vn i{ color: #a8a69e; font-style: italic; }
.colmenu .cm-c{ flex: none; font-size: 11px; color: #a8a69e; font-variant-numeric: tabular-nums; }
.colmenu .cm-empty{ padding: 14px 9px; color: #a8a69e; font-size: 12.5px; text-align: center; }
.colmenu .cm-foot{
  display: flex; gap: 6px; padding: 8px; border-top: 1px solid #f1efe8; background: #faf9f5;
}
.colmenu .cm-clr{
  flex: 1; height: 34px; border: 1px solid #e2e0d9; background: #fff; border-radius: 8px;
  font: inherit; font-size: 12.5px; color: #5f5e5a; cursor: pointer;
}
.colmenu .cm-clr:disabled{ opacity: .45; cursor: default; }
.colmenu .cm-clr:not(:disabled):hover{ background: #f1efe8; }
.colmenu .cm-ok{
  flex: 1; height: 34px; border: 1px solid #2f6fb0; background: #2f6fb0; border-radius: 8px;
  font: inherit; font-size: 12.5px; font-weight: 600; color: #fff; cursor: pointer;
}
.colmenu .cm-ok:hover{ background: #2a6199; }

/* ===== cảm ứng / điện thoại ===== */
@media (hover: none), (pointer: coarse){
  #orghost table.grid th .th-menu{ opacity: 1; }
  #orghost table.grid th.selcol .th-rs{ width: 34px; right: -17px; }
  #orghost table.grid th.selcol .th-rs svg{ width: 28px; height: 28px; }
}
@media (max-width: 719px){
  /* menu cột thành tấm trượt dưới đáy — thao tác một tay như Sheets trên điện thoại */
  .colmenu{
    left: 0; right: 0; bottom: 0; top: auto; width: auto;
    border-radius: 16px 16px 0 0; max-height: 78vh;
    box-shadow: 0 -8px 32px rgba(0,0,0,.22);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .colmenu .cm-head{ padding: 12px 8px 10px 14px; }
  .colmenu .cm-it{ padding: 11px 10px; }
  .colmenu .cm-v{ padding: 11px 10px; }
  .colmenu .cm-q, .colmenu .cm-clr, .colmenu .cm-ok{ height: 38px; }
}
