
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #1A1A1A;
  --surface:  #212121;
  --surface2: #2A2A2A;
  --surface3: #333333;
  --border:   rgba(255,255,255,0.08);
  --border2:  rgba(255,255,255,0.12);
  --text:     #E8E8E8;
  --text-dim: #8A8A8A;
  --text-faint: #555;
  --orange:   #FF8C00;
  --orange-dim: rgba(255,140,0,0.15);
  --orange-hover: rgba(255,140,0,0.08);
  --sans: 'DM Sans', system-ui, sans-serif;
  --mono: 'DM Mono', monospace;
  --sidebar-w: 260px;
  --radius: 12px;
}

html, body { height: 100%; overflow: hidden; }
body { font-family: var(--sans); background: var(--bg); color: var(--text); font-size: 14px; display: flex; }

/* ═══════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  transition: width 0.25s ease, min-width 0.25s ease;
}
.sidebar.collapsed { width: 0; min-width: 0; border-right: none; }

.sidebar-top {
  padding: 16px 12px 12px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.logo {
  display: flex; align-items: center; gap: 9px;
  font-weight: 500; font-size: 0.9rem; color: var(--text);
  text-decoration: none; white-space: nowrap;
}
.logo-k {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--orange); color: #000;
  font-weight: 700; font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.icon-btn {
  width: 32px; height: 32px; border-radius: 7px;
  background: transparent; border: none; cursor: pointer;
  color: var(--text-dim); display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface2); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }

.sidebar-actions {
  padding: 4px 12px 8px;
  display: flex; gap: 6px;
  flex-shrink: 0;
}
.new-chat-btn {
  flex: 1; padding: 8px 12px; border-radius: 8px;
  background: var(--orange); color: #000;
  border: none; cursor: pointer;
  font-family: var(--sans); font-size: 0.8rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}
.new-chat-btn:hover { background: #e07b00; }
.new-chat-btn:active { transform: scale(0.98); }

.sidebar-scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 0 8px;
}
.sidebar-scroll::-webkit-scrollbar { width: 3px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }

/* Upload zone */
.upload-zone {
  margin: 8px 4px 4px;
  padding: 12px 14px;
  border: 1px dashed var(--border2);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.upload-zone:hover { border-color: var(--orange); background: var(--orange-hover); }
.upload-zone input { display: none; }
.upload-zone-label { cursor: pointer; display: block; }
.upload-zone-title {
  font-size: 0.78rem; font-weight: 500; color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
}
.upload-zone-title svg { color: var(--orange); }
.upload-zone-sub { font-size: 0.7rem; color: var(--text-faint); margin-top: 3px; }

.file-preview {
  margin: 4px 4px 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--orange-dim);
  border: 1px solid rgba(255,140,0,0.25);
  font-size: 0.75rem; color: var(--text-dim);
  display: none; align-items: center; gap: 8px;
}
.file-preview.active { display: flex; }
.file-preview-name { flex: 1; truncate: true; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--orange); font-weight: 500; }
.file-preview-remove { cursor: pointer; color: var(--text-faint); flex-shrink: 0; }
.file-preview-remove:hover { color: var(--text); }

/* Section labels */
.section-label {
  font-family: var(--mono); font-size: 0.65rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-faint);
  padding: 14px 8px 6px;
}

/* Mode buttons */
.mode-btn {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  background: transparent; border: none; cursor: pointer;
  font-family: var(--sans); font-size: 0.8rem; color: var(--text-dim);
  display: flex; align-items: center; gap: 9px;
  text-align: left; transition: background 0.15s, color 0.15s;
  margin-bottom: 1px;
}
.mode-btn:hover { background: var(--surface2); color: var(--text); }
.mode-btn.active { background: var(--orange-dim); color: var(--orange); }
.mode-btn svg { flex-shrink: 0; width: 15px; height: 15px; }
.mode-btn-sub { font-size: 0.68rem; color: var(--text-faint); font-family: var(--mono); margin-left: auto; }
.mode-btn.active .mode-btn-sub { color: rgba(255,140,0,0.5); }

/* Chat history */
.chat-item {
  padding: 8px 10px; border-radius: 8px;
  font-size: 0.8rem; color: var(--text-dim);
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; transition: background 0.15s, color 0.15s;
  margin-bottom: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item:hover { background: var(--surface2); color: var(--text); }
.chat-item svg { flex-shrink: 0; width: 14px; height: 14px; }

/* Sidebar footer */
.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px; border-radius: 8px; cursor: pointer;
  transition: background 0.15s;
}
.user-row:hover { background: var(--surface2); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--orange); color: #000;
  font-weight: 700; font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-name { font-size: 0.8rem; font-weight: 500; }
.user-meta { font-size: 0.7rem; color: var(--text-faint); }

/* ═══════════════════════════════════════
   MAIN
═══════════════════════════════════════ */
.main {
  flex: 1; display: flex; flex-direction: column;
  height: 100vh; overflow: hidden;
  background: var(--bg);
}

/* Top bar */
.topbar {
  height: 52px; flex-shrink: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}
.topbar-title {
  font-size: 0.85rem; font-weight: 500; color: var(--text-dim);
}
.model-pill {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 20px;
  background: var(--surface2); border: 1px solid var(--border);
  font-size: 0.75rem; color: var(--text-dim); cursor: pointer;
  transition: border-color 0.15s;
}
.model-pill:hover { border-color: var(--orange); }
.model-pill-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--orange); }
.topbar-right { margin-left: auto; display: flex; gap: 6px; }

/* Messages */
.messages {
  flex: 1; overflow-y: auto; padding: 24px 0;
}
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--surface3); border-radius: 2px; }

/* Welcome screen */
.welcome {
  max-width: 680px; margin: 40px auto 0;
  padding: 0 24px; text-align: center;
}
.welcome-icon {
  width: 52px; height: 52px; border-radius: 14px;
  background: var(--orange); color: #000;
  font-weight: 800; font-size: 1.4rem;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
}
.welcome h1 {
  font-size: 1.6rem; font-weight: 500; letter-spacing: -0.02em;
  color: var(--text); margin-bottom: 10px;
}
.welcome p {
  font-size: 0.9rem; color: var(--text-dim); line-height: 1.7;
  max-width: 480px; margin: 0 auto 28px;
}
.welcome-chips {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.chip {
  padding: 8px 14px; border-radius: 20px;
  background: var(--surface2); border: 1px solid var(--border);
  font-size: 0.8rem; color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; gap: 7px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.chip:hover { background: var(--surface3); border-color: var(--orange); color: var(--text); }
.chip svg { width: 14px; height: 14px; color: var(--orange); }

/* Message rows */
.msg-row {
  max-width: 720px; margin: 0 auto;
  padding: 6px 24px;
  display: flex; gap: 14px;
  animation: fadeUp 0.25s ease;
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.msg-row.user { flex-direction: row-reverse; }

.msg-avatar-wrap {
  flex-shrink: 0; padding-top: 2px;
}
.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 600; color: var(--text-dim);
}
.msg-row.assistant .msg-avatar { background: var(--orange); color: #000; border: none; }

.bubble {
  padding: 12px 16px; border-radius: 16px;
  font-size: 0.88rem; line-height: 1.7; color: var(--text);
  max-width: 580px;
}
.msg-row.assistant .bubble {
  background: transparent;
  padding-left: 0; padding-right: 0;
  border-radius: 0;
}
.msg-row.user .bubble {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.typing-dots {
  display: flex; gap: 4px; align-items: center; padding: 4px 0;
}
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-faint);
  animation: blink 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.3; transform: scale(1); }
  40% { opacity: 1; transform: scale(1.3); }
}

/* ═══════════════════════════════════════
   COMPOSER
═══════════════════════════════════════ */
.composer-wrap {
  flex-shrink: 0; padding: 12px 24px 16px;
}
.composer {
  max-width: 720px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: 16px; transition: border-color 0.15s;
}
.composer:focus-within { border-color: rgba(255,140,0,0.4); }

.composer-textarea {
  width: 100%; resize: none; border: none; outline: none;
  background: transparent; color: var(--text);
  font-family: var(--sans); font-size: 0.9rem; line-height: 1.6;
  padding: 14px 16px 6px;
  min-height: 48px; max-height: 200px;
  scrollbar-width: thin;
}
.composer-textarea::placeholder { color: var(--text-faint); }

.composer-bar {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 10px 10px;
}
.composer-chips { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.compose-chip {
  padding: 4px 10px; border-radius: 14px;
  background: var(--surface2); border: 1px solid var(--border);
  font-size: 0.72rem; color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; gap: 5px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}
.compose-chip:hover { background: var(--surface3); border-color: var(--border2); color: var(--text); }
.compose-chip.active { background: var(--orange-dim); border-color: rgba(255,140,0,0.3); color: var(--orange); }
.compose-chip svg { width: 12px; height: 12px; }

.attach-btn {
  width: 30px; height: 30px; border-radius: 8px;
  background: transparent; border: 1px solid var(--border);
  cursor: pointer; color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.attach-btn:hover { background: var(--surface2); color: var(--text); }
.attach-btn svg { width: 14px; height: 14px; }

.send-btn {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--surface3); border: none; cursor: pointer;
  color: var(--text-faint); display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.send-btn.ready { background: var(--orange); color: #000; }
.send-btn.ready:hover { background: #e07b00; }
.send-btn.ready:active { transform: scale(0.95); }
.send-btn svg { width: 16px; height: 16px; }

.disclaimer {
  text-align: center; font-size: 0.68rem; color: var(--text-faint);
  margin-top: 8px; max-width: 720px; margin: 8px auto 0;
}

/* ═══════════════════════════════════════
   MOBILE OVERLAY
═══════════════════════════════════════ */
.overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 50;
}
@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 60; height: 100%; }
  .sidebar.collapsed { width: 0; }
  .overlay.active { display: block; }
  .topbar { padding: 0 12px; }
  .composer-wrap { padding: 8px 12px 12px; }
  .msg-row { padding: 6px 12px; }
  .welcome { padding: 0 16px; }
}


/* PHP site integration fixes */
body.chatbot-body {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.site-loader,
.nav,
footer {
  display: none !important;
}

.main {
  min-width: 0;
}

/* Better message visibility + smaller input */
.messages {
  padding: 18px 0 12px !important;
}

.composer-wrap {
  padding: 8px 20px 10px !important;
}

.composer-textarea {
  min-height: 38px !important;
  height: 38px;
  max-height: 112px !important;
  padding: 10px 14px 4px !important;
}

.composer-bar {
  padding: 6px 9px 8px !important;
}

.disclaimer {
  margin-top: 5px !important;
}

/* File preview enhanced */
.file-preview {
  display: none;
}

.file-preview.active {
  display: block;
}

.file-preview-card {
  display: grid;
  gap: 8px;
}

.file-preview-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-preview-name {
  color: var(--orange);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-preview-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.file-preview-pill {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px;
  font-size: .68rem;
  color: var(--text-dim);
}

.file-preview-pill strong {
  display: block;
  color: var(--text);
  font-size: .76rem;
}

/* Response formatting */
.bubble pre {
  white-space: pre-wrap;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.bubble code {
  font-family: var(--mono);
}

@media (max-width: 768px) {
  .composer-wrap {
    padding: 8px 10px 10px !important;
  }
}
