/* Bố cục PLAYGROUND 2 cột (bảng tham số trái + lưới kết quả phải), tone tím Studio.
   DÙNG CHUNG cho /customer/ai/studio/image và /customer/ai/studio/video — 2 trang khác nhau ở THAM SỐ
   (độ phân giải vs thời lượng) và ở Ô KẾT QUẢ (<img> vs <video>), còn khung sườn thì y hệt.
   ⚠ Đổi gì ở đây là đổi CẢ HAI trang. Thứ chỉ một trang dùng → để trong mục riêng cuối file.

   Nạp SAU hub.css + gallery.css, TRƯỚC studio-ui.css.
   ⚠⚠ HỆ QUẢ CỦA THỨ TỰ ĐÓ: muốn ĐÈ thuộc tính mà `.ais-*` đã đặt thì phải viết 2 class
   (vd `.ais-soft-menu.aigen-ddmenu`) — 1 class sẽ THUA vì studio-ui.css nạp sau.
   Dùng lại từ gallery.css: .aig-selbar, .aig-lb*, .aig-bar-fade  |  từ studio-ui.css: .ais-* */

.aigen { display: flex; flex-direction: column; gap: var(--cm-space-md); }

/* ── thanh trên ─────────────────────────────────────────────────────────── */
.aigen-top { display: flex; align-items: center; gap: var(--cm-space-md); flex-wrap: wrap; }
.aigen-top-left { display: flex; align-items: center; gap: 10px; }
.aigen-top-ic { color: var(--ais-accent2); font-size: 18px; }
.aigen-title { font-size: 18px; font-weight: 700; color: var(--cm-text-primary); }
.aigen-top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.aigen-chip {
  display: inline-flex; align-items: center; gap: 7px; height: 34px; padding: 0 12px; border-radius: var(--cm-radius-full);
  background: rgba(255, 255, 255, .05); border: 1px solid var(--cm-border);
  font-size: 12px; font-weight: 600; color: var(--cm-text-secondary); transition: var(--cm-transition-fast);
}
.aigen-chip i { color: var(--ais-accent2); }

/* ── khung 2 cột (bám .aig-body của Bộ sưu tập) ─────────────────────────── */
.aigen-body { display: flex; gap: var(--cm-space-lg); align-items: flex-start; }
/* ⚠⚠ CỘT TRÁI KHÔNG CÓ THANH CUỘN RIÊNG (user chốt 2026-08-06) — cả trang cuộn chung.
   Trước đây cột bị ghim `max-height: calc(100vh - 110px)` + `overflow-y: auto`, đẻ ra một vệt cuộn
   sáng chạy dọc giữa hai cột: phá đúng tinh thần "canvas" của khu Studio, và bắt khách cuộn HAI chỗ
   khác nhau trên cùng một màn hình.
   ⚠ Bỏ `overflow` thì PHẢI bỏ luôn `position: sticky`: cột này cao hơn màn hình, mà sticky ghim
   ĐỈNH phần tử lại ⇒ phần đáy (nút Dựng video) nằm ngoài khung nhìn và KHÔNG cuộn tới được. Sticky
   chỉ an toàn với cột THẤP HƠN viewport. Muốn nút luôn trong tầm tay thì ghim riêng .aigen-actions. */
.aigen-panel {
  flex: 0 0 360px; max-width: 360px;
  display: flex; flex-direction: column; gap: 12px;
  padding: var(--cm-space-lg); background: var(--cm-bg-card);
  border: 1px solid var(--cm-border); border-radius: var(--cm-radius-lg);
}
/* Con của flex-column mặc định flex-shrink:1 → giữ `flex: 0 0 auto` để không bao giờ bị bóp lại
   (`.ais-sec` có overflow:hidden nên co lại là nội dung bị CẮT, không dấu hiệu gì).
   Đã dính thật hồi cột còn max-height: hàng "tỉ lệ khung" mất nửa dưới. */
.aigen-panel > * { flex: 0 0 auto; }
.aigen-results {
  position: relative; flex: 1; min-width: 0; min-height: 62vh; padding: var(--cm-space-md);
  border: 1px solid var(--cm-border); border-radius: var(--cm-radius-lg);
  background-image: radial-gradient(rgba(255, 255, 255, .055) 1px, transparent 1px);
  background-size: 22px 22px; cursor: var(--ais-grab);
  transition: var(--cm-transition-fast);
}
.aigen-results:hover { border-color: rgba(99, 102, 241, .32); }

/* ── 3 ô chọn mềm: model · dự án · thư mục ──────────────────────────────────
   Cùng MỘT cơ chế cho cả ba (thay <select> native thô của OS): nút mềm + menu .ais-soft-menu
   position:FIXED toạ độ tính từ getBoundingClientRect của nút.
   ⚠ Vì sao fixed chứ không absolute: JS đo bằng getBoundingClientRect (toạ độ theo KHUNG NHÌN) rồi
   gán thẳng top/left ⇒ chỉ `fixed` mới hiểu đúng bộ toạ độ đó; đổi sang absolute là menu nhảy chỗ.
   (Lý do cũ — cột trái có overflow cắt mất menu — nay không còn, cột đã bỏ thanh cuộn riêng.)
   Menu mở ra mà cuộn trang thì JS tự đóng (listener `scroll` ở chế độ capture trong gen-*.js). */
.aigen-dd { position: relative; }
.aigen-ddbtn {
  display: flex; align-items: center; gap: 9px; width: 100%; height: 40px; padding: 0 12px;
  border-radius: var(--cm-radius-md); background: rgba(255, 255, 255, .05);
  border: 1px solid var(--cm-border); color: var(--cm-text-primary); cursor: pointer;
  font-size: var(--cm-font-sm); font-weight: 600; transition: var(--cm-transition-fast);
}
.aigen-ddbtn:hover, .aigen-ddbtn.on { border-color: var(--ais-accent); background: var(--ais-soft-fill); }
.aigen-modelbtn { height: 46px; padding: 0 13px; font-weight: 700; }
.aigen-dd-ic { flex: 0 0 auto; width: 15px; text-align: center; color: var(--ais-accent2); font-size: 13px; }
.aigen-ddname { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.aigen-ddcaret { flex: 0 0 auto; color: var(--cm-text-muted); font-size: 11px; }
.aigen-dd-backdrop { position: fixed; inset: 0; z-index: 3199; }
/* ⚠ PHẢI viết 2 class `.ais-soft-menu.aigen-ddmenu`, KHÔNG được `.aigen-ddmenu` một mình:
   studio-ui.css nạp SAU file này (xem thứ tự <link> ở đầu view) nên `.ais-soft-menu { position:absolute }`
   cùng độ đặc hiệu sẽ THẮNG và menu văng khỏi màn hình (đo được: top = -708px, không lỗi console nào). */
.ais-soft-menu.aigen-ddmenu { position: fixed; z-index: 3200; min-width: 210px; }
.aigen-ddmenu .ais-soft-item > span:first-of-type { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aigen-dd-ok { flex: 0 0 auto; color: var(--ais-accent3); font-size: 11px; }
/* Giá bậc THẤP NHẤT của model — để khách xổ danh sách ra là so giá được ngay (danh sách đã xếp rẻ→đắt) */
.aigen-mprice { flex: 0 0 auto; font-size: 11px; font-weight: 700; color: var(--ais-accent3); }
.aigen-mprice.aigen-mprice-free { color: #4ade80; font-size: 12px; letter-spacing: .02em; }
.aigen-ddmenu .aigen-mday { opacity: .5; }
.aigen-badge {
  flex: 0 0 auto; padding: 2px 8px; border-radius: var(--cm-radius-full);
  font-size: 10px; font-weight: 700; letter-spacing: .02em;
}
.aigen-badge.std { background: rgba(99, 102, 241, .16); color: #c7d2fe; }
.aigen-badge.eco { background: rgba(16, 185, 129, .16); color: #6ee7b7; }
.aigen-run-meta .aigen-badge { display: inline-block; margin-left: 6px; vertical-align: baseline; }
.aigen-run-meta.aigen-meta-ngat { white-space: normal; line-height: 1.75; }

/* ── các ô nhập ─────────────────────────────────────────────────────────── */
.aigen-lbl { font-size: 11px; font-weight: 700; color: var(--cm-text-secondary); text-transform: uppercase; letter-spacing: .04em; margin: 15px 0 8px; }
.aigen-lbl:first-child { margin-top: 0; }
.aigen-lbl-sub { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--cm-text-secondary); }
.aigen-ta, .aigen-input {
  width: 100%; padding: 10px 12px; border-radius: var(--cm-radius-md); resize: vertical;
  background: rgba(0, 0, 0, .22); border: 1px solid var(--cm-border); color: var(--cm-text-primary);
  font-size: var(--cm-font-sm); font-family: inherit; line-height: 1.5; transition: var(--cm-transition-fast);
}
.aigen-input { resize: none; }
.aigen-ta:focus, .aigen-input:focus { outline: none; border-color: var(--ais-accent); background: rgba(0, 0, 0, .3); }
.aigen-hint { margin: 11px 0 0; font-size: 11px; color: var(--cm-text-secondary); line-height: 1.55; }

.aigen-tawrap { position: relative; }
.aigen-tawrap.keo .aigen-ta { border-color: var(--ais-accent); background: rgba(139, 92, 246, .1); }
.aigen-tadrop {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: 6px; border-radius: var(--cm-radius-md); pointer-events: none;
  background: rgba(0, 0, 0, .72); color: var(--cm-text-primary); font-size: var(--cm-font-sm); font-weight: 600;
}
.aigen-tawrap.keo .aigen-tadrop { display: flex; }
.aigen-tadrop i { font-size: 22px; color: var(--ais-accent); }
.aigen-tafoot { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.aigen-tafile {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: var(--cm-radius-sm);
  background: rgba(139, 92, 246, .14); border: 1px solid rgba(139, 92, 246, .3);
  font-size: 11px; color: var(--cm-text-primary); max-width: 100%;
}
.aigen-tafile b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.aigen-tafile button {
  background: none; border: 0; padding: 0; cursor: pointer; color: var(--cm-text-muted); font-size: 12px; line-height: 1;
}
.aigen-tafile button:hover { color: var(--cm-danger, #ef4444); }
.aigen-hint.loi { color: var(--cm-danger, #ef4444); }

.aigen-vtim { position: relative; display: flex; align-items: center; margin: 14px 0 10px; }
.aigen-vtim > i:first-child {
  position: absolute; left: 10px; font-size: 12px; color: var(--cm-text-muted); pointer-events: none;
}
.aigen-vtim-in {
  width: 100%; padding: 8px 30px 8px 30px; border-radius: var(--cm-radius-md);
  background: rgba(0, 0, 0, .22); border: 1px solid var(--cm-border); color: var(--cm-text-primary);
  font-size: var(--cm-font-sm); font-family: inherit; transition: var(--cm-transition-fast);
}
.aigen-vtim-in:focus { outline: none; border-color: var(--ais-accent); background: rgba(0, 0, 0, .3); }
.aigen-vtim-x {
  position: absolute; right: 8px; background: none; border: 0; padding: 2px 4px; cursor: pointer;
  color: var(--cm-text-muted); font-size: 12px; line-height: 1;
}
.aigen-vtim-x:hover { color: var(--cm-text-primary); }
.aigen-vtabs { margin-bottom: 8px; }
.aigen-vtabs .aigen-opt:disabled { opacity: .45; cursor: not-allowed; }

.aigen-voices { max-height: 340px; overflow-y: auto; }
.aigen-vtai { text-align: center; padding: 8px 0; }
.aigen-voice-fav {
  background: none; border: 0; padding: 4px 6px; cursor: pointer; line-height: 1;
  color: var(--cm-text-dim); font-size: 13px; transition: var(--cm-transition-fast);
}
.aigen-voice-fav:hover { color: var(--cm-warning, #f59e0b); }
.aigen-voice-fav.on { color: var(--cm-warning, #f59e0b); }

.aigen-opts { display: flex; flex-wrap: wrap; gap: 8px; }
.aigen-opt {
  min-width: 46px; height: 32px; padding: 0 11px; border-radius: 9px;
  background: rgba(255, 255, 255, .05); border: 1px solid var(--cm-border); color: var(--cm-text-secondary);
  font-size: 12px; font-weight: 700; cursor: pointer; transition: var(--cm-transition-fast);
}
.aigen-opt:hover { border-color: var(--ais-accent); background: var(--ais-soft-fill); color: #fff; }
.aigen-opt.on { border-color: var(--ais-accent); background: var(--ais-soft-fill2); color: #fff; }
.aigen-opt:disabled, .aigen-opt:disabled:hover { opacity: .45; cursor: not-allowed; border-color: var(--cm-border); background: rgba(255, 255, 255, .05); color: var(--cm-text-secondary); }

/* ảnh tham chiếu */
.aigen-refs { display: flex; flex-wrap: wrap; gap: 8px; }
.aigen-ref { position: relative; width: 58px; height: 58px; border-radius: 10px; overflow: hidden; border: 1px solid var(--cm-border); }
.aigen-ref img { width: 100%; height: 100%; object-fit: cover; display: block; }
.aigen-file { display: none; }
.aigen-ref-up {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  border-radius: 10px; background: rgba(0, 0, 0, .5); color: #fff; font-size: 13px;
}
/* Kéo tệp từ máy vào bảng tham số — viền cả cột sáng lên để thấy rõ vùng thả kể cả khi
   khối "Ảnh tham chiếu" đang gập (thả xong JS tự mở khối đó ra). */
.aigen-panel.drop { border-color: var(--ais-accent); box-shadow: inset 0 0 0 2px rgba(99, 102, 241, .3); }
.aigen-panel.drop .aigen-refs { outline: 2px dashed var(--ais-accent); outline-offset: 5px; border-radius: 8px; }
.aigen-ref-x {
  position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .66); color: #fff; font-size: 9px; cursor: pointer; line-height: 1;
}
.aigen-ref-x:hover { background: var(--cm-danger); }
.aigen-ref-add {
  width: 58px; height: 58px; border-radius: 10px; cursor: pointer; transition: var(--cm-transition-fast);
  background: rgba(255, 255, 255, .04); border: 1px dashed var(--cm-border-strong); color: var(--ais-accent2); font-size: 15px;
}
.aigen-ref-add:hover { border-color: var(--ais-accent); background: var(--ais-soft-fill); }

/* ── khối hành động DÍNH ĐÁY KHUNG NHÌN ──────────────────────────────────────
   Cột trái nay cuộn theo cả trang, nên đây là thứ DUY NHẤT còn ghim: giá tạm tính + nút Dựng video
   luôn trong tầm tay dù khách đang điền ở đoạn nào của cột.
   ⚠ `bottom: 0` chứ KHÔNG âm như cũ. Số âm chỉ đúng khi cha là khung cuộn riêng (ghim sát mép trong
   của cột); nay cha là cả trang, số âm sẽ ghim khối này THẤP HƠN mép dưới màn hình = cụt mất nút. */
.aigen-actions {
  position: sticky; bottom: 0; margin-top: 6px;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 0 4px; background: var(--cm-bg-card); border-top: 1px solid var(--cm-border);
}
.aigen-actions > .aigen-hint, .aigen-actions > .ais-warn { margin: 0; }
.aigen-cost { display: flex; align-items: baseline; justify-content: space-between; font-size: 12px; color: var(--cm-text-muted); }
.aigen-cost b { font-size: 15px; color: var(--ais-accent3); }
.aigen-go { justify-content: center; height: 44px; font-size: 14px; }
.aigen-reset { justify-content: center; }

/* ── lưới kết quả ───────────────────────────────────────────────────────── */
.aigen-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: var(--cm-space-md); }
/* Đếm số lượt — thay cho chữ "Lịch sử": nói được thứ mà cái nhãn kia không nói, và vẫn cân bằng
   thanh ngang với nút "Làm mới" bên phải. */
.aigen-bar-count { display: inline-flex; align-items: center; gap: 7px; font-size: var(--cm-font-xs, 12px); color: var(--cm-text-secondary); }
.aigen-bar-count i { color: var(--ais-accent2); }

/* ⚠ `.cm-pill-tabs` (components.css) sinh ra để làm THANH TAB ĐỘC LẬP của cả trang nên nó tự mang
   `margin-bottom: lg` + `padding-bottom: md` + gạch chân. Nhét nguyên vào một hàng flex
   `align-items: center` thì phần đệm dưới đội cụm pill LÊN, lệch hẳn so với nhãn trái và nút phải —
   đúng chỗ user khoanh đỏ. Ở đây nó là một cụm TRONG hàng, nên phải gỡ hết phần đệm "đứng riêng". */
.cm-pill-tabs.aigen-tabs { margin: 0; padding: 0; border-bottom: 0; gap: 6px; }
.aigen-tabs .cm-pill-tab { padding: 5px 13px; font-size: var(--cm-font-xs, 12px); }
/* Tab đang chọn theo tông tím studio, KHÔNG dùng --cm-primary (xanh) như tab dùng chung ngoài site */
.aigen-tabs .cm-pill-tab.active { background: linear-gradient(135deg, var(--ais-accent), var(--ais-accent2)) no-repeat border-box; border-color: transparent; color: #fff; }
.aigen-bar-sp { flex: 1; }

/* ⭐ LỊCH SỬ XẾP 2 CỘT (sửa 2026-08-05). Trước đây mỗi lượt là một khối FULL-WIDTH, mà lượt mặc định
   chỉ có 1 ảnh ⇒ ảnh nằm chơ vơ nửa trái, nửa phải bỏ trắng, cả trang đọc thành một dải dọc.
   Nay: lượt 1 ảnh chiếm 1 cột (2 lượt nằm cạnh nhau = 2 ảnh 1 hàng), lượt nhiều ảnh chiếm trọn
   bề ngang và xếp đúng 2 ảnh/hàng.
   ⚠ `grid-column: 1 / -1` chứ KHÔNG `span 2`: cửa sổ hẹp (~1025-1180px) lưới chỉ còn 1 cột, `span 2`
   sẽ đẻ cột ngầm → tràn ngang. `1 / -1` luôn bám đúng số cột đang có. */
.aigen-runs {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: var(--cm-space-lg) var(--cm-space-md); align-items: start;
}
.aigen-run {
  min-width: 0; padding: 12px; border-radius: 14px;
  background: rgba(255, 255, 255, .028); border: 1px solid var(--cm-border);
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
@media (hover: hover) {
  .aigen-run:hover { border-color: rgba(99, 102, 241, .42); transform: translateY(-2px); box-shadow: var(--cm-shadow-hover); }
}
@media (prefers-reduced-motion: reduce) {
  .aigen-run { transition: border-color .18s ease; }
  .aigen-run:hover { transform: none; }
}
.aigen-run.wide { grid-column: 1 / -1; }
.aigen-run-head { display: flex; align-items: center; gap: 5px 9px; margin-bottom: 9px; flex-wrap: wrap; }
/* Prompt chiếm trọn 1 dòng: khối chỉ rộng ~210px nên để chung dòng với model + nút là vỡ bố cục */
.aigen-run-prompt {
  flex: 1 1 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; font-weight: 600; color: var(--cm-text-primary);
}
.aigen-run-meta {
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 11px; color: var(--cm-text-muted);
}
.aigen-run-head > .aigen-run-ten { flex: 1 1 100%; margin-left: -9px; font-size: 13px; }

.aigen-grid { display: grid; grid-template-columns: 1fr; gap: var(--cm-space-md); }
.aigen-run.wide .aigen-grid { grid-template-columns: repeat(2, 1fr); }
.aigen-cell {
  position: relative; border-radius: var(--cm-radius-md); overflow: hidden;
  border: 2px solid transparent; background: rgba(0, 0, 0, .25); transition: var(--cm-transition-fast);
}
.aigen-cell:hover { border-color: rgba(99, 102, 241, .4); }
.aigen-cell.sel { border-color: #a855f7; box-shadow: 0 0 0 2px rgba(168, 85, 247, .35); }
/* aspect-ratio THẬT của ảnh do JS gắn inline (ratio(size)) — 1/1 ở đây chỉ là lưới đỡ khi thiếu size.
   Ảnh 16:9 / 9:16 mà ép ô vuông là cắt mất bố cục đúng thứ khách vừa trả tiền để có. */
.aigen-thumb { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; cursor: pointer; }
.aigen-check {
  position: absolute; top: 7px; left: 7px; width: 24px; height: 24px; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 13px; cursor: pointer; opacity: 0; transition: var(--cm-transition-fast);
}
.aigen-cell:hover .aigen-check, .aigen-cell.sel .aigen-check { opacity: 1; }
.aigen-mid {
  display: inline-block; margin-left: 6px; padding: 2px 7px;
  border-radius: var(--cm-radius-full); border: 1px solid var(--cm-border);
  background: rgba(255, 255, 255, .06); color: var(--cm-text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
  user-select: all; vertical-align: baseline;
}
.aigen-cell.sel .aigen-check { color: #c084fc; }

/* ô đang tạo */
.aigen-cell.pending { border-color: transparent; }
.aigen-wait {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px;
  aspect-ratio: 1 / 1; border-radius: var(--cm-radius-md);
  font-size: 11px; color: var(--cm-text-secondary); text-align: center; padding: 10px;
}
.aigen-wait i { font-size: 17px; color: var(--ais-accent2); }

.aigen-more { display: flex; justify-content: center; padding: var(--cm-space-md) 0 4px; }

/* ── picker ảnh tham chiếu ──────────────────────────────────────────────── */
.aigen-pk-backdrop { position: fixed; inset: 0; z-index: 3000; background: rgba(0, 0, 0, .62); display: flex; align-items: center; justify-content: center; padding: 18px; }
.aigen-pk {
  width: min(880px, 100%); max-height: 82vh; display: flex; flex-direction: column;
  background: var(--ais-panel); border: 1px solid var(--cm-border-strong); border-radius: var(--cm-radius-lg);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55); overflow: hidden;
}
.aigen-pk-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 15px; border-bottom: 1px solid var(--cm-border); font-size: 14px; font-weight: 700; color: var(--cm-text-primary); }
.aigen-pk-head i { color: var(--ais-accent2); margin-right: 7px; }
.aigen-pk-body { flex: 1; overflow-y: auto; padding: 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.aigen-pk-cell { border-radius: 10px; overflow: hidden; border: 2px solid transparent; cursor: pointer; transition: var(--cm-transition-fast); }
.aigen-pk-cell:hover { border-color: var(--ais-accent); }
.aigen-pk-cell img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; }

/* ── điện thoại: xếp dọc, bảng tham số lên trên ─────────────────────────── */
@media (max-width: 1024px) {
  .aigen-body { flex-direction: column; }
  .aigen-panel { flex: 1 1 auto; max-width: 100%; width: 100%; }
  /* ⚠ .aigen-body giữ `align-items: flex-start` cả khi đã xếp dọc → trong flex COLUMN nó bắt con rộng
     theo max-content chứ không theo màn hình. Cột trái thoát nhờ có width:100%, cột PHẢI thì không
     ⇒ ở 375px nó phình 559px, kéo cuộn ngang cả trang (đo được scrollWidth 559 / clientWidth 375). */
  .aigen-results { width: 100%; max-width: 100%; }
  .aigen-actions { position: static; }
}
@media (max-width: 600px) {
  /* Điện thoại: bỏ lưới 2 cột cho LƯỢT (mỗi lượt một khối xếp dọc) — ô 150px thì nhìn không ra gì.
     Bên trong vẫn giữ luật cũ: lượt 1 ảnh = ảnh to hết bề ngang, lượt nhiều ảnh = 2 ảnh/hàng. */
  .aigen-runs { display: block; }
  .aigen-run { margin-bottom: var(--cm-space-lg); }
  .aigen-top-right { width: 100%; }
}

/* ══ CHỈ TRANG TẠO VIDEO ═══════════════════════════════════════════════════ */

/* Ô kết quả là <video> chứ không phải <img>: giữ nguyên khung/bo góc/viền chọn của .aigen-cell,
   chỉ đổi phần tử bên trong. `preload="metadata"` = chỉ tải phần đầu tệp để có khung hình + thời
   lượng, KHÔNG kéo cả clip vài MB về chỉ để hiện một hình tĩnh trong lưới. */
/* ⚠ KHÔNG ép `aspect-ratio` ở đây: khung THẬT của clip do nhà cung cấp quyết, KHÁC khung ta xin.
   Đo 2026-08-05: xin 480x848 (dọc) → grok trả 848x480 (ngang); xin 720x720 → wan trả 720x1280.
   Đóng khung theo `size` đã lưu = video ngang nằm trong hộp dọc, viền đen hai bên.
   `height: auto` cho <video> tự lấy tỉ lệ nội tại sau khi nạp metadata — luôn đúng, khỏi đoán. */
.aigen-video { display: block; width: 100%; height: auto; background: #000; cursor: pointer; }
.aigen-vbieu {
  position: absolute; inset: 0; z-index: 0;
  display: flex; align-items: center; justify-content: center;
  color: rgba(255, 255, 255, .28); font-size: 34px; pointer-events: none;
}
.aigen-cell > video, .aigen-cell > .aimo-out { position: relative; z-index: 1; background: transparent; }
/* Khổ ô chờ do JS dán inline theo lượt khách đặt (`ratio(size)`); 16/9 đây chỉ là lưới đỡ khi
   thiếu size. Trước đây ép cứng 16/9 nên khách đặt 9:16 vẫn phải nhìn khung ngang suốt lúc chờ. */
.aigen-wait.aigen-wait-v { aspect-ratio: 16 / 9; }
/* Khung ĐẦU / khung CUỐI đứng cạnh nhau — nhìn ra ngay đây là hai đầu của một cảnh */
.aigen-frames { display: flex; gap: var(--cm-space-md); flex-wrap: wrap; }
.aigen-frame { flex: 1 1 120px; min-width: 0; }
.aigen-frame-lbl { font-size: 11px; font-weight: 700; color: var(--cm-text-muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }

/* ── Lượt tạo HỎNG ────────────────────────────────────────────────────────────
   Ô hỏng nằm NGUYÊN chỗ cũ trong lưới (trước đây bị xoá đi, khách quay lại không còn dấu vết nào
   nên tưởng chưa từng bấm — rồi bấm lại và trả tiền lần nữa cho cùng một lỗi). */
.aigen-cell.failed { cursor: default; }
.aigen-fail {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
    padding: 14px; text-align: center;
    border: 1px dashed rgba(239, 68, 68, .45); border-radius: 12px;
    background: rgba(239, 68, 68, .07); color: #fca5a5;
    font-size: var(--cm-font-xs, 12px); line-height: 1.45;
}
.aigen-fail i { font-size: 20px; opacity: .85; }

/* ══ CHỈ TRANG TẠO GIỌNG ĐỌC ═══════════════════════════════════════════════
   Khác hai trang kia ở một chỗ căn bản: KẾT QUẢ KHÔNG NHÌN ĐƯỢC. Không ảnh, không khung hình,
   không ảnh bìa — nên mọi thứ phân biệt các ô với nhau phải là CHỮ (tên giọng + đầu câu), và ô
   phải cao vừa đủ chứa thanh phát, không ép `aspect-ratio` như ô ảnh/video. */

/* ── kho giọng trong bảng tham số ─────────────────────────────────────────
   Danh sách dọc có thanh cuộn RIÊNG: 8 giọng × 3 bậc mà xổ thẳng ra là đẩy nút "Tạo giọng đọc"
   xuống tận đáy trang. Đây là ngoại lệ CÓ CHỦ Ý với luật "cột trái không cuộn riêng" — cuộn nằm
   trong một khối con, không phải cả cột. */
.aigen-voices { max-height: 306px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-top: 12px; padding-right: 4px; }
.aigen-voice {
  display: flex; align-items: center; gap: 9px; padding: 7px 9px; cursor: pointer;
  border: 1px solid var(--cm-border); border-radius: var(--cm-radius-md);
  background: rgba(255, 255, 255, .03); transition: var(--cm-transition-fast);
}
.aigen-voice:hover { border-color: var(--ais-accent); background: var(--ais-soft-fill); }
.aigen-voice.on { border-color: var(--ais-accent); background: var(--ais-soft-fill2); }
.aigen-voice-play {
  flex: 0 0 28px; width: 28px; height: 28px; border-radius: 50%; border: 1px solid var(--cm-border);
  background: rgba(0, 0, 0, .3); color: var(--ais-accent2); font-size: 10px; cursor: pointer;
  transition: var(--cm-transition-fast);
}
.aigen-voice-play:hover:not(:disabled) { border-color: var(--ais-accent); color: #fff; }
.aigen-voice-play.playing { background: var(--ais-accent); color: #fff; border-color: var(--ais-accent); }
.aigen-voice-play:disabled { opacity: .35; cursor: default; }
.aigen-voice-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.aigen-voice-ten { font-size: 13px; font-weight: 600; color: var(--cm-text-primary); }
.aigen-voice-sub { font-size: 11px; color: var(--cm-text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.aigen-voice-ok { flex: 0 0 auto; color: #c084fc; font-size: 13px; }

/* Đếm ký tự vượt trần → đỏ. Không đổi màu thì con số cứ chạy tiếp và khách chỉ biết mình vượt
   khi bấm nút rồi bị từ chối. */
.ais-sec-note.over { color: #fca5a5; font-weight: 700; }

/* ── ô kết quả ────────────────────────────────────────────────────────── */
.aigen-runs-audio { grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 16px; }
.aigen-run-audio { padding: 15px 15px 16px; }
.aigen-run-audio .aigen-run-head { margin-bottom: 14px; gap: 10px 10px; }
.aigen-run-audio .aigen-run-prompt { white-space: normal; line-height: 1.5; max-height: 3em; overflow: hidden; }

.aigen-grid-audio { gap: 10px; }
.aigen-cell-audio { padding: 10px 11px 12px; background: rgba(0, 0, 0, .28); }
.aigen-audio-head { display: flex; align-items: center; gap: 7px; margin-bottom: 10px; }

.ais-soft-btn.ais-sm.aigen-dl-btn {
  flex: 0 0 auto; height: 30px; padding: 0 9px; border-radius: 9px; gap: 6px; font-size: 11.5px;
}
.ais-soft-btn.ais-sm.aigen-dl-btn .ais-btn-ic { font-size: 12px; }
.aigen-audio-ten {
  flex: 1; min-width: 0; font-size: 12px; font-weight: 600; color: var(--cm-text-primary);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}/* Ô chọn của ô audio nằm TRONG hàng tiêu đề (không phải nổi đè góc ảnh như hai trang kia) và
   LUÔN hiện: ô audio không có ảnh để rê chuột lên, ẩn đi thì không ai tìm ra nút chọn. */
.aigen-cell-audio .aigen-check { position: static; opacity: 1; flex: 0 0 24px; background: transparent; }
.aigen-wait.aigen-wait-a { aspect-ratio: auto; min-height: 78px; }

.aigen-sw-row { display: flex; align-items: center; gap: 10px; }
.aigen-sw {
  position: relative; flex: 0 0 auto; width: 40px; height: 22px; padding: 0;
  border-radius: var(--cm-radius-full); border: 1px solid var(--cm-border);
  background: rgba(255, 255, 255, .05); cursor: pointer;
  transition: background .18s ease, border-color .18s ease;
}
.aigen-sw::after {
  content: ''; position: absolute; left: 2px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; border-radius: 50%; background: var(--cm-text-muted);
  transition: transform .18s ease, background .18s ease;
}
.aigen-sw:hover:not(:disabled) { border-color: var(--ais-accent); }
.aigen-sw.on { border-color: var(--ais-accent); background: linear-gradient(90deg, var(--ais-accent), var(--ais-accent2)); }
.aigen-sw.on::after { transform: translate(18px, -50%); background: #fff; }
.aigen-sw:disabled { cursor: not-allowed; opacity: .45; }
.aigen-sw-txt { flex: 1; min-width: 0; font-size: 12px; font-weight: 600; color: var(--cm-text-primary); }
.aigen-sw-pct {
  flex: 0 0 auto; font-size: 11px; font-weight: 700; color: var(--ais-accent2);
  padding: 2px 7px; border-radius: var(--cm-radius-full); background: var(--ais-soft-fill);
}

.aigen-luat-head, .aigen-luat-row { display: flex; align-items: center; gap: 6px; }
.aigen-luat-head { margin: 10px 0 4px; font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--cm-text-muted); }
.aigen-luat-row { margin-bottom: 6px; }
.aigen-luat-c1, .aigen-luat-c2 { flex: 1 1 0; min-width: 0; }
.aigen-luat-c3 { flex: 0 0 62px; text-align: center; }
.aigen-luat-c4 { flex: 0 0 24px; text-align: center; }
.aigen-luat-in {
  width: 100%; padding: 6px 8px; font-size: 12px; color: var(--cm-text-primary);
  background: rgba(255, 255, 255, .04); border: 1px solid var(--cm-border);
  border-radius: var(--cm-radius-md); transition: border-color var(--cm-transition-fast);
}
.aigen-luat-in:focus { outline: none; border-color: var(--ais-accent); }
.aigen-luat-in::placeholder { color: var(--cm-text-dim); }
.aigen-luat-chk { display: flex; justify-content: center; cursor: pointer; }
.aigen-luat-chk input { accent-color: var(--ais-accent); cursor: pointer; }
.aigen-luat-x {
  width: 24px; height: 24px; padding: 0; border: 0; border-radius: var(--cm-radius-md);
  background: transparent; color: var(--cm-text-muted); cursor: pointer;
  transition: color var(--cm-transition-fast), background var(--cm-transition-fast);
}
.aigen-luat-x:hover { color: var(--cm-danger); background: rgba(239, 68, 68, .12); }
.aigen-luat-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.aigen-luat-ap { margin-top: 10px; width: 100%; justify-content: center; }
.ais-sec-note.on { color: var(--ais-accent3); }

@media (max-width: 560px) {
  .aigen-luat-c3 { flex: 0 0 30px; }
  .aigen-luat-head .aigen-luat-c3 { font-size: 0; }
  .aigen-luat-head .aigen-luat-c3::after { content: "NV"; font-size: 10px; }
}

.aigen-quy { margin-top: 10px; background: rgba(255,255,255,.015); }
.aigen-quy .ais-sec-head { font-size: 12px; padding: 8px 10px; }
.aigen-quy .ais-sec-body { padding-top: 4px; }
.aigen-quy code { font-size: 11px; white-space: nowrap; }
.aigen-mau{display:flex;flex-direction:column;gap:10px;width:100%;max-width:560px;margin:16px auto 0;text-align:left}
.aigen-mau-dau{font-size:13px;line-height:1.5;color:var(--cm-text-secondary);text-align:center}
.aigen-mau [data-aits]{width:100%;border-radius:12px}
.aigen-mau-chu{font-size:12.5px;line-height:1.5;color:var(--cm-text-secondary)}
.aigen-mau-muc{display:flex;flex-direction:column;gap:10px;min-width:0}
.aigen-mau-muc + .aigen-mau-muc{margin-top:14px}
.aigen-tai-loi .ais-soft-btn{margin-top:12px}
@media (max-width:600px){.aigen-mau{width:auto;max-width:none;margin:16px calc(-1 * var(--cm-space-lg)) 0}}
.aigen-xem-khach{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;margin:0 0 12px;padding:10px 14px;border:1px dashed var(--ais-accent2);border-radius:10px;background:rgba(168,85,247,.10);color:var(--cm-text-secondary);font-size:13px;line-height:1.5}
.aigen-xem-khach .fa-eye{color:var(--ais-accent2)}
.aigen-xem-khach span{flex:1 1 260px;min-width:0}
.aigen-xem-khach a{color:var(--ais-accent2);font-weight:600;white-space:nowrap}
.aigen-nhung .aigen-top{justify-content:flex-end}
.aigen-voice-mien{display:inline-block;margin-left:6px;padding:0 7px;border-radius:999px;font-size:10.5px;font-weight:600;line-height:17px;color:var(--ais-accent4,#d8b4fe);background:rgba(168,85,247,.12);vertical-align:1px;white-space:nowrap}
.aigen-mau-nghe{display:flex;flex-direction:column;gap:12px;padding:14px;border:1px solid var(--cm-border,rgba(148,163,184,.25));border-radius:12px;background:rgba(148,163,184,.06)}
.aigen-mau-vb{font-size:13px;line-height:1.65;color:var(--cm-text-primary);white-space:pre-line;padding-bottom:12px;border-bottom:1px solid var(--cm-border,rgba(148,163,184,.25))}
.aigen-mau-dong{display:flex;flex-direction:column;gap:6px;min-width:0}
.aigen-mau-nhan{font-size:12.5px;font-weight:600;line-height:1.4;color:var(--cm-text-primary)}
.aigen-mau-phu{margin-left:8px;font-weight:400;color:var(--cm-text-secondary)}
.aigen-mau-am{display:block;width:100%;height:40px}
.aigen-mau-phim{display:block;width:100%;aspect-ratio:16/9;border-radius:10px;background:#000;object-fit:contain}
.aigen-mau-ds{display:flex;flex-direction:column;gap:12px;min-width:0}
.aigen-mau-nghe.doc .aigen-mau-ds{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;align-items:end}
.aigen-mau-nghe.doc .aigen-mau-phim{aspect-ratio:9/16;max-height:520px}
.aigen-mau-nghe.doc .aigen-mau-phu{display:block;margin-left:0}
