/* ─── Variables ─────────────────────────────────── */
:root {
  --bg:         #0d1117;
  --surface:    #161b22;
  --surface-2:  #1c2128;
  --border:     #30363d;
  --border-sub: #21262d;
  --primary:    #58a6ff;
  --primary-dim:#162032;
  --text:       #e6edf3;
  --text-dim:   #7d8590;
  --text-sub:   #444c56;
  --user-bg:    #1c2335;
  --user-border:#2a3f63;
  --ai-bg:      #161b22;
  --radius:     6px;
  --font:       'Geist', system-ui, sans-serif;
  --font-mono:  'Geist Mono', 'Fira Code', monospace;
}

/* ─── Keyframes ──────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes msgInLeft {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes msgInRight {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes pulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.75); }
  40%            { opacity: 1;   transform: scale(1); }
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── App shell ──────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 780px;
  margin: 0 auto;
  border-left: 1px solid var(--border-sub);
  border-right: 1px solid var(--border-sub);
}

/* ─── Topbar ─────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  animation: fadeIn 200ms ease both;
}

#topbar-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}

/* ─── Model select ───────────────────────────────── */
.model-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
}

.model-icon {
  color: var(--text-sub);
  display: flex;
  align-items: center;
}

#model-select {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  padding: 5px 26px 5px 10px;
  cursor: pointer;
  outline: none;
  max-width: 240px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='%237d8590' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color 150ms ease;
  animation: fadeIn 250ms ease 80ms both;
}
#model-select:hover { border-color: var(--text-dim); }
#model-select:focus { border-color: var(--primary); outline: none; }
#model-select option:disabled {
  color: var(--text-sub);
  cursor: not-allowed;
}

/* ─── Messages area ──────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  background: var(--bg);
  scroll-behavior: smooth;
  animation: slideUp 220ms ease 80ms both;
}
#messages::-webkit-scrollbar { width: 3px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── Message row ────────────────────────────────── */
.msg {
  display: flex;
  gap: 12px;
  max-width: 100%;
  animation: msgInLeft 180ms ease both;
}
.msg.user {
  flex-direction: row-reverse;
  animation: msgInRight 320ms ease both;
}

/* ─── Avatar ─────────────────────────────────────── */
.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
  background: var(--surface-2);
  color: var(--text-sub);
}
.msg.user .msg-avatar {
  background: var(--primary-dim);
  border-color: var(--user-border);
  color: var(--primary);
}

/* ─── Bubble body ────────────────────────────────── */
.msg-body {
  max-width: calc(100% - 50px);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.msg.user .msg-body { align-items: flex-end; }

/* ─── Bubble ─────────────────────────────────────── */
.msg-bubble {
  padding: 11px 15px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
  font-size: 14px;
}
.msg.user .msg-bubble {
  background: var(--user-bg);
  border-color: var(--user-border);
  color: var(--text);
}

/* ─── Loading bubble ─────────────────────────────── */
.msg-bubble.loading {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 18px;
}
.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: pulse 1.4s ease-in-out infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

/* ─── Code inside bubbles ────────────────────────── */
.msg-bubble code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--surface-2);
  border: 1px solid var(--border-sub);
  border-radius: 4px;
  padding: 1px 5px;
}
.msg-bubble pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.6;
}
.msg-bubble strong { color: var(--text); font-weight: 600; }
.msg-bubble em     { color: var(--text-dim); }

/* ─── Empty state ────────────────────────────────── */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 12px;
  user-select: none;
  pointer-events: none;
  animation: slideUp 280ms ease 150ms both;
}
#empty-state svg {
  color: var(--text-sub);
}
#empty-state p {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-dim);
}
#empty-state span {
  font-size: 12px;
  color: var(--text-sub);
}

/* ─── Input area ─────────────────────────────────── */
#input-area {
  padding: 12px 20px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  animation: slideUp 220ms ease 120ms both;
}

#input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 8px 8px 14px;
  transition: border-color 150ms ease;
}
#input-row:focus-within { border-color: #444c56; }

#msg-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  max-height: 200px;
  min-height: 22px;
  overflow-y: auto;
}
#msg-input::placeholder { color: var(--text-sub); }
#msg-input::-webkit-scrollbar { width: 3px; }
#msg-input::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ─── Send button ────────────────────────────────── */
#send-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 5px;
  background: var(--primary);
  color: #0d1117;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 150ms ease, transform 100ms ease;
}
#send-btn:hover    { opacity: 0.88; }
#send-btn:active   { transform: scale(0.91); opacity: 0.75; }
#send-btn:disabled { opacity: 0.3; cursor: default; transform: none; }

/* ─── Hint line ──────────────────────────────────── */
#input-hint {
  margin-top: 7px;
  font-size: 11px;
  color: var(--text-sub);
  text-align: right;
}
