/* ===== Chat Layout ===== */
.chat-body {
  overflow: hidden;
  height: 100vh;
}

.chat-layout {
  display: flex;
  height: 100vh;
  background: var(--bg);
}

/* ===== Sidebar ===== */
.chat-sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.chat-sidebar.collapsed {
  transform: translateX(-100%);
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header .nav-brand {
  font-size: 0.95rem;
}

.new-chat-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.15s;
}
.new-chat-btn:hover { opacity: 0.85; }

.sidebar-search {
  padding: 12px 16px;
}
.sidebar-search input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
}
.sidebar-search input::placeholder { color: var(--muted); }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.conv-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 12px 8px 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  text-align: left;
  transition: background 0.15s;
  margin-bottom: 2px;
}
.conv-item:hover { background: rgba(255,255,255,0.04); }
.conv-item.active { background: rgba(88,166,255,0.1); color: var(--accent); }

.conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-time {
  font-size: 0.7rem;
  color: var(--muted);
  margin-left: 8px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 8px;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.status-dot.connected { background: var(--accent-green); }

.sidebar-nav {
  display: flex;
  gap: 12px;
}
.sidebar-nav a {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
}
.sidebar-nav a:hover { color: var(--accent); }

/* ===== Main Chat Area ===== */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
.sidebar-toggle:hover { color: var(--text); background: rgba(255,255,255,0.04); }

.chat-title {
  font-size: 0.95rem;
  font-weight: 600;
  flex: 1;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,0.04); }

/* ===== Messages ===== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
}

/* Welcome screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 40px 20px;
}
.welcome-icon svg {
  width: 56px;
  height: 56px;
  margin-bottom: 16px;
}
.welcome-screen h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}
.welcome-screen > p {
  color: var(--muted);
  max-width: 400px;
  margin-bottom: 32px;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  width: 100%;
  max-width: 640px;
}

.suggestion-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text);
}
.suggestion-card:hover {
  border-color: var(--accent);
  background: rgba(88,166,255,0.05);
}
.suggestion-icon {
  font-size: 1.3rem;
  margin-bottom: 8px;
}
.suggestion-label {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 4px;
}
.suggestion-desc {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Message bubbles */
.message {
  max-width: 720px;
  margin-bottom: 20px;
  animation: msgFadeIn 0.3s ease;
}
.message.user {
  align-self: flex-end;
}
.message.assistant {
  align-self: flex-start;
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}
.message.user .message-avatar {
  background: var(--accent-purple);
  color: var(--bg);
}
.message.assistant .message-avatar {
  background: var(--accent);
  color: var(--bg);
}
.message-sender {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.message-body {
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.65;
}
.message.user .message-body {
  background: rgba(88,166,255,0.1);
  border: 1px solid rgba(88,166,255,0.2);
  border-bottom-right-radius: 4px;
}
.message.assistant .message-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-body code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  background: rgba(0,0,0,0.3);
  padding: 2px 6px;
  border-radius: 4px;
}

.message-body pre {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 10px 0;
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  line-height: 1.5;
}
.message-body pre code {
  background: none;
  padding: 0;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  font-size: 0.7rem;
  color: var(--muted);
}

.meta-tag {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
}
.meta-tag.pbi { background: rgba(88,166,255,0.15); color: var(--accent); }
.meta-tag.snowflake { background: rgba(63,185,80,0.15); color: var(--accent-green); }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px 18px;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

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

/* ===== Input Area ===== */
.chat-input-area {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-form {
  max-width: 720px;
  margin: 0 auto;
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 12px;
  transition: border-color 0.15s;
}
.chat-input-wrapper:focus-within {
  border-color: var(--accent);
}

.chat-input-wrapper textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  resize: none;
  min-height: 24px;
  max-height: 160px;
  line-height: 1.5;
  outline: none;
}
.chat-input-wrapper textarea::placeholder { color: var(--muted); }

.send-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 10px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.3; cursor: default; }
.send-btn:not(:disabled):hover { opacity: 0.85; }

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

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .chat-sidebar {
    position: absolute;
    z-index: 100;
    height: 100vh;
  }
  .chat-sidebar:not(.collapsed) {
    box-shadow: 4px 0 24px rgba(0,0,0,0.4);
  }
  .suggestion-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 480px) {
  .suggestion-grid {
    grid-template-columns: 1fr;
  }
  .chat-messages { padding: 12px; }
  .chat-input-area { padding: 8px 12px 12px; }
}

/* ===== LLM Switcher (dropdown + gear) ===== */
.llm-switcher {
  display: flex;
  align-items: center;
  gap: 4px;
}

.llm-dropdown {
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
  appearance: auto;
}
.llm-dropdown:focus { border-color: var(--accent); }
.llm-dropdown--mock   { border-color: var(--border); color: var(--text-muted); }
.llm-dropdown--gemini { border-color: rgba(88,166,255,0.5); color: var(--accent); }
.llm-dropdown--groq   { border-color: rgba(240,136,62,0.5); color: var(--accent-orange); }

/* ===== Provider meta tags ===== */
.meta-tag.gemini { background: rgba(88,166,255,0.15); color: var(--accent); }
.meta-tag.groq { background: rgba(240,136,62,0.15); color: var(--accent-orange); }
.meta-tag.mock { background: rgba(139,148,158,0.15); color: var(--text-muted); }

/* ===== LLM Settings Modal ===== */
.llm-settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.llm-settings-panel {
  background: var(--bg-card, #0d1117);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 420px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.llm-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.llm-settings-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-bright, #f0f6fc);
}
.llm-settings-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.llm-settings-close:hover { color: var(--text); }

.llm-settings-body {
  padding: 20px 24px 24px;
}

.llm-field-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  margin-top: 16px;
}
.llm-field-label:first-child { margin-top: 0; }

.llm-select, .llm-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg, #090c10);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.15s;
}
.llm-select:focus, .llm-input:focus { border-color: var(--accent); }
.llm-select { cursor: pointer; }

.llm-help-link {
  display: inline-block;
  font-size: 0.75rem;
  margin-top: 6px;
  color: var(--accent);
}

.llm-settings-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}
.llm-settings-actions .btn { flex: 1; justify-content: center; }

.llm-test-btn { font-size: 0.8rem !important; }

.llm-test-result {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 20px;
}
.llm-test-result.success { color: var(--accent-green); }
.llm-test-result.error { color: var(--accent-red, #f85149); }

/* Provider sections inside modal */
.llm-provider-section {
  padding: 0;
}
.llm-provider-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-bright, #f0f6fc);
  margin-bottom: 4px;
  margin-top: 4px;
}
.llm-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.llm-dot.gemini { background: var(--accent); }
.llm-dot.groq   { background: var(--accent-orange); }

.llm-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}
