:root, [data-theme="light"] {
  --bg: #f9f9f7;
  --sidebar: #f0eee6;
  --sidebar-text: #1a1a1a;
  --main: #f9f9f7;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e5e3d9;
  --accent: #d97757;
  --accent-hover: #c45d3e;
  --user-bg: #e8e6dc;
  --card: #ffffff;
  --code-bg: #f0eee6;
  --input-bg: #ffffff;
}

[data-theme="dark"] {
  --bg: #1a1a1a;
  --sidebar: #141414;
  --sidebar-text: #e8e8e8;
  --main: #1a1a1a;
  --text: #ececec;
  --muted: #999;
  --border: #333;
  --accent: #10a37f;
  --accent-hover: #0d8c6d;
  --user-bg: #2a2a2a;
  --card: #242424;
  --code-bg: #2a2a2a;
  --input-bg: #242424;
}

[data-theme="claude"] {
  --bg: #faf9f5;
  --sidebar: #f0eee6;
  --sidebar-text: #1a1a1a;
  --main: #faf9f5;
  --text: #1a1a1a;
  --muted: #666;
  --border: #e5e3d9;
  --accent: #d97757;
  --accent-hover: #c45d3e;
  --user-bg: #e8e6dc;
  --card: #fff;
  --code-bg: #f0eee6;
  --input-bg: #fff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

/* Sidebar */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  transition: margin 0.25s ease;
}
.sidebar.collapsed { margin-left: -280px; }

.sidebar-top { padding: 12px; }
.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--sidebar-text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.new-chat-btn:hover { background: rgba(0,0,0,0.05); }
.new-chat-btn svg { flex-shrink: 0; }

.sidebar-chats { flex: 1; overflow-y: auto; padding: 8px; }
.sidebar-hint { padding: 12px; font-size: 13px; color: var(--muted); }

.chat-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.chat-item:hover, .chat-item.active { background: rgba(0,0,0,0.06); }
.chat-item .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chat-item .del {
  opacity: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 0 4px;
}
.chat-item:hover .del { opacity: 1; }

.sidebar-bottom {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-box input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
  margin-bottom: 6px;
  display: block;
}
.auth-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.auth-tab {
  flex: 1;
  padding: 7px;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  color: var(--muted);
}
.auth-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.primary-btn {
  width: 100%;
  padding: 9px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}
.primary-btn:hover { background: var(--accent-hover); }
.auth-error { color: #c00; font-size: 12px; min-height: 16px; margin-top: 4px; }
.user-email { font-size: 12px; color: var(--muted); word-break: break-all; margin-bottom: 4px; }
.side-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  text-align: left;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}
.side-btn:hover { background: rgba(0,0,0,0.05); color: var(--sidebar-text); }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--main); }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}
.chat-title { font-size: 14px; font-weight: 500; flex: 1; }
.mode-pills { display: flex; gap: 4px; flex-wrap: wrap; }
.mode-pill {
  padding: 5px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  color: var(--muted);
}
.mode-pill.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: rgba(0,0,0,0.06); color: var(--text); }
.icon-btn svg, .send-btn svg, .new-chat-btn svg { display: block; pointer-events: none; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.welcome { margin: auto; text-align: center; color: var(--muted); }
.welcome-logo { font-size: 36px; margin-bottom: 12px; color: var(--accent); }
.welcome h2 { font-size: 22px; color: var(--text); font-weight: 600; }

.message {
  max-width: 740px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  gap: 14px;
  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: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  margin-top: 2px;
}
.message.assistant .avatar { background: var(--accent); }
.message.user .avatar { background: #5c5c5c; }

.bubble { flex: 1; min-width: 0; line-height: 1.55; font-size: 15px; }
.message.user .bubble {
  background: var(--user-bg);
  padding: 10px 16px;
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  max-width: 85%;
  margin-left: auto;
}
.message.assistant .bubble p { margin-bottom: 0.7em; }
.message.assistant .bubble p:last-child { margin-bottom: 0; }

.code-block {
  background: var(--code-bg);
  border-radius: 10px;
  margin: 10px 0;
  overflow: hidden;
  border: 1px solid var(--border);
}
.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 12px;
  background: rgba(0,0,0,0.04);
  font-size: 12px;
  color: var(--muted);
}
.copy-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
}
.copy-btn:hover { background: rgba(0,0,0,0.05); }
.code-block pre {
  margin: 0;
  padding: 14px;
  overflow-x: auto;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}
.code-block code { background: none; padding: 0; }

.typing-wrap {
  display: flex;
  gap: 14px;
  max-width: 740px;
  margin: 0 auto;
  width: 100%;
}
.typing-dots { display: flex; gap: 5px; padding: 8px 0; }
.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-6px); opacity: 1; }
}

.composer {
  padding: 12px 16px 18px;
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
}
.composer-inner {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 8px 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.04);
}
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
#userInput {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  max-height: 160px;
  color: var(--text);
  padding: 8px 4px;
}
.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.send-btn:not(:disabled):hover { background: var(--accent-hover); }
.disclaimer { text-align: center; font-size: 11px; color: var(--muted); margin-top: 10px; }

.image-preview { position: relative; display: inline-block; margin: 6px 8px; }
.image-preview img { max-height: 80px; border-radius: 8px; }
.image-preview button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: #333;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
}
#micBtn.recording { color: #e53935; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }

.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.settings-panel[hidden], #imagePreview[hidden], #userBox[hidden], #authBox[hidden] {
  display: none !important;
}
.settings-card {
  background: var(--card);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  border: 1px solid var(--border);
}
.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.settings-section label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}
.theme-row { display: flex; gap: 8px; }
.theme-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
}
.theme-btn.active {
  border-color: var(--accent);
  background: rgba(217, 119, 87, 0.12);
}


/* Expanded settings */
.settings-card-wide {
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.settings-scroll {
  overflow-y: auto;
  padding-right: 4px;
}
.settings-section { margin-bottom: 18px; }
.settings-select, .settings-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}
.settings-textarea {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  resize: vertical;
  min-height: 100px;
}
.settings-section input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.set-val { color: var(--text); font-weight: 500; }
.settings-check {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  color: var(--text) !important;
  cursor: pointer;
  font-size: 13px;
}
.settings-check input { width: auto; margin: 0; }
.settings-save-btn { width: auto; margin-top: 8px; padding: 8px 14px; }
.settings-actions { display: flex; flex-direction: column; gap: 4px; }
.welcome-hint { font-size: 13px; margin-top: 8px; color: var(--muted); }
.message.user .bubble .msg-image {
  display: block;
  max-width: 100%;
  max-height: 280px;
  border-radius: 10px;
  margin-bottom: 8px;
  object-fit: contain;
}
.message.user .bubble .msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}
.model-tag {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}
.bubble { font-size: var(--msg-font, 15px); }
body.density-compact .messages { gap: 12px; padding: 16px 12px; }
body.density-compact .message { gap: 10px; }
.disclaimer a { color: inherit; text-decoration: underline; }

@media (max-width: 700px) {
  .sidebar { position: fixed; z-index: 40; height: 100%; }
  .mode-pills { display: none; }
}