/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #252525;
  --bg-hover: #2a2a2a;
  --border: #333;
  --text: #e5e5e5;
  --text-secondary: #888;
  --text-muted: #555;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: rgba(99, 102, 241, 0.15);
  --user-bubble: #6366f1;
  --assistant-bubble: #1e1e1e;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-width: 300px;
  --header-height: 56px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.5;
}

/* Screens */
.screen { display: flex; height: 100vh; }
.hidden { display: none !important; }

/* Auth */
.auth-container {
  margin: auto;
  text-align: center;
  padding: 2rem;
}
.auth-logo {
  color: var(--accent);
  margin-bottom: 1rem;
}
.auth-container h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.auth-subtitle {
  color: var(--text-secondary);
  margin-bottom: 2rem;
}
.auth-note {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 1.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  padding: 0.6rem 1.2rem;
  transition: all 0.15s ease;
}
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-google {
  background: white;
  color: #333;
  padding: 0.75rem 1.5rem;
  font-size: 15px;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.btn-google:hover { background: #f5f5f5; }
.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text);
  border: none;
  cursor: pointer;
}
.btn-icon:hover { background: var(--bg-hover); }
.btn-ghost { background: none; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 13px; }
.btn-xs { padding: 0.2rem 0.4rem; font-size: 16px; line-height: 1; }
.btn-danger { background: var(--danger); color: white; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

/* Tabs */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1;
  padding: 0.6rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.tab:hover { color: var(--text); }
.tab-content { display: none; flex: 1; overflow-y: auto; }
.tab-content.active { display: flex; flex-direction: column; }

/* Chat List */
.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--accent-soft); }
.chat-item-info { flex: 1; min-width: 0; }
.chat-item-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
}
.chat-item-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}
.chat-item-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 16px;
  border-radius: 4px;
}
.chat-item:hover .chat-item-delete { opacity: 1; }
.chat-item-delete:hover { color: var(--danger); background: rgba(239,68,68,0.1); }

/* Agent List */
.agent-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.75rem;
}
.agent-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
}
.agent-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.agent-card-icon { font-size: 1.5rem; margin-bottom: 0.25rem; }
.agent-card-name { font-size: 12px; font-weight: 600; }
.agent-card-desc { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

/* Image Gen */
.image-gen-form { padding: 0.75rem; border-bottom: 1px solid var(--border); }
.image-gen-form textarea {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 0.5rem;
  resize: none;
}
.image-gen-form textarea:focus { outline: none; border-color: var(--accent); }
.image-gen-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.image-gen-controls select {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 0.4rem;
}
.image-gallery {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.75rem;
  overflow-y: auto;
}
.image-gallery-item {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
}
.image-gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Sidebar Footer */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}
.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 13px;
  font-weight: 500;
  min-width: 0;
}
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
#user-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-header-info { flex: 1; min-width: 0; }
#chat-title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
}
.model-select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
}
.model-select:focus { outline: none; border-color: var(--accent); }

/* Messages */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-secondary);
}
.empty-state p { margin-top: 0.5rem; }
.text-muted { color: var(--text-muted); font-size: 13px; }

/* Message Bubbles */
.message {
  display: flex;
  gap: 0.75rem;
  max-width: 80%;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.message.user { align-self: flex-end; flex-direction: row-reverse; }
.message.assistant { align-self: flex-start; }

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.message.user .message-avatar { background: var(--accent); color: white; }
.message.assistant .message-avatar { background: var(--bg-tertiary); border: 1px solid var(--border); }

.message-content {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  line-height: 1.6;
  font-size: 14px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.message.user .message-content {
  background: var(--user-bubble);
  color: white;
  border-bottom-right-radius: 4px;
}
.message.assistant .message-content {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Markdown in messages */
.message-content h1, .message-content h2, .message-content h3 {
  margin: 0.75rem 0 0.25rem;
  font-weight: 600;
}
.message-content h1 { font-size: 1.2em; }
.message-content h2 { font-size: 1.1em; }
.message-content h3 { font-size: 1em; }
.message-content p { margin: 0.4rem 0; }
.message-content ul, .message-content ol { margin: 0.4rem 0; padding-left: 1.5rem; }
.message-content li { margin: 0.2rem 0; }
.message-content strong { font-weight: 600; }

.message-content code {
  background: rgba(255,255,255,0.1);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.9em;
}
.message-content pre {
  background: #0d0d0d;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin: 0.5rem 0;
  overflow-x: auto;
  position: relative;
}
.message-content pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
}
.copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.copy-btn:hover { color: var(--text); }

.message-content a { color: var(--accent); text-decoration: none; }
.message-content a:hover { text-decoration: underline; }

.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 0.75rem;
  margin: 0.5rem 0;
  color: var(--text-secondary);
}

.message-image {
  max-width: 300px;
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
}

/* Streaming cursor */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  animation: blink 0.8s infinite;
  vertical-align: text-bottom;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* Compose */
.compose-area {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.image-preview {
  position: relative;
  display: inline-block;
  margin-bottom: 0.5rem;
}
.image-preview img {
  height: 60px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.image-preview .btn-xs {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 14px;
  line-height: 1;
}
.compose-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem;
}
.compose-bar textarea {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 0.4rem;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  line-height: 1.5;
}
.compose-bar textarea:focus { outline: none; }
.compose-bar textarea::placeholder { color: var(--text-muted); }

.attach-btn { cursor: pointer; }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 100;
  animation: toastIn 0.3s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

/* Mobile */
.mobile-only { display: none; }

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: flex; }
  .message { max-width: 90%; }
}
