.ai-conversation-item { border-color: rgba(169, 132, 86, .22); background: linear-gradient(135deg, rgba(169, 132, 86, .08), transparent); }
.ai-conversation-item:hover, .ai-conversation-item.active { border-color: rgba(169, 132, 86, .55); background: rgba(169, 132, 86, .12); }
.ai-avatar {
  background: linear-gradient(145deg, #2f4035, #17231b) !important;
  color: #d9b67a !important;
  font-size: 9px !important;
  font-weight: 800;
  letter-spacing: .08em;
  overflow: hidden !important;
  position: relative;
  border-radius: 50%;
}

.ai-avatar img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* ==========================================================================
   Chuột GPT AI Model Dock — Đặt ngay trên thanh nhập chữ (#composer)
   ========================================================================== */
.ai-model-dock {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 32px 4px;
  padding: 5px 8px 5px 6px;
  border: 1px solid rgba(169, 132, 86, .28);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(251, 250, 247, .94), rgba(240, 238, 232, .92));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 14px rgba(40, 44, 35, .04);
  transition: border-color .2s ease, box-shadow .2s ease;
}

:root[data-theme="dark"] .ai-model-dock {
  border-color: rgba(214, 174, 114, .25);
  background: linear-gradient(135deg, rgba(23, 32, 26, .94), rgba(32, 43, 35, .92));
  box-shadow: 0 4px 18px rgba(0, 0, 0, .24);
}

.ai-model-dock:hover {
  border-color: rgba(169, 132, 86, .45);
}

/* Nút kích hoạt mở Box Chọn Model */
.ai-model-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
  padding: 4px 9px 4px 7px;
  border: 1px solid rgba(169, 132, 86, .35);
  border-radius: 9px;
  background: linear-gradient(135deg, rgba(169, 132, 86, .12), rgba(82, 101, 85, .08));
  color: var(--ink);
  cursor: pointer;
  outline: 0;
  transition: all .2s cubic-bezier(.2, .8, .2, 1);
}

.ai-model-trigger:hover {
  border-color: var(--gold);
  background: linear-gradient(135deg, rgba(169, 132, 86, .22), rgba(82, 101, 85, .15));
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(169, 132, 86, .18);
}

.ai-model-trigger:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.ai-trigger-icon {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  color: var(--gold);
}

.ai-trigger-icon svg {
  width: 15px;
  height: 15px;
}

.ai-trigger-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}

.ai-trigger-kicker {
  color: var(--gold);
  font-size: 7.5px;
  font-weight: 800;
  letter-spacing: .12em;
}

.ai-trigger-name {
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-trigger-badge {
  display: inline-block;
  padding: 2px 5px;
  border-radius: 5px;
  background: rgba(169, 132, 86, .18);
  color: var(--gold);
  font-size: 8.5px;
  font-weight: 800;
  letter-spacing: .04em;
  white-space: nowrap;
}

:root[data-theme="dark"] .ai-trigger-badge {
  background: rgba(214, 174, 114, .2);
  color: #eed09d;
}

.ai-trigger-chevron {
  display: grid;
  place-items: center;
  width: 12px;
  height: 12px;
  color: var(--muted);
  transition: transform .2s ease;
}

.ai-trigger-chevron svg {
  width: 11px;
  height: 11px;
}

.ai-model-trigger[aria-expanded="true"] .ai-trigger-chevron {
  transform: rotate(180deg);
}

/* Dải phím chọn nhanh Pills ngay trên thanh nhập chữ */
.ai-model-pills {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
  flex: 1 1 auto;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 1px 2px;
}

.ai-model-pills::-webkit-scrollbar {
  display: none;
}

.ai-model-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
  cursor: pointer;
  outline: 0;
  white-space: nowrap;
  transition: all .18s cubic-bezier(.2, .8, .2, 1);
}

.ai-model-pill:hover {
  border-color: var(--gold);
  background: var(--paper-deep);
  color: var(--ink);
  transform: translateY(-1px);
}

.ai-model-pill.active {
  border-color: var(--gold);
  background: linear-gradient(135deg, var(--olive-dark), #1c2720);
  color: #eed09d;
  box-shadow: 0 2px 8px rgba(41, 59, 48, .25);
}

:root[data-theme="dark"] .ai-model-pill.active {
  background: linear-gradient(135deg, #2b3d31, #17241b);
  border-color: var(--gold);
  color: #f7dfb5;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .4);
}

.ai-pill-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  transition: background .2s ease;
}

.ai-model-pill.active .ai-pill-dot {
  background: var(--gold);
  box-shadow: 0 0 6px var(--gold);
}

/* Nút New Chat trên dock */
.ai-new-chat {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  height: 27px;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--button-soft);
  color: var(--olive-dark);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s ease, border-color .2s ease, color .2s ease, transform .2s ease;
}

.ai-new-chat:hover {
  border-color: var(--gold);
  background: var(--button-soft-hover);
  color: var(--olive);
  transform: translateY(-1px);
}

.ai-new-chat:disabled {
  cursor: wait;
  opacity: .5;
  transform: none;
}

.ai-web-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--muted);
  font: inherit;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease, color .2s ease, transform .2s ease;
}

.ai-web-toggle { display: none !important; }

.ai-web-toggle svg { width: 15px; height: 15px; }
.ai-web-toggle:hover { border-color: var(--gold); color: var(--ink); transform: translateY(-1px); }
.ai-web-toggle.is-active { border-color: var(--gold); background: rgba(169, 132, 86, .16); color: var(--gold); }
:root[data-theme="dark"] .ai-web-toggle { background: var(--paper); }

.ai-new-chat svg {
  width: 14px;
  height: 14px;
}

.ai-new-chat-text {
  white-space: nowrap;
}

/* Credit Pill hiển thị số dư credit theo tháng */
.ai-quota-pill {
  display: inline-flex;
  align-items: center;
  gap: 4.5px;
  flex: 0 0 auto;
  height: 27px;
  padding: 0 9px;
  border-radius: 8px;
  border: 1px solid rgba(169, 132, 86, .35);
  background: rgba(169, 132, 86, .08);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  user-select: none;
  transition: border-color .2s ease, background .2s ease, color .2s ease;
}

:root[data-theme="dark"] .ai-quota-pill {
  border-color: rgba(214, 174, 114, .32);
  background: rgba(214, 174, 114, .08);
  color: #dfd3c3;
}

.ai-quota-icon {
  color: var(--gold);
  font-size: 11px;
  line-height: 1;
}

.ai-quota-pill strong {
  color: var(--gold);
  font-weight: 700;
}

:root[data-theme="dark"] .ai-quota-pill strong {
  color: #eed09d;
}

.ai-quota-pill.is-exhausted {
  border-color: rgba(239, 68, 68, .5);
  background: rgba(239, 68, 68, .1);
  color: #ef4444;
}

.ai-quota-pill.is-exhausted strong,
.ai-quota-pill.is-exhausted .ai-quota-icon {
  color: #ef4444;
}

/* Class hỗ trợ trợ năng / backward compatibility */
.ai-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================================================================
   Giao diện Riêng Đẹp Mắt: BOX CHỌN MODEL (Modal Dialog)
   ========================================================================== */
.ai-model-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 18px;
  opacity: 1;
  visibility: visible;
  transition: opacity .24s cubic-bezier(.2, .8, .2, 1), visibility .24s cubic-bezier(.2, .8, .2, 1);
}

.ai-model-modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.ai-model-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 21, 18, .58);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.ai-model-dialog {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(100%, 660px);
  max-height: min(88dvh, 740px);
  overflow: hidden;
  border: 1px solid rgba(169, 132, 86, .38);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 28px 75px rgba(16, 21, 18, .36), 0 0 0 1px rgba(255, 255, 255, .06) inset;
  transform: translateY(0) scale(1);
  transition: transform .26s cubic-bezier(.16, 1, .3, 1), opacity .26s cubic-bezier(.16, 1, .3, 1);
}

.ai-model-modal.hidden .ai-model-dialog {
  transform: translateY(12px) scale(.97);
  opacity: 0;
}

:root[data-theme="dark"] .ai-model-dialog {
  border-color: rgba(214, 174, 114, .3);
  background: #17201a;
  box-shadow: 0 30px 85px rgba(0, 0, 0, .6), 0 0 0 1px rgba(214, 174, 114, .12) inset;
}

/* Header của Box */
.ai-modal-header {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--paper-deep), var(--paper));
}

.ai-modal-header::before {
  position: absolute;
  top: 0;
  left: 24px;
  right: 24px;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), var(--olive), transparent);
  content: "";
}

.ai-modal-title-group {
  min-width: 0;
}

.ai-modal-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--gold);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.ai-modal-title {
  margin: 4px 0 0;
  color: var(--ink);
  font-family: inherit;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -.02em;
}

.ai-modal-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
}

.ai-modal-close-btn {
  display: grid;
  place-items: center;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  color: var(--muted);
  cursor: pointer;
  transition: all .2s ease;
}

.ai-modal-close-btn:hover {
  border-color: var(--gold);
  background: var(--paper-deep);
  color: var(--ink);
  transform: scale(1.05);
}

.ai-modal-close-btn svg {
  width: 16px;
  height: 16px;
}

/* Danh sách Card Model trong Box */
.ai-model-card-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 16px 22px;
  overflow-y: auto;
  max-height: 480px;
}

.ai-model-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(145deg, var(--paper), var(--paper-deep));
  cursor: pointer;
  outline: 0;
  transition: all .22s cubic-bezier(.2, .8, .2, 1);
}

.ai-model-card:hover {
  border-color: rgba(169, 132, 86, .55);
  background: linear-gradient(145deg, var(--paper), rgba(169, 132, 86, .07));
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(40, 44, 35, .08);
}

:root[data-theme="dark"] .ai-model-card:hover {
  border-color: rgba(214, 174, 114, .5);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

.ai-model-card:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Trạng thái card được chọn */
.ai-model-card.selected {
  border-color: var(--gold);
  background: linear-gradient(145deg, rgba(169, 132, 86, .12), rgba(82, 101, 85, .08));
  box-shadow: 0 0 0 1.5px var(--gold), 0 8px 24px rgba(169, 132, 86, .18);
}

:root[data-theme="dark"] .ai-model-card.selected {
  background: linear-gradient(145deg, rgba(214, 174, 114, .14), rgba(43, 61, 49, .3));
  box-shadow: 0 0 0 1.5px var(--gold), 0 8px 28px rgba(0, 0, 0, .45);
}

.ai-card-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ai-card-title-group {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.ai-card-icon {
  display: grid;
  place-items: center;
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(169, 132, 86, .2), rgba(82, 101, 85, .15));
  color: var(--gold);
}

:root[data-theme="dark"] .ai-card-icon {
  background: linear-gradient(135deg, rgba(214, 174, 114, .25), rgba(41, 59, 48, .4));
  color: #f3d7a8;
}

.ai-card-icon svg {
  width: 16px;
  height: 16px;
}

.ai-card-name {
  margin: 0;
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.25;
}

.ai-card-radio-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.ai-card-radio-dot {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--line-strong);
  border-radius: 50%;
  background: transparent;
  transition: all .2s ease;
}

.ai-model-card.selected .ai-card-radio-dot {
  border-color: var(--gold);
  background: var(--gold);
  color: #17201a;
  box-shadow: 0 0 8px rgba(169, 132, 86, .45);
}

.ai-card-radio-dot svg {
  width: 11px;
  height: 11px;
  opacity: 0;
  transform: scale(.5);
  transition: all .2s ease;
}

.ai-model-card.selected .ai-card-radio-dot svg {
  opacity: 1;
  transform: scale(1);
}

.ai-card-selected-tag {
  color: var(--gold);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
  opacity: 0;
  transition: opacity .2s ease;
}

.ai-model-card.selected .ai-card-selected-tag {
  opacity: 1;
}

.ai-card-desc {
  margin: 0;
  color: var(--ink-soft);
  font-size: 11.5px;
  line-height: 1.45;
}

.ai-card-meta-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 9.5px;
  font-weight: 700;
}

.ai-chip-context {
  border: 1px solid rgba(169, 132, 86, .35);
  background: rgba(169, 132, 86, .12);
  color: var(--gold);
}

.ai-chip-moe {
  border: 1px solid rgba(82, 101, 85, .35);
  background: rgba(82, 101, 85, .1);
  color: var(--olive);
}

:root[data-theme="dark"] .ai-chip-moe {
  color: #b1d4b9;
}

/* Chỉ hiển thị Mushoku Tensei Pro trong bộ chọn model ở giao diện. */
.ai-model-pill[data-model-id="kira-2.0"],
.ai-model-pill[data-model-id="mimo-v2.5"],
.ai-model-pill[data-model-id="hy3"],
.ai-model-card[data-model-id="kira-2.0"],
.ai-model-card[data-model-id="mimo-v2.5"],
.ai-model-card[data-model-id="hy3"] {
  display: none !important;
}

.ai-chip-tag {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
}

.ai-card-specs-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 2px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 9.5px;
}

.ai-card-specs-bar strong {
  color: var(--ink);
  font-weight: 700;
}

/* Footer của Box */
.ai-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, var(--paper), var(--paper-deep));
}

.ai-modal-footer-note {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 10px;
}

.ai-modal-footer-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--olive);
  box-shadow: 0 0 5px var(--olive);
}

.ai-modal-done-btn {
  padding: 7px 18px;
  border: 0;
  border-radius: 9px;
  background: var(--olive-dark);
  color: #f4f1eb;
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all .2s ease;
}

.ai-modal-done-btn:hover {
  background: var(--olive);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(41, 59, 48, .25);
}

/* ==========================================================================
   Các phần tử giao diện trò chuyện AI khác (Avatar, Message Bubbles, Cursor)
   ========================================================================== */
.ai-empty-icon {
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #d6b076;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  overflow: hidden !important;
  border-radius: 50%;
}

.ai-empty-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.ai-message-row .message-bubble { border-color: rgba(169, 132, 86, .34); }
.ai-message-row.theirs .message-bubble { background: linear-gradient(145deg, var(--paper), var(--paper-deep)); }
.ai-message-row.mine .message-bubble { background: var(--olive-dark); }
/* 1. Trạng thái AI đang suy nghĩ (trước khi nhận được phản hồi từ server) */
.ai-message-row.is-thinking .message-bubble {
  border-color: rgba(169, 132, 86, .5);
  background: linear-gradient(145deg, var(--paper), var(--paper-deep));
  box-shadow: 0 4px 16px rgba(169, 132, 86, .12);
}

:root[data-theme="dark"] .ai-message-row.is-thinking .message-bubble {
  border-color: rgba(214, 174, 114, .4);
  background: rgba(30, 42, 34, .88);
  box-shadow: 0 4px 20px rgba(0, 0, 0, .38);
}

.ai-thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 2px;
}

/* 3 cục tròn nhấp nhô lượn sóng rõ rệt trên cả Mobile và PC */
.ai-thinking-dot {
  display: inline-block !important;
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px rgba(169, 132, 86, .7);
  animation: ai-thinking-wave 1.15s cubic-bezier(.45, .05, .55, .95) infinite both !important;
  -webkit-animation: ai-thinking-wave 1.15s cubic-bezier(.45, .05, .55, .95) infinite both !important;
  will-change: transform, opacity;
}

.ai-thinking-dot:nth-child(1) {
  animation-delay: 0s !important;
  -webkit-animation-delay: 0s !important;
}
.ai-thinking-dot:nth-child(2) {
  animation-delay: 0.18s !important;
  -webkit-animation-delay: 0.18s !important;
}
.ai-thinking-dot:nth-child(3) {
  animation-delay: 0.36s !important;
  -webkit-animation-delay: 0.36s !important;
}

@keyframes ai-thinking-wave {
  0%, 100% {
    transform: translate3d(0, 0, 0);
    opacity: 0.35;
  }
  35% {
    transform: translate3d(0, -9px, 0);
    opacity: 1;
    box-shadow: 0 6px 14px rgba(169, 132, 86, .9);
  }
  70% {
    transform: translate3d(0, 1px, 0);
    opacity: 0.55;
  }
}

@-webkit-keyframes ai-thinking-wave {
  0%, 100% {
    -webkit-transform: translate3d(0, 0, 0);
    opacity: 0.35;
  }
  35% {
    -webkit-transform: translate3d(0, -9px, 0);
    opacity: 1;
    box-shadow: 0 6px 14px rgba(169, 132, 86, .9);
  }
  70% {
    -webkit-transform: translate3d(0, 1px, 0);
    opacity: 0.55;
  }
}

/* Dòng chữ suy nghĩ swap ngẫu nhiên mượt mà */
.ai-thinking-label {
  display: inline-block;
  margin-left: 9px;
  font-size: 12.5px;
  font-style: italic;
  font-weight: 500;
  color: var(--ink-soft);
  opacity: .92;
  transition: opacity .22s cubic-bezier(.4, 0, .2, 1), transform .22s cubic-bezier(.4, 0, .2, 1);
  will-change: opacity, transform;
}

.ai-thinking-label.is-swapping {
  opacity: 0;
  transform: translateY(4px);
}

:root[data-theme="dark"] .ai-thinking-label {
  color: #d1e2d3;
}

/* 2. Trạng thái AI đang flush chữ từ bộ nhớ tạm ra màn hình */
.ai-message-row.is-streaming .message-bubble {
  position: relative;
  border-color: rgba(169, 132, 86, .6);
  box-shadow: 0 4px 20px rgba(169, 132, 86, .18), 0 0 0 1px rgba(169, 132, 86, .2) inset;
  animation: ai-bubble-streaming 2s ease-in-out infinite alternate;
}

:root[data-theme="dark"] .ai-message-row.is-streaming .message-bubble {
  border-color: rgba(214, 174, 114, .5);
  box-shadow: 0 4px 24px rgba(0, 0, 0, .45), 0 0 0 1px rgba(214, 174, 114, .2) inset;
  animation: ai-bubble-streaming-dark 2s ease-in-out infinite alternate;
}

@keyframes ai-bubble-streaming {
  0% { border-color: rgba(169, 132, 86, .35); box-shadow: 0 4px 14px rgba(40, 44, 35, .04); }
  100% { border-color: rgba(169, 132, 86, .75); box-shadow: 0 6px 22px rgba(169, 132, 86, .25), 0 0 0 1px rgba(169, 132, 86, .3) inset; }
}

@keyframes ai-bubble-streaming-dark {
  0% { border-color: rgba(214, 174, 114, .25); box-shadow: 0 4px 16px rgba(0, 0, 0, .3); }
  100% { border-color: rgba(214, 174, 114, .65); box-shadow: 0 6px 28px rgba(0, 0, 0, .6), 0 0 0 1px rgba(214, 174, 114, .3) inset; }
}

.ai-message-row.is-streaming .message-bubble p {
  min-height: 1.25em;
  word-break: break-word;
}

/* Con trỏ phát sáng hiện đại bám sát từng ký tự flush */
.ai-stream-cursor {
  display: inline-block;
  vertical-align: -0.15em;
  width: 2.5px;
  height: 1.15em;
  margin-left: 3px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--gold), #eed09d);
  box-shadow: 0 0 10px rgba(169, 132, 86, .9), 0 0 3px rgba(214, 174, 114, .7);
  animation: ai-cursor-pulse 650ms cubic-bezier(.4, 0, .2, 1) infinite alternate;
}

@keyframes ai-cursor-pulse {
  0% { opacity: .2; transform: scaleY(.85); }
  100% { opacity: 1; transform: scaleY(1); box-shadow: 0 0 12px var(--gold); }
}

@media (prefers-reduced-motion: reduce) {
  .ai-message-row.is-streaming .message-bubble,
  .ai-message-row.is-thinking .message-bubble { animation: none; }
  .ai-model-dialog, .ai-model-trigger, .ai-model-pill, .ai-model-card { transition: none; }
}

/* ==========================================================================
   Gợi ý câu hỏi nhanh & Khối mã Markdown
   ========================================================================== */
.ai-prompt-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 480px;
  margin: 16px auto 0;
  padding: 0 10px;
}

.ai-suggestion-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .2s ease, background .2s ease, transform .15s ease, box-shadow .2s ease;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .04);
}

.ai-suggestion-chip:hover {
  border-color: var(--gold);
  background: var(--paper-deep);
  color: var(--olive-dark);
  transform: translateY(-1px);
}

.ai-suggestion-chip:active {
  transform: scale(0.97);
}

:root[data-theme="dark"] .ai-suggestion-chip {
  background: rgba(30, 42, 34, .75);
  border-color: rgba(214, 174, 114, .25);
  color: #eed09d;
}

:root[data-theme="dark"] .ai-suggestion-chip:hover {
  border-color: var(--gold);
  background: rgba(41, 59, 48, .9);
  color: #fff;
}

.ai-message-row pre {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .05);
  border: 1px solid var(--line);
  overflow-x: auto;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.45;
}

:root[data-theme="dark"] .ai-message-row pre {
  background: rgba(0, 0, 0, .35);
  border-color: rgba(255, 255, 255, .1);
}

.ai-message-row code {
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 12px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(169, 132, 86, .12);
  color: var(--olive-dark);
}

.ai-rich-content { min-width: 0; overflow-wrap: anywhere; }
.ai-rich-paragraph { margin: 0 0 10px; white-space: pre-wrap; }
.ai-rich-paragraph:last-child { margin-bottom: 0; }
.ai-inline-code { padding: 2px 5px; border: 1px solid rgba(169, 132, 86, .25); border-radius: 5px; background: rgba(169, 132, 86, .12); color: var(--olive-dark); font-family: Consolas, Monaco, "Courier New", monospace; font-size: .9em; }
.ai-code-block { position: relative; margin: 12px 0; padding: 30px 14px 13px; overflow-x: auto; border: 1px solid rgba(82, 101, 85, .34); border-radius: 9px; background: #1b2520; color: #e8f0e8; font-family: Consolas, Monaco, "Courier New", monospace; font-size: 12px; line-height: 1.55; tab-size: 2; white-space: pre; }
.ai-code-block code { display: block; padding: 0; border: 0; background: transparent; color: inherit; font: inherit; white-space: inherit; }
.ai-code-language { position: absolute; top: 8px; left: 12px; color: #d6ae72; font-family: Lato, "Segoe UI", sans-serif; font-size: 9px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.tok-comment { color: #8fa596; font-style: italic; }
.tok-string { color: #e6c27a; }
.tok-keyword { color: #9dc4ed; font-weight: 700; }
.tok-number { color: #d6a6e8; }
.ai-math-block { display: block; margin: 14px 0; overflow-x: auto; padding: 8px 4px; color: var(--ink); text-align: center; }
.ai-math-inline { display: inline-block; margin: 0 2px; color: inherit; vertical-align: middle; }
.ai-math-fallback { font-family: Consolas, Monaco, "Courier New", monospace; font-size: .92em; white-space: pre-wrap; }
:root[data-theme="dark"] .ai-inline-code { background: rgba(214, 174, 114, .18); color: #eed09d; }
:root[data-theme="dark"] .ai-math-block, :root[data-theme="dark"] .ai-math-inline { color: #f0f5ee; }
.mine .ai-code-block { background: #1b2c24; }

:root[data-theme="dark"] .ai-message-row code {
  background: rgba(214, 174, 114, .18);
  color: #eed09d;
}

/* ==========================================================================
   Responsive Mobile (< 720px) — Bố cục giao diện chat AI chuẩn như chat người
   ========================================================================== */
@media (max-width: 720px) {
  /* 1. Header AI trên mobile */
  .chat-view.ai-conversation-active .chat-header {
    padding: 12px 16px;
    gap: 10px;
    background: var(--canvas);
    border-bottom: 1px solid var(--line);
  }

  .chat-view.ai-conversation-active .chat-contact {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .chat-view.ai-conversation-active .contact-avatar.ai-avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(145deg, #27372d, #141c16) !important;
    color: #dfba7f !important;
    border: 1.5px solid rgba(169, 132, 86, .55);
    box-shadow: 0 0 10px rgba(169, 132, 86, .25);
    font-weight: 900;
    font-size: 11px;
    overflow: hidden !important;
  }

  .chat-view.ai-conversation-active .chat-overline {
    color: var(--gold);
    font-size: 9px;
    letter-spacing: .08em;
  }

  .chat-view.ai-conversation-active .ai-status-text {
    color: var(--olive);
    font-weight: 600;
    font-size: 11px;
  }

  :root[data-theme="dark"] .chat-view.ai-conversation-active .ai-status-text {
    color: #a7c5af;
  }

  /* 2. Dock điều khiển AI trên mobile - Gọn gàng thanh lịch ngay trên composer */
  .ai-model-dock {
    margin: 0 17px 6px;
    padding: 3px 6px;
    height: 34px;
    gap: 5px;
    border-radius: 9px;
    background: var(--paper);
    border: 1px solid var(--line);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .04);
    display: flex;
    align-items: center;
  }

  :root[data-theme="dark"] .ai-model-dock {
    background: rgba(28, 38, 31, .88);
    border-color: rgba(214, 174, 114, .2);
  }

  .ai-model-trigger {
    flex: 0 0 auto;
    height: 26px;
    padding: 0 7px;
    gap: 4px;
    border-radius: 6px;
  }

  .ai-trigger-icon {
    width: 14px;
    height: 14px;
  }

  .ai-trigger-icon svg {
    width: 12px;
    height: 12px;
  }

  .ai-trigger-kicker {
    display: none;
  }

  .ai-trigger-name {
    max-width: 82px;
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .ai-trigger-badge {
    display: none;
  }

  .ai-trigger-chevron svg {
    width: 10px;
    height: 10px;
  }

  .ai-model-pills {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1 1 auto;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 1px 0;
  }

  .ai-model-pills::-webkit-scrollbar {
    display: none;
  }

  .ai-model-pill {
    flex: 0 0 auto;
    height: 24px;
    padding: 0 7px;
    font-size: 9.5px;
    font-weight: 600;
    border-radius: 6px;
    white-space: nowrap;
  }

  .ai-new-chat {
    flex: 0 0 auto;
    height: 24px;
    padding: 0 6px;
    border-radius: 6px;
  }

  .ai-web-toggle { height: 24px; min-height: 24px; padding: 0 6px; border-radius: 6px; font-size: 9.5px; }
  .ai-web-toggle svg { width: 13px; height: 13px; }

  .ai-new-chat-text {
    display: none;
  }

  .ai-new-chat svg {
    width: 12px;
    height: 12px;
  }

  .ai-quota-pill {
    flex: 0 0 auto;
    height: 24px;
    padding: 0 6px;
    font-size: 9.5px;
    border-radius: 6px;
    gap: 3px;
  }

  /* 3. Composer AI trên mobile giống hệt chat người */
  .chat-view.ai-conversation-active .composer {
    margin: 0 17px 8px;
    gap: 8px;
  }

  .chat-view.ai-conversation-active #attachment-button {
    display: none; /* AI không gửi ảnh/file, ẩn nút đính kèm để ô nhập rộng rãi tối đa */
  }

  .chat-view.ai-conversation-active #message-input {
    font-size: 14.5px;
    padding: 10px 14px;
    border-radius: 12px;
  }

  .chat-view.ai-conversation-active .message-bubble {
    max-width: 86%;
    padding: 11px 14px;
    font-size: 14px;
    line-height: 1.5;
  }

  .ai-prompt-suggestions {
    gap: 6px;
  }

  .ai-suggestion-chip {
    padding: 6px 11px;
    font-size: 11px;
  }

  .ai-code-block { max-width: 100%; font-size: 11px; }
  .ai-math-block { font-size: .9em; text-align: left; }

  /* Modal chọn Model trên mobile dạng bottom-sheet mượt mà */
  .ai-model-dialog {
    max-height: 90dvh;
    border-radius: 18px 18px 0 0;
  }

  .ai-modal-header {
    padding: 16px 18px 12px;
  }

  .ai-modal-title {
    font-size: 17px;
  }

  .ai-model-card-list {
    padding: 12px 14px;
    gap: 8px;
  }

  .ai-model-card {
    padding: 12px 14px;
  }

  .ai-card-name {
    font-size: 12.5px;
  }

  .ai-modal-footer {
    padding: 12px 18px;
  }

  .ai-modal-footer-note {
    font-size: 9px;
  }
}
