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

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --border:   #2e3147;
  --accent:   #7c6af7;
  --user-bg:  #26293b;
  --bot-bg:   #1a1d27;
  --text:     #e2e4f0;
  --muted:    #6b7099;
  --radius:   12px;
  --font:     'Segoe UI', system-ui, sans-serif;
}

/* ── Light mode ─────────────────────────────────────────────────────────── */
:root[data-theme="light"] {
  --bg:       #f5f6fa;
  --surface:  #ffffff;
  --border:   #e0e2ec;
  --accent:   #6554e8;
  --user-bg:  #eef0fb;
  --bot-bg:   #ffffff;
  --text:     #1a1d27;
  --muted:    #6b7099;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  display: flex;
  justify-content: center;
  align-items: stretch;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 760px;
  height: 100dvh;
  padding: 0;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

header h1 { flex: 1; font-size: 1.1rem; font-weight: 600; }

.brand { color: #2e7d32; }

.model-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#clear-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 1rem;
  transition: color 0.15s, border-color 0.15s;
}
#clear-btn:hover { color: var(--text); border-color: var(--text); }

#theme-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 1rem;
  transition: color 0.15s, border-color 0.15s;
}
#theme-btn:hover { color: var(--text); border-color: var(--text); }

/* ── Messages ───────────────────────────────────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 4px;
}

.msg.user  { align-self: flex-end; align-items: flex-end; }
.msg.bot   { align-self: flex-start; align-items: flex-start; }

.msg .role {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.msg .bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user .bubble {
  background: var(--user-bg);
  border: 1px solid var(--border);
  border-bottom-right-radius: 3px;
}

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

/* streaming cursor */
.cursor::after {
  content: '▋';
  display: inline-block;
  animation: blink 0.7s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ── Input form ─────────────────────────────────────────────────────────── */
#chat-form {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

#input {
  flex: 1;
  resize: none;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.15s;
}
#input:focus { border-color: var(--accent); }

#send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0 22px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: opacity 0.15s;
  align-self: flex-end;
  height: 42px;
}
#send-btn:hover  { opacity: 0.85; }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Footer ─────────────────────────────────────────────────────────────── */
footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  padding: 8px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.75rem;
  color: var(--muted);
  flex-shrink: 0;
  text-align: center;
}

footer span { display: inline-block; }

footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  transition: opacity 0.15s;
}
footer a:hover { opacity: 0.8; }
