*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-bg: #1a1a1a;
  --sidebar-hover: #2a2a2a;
  --sidebar-active: #333;
  --main-bg: #212121;
  --input-bg: #2f2f2f;
  --border: rgba(255,255,255,0.08);
  --text-primary: #ececec;
  --text-secondary: #8e8ea0;
  --text-muted: #5a5a72;
  --accent: #cc785c;
  --user-bubble: #2f2f2f;
  --ai-bubble: transparent;
  --font: 'Söhne', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --radius: 12px;
  --scrollbar: rgba(255,255,255,0.1);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--main-bg);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 4px; }

/* ═══════════════════════════════════════
   APP SHELL
═══════════════════════════════════════ */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ═══════════════════════════════════════
   SIDEBAR
═══════════════════════════════════════ */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  border-right: 1px solid var(--border);
}

.sidebar-top {
  padding: 12px 12px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  padding: 6px 8px;
  border-radius: 8px;
}

.sidebar-logo svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.icon-btn:hover { background: var(--sidebar-hover); color: var(--text-primary); }

.icon-btn svg { width: 18px; height: 18px; }

/* New chat button */
.new-chat-btn {
  margin: 0 12px 8px;
  padding: 9px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s;
  width: calc(100% - 24px);
  flex-shrink: 0;
}

.new-chat-btn:hover { background: var(--sidebar-hover); }

.new-chat-btn svg { width: 16px; height: 16px; color: var(--text-secondary); }

/* Search */
.sidebar-search {
  margin: 0 12px 8px;
  position: relative;
  flex-shrink: 0;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: var(--sidebar-hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  font-family: var(--font);
  transition: border-color 0.15s;
}

.sidebar-search input::placeholder { color: var(--text-muted); }
.sidebar-search input:focus { border-color: rgba(255,255,255,0.2); }

.sidebar-search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
}

.sidebar-search .search-icon svg { width: 14px; height: 14px; }

/* Sidebar sections */
.sidebar-section {
  padding: 0 8px;
  margin-bottom: 4px;
  flex-shrink: 0;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 6px 8px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-transform: uppercase;
}

.sidebar-section-title button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.sidebar-section-title button:hover { background: var(--sidebar-hover); color: var(--text-primary); }

/* Project items */
.project-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  transition: background 0.12s, color 0.12s;
  user-select: none;
}

.project-item:hover { background: var(--sidebar-hover); color: var(--text-primary); }
.project-item.active { background: var(--sidebar-active); color: var(--text-primary); }

.project-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.7; }

/* Divider */
.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 12px;
  flex-shrink: 0;
}

/* Chat list */
.chat-list-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 12px;
  min-height: 0;
}

.chat-group-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 10px 10px 4px;
  text-transform: uppercase;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13.5px;
  transition: background 0.12s, color 0.12s;
  position: relative;
  group: true;
}

.chat-item:hover { background: var(--sidebar-hover); color: var(--text-primary); }
.chat-item.active { background: var(--sidebar-active); color: var(--text-primary); }

.chat-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.chat-item-del {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s;
}

.chat-item:hover .chat-item-del { display: flex; }
.chat-item-del:hover { color: #f87171; }
.chat-item-del svg { width: 14px; height: 14px; }

/* Sidebar footer */
.sidebar-footer {
  padding: 8px 12px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.user-row:hover { background: var(--sidebar-hover); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #cc785c, #e0956e);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.user-name {
  font-size: 13.5px;
  color: var(--text-primary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-row .icon-btn { width: 28px; height: 28px; }

/* ═══════════════════════════════════════
   MAIN AREA
═══════════════════════════════════════ */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--main-bg);
  position: relative;
}

/* Header */
.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 56px;
}

.header-model {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s;
}

.header-model:hover { background: var(--sidebar-hover); }
.header-model svg { width: 14px; height: 14px; color: var(--text-secondary); }

.header-actions { display: flex; align-items: center; gap: 4px; }

/* ═══════════════════════════════════════
   MESSAGES
═══════════════════════════════════════ */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 8px;
  scroll-behavior: smooth;
}

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  padding: 40px 20px;
}

.welcome-logo {
  width: 52px;
  height: 52px;
  color: var(--text-primary);
  opacity: 0.9;
}

.welcome h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.welcome-prompts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 520px;
  width: 100%;
  margin-top: 8px;
}

.welcome-prompt-btn {
  padding: 14px 16px;
  background: var(--user-bubble);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
  font-family: var(--font);
}

.welcome-prompt-btn:hover { background: var(--sidebar-hover); color: var(--text-primary); }

/* Message row */
.msg-row {
  max-width: 760px;
  margin: 0 auto;
  padding: 6px 24px;
  width: 100%;
}

.msg-row.user { display: flex; justify-content: flex-end; }
.msg-row.ai { display: flex; justify-content: flex-start; }

/* Bubbles */
.bubble {
  max-width: 85%;
  line-height: 1.7;
  font-size: 15px;
}

.user .bubble {
  background: var(--user-bubble);
  padding: 12px 18px;
  border-radius: 18px 18px 4px 18px;
  color: var(--text-primary);
  word-break: break-word;
}

.ai .bubble {
  background: var(--ai-bubble);
  padding: 4px 0;
  color: var(--text-primary);
  word-break: break-word;
}

/* AI avatar */
.ai-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  margin-right: 10px;
}

.ai-avatar svg { width: 16px; height: 16px; color: white; }

.ai-content { display: flex; align-items: flex-start; max-width: 100%; }

/* Markdown inside AI bubble */
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 1em 0 0.4em;
  font-weight: 600;
  line-height: 1.3;
}

.bubble h1 { font-size: 1.3em; }
.bubble h2 { font-size: 1.15em; }
.bubble h3 { font-size: 1em; }

.bubble p { margin: 0.6em 0; }
.bubble p:first-child { margin-top: 0; }
.bubble p:last-child { margin-bottom: 0; }

.bubble ul, .bubble ol { padding-left: 1.5em; margin: 0.5em 0; }
.bubble li { margin: 0.3em 0; }

.bubble strong { font-weight: 600; color: var(--text-primary); }
.bubble em { font-style: italic; }

.bubble code:not(pre code) {
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: #e5c07b;
}

.bubble pre {
  background: #0d0d0d;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  overflow-x: auto;
  margin: 10px 0;
  position: relative;
}

.bubble pre code {
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
  line-height: 1.6;
  color: #abb2bf;
}

.copy-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  font-family: var(--font);
}

.copy-btn:hover { background: rgba(255,255,255,0.13); color: var(--text-primary); }

.bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  margin: 8px 0;
  color: var(--text-secondary);
}

.bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 14px;
}

.bubble th, .bubble td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.bubble th { background: rgba(255,255,255,0.05); font-weight: 600; }

/* Typing cursor */
.cursor {
  display: inline-block;
  width: 2px;
  height: 16px;
  background: var(--text-primary);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.9s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* Action buttons below AI message */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

.msg-row.ai:hover .msg-actions { opacity: 1; }

.msg-action-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.15s, color 0.15s;
  font-family: var(--font);
}

.msg-action-btn:hover { background: var(--sidebar-hover); color: var(--text-secondary); }
.msg-action-btn svg { width: 14px; height: 14px; }

/* ═══════════════════════════════════════
   INPUT BAR
═══════════════════════════════════════ */
.input-section {
  flex-shrink: 0;
  padding: 12px 20px 20px;
}

.input-wrapper {
  max-width: 760px;
  margin: 0 auto;
  background: var(--input-bg);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 16px;
  transition: border-color 0.2s;
  overflow: hidden;
}

.input-wrapper:focus-within { border-color: rgba(255,255,255,0.25); }

/* File preview inside input */
#filePreview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 14px 0;
}

#filePreview:empty { display: none; }

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--border);
  padding: 4px 8px 4px 10px;
  border-radius: 20px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.file-chip svg { width: 13px; height: 13px; color: var(--text-muted); }

.file-chip button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}

.file-chip button:hover { color: #f87171; }

/* Textarea */
.input-row {
  display: flex;
  align-items: flex-end;
  padding: 10px 12px;
  gap: 8px;
}

#input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font);
  line-height: 1.6;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  overflow-y: auto;
  padding: 0;
}

#input::placeholder { color: var(--text-muted); }

.input-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.attach-btn {
  width: 34px;
  height: 34px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.attach-btn:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }
.attach-btn svg { width: 18px; height: 18px; }

.send-btn {
  width: 34px;
  height: 34px;
  background: var(--text-primary);
  border: none;
  border-radius: 8px;
  color: #1a1a1a;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.send-btn:not(:disabled):hover { opacity: 0.85; }
.send-btn:not(:disabled):active { transform: scale(0.93); }
.send-btn svg { width: 16px; height: 16px; }

/* Stop button */
.stop-btn {
  width: 34px;
  height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.stop-btn:hover { background: rgba(255,255,255,0.08); }
.stop-btn svg { width: 16px; height: 16px; }

.input-hint {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ═══════════════════════════════════════
   LOADING STATES
═══════════════════════════════════════ */
.thinking-dots {
  display: flex;
  gap: 4px;
  padding: 4px 0;
  align-items: center;
}

.thinking-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: dotPulse 1.2s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 60%, 100% { transform: scale(0.8); opacity: 0.4; }
  30% { transform: scale(1); opacity: 1; }
}

/* ═══════════════════════════════════════
   LOGIN PAGE
═══════════════════════════════════════ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--main-bg);
  padding: 20px;
}

.login-box {
  width: 100%;
  max-width: 360px;
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 36px;
}

.login-logo svg { width: 40px; height: 40px; color: var(--text-primary); }
.login-logo h1 { font-size: 20px; font-weight: 600; color: var(--text-primary); }

.login-field {
  margin-bottom: 12px;
}

.login-field input {
  width: 100%;
  padding: 13px 16px;
  background: var(--user-bubble);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}

.login-field input::placeholder { color: var(--text-muted); }
.login-field input:focus { border-color: rgba(255,255,255,0.3); }

.login-submit {
  width: 100%;
  padding: 13px;
  margin-top: 8px;
  background: var(--text-primary);
  border: none;
  border-radius: 10px;
  color: #1a1a1a;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: opacity 0.15s;
}

.login-submit:hover { opacity: 0.88; }

.login-error {
  margin-top: 14px;
  padding: 10px 14px;
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.25);
  border-radius: 8px;
  color: #f87171;
  font-size: 13.5px;
  display: none;
}

.login-error.show { display: block; }

/* ═══════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════ */
@media (max-width: 700px) {
  .sidebar { display: none; }
  .welcome-prompts { grid-template-columns: 1fr; }
}