/* ====================================================================== */
/*  TIMELINE — dải track kiểu Premiere dưới khung xem trước (09/10/2026)   */
/*                                                                        */
/*  Thay cho "Danh sách slide" cũ. Nằm ở HÀNG DƯỚI của bố cục ba cột, kéo  */
/*  dài dưới cột giữa (sân khấu) lẫn cột phải (bảng sửa); cột trái (AI)    */
/*  vẫn cao hết cửa sổ. Logic ở `render/timeline.js`.                      */
/*                                                                        */
/*  ⚠ NHẸ MẮT trước đã (chủ dự án: "nhìn rối mắt quá"): khối nền nhạt,      */
/*     không viền, không sọc xen kẽ, chữ chỉ hiện khi đủ chỗ.               */
/*  ⚠ Màu/cỡ/khoảng cách đều qua token (`tokens.css`, nhóm --tl-*) —        */
/*     `verify:css` chặn số viết cứng.                                     */
/* ====================================================================== */

/* ── Bố cục: thêm một hàng dưới cho timeline ───────────────────────────
   `grid-template-areas` chứ không `order`: timeline chiếm HAI ô của hàng dưới
   (giữa + phải) mà cột trái thì chiếm cả hai hàng. */
.dashboard-shell.bt-ba-cot.co-tl {
  grid-template-rows: minmax(0, 1fr) var(--tl-cao);
  grid-template-areas: "trai giua phai" "trai tl tl";
}
.dashboard-shell.bt-ba-cot.co-tl .slide-list { grid-area: trai; }
.dashboard-shell.bt-ba-cot.co-tl .bt-san-khau { grid-area: giua; }
.dashboard-shell.bt-ba-cot.co-tl .bt-bang-sua { grid-area: phai; }
.dashboard-shell.bt-ba-cot.co-tl > .bt-timeline { grid-area: tl; }
/* Tay kéo cột phải chỉ ngăn HÀNG TRÊN — hàng dưới là một khối timeline liền. */
.dashboard-shell.bt-ba-cot.co-tl .bt-keo[data-ben="phai"] { bottom: var(--tl-cao); }
/* Thanh phát cũ dưới khung xem trước (▶ · giờ · tiến độ · loa · thư mục) BỎ
   (chủ dự án 09/10/2026): timeline đã có ▶, đồng hồ, tua, nút loa; mở thư mục
   video còn ở bảng sửa. Chỉ GIẤU — thanh-phat.js vẫn là bộ điều khiển video mà
   timeline gọi vào (mở/tua/chạy), các nút ẩn vẫn bấm hộ được. */
.dashboard-shell.co-tl .tp-thanh-phat { display: none; }
/* Dải slide cũ nhường chỗ. Mã của nó vẫn chạy (thanh phát, bảng sửa còn gọi
   vào) nên chỉ giấu, không gỡ. */
.dashboard-shell.co-tl .sk-dai { display: none; }

@media (max-width: 1180px) {
  /* Hẹp: cột trái đã tụt xuống dưới cùng (bien-tap.css). Hàng cuối CHIA PHẦN
     với sân khấu chứ không `auto` — khung cao cố định, `auto` cho cột AI cao
     theo nội dung là sân khấu bị ép về 0 (đã chụp thấy ở cửa sổ 1067px). */
  .dashboard-shell.bt-ba-cot.co-tl {
    grid-template-rows: minmax(0, 1.3fr) var(--tl-cao) minmax(0, 1fr);
    grid-template-areas: "giua phai" "tl tl" "trai trai";
  }
}

/* ── Khung ngoài ──────────────────────────────────────────────────────── */
.bt-timeline {
  position: relative;
  container-type: inline-size;
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--tl-nen);
  border-top: 1px solid var(--line);
  color: var(--text);
  outline: none;
}
.bt-timeline.thu .tl-than { display: none; }

/* Tay kéo chiều cao — dải 9px nằm đè lên mép trên, thấy được 1px khi kéo. */
.tl-keo {
  position: absolute; left: 0; right: 0; top: calc(var(--sp-4) * -1);
  height: 9px; z-index: var(--z-pop);
  cursor: row-resize;
}
.tl-keo::before {
  content: ''; position: absolute; left: 0; right: 0; top: var(--sp-4); height: 1px;
  background: none; transition: background var(--dur-fast) ease;
}
.tl-keo.dang-keo::before, .tl-keo:focus-visible::before { background: var(--tl-dau-phat); }
.tl-keo:focus-visible { outline: none; }
.bt-timeline.thu .tl-keo { display: none; }
body.tl-dang-keo { user-select: none; cursor: row-resize; }

/* ── Thanh công cụ ────────────────────────────────────────────────────── */
.tl-thanh {
  flex: none;
  display: flex; align-items: center; gap: var(--sp-4);
  height: 36px; padding: 0 var(--sp-8) 0 var(--sp-14);
}
.tl-gio {
  flex: none;
  font-family: var(--font-mono); font-size: var(--text-md); font-weight: var(--weight-semibold);
  color: var(--tl-dau-phat);
  font-variant-numeric: tabular-nums;
}
.tl-gio-tong {
  white-space: nowrap; color: var(--text-mo);
  font-size: var(--text-xs); font-family: var(--font-mono);
  margin: 0 var(--sp-8) 0 var(--sp-4);
}
.tl-nut {
  flex: none; display: inline-grid; place-items: center;
  min-width: 26px; height: 26px; padding: 0 var(--sp-4);
  border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text-faint);
  font-size: var(--text-base); cursor: pointer;
}
.tl-nut:hover:not(:disabled) { background: var(--surface); color: var(--text); }
.tl-nut:disabled { color: var(--text-mo); cursor: default; }
.tl-nut.bat { color: var(--tl-dau-phat); }
/* Tắt (chưa mở dự án / timeline chỉ đọc) thì KHÔNG tô xanh dù đang "bật" — trông bấm được mà bấm không ăn (audit 23/10). */
.tl-nut.bat:disabled { color: var(--text-mo); }
.tl-nut.dang-tat { color: var(--text-mo); }
.tl-nut .btn-icon { background: none; box-shadow: none; color: inherit; }
.tl-nut svg { width: 14px; height: 14px; }
.tl-vach { flex: none; width: 1px; height: 14px; background: var(--tl-vach); margin: 0 var(--sp-6); }
.tl-trang-thai {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--text-xs); color: var(--text-mo);
}
.tl-trang-thai.canh-bao { color: var(--warn-text); }
.tl-gian { flex: 1 1 auto; }
.tl-zoom { flex: none; width: 96px; accent-color: var(--tl-dau-phat); }
/* Timeline hẹp: bỏ bớt thứ phụ — phím tắt và Alt + lăn chuột vẫn phóng/thu được. */
@container (max-width: 900px) {
  .tl-zoom, .tl-gio-tong { display: none; }
}
@container (max-width: 680px) {
  .tl-trang-thai { display: none; }
}

/* ── Thân: một vùng cuộn, cột tên track + thước dính theo ─────────────── */
.tl-than { flex: 1 1 auto; min-height: 0; display: flex; }
.tl-cuon {
  position: relative; flex: 1 1 auto; min-width: 0;
  overflow: auto; overscroll-behavior: contain;
  background: var(--tl-lan);
}
/* Lưới hai cột: tên track (dính trái) | làn (rộng theo thời lượng × mức zoom). */
.tl-luoi {
  position: relative;
  display: grid;
  grid-template-columns: var(--tl-dau-w) auto;
  min-width: 100%;
  padding-bottom: var(--sp-4);
}
.tl-goc, .tl-ten {
  /* Thứ tự chồng trong timeline: làn < thước (+1) < đầu phát (+2) < cột tên
     track (+3) < góc trên trái (+4). Đầu phát chui DƯỚI cột tên khi cuộn. */
  position: sticky; left: 0; z-index: calc(var(--z-base) + 3);
  background: var(--tl-dau);
}
.tl-goc { top: 0; z-index: calc(var(--z-base) + 4); height: 22px; }
.tl-thuoc-o {
  position: sticky; top: 0; z-index: calc(var(--z-base) + 1);
  height: 22px; background: var(--tl-nen);
  cursor: ew-resize;
}
.tl-thuoc {
  display: block; height: 22px; position: sticky; left: var(--tl-dau-w);
  color: var(--tl-chu-thuoc); /* canvas không đọc được var() — timeline.js lấy màu đã tính từ đây */
}

/* Tên track: một dòng — huy hiệu V1/A1 nhạt + tên. Thông tin phụ nằm ở
   `title` (rê chuột), không chiếm chỗ. */
.tl-ten {
  display: flex; align-items: center; gap: var(--sp-8);
  padding: 0 var(--sp-8) 0 var(--sp-14);
  min-width: 0;
}
.tl-huy {
  flex: none; display: grid; place-items: center;
  min-width: 24px; height: 16px; padding: 0 var(--sp-4);
  border-radius: var(--radius-xs);
  font-size: var(--text-2xs); font-weight: var(--weight-semibold);
}
.tl-huy.p { background: var(--tl-phude); color: var(--tl-phude-chu); }
.tl-huy.v { background: var(--tl-hinh); color: var(--tl-hinh-chu); }
.tl-huy.a { background: var(--tl-giong); color: var(--tl-giong-chu); }
.tl-ten-chu {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: var(--text-xs); color: var(--text-faint);
}

/* Làn: một màu nền, không sọc xen kẽ, không kẻ ngang. */
.tl-lan { position: relative; cursor: text; }
.tl-lan-trong {
  position: absolute; left: var(--sp-8); top: 50%; transform: translateY(-50%);
  font-size: var(--text-xs); color: var(--text-mo); white-space: nowrap; pointer-events: none;
}

/* ── Khối (clip) ──────────────────────────────────────────────────────── */
.tl-khoi {
  position: absolute; top: var(--sp-2); bottom: var(--sp-2);
  display: flex; align-items: center; gap: var(--sp-6);
  overflow: hidden;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: filter var(--dur-fast) ease;
}
.tl-khoi::after {
  /* Sọc chéo RẤT nhạt cho khối ƯỚC TÍNH (chưa dựng video). */
  content: none; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(135deg, var(--tl-uoc) 0 5px, transparent 5px 10px);
}
.tl-khoi.uoc::after { content: ''; }
.tl-khoi.hinh { background: var(--tl-hinh); color: var(--tl-hinh-chu); }
.tl-khoi.phude { background: var(--tl-phude); color: var(--tl-phude-chu); }
.tl-khoi.giong { background: var(--tl-giong); color: var(--tl-giong-chu); }
.tl-khoi.nhac { background: var(--tl-nhac); color: var(--tl-nhac-chu); }
.tl-khoi.sfx { background: var(--tl-sfx); color: var(--tl-sfx-chu); border-radius: var(--radius-pill); }
.tl-khoi.tat { opacity: 0.45; }
.tl-khoi:hover { filter: brightness(0.97) saturate(1.15); }
body:not(.theme-light) .tl-khoi:hover { filter: brightness(1.18); }
/* Slide đang ở dưới đầu phát: một vòng mảnh màu đầu phát — đủ thấy, không chói. */
.tl-khoi.dang-o { box-shadow: inset 0 0 0 1px var(--tl-chon); }

/* Khối slide: MỘT ảnh thu nhỏ ở đầu khối + số và chữ — không lặp dải ảnh. */
.tl-anh {
  flex: none; height: 100%; width: auto; display: block;
  border-radius: var(--radius-xs);
  pointer-events: none;
}
.tl-khoi-nhan {
  position: relative; min-width: 0;
  display: flex; align-items: baseline; gap: var(--sp-4);
  padding: 0 var(--sp-6);
  font-size: var(--text-xs); line-height: var(--leading-snug);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
}
.tl-khoi.hinh .tl-anh + .tl-khoi-nhan { padding-left: 0; }
.tl-khoi-nhan b { font-weight: var(--weight-semibold); }
.tl-khoi-chu { opacity: 0.8; overflow: hidden; text-overflow: ellipsis; }
/* Khối tiếng: nhãn ở góc trên, sóng âm nằm dưới. */
.tl-khoi.giong .tl-khoi-nhan, .tl-khoi.nhac .tl-khoi-nhan {
  position: absolute; left: 0; top: 0; font-size: var(--text-2xs);
  /* Nền cùng màu khối để sóng âm không đè lên chữ. */
  border-bottom-right-radius: var(--radius-xs);
}
.tl-khoi.giong .tl-khoi-nhan { background: var(--tl-giong); }
.tl-khoi.nhac .tl-khoi-nhan { background: var(--tl-nhac); }
.tl-khoi.sfx .tl-khoi-nhan, .tl-khoi.phude .tl-khoi-nhan { font-size: var(--text-2xs); }

/* Sóng âm vẽ bằng canvas — màu nét = màu chữ của track (timeline.js đọc `color`). */
.tl-song {
  position: absolute; left: 0; top: 0;
  width: 100%; height: 100%; pointer-events: none;
  color: inherit;
}
/* Nhạc mẫu tổng hợp: không có tệp để vẽ sóng — vân dọc rất nhạt thay cho sóng. */
.tl-khoi.nhac.tong-hop {
  background-image: repeating-linear-gradient(90deg, var(--tl-uoc) 0 1px, transparent 1px 6px);
}

/* ── Đầu phát ─────────────────────────────────────────────────────────── */
.tl-dau-phat {
  position: absolute; top: 0; bottom: 0; width: 0;
  z-index: calc(var(--z-base) + 2);
  pointer-events: none;
  border-left: 1px solid var(--tl-dau-phat);
}
.tl-dau-phat::before {
  /* "Mũ" đầu phát trên thước — hình khiên nhỏ như Premiere. */
  content: ''; position: absolute; top: 0; left: -5px;
  width: 9px; height: 11px;
  background: var(--tl-dau-phat);
  clip-path: polygon(0 0, 100% 0, 100% 60%, 50% 100%, 0 60%);
}

/* ── Giai đoạn 2: chuyển cảnh, keyframe, điểm đánh dấu ─────────────────── */
.tl-chuyen { position: absolute; top: 0; bottom: 0; pointer-events: none; }
.tl-chuyen.vao { left: 0; background: linear-gradient(to right, var(--tl-chuyen), transparent); }
.tl-chuyen.vao.noi { background: linear-gradient(to right, var(--tl-chuyen-noi), transparent); }
.tl-chuyen.ra { right: 0; background: linear-gradient(to left, var(--tl-chuyen), transparent); }
.tl-kf {
  position: absolute; bottom: var(--sp-2); width: 7px; height: 7px;
  background: var(--tl-kf); transform: translateX(-50%) rotate(45deg); pointer-events: none;
}
.tl-dd-ten {
  position: absolute; top: 0; z-index: calc(var(--z-base) + 5); width: 160px; height: 22px;
  padding: 0 var(--sp-6);
  border: 1px solid var(--tl-danh-dau); border-radius: var(--radius-xs);
  background: var(--field-bg); color: var(--text); font-size: var(--text-xs);
}

/* ── Giai đoạn 3: sửa V1 (cắt / bỏ / đổi chỗ đoạn slide) ──────────────── */
.tl-khoi.hinh[data-doan] .tl-tay { cursor: ew-resize; }
.tl-khoi.hinh[data-doan]:hover .tl-tay::after {
  content: ''; position: absolute; top: 25%; bottom: 25%; width: 2px; left: var(--sp-2);
  border-radius: var(--radius-pill); background: var(--tl-tay);
}
.tl-khoi.hinh.chon-v1 { box-shadow: inset 0 0 0 2px var(--tl-chon); }
.tl-khoi.hinh.v1doan { border-left: 2px solid var(--tl-chuyen-noi); }
/* Phụ đề sửa được (phụ đề tách lớp) */
.tl-khoi.phude.sua { cursor: grab; }
.tl-khoi.phude.sua:hover .tl-tay::after {
  content: ''; position: absolute; top: 25%; bottom: 25%; width: 2px; left: var(--sp-2);
  border-radius: var(--radius-pill); background: var(--tl-tay);
}
.tl-khoi.phude.chon { box-shadow: inset 0 0 0 2px var(--tl-chon); }
.tl-pd-sua { width: 260px; }
