:root {
  --bg: #0a0b10;
  --bg-elev: #13151c;
  --bg-elev-2: #1b1e29;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f6fa;
  --text-dim: rgba(245, 246, 250, 0.65);
  --text-faint: rgba(245, 246, 250, 0.42);
  --error: #ff6a75;
  --live: #22d3ee;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --radius-sm: 8px;
  --radius-md: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
/* V.AI STUDIO background image — logo centered on screen (centered-crop asset) */
body {
  background: var(--bg);
  background-image: url("/public/avatars/vaistudio_center.png");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--text); font-family: Inter, system-ui, -apple-system, sans-serif; overflow: hidden;
}
#app { position: relative; height: 100dvh; }
#stage { position: absolute; inset: 0; }
#stage canvas { display: block; }
[hidden] { display: none !important; }
/* Smartphone: show the FULL background image width (no side cropping) so the
   V.AI STUDIO logo/art is fully visible on narrow portrait screens. Because the
   image is short & wide (1114x1024), tile it (loop) vertically to fill the full
   viewport height. */
@media (max-width: 768px) {
  body {
    background-position: center top;
    background-size: 100% auto;
    background-repeat: repeat;
    background-attachment: scroll;
  }
}

#loading { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-mono); font-size: 12px; font-weight: 500; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-faint); background: var(--bg); transition: opacity 0.6s ease; pointer-events: none; }
#loading.done { opacity: 0; }

#topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: flex-start; justify-content: space-between; padding: 18px 20px; pointer-events: none; z-index: 10050; }
#topbar > * { pointer-events: auto; }
#identity h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: 0.01em; }
#identity p { margin: 4px 0 0; max-width: 340px; font-size: 12px; line-height: 1.45; color: var(--text-faint); }
#identity strong { color: var(--text-dim); font-weight: 500; }

.icon-btn { display: grid; place-items: center; width: 36px; height: 36px; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elev); color: var(--text-dim); cursor: pointer; touch-action: manipulation; transition: color 0.15s ease, border-color 0.15s ease; }
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn.active { color: var(--live); border-color: var(--border-strong); }
.icon-btn.small { width: 28px; height: 28px; }

#main-btn { min-width: 190px; height: 46px; padding: 0 26px; border: none; border-radius: 23px; background: var(--text); color: var(--bg); font-family: Inter, system-ui, sans-serif; font-size: 14px; font-weight: 600; cursor: pointer; touch-action: manipulation; transition: transform 0.12s ease, opacity 0.15s ease; }
#main-btn:hover:not(:disabled) { transform: translateY(-1px); }
#main-btn:disabled { opacity: 0.45; cursor: default; }
#main-btn.live { background: var(--bg-elev); color: var(--text); border: 1px solid var(--border-strong); }

#controls { position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 0 20px calc(22px + env(safe-area-inset-bottom)); z-index: 100; }
#buttons { display: flex; align-items: center; gap: 10px; }
#caption { font-family: var(--font-mono); font-size: 11px; font-weight: 500; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-faint); transition: color 0.2s ease; }
#caption.live { color: var(--live); }
#caption.error { color: var(--error); }

#subtitles { position: absolute; left: 50%; bottom: 118px; transform: translateX(-50%); max-width: min(640px, calc(100vw - 48px)); padding: 10px 16px; border-radius: var(--radius-md); background: rgba(10, 11, 16, 0.72); backdrop-filter: blur(6px); border: 1px solid var(--border); font-size: 15px; line-height: 1.5; text-align: center; text-wrap: balance; color: var(--text); opacity: 0; transition: opacity 0.25s ease; pointer-events: none; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
#subtitles.visible { opacity: 1; }

/* ═══════════════════════════════════════════
   POST-MESSAGE CONTEXT (suggestions + hot tags + source cards)
   All rendered INSIDE each assistant chat bubble, dark themed
   ═══════════════════════════════════════════ */

/* Main wrapper — sits directly below the AI text within same bubble */
.post-message-context {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.06);
  animation: fadeSlideUp 0.35s ease;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

/* ── SUGGESTIONS ROW (context-aware follow-up questions) ── */
.suggestions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chat-suggestion-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  max-width: 100%;
  font-family: Inter, system-ui, sans-serif;
  line-height: 1.35;
  word-break: break-word;
}
.chat-suggestion-pill .pill-icon {
  font-size: 0.78rem;
  flex-shrink: 0;
}
.chat-suggestion-pill:hover {
  background: rgba(34, 211, 238, 0.08);
  border-color: rgba(34, 211, 238, 0.35);
  color: #fff;
  transform: translateY(-1px);
}
.chat-suggestion-pill:active {
  transform: translateY(0);
  background: rgba(34, 211, 238, 0.14);
}

/* ── HOT TRENDING TAGS ROW ── */
.hot-tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.hot-tags-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: #f59e0b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 3px;
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.hot-tag-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  background: #f59e0b;
  border-radius: 50%;
  animation: hotPulse 1.5s ease-in-out infinite;
}
@keyframes hotPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.75); }
}
.hot-tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: 10px;
  color: #fbbf24;
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  font-family: Inter, system-ui, sans-serif;
}
.hot-tag:hover {
  background: rgba(245, 158, 11, 0.2);
  border-color: #f59e0b;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(245,158,11,0.15);
}
.hot-tag:active {
  transform: translateY(0);
}

/* ── SOURCE NEWS CARDS ROW (Vietnamese trust sources) ── */
.news-section {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.news-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #f59e0b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 7px;
}
.source-cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 5px;
}
.source-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  overflow: hidden;
}
.source-card:hover {
  border-color: rgba(34, 211, 238, 0.4);
  background: rgba(34, 211, 238, 0.06);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.source-card-source {
  font-size: 0.58rem;
  font-weight: 700;
  color: #22d3ee;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 3px;
}
.source-card-title {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.source-card-desc {
  font-size: 0.58rem;
  color: var(--text-dim);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.source-card-thumb-wrap {
  width: 100%;
  height: 70px;
  border-radius: 7px;
  overflow: hidden;
  background: rgba(255,255,255,0.05);
  flex-shrink: 0;
}
.source-card-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* ── Per-news suggested questions (ngữ cảnh cụ thể cho từng tin) ── */
.source-card-askai {
  margin-top: 4px;
  padding: 5px 8px;
  background: rgba(34, 211, 238, 0.12);
  border: 1px solid rgba(34, 211, 238, 0.35);
  border-radius: 7px;
  color: #22d3ee;
  font-size: 0.6rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.source-card-askai:hover {
  background: rgba(34, 211, 238, 0.25);
  color: #fff;
}
.news-q-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 4px;
}
.news-q-pill {
  padding: 4px 6px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 0.54rem;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}
.news-q-pill:hover {
  background: rgba(34, 211, 238, 0.14);
  color: #22d3ee;
  border-color: rgba(34, 211, 238, 0.4);
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Ask AI Button (product detail modal) ── */
.ask-ai-section {
  padding: 10px 16px 4px;
  display: block;
  border-top: 1px solid #e2e8f0;
  margin-top: 4px;
}
.ask-ai-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  background: linear-gradient(135deg, #6B21A8, #9333EA);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.2s;
  box-shadow: 0 2px 8px rgba(107,33,168,0.25);
}
.ask-ai-btn:hover {
  background: linear-gradient(135deg, #581c87, #7e22ce);
  box-shadow: 0 4px 16px rgba(107,33,168,0.35);
  transform: translateY(-1px);
}
.ask-ai-btn:active {
  transform: translateY(0);
}
.ask-ai-btn .btn-icon {
  font-size: 1rem;
}

/* ── Settings Dialog (HTML <dialog>) — full overlay + animation ── */
dialog#settings,
dialog.settings {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.92);
  width: min(460px, calc(100vw - 48px));
  max-height: 85vh;
  overflow-y: auto;
  padding: 28px 24px 20px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255,255,255,0.04) inset;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
  z-index: 99999;
}
dialog#settings[open],
dialog.settings[open] {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}
dialog#settings::backdrop,
dialog.settings::backdrop {
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
dialog#settings h2,
dialog.settings h2 {
  margin: 0 0 20px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}
dialog#settings label,
dialog.settings label {
  display: block;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}
dialog#settings select,
dialog.settings select,
dialog#settings textarea,
dialog.settings textarea,
dialog#settings input[type="url"],
dialog.settings input[type="url"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  transition: border-color 0.15s ease;
}
dialog#settings select:focus,
dialog.settings select:focus,
dialog#settings textarea:focus,
dialog.settings textarea:focus,
dialog#settings input:focus,
dialog.settings input:focus {
  outline: 1px solid var(--live);
  outline-offset: 1px;
  border-color: var(--live);
}
dialog#settings textarea {
  resize: vertical;
  min-height: 80px;
}
dialog#settings .check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
dialog#settings .check-row input {
  display: inline-block;
  width: auto;
  margin: 0;
  accent-color: var(--live);
  transform: scale(1.15);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.dialog-actions .primary {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.dialog-actions .primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

/* ── Draggable / Resizable Chat ───────────────────────────────────────────── */
#text-chat {
  position: fixed;
  z-index: 9999;
  top: 100px;
  left: 20px;
  width: min(380px, calc(100vw - 40px));
  height: 50vh;
  display: flex;
  flex-direction: column;
  background: rgba(10, 11, 16, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
  min-height: 2.5rem;
  max-height: 80vh;
  cursor: default;
  resize: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  touch-action: none;
}
#text-chat.dragging { cursor: grabbing !important; user-select: none !important; }
#text-chat.resizing { user-select: none !important; }

/* Chat header bar — drag handle */
#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  cursor: grab;
  flex-shrink: 0;
  touch-action: none;
}
#text-chat.dragging #chat-header { cursor: grabbing !important; }
#chat-title { font-size: 12px; font-weight: 600; color: var(--text-dim); letter-spacing: 0.04em; }
#chat-header-actions { display: flex; align-items: center; gap: 6px; pointer-events: auto; }
#chat-avatar-select { font-size: 11px; padding: 2px 6px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg-elev-2); color: var(--text); cursor: pointer; max-width: 100px; pointer-events: auto; }

#chat-messages { flex: 1; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
#chat-messages::-webkit-scrollbar { width: 6px; }
#chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.chat-message { max-width: 85%; padding: 8px 12px; border-radius: var(--radius-sm); font-size: 13px; line-height: 1.5; word-wrap: break-word; }
.chat-message.user { align-self: flex-end; background: var(--live); color: var(--bg); }
.chat-message.assistant { align-self: flex-start; background: var(--bg-elev-2); color: var(--text); border: 1px solid var(--border); position: relative; }
.chat-message .chat-read-btn { position:absolute; top:6px; right:6px; display:inline-flex; align-items:center; background:transparent; border:none; color:#64748b; cursor:pointer; padding:3px; border-radius:4px; opacity:0.55; line-height:1; transition:opacity 0.15s, color 0.15s; z-index:2 }
.chat-message .chat-read-btn:hover { opacity:1; color:#22d3ee }
.chat-message .chat-msg-text { padding-right:20px }
.chat-message.typing { display: inline-flex; align-items: center; gap: 6px; background: var(--bg-elev-2); color: var(--text-dim); }
.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim); animation: typing-blink 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: 0.2s; }
.typing-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-blink { 0%, 60%, 100% { opacity: 0.3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.chat-product-cards { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

#chat-input-container { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); background: var(--bg-elev); flex-shrink: 0; }
#chat-input { flex: 1; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); font-family: inherit; font-size: 13px; }
#chat-input:focus { outline: 1px solid var(--text-dim); outline-offset: 1px; }
#chat-mic-btn.active { color: var(--live); border-color: var(--border-strong); background: rgba(34,211,238,0.12); }

/* Resize handle at bottom-right corner — bigger, better contrast */
#chat-resize-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 24px;
  height: 24px;
  cursor: nwse-resize;
  background: transparent;
  z-index: 1;
  touch-action: none;
}
#chat-resize-handle::after {
  content: '';
  position: absolute;
  bottom: 3px;
  right: 3px;
  width: 14px;
  height: 14px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  opacity: 0.4;
  transition: opacity 0.15s;
}
#chat-resize-handle:hover::after { opacity: 1; }
#text-chat.resizing #chat-resize-handle::after { opacity: 1; }

@media (max-width: 600px) {
  #identity p { display: none; }
  #subtitles { bottom: 128px; font-size: 14px; }
  #text-chat { top: 60px; left: 10px; width: calc(100vw - 20px); height: 40vh; }
  /* Mobile: stack suggested pills vertically if too wide */
  #suggested-questions { flex-direction: column; align-items: stretch; width: 90%; max-width: 340px; }
}
/* SETTINGS-MODAL-FIX-V3-804 */
