:root {
  --bg: #f3f7ff;
  --bg-gradient: radial-gradient(circle at 8% 10%, #dbeafe 0%, transparent 45%), radial-gradient(circle at 92% 90%, #d1fae5 0%, transparent 42%);
  --text: #0f172a;
  --muted: #64748b;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-border: rgba(148, 163, 184, 0.25);
  --sidebar-bg: #0f172a;
  --sidebar-item: #1e293b;
  --sidebar-text: #e2e8f0;
  --bubble-user: linear-gradient(135deg, #222939, #25353d);
  --bubble-user-text: #fff;
  --bubble-bot: #f8fafc;
  --bubble-bot-text: #0f172a;
  --grad: linear-gradient(120deg, #1e2433, #222f2e);
  --shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  --highlight: #fde68a;
  --input-bg: #fff;
}

body.dark {
  --bg: #020617;
  --bg-gradient: radial-gradient(circle at 10% 12%, #1e3a8a 0%, transparent 40%), radial-gradient(circle at 90% 85%, #134e4a 0%, transparent 42%);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --panel: rgba(15, 23, 42, 0.84);
  --panel-border: rgba(148, 163, 184, 0.22);
  --sidebar-bg: #020617;
  --sidebar-item: #172033;
  --sidebar-text: #e2e8f0;
  --bubble-user: linear-gradient(135deg, #1d4ed8, #0891b2);
  --bubble-bot: #1e293b;
  --bubble-bot-text: #e2e8f0;
  --shadow: 0 16px 34px rgba(0, 0, 0, 0.4);
  --highlight: #92400e;
  --input-bg: #0f172a;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  background: var(--bg-gradient), var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(148, 163, 184, 0.2);
  z-index: 20;
}

.sidebar-header,
.sidebar-search-wrap {
  padding: 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

.sidebar-header h2 { margin: 0 0 0.75rem; letter-spacing: 0.08em; }

.sidebar-search-wrap input {
  width: 100%;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 0.65rem;
  padding: 0.55rem;
  background: rgba(15, 23, 42, 0.5);
  color: #e2e8f0;
}
.search-status { display: block; margin-top: 0.35rem; min-height: 1rem; color: #cbd5e1; font-size: 0.74rem; }

.sidebar-list { padding: 0.75rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; }
.chat-row { border: 1px solid transparent; border-radius: 0.75rem; padding: 0.5rem; cursor: pointer; }
.chat-row.active, .chat-row:hover { background: var(--sidebar-item); border-color: rgba(148, 163, 184, 0.2); }
.chat-row-head { display: flex; justify-content: space-between; gap: 0.5rem; }
.chat-row-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 0.9rem; }
.chat-row-actions { display: none; margin-top: 0.4rem; gap: 0.25rem; flex-wrap: wrap; }
.chat-row:hover .chat-row-actions { display: flex; }

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(14px);
}

.topbar {
  background: var(--grad);
  color: #fff;
  padding: 0.85rem 1rem;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
}
.topbar-left { display: flex; align-items: center; gap: 0.6rem; }
.topbar-left h1 { margin: 0; font-size: 1.2rem; }
.topbar-left p { margin: 0; opacity: 0.9; font-size: 0.82rem; }
.topbar-right { display: flex; gap: 0.45rem; align-items: center; flex-wrap: wrap; }
.topbar-right > * { height: 36px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.msg {
  max-width: min(76%, 780px);
  border-radius: 1rem;
  padding: 0.7rem 0.9rem;
  box-shadow: var(--shadow);
  position: relative;
  animation: fadeIn 0.2s ease;
}
.msg.user { align-self: flex-end; background: var(--bubble-user); color: var(--bubble-user-text); }
.msg.bot { align-self: flex-start; background: var(--bubble-bot); color: var(--bubble-bot-text); border: 1px solid var(--panel-border); }

.user-line { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
.user-time { font-size: 0.74rem; opacity: 0.9; }
.bot-body { margin: 0; line-height: 1.5; }
.bot-body a { color: #0284c7; font-weight: 600; }
.msg img { margin-top: 0.6rem; width: 100%; max-width: 280px; border-radius: 0.6rem; }

.msg.highlight { outline: 2px solid var(--highlight); }
.msg-actions {
  display: none;
  position: absolute;
  right: 0.45rem;
  top: -0.9rem;
  background: rgba(15, 23, 42, 0.92);
  border-radius: 0.45rem;
  padding: 0.2rem;
  gap: 0.2rem;
}
.msg:hover .msg-actions { display: flex; }

.composer-wrap { padding: 0.85rem; border-top: 1px solid var(--panel-border); }
.suggestion-tray { display: flex; gap: 0.45rem; overflow-x: auto; padding-bottom: 0.6rem; }
.suggestion-chip {
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
  padding: 0.35rem 0.65rem;
  white-space: nowrap;
  cursor: pointer;
}
.suggestion-tray.hidden { display: none; }
.composer { display: flex; align-items: center; gap: 0.5rem; max-width: 1100px; margin: 0 auto; }

#promptInput {
  flex: 1;
  border: 1px solid var(--panel-border);
  border-radius: 1.2rem;
  padding: 0.72rem 0.9rem;
  background: var(--input-bg);
  color: var(--text);
}

.btn, .icon-btn, select { border: 1px solid rgba(148, 163, 184, 0.4); border-radius: 0.65rem; font: inherit; }
.btn, .icon-btn, .action-btn { cursor: pointer; }
.btn { padding: 0.55rem 0.75rem; }
.btn-primary { width: 100%; background: rgba(37, 99, 235, 0.2); color: #e2e8f0; }
.btn-send { background: #0f766e; color: #fff; border-color: transparent; padding: 0.7rem 1rem; min-width: 80px; }
.icon-btn, select { background: rgba(255, 255, 255, 0.18); color: #fff; padding: 0.5rem 0.65rem; }
select option { color: #111827; }

.action-btn { border: none; background: transparent; color: #e2e8f0; font-size: 0.74rem; padding: 0.25rem 0.42rem; border-radius: 0.35rem; }
.action-btn:hover { background: rgba(148, 163, 184, 0.32); }

.typing-dots { display: inline-flex; gap: 0.24rem; margin-left: 0.2rem; }
.typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

.mobile-only { display: none; }
.mobile-backdrop { display: none; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%,80%,100% { opacity: .35; transform: scale(.75); } 40% { opacity: 1; transform: scale(1); } }

@media (max-width: 950px) {
  .msg { max-width: 88%; }
  .topbar-left p { display: none; }
}

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: -305px;
    height: 100vh;
    transition: left 0.25s ease;
  }
  .app.sidebar-open .sidebar { left: 0; }
  .mobile-only { display: inline-block; }
  .mobile-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 10; }
  .app.sidebar-open .mobile-backdrop { display: block; }
  .topbar { align-items: flex-start; }
  .topbar-right { width: 100%; justify-content: flex-start; }
}
