/* ── Chat Layout ─────────────────────────────────────────────────────────── */
.chat-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: calc(100vh - 70px);
  gap: 0;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.chat-sidebar {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 8px;
  overflow-y: auto;
}

.chat-new-btn {
  width: 100%;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  border: none;
  border-radius: 10px;
  color: white;
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}
.chat-new-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(79, 70, 229, 0.4);
}

.chat-session-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.chat-session-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  position: relative;
  transition: background 0.15s;
  border: 1px solid transparent;
}
.chat-session-item:hover {
  background: var(--bg-card);
  border-color: var(--border-glass);
}
.chat-session-item.active {
  background: rgba(79, 70, 229, 0.12);
  border-color: rgba(79, 70, 229, 0.3);
}

.chat-session-title {
  font-size: 0.8rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 20px;
}
.chat-session-meta {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.chat-session-delete {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.15s;
}
.chat-session-item:hover .chat-session-delete { opacity: 1; }
.chat-session-delete:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

/* ── Main Chat Area ─────────────────────────────────────────────────────── */
.chat-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.chat-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border-glass);
  background: rgba(15, 21, 36, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  gap: 16px;
  flex-wrap: wrap;
}

/* ── Brand Selector ─────────────────────────────────────────────────────── */
.chat-brand-selector {
  display: flex;
  gap: 6px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 4px;
}

.chat-brand-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.chat-brand-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--text-primary);
}

.chat-brand-btn.active {
  background: rgba(79, 70, 229, 0.18);
  border-color: rgba(79, 70, 229, 0.4);
  color: #818cf8;
  font-weight: 600;
}

.chat-brand-btn[data-brand="thi"].active {
  background: rgba(79, 70, 229, 0.18);
  border-color: rgba(79, 70, 229, 0.4);
  color: #818cf8;
}

.chat-brand-btn[data-brand="khastana"].active {
  background: rgba(14, 165, 233, 0.15);
  border-color: rgba(14, 165, 233, 0.4);
  color: #38bdf8;
}

.chat-brand-btn[data-brand="all"].active {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}

.chat-agent-info { display: flex; align-items: center; gap: 12px; }

.chat-agent-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4F46E5, #7C3AED);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Outfit', sans-serif;
  font-weight: 800;
  font-size: 1rem;
  color: white;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.3);
  flex-shrink: 0;
}

.chat-agent-name {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
}
.chat-agent-sub  { font-size: 0.72rem; color: var(--text-secondary); }
.chat-header-actions { display: flex; align-items: center; gap: 6px; }

/* ── Messages ────────────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Custom scrollbar */
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(79, 70, 229, 0.25);
  border-radius: 10px;
}
.chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(79, 70, 229, 0.45); }

/* ── Welcome State ─────────────────────────────────────────────────────── */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 20px;
  text-align: center;
  min-height: 100%;
}

.chat-welcome-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, #4F46E5, #7C3AED);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Outfit', sans-serif;
  font-weight: 900;
  font-size: 2rem;
  color: white;
  margin-bottom: 20px;
  box-shadow: 0 0 0 6px rgba(79, 70, 229, 0.15), 0 8px 32px rgba(79, 70, 229, 0.3);
  animation: avatarPulse 3s ease-in-out infinite;
}

@keyframes avatarPulse {
  0%, 100% {
    box-shadow: 0 0 0 6px rgba(79, 70, 229, 0.15), 0 8px 32px rgba(79, 70, 229, 0.3);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(79, 70, 229, 0.08), 0 8px 40px rgba(79, 70, 229, 0.4);
  }
}

.chat-welcome-title {
  font-family: 'Outfit', sans-serif;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0 0 8px;
}
.chat-welcome-sub {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin: 0 0 32px;
}

.chat-suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 520px;
  width: 100%;
}

.chat-suggestion {
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 0.82rem;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  font-family: 'Inter', sans-serif;
  line-height: 1.4;
}
.chat-suggestion:hover {
  border-color: rgba(79, 70, 229, 0.4);
  background: rgba(79, 70, 229, 0.08);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.15);
}

/* ── Message Bubbles ────────────────────────────────────────────────────── */
.chat-message {
  display: flex;
  gap: 12px;
  animation: msgFadeIn 0.3s ease;
}

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

.chat-message-user      { justify-content: flex-end; }
.chat-message-assistant { justify-content: flex-start; }

.chat-bubble {
  max-width: 72%;
  padding: 14px 18px;
  border-radius: 18px;
  font-size: 0.875rem;
  line-height: 1.7;
  position: relative;
  word-break: break-word;
}

.chat-bubble-user {
  background: linear-gradient(135deg, #4F46E5, #7C3AED);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-bubble-assistant {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

/* ── Markdown inside assistant bubble ──────────────────────────────────── */
.chat-bubble-assistant h1,
.chat-bubble-assistant h2,
.chat-bubble-assistant h3 {
  font-family: 'Outfit', sans-serif;
  margin: 12px 0 6px;
  color: var(--text-primary);
}
.chat-bubble-assistant h1 { font-size: 1.15rem; }
.chat-bubble-assistant h2 { font-size: 1.05rem; }
.chat-bubble-assistant h3 { font-size: 0.95rem; }

.chat-bubble-assistant p  { margin: 0 0 10px; }
.chat-bubble-assistant p:last-child { margin-bottom: 0; }
.chat-bubble-assistant ul,
.chat-bubble-assistant ol { padding-left: 20px; margin: 8px 0; }
.chat-bubble-assistant li { margin-bottom: 4px; }
.chat-bubble-assistant strong { color: #A78BFA; font-weight: 600; }
.chat-bubble-assistant em { color: #C4B5FD; }
.chat-bubble-assistant a { color: #818CF8; text-decoration: underline; }

.chat-bubble-assistant code {
  background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: 'Fira Code', 'Courier New', monospace;
  color: #A5F3FC;
}
.chat-bubble-assistant pre {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-glass);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
}
.chat-bubble-assistant pre code {
  background: none;
  padding: 0;
  color: #A5F3FC;
  font-size: 0.82rem;
}

.chat-bubble-assistant table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 0.82rem;
}
.chat-bubble-assistant th,
.chat-bubble-assistant td {
  padding: 8px 12px;
  border: 1px solid var(--border-glass);
  text-align: left;
}
.chat-bubble-assistant th {
  background: rgba(79, 70, 229, 0.15);
  color: #A78BFA;
  font-weight: 600;
  font-family: 'Outfit', sans-serif;
}
.chat-bubble-assistant tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

blockquote.chat-bubble-assistant {
  border-left: 3px solid #4F46E5;
  padding-left: 12px;
  color: var(--text-secondary);
  margin: 8px 0;
}

/* ── Typing Indicator ───────────────────────────────────────────────────── */
.chat-typing {
  display: flex;
  gap: 5px;
  padding: 6px 2px;
  align-items: center;
}
.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #818CF8;
  animation: typingBounce 1.2s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
  30% { transform: translateY(-8px); opacity: 1; }
}

/* ── Streaming Cursor ───────────────────────────────────────────────────── */
.chat-cursor {
  display: inline-block;
  animation: cursorBlink 1s ease-in-out infinite;
  color: #818CF8;
  font-weight: 300;
  margin-left: 1px;
}
@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ── Copy Button ────────────────────────────────────────────────────────── */
.chat-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-glass);
  border-radius: 6px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 5px 7px;
  opacity: 0;
  transition: all 0.2s;
  font-size: 0.72rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  min-height: 28px;
}
.chat-bubble-assistant:hover .chat-copy-btn { opacity: 1; }
.chat-copy-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(79, 70, 229, 0.4);
}

/* ── Input Area ─────────────────────────────────────────────────────────── */
.chat-input-area {
  padding: 16px 24px 20px;
  background: rgba(15, 21, 36, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-glass);
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 10px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-input-wrapper:focus-within {
  border-color: rgba(79, 70, 229, 0.5);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  line-height: 1.6;
  resize: none;
  min-height: 24px;
  max-height: 200px;
  overflow-y: auto;
}
.chat-input::placeholder { color: var(--text-secondary); }

.chat-input::-webkit-scrollbar { width: 3px; }
.chat-input::-webkit-scrollbar-thumb { background: rgba(79, 70, 229, 0.3); border-radius: 10px; }

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, #4F46E5, #7C3AED);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}
.chat-send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
}
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.chat-input-hint {
  font-size: 0.7rem;
  color: var(--text-secondary);
  margin-top: 8px;
  text-align: center;
}

/* ── Scrollbar for sidebar ──────────────────────────────────────────────── */
.chat-sidebar::-webkit-scrollbar { width: 4px; }
.chat-sidebar::-webkit-scrollbar-track { background: transparent; }
.chat-sidebar::-webkit-scrollbar-thumb {
  background: rgba(79, 70, 229, 0.2);
  border-radius: 10px;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }
  .chat-sidebar { display: none; }
  .chat-suggestions { grid-template-columns: 1fr; }
  .chat-bubble { max-width: 90%; }
  .chat-messages { padding: 16px; }
  .chat-input-area { padding: 12px 16px 16px; }
}
