:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-soft: color-mix(in srgb, var(--accent) 15%, transparent);
  --user: #1e3a5f;
  --bot: #1a2e1a;
  --danger: #f87171;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body.mode-embed {
  min-height: 100%;
  height: 100%;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

body.mode-embed header {
  padding: 0.65rem 0.85rem;
}

header .header-text { min-width: 0; }

header h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

body.mode-embed header h1 {
  font-size: 0.95rem;
}

header p {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

body.mode-embed header p {
  display: none;
}

header .logo {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

body.mode-embed header .logo {
  width: 1.75rem;
  height: 1.75rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-icon {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
}

.btn-icon:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.chat-wrap {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 48rem;
  width: 100%;
  margin: 0 auto;
}

body.mode-embed #chat {
  padding: 0.65rem;
  max-width: none;
  gap: 0.5rem;
}

.msg {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  line-height: 1.5;
  white-space: pre-wrap;
  max-width: 95%;
  font-size: 0.95rem;
}

body.mode-embed .msg {
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
  border-radius: 8px;
}

.msg.user { background: var(--user); align-self: flex-end; }
.msg.assistant { background: var(--bot); align-self: flex-start; border: 1px solid var(--border); }
.msg.assistant.welcome {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
  background: color-mix(in srgb, var(--accent) 12%, var(--bot));
}
.msg.system { color: var(--muted); font-size: 0.85rem; align-self: center; }

.msg.thinking {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.88rem;
  padding: 0.55rem 0.85rem;
}

.msg.thinking .thinking-label {
  font-weight: 500;
}

.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
}

.thinking-dots span {
  width: 0.35rem;
  height: 0.35rem;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.35;
  animation: thinking-bounce 1.2s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.composer {
  border-top: 1px solid var(--border);
  background: var(--panel);
  max-width: 48rem;
  width: 100%;
  margin: 0 auto;
  padding: 0.75rem 1rem 1rem;
  flex-shrink: 0;
}

body.mode-embed .composer {
  max-width: none;
  padding: 0.55rem 0.65rem 0.65rem;
}

.attach-chip {
  display: none;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  padding: 0.4rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 100%;
}

.attach-chip.visible { display: flex; }

.attach-chip .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.attach-chip .remove {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0 0.25rem;
  font-size: 1.1rem;
  line-height: 1;
}

.attach-chip .remove:hover { color: var(--danger); }

form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.attach-btn {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

body.mode-embed .attach-btn {
  width: 2.25rem;
  height: 2.25rem;
}

.attach-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.attach-btn svg { width: 1.15rem; height: 1.15rem; }

#fileInput { display: none; }

textarea {
  flex: 1;
  resize: none;
  min-height: 2.5rem;
  max-height: 8rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

body.mode-embed textarea {
  min-height: 2.25rem;
  max-height: 5rem;
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
}

button#send {
  padding: 0 1.25rem;
  height: 2.5rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

body.mode-embed button#send {
  height: 2.25rem;
  padding: 0 0.9rem;
  font-size: 0.9rem;
}

button#send:disabled { opacity: 0.5; cursor: not-allowed; }

.drop-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(15, 20, 25, 0.82);
  border: 2px dashed var(--accent);
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
  pointer-events: none;
}

.chat-wrap.dragging .drop-overlay { display: flex; }

.auth-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(15, 20, 25, 0.92);
  text-align: center;
}

.auth-overlay.visible { display: flex; }

.auth-overlay .auth-box {
  max-width: 22rem;
}

.auth-overlay h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
}

.auth-overlay p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.composer.blocked {
  opacity: 0.45;
  pointer-events: none;
}
