/* =============================================
   ChatATG — Chat UI Redesign v1.0
   "Refined Darkness" — สะอาด เบา หายใจได้
   ใส่หลัง style.css เดิม
   ============================================= */

/* ─────────────────────────────────────────
   GLOBAL BASE OVERRIDE
───────────────────────────────────────── */
:root {
  --chat-bg: #07080f;
  --msg-max:  720px;
}

body {
  background: var(--chat-bg) !important;
}
body::before {
  /* subtle ambient — ไม่โชว์มากจนฟุ้ง */
  background: 
    radial-gradient(ellipse 55% 35% at 18% 8%,  rgba(99,179,237,0.05) 0%, transparent 70%),
    radial-gradient(ellipse 40% 40% at 82% 92%, rgba(129,140,248,0.04) 0%, transparent 70%) !important;
}

/* ─────────────────────────────────────────
   TOPBAR — ลดความหนาลง
───────────────────────────────────────── */
.topbar {
  border-bottom: 1px solid rgba(255,255,255,0.04) !important;
  background: rgba(7,8,15,0.8) !important;
  backdrop-filter: blur(12px) !important;
  padding: 10px 22px !important;
}
.app-logo-text {
  font-size: 0.95rem !important;
  font-weight: 600 !important;
  letter-spacing: -0.02em !important;
  color: #e8ecff !important;
}

/* ─────────────────────────────────────────
   WELCOME SCREEN — Grok-inspired minimal
───────────────────────────────────────── */
.welcome-screen {
  background: transparent !important;
  gap: 0 !important;
}

.welcome-content {
  animation: wFadeUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) both !important;
}

@keyframes wFadeUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}

.welcome-title {
  font-size: clamp(1.9rem, 4.5vw, 2.8rem) !important;
  font-weight: 500 !important;
  color: #dde3ff !important;
  letter-spacing: -0.045em !important;
  line-height: 1.1 !important;
  margin-bottom: 8px !important;
}
.welcome-title strong {
  font-weight: 700 !important;
  background: linear-gradient(120deg, #63b3ed, #a78bfa 60%, #63b3ed);
  background-size: 200%;
  -webkit-background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  background-clip: text !important;
  animation: shimmer 4s linear infinite;
}
@keyframes shimmer {
  0%   { background-position: 0% center; }
  100% { background-position: 200% center; }
}

.welcome-sub {
  font-size: 0.9rem !important;
  color: rgba(110,120,155,0.9) !important;
  letter-spacing: 0 !important;
  margin-bottom: 0 !important;
}

/* Suggestion chips — Grok-like pills */
.suggestion-chips-container {
  margin-top: 28px !important;
  animation: wFadeUp 0.6s 0.12s cubic-bezier(0.22, 1, 0.36, 1) both !important;
}
.suggestion-grid {
  display: flex !important;
  flex-wrap: wrap !important;
  justify-content: center !important;
  gap: 8px !important;
  width: 100% !important;
}
.suggestion-chip {
  padding: 8px 16px !important;
  background: rgba(255,255,255,0.04) !important;
  border: 1px solid rgba(255,255,255,0.08) !important;
  border-radius: 99px !important;    /* pill shape */
  color: rgba(160,170,210,0.9) !important;
  font-size: 0.84rem !important;
  font-weight: 450 !important;
  cursor: pointer !important;
  text-align: center !important;
  line-height: 1.3 !important;
  white-space: nowrap !important;
  transition: all 0.18s ease !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 6px !important;
}
.suggestion-chip span[style] {
  display: none !important; /* ซ่อน sub-text ใต้ chip */
}
.suggestion-chip:hover {
  background: rgba(99,179,237,0.1) !important;
  border-color: rgba(99,179,237,0.28) !important;
  color: #63b3ed !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 6px 20px rgba(99,179,237,0.12) !important;
}

/* ─────────────────────────────────────────
   CHAT AREA
───────────────────────────────────────── */
.chat-area {
  background: var(--chat-bg) !important;
}

/* ─────────────────────────────────────────
   MESSAGES CONTAINER
───────────────────────────────────────── */
.messages-container {
  max-width: var(--msg-max) !important;
  padding: 32px 24px 16px !important;
  gap: 0 !important;
}

/* ─────────────────────────────────────────
   USER MESSAGE — subtle pill, no heavy bubble
───────────────────────────────────────── */
.user-message {
  padding: 16px 0 4px !important;
}
.user-message .msg-content-wrapper {
  max-width: 80% !important;
  align-items: flex-end !important;
}
.user-message .msg-body {
  background: rgba(255,255,255,0.055) !important;
  border: 1px solid rgba(255,255,255,0.09) !important;
  border-radius: 22px 22px 4px 22px !important;
  padding: 11px 18px !important;
  color: #dde3ff !important;
  font-size: 0.94rem !important;
  line-height: 1.65 !important;
  box-shadow: none !important;
}
.user-message .msg-body:hover {
  background: rgba(255,255,255,0.07) !important;
  border-color: rgba(255,255,255,0.13) !important;
}

/* User actions */
.user-actions {
  opacity: 0 !important;
  transform: translateY(4px) !important;
  transition: opacity 0.18s, transform 0.18s !important;
  margin-top: 4px !important;
}
.user-message:hover .user-actions {
  opacity: 1 !important;
  transform: translateY(0) !important;
}

/* ─────────────────────────────────────────
   AI MESSAGE — text-first, no bubble
───────────────────────────────────────── */
.ai-message {
  padding: 18px 0 4px !important;
  gap: 14px !important;
  background: transparent !important;
  border-radius: 0 !important;
  position: relative !important;
}
.ai-message + .ai-message {
  padding-top: 6px !important;
}

/* Avatar — เล็กลง มีกรอบ glow นิดหน่อย */
.msg-avatar.ai-avatar {
  width: 26px !important;
  height: 26px !important;
  border-radius: 8px !important;
  background: rgba(99,179,237,0.06) !important;
  border: 1px solid rgba(99,179,237,0.18) !important;
  padding: 3px !important;
  margin-top: 4px !important;
  flex-shrink: 0 !important;
  box-shadow: 0 0 12px rgba(99,179,237,0.08) !important;
}
.msg-avatar.ai-avatar img {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
  border-radius: 5px !important;
  opacity: 0.9 !important;
}

/* AI body text */
.ai-message .msg-body {
  font-size: 0.96rem !important;
  line-height: 1.82 !important;
  color: #cdd5f0 !important;
  letter-spacing: -0.005em !important;
  font-weight: 400 !important;
}

/* Headings in AI response */
.ai-message .msg-body h1,
.ai-message .msg-body h2,
.ai-message .msg-body h3 {
  color: #e8ecff !important;
  font-weight: 650 !important;
  letter-spacing: -0.03em !important;
  margin: 1.2em 0 0.5em !important;
}

/* ─────────────────────────────────────────
   META / SEARCH INDICATOR
───────────────────────────────────────── */
.msg-meta {
  margin-bottom: 6px !important;
}

/* ─────────────────────────────────────────
   MESSAGE ACTIONS — Grok-style action row
───────────────────────────────────────── */
.msg-actions {
  display: flex !important;
  align-items: center !important;
  gap: 2px !important;
  margin-top: 10px !important;
  opacity: 0 !important;
  transform: translateY(4px) !important;
  transition: opacity 0.2s ease, transform 0.2s ease !important;
  flex-wrap: nowrap !important;
  overflow: hidden !important;
}
.ai-message:hover .msg-actions {
  opacity: 1 !important;
  transform: translateY(0) !important;
}

/* Action buttons */
.msg-action-btn {
  display: flex !important;
  align-items: center !important;
  gap: 5px !important;
  padding: 5px 9px !important;
  border-radius: 8px !important;
  font-size: 0.76rem !important;
  color: rgba(100,110,145,0.9) !important;
  border: none !important;
  background: transparent !important;
  font-weight: 500 !important;
  transition: all 0.14s ease !important;
  white-space: nowrap !important;
}
.msg-action-btn:hover {
  background: rgba(255,255,255,0.06) !important;
  color: #e8ecff !important;
}
.msg-action-btn svg {
  opacity: 0.7 !important;
  flex-shrink: 0 !important;
}
.msg-action-btn:hover svg { opacity: 1 !important; }

/* Rating buttons */
.rating-actions {
  display: flex !important;
  gap: 1px !important;
  margin-right: 6px !important;
  padding-right: 6px !important;
  border-right: 1px solid rgba(255,255,255,0.07) !important;
}
.rate-btn { border-radius: 7px !important; }
.rate-btn.active { color: #63b3ed !important; background: rgba(99,179,237,0.08) !important; }
.rate-btn.active svg { fill: #63b3ed !important; opacity: 1 !important; }

/* Version switcher */
.version-switcher {
  display: flex !important;
  align-items: center !important;
  gap: 3px !important;
  margin-right: 4px !important;
}
.v-counter-text {
  font-size: 0.7rem !important;
  color: rgba(90,100,140,0.9) !important;
  font-family: var(--mono) !important;
  letter-spacing: 0.03em !important;
}
.v-switch-btn {
  width: 20px !important; height: 20px !important;
  color: rgba(100,110,145,0.8) !important;
  border-radius: 5px !important;
}
.v-switch-btn:hover:not(:disabled) {
  background: rgba(255,255,255,0.07) !important;
  color: #e8ecff !important;
}

/* Regenerate button highlight */
.regenerate-btn:hover {
  background: rgba(99,179,237,0.08) !important;
  color: #63b3ed !important;
}
.copy-btn:hover {
  background: rgba(52,211,153,0.08) !important;
  color: #34d399 !important;
}

/* ─────────────────────────────────────────
   CODE BLOCKS — signature ChatATG style
───────────────────────────────────────── */
.msg-body pre {
  background: #0a0b14 !important;
  border: 1px solid rgba(255,255,255,0.07) !important;
  border-radius: 14px !important;
  padding: 0 !important;
  overflow: hidden !important;
  margin: 14px 0 !important;
  box-shadow: 0 4px 24px rgba(0,0,0,0.35) !important;
  position: relative !important;
}

/* Code header bar */
.msg-body pre::before {
  content: attr(data-lang);
  display: flex;
  align-items: center;
  padding: 8px 16px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(90,110,160,0.9);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-family: var(--mono, monospace);
  min-height: 34px;
}

/* code content padding */
.msg-body pre code {
  display: block !important;
  padding: 16px !important;
  font-size: 0.85rem !important;
  line-height: 1.7 !important;
  font-family: var(--mono, monospace) !important;
  color: #c8d3f5 !important;
  background: none !important;
  border: none !important;
}

/* Copy + view buttons on code */
.code-actions-sticky {
  position: sticky !important;
  top: 8px !important;
  float: right !important;
  display: flex !important;
  gap: 5px !important;
  z-index: 10 !important;
  margin: 8px 10px !important;
  /* offset from top of pre::before bar */
  margin-top: -30px !important;
}
.copy-code-btn {
  width: 28px !important; height: 28px !important;
  border-radius: 8px !important;
  background: rgba(255,255,255,0.07) !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  color: rgba(120,140,190,0.9) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  cursor: pointer !important;
  transition: all 0.15s !important;
  position: static !important;
  backdrop-filter: blur(6px) !important;
}
.copy-code-btn:hover {
  background: rgba(99,179,237,0.15) !important;
  border-color: rgba(99,179,237,0.3) !important;
  color: #63b3ed !important;
}

/* Inline code */
.msg-body code {
  font-family: var(--mono, monospace) !important;
  font-size: 0.83em !important;
  background: rgba(99,179,237,0.08) !important;
  border: 1px solid rgba(99,179,237,0.14) !important;
  padding: 2px 7px !important;
  border-radius: 6px !important;
  color: #93c5fd !important;
}

/* ─────────────────────────────────────────
   THINKING / STREAMING
───────────────────────────────────────── */
.thinking-dots {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  padding: 8px 0 !important;
}
.thinking-dots span {
  width: 5px !important; height: 5px !important;
  border-radius: 50% !important;
  background: #63b3ed !important;
  animation: tDot 1.4s ease-in-out infinite !important;
  opacity: 0.35 !important;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.16s !important; background: #818cf8 !important; }
.thinking-dots span:nth-child(3) { animation-delay: 0.32s !important; background: #a78bfa !important; }
@keyframes tDot {
  0%, 60%, 100% { transform: translateY(0) scale(1); opacity: 0.35; }
  30% { transform: translateY(-6px) scale(1.15); opacity: 1; }
}

.streaming-cursor::after {
  content: '▌' !important;
  color: #63b3ed !important;
  opacity: 0.8 !important;
  animation: cursorBlink 0.85s step-end infinite !important;
  margin-left: 1px !important;
}
@keyframes cursorBlink {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 0; }
}

/* Thinking details */
.thinking-details {
  background: rgba(99,179,237,0.03) !important;
  border: 1px solid rgba(99,179,237,0.1) !important;
  border-radius: 12px !important;
  margin: 10px 0 !important;
}
.thinking-summary {
  color: rgba(99,179,237,0.7) !important;
  font-size: 0.79rem !important;
  padding: 8px 14px !important;
}
.thinking-content {
  color: rgba(130,145,185,0.9) !important;
  font-size: 0.845rem !important;
  padding: 10px 16px 14px !important;
  border-top: 1px solid rgba(99,179,237,0.08) !important;
}

/* ─────────────────────────────────────────
   INPUT AREA — ลดความอ้วน เพิ่มความสวย
───────────────────────────────────────── */
.input-area {
  padding: 6px 24px 20px !important;
}
body.home-view .input-area {
  padding: 16px 24px 0 !important;
}

.input-wrapper {
  background: rgba(255,255,255,0.04) !important;
  border: 1px solid rgba(255,255,255,0.09) !important;
  border-radius: 24px !important;
  padding: 12px 14px 10px !important;
  max-width: 680px !important;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.02) inset,
    0 4px 28px rgba(0,0,0,0.22) !important;
  transition: border-color 0.22s, box-shadow 0.22s, background 0.22s !important;
}
.input-wrapper:focus-within {
  border-color: rgba(99,179,237,0.32) !important;
  background: rgba(99,179,237,0.03) !important;
  box-shadow:
    0 0 0 1px rgba(99,179,237,0.06) inset,
    0 4px 28px rgba(0,0,0,0.26),
    0 0 0 4px rgba(99,179,237,0.055) !important;
}

#messageInput {
  color: #e0e6ff !important;
  font-size: 0.95rem !important;
  line-height: 1.62 !important;
  padding: 0 6px 10px !important;
  caret-color: #63b3ed !important;
}
#messageInput::placeholder {
  color: rgba(80,90,125,0.9) !important;
}

.input-bottom-row {
  border-top: 1px solid rgba(255,255,255,0.05) !important;
  padding-top: 7px !important;
}

/* Input tool buttons */
.btn-circle-add {
  background: rgba(255,255,255,0.05) !important;
  border: 1px solid rgba(255,255,255,0.09) !important;
  color: rgba(120,135,175,0.9) !important;
}
.btn-circle-add:hover {
  background: rgba(255,255,255,0.1) !important;
  color: #e0e6ff !important;
  border-color: rgba(255,255,255,0.16) !important;
}

.btn-pill-tools {
  background: rgba(255,255,255,0.04) !important;
  border: 1px solid rgba(255,255,255,0.08) !important;
  color: rgba(110,120,160,0.9) !important;
  font-size: 0.77rem !important;
  border-radius: 99px !important;
}
.btn-pill-tools:hover {
  background: rgba(99,179,237,0.09) !important;
  color: #63b3ed !important;
  border-color: rgba(99,179,237,0.22) !important;
}

.model-selector-pill {
  background: rgba(255,255,255,0.04) !important;
  border: 1px solid rgba(255,255,255,0.08) !important;
  color: rgba(110,120,160,0.9) !important;
  font-size: 0.77rem !important;
  border-radius: 99px !important;
  padding: 5px 12px !important;
}
.model-selector-pill:hover {
  background: rgba(99,179,237,0.09) !important;
  color: #63b3ed !important;
  border-color: rgba(99,179,237,0.22) !important;
}

/* Send button */
.send-btn {
  width: 32px !important; height: 32px !important;
  background: linear-gradient(135deg, #63b3ed 0%, #818cf8 100%) !important;
  box-shadow: 0 3px 14px rgba(99,179,237,0.3) !important;
}
.send-btn:not(:disabled):hover {
  box-shadow: 0 6px 22px rgba(99,179,237,0.48) !important;
  transform: scale(1.08) !important;
}

/* Mic button */
.btn-icon-mic {
  color: rgba(110,120,160,0.9) !important;
}
.btn-icon-mic:hover {
  background: rgba(255,255,255,0.06) !important;
  color: #e0e6ff !important;
}

/* ─────────────────────────────────────────
   SCROLL TO BOTTOM BTN
───────────────────────────────────────── */
.scroll-to-bottom-btn {
  background: rgba(10,12,22,0.92) !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), 0 0 0 1px rgba(99,179,237,0.08) !important;
  color: rgba(120,140,185,0.9) !important;
}
.scroll-to-bottom-btn:hover {
  border-color: rgba(99,179,237,0.3) !important;
  color: #63b3ed !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), 0 0 12px rgba(99,179,237,0.12) !important;
}

/* ─────────────────────────────────────────
   ATTACHMENT PREVIEW
───────────────────────────────────────── */
.file-card {
  background: rgba(255,255,255,0.03) !important;
  border: 1px solid rgba(255,255,255,0.08) !important;
  border-radius: 14px !important;
}
.file-preview-icon {
  background: rgba(99,179,237,0.08) !important;
  border-radius: 10px !important;
}

/* ─────────────────────────────────────────
   CHAT MEDIA CARDS
───────────────────────────────────────── */
.chat-media-card {
  border-radius: 14px !important;
  border: 1px solid rgba(255,255,255,0.08) !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3) !important;
}
.chat-media-card:hover {
  border-color: rgba(99,179,237,0.25) !important;
  box-shadow: 0 6px 28px rgba(0,0,0,0.4) !important;
}

/* ─────────────────────────────────────────
   GENERATED MEDIA
───────────────────────────────────────── */
.generated-media {
  border-radius: 16px !important;
  border: 1px solid rgba(255,255,255,0.07) !important;
  box-shadow: 0 12px 40px rgba(0,0,0,0.45) !important;
  transition: transform 0.2s, box-shadow 0.2s !important;
}
.generated-media:hover {
  transform: scale(1.01) !important;
  box-shadow: 0 16px 50px rgba(0,0,0,0.55) !important;
}

.generated-media-container .media-overlay {
  background: rgba(0,0,0,0.5) !important;
  backdrop-filter: blur(8px) !important;
  border-radius: 10px !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  padding: 5px !important;
}

/* ─────────────────────────────────────────
   EDIT MODE
───────────────────────────────────────── */
.edit-container {
  background: rgba(99,179,237,0.04) !important;
  border: 1px solid rgba(99,179,237,0.2) !important;
  border-radius: 18px !important;
}
.edit-textarea {
  color: #e0e6ff !important;
  font-size: 0.94rem !important;
}

/* ─────────────────────────────────────────
   POPOVER MENUS
───────────────────────────────────────── */
.popover-menu {
  background: rgba(9,10,20,0.98) !important;
  backdrop-filter: blur(28px) saturate(1.8) !important;
  border: 1px solid rgba(255,255,255,0.1) !important;
  border-radius: 18px !important;
  padding: 6px !important;
  box-shadow:
    0 28px 64px rgba(0,0,0,0.7),
    0 0 0 1px rgba(255,255,255,0.02) inset !important;
}
.popover-item {
  border-radius: 11px !important;
  color: rgba(160,170,210,0.9) !important;
  padding: 9px 13px !important;
  font-size: 0.855rem !important;
}
.popover-item:hover {
  background: rgba(255,255,255,0.06) !important;
  color: #e8ecff !important;
}
.popover-item:hover svg { color: #63b3ed !important; }
.popover-item.active {
  background: rgba(99,179,237,0.1) !important;
  border: 1px solid rgba(99,179,237,0.15) !important;
}
.popover-item.active .pi-title { color: #63b3ed !important; }
.pi-title { color: #dde3ff !important; font-size: 0.875rem !important; }
.pi-desc  { color: rgba(90,100,140,0.9) !important; font-size: 0.73rem !important; }

/* ─────────────────────────────────────────
   RESPONSIVE — MOBILE CHAT
───────────────────────────────────────── */
@media (max-width: 768px) {
  .messages-container {
    padding: 18px 14px 10px !important;
  }
  .user-message .msg-content-wrapper { max-width: 90% !important; }
  .input-area { padding: 6px 12px 18px !important; }
  .input-wrapper { padding: 11px 12px 9px !important; border-radius: 20px !important; }
  .suggestion-grid { gap: 6px !important; }
  .suggestion-chip {
    padding: 7px 14px !important;
    font-size: 0.82rem !important;
  }
  .ai-message { gap: 10px !important; }
  .msg-avatar.ai-avatar { width: 22px !important; height: 22px !important; }
  .msg-actions { gap: 1px !important; }
  .msg-action-btn { padding: 5px 7px !important; font-size: 0.73rem !important; }
}

@media (max-width: 480px) {
  .welcome-title { font-size: 1.7rem !important; }
  .input-wrapper { border-radius: 18px !important; }
  .model-selector-pill, .btn-pill-tools { font-size: 0.72rem !important; padding: 4px 9px !important; }
}