:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #1c1d21;
  --muted: #6b7280;
  --line: #e3e5e9;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --user: #eef2ff;
  --warn-bg: #fef3c7;
  --warn-ink: #92400e;
  --error: #b91c1c;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.muted { color: var(--muted); }
.error { color: var(--error); font-weight: 600; }

/* login */
.centered {
  align-items: center;
  justify-content: center;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px;
  width: min(360px, 92vw);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
}
.card h1 { margin: 0 0 4px; font-size: 20px; }
.card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; }
.card input {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 16px;
}
button {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: default; }
button.link {
  background: none;
  color: var(--accent);
  padding: 0;
  font-weight: 600;
}

/* chat */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-left { min-width: 0; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap; justify-content: flex-end; }
.topbar-right form { margin: 0; }

@media (max-width: 480px) {
  .topbar { justify-content: space-between; }
  .topbar-right { flex: 1 1 100%; justify-content: space-between; }
  .client-picker select { max-width: none; flex: 1; }
}
.chip {
  background: var(--user);
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 600;
}
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }

.client-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.client-picker select {
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  background: var(--user);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  max-width: 55vw;
}

.messages {
  flex: 1;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg {
  padding: 12px 14px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg.intro { white-space: normal; }
.msg.thinking { color: var(--muted); animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .45; } 50% { opacity: 1; } }
.msg.user { background: var(--user); align-self: flex-end; max-width: 85%; }
.msg.assistant { background: var(--card); border: 1px solid var(--line); align-self: flex-start; max-width: 95%; }
.msg.err { background: #fee2e2; color: var(--error); }

.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--card);
  border-top: 1px solid var(--line);
  width: min(760px, 100%);
  margin: 0 auto;
}
.composer textarea {
  flex: 1;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  max-height: 160px;
}
