/* ==========================================================================
   hero-demo.css — khung Telegram (dark) ở hero: cột trợ lý + khung chat tự chạy
   Nội dung/kịch bản nằm trong js/hero-demo.js (AGENTS). Cột .hero__visual là container (sections.css)
   nên bố cục tự đổi theo BỀ RỘNG CỘT chứ không theo viewport.
   ========================================================================== */

.tg-wrap { position: relative; padding-top: 58px; }

.tg {
  --tg-bar: #17212b;
  --tg-list: #17212b;
  --tg-hover: #202b36;
  --tg-active: #2b5278;
  --tg-chat: #0e1621;
  --tg-in: #182533;
  --tg-out: #2b5278;
  --tg-text: #e9eff5;
  --tg-muted: #8b9db0;          /* ≥5:1 trên #17212b / #182533 */
  --tg-line: rgba(255, 255, 255, 0.07);
  --tg-link: #7fbdf7;
  --tg-ok: #6fdc9b;
  --tg-badge: #1f6fd0;          /* chữ trắng ≈5.3:1 */

  width: 100%; max-width: 680px; margin-inline: auto; overflow: hidden;
  border-radius: 18px; background: var(--tg-chat); color: var(--tg-text);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 28px 70px rgba(6, 18, 48, 0.42), 0 0 0 1px rgba(9, 53, 160, 0.08);
  font-size: 13.5px; line-height: 1.45;
}
.tg .icon { width: 18px; height: 18px; stroke-width: 1.9; }

/* ---- Thanh tiêu đề ---- */
.tg__bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--tg-bar); border-bottom: 1px solid var(--tg-line); }
.tg__dots { display: flex; gap: 7px; flex: none; }
.tg__dots i { width: 11px; height: 11px; border-radius: 50%; background: #ff5f57; }
.tg__dots i:nth-child(2) { background: #febc2e; }
.tg__dots i:nth-child(3) { background: #28c840; }
.tg__title { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; font-weight: 600; color: #c7d3df; }
.tg__tag { flex: none; padding: 2px 9px; border-radius: 999px; background: rgba(255, 255, 255, 0.09); color: #c7d3df; font-size: 11px; font-weight: 600; }
.tg__toggle { flex: none; width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: #c7d3df; transition: background-color var(--duration-fast); }
.tg__toggle:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.tg__toggle .icon { width: 15px; height: 15px; fill: currentColor; stroke-width: 1.6; grid-area: 1 / 1; }
.tg__toggle .icon--play { display: none; }
.tg__toggle[aria-pressed="true"] .icon--play { display: block; }
.tg__toggle[aria-pressed="true"] .icon--pause { display: none; }
.tg :focus-visible { outline-color: #7fbdf7; }

/* ---- Thân: cột trợ lý + chat (chiều cao cố định → không nhảy layout khi tin nhắn chạy) ---- */
.tg__body { display: grid; grid-template-columns: minmax(200px, 34%) minmax(0, 1fr); height: 500px; }
.tg__side { display: flex; flex-direction: column; min-width: 0; background: var(--tg-list); border-right: 1px solid var(--tg-line); }
.tg__search { display: flex; align-items: center; gap: 8px; margin: 10px 10px 6px; padding: 8px 12px; border-radius: 20px; background: rgba(255, 255, 255, 0.06); color: var(--tg-muted); font-size: 12.5px; }
.tg__search .icon { width: 15px; height: 15px; }
.tg__list { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; scrollbar-width: none; }
.tg__list::-webkit-scrollbar { display: none; }
.tg__hint { margin-top: auto; padding: 12px 14px 14px; font-size: 12px; color: var(--tg-muted); text-align: center; }

.tg-row {
  flex: none; display: flex; align-items: center; gap: 10px; width: 100%; height: 62px; padding: 0 12px; text-align: left; color: inherit;
  border-radius: 0; transition: background-color var(--duration-fast);
}
.tg-row:hover { background: var(--tg-hover); }
.tg-row.is-active { background: var(--tg-active); }
.tg-row:focus-visible { outline-offset: -3px; border-radius: 0; }
.tg-row__main { min-width: 0; flex: 1; display: grid; gap: 1px; }
.tg-row__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; font-weight: 600; color: #fff; }
.tg-row__prev { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--tg-muted); }
.tg-row.is-active .tg-row__prev { color: #cfdeed; }
.tg-row.is-working .tg-row__prev { color: var(--tg-link); }
.tg-row.is-active.is-working .tg-row__prev { color: #d9ebff; }
.tg-row.is-working .tg-row__prev::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: currentColor; vertical-align: 1px; animation: tg-pulse 1.1s ease-in-out infinite; }
/* Huy hiệu chờ duyệt: nằm ở góc avatar như chấm thông báo */
.tg-badge { position: absolute; left: 40px; top: 7px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: var(--tg-badge); color: #fff; font-size: 11px; font-weight: 700; line-height: 19px; text-align: center; box-shadow: 0 0 0 2px var(--tg-list); }
.tg-row.is-active .tg-badge { box-shadow: 0 0 0 2px var(--tg-active); }
.tg-row { position: relative; }
.tg-badge[hidden] { display: none; }

/* Avatar trợ lý (SVG icon trên nền gradient) */
.tg-av { flex: none; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, #1553e0, #38a3f5); }
.tg-av .icon { width: 20px; height: 20px; }
.tg-av[data-av="opc"] { background: linear-gradient(135deg, #0b4fe0, #6d4ce6); }
.tg-av[data-av="writer"] { background: linear-gradient(135deg, #1553e0, #38a3f5); }
.tg-av[data-av="image"] { background: linear-gradient(135deg, #d9540f, #f5a524); }
.tg-av[data-av="video"] { background: linear-gradient(135deg, #7b3fe4, #c04bdc); }
.tg-av[data-av="editor"] { background: linear-gradient(135deg, #0f9488, #3fd0a0); }
.tg-av[data-av="report"] { background: linear-gradient(135deg, #d98e04, #f5c542); }

/* ---- Chat ---- */
.tg__chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--tg-chat); }
.tg__head { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--tg-bar); border-bottom: 1px solid var(--tg-line); }
.tg__head .tg-av { width: 36px; height: 36px; }
.tg__head .tg-av .icon { width: 17px; height: 17px; }
.tg__head-txt { min-width: 0; display: grid; }
.tg__head-txt b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 600; color: #fff; }
.tg__head-txt span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--tg-muted); }
.tg__head-txt span.is-busy { color: var(--tg-link); }

.tg__msgs { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 6px; }
.tg__msgs::-webkit-scrollbar { display: none; }
.tg__msgs > :first-child { margin-top: auto; }   /* tin nhắn ít thì dồn xuống đáy như Telegram */

.tg-msg { max-width: 88%; padding: 7px 10px 6px; border-radius: 12px; background: var(--tg-in); border-bottom-left-radius: 4px; word-wrap: break-word; animation: tg-in 0.28s var(--ease-standard) both; }
.tg-msg--out { align-self: flex-end; background: var(--tg-out); border-radius: 12px; border-bottom-right-radius: 4px; }
.tg-msg--in { align-self: flex-start; }
.tg-msg__name { display: block; margin-bottom: 2px; font-size: 12.5px; font-weight: 700; }
.tg-msg__name[data-av="opc"] { color: #86b8ff; }
.tg-msg__name[data-av="writer"] { color: #7fc0f7; }
.tg-msg__name[data-av="image"] { color: #ffb47f; }
.tg-msg__name[data-av="video"] { color: #dba4ff; }
.tg-msg__name[data-av="editor"] { color: #72e6c5; }
.tg-msg__name[data-av="report"] { color: #ffd36e; }
.tg-msg p + p { margin-top: 3px; }
.tg-msg b { font-weight: 700; }
.tg-msg__time { display: flex; justify-content: flex-end; align-items: center; gap: 3px; margin-top: 2px; font-size: 11px; color: #8fa5ba; }
.tg-msg--out .tg-msg__time { color: #a9c6e3; }
.tg-msg__time .icon { width: 14px; height: 14px; stroke-width: 2.2; color: #7fbdf7; }
@keyframes tg-in { from { opacity: 0; transform: translateY(8px); } }

/* Đang gõ */
.tg-typing { display: inline-flex; gap: 4px; align-items: center; padding: 11px 13px; }
.tg-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--tg-link); opacity: 0.4; animation: tg-blink 1.2s infinite; }
.tg-typing i:nth-child(2) { animation-delay: 0.18s; }
.tg-typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes tg-blink { 0%, 60%, 100% { opacity: 0.35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes tg-pulse { 50% { opacity: 0.35; } }

/* Checklist tiến độ */
.tg-steps { display: grid; gap: 5px; margin: 2px 0 1px; }
.tg-steps li { display: flex; align-items: center; gap: 8px; }
.tg-steps .tg-step__ico { flex: none; width: 15px; height: 15px; display: grid; place-items: center; }
.tg-steps .tg-step__ico .icon { width: 15px; height: 15px; stroke-width: 2.6; color: var(--tg-ok); display: none; }
.tg-steps li.is-run .tg-step__ico::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 2px solid rgba(127, 189, 247, 0.35); border-top-color: var(--tg-link); animation: tg-spin 0.8s linear infinite; }
.tg-steps li.is-done .tg-step__ico .icon { display: block; }
.tg-steps li.is-run { color: #c4d4e4; }
@keyframes tg-spin { to { transform: rotate(360deg); } }

/* Thẻ giao việc của OPC */
.tg-deleg { display: grid; gap: 6px; margin: 4px 0 2px; min-width: 250px; }
.tg-deleg__row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 9px; background: rgba(255, 255, 255, 0.05); }
.tg-deleg__row .tg-av { width: 26px; height: 26px; }
.tg-deleg__row .tg-av .icon { width: 13px; height: 13px; }
.tg-deleg__txt { min-width: 0; flex: 1; display: grid; line-height: 1.3; }
.tg-deleg__txt b { font-size: 12.5px; color: var(--tg-link); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-deleg__txt span { font-size: 12px; color: var(--tg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-chip { flex: none; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: rgba(255, 255, 255, 0.09); color: #b9c8d8; white-space: nowrap; }
.tg-chip[data-s="run"] { background: rgba(127, 189, 247, 0.16); color: var(--tg-link); }
.tg-chip[data-s="done"] { background: rgba(111, 220, 155, 0.16); color: var(--tg-ok); }

/* Thẻ file + thumbnail tài liệu (không phóng to) */
.tg-file { display: flex; align-items: center; gap: 10px; margin: 2px 0 6px; }
.tg-file__ico { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: #3e8fd6; color: #fff; }
.tg-file__ico .icon { width: 19px; height: 19px; }
.tg-file__txt { min-width: 0; display: grid; }
.tg-file__txt b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.tg-file__txt span { font-size: 12px; color: var(--tg-muted); }
.tg-thumb { width: 290px; max-width: 100%; margin: 0 0 6px; border-radius: 8px; overflow: hidden; background: #fff; }
.tg-thumb img { width: 100%; height: 132px; object-fit: cover; object-position: top left; }
.tg-thumb--sheet img { height: 118px; }

/* Album ảnh (bấm để phóng to) */
.tg-album { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; width: 300px; max-width: 100%; margin: 2px 0 5px; border-radius: 9px; overflow: hidden; }
.tg-photo { display: block; aspect-ratio: 1; padding: 0; overflow: hidden; cursor: zoom-in; }
.tg-photo img { width: 100%; height: 100%; object-fit: cover; transition: transform 0.4s var(--ease-standard); }
.tg-photo:hover img { transform: scale(1.05); }

/* Video dọc tự phát câm */
.tg-video { position: relative; width: 158px; aspect-ratio: 9 / 16; margin: 2px 0 5px; border-radius: 10px; overflow: hidden; background: #000; }
.tg-video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tg-video__play { position: absolute; inset: 0; margin: auto; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(0, 0, 0, 0.55); color: #fff; transition: opacity var(--duration-fast); }
.tg-video__play .icon { width: 20px; height: 20px; fill: currentColor; margin-left: 2px; }
.tg-video.is-playing .tg-video__play { opacity: 0; pointer-events: none; }
.tg-video__len { position: absolute; left: 7px; top: 7px; padding: 1px 7px; border-radius: 999px; background: rgba(0, 0, 0, 0.55); font-size: 11px; color: #fff; }

/* So sánh trước → sau */
.tg-diff { display: grid; gap: 6px; margin: 3px 0; }
.tg-diff__row { padding: 6px 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.05); display: grid; gap: 3px; }
.tg-diff del { color: #ff9a94; text-decoration-thickness: 1.5px; }
.tg-diff ins { text-decoration: none; color: #a9f0c4; background: rgba(111, 220, 155, 0.12); border-radius: 3px; padding: 0 2px; }
.tg-diff__why { font-size: 11.5px; color: var(--tg-muted); }

/* Nút inline (bước nhân sự duyệt) */
.tg-btns { align-self: flex-start; width: min(88%, 320px); display: flex; gap: 4px; margin-top: -2px; animation: tg-in 0.28s var(--ease-standard) both; }
.tg-btn { flex: 1 1 0; min-width: 0; padding: 8px 8px; border-radius: 8px; background: rgba(38, 66, 96, 0.9); color: #d7e8fa; font-size: 12.5px; font-weight: 600; text-align: center; transition: background-color var(--duration-fast), transform var(--duration-fast); }
.tg-btn:hover:not(:disabled) { background: rgba(52, 88, 128, 0.95); }
.tg-btn--ok { background: #1f6fd0; color: #fff; }
.tg-btn--ok:hover:not(:disabled) { background: #2a7fe6; }
.tg-btn.is-pressed { transform: scale(0.96); background: #3d8ff0; }
.tg-btn:disabled { cursor: default; }
.tg-btn.is-done { background: rgba(111, 220, 155, 0.16); color: var(--tg-ok); }
.tg-sys { align-self: center; max-width: 92%; padding: 3px 12px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); color: #b9c8d8; font-size: 12px; text-align: center; animation: tg-in 0.28s var(--ease-standard) both; }

/* Ô nhập */
.tg__composer { flex: none; display: flex; align-items: center; gap: 10px; margin: 6px 10px 10px; padding: 7px 8px 7px 12px; border-radius: 22px; background: var(--tg-in); color: var(--tg-muted); }
.tg__composer .icon { width: 18px; height: 18px; }
.tg__input { flex: 1; min-width: 0; height: 20px; overflow: hidden; white-space: nowrap; text-overflow: clip; font-size: 13px; color: var(--tg-text); }   /* JS cuộn để luôn thấy chữ vừa gõ */
.tg__input:empty::before { content: attr(data-placeholder); color: var(--tg-muted); }
.tg__input.is-typing::after { content: ""; display: inline-block; width: 1.5px; height: 14px; margin-left: 1px; background: var(--tg-link); vertical-align: -2px; animation: tg-caret 0.9s steps(1) infinite; }
@keyframes tg-caret { 50% { opacity: 0; } }
.tg__send { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: #2a7fe6; color: #fff; }
.tg__send .icon { width: 15px; height: 15px; }
.tg__noscript { margin-top: 12px; font-size: 13px; color: var(--viai-muted-strong); text-align: center; }

/* Phóng to ảnh */
.tg-lb { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 24px; background: rgba(5, 10, 20, 0.88); cursor: zoom-out; }
.tg-lb img { max-width: min(92vw, 900px); max-height: 88vh; border-radius: 12px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5); }
.tg-lb__close { position: absolute; top: 16px; right: 18px; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, 0.14); color: #fff; }
.tg-lb__close:hover { background: rgba(255, 255, 255, 0.24); }

/* ==========================================================================
   Cột visual hẹp (< 560px): danh sách trợ lý thành hàng ngang phía trên, chat bên dưới
   ========================================================================== */
@container (max-width: 559px) {
  .tg { font-size: 13px; border-radius: 16px; }
  .tg__body { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: 540px; }
  .tg__side { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--tg-line); }
  .tg__search, .tg__hint { display: none; }
  .tg__list { flex: 1 1 auto; min-width: 0; }
  .tg__list { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 8px 6px 6px; gap: 2px; }
  .tg-row { flex: 0 0 76px; height: auto; flex-direction: column; justify-content: flex-start; gap: 5px; padding: 6px 4px; border-radius: 12px; text-align: center; }
  .tg-row:focus-visible { border-radius: 12px; outline-offset: -2px; }
  .tg-row__prev { display: none; }
  .tg-row__main { flex: none; }
  .tg-row__name { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 11.5px; line-height: 1.25; height: 2.5em; }
  .tg-badge { left: auto; right: 10px; top: 3px; }
  .tg-row.is-working .tg-av { box-shadow: 0 0 0 2px var(--tg-list), 0 0 0 4px #7fbdf7; }
  .tg-msg { max-width: 92%; }
  .tg-btns { width: 92%; }
  .tg-deleg { min-width: 0; }
  .tg-video { width: 138px; }
}

/* Giảm chuyển động (class .reduce-motion do công tắc ở <head> index.html bật) */
.reduce-motion .tg-msg, .reduce-motion .tg-btns, .reduce-motion .tg-sys { animation: none; }
.reduce-motion .tg-typing i, .reduce-motion .tg-row.is-working .tg-row__prev::before, .reduce-motion .tg__input.is-typing::after { animation: none; opacity: 1; }
.reduce-motion .tg-steps li.is-run .tg-step__ico::before { animation: none; }
.reduce-motion .tg-photo:hover img { transform: none; }
