:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e3e6ea;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #2f6df6;
  --accent-ink: #ffffff;
  --user-bubble: #2f6df6;
  --bot-bubble: #ffffff;
  --chip: #eef2ff;
  --chip-ink: #3b4fb8;
  --error: #b42318;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --border: #262c35;
    --text: #e7eaee;
    --muted: #9aa3af;
    --bot-bubble: #1d222a;
    --chip: #1f2a4a;
    --chip-ink: #aebcff;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
}

.app {
  max-width: 820px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}
body.embed .app { max-width: none; padding: 0 12px; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 10px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 18px;
}
.title { font-weight: 650; font-size: 16px; }
.subtitle { color: var(--muted); font-size: 12.5px; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.status { width: 9px; height: 9px; border-radius: 50%; background: #c4c9d0; }
.status.ok { background: #16a34a; }
.status.bad { background: var(--error); }
.icon-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 6px 10px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.icon-btn:hover { background: var(--surface); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}
.msg { display: flex; flex-direction: column; max-width: 85%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.bot { align-self: flex-start; }
.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--user-bubble);
  color: var(--accent-ink);
  border-color: transparent;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.msg.bot .bubble { border-bottom-left-radius: 4px; }
.msg.bot.error .bubble { border-color: var(--error); color: var(--error); }

.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble li { margin: 2px 0; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 15px; margin: 10px 0 4px; }
.bubble code { font-family: var(--mono); font-size: 13px; background: rgba(127,127,127,.14); padding: 1px 5px; border-radius: 5px; }
.bubble pre { background: rgba(127,127,127,.12); padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: 6px 0 10px; }
.bubble pre code { background: none; padding: 0; }
.bubble a { color: var(--accent); text-decoration: none; }
.bubble a:hover { text-decoration: underline; }
.bubble blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--border); color: var(--muted); }
.bubble table { border-collapse: collapse; margin: 6px 0; font-size: 13.5px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 4px 8px; }

.activity {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 13px; margin: 6px 2px 0;
}
.activity .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: .25 } 50% { opacity: 1 } }

.sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sources .label { color: var(--muted); font-size: 12.5px; align-self: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--chip); color: var(--chip-ink);
  padding: 4px 10px; border-radius: 999px; font-size: 12.5px;
  text-decoration: none; max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.chip:hover { filter: brightness(.95); }

.cursor::after { content: "▍"; animation: pulse 1s infinite; color: var(--muted); }

.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 8px 8px 14px;
  margin-top: 4px;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,109,246,.15); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent;
  font: inherit; color: inherit; max-height: 160px; padding: 6px 0;
}
.composer button {
  width: 38px; height: 38px; border-radius: 10px; border: 0;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; cursor: pointer;
}
.composer button:disabled { opacity: .5; cursor: not-allowed; }

.footnote { color: var(--muted); font-size: 11.5px; text-align: center; padding: 8px 0 12px; }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.suggestions button {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.suggestions button:hover { border-color: var(--accent); }

.escalate { margin-top: 8px; }
.escalate button {
  background: transparent; border: 1px dashed var(--border); color: var(--muted);
  border-radius: 999px; padding: 5px 12px; font-size: 12.5px; cursor: pointer;
}
.escalate button:hover { color: var(--accent); border-color: var(--accent); }
.ticket-tag {
  align-self: flex-start;
  display: inline-block; margin-top: 8px; padding: 4px 10px; border-radius: 999px;
  background: #dcfce7; color: #166534; font-size: 12.5px; font-weight: 600;
}
@media (prefers-color-scheme: dark) { .ticket-tag { background: #14532d; color: #bbf7d0; } }
