/* =====================================================================
   PHÒNG THỬ VÁY AI – GIAO DIỆN TRÒ CHUYỆN (tryon.html)
   1. Khung trang   2. Tin nhắn   3. Ảnh ướm thử   4. Khung soạn tin   5. Tấm chọn   6. Điện thoại
   ===================================================================== */

/* ---------- 1. KHUNG TRANG ---------- */
/* Trang dạng ứng dụng: khung soạn tin dính đáy, không cần footer bên dưới */
.page-chat #app-footer { display: none; }

.chat { width: min(800px, 100%); margin: 0 auto; padding: 18px 16px 0; flex: 1 0 auto; display: flex; flex-direction: column; }
/* Thanh tiêu đề dính ngay dưới header khi cuộn (--header-h đo bằng JS trong tryon.js) */
.chat-top { position: sticky; top: calc(var(--header-h, 64px) + env(safe-area-inset-top, 0px)); z-index: 15; display: flex; align-items: center; gap: 12px;
  margin-top: -18px; padding: 14px 0; border-bottom: 1px solid var(--line); background: var(--bg); }
.chat-top-logo { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: #fff; }
.chat-top-text { flex: 1; min-width: 0; }
.chat-top h1 { margin: 0; font-size: clamp(21px, 2.6vw, 26px); }
.chat-top p { margin: 2px 0 0; font-size: 13.5px; color: var(--muted); }
.chat-top-link { flex: none; }

.chat-thread { flex: 1; display: flex; flex-direction: column; gap: 20px; padding: 22px 0 18px; }
.chat-history { display: flex; flex-direction: column; gap: 20px; padding-bottom: 20px; border-bottom: 1px dashed var(--line); }
.chat-loading { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.history-more { align-self: center; padding: 7px 16px; border: 1px solid var(--line); border-radius: 999px; background: var(--card);
  color: var(--brand-dark); font: 600 13px var(--font-body); cursor: pointer; }
.history-more:hover { border-color: var(--brand); }

/* ---------- 2. TIN NHẮN ---------- */
.msg-row { display: flex; gap: 10px; align-items: flex-start; animation: msg-in .25s ease-out; }
.msg-row.user { justify-content: flex-end; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-avatar { flex: none; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--line); background: #fff; }
.msg-body { flex: 1; min-width: 0; max-width: 640px; display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.msg-row.user .msg-body { flex: 0 1 auto; max-width: min(80%, 520px); align-items: flex-end; }
.msg-text { margin: 0; line-height: 1.6; }
.msg-bubble { margin: 0; padding: 10px 14px; border-radius: 18px 18px 6px 18px; background: var(--brand); color: #fff;
  line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
.msg-time { font-size: 11.5px; color: var(--muted); }
.msg-attachments { display: flex; gap: 8px; }
.msg-attachments figure { margin: 0; width: 86px; display: flex; flex-direction: column; gap: 4px; }
.msg-attachments img, .msg-attachments .ph { width: 86px; height: 112px; border-radius: 12px; border: 1px solid var(--line);
  object-fit: cover; object-position: top; background: var(--brand-soft); }
.msg-attachments .ph { display: grid; place-items: center; font-size: 26px; }
.msg-attachments figcaption { font-size: 11.5px; color: var(--muted); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Trợ lý đang trả lời: 3 chấm nhún */
.typing { display: inline-flex; gap: 4px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--brand-light); animation: typing 1.1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-4px); opacity: 1; } }
.chat-loading .typing { padding: 8px 10px; }

/* Lời chào: 3 bước */
.chat-steps { list-style: none; width: 100%; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.chat-steps li { display: flex; flex-direction: column; gap: 2px; padding: 12px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); font-size: 13.5px; }
.chat-steps li span { font-size: 22px; line-height: 1.3; }
.chat-steps li small { font-size: 12px; line-height: 1.35; color: var(--muted); }

/* Nút gợi ý dưới tin nhắn */
.suggest-row { display: flex; flex-wrap: wrap; gap: 8px; }
.suggest { padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); color: var(--ink);
  font: 600 13.5px var(--font-body); cursor: pointer; transition: border-color .15s, background .15s; }
.suggest:hover { border-color: var(--brand); background: #fffaf8; }
.suggest.primary { border-color: var(--brand); background: var(--brand); color: #fff; }
.suggest.primary:hover { background: var(--brand-dark); }

/* Thẻ mẫu váy (mở từ "Thử váy này") */
.dress-card { width: 100%; display: flex; gap: 14px; padding: 12px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); box-shadow: var(--shadow); }
.dress-card-photo { position: relative; flex: none; width: 112px; }
.dress-card-photo img { width: 100%; aspect-ratio: 3 / 4; border-radius: 12px; object-fit: cover; background: var(--brand-soft); }
.dress-card-tag { position: absolute; left: 6px; bottom: 6px; padding: 2px 8px; border-radius: 999px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 11px; font-weight: 600; }
.dress-card-info { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.dress-card-name { font-size: 15.5px; line-height: 1.35; }
.dress-card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.fit-line { margin: 0; color: var(--muted); line-height: 1.5; }
.fit-line strong { color: var(--brand-dark); }

/* Mẫu gợi ý theo kiểu váy trợ lý tư vấn */
.suggest-dresses { width: 100%; display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 6px; scroll-snap-type: x mandatory; }
.mini-dress { flex: none; width: 128px; display: flex; flex-direction: column; gap: 3px; padding: 6px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--card); color: inherit; font: inherit; text-align: left; cursor: pointer; scroll-snap-align: start; }
.mini-dress:hover { border-color: var(--brand); }
.mini-dress img { width: 100%; aspect-ratio: 3 / 4; border-radius: 10px; object-fit: cover; }
.mini-name { font-size: 12.5px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mini-price { font-size: 12px; font-weight: 700; color: var(--brand-dark); }

/* ---------- 3. ẢNH ƯỚM THỬ ---------- */
.gen { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.gen-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.gen-tag { font-size: 14px; font-weight: 700; }
.gen-meta { padding: 2px 10px; border-radius: 999px; background: var(--brand-soft); font-size: 12.5px; color: var(--muted); }
/* Khung theo đúng tỷ lệ ảnh (--ratio đặt bằng JS khi ảnh tải xong), không cao quá ~68% màn hình */
.gen-frame { --ratio: .75; --split: 50%; position: relative; overflow: hidden; width: min(100%, 460px, calc(68vh * var(--ratio)));
  aspect-ratio: var(--ratio); border-radius: 18px; background: #efe5dd; box-shadow: 0 10px 30px rgba(42, 36, 33, .14); }
.gen-frame > img { width: 100%; height: 100%; object-fit: cover; }
.gen-zoom { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: rgba(20, 15, 12, .55); color: #fff; font-size: 18px; cursor: pointer; backdrop-filter: blur(4px); }
.gen-zoom:hover { background: rgba(20, 15, 12, .75); }
.gen-thumbs { display: flex; gap: 8px; }
.gen-thumbs button { position: relative; width: 58px; height: 76px; padding: 0; border: 2px solid transparent; border-radius: 10px; overflow: hidden; background: none; cursor: pointer; }
.gen-thumbs button.active { border-color: var(--brand); }
.gen-thumbs img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.gen-thumbs span { position: absolute; left: 4px; bottom: 4px; min-width: 18px; padding: 0 4px; border-radius: 999px;
  background: rgba(0, 0, 0, .65); color: #fff; font: 700 11px/18px var(--font-body); text-align: center; }
.gen-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* So sánh trước/sau: ảnh gốc phủ lên, cắt theo --split; đường chia trắng; thanh kéo ở đáy */
.gen-compare { position: absolute; inset: 0; pointer-events: none; }
.gen-compare img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; clip-path: inset(0 calc(100% - var(--split)) 0 0); }
.gen-compare::after { content: ''; position: absolute; top: 0; bottom: 0; left: var(--split); width: 2px; margin-left: -1px; background: #fff; box-shadow: 0 0 8px rgba(0, 0, 0, .5); }
.gen-side { position: absolute; bottom: 46px; padding: 3px 10px; border-radius: 999px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 12px; font-weight: 600; }
.gen-side.before { left: 12px; }
.gen-side.after { right: 12px; }
.gen-frame .gen-range { position: absolute; left: 14px; bottom: 14px; width: calc(100% - 28px); margin: 0; cursor: ew-resize; }

/* Đang ướm: ảnh của bạn làm mờ + vệt sáng quét + thanh tiến độ */
.gen-pending .gen-frame > .gen-ghost { filter: blur(14px) saturate(.7); transform: scale(1.08); opacity: .8; }
.gen-wait { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 20px; background: rgba(40, 24, 20, .3); color: #fff; font-weight: 600; text-align: center; text-shadow: 0 1px 4px rgba(0, 0, 0, .4); }
.gen-pending .gen-frame::after { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 30%;
  background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, .28), transparent); animation: gen-scan 2.2s linear infinite; }
@keyframes gen-scan { from { transform: translateY(-100%); } to { transform: translateY(340%); } }
.gen-progress { position: absolute; left: 14px; right: 14px; bottom: 14px; height: 5px; border-radius: 999px; background: rgba(255, 255, 255, .3); overflow: hidden; }
.gen-progress span { display: block; width: 94%; height: 100%; border-radius: inherit; background: #fff; transform-origin: left;
  animation: gen-progress var(--eta, 40s) cubic-bezier(.15, .7, .3, 1) forwards; }
@keyframes gen-progress { from { transform: scaleX(.03); } to { transform: scaleX(1); } }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .35); border-top-color: #fff; animation: spin .8s linear infinite; }

/* ---------- 4. KHUNG SOẠN TIN ---------- */
.composer { position: sticky; bottom: 0; z-index: 20; margin-top: auto; padding: 8px 0 16px;
  background: linear-gradient(to top, var(--bg) 78%, rgba(250, 245, 239, 0)); }
.composer-box { display: flex; flex-direction: column; gap: 6px; padding: 10px 10px 8px; border: 1px solid var(--line); border-radius: 22px;
  background: var(--card); box-shadow: 0 10px 34px rgba(42, 36, 33, .12); transition: border-color .15s, box-shadow .15s; }
.composer-box:focus-within { border-color: #dcc3b6; box-shadow: 0 10px 34px rgba(42, 36, 33, .14), 0 0 0 3px var(--brand-soft); }
.composer-slots { display: flex; gap: 8px; }
.slot-wrap { position: relative; flex: 1 1 0; min-width: 0; max-width: 270px; }
.slot { width: 100%; min-height: 56px; display: flex; align-items: center; gap: 10px; padding: 6px 30px 6px 6px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--bg); color: inherit; font: inherit; text-align: left; cursor: pointer; }
.slot:hover { border-color: var(--brand); }
.slot img, .slot-plus { flex: none; width: 40px; height: 44px; border-radius: 9px; }
.slot img { object-fit: cover; object-position: top; }
.slot.empty { padding-right: 10px; border-style: dashed; border-color: #d9c2b5; background: transparent; }
.slot-plus { display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-dark); font-size: 20px; }
.slot-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.slot-text strong { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-text small { font-size: 11.5px; color: var(--muted); }
.slot.uploading img { opacity: .45; }
.slot.uploading strong { color: var(--muted); }
.slot.nudge { border-color: var(--brand); animation: shake .45s; }
.slot-clear { position: absolute; top: 50%; right: 5px; width: 24px; height: 24px; margin-top: -12px; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; }
.slot-clear:hover { background: var(--brand-soft); color: var(--brand-dark); }
.composer textarea { width: 100%; max-height: 140px; padding: 6px 4px; border: 0; outline: 0; resize: none; background: transparent;
  color: var(--ink); font: 15px/1.5 var(--font-body); }
.composer-bar { display: flex; align-items: center; gap: 8px; }
.composer-settings { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--ink); font: 600 12.5px var(--font-body); cursor: pointer; white-space: nowrap; }
.composer-settings:hover { border-color: var(--brand); }
.composer-cost { margin-left: auto; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.composer-cost.short { color: var(--red); font-weight: 600; }
.composer-send { flex: none; width: 42px; height: 42px; display: grid; place-items: center; border: 0; border-radius: 50%;
  background: var(--brand); color: #fff; cursor: pointer; transition: background .15s, transform .15s; }
.composer-send:hover:not(:disabled) { background: var(--brand-dark); transform: scale(1.05); }
.composer-send:disabled { background: #d9c7bd; cursor: default; }

/* ---------- 5. TẤM CHỌN (ảnh, váy, tùy chỉnh) ---------- */
.upload-tile { display: flex; align-items: center; gap: 12px; padding: 14px; border: 1.5px dashed #d9c2b5; border-radius: 16px;
  background: var(--bg); color: inherit; cursor: pointer; }
.upload-tile:hover { border-color: var(--brand); text-decoration: none; }
.upload-icon { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 50%; background: var(--brand-soft); font-size: 22px; }
.upload-text { display: flex; flex-direction: column; }
.upload-text small { font-size: 12.5px; color: var(--muted); }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.pick-grid.dresses { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.pick-tile { position: relative; }
.pick-main { width: 100%; display: flex; flex-direction: column; gap: 3px; padding: 5px; border: 2px solid transparent; border-radius: 14px;
  background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; transition: background .18s var(--ease-out), border-color .18s var(--ease-out), transform .15s var(--ease-out); }
.pick-main:hover { background: var(--bg); }
.pick-main:active { transform: scale(.98); }
.pick-tile.active .pick-main { border-color: var(--brand); background: #fffaf8; }
.pick-thumb-wrap { position: relative; width: 100%; border-radius: 10px; overflow: hidden; background: var(--brand-soft); }
.pick-main img { width: 100%; aspect-ratio: 3 / 4; border-radius: 10px; object-fit: cover; object-position: top; background: var(--brand-soft); }
.pick-badge {
  position: absolute; top: 6px; padding: 2px 7px; border-radius: 999px;
  font: 700 10.5px/1.3 var(--font-body); letter-spacing: .01em; pointer-events: none;
  box-shadow: 0 2px 6px rgba(42, 36, 33, .18);
}
.pick-badge.hot {
  left: 6px; background: linear-gradient(135deg, var(--brand-light), var(--brand-dark));
  color: #ffe9ad; border: 1px solid rgba(255, 232, 163, .55);
}
.pick-badge.sale { right: 6px; background: var(--red); color: #fff; }
.pick-badge.bespoke { right: 6px; background: var(--purple-soft); color: var(--purple); border: 1px solid #d8c6f0; }
.pick-fit {
  position: absolute; left: 6px; bottom: 6px; padding: 2px 7px; border-radius: 999px;
  background: rgba(34, 26, 22, .68); backdrop-filter: blur(4px);
  color: #fff8e7; font: 600 10.5px/1.3 var(--font-body); font-variant-numeric: tabular-nums; pointer-events: none;
}
.pick-name { font-size: 12.5px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pick-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-price-row { display: flex; align-items: baseline; gap: 5px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.pick-price { font-size: 12.5px; font-weight: 700; color: var(--brand-dark); font-variant-numeric: tabular-nums; }
.pick-old-price { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pick-remove { position: absolute; top: -2px; right: -2px; width: 26px; height: 26px; border: 1px solid var(--line); border-radius: 50%;
  background: var(--card); color: var(--red); font: 700 15px/1 var(--font-body); cursor: pointer; box-shadow: var(--shadow); }
.pick-remove:hover { background: var(--red-soft); }
.sheet-tabs { flex: none; width: 100%; }
.sheet-tabs .tab { flex: 1; }
.dress-toolbar { display: flex; gap: 8px; flex: none; align-items: center; }
.dress-toolbar .dress-search { flex: 1 1 180px; min-width: 0; padding: 8px 12px; font-size: 14px; border-radius: 999px; background: var(--bg); }
.dress-toolbar .dress-range { flex: 0 0 auto; width: auto; max-width: 165px; padding: 8px 10px; font-size: 13.5px; font-weight: 600; border-radius: 999px; background: var(--bg); cursor: pointer; }
.sheet-filter { flex: none; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.sheet-filter .chip { flex: none; display: inline-flex; align-items: center; gap: 5px; }
.sheet-filter .chip-trend:not(.active) { background: linear-gradient(135deg, #fffdf9, var(--gold-soft, #fcf4df)); border-color: var(--gold-line, #e4cfa3); color: var(--ink); }
.chip-count {
  display: inline-block; padding: 0 5px; border-radius: 999px;
  background: rgba(42, 36, 33, .08); color: var(--muted);
  font-size: 11px; font-weight: 700; line-height: 1.45; font-variant-numeric: tabular-nums;
}
.chip.active .chip-count { background: rgba(155, 35, 53, .16); color: var(--brand-dark); }
.dress-empty { padding: 24px 16px; }

.settings-sheet .opts, .settings-sheet .measure { display: flex; flex-direction: column; gap: 14px; }
.settings-sheet .measure { padding-top: 14px; border-top: 1px solid var(--line); }
.opt-group { display: flex; flex-direction: column; gap: 6px; }
.opt-note { font-size: 12px; color: var(--muted); }
.opt-check { display: flex; align-items: flex-start; gap: 8px; font-size: 13.5px; cursor: pointer; }
.opt-check input { margin-top: 3px; accent-color: var(--brand); }
.opt-check small { color: var(--muted); }
.opt-total { margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--brand-soft); font-size: 13.5px; }

/* ---------- 6. ĐIỆN THOẠI ---------- */
@media (max-width: 900px) {
  /* Khung soạn tin nằm ngay trên thanh tab dưới đáy */
  .composer { bottom: calc(58px + env(safe-area-inset-bottom, 0px)); padding-bottom: 8px; }
}
@media (max-width: 560px) {
  .chat { padding: 12px 12px 0; }
  .chat-top { gap: 10px; margin-top: -12px; padding: 10px 0; }
  .chat-top-logo, .chat-top p { display: none; }
  .chat-top-link { padding: 6px 10px; font-size: 12.5px; }
  .chat-thread { gap: 16px; padding-top: 16px; }
  .chat-steps { grid-template-columns: minmax(0, 1fr); }
  .chat-steps li { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; padding: 10px 12px; }
  .chat-steps li span { grid-row: span 2; }
  .msg-avatar { width: 28px; height: 28px; }
  .msg-row.user .msg-body { max-width: 86%; }
  .dress-card-photo { width: 92px; }
  .composer-box { padding: 8px; border-radius: 18px; }
  .slot { min-height: 50px; gap: 8px; }
  .slot img, .slot-plus { width: 34px; height: 40px; }
  .composer-cost { font-size: 11.5px; }
  .pick-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pick-grid.dresses { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .dress-toolbar { flex-direction: column; align-items: stretch; gap: 6px; }
  .dress-toolbar .dress-search, .dress-toolbar .dress-range { width: 100%; max-width: 100%; flex: none; font-size: 16px; padding: 9px 12px; }
  .sheet-filter { scrollbar-width: none; -webkit-overflow-scrolling: touch; margin-inline: -4px; padding-inline: 4px; }
  .sheet-filter::-webkit-scrollbar { display: none; }
  .pick-badge, .pick-fit { font-size: 10px; padding: 2px 6px; }
}
@media (prefers-reduced-motion: reduce) {
  .msg-row, .typing i, .gen-pending .gen-frame::after, .gen-progress span, .spinner { animation: none !important; }
}
