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

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  height: 100vh;
  overflow: hidden;
  transition: background 0.3s, color 0.3s;
}

/* ===== Light (default) ===== */
body {
  background: #fff;
  color: #1f1f1f;
}

/* ===== Dark ===== */
body.dark {
  background: #1a1a1a;
  color: #e0e0e0;
}

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

/* ===== Sidebar ===== */
.sidebar {
  width: 270px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: background 0.3s, border-color 0.3s;
}

body:not(.dark) .sidebar {
  background: #f7f7f7;
  border-right: 1px solid #e8e8e8;
}

body.dark .sidebar {
  background: #141414;
  border-right: 1px solid #2a2a2a;
}

.sidebar-header { padding: 12px 14px; }

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: 50px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  font-family: inherit;
}

body:not(.dark) .new-chat-btn {
  background: #fff;
  border: 1px solid #ddd;
  color: #1f1f1f;
}

body:not(.dark) .new-chat-btn:hover {
  background: #f5f5f5;
  border-color: #ccc;
}

body.dark .new-chat-btn {
  background: #252525;
  border: 1px solid #333;
  color: #e0e0e0;
}

body.dark .new-chat-btn:hover {
  background: #2f2f2f;
  border-color: #444;
}

/* Search */
.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  margin: 0 10px 8px;
  border-radius: 8px;
  transition: all 0.3s;
}

body:not(.dark) .sidebar-search {
  background: #fff;
  border: 1px solid #e0e0e0;
  color: #666;
}

body.dark .sidebar-search {
  background: #252525;
  border: 1px solid #333;
  color: #888;
}

.sidebar-search input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 13px;
  font-family: inherit;
  background: transparent;
}

body:not(.dark) .sidebar-search input { color: #1f1f1f; }
body:not(.dark) .sidebar-search input::placeholder { color: #999; }
body.dark .sidebar-search input { color: #e0e0e0; }
body.dark .sidebar-search input::placeholder { color: #666; }

/* Sections */
.sidebar-section { margin-bottom: 4px; }

.sidebar-section-title {
  padding: 8px 18px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

body:not(.dark) .sidebar-section-title { color: #888; }
body.dark .sidebar-section-title { color: #666; }

.sidebar-list {
  padding: 2px 8px;
  max-height: 400px;
  overflow-y: auto;
}

.sidebar-list::-webkit-scrollbar { width: 4px; }
body:not(.dark) .sidebar-list::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }
body.dark .sidebar-list::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }

.sidebar-item {
  padding: 10px 14px;
  border-radius: 0 50px 50px 0;
  margin: 2px 0;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s;
}

body:not(.dark) .sidebar-item { color: #333; }
body.dark .sidebar-item { color: #ccc; }
body:not(.dark) .sidebar-item:hover { background: #e8e8e8; }
body.dark .sidebar-item:hover { background: #252525; }
body:not(.dark) .sidebar-item.active { background: #e0e0e0; font-weight: 500; }
body.dark .sidebar-item.active { background: #2f2f2f; font-weight: 500; }

.sidebar-item .pin-badge { display: none; font-size: 11px; }
.sidebar-item.pinned .pin-badge { display: inline; }
.sidebar-item .item-info { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sidebar-item .item-meta { font-size: 11px; flex-shrink: 0; }
body:not(.dark) .sidebar-item .item-meta { color: #999; }
body.dark .sidebar-item .item-meta { color: #666; }

.sidebar-item .item-actions { display: none; gap: 2px; flex-shrink: 0; }
.sidebar-item:hover .item-actions { display: flex; }

.item-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 5px;
  border-radius: 4px;
}

body:not(.dark) .item-actions button { color: #888; }
body.dark .item-actions button { color: #666; }
body:not(.dark) .item-actions button:hover { background: #ddd; color: #333; }
body.dark .item-actions button:hover { background: #333; color: #ccc; }

.sidebar-footer {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

body:not(.dark) .sidebar-footer { border-top: 1px solid #e8e8e8; }
body.dark .sidebar-footer { border-top: 1px solid #2a2a2a; }

.stats {
  font-size: 11px;
}

body:not(.dark) .stats { color: #999; }
body.dark .stats { color: #555; }

.theme-toggle {
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.2s;
  text-align: center;
}

body:not(.dark) .theme-toggle {
  background: #f0f0f0;
  border: 1px solid #ddd;
  color: #333;
}

body:not(.dark) .theme-toggle:hover {
  background: #e8e8e8;
}

body.dark .theme-toggle {
  background: #252525;
  border: 1px solid #333;
  color: #ccc;
}

body.dark .theme-toggle:hover {
  background: #2f2f2f;
}

/* Mobile toggle */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
}

body:not(.dark) .sidebar-toggle {
  background: #fff;
  border: 1px solid #ddd;
  color: #333;
}

body.dark .sidebar-toggle {
  background: #252525;
  border: 1px solid #333;
  color: #ccc;
}

/* ===== Main ===== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.welcome-logo {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

body:not(.dark) .welcome-logo { background: #f0f0f0; color: #1f1f1f; }
body.dark .welcome-logo { background: #252525; color: #ccc; }

body:not(.dark) .welcome h1 { font-size: 22px; font-weight: 400; color: #1f1f1f; margin-bottom: 8px; }
body.dark .welcome h1 { font-size: 22px; font-weight: 400; color: #e0e0e0; margin-bottom: 8px; }

body:not(.dark) .welcome p { font-size: 14px; color: #888; margin-bottom: 30px; }
body.dark .welcome p { font-size: 14px; color: #666; margin-bottom: 30px; }

.url-bar {
  width: 100%;
  max-width: 500px;
  padding: 8px 14px;
  border-radius: 12px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

body:not(.dark) .url-bar {
  background: #f7f7f7;
  border: 1px solid #e0e0e0;
  color: #888;
}

body.dark .url-bar {
  background: #252525;
  border: 1px solid #333;
  color: #666;
}

.url-bar input {
  outline: none;
}

.url-bar input::selection {
  background: rgba(0, 0, 0, 0.1);
}

/* Feature tags */
.feature-icons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 16px;
}

.feature-tag {
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  cursor: default;
  transition: all 0.2s;
}

body:not(.dark) .feature-tag {
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  color: #666;
}

body.dark .feature-tag {
  background: #252525;
  border: 1px solid #333;
  color: #888;
}

body.dark .url-bar input::selection {
  background: rgba(255, 255, 255, 0.1);
}

.suggestions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 500px;
  width: 100%;
}

.suggestions button {
  padding: 12px 16px;
  border-radius: 18px;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  transition: all 0.2s;
  font-family: inherit;
}

body:not(.dark) .suggestions button {
  background: #fff;
  border: 1px solid #e0e0e0;
  color: #333;
}

body:not(.dark) .suggestions button:hover {
  background: #f5f5f5;
  border-color: #ccc;
}

body.dark .suggestions button {
  background: #252525;
  border: 1px solid #333;
  color: #ccc;
}

body.dark .suggestions button:hover {
  background: #2f2f2f;
  border-color: #444;
}

/* ===== Chat Messages ===== */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
}

body:not(.dark) .chat-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 10px; }
body.dark .chat-messages::-webkit-scrollbar-thumb { background: #333; border-radius: 10px; }

.chat-messages::-webkit-scrollbar { width: 5px; }

.msg-row {
  display: flex;
  gap: 14px;
  padding: 12px 20px;
  max-width: 780px;
  margin: 0 auto;
  width: 100%;
  animation: fadeIn 0.25s ease;
}

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

body:not(.dark) .msg-avatar.user { background: #e8e8e8; color: #555; }
body.dark .msg-avatar.user { background: #333; color: #aaa; }

.msg-avatar.ai { background: #1f1f1f; color: #fff; }
body.dark .msg-avatar.ai { background: #444; color: #fff; }

.msg-body { flex: 1; min-width: 0; }

.msg-actions {
  display: none;
  gap: 4px;
  margin-top: 6px;
}

.msg-row:hover .msg-actions { display: flex; }

.msg-actions button {
  background: none;
  border: 1px solid;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

body:not(.dark) .msg-actions button { border-color: #e0e0e0; color: #888; }
body:not(.dark) .msg-actions button:hover { background: #f5f5f5; color: #333; }
body.dark .msg-actions button { border-color: #333; color: #666; }
body.dark .msg-actions button:hover { background: #252525; color: #ccc; }

.msg-text {
  font-size: 14px;
  line-height: 1.6;
  padding-top: 2px;
  word-break: break-word;
}

body:not(.dark) .msg-text { color: #1f1f1f; }
body.dark .msg-text { color: #d0d0d0; }

.msg-text strong { font-weight: 600; }
.msg-text a { text-decoration: underline; text-underline-offset: 2px; }
body:not(.dark) .msg-text a { color: #1f1f1f; }
body.dark .msg-text a { color: #a0a0ff; }

/* Typing */
.typing-indicator { display: flex; gap: 4px; padding: 6px 0; }

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  animation: typing 1.2s ease-in-out infinite;
}

body:not(.dark) .typing-indicator span { background: #bbb; }
body.dark .typing-indicator span { background: #555; }

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.25s; }

/* Streaming cursor */
.streaming-cursor {
  display: inline-block;
  animation: blink 1s step-end infinite;
  font-weight: 300;
}

/* Error */
.msg-text.error {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
}

body:not(.dark) .msg-text.error { color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca; }
body.dark .msg-text.error { color: #f87171; background: #2d1215; border: 1px solid #7f1d1d; }

/* ===== Code blocks ===== */
.code-block {
  margin: 10px 0;
  border-radius: 12px;
  overflow: hidden;
}

body:not(.dark) .code-block { background: #f7f7f7; border: 1px solid #e8e8e8; }
body.dark .code-block { background: #1a1a2e; border: 1px solid #333; }

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  border-bottom: 1px solid;
}

body:not(.dark) .code-header { background: #efefef; border-color: #e8e8e8; }
body.dark .code-header { background: #16213e; border-color: #333; }

.code-lang { font-size: 11px; font-weight: 500; text-transform: capitalize; }
body:not(.dark) .code-lang { color: #666; }
body.dark .code-lang { color: #a0a0ff; }

.code-actions { display: flex; gap: 6px; }

/* ===== Tables ===== */
.msg-text table {
  border-collapse: collapse;
  width: 100%;
  margin: 10px 0;
  font-size: 13px;
}

.msg-text th, .msg-text td {
  border: 1px solid;
  padding: 6px 10px;
  text-align: left;
}

body:not(.dark) .msg-text th {
  background: #f0f0f0;
  border-color: #e0e0e0;
  font-weight: 600;
}

body.dark .msg-text th {
  background: #252540;
  border-color: #333;
  font-weight: 600;
}

body:not(.dark) .msg-text td {
  border-color: #e8e8e8;
}

body.dark .msg-text td {
  border-color: #333;
}

/* ===== Attach Button ===== */
.attach-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

body:not(.dark) .attach-btn {
  background: #e8e8e8;
  color: #555;
}

body:not(.dark) .attach-btn:hover {
  background: #ddd;
  color: #333;
}

body.dark .attach-btn {
  background: #333;
  color: #ccc;
}

body.dark .attach-btn:hover {
  background: #444;
  color: #fff;
}

/* ===== File Preview ===== */
.file-preview {
  max-width: 780px;
  margin: 0 auto 8px;
  width: 100%;
}

.file-preview-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
}

body:not(.dark) .file-preview-item {
  background: #f0f0f0;
  border: 1px solid #e0e0e0;
}

body.dark .file-preview-item {
  background: #252525;
  border: 1px solid #333;
}

.file-preview-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

body:not(.dark) .file-preview-icon { background: #e8e8e8; }
body.dark .file-preview-icon { background: #333; }

.file-preview-icon.image-icon { background: #e3f2fd; }
body.dark .file-preview-icon.image-icon { background: #1a3a4a; }
.file-preview-icon.pdf-icon { background: #fce4ec; }
body.dark .file-preview-icon.pdf-icon { background: #3a1a1a; }
.file-preview-icon.doc-icon { background: #e8f5e9; }
body.dark .file-preview-icon.doc-icon { background: #1a3a1a; }
.file-preview-icon.code-icon { background: #f3e5f5; }
body.dark .file-preview-icon.code-icon { background: #2a1a3a; }
.file-preview-icon.spreadsheet-icon { background: #e8f5e9; }
body.dark .file-preview-icon.spreadsheet-icon { background: #1a3a1a; }

.file-preview-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-preview-size {
  font-size: 11px;
  flex-shrink: 0;
}

body:not(.dark) .file-preview-size { color: #999; }
body.dark .file-preview-size { color: #666; }

.file-preview-remove {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.2s;
}

body:not(.dark) .file-preview-remove { color: #999; }
body:not(.dark) .file-preview-remove:hover { background: #e0e0e0; }
body.dark .file-preview-remove { color: #666; }
body.dark .file-preview-remove:hover { background: #333; }

.file-preview-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.file-action-btn {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

body:not(.dark) .file-action-btn {
  background: #fff;
  border: 1px solid #ddd;
  color: #333;
}

body:not(.dark) .file-action-btn:hover {
  background: #f5f5f5;
  border-color: #ccc;
}

body.dark .file-action-btn {
  background: #252525;
  border: 1px solid #444;
  color: #ccc;
}

body.dark .file-action-btn:hover {
  background: #333;
}

/* ===== Image Preview ===== */
.file-image-preview {
  max-width: 200px;
  max-height: 150px;
  border-radius: 8px;
  margin-top: 8px;
}

/* ===== Export Menu ===== */
.export-menu {
  position: absolute;
  bottom: 80px;
  right: 20px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  padding: 6px;
  z-index: 100;
  min-width: 200px;
  border: 1px solid;
}

body:not(.dark) .export-menu { border-color: #e0e0e0; }
body.dark .export-menu { background: #252525; border-color: #333; }

.export-item {
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
}

body:not(.dark) .export-item:hover { background: #f5f5f5; }
body.dark .export-item:hover { background: #2f2f2f; }

.copy-btn, .save-btn {
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

body:not(.dark) .copy-btn { background: #fff; border: 1px solid #ddd; color: #555; }
body:not(.dark) .copy-btn:hover { background: #f5f5f5; }

body.dark .copy-btn { background: #252525; border: 1px solid #444; color: #ccc; }
body.dark .copy-btn:hover { background: #2f2f2f; }

body:not(.dark) .save-btn { background: #1f1f1f; border: 1px solid #1f1f1f; color: #fff; }
body:not(.dark) .save-btn:hover { background: #333; }

body.dark .save-btn { background: #444; border: 1px solid #555; color: #fff; }
body.dark .save-btn:hover { background: #555; }

.code-body {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

body:not(.dark) .code-body { color: #1f1f1f; }
body.dark .code-body { color: #c0c0e0; }

.inline-code {
  padding: 2px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12.5px;
  border: 1px solid;
}

body:not(.dark) .inline-code { background: #f0f0f0; color: #1f1f1f; border-color: #e0e0e0; }
body.dark .inline-code { background: #252540; color: #a0a0ff; border-color: #333; }

/* ===== Input Area ===== */
.input-area { padding: 12px 20px 20px; }

.input-wrapper {
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border-radius: 24px;
  padding: 8px 8px 8px 18px;
  transition: all 0.2s;
}

body:not(.dark) .input-wrapper {
  background: #f2f2f2;
  border: 1px solid #e0e0e0;
}

body:not(.dark) .input-wrapper:focus-within {
  border-color: #ccc;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
}

body.dark .input-wrapper {
  background: #252525;
  border: 1px solid #333;
}

body.dark .input-wrapper:focus-within {
  border-color: #555;
  background: #2a2a2a;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

#messageInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  padding: 8px 0;
  max-height: 120px;
  line-height: 1.4;
}

body:not(.dark) #messageInput { color: #1f1f1f; }
body:not(.dark) #messageInput::placeholder { color: #999; }
body.dark #messageInput { color: #e0e0e0; }
body.dark #messageInput::placeholder { color: #555; }

#sendBtn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
}

body:not(.dark) #sendBtn { background: #1f1f1f; color: #fff; }
body:not(.dark) #sendBtn:hover { background: #333; transform: scale(1.05); }

body.dark #sendBtn { background: #444; color: #fff; }
body.dark #sendBtn:hover { background: #555; transform: scale(1.05); }

#sendBtn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

/* ===== Context Menu ===== */
.context-menu {
  position: fixed;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  padding: 6px;
  z-index: 200;
  min-width: 180px;
}

body:not(.dark) .context-menu { background: #fff; border: 1px solid #e0e0e0; }
body.dark .context-menu { background: #252525; border: 1px solid #333; }

.context-item {
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.15s;
}

body:not(.dark) .context-item:hover { background: #f5f5f5; }
body.dark .context-item:hover { background: #2f2f2f; }
.context-item.danger { color: #e53e3e; }

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 200;
  animation: fadeIn 0.2s ease;
}

body:not(.dark) .toast { background: #1f1f1f; color: #fff; }
body.dark .toast { background: #555; color: #fff; }

/* ===== Mobile ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 90;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  .msg-row { padding: 10px 14px; }
  .input-area { padding: 10px 12px 14px; }
  .suggestions { grid-template-columns: 1fr; }
}
