:root {
  --bg: #0b0d12;
  --panel: #141824;
  --panel-2: #1b2133;
  --border: #2a3352;
  --text: #e8ecf6;
  --muted: #9aa3bd;
  --accent: #8b7cf6;
  --accent-2: #f472b6;
  --ok: #34d399;
  --err: #f87171;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: radial-gradient(1200px 600px at 20% -10%, #1b1f3b 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

a { color: var(--accent); }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 13, 18, 0.7);
  backdrop-filter: blur(8px);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: 0.3px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.brand p a { color: var(--muted); text-decoration: none; border-bottom: 1px dashed var(--border); }

.logo {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 20px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 22px rgba(139, 124, 246, 0.35);
}
.logo.big { width: 64px; height: 64px; font-size: 30px; border-radius: 16px; }

.top-actions { display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--panel);
}
.badge.busy { color: var(--accent-2); border-color: var(--accent-2); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.err { color: var(--err); border-color: var(--err); }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:hover { background: #232b47; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { background: transparent; border-color: var(--err); color: var(--err); }

/* ---------- settings ---------- */
.settings {
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.settings-inner {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  gap: 16px;
  align-items: flex-end;
  padding: 14px 18px;
  flex-wrap: wrap;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.field small { font-size: 11px; color: var(--muted); max-width: 320px; }
.field input[type="text"],
.field input[type="password"],
.field select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 13px;
  min-width: 200px;
}
.field.grow { flex: 1 1 320px; }
.field.grow input { width: 100%; }
.field input[type="range"] { accent-color: var(--accent); width: 140px; }

/* ---------- chat ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  padding: 18px;
}
.messages {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.welcome { text-align: center; padding: 40px 12px 12px; }
.welcome h2 { margin: 14px 0 6px; }
.welcome p { color: var(--muted); margin: 4px auto; max-width: 560px; line-height: 1.5; }
.welcome .hint { font-size: 12px; margin-top: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.chip {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.chip:hover { border-color: var(--accent); }

.msg { display: flex; flex-direction: column; gap: 6px; max-width: 92%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; }
.msg.error { align-self: center; }

.bubble {
  padding: 11px 15px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: linear-gradient(135deg, #3d3560, #453a5f);
  border-bottom-right-radius: 4px;
}
.msg.assistant .bubble {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.error .bubble { background: rgba(248, 113, 113, 0.12); border: 1px solid var(--err); color: var(--err); font-size: 13px; }

.attachments-preview { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.attachments-preview img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

details.reasoning {
  background: rgba(139, 124, 246, 0.08);
  border: 1px solid rgba(139, 124, 246, 0.35);
  border-radius: 10px;
  padding: 8px 12px;
  max-width: 92%;
  align-self: flex-start;
}
details.reasoning summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--accent);
  user-select: none;
}
details.reasoning .reasoning-body {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.blink { animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- composer ---------- */
.composer {
  border-top: 1px solid var(--border);
  background: rgba(11, 13, 18, 0.85);
  backdrop-filter: blur(8px);
  padding: 12px 18px 8px;
}
.attachments { max-width: 860px; margin: 0 auto 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.attachments .thumb {
  position: relative;
  width: 64px; height: 64px;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.attachments .thumb img { width: 100%; height: 100%; object-fit: cover; }
.attachments .thumb .x {
  position: absolute; top: 3px; right: 3px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
}

.input-row {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px;
}
.attach {
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  line-height: 1;
  user-select: none;
}
.attach:hover { background: var(--panel-2); }
#imageUrl {
  background: transparent;
  border: none;
  outline: none;
  color: var(--muted);
  font-size: 12.5px;
  width: 200px;
  padding: 8px;
  border-left: 1px solid var(--border);
}
#prompt {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 8px;
  max-height: 140px;
}
#sendBtn { font-size: 15px; padding: 10px 16px; border-radius: 12px; }
#stopBtn { padding: 10px 14px; font-size: 14px; }

.legal { text-align: center; font-size: 11px; color: var(--muted); margin: 8px 0 2px; }

.hidden { display: none !important; }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2b3450; border-radius: 999px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 640px) {
  #imageUrl { display: none; }
  .brand p { display: none; }
}