/* ============================================================
   HR · LỊCH LÀM / PHÂN CA (schedule.js) — chỉ class MỚI của module này.
   Port từ Schedule.dc.html: bảng spreadsheet dày đặc + Gantt/Timeline kéo-thả.
   Token dùng lại từ tokens.css (--gold/--purple/--bg-2/--line…); phần cần thang
   màu 8 sắc độ theo mã ca (A/B/C) được tính runtime trong schedule.js vì tokens.css
   không có khái niệm "biến thể giờ ca" tương đương.
   ============================================================ */

.sch-root { display: flex; flex-direction: column; }

/* — Điều hướng Tháng/Năm — */
.sch-nav {
  display: flex; align-items: center; gap: 2px;
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: var(--r-md); padding: 3px;
}
.sch-navbtn {
  width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 7px; color: var(--muted); cursor: pointer; background: transparent; border: none;
  transition: background var(--mo-fast), color var(--mo-fast);
}
.sch-navbtn:hover { background: var(--hover); color: var(--ink); }
.sch-navbtn .ic { width: 15px; height: 15px; }
.sch-navbtn .ic.sch-flip { transform: rotate(180deg); }
.sch-navsel {
  height: 26px; border: none; background: transparent; color: var(--ink);
  font-size: var(--fs-label); font-weight: 700; cursor: pointer; outline: none; padding: 0 2px;
}

/* — Bộ lọc bộ phận — */
.sch-filter { width: 220px; }

/* — Seg Bảng/Timeline (dùng chung .seg, chỉ style icon) — */
.sch-viewseg button { display: inline-flex; align-items: center; gap: 5px; }
.sch-viewseg .ic { width: 14px; height: 14px; }

/* — OT chip trong toolbar — */
.sch-otchip {
  display: inline-flex; align-items: center; height: 22px; padding: 0 10px; border-radius: 6px;
  background: var(--warn-2); color: #3a2000; font-size: 10.5px; font-weight: 800; font-family: var(--mono);
  letter-spacing: .4px;
}

/* — Zoom — */
.sch-zoom {
  display: flex; align-items: center; gap: 2px; background: var(--bg-2); border: 1px solid var(--line-2);
  border-radius: var(--r-md); padding: 2px;
}
.sch-zoom button {
  width: 24px; height: 24px; border: none; border-radius: 6px; background: transparent; color: var(--muted);
  font-size: 15px; font-weight: 700; cursor: pointer; transition: background var(--mo-fast), color var(--mo-fast);
}
.sch-zoom button:hover { background: var(--hover); color: var(--ink); }
.sch-zoom span { font-size: 11px; font-weight: 700; font-family: var(--mono); min-width: 38px; text-align: center; color: var(--muted); }

/* — Thanh trượt độ rộng giờ (timeline) — */
.sch-hourw { display: inline-flex; align-items: center; gap: 6px; color: var(--faint); }
.sch-hourw .ic { width: 14px; height: 14px; }
.sch-hourw input[type="range"] { width: 84px; accent-color: var(--purple-l); cursor: ew-resize; }

/* — Nhấp nháy khi thao tác không hợp lệ (chưa chọn ô / mã sai) — */
.sch-flash { animation: sch-flash-kf .35s var(--ease-io); }
@keyframes sch-flash-kf { 0%, 100% { box-shadow: none; } 40% { box-shadow: 0 0 0 2px var(--bad); } }

/* ================= BẢNG (GRID) ================= */
.sch-gridcard { padding: 0; overflow: hidden; }
.sch-gridwrap { overflow: auto; max-height: 68vh; }
.sch-tbl {
  border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: 11.5px;
  /* Never squeeze a 30/31-day roster into the viewport.  The wrapper scrolls
     horizontally; every day remains tappable and the employee column stays put. */
  width: max-content; min-width: 1720px;
}
.sch-tbl th, .sch-tbl td { border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); box-sizing: border-box; }
.sch-tbl thead th {
  position: sticky; top: 0; z-index: 20; background: var(--bg-1); color: var(--faint);
  font-size: 10px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; padding: 6px 4px; text-align: center;
}
.sch-tbl thead th.sch-col-name { text-align: left; padding-left: 10px; }

/* Cột trái dính (sticky) — # / YDI / Họ tên / Vai trò / Bộ phận */
.sch-tbl .sch-col-num  { position: sticky; left: 0px;   width: 26px;  min-width: 26px;  z-index: 15; text-align: center; }
.sch-tbl .sch-col-ydi  { position: sticky; left: 26px;  width: 68px;  min-width: 68px;  z-index: 15; text-align: center; font-family: var(--mono); font-size: 10.5px; color: var(--muted); }
.sch-tbl .sch-col-name { position: sticky; left: 0; width: 220px; min-width: 220px; z-index: 15; text-align: left; }
.sch-tbl .sch-col-role { position: sticky; left: 262px; width: 74px;  min-width: 74px;  z-index: 15; text-align: center; }
.sch-tbl .sch-col-dept { position: sticky; left: 336px; width: 74px;  min-width: 74px;  z-index: 15; text-align: center; border-right: 1px solid var(--line); font-size: 10px; color: var(--muted); }
.sch-tbl thead .sch-col-num, .sch-tbl thead .sch-col-ydi, .sch-tbl thead .sch-col-name, .sch-tbl thead .sch-col-role, .sch-tbl thead .sch-col-dept { z-index: 25; }
.sch-tbl tbody td.sch-col-num, .sch-tbl tbody td.sch-col-ydi, .sch-tbl tbody td.sch-col-name, .sch-tbl tbody td.sch-col-role, .sch-tbl tbody td.sch-col-dept,
.sch-tbl tfoot td.sch-botlabel {
  background: var(--bg-2); color: var(--muted); font-size: 10.5px; padding: 3px 4px; vertical-align: middle;
}
.sch-namecell { display: flex; align-items: center; gap: 6px; }
.sch-namewrap { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.sch-namewrap b { font-size: 11.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sch-namewrap .cn { font-size: 9.5px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sch-role {
  display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border-radius: 5px;
  background: var(--purple-soft); color: var(--purple-xl); font-size: 9px; font-weight: 700; letter-spacing: .3px;
}

/* Ô ngày (header) */
.sch-daycol { width: 48px; min-width: 48px; height: 34px; padding: 3px 0 !important; vertical-align: middle; }
.sch-daycol.weekend { background: rgba(96,165,250,.08); }
.sch-daynum { font-size: 12px; font-weight: 700; font-family: var(--mono); color: var(--ink); line-height: 1.1; }
.sch-daycol.weekend .sch-daynum { color: var(--info); }
.sch-daywd { font-size: 8px; font-weight: 600; color: var(--faint); text-transform: uppercase; }

/* Ô ca — bấm trực tiếp như bảng Excel. Không dùng select/dropdown trong ô.
   Màu, giờ và tên đều đi từ catalogue mã ca nên các tháng cũ vẫn giữ đúng mã. */
.sch-gcell { width: 48px; min-width: 48px; height: 30px; text-align: center; padding: 0 !important; user-select: none; position: relative; background: var(--card); }
.sch-cell {
  width: 100%; min-width: 48px; height: 29px; border: 0; outline: 0; display: flex;
  align-items: center; justify-content: center; background: var(--shift-bg, #f3f4f6);
  color: var(--shift-fg, #374151); font: 800 10px var(--mono); letter-spacing: .15px;
  padding: 0 2px; box-sizing: border-box; position: relative; transition: filter var(--mo-fast), box-shadow var(--mo-fast), transform var(--mo-fast);
}
button.sch-cell.editable { cursor: pointer; }
button.sch-cell.editable:hover { filter: brightness(.95); box-shadow: inset 0 0 0 1px rgba(17,24,39,.25); }
.sch-cell.readonly { cursor: default; opacity: .82; }
.sch-cell.empty { background: var(--card-2); color: var(--faint); }
.sch-cell.selected { box-shadow: inset 0 0 0 2px var(--purple-l), 0 0 0 1px rgba(255,255,255,.22); position: relative; z-index: 3; }
.sch-cell.sch-dirty::after { content: ''; position: absolute; right: 2px; top: 2px; width: 5px; height: 5px; border-radius: 99px; background: var(--gold); box-shadow: 0 0 0 1px rgba(20,14,5,.45); }
.sch-namewrap span { color: var(--faint); font-size: 9.5px; }
.sch-namewrap b { display: flex; align-items: center; gap: 4px; }
.sch-roster-remove {
  border: 0; border-radius: 4px; background: transparent; color: var(--faint); cursor: pointer;
  font-size: 16px; line-height: 14px; padding: 0 2px;
}
.sch-roster-remove:hover { color: var(--bad); background: rgba(248,113,113,.12); }
.sch-history { display: flex; flex-direction: column; gap: 8px; }
.sch-history-row { display: flex; flex-direction: column; gap: 2px; padding: 9px 0; border-bottom: 1px solid var(--line-2); }
.sch-history-row:last-child { border-bottom: 0; }
.sch-history-row b { font-size: 12px; color: var(--ink); }
.sch-history-row span { color: var(--muted); font: 11px var(--mono); }
.sch-history-row small { color: var(--faint); font-size: 10px; }

/* Cột đếm bên phải */
.sch-cnthead { width: 28px; min-width: 28px; padding: 3px 0 !important; }
.sch-cnthead .sch-chip.ot { background: var(--warn-2); color: #3a2000; }
.sch-cnt { width: 28px; min-width: 28px; text-align: center; font-size: 10.5px; font-weight: 600; font-family: var(--mono); color: var(--muted); background: var(--card-2); }
.sch-cnt.warn { color: var(--bad); font-weight: 800; }
.sch-cnt.ot { color: var(--warn-2); font-weight: 700; }

/* Chip mã dùng chung (đầu cột đếm, hàng đáy, bảng mã) */
.sch-chip { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 18px; padding: 0 5px; border-radius: 5px; font-size: 9.5px; font-weight: 700; font-family: var(--mono); }
.sch-chip.sm { min-width: 20px; height: 17px; }

/* Hàng đáy — số ca theo ngày */
.sch-botlabel { text-align: right; padding-right: 8px !important; }
.sch-botcell { width: 30px; min-width: 30px; height: 22px; text-align: center; font-size: 10px; font-weight: 600; font-family: var(--mono); color: var(--muted); background: var(--card-2); }

/* — Bảng mã nhanh (palette) — */
.sch-palette {
  display: flex; align-items: center; gap: 6px; padding: 8px 2px; margin-bottom: var(--sp-3);
  overflow-x: auto; border: 1px dashed var(--line-2); border-radius: var(--r-md); background: var(--card);
}
.sch-palette-lab { font-size: 10px; font-weight: 700; color: var(--faint); flex: none; margin: 0 4px 0 8px; letter-spacing: .3px; }
.sch-swatch {
  flex: none; min-width: 26px; height: 26px; padding: 0 7px; border-radius: 6px; font-size: 11px; font-weight: 700;
  font-family: var(--mono); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  border: 1px solid rgba(17,24,39,.18); background: var(--shift-bg, var(--card-2)); color: var(--shift-fg, var(--ink));
  transition: transform var(--mo-fast), filter var(--mo-fast);
}
.sch-swatch:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(.96); }
.sch-swatch:disabled { opacity: .58; cursor: default; }
.sch-swatch.clear { background: var(--card-2); color: var(--bad); border-color: rgba(248,113,113,.42); font-size: 18px; }

/* ================= TIMELINE (GANTT) ================= */
.sch-tlcard { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.sch-tl-hint {
  flex: none; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 14px;
  border-bottom: 1px solid var(--line-2); background: var(--bg-1); font-size: 11px; color: var(--muted);
}
.sch-tl-hint .ic { width: 14px; height: 14px; color: var(--warn-2); flex: none; }
.sch-tl-hint .cn { font-size: 10px; color: var(--faint); display: block; width: 100%; margin-top: 2px; }
.sch-tl-hint b { color: var(--ink); }

.sch-tl-scroll { overflow: auto; max-height: 66vh; position: relative; }
.sch-tl-inner { position: relative; min-width: 100%; }
.sch-tl-headrow { display: flex; position: sticky; top: 0; z-index: 40; }
.sch-tl-corner {
  position: sticky; left: 0; z-index: 45; flex: none; box-sizing: border-box; background: var(--bg-1);
  border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; align-items: flex-end;
  padding: 0 12px 6px; font-size: 10px; font-weight: 700; letter-spacing: .5px; color: var(--faint); height: 46px;
}
.sch-tl-corner .cn { font-size: 9px; margin-left: 4px; }
.sch-tl-days { display: flex; }
.sch-tl-day { flex: none; box-sizing: border-box; height: 46px; background: var(--bg-1); border-right: 2px solid var(--line); border-bottom: 1px solid var(--line); }
.sch-tl-day.weekend { background: rgba(96,165,250,.07); }
.sch-tl-daynum { height: 20px; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; font-weight: 700; font-family: var(--mono); color: var(--ink); }
.sch-tl-day.weekend .sch-tl-daynum { color: var(--info); }
.sch-tl-daywd { font-size: 8.5px; font-weight: 600; color: var(--faint); text-transform: uppercase; }
.sch-tl-hours { position: relative; height: 20px; width: 100%; }
.sch-tl-hourlbl { position: absolute; top: 2px; font-size: 10px; font-weight: 600; font-family: var(--mono); color: var(--faint); line-height: 16px; white-space: nowrap; }
.sch-tl-hourlbl.major { font-weight: 800; color: var(--muted); font-size: 11px; }

.sch-tl-row { display: flex; align-items: stretch; }
.sch-tl-left {
  position: sticky; left: 0; z-index: 20; flex: none; width: 230px; box-sizing: border-box; height: 44px;
  background: var(--bg-2); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
}
.sch-tl-num { font-size: 9px; color: var(--faint); font-family: var(--mono); flex: none; width: 20px; }
.sch-tl-leftmain { flex: 1; min-width: 0; }
.sch-tl-nm { font-size: 12px; font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sch-tl-sub { font-size: 9.5px; color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.sch-tl-lane { position: relative; flex: none; height: 44px; cursor: crosshair; border-bottom: 1px solid var(--line-2); box-sizing: border-box; }

.sch-tl-tint {
  position: absolute; top: 0; bottom: 0; display: flex; align-items: center; padding-left: 8px;
  font-size: 9.5px; font-weight: 700; font-family: var(--mono); pointer-events: none; box-sizing: border-box; border-left: 2px solid;
}
.sch-tl-bar {
  position: absolute; top: 7px; height: 30px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
  gap: 4px; padding: 0 16px 0 8px; font-size: 10.5px; font-weight: 700; font-family: var(--mono); white-space: nowrap;
  overflow: visible; box-sizing: border-box; cursor: grab; box-shadow: inset 0 0 0 1px var(--bg-main, var(--bg-1)), 0 1px 3px rgba(0,0,0,.3); z-index: 2;
}
.sch-tl-bar.ot { background: repeating-linear-gradient(135deg, var(--warn-2) 0 6px, #c97b2e 6px 12px); color: #2e1c00; z-index: 3; }
.sch-tl-bar.sel { box-shadow: 0 0 0 2px var(--purple-l), inset 0 0 0 1px var(--bg-1), 0 1px 3px rgba(0,0,0,.3); z-index: 5; }
.sch-tl-bar:active { cursor: grabbing; }
.sch-barlabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sch-barnote { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; font-style: italic; opacity: .82; font-size: 9.5px; }
.sch-bardel {
  position: absolute; right: 2px; top: 2px; width: 14px; height: 14px; border-radius: 4px; display: inline-flex;
  align-items: center; justify-content: center; cursor: pointer; font-size: 12px; line-height: 1; opacity: .45;
  background: rgba(0,0,0,.18); transition: opacity var(--mo-fast), background var(--mo-fast); z-index: 4;
}
.sch-tl-bar:hover .sch-bardel { opacity: .85; }
.sch-bardel:hover { opacity: 1 !important; background: rgba(0,0,0,.35); }
.sch-barmark {
  position: absolute; top: -8px; right: -6px; width: 20px; height: 20px; display: inline-flex; align-items: center;
  justify-content: center; z-index: 6; cursor: pointer; filter: drop-shadow(0 1px 2px rgba(0,0,0,.7));
}
.sch-barmark .ic { width: 15px; height: 15px; }
.sch-barmark.warn { color: var(--bad); }
.sch-barmark.flag { color: var(--gold-l); }

.sch-tl-preview {
  position: absolute; top: 6px; height: 32px; border-radius: 6px; background: rgba(251,146,60,.24);
  border: 2px dashed var(--warn-2); color: var(--warn-2); display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; font-family: var(--mono); pointer-events: none; box-sizing: border-box;
  white-space: nowrap; overflow: hidden; z-index: 8;
}

/* — Sổ ghi chú nổi (double-click 1 thanh) — */
.sch-noteed {
  position: fixed; width: 262px; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 11px; z-index: 2000; box-shadow: var(--el-3); box-sizing: border-box;
}
.sch-noteed-hd { font-size: 10px; font-weight: 700; color: var(--faint); letter-spacing: .4px; margin-bottom: 6px; }
.sch-noteed-inp {
  width: 100%; height: 30px; border: 1px solid var(--line); background: var(--bg-1); color: var(--ink);
  border-radius: 7px; font-size: 12px; outline: none; padding: 0 9px; box-sizing: border-box;
}
.sch-noteed-inp:focus { border-color: var(--purple-l); box-shadow: var(--glow-purple); }
.sch-noteed-marks { display: flex; align-items: center; gap: 6px; margin-top: 9px; flex-wrap: wrap; }
.sch-noteed-lab { font-size: 9px; font-weight: 700; color: var(--faint); letter-spacing: .4px; flex: none; }
.sch-mk {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; height: 26px; padding: 0 9px;
  border-radius: 7px; font-size: 11px; font-weight: 600; cursor: pointer; border: 1px solid var(--line); color: var(--muted);
  background: var(--card-2);
}
.sch-mk .ic { width: 13px; height: 13px; }
.sch-mk.on { border-color: var(--purple-l); background: var(--purple-soft); color: var(--purple-xl); }
.sch-mk-warn.on { border-color: var(--bad); background: rgba(248,113,113,.14); color: var(--bad); }
.sch-mk-flag.on { border-color: var(--gline); background: var(--gold-soft); color: var(--gold-l); }
.sch-noteed-ft { display: flex; gap: 6px; margin-top: 9px; justify-content: flex-end; }

/* — Peek ghi chú khi hover icon đánh dấu — */
.sch-peek {
  position: fixed; max-width: 240px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 11px; z-index: 2100; box-shadow: var(--el-2); pointer-events: none;
}
.sch-peek-who { font-size: 9px; font-weight: 700; color: var(--faint); letter-spacing: .4px; margin-bottom: 3px; }
.sch-peek-txt { font-size: 12px; color: var(--ink); line-height: 1.4; }

/* — Chú thích mã ca: một ngôn ngữ, ngay trước bảng — */
.sch-legend { margin: 0 0 var(--sp-2); color: var(--muted); font-size: 11px; }
