:root {
  --bg: #0e141b;
  --panel: #121d27;
  --muted: #8ea3b8;
  --text: #eef5fb;
  --accent: #4dd0a8;
  --line: rgba(255,255,255,0.08);
  --warn: #ffb84d;
  --user: #1d3446;
  --assistant: #172d24;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(77,208,168,.18), transparent 28%),
    radial-gradient(circle at top right, rgba(92,132,255,.16), transparent 24%),
    var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
.auth-gate {
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: min(100%, 460px);
  background: linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 28px 22px;
  box-shadow: 0 24px 80px rgba(0,0,0,.32);
}
.shell { min-height: 100svh; padding: 18px; width: 100%; overflow-x: hidden; }
.shell-hidden { display: none; }
.hero { padding: 10px 4px 20px; }
.hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.eyebrow { text-transform: uppercase; letter-spacing: .18em; color: var(--accent); font-size: 12px; }
h1 { margin: 0 0 8px; font-size: clamp(30px, 7vw, 48px); line-height: .96; max-width: 8ch; }
.sub, .hint { color: var(--muted); max-width: 44rem; }
.token-row { display: flex; gap: 10px; margin: 16px 0 10px; flex-wrap: wrap; }
.auth-row {
  flex-direction: column;
}
.token-row input, .token-row button, .panel-head button {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255,255,255,.03);
  color: var(--text);
}
.token-row input { flex: 1; }
.token-row button, .panel-head button { background: var(--accent); color: #062419; font-weight: 700; border: none; }
.secondary-btn {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255,255,255,.03);
  color: var(--text);
  font-weight: 700;
}
.auth-error {
  margin: 6px 0 0;
  color: #ff8d8d;
}
.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; width: 100%; }
.panel {
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.02));
  border: 1px solid var(--line);
  border-radius: 24px;
  overflow: hidden;
  min-height: 42svh;
  min-width: 0;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.title-wrap {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.title-wrap h2 {
  margin: 0;
}
.toolbar { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.badge {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,184,77,.18);
  color: var(--warn);
}
.badge.live { background: rgba(77,208,168,.18); color: var(--accent); }
.threads, .messages {
  padding: 8px;
  min-width: 0;
}
.threads {
  display: grid;
  gap: 10px;
}
.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: min(68svh, 760px);
  max-height: min(68svh, 760px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  align-items: stretch;
}
.composer-body { padding: 16px; display: grid; gap: 12px; border-bottom: 1px solid var(--line); }
.chat-reply { border-top: 1px solid var(--line); border-bottom: none; }
.author-row {
  display: grid;
  gap: 6px;
}
.text-input.slim {
  max-width: 180px;
}
.text-input, .text-area {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255,255,255,.03);
  color: var(--text);
  font: inherit;
}
.text-area { min-height: 132px; resize: vertical; }
.text-area.compact { min-height: 92px; }
.send-btn {
  border: none;
  border-radius: 16px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--accent), #6fb7ff);
  color: #072118;
  font-weight: 800;
}
.thread {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255,255,255,.03);
  border: 1px solid transparent;
  min-width: 0;
}
.thread.active { border-color: rgba(77,208,168,.5); }
.thread-title { font-weight: 700; margin: 0 0 6px; }
.thread-meta { color: var(--muted); font-size: 12px; }
.message {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.45;
  border: 1px solid var(--line);
  min-width: 0;
  min-height: auto;
  overflow: visible;
}
.message.user { background: var(--user); }
.message.assistant { background: var(--assistant); }
.message.system { background: rgba(255,255,255,.05); }
.message.kind-delivery_status {
  border-style: dashed;
}
.message.status-sending {
  background: rgba(92, 132, 255, 0.14);
  border-color: rgba(92, 132, 255, 0.4);
}
.message.status-sent {
  background: rgba(77, 208, 168, 0.14);
  border-color: rgba(77, 208, 168, 0.42);
}
.message.status-busy,
.message.status-blocked {
  background: rgba(255, 184, 77, 0.14);
  border-color: rgba(255, 184, 77, 0.42);
}
.message.status-failed {
  background: rgba(255, 96, 96, 0.14);
  border-color: rgba(255, 96, 96, 0.42);
}
.message-meta {
  display: block;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  line-height: 1.35;
}
.message-text {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
@media (min-width: 980px) {
  .shell { padding: 28px; }
  .grid { grid-template-columns: 320px 1fr 420px; align-items: start; }
  .panel { min-height: calc(100svh - 220px); }
  .messages {
    height: min(62svh, 760px);
    max-height: min(62svh, 760px);
  }
}
