:root {
  --bg: #0b0f1a;
  --bg-side: #0e1424;
  --bg-card: #151c2e;
  --bg-input: #121826;
  --border: #1e293b;
  --text: #e8eef8;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --bubble-user: #1d4ed8;
  --bubble-ai: #151c2e;
  --radius: 16px;
}

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 18px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.35);
}

.brand-logo.sm {
  width: 28px;
  height: 28px;
  font-size: 13px;
  border-radius: 8px;
}

.brand-name {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.3px;
}

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px;
  margin-bottom: 14px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.new-chat-btn:hover { filter: brightness(1.08); }

.history-wrap {
  flex: 0 1 auto;
  max-height: 180px;
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
  min-height: 0;
}

.history-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 0 6px 6px;
}

.icon-tiny {
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.7;
  font-size: 13px;
}
.icon-tiny:hover { opacity: 1; }

.history-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.history-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.history-item.active { background: rgba(59,130,246,0.15); color: #93c5fd; }
.history-item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .x { opacity: 0; border: none; background: none; color: var(--muted); cursor: pointer; }
.history-item:hover .x { opacity: 1; }
.history-item .x:hover { color: #f87171; }
.history-empty { font-size: 12px; color: var(--muted); padding: 10px; text-align: center; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
}
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.nav-item.active {
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
}

.theme-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
}

/* Main */
.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  background: var(--bg);
}

.topbar {
  display: none;
  align-items: center;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}
.topbar.visible { display: flex; }

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-title { font-weight: 600; font-size: 15px; }
.topbar-sub { font-size: 12px; color: var(--muted); }

.view { display: none; flex: 1; flex-direction: column; min-height: 0; }
.view.active { display: flex; }

/* Welcome */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.welcome-logo {
  width: 72px;
  height: 72px;
  border-radius: 20px;
  background: linear-gradient(135deg, #60a5fa, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 20px;
  box-shadow: 0 12px 40px rgba(37, 99, 235, 0.35);
}

.welcome h1 {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -1px;
  margin-bottom: 8px;
}

.tagline {
  color: var(--muted);
  font-size: 15px;
  margin-bottom: 32px;
}

.welcome-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(560px, 92%);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 8px 8px 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.welcome-input-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
.welcome-input-wrap input::placeholder { color: var(--muted); }

.send-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.send-circle:hover { filter: brightness(1.1); }
.send-circle:disabled { opacity: 0.5; cursor: not-allowed; }

/* Chat */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px 12px;
}
.chat-area.hidden { display: none; }

.messages {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.message {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

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

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
}
.avatar.ai {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
}
.avatar.user {
  background: #334155;
}

.bubble-wrap {
  max-width: 75%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.message.user .bubble-wrap { align-items: flex-end; }

.bubble {
  padding: 14px 16px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.6;
  word-break: break-word;
}
.message.user .bubble {
  background: var(--bubble-user);
  border-bottom-right-radius: 6px;
}
.message.assistant .bubble {
  background: var(--bubble-ai);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}

.time {
  font-size: 11px;
  color: var(--muted);
  padding: 0 4px;
}

.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 8px 0 8px 18px; }
.bubble li { margin-bottom: 4px; }
.bubble strong { color: #fff; }
.bubble a { color: #60a5fa; }
.bubble pre {
  background: #0a0f1a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
}
.bubble code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
}
.bubble p code {
  background: rgba(59,130,246,0.15);
  padding: 2px 5px;
  border-radius: 4px;
  color: #93c5fd;
}
.bubble img.msg-image {
  max-width: 220px;
  border-radius: 10px;
  margin-top: 8px;
  display: block;
}

.typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: none; }
  30% { transform: translateY(-5px); }
}

/* Composer */
.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 820px;
  width: calc(100% - 48px);
  margin: 0 auto 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 8px 8px 14px;
}
.composer.hidden { display: none; }

.composer input[type="text"] {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14.5px;
  font-family: inherit;
}
.composer input::placeholder { color: var(--muted); }

.attach {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  color: var(--muted);
  font-size: 16px;
}
.attach:hover { background: rgba(255,255,255,0.05); color: var(--text); }

.img-preview {
  display: flex;
  align-items: center;
  gap: 6px;
}
.img-preview.hidden { display: none; }
.img-preview img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 8px;
}
.img-preview button {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

/* Panels */
.panel {
  padding: 32px;
  overflow-y: auto;
}
.panel h2 { font-size: 22px; margin-bottom: 6px; }
.muted { color: var(--muted); font-size: 14px; margin-bottom: 20px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.prompt-card, .tool-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}
.prompt-card:hover, .tool-card:hover {
  border-color: var(--accent);
}

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
