/* ============================================================
   AI: Tạo nội dung thiệp — style cho modal (openBottomSheet)
   Tách khỏi index.html cho gọn. Xem thêm ai-modal.js.
   ============================================================ */

/* Thẻ Soft "Tạo với AI" — thẻ glassmorphism nổi góc dưới-phải, hiển thị ở CẢ PC
   lẫn mobile (không còn banner PC riêng). Bấm X → thu về nút tròn nhỏ. */
.ai-fab {
  position: fixed;
  right: 1rem;
  touch-action: none; /* kéo bằng cảm ứng không làm cuộn trang */
  /* Luôn cách mép trên thanh điều hướng dưới cùng 16px. Giá trị --ai-fab-bottom
     do JS cập nhật theo chiều cao thực của navbar (kể cả khi có Local Draft
     Notice). Fallback ~ chiều cao navbar mặc định + 16px khi JS chưa chạy. */
  bottom: var(--ai-fab-bottom, calc(60px + 24px));
  z-index: 45;
}

/* Thẻ mời kiểu "glassmorphism" (theo bongbong.html): nền trắng mờ + blur, bo góc
   lớn, icon vuông gradient tím→xanh, tiêu đề + mô tả + nút CTA tối. Vào mượt bằng
   trượt lên + hiện dần. Bấm cả thẻ (hoặc nút CTA) → mở popup AI. */
.ai-card {
  position: relative;
  width: 12rem;
  padding: 1.125rem;
  border-radius: 1.5rem;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.14);
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  animation: ai-card-in 0.5s ease-out both;
}
@keyframes ai-card-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.ai-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.18);
}

/* Icon vuông bo góc, gradient tím→xanh + đổ bóng tím (giống .ai-icon reference). */
.ai-icon {
  width: 3.25rem;
  height: 3.25rem;
  margin: 0 auto;
  border-radius: 1.125rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #cbb9f5, #81b1ff);
  box-shadow: 0 10px 25px rgba(99, 102, 241, 0.3);
}
.ai-icon svg {
  width: 24px;
  height: 24px;
  color: #fff;
}

.ai-title {
  margin-top: 0.875rem;
  text-align: center;
  font-size: 0.9375rem;
  font-weight: 700;
  color: #1f2937;
}
.ai-desc {
  margin-top: 0.5rem;
  text-align: center;
  font-size: 0.8125rem;
  color: #6b7280;
  line-height: 1.5;
}
.ai-card-btn {
  margin-top: 0.875rem;
  width: 100%;
  height: 2.5rem;
  border: none;
  border-radius: 0.75rem;
  background: #111827;
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.25s ease;
}
.ai-card-btn:hover {
  background: #000;
}

/* Nút "x" đóng thẻ mời — tròn nhỏ ở góc trên-phải trong thẻ. Bấm → thu thẻ về
   nút tròn nhỏ (.ai-mini) để mobile vẫn còn lối vào AI. */
.ai-fab-close {
  position: absolute;
  top: 0.625rem;
  right: 0.625rem;
  width: 22px;
  height: 22px;
  border-radius: 9999px;
  background: rgba(243, 244, 246, 0.9);
  border: none;
  color: #9ca3af;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
  z-index: 1;
}
.ai-fab-close:hover {
  color: #4b5563;
  background: #e5e7eb;
}
.ai-fab-close svg {
  width: 13px;
  height: 13px;
}

/* Nút thu gọn: nút tròn gradient tím→xanh + icon ✨ trắng (khớp .ai-icon). */
.ai-mini {
  position: relative;
  width: 3.25rem;
  height: 3.25rem;
  border: none;
  padding: 0;
  border-radius: 9999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Lớp 1: dải sáng nghiêng lướt qua (animate background-position).
     Lớp 2: nền gradient gốc. Bo tròn tự cắt dải sáng theo hình tròn. */
  background:
    linear-gradient(110deg, transparent 42%, rgba(255, 255, 255, 0.6) 50%, transparent 58%) no-repeat,
    linear-gradient(135deg, #cbb9f5, #81b1ff) no-repeat;
  background-size: 200% 100%, 100% 100%;
  background-position: 120% 0, 0 0;
  box-shadow: 0 10px 25px rgba(99, 102, 241, 0.35);
  color: #fff;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: ai-card-in 0.4s ease-out both,
    ai-mini-shine 3s ease-in-out 0.4s infinite;
}
/* Sóng lan tỏa như phát sóng điện thoại — CHỈ phát ra 2 bên: border trong suốt,
   chỉ tô cạnh trái + phải → thành 2 cung khuyết ( ) ở hai bên. Lệch pha 1s. */
.ai-mini::before,
.ai-mini::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 9999px;
  border: 2px solid transparent;
  border-left-color: rgba(129, 177, 255, 0.6);
  border-right-color: rgba(129, 177, 255, 0.6);
  pointer-events: none;
  animation: ai-mini-radar 2s ease-out infinite;
}
.ai-mini::after {
  animation-delay: 1s;
}
.ai-mini:hover {
  transform: scale(1.06);
  box-shadow: 0 12px 28px rgba(99, 102, 241, 0.45);
}
.ai-mini svg {
  width: 26px;
  height: 26px;
}
@keyframes ai-mini-shine {
  0% {
    background-position: 120% 0, 0 0;
  }
  33% {
    background-position: -20% 0, 0 0;
  }
  100% {
    background-position: -20% 0, 0 0;
  }
}
@keyframes ai-mini-radar {
  0% {
    transform: scale(1);
    opacity: 0.6;
  }
  100% {
    transform: scale(2.1);
    opacity: 0;
  }
}

/* Đang kéo: con trỏ "nắm", tắt transition để bám tay mượt, khỏi chọn chữ. */
.ai-fab.dragging {
  cursor: grabbing;
  user-select: none;
}
.ai-fab.dragging .ai-card,
.ai-fab.dragging .ai-mini {
  transition: none;
  cursor: grabbing;
}

/* Ẩn hoàn toàn thẻ AI khi trang còn skeleton (F5). Gỡ trong _showContent(). */
.ai-fab.hidden-boot { display: none; }

/* Chuyển thẻ ↔ nút thu gọn (robust hơn class .hidden của Tailwind về thứ tự nạp). */
.ai-fab .ai-mini { display: none; }
.ai-fab.collapsed .ai-card { display: none; }
.ai-fab.collapsed .ai-mini { display: inline-flex; }

@media (prefers-reduced-motion: reduce) {
  .ai-card, .ai-mini { animation: none; }
  .ai-mini::before, .ai-mini::after { display: none; }
  .ai-card, .ai-card-btn, .ai-mini { transition: none; }
  .ai-card:hover, .ai-mini:hover { transform: none; }
}

/* Nút "Quay lại" ở màn Lịch sử tạo — nổi bật với tông rose, không chìm như
   nút viền xám thường; mũi tên trượt nhẹ sang trái khi hover. */
.ai-back-btn {
  width: 100%;
  height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #e11d48;
  background: linear-gradient(135deg, #fff5f7 0%, #ffe4e9 100%);
  border: 1.5px solid #fecdd3;
  box-shadow: 0 4px 12px -4px rgba(244, 63, 94, 0.28);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease,
              background 0.15s ease, border-color 0.15s ease;
}
.ai-back-btn:hover {
  background: linear-gradient(135deg, #ffe4e9 0%, #fecdd3 100%);
  border-color: #fda4af;
  box-shadow: 0 7px 18px -4px rgba(244, 63, 94, 0.42);
  transform: translateY(-1px);
}
.ai-back-btn:active {
  transform: translateY(0);
  box-shadow: 0 3px 9px -4px rgba(244, 63, 94, 0.35);
}
.ai-back-btn svg {
  transition: transform 0.18s ease;
}
.ai-back-btn:hover svg { transform: translateX(-3px); }
@media (prefers-reduced-motion: reduce) {
  .ai-back-btn, .ai-back-btn svg { transition: none; }
  .ai-back-btn:hover { transform: none; }
  .ai-back-btn:hover svg { transform: none; }
}

/* Dải chọn văn phong: cuộn ngang + nút mũi tên hai bên */
.ai-tone-wrap {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}
.ai-tone-scroll {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scroll-behavior: smooth;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge cũ */
  padding: 2px;
}
.ai-tone-scroll::-webkit-scrollbar {
  display: none;
}
.ai-tone-nav {
  flex: 0 0 auto;
  width: 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #e5e7eb;
  border-radius: 9999px;
  color: #9ca3af;
  background: #fff;
  transition: all 0.15s ease;
}
.ai-tone-nav:hover {
  border-color: #fda4af;
  color: #e11d48;
}

/* Nút chọn văn phong (item trong dải cuộn) */
.ai-tone-btn {
  flex: 0 0 auto;
  height: 2.5rem;
  padding: 0 1rem;
  white-space: nowrap;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  font-size: 0.8125rem;
  color: #6b7280;
  background: #fff;
  transition: all 0.15s ease;
}
.ai-tone-btn:hover {
  border-color: #fda4af;
}
.ai-tone-btn.active {
  border-color: #f43f5e;
  background: #fff1f2;
  color: #e11d48;
  font-weight: 600;
}

/* Input dùng chung trong form AI */
.ai-inp {
  width: 100%;
  height: 2.75rem;
  padding: 0 0.875rem;
  font-size: 0.875rem;
  color: #374151;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  outline: none;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
textarea.ai-inp {
  height: auto;
  padding: 0.625rem 0.875rem;
  line-height: 1.5;
}
.ai-inp:focus {
  border-color: #fb7185;
  box-shadow: 0 0 0 3px rgba(251, 113, 133, 0.18);
}
.ai-inp::placeholder {
  color: #b6bcc6;
}

/* Ô input thường có nút "x" xoá nhanh (tên cô dâu/chú rể) */
.ai-inp-wrap {
  position: relative;
}
.ai-inp.has-clear {
  padding-right: 2.25rem;
}
.ai-inp-clear {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 0.375rem;
  color: #9ca3af;
  transition: color 0.12s ease, background 0.12s ease;
}
.ai-inp-clear.show {
  display: inline-flex;
}
.ai-inp-clear:hover {
  color: #4b5563;
  background: #f3f4f6;
}

/* Combobox: bỏ mũi tên mặc định (xấu), thay chevron tuỳ biến cho gọn đẹp */
.ai-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 2.5rem;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
}
.ai-select::-ms-expand {
  display: none;
}

/* Combobox tuỳ biến: panel rộng ĐÚNG bằng control (left/right = 0) */
.ai-cselect {
  position: relative;
}
.ai-cselect-btn {
  display: flex;
  align-items: center;
  text-align: left;
}
.ai-cselect-btn .ai-cselect-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-cselect-label.is-placeholder {
  color: #b6bcc6;
}
.ai-cselect-btn.open {
  border-color: #fb7185;
  box-shadow: 0 0 0 3px rgba(251, 113, 133, 0.18);
}
.ai-cselect-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 50;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12);
  padding: 0.25rem;
  max-height: 15rem;
  overflow-y: auto;
}
.ai-cselect-opt {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 0.875rem;
  color: #374151;
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.12s ease;
}
.ai-cselect-opt:hover {
  background: #fff1f2;
}
.ai-cselect-opt.sel {
  background: #fff1f2;
  color: #e11d48;
  font-weight: 600;
}

/* Chip nhỏ (nút "Chèn mẫu") */
.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  color: #e11d48;
  background: #fff1f2;
  border: 1px solid #fecdd3;
  padding: 0.25rem 0.625rem;
  border-radius: 9999px;
  transition: background 0.15s ease;
}
.ai-chip:hover {
  background: #ffe4e6;
}
/* Biến thể "Nói" (mic) — tông tím/xanh khớp icon AI, phân biệt với "Chèn mẫu" */
.ai-chip-mic {
  color: #6d4fce;
  background: #f3efff;
  border-color: #ddd0fb;
}
.ai-chip-mic:hover {
  background: #e9e1ff;
}
/* Nút "x" xoá nhanh của textarea nay do <x-textarea> tự dựng & tự style
   (xem core/x-controls.js). Ô "Thông tin cô dâu/chú rể" dùng <x-textarea>. */

/* Skeleton loading khi AI đang tạo (khớp thứ tự hiển thị của preview) */
.ai-sk {
  background: linear-gradient(90deg, #f1f2f4 25%, #e7e9ec 37%, #f1f2f4 63%);
  background-size: 200% 100%;
  animation: ai-shimmer 1.4s ease-in-out infinite;
  border-radius: 0.5rem;
}
@keyframes ai-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.ai-sk-group { margin-bottom: 1rem; }
.ai-sk-label { height: 0.7rem; margin-bottom: 0.5rem; border-radius: 0.25rem; }
.ai-sk-box { height: 3.25rem; } /* nằm trong .ai-fld-grid (2 cột) */
.ai-sk-card { height: 2.75rem; margin-bottom: 0.375rem; }
.ai-sk-card.sm { height: 2.25rem; }
.ai-sk-card.lg { height: 3.75rem; }
@media (prefers-reduced-motion: reduce) {
  .ai-sk { animation: none; }
}

/* Khoá cuộn khung sheet khi đang hiển thị skeleton (placeholder gọn trong 1 màn) */
.ai-lock-scroll {
  overflow: hidden !important;
}

/* Sửa kết quả AI: ô hiển thị + bút chì → bấm để bind sang control tương ứng */
.ai-disp-empty {
  color: #b6bcc6;
  font-style: italic;
}
.ai-edit-live {
  width: 100%;
  margin-top: 0.125rem;
}
.ai-edit-ctrl {
  position: relative;
  width: 100%;
}
/* Chừa lề phải cho nút ✓ (và nút × của control nếu có), để 2 nút nằm TRONG ô nhập.
   Chỉ nhắm ô nhập chính (con trực tiếp) — KHÔNG đụng input bên trong lịch flatpickr. */
.ai-edit-ctrl > input {
  padding-right: 2.4rem !important; /* chỉ có ✓ (ô ngày/giờ không có ×) */
}
.ai-edit-ctrl x-input input,
.ai-edit-ctrl x-textarea textarea {
  padding-right: 3.9rem !important; /* có cả × lẫn ✓ */
}
/* Dời nút × của control sang trái để nhường chỗ ✓ ở ngoài cùng bên phải. */
.ai-edit-ctrl .x-clear,
.ai-edit-ctrl .x-ta-clear {
  right: 2.1rem !important;
}
/* Nút ✓ lưu — nằm trong ô nhập, cùng cấp & bên phải nút ×, CÙNG MÀU với nút ×. */
.ai-edit-ok {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 0.375rem;
  color: #9ca3af; /* gray-400 — khớp nút × */
  background: transparent;
  transition: color 0.12s ease, background 0.12s ease;
}
.ai-edit-ok:hover {
  color: #4b5563; /* gray-600 — khớp hover nút × */
  background: #f3f4f6;
}
.ai-edit-ico {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 0.375rem;
  color: #cbd0d6;
  transition: color 0.12s ease, background 0.12s ease;
}
.ai-edit-ico:hover {
  color: #f43f5e;
  background: #fff1f2;
}
/* Header nhóm có nút bút chì bên phải (VD Slogan) */
.ai-ed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}
/* Mốc chuyện tình: hàng tiêu đề (title · date) + bút chì bên phải */
.ai-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
/* Field trích xuất: hàng nhãn + bút chì */
.ai-fld-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
}

/* Block/card gom nhóm: "Thông tin cô dâu/chú rể" và "Chuyện tình yêu" tách bạch */
.ai-block {
  border: 1px solid #eef0f2;
  border-radius: 1rem;
  padding: 0.875rem 0.875rem 1rem;
  background: #fcfcfd;
}
.ai-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.ai-block-title {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #374151;
}
.ai-block-title i,
.ai-block-title svg {
  color: #f43f5e;
  flex-shrink: 0;
}
.ai-block-sub {
  display: flex;
  align-items: flex-start;
  gap: 0.375rem;
  font-size: 0.75rem;
  line-height: 1.45;
  color: #6b7280;
  margin-bottom: 0.625rem;
}

/* Textarea thông tin cô dâu/chú rể: cuộn được khi nội dung dài (kể cả trên mobile
   bên trong bottom-sheet — overscroll-behavior giữ cuộn trong ô, không đẩy sheet) */
textarea#ai-info {
  max-height: 40vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* Preview: từng hạng mục thông tin dâu/rể hiển thị riêng lẻ (không dồn 1 khối) */
.ai-fld-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}
.ai-fld {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid #f1f2f4;
  border-radius: 0.625rem;
  background: #fafafa;
  min-width: 0;
}
.ai-fld.full {
  grid-column: 1 / -1;
}
.ai-fld-label {
  font-size: 0.6875rem;
  color: #9ca3af;
  line-height: 1.2;
}
.ai-fld-val {
  font-size: 0.8125rem;
  font-weight: 500;
  color: #374151;
  word-break: break-word;
  line-height: 1.35;
}

/* Lịch sử tạo: khi đang là view đang hiện, kéo dài hết chiều cao còn lại của
   sheet để danh sách/trạng thái rỗng không bị dồn lên đầu, chừa khoảng trống bên dưới. */
#ai-history:not(.hidden) {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
#ai-history-list {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
/* Trạng thái rỗng ("Chưa có nội dung...") canh giữa trong toàn bộ khoảng trống đó. */
#ai-history-list > .ai-history-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
