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

:root {
  --bg-base:     #0f1117;
  --bg-sidebar:  #161b27;
  --bg-surface:  #1e2535;
  --bg-input:    #252d3e;
  --border:      #2d3748;
  --text-primary: #e2e8f0;
  --text-muted:   #64748b;
  --text-subtle:  #94a3b8;
  --accent:       #3b82f6;
  --accent-hover: #2563eb;
  --user-bubble:  #1d3461;
  --assistant-bg: #1a2035;
  --artifact-bg:  #141923;
  --artifact-border: #2d4a6b;
  --success:      #22c55e;
  --error:        #ef4444;
  --warning:      #f59e0b;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */

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

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.sidebar-logo {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  text-decoration: none;
  letter-spacing: -0.3px;
  flex-shrink: 0;
}
.sidebar-logo span { color: #1B96FF; }

.sidebar-header h2 {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}

.btn-new-chat {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-subtle);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
}
.btn-new-chat:hover { border-color: var(--accent); color: var(--accent); }

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.conv-item {
  padding: 0.6rem 0.75rem;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.1s;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.conv-item:hover  { background: var(--bg-surface); }
.conv-item.active { background: var(--bg-input); }

.conv-title {
  font-size: 0.82rem;
  color: var(--text-subtle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.conv-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity 0.15s;
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-delete:hover { color: var(--error); background: rgba(239,68,68,0.1); }

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.usage-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-signout {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  text-decoration: underline;
  padding: 0;
}
.btn-signout:hover { color: var(--text-subtle); }

/* ── Main Chat Area ───────────────────────────────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 0.875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-sidebar);
}

.chat-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-subtle);
}

.btn-download {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  padding: 0.3rem 0.65rem;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.btn-download:hover { border-color: var(--accent); color: var(--accent); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Message Bubbles ─────────────────────────────────────────────────────────── */

.message { display: flex; flex-direction: column; max-width: 84%; }
.message.user   { align-self: flex-end; align-items: flex-end; }
.message.assistant { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 3px;
  color: #dbeafe;
}

.message.assistant .bubble {
  background: var(--assistant-bg);
  border-bottom-left-radius: 3px;
  border: 1px solid var(--border);
}

/* Streaming cursor */
.streaming-cursor::after {
  content: '▋';
  animation: blink 0.8s step-end infinite;
  color: var(--accent);
  margin-left: 1px;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ── Artifact Cards ──────────────────────────────────────────────────────────── */

.artifact-card {
  margin-top: 0.75rem;
  background: var(--artifact-bg);
  border: 1px solid var(--artifact-border);
  border-radius: 10px;
  overflow: hidden;
  width: 100%;
  max-width: 640px;
}

.artifact-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: rgba(45, 74, 107, 0.3);
  border-bottom: 1px solid var(--artifact-border);
  gap: 0.5rem;
}

.artifact-lang {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #93c5fd;
}

.artifact-actions {
  display: flex;
  gap: 0.4rem;
}

.btn-artifact {
  border: none;
  border-radius: 5px;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-copy {
  background: var(--bg-input);
  color: var(--text-subtle);
}
.btn-copy:hover { background: var(--bg-surface); color: var(--text-primary); }

.btn-deploy {
  background: var(--accent);
  color: #fff;
}
.btn-deploy:hover { background: var(--accent-hover); }
.btn-deploy:disabled { background: #374151; color: var(--text-muted); cursor: not-allowed; }

.artifact-code {
  padding: 0.75rem 1rem;
  font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  color: #cbd5e1;
  overflow-x: auto;
  white-space: pre;
  max-height: 320px;
  overflow-y: auto;
}

.deploy-status {
  padding: 0.4rem 0.75rem;
  font-size: 0.78rem;
  border-top: 1px solid var(--artifact-border);
}
.deploy-status.success { color: var(--success); background: rgba(34, 197, 94, 0.08); }
.deploy-status.error   { color: var(--error);   background: rgba(239, 68, 68, 0.08); }
.deploy-status.loading { color: var(--warning);  background: rgba(245, 158, 11, 0.08); }

/* ── Empty State ─────────────────────────────────────────────────────────────── */

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 1rem; }
.empty-state h3 { font-size: 1rem; color: var(--text-subtle); margin-bottom: 0.5rem; }
.empty-state p  { font-size: 0.82rem; max-width: 320px; line-height: 1.55; }

/* ── Input Area ──────────────────────────────────────────────────────────────── */

.input-area {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--bg-sidebar);
}

.input-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.5rem 0.5rem 0.875rem;
  transition: border-color 0.15s;
}
.input-row:focus-within { border-color: var(--accent); }

#message-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.875rem;
  resize: none;
  line-height: 1.5;
  max-height: 160px;
  overflow-y: auto;
  padding: 0.15rem 0;
}
#message-input::placeholder { color: var(--text-muted); }

.btn-send {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 7px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: var(--accent-hover); }
.btn-send:disabled { background: #374151; cursor: not-allowed; }
.btn-send svg { width: 16px; height: 16px; }

/* ── Scrollbar ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2d3748; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4b5563; }
