:root {
  --bg: #0d0d0d;
  --bg-elevated: #171717;
  --bg-sidebar: #111111;
  --border: #2a2a2a;
  --text: #ececec;
  --text-muted: #9b9b9b;
  --accent: #ff481f;
  --accent-hover: #ff6b47;
  --user-bg: #2f2f2f;
  --input-bg: #2a2a2a;
  --radius: 16px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-elevated: #f7f7f8;
  --bg-sidebar: #f9f9f9;
  --border: #e5e5e5;
  --text: #0d0d0d;
  --text-muted: #6e6e80;
  --user-bg: #f4f4f4;
  --input-bg: #ffffff;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }

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

.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.25s ease;
  z-index: 100;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
}

.sidebar-logo img { height: 28px; }

.new-chat-btn {
  margin: 12px 16px;
  padding: 10px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  width: calc(100% - 32px);
}

.new-chat-btn:hover { background: var(--bg-elevated); }

.chat-history { flex: 1; overflow-y: auto; padding: 8px 12px; }

.history-item {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.history-item:hover, .history-item.active {
  background: var(--bg-elevated);
  color: var(--text);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  margin-right: 6px;
}

.status-dot.syncing { background: #f59e0b; animation: pulse 1.5s infinite; }

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

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.topbar-left { display: flex; align-items: center; gap: 10px; }

.menu-btn, .icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.menu-btn:hover, .icon-btn:hover { background: var(--bg-elevated); color: var(--text); }

.model-select-wrap { position: relative; }

.model-select {
  appearance: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 32px 8px 12px;
  cursor: pointer;
  min-width: 200px;
}

.model-select-wrap::after {
  content: '▾';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--text-muted);
}

.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  border-radius: 10px;
  padding: 3px;
  border: 1px solid var(--border);
}

.mode-tab {
  padding: 6px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
}

.mode-tab.active { background: var(--accent); color: #fff; }

.chat-area { flex: 1; overflow-y: auto; }

.messages { max-width: 768px; margin: 0 auto; padding: 24px 16px 120px; }

.welcome { text-align: center; padding: 60px 20px; }
.welcome h1 { font-size: 28px; font-weight: 700; margin-bottom: 8px; }
.welcome p { color: var(--text-muted); font-size: 15px; margin-bottom: 32px; }

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 520px;
  margin: 0 auto;
}

.suggestion {
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
}

.suggestion:hover { border-color: var(--accent); }

.msg-row { display: flex; gap: 16px; padding: 20px 0; }

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

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}

.msg-row.ai .msg-avatar { background: var(--accent); color: #fff; }
.msg-row.user .msg-avatar { background: #5436da; color: #fff; }

.msg-body { flex: 1; min-width: 0; font-size: 15px; line-height: 1.65; }

.msg-row.user .msg-body {
  background: var(--user-bg);
  padding: 12px 16px;
  border-radius: 18px;
  border-top-right-radius: 4px;
  max-width: 85%;
}

.msg-body pre {
  background: #1e1e1e;
  border-radius: 8px;
  padding: 14px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
}

[data-theme="light"] .msg-body pre { background: #f4f4f4; }

.typing-dots { display: flex; gap: 5px; padding: 8px 0; }
.typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

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

.generated-image { max-width: 100%; border-radius: 12px; margin-top: 10px; border: 1px solid var(--border); }

.input-area {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px 20px;
  background: linear-gradient(transparent, var(--bg) 30%);
}

.input-wrap {
  max-width: 768px;
  margin: 0 auto;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: flex-end;
  padding: 8px 8px 8px 16px;
}

.input-wrap:focus-within { border-color: var(--accent); }

.input-wrap textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 200px;
  line-height: 1.5;
  padding: 8px 0;
  outline: none;
}

.send-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
}

.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 8px; }

.attach-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}

.image-preview {
  display: none;
  max-width: 120px;
  max-height: 80px;
  border-radius: 8px;
  margin: 0 8px 8px 16px;
  border: 1px solid var(--border);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .suggestion-grid { grid-template-columns: 1fr; }
  .model-select { min-width: 140px; max-width: 180px; font-size: 12px; }
  .mode-tabs { display: none; }
}

@media (min-width: 769px) { .menu-btn { display: none; } }
