/* Chat / Marketer AI view ----------------------------------------- */

.chat {
  display: grid;
  grid-template-columns: 296px 1fr;
  height: 100%;
  min-height: 0;
}

/* --- rail ------------------------------------------------------ */
.chat-rail {
  border-right: 1px solid var(--line);
  background: var(--bg);
  display: flex; flex-direction: column;
  min-height: 0;
}
/* Collapsed state — rail slims to a 44px sliver that still holds the
   expand toggle. Grid template flips via :has() so chat-main fills the
   freed space instead of auto-placing into the old 296px column. */
.chat:has(.chat-rail[data-collapsed="true"]) { grid-template-columns: 44px 1fr; }
.chat-rail[data-collapsed="true"] .chat-rail-list { display: none; }
.chat-rail[data-collapsed="true"] .chat-rail-head { padding: 14px 6px; }
.chat-rail[data-collapsed="true"] .chat-rail-head .btn-sm { display: none; }
.chat-rail-head { display: flex; gap: 8px; padding: 14px 14px 8px; }
.chat-rail-list  { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 8px 12px; }
.thread-group   { padding: 4px 0; }
.thread-group-h {
  display: flex; align-items: center; gap: 6px;
  width: 100%; background: transparent; border: 0; cursor: pointer;
  font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-4); padding: 10px 8px 6px;
  text-align: left;
}
.thread-group-h:hover { color: var(--ink-2); }
.thread-group-chev {
  display: inline-flex; align-items: center; justify-content: center;
  width: 12px; height: 12px;
  color: var(--ink-4);
  transition: transform .12s ease;
}
.thread-group-chev.is-open { transform: rotate(90deg); }
.thread-group-count {
  margin-left: auto;
  font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  color: var(--ink-4); letter-spacing: 0;
}
.thread {
  display: block; width: 100%; text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 2px;
  transition: background .12s, border-color .12s;
  position: relative;
}
.thread:hover { background: var(--bg-sunk); }
.thread[data-active="true"] { background: var(--bg-sunk); border-color: var(--line-2); }
.thread-top { display: flex; align-items: center; gap: 6px; }
.thread-scope {
  flex: 0 0 16px;
  width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 5px;
  font-size: 9.5px; font-weight: 700; font-family: var(--font-mono);
  letter-spacing: 0; line-height: 1;
  color: var(--ink);
  background: var(--bg-sunk);
  border: 1px solid var(--line);
}
.thread-scope.is-workspace { background: var(--accent-wash); border-color: var(--accent-soft); color: var(--accent-deep); }
.thread-scope.is-project   { background: var(--bg-sunk); border-color: var(--line-2); color: var(--ink-2); }
/* Wątek trybu demo (dane przykładowe) — ten sam fiolet co przełącznik
   i ramka trybu demo w aplikacji. */
.thread-demo {
  flex: none; font-size: 9px; font-weight: 700; letter-spacing: .05em; line-height: 1;
  padding: 2px 5px; border-radius: 999px; color: #fff;
  background: linear-gradient(135deg, #7c3aed, #a855f7);
}
.thread-scope.is-user      { background: transparent; border-color: var(--line); color: var(--ink-3); }
.thread-title {
  font-size: 13.5px; font-weight: 500; color: var(--ink);
  letter-spacing: -.005em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;
}
.thread-pin { color: var(--accent-deep); display: inline-flex; }
.thread-meta {
  display: flex; align-items: center; gap: 6px; margin-top: 2px;
  font-size: 11.5px; color: var(--ink-4);
}
.thread-agent {
  color: var(--ink-3); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 130px;
}
.thread-dot  { opacity: .5; }
.thread-time { font-family: var(--font-mono); font-size: 11px; }
.thread-unread-dot {
  position: absolute;
  top: 8px; right: 8px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

/* --- main ------------------------------------------------------ */
.chat-main {
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0; position: relative;
  flex: 1;
}
.chat-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  flex: none;
}
.chat-thread-title {
  font-size: 13px; color: var(--ink-2, var(--ink-3));
  max-width: min(46vw, 520px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 3px 8px; border-radius: 6px; border: 1px solid transparent; cursor: text; outline: none;
}
.chat-thread-title:hover { border-color: var(--line); }
.chat-thread-title:focus { border-color: var(--accent, #b8860b); background: var(--surface, #fff); text-overflow: clip; }
.chat-thread-title:empty::before { content: attr(data-placeholder); color: var(--ink-4, var(--ink-3)); }
.agent-select { position: relative; }
.agent-glyph-sm {
  width: 18px; height: 18px; border-radius: 5px;
  background: var(--accent); color: var(--ink);
  display: grid; place-items: center;
  font-size: 10.5px; font-weight: 700;
}
.agent-pop {
  position: absolute;
  top: calc(100% + 6px); left: 0;
  width: 360px;
  background: var(--bg-elev);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  box-shadow: var(--sh-3);
  padding: 6px;
  z-index: 50;
}
[x-cloak] { display: none !important; }
.agent-pop-h {
  font-size: 10.5px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-4); padding: 8px 10px 6px;
}
.agent-row {
  display: flex; align-items: flex-start; gap: 10px;
  width: 100%; padding: 8px 10px;
  background: transparent; border: 1px solid transparent;
  border-radius: 10px; text-align: left;
  transition: background .12s;
}
.agent-row:hover { background: var(--bg-sunk); }
.agent-row[data-active="true"] { background: var(--accent-wash); border-color: var(--accent-soft); }
.agent-row-glyph {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--ink); color: var(--accent);
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
  flex: none;
}
.agent-row-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.agent-row-name { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink); }
.agent-row-desc { font-size: 12px; color: var(--ink-3); line-height: 1.4; }

/* --- welcome (premium hero) ------------------------------------ */
.chat-scroll  { flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: smooth; }
.welcome {
  max-width: 920px; margin: 0 auto;
  padding: 64px 32px 80px;
  display: flex; flex-direction: column; gap: 36px;
}
/* Hero: spark po lewej, greeting + lead obok */
.welcome-hero {
  display: flex; align-items: flex-start; gap: 18px;
}
.welcome-hero-body { flex: 1; min-width: 0; }
.welcome-spark {
  width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-soft) 60%, var(--accent-wash) 100%);
  display: grid; place-items: center;
  box-shadow: 0 12px 36px -10px rgba(0,0,0,.18), inset 0 -3px 0 rgba(0,0,0,.06);
  color: var(--ink);
  flex: none;
}
.welcome-h {
  font-size: 32px; font-weight: 600; letter-spacing: -.025em;
  color: var(--ink); margin: 0 0 8px; line-height: 1.15;
}
.welcome-sub {
  font-size: 15px; color: var(--ink-3); margin: 0;
  line-height: 1.55; max-width: 620px;
  letter-spacing: -.005em;
}
.welcome-section-title {
  font-size: 11px; font-weight: 600;
  color: var(--ink-4);
  margin: 0 0 14px 0;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.welcome-suggest-section { display: flex; flex-direction: column; }
.welcome-suggest { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.welcome-suggest-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (max-width: 720px) { .welcome-suggest-grid { grid-template-columns: 1fr; } }
.suggest {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-align: left;
  transition: background .12s, border-color .12s, transform .12s, box-shadow .15s;
  width: 100%;
  cursor: pointer;
}
.suggest:hover {
  background: var(--bg);
  border-color: var(--line-2);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px -10px rgba(0,0,0,.18);
}
.suggest-i {
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-soft) 100%);
  color: var(--ink);
  display: grid; place-items: center;
  border: 1px solid var(--accent-soft);
  flex: none;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.05);
}
.suggest-t { flex: 1; font-size: 13.5px; color: var(--ink-1); line-height: 1.45; letter-spacing: -.005em; font-weight: 500; }
.suggest-arrow { color: var(--ink-4); flex: none; }
.suggest:hover .suggest-arrow { color: var(--ink); transform: translateX(2px); transition: transform .12s, color .12s; }

/* --- messages -------------------------------------------------- */
.chat-stream {
  max-width: none; margin: 0;
  padding: 28px 32px 40px;
  display: flex; flex-direction: column; gap: 22px;
  align-items: flex-start;
}
.chat-stream:empty { display: none; }
.msg { display: flex; gap: 12px; }
.msg-user {
  align-self: flex-end;
  max-width: 85%;
}
.msg-bubble-user {
  background: var(--accent); color: var(--ink);
  padding: 8px 12px 4px;
  border-radius: 16px 16px 4px 16px;
  font-size: 14px;
  letter-spacing: -.005em;
  white-space: pre-wrap;
  border: 1px solid var(--accent-deep);
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.05);
  font-weight: 500;
  display: flex; flex-direction: column; align-items: flex-end;
}
/* Globalny ::selection (base.css) maluje zaznaczenie żółtym akcentem —
 * a user-bubble już ma żółte tło, więc selection znikał. Invertujemy:
 * ciemne tło + jasny tekst, czytelne na każdym akcencie. */
.msg-bubble-user ::selection,
.msg-bubble-user::selection { background: var(--ink); color: var(--accent); }
.msg-bubble-user ::-moz-selection,
.msg-bubble-user::-moz-selection { background: var(--ink); color: var(--accent); }
.msg-bubble-user .msg-bubble-body { align-self: stretch; }
.msg-bubble-user p { margin: 0 0 4px; }
.msg-bubble-user p:last-child { margin: 0; }
/* Quill leaves a trailing <p><br></p> after Enter — hide it so the user
 * meta line (name · time) sits flush with the last real line of text. */
.msg-bubble-user .msg-bubble-body > p:last-child:has(> br:only-child),
.msg-bubble-user .msg-bubble-body > p:last-child:empty {
  display: none;
}
.msg-user .msg-meta {
  font-size: 10.5px; color: rgba(0,0,0,.65);
  font-family: var(--font-mono);
  margin-top: 1px;
  line-height: 1;
}

/* Dark mode: --ink jest jasny (#F4F1E8), --accent zostaje jasny żółty
 * (#F5C518) → tekst na user-bubble był prawie nieczytelny. Wymuszamy
 * ciemny tekst niezależnie od motywu — accent jest jasny w obu, więc
 * dark text wygrywa kontrastowo. Meta line analogicznie bumpniemy
 * opacity żeby imię + timestamp też dobrze siedziały. */
[data-theme="dark"] .msg-bubble-user {
  color: #14130F;
}
[data-theme="dark"] .msg-user .msg-meta {
  color: rgba(0,0,0,.7);
}
/* Timestamp w bubble agenta w dark — --ink-4 (#7E7969) ma marginalny
 * kontrast na --bg-elev (#161513). Bumpujemy do --ink-3 (#ADA89A). */
[data-theme="dark"] .msg-time {
  color: var(--ink-3);
}

/* System routing events (np. zmiana agenta) — wyśrodkowany, przygaszony
 * wiersz, bez avatara/dymka, żeby nie mylić się z treścią od usera/agenta. */
.msg-system {
  align-self: center;
  justify-content: center;
}
.msg-system-pill {
  font-size: 11.5px;
  color: var(--ink-3);
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 12px;
  font-family: var(--font-mono);
  white-space: nowrap;
}

/* Kontekst ekranu dołączony do pytania (strona, klocki, wiersze) — chipy
 * pod treścią dymka usera zamiast technicznego bloku z treści wiadomości. */
.msg-ctx {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}
.msg-ctx-chip {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  line-height: 18px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--ink-2);
}
.msg-ctx-chip--page {
  background: var(--bg-sunk);
}

.msg-agent {
  align-self: flex-start;
  max-width: 85%;
  align-items: flex-start;
  padding: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 4px 16px 16px 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,.03);
  overflow: hidden;
}
.msg-avatar { flex: none; }
.msg-avatar-glyph {
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-soft) 60%, var(--accent-wash) 100%);
  color: var(--ink);
  display: grid; place-items: center;
  border: 1px solid var(--accent-deep);
  box-shadow: 0 2px 6px -2px rgba(0,0,0,.15);
  font-weight: 700; font-size: 13px; font-family: var(--font-mono);
  letter-spacing: 0; line-height: 1;
}
.msg-avatar-glyph.is-workspace {
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-soft) 60%, var(--accent-wash) 100%);
  border-color: var(--accent-deep);
  color: var(--ink);
}
.msg-avatar-glyph.is-project {
  background: var(--bg-sunk);
  border-color: var(--line-2);
  color: var(--ink-2);
}
.msg-avatar-glyph.is-user {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--accent);
}
.msg-body, .msg-bubble-wrap { flex: 1; min-width: 0; }
.msg-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--ink-2);
  margin-bottom: 4px;
}
.msg-head b { font-weight: 600; color: var(--ink); }
.msg-time { font-family: var(--font-mono); font-size: 11px; color: var(--ink-4); margin-left: auto; }
/* Markdown bubble typography — applies to both the agent body
   (.msg-body) and the user bubble (.msg-bubble) so user-side rich text
   is styled identically. The :is() grouping keeps the selectors short
   and avoids the "wrong split" trap from a naive find-replace. */
:is(.msg-body, .msg-bubble) { font-size: 14px; line-height: 1.55; color: var(--ink-2); letter-spacing: -.003em; }
:is(.msg-body, .msg-bubble) p { margin: 0 0 10px; }
:is(.msg-body, .msg-bubble) p:last-child { margin: 0; }
:is(.msg-body, .msg-bubble) ul,
:is(.msg-body, .msg-bubble) ol { margin: 0 0 10px; padding-left: 20px; }
:is(.msg-body, .msg-bubble) li { margin-bottom: 4px; }
:is(.msg-body, .msg-bubble) code {
  font-family: var(--font-mono); font-size: 12px;
  background: var(--bg-sunk);
  padding: 1px 5px; border-radius: 4px;
  overflow-wrap: anywhere;
  word-break: break-word;
}
:is(.msg-body, .msg-bubble) b,
:is(.msg-body, .msg-bubble) strong { color: var(--ink); font-weight: 600; }
:is(.msg-body, .msg-bubble) em,
:is(.msg-body, .msg-bubble) i { font-style: italic; }
:is(.msg-body, .msg-bubble) h1,
:is(.msg-body, .msg-bubble) h2,
:is(.msg-body, .msg-bubble) h3 {
  color: var(--ink); font-weight: 700;
  margin: 12px 0 6px; line-height: 1.2;
}
:is(.msg-body, .msg-bubble) h1 { font-size: 1.35em; }
:is(.msg-body, .msg-bubble) h2 { font-size: 1.2em; }
:is(.msg-body, .msg-bubble) h3 { font-size: 1.05em; }
:is(.msg-body, .msg-bubble) blockquote {
  border-left: 3px solid var(--line-2); padding-left: 10px;
  margin: 6px 0; color: var(--ink-3);
}
:is(.msg-body, .msg-bubble) pre {
  background: var(--bg-sunk); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px;
  font-size: 12.5px; line-height: 1.4;
  font-family: var(--font-mono);
  margin: 6px 0;
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}
:is(.msg-body, .msg-bubble) pre code { background: transparent; padding: 0; border-radius: 0; }
:is(.msg-body, .msg-bubble) a {
  color: var(--accent-deep); text-decoration: underline;
  word-break: break-word;
}
:is(.msg-body, .msg-bubble) hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
:is(.msg-body, .msg-bubble) table {
  border-collapse: collapse; font-size: 13px; margin: 8px 0;
}
:is(.msg-body, .msg-bubble) th,
:is(.msg-body, .msg-bubble) td {
  border: 1px solid var(--line); padding: 4px 8px; text-align: left;
}
.msg-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }

/* Inline artefakt w bańce agenta — render area pod BodyHTML, ładowana
   przez HTMX hx-get on load. Wizualnie: lekki kontener z border, żeby
   artefakt nie zlewał się z tekstem wiadomości. Loading state to to
   samo "thinking" animation co w ThinkingBubble. */
.msg-inline-artifact {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-sunk);
}
.msg-inline-artifact-loading {
  display: flex; align-items: center; justify-content: center;
  min-height: 32px; color: var(--ink-4);
}

.msg-attachments {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 8px;
}
.msg-attach {
  display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none;
  border-radius: 8px;
  transition: transform .12s, box-shadow .12s;
}
.msg-attach-img {
  display: block;
  border: 1px solid var(--line);
  overflow: hidden;
  max-width: 220px; max-height: 220px;
}
.msg-attach-img img { display: block; max-width: 220px; max-height: 220px; object-fit: cover; }
.msg-attach-img:hover { transform: scale(1.02); box-shadow: var(--sh-2); }
.msg-attach-file {
  padding: 6px 10px;
  background: var(--bg-sunk); border: 1px solid var(--line);
  font-size: 12.5px; color: var(--ink-2);
}
.msg-attach-file:hover { background: var(--bg); border-color: var(--ink-4); color: var(--ink); }
.msg-attach-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-attach-size { color: var(--ink-4); font-size: 11.5px; margin-left: 4px; }

/* KB viewer modal — opened by clicking a knowledge mention chip. */
.kb-viewer-body { max-height: 60vh; overflow-y: auto; padding: 14px 20px 18px; font-size: 14px; line-height: 1.55; color: var(--ink-2); }
.kb-viewer-body p { margin: 0 0 10px; }
.kb-viewer-body h1, .kb-viewer-body h2, .kb-viewer-body h3 { color: var(--ink); margin: 14px 0 6px; }
.kb-viewer-body h1 { font-size: 1.35em; } .kb-viewer-body h2 { font-size: 1.18em; } .kb-viewer-body h3 { font-size: 1.05em; }
.kb-viewer-body ul, .kb-viewer-body ol { margin: 0 0 10px; padding-left: 20px; }
.kb-viewer-body code { font-family: var(--font-mono); background: var(--bg-sunk); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.kb-viewer-body pre { background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 6px; padding: 10px; overflow-x: auto; }
.kb-viewer-body blockquote { border-left: 3px solid var(--line-2); padding-left: 10px; color: var(--ink-3); margin: 6px 0; }
.kb-viewer-body a { color: var(--accent-deep); text-decoration: underline; }
.kb-viewer-pre { white-space: pre-wrap; word-break: break-word; }
.kb-viewer-err { color: var(--bad); font-style: italic; }

/* User card popover — opened by clicking a @user mention chip. */
.user-card-backdrop {
  position: fixed; inset: 0; z-index: 220;
  background: rgba(20, 19, 15, .25);
  display: grid; place-items: center;
}
.user-card {
  position: relative;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.18);
  width: 320px; padding: 18px 18px 14px;
}
.user-card-close {
  position: absolute; top: 8px; right: 8px;
  width: 26px; height: 26px;
  border: 0; background: transparent;
  color: var(--ink-4); border-radius: 6px;
  display: grid; place-items: center; cursor: pointer;
}
.user-card-close:hover { background: var(--bg-sunk); color: var(--ink-2); }
.user-card-head { display: flex; gap: 12px; align-items: center; }
.user-card-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--accent-deep); color: var(--bg);
  display: grid; place-items: center;
  font-weight: 600; font-size: 18px;
  flex: 0 0 48px;
}
.user-card-meta { min-width: 0; flex: 1; }
.user-card-name { font-weight: 600; font-size: 15px; color: var(--ink); margin-bottom: 2px; word-break: break-word; }
.user-card-email { font-size: 12.5px; color: var(--accent-deep); text-decoration: none; word-break: break-all; }
.user-card-email:hover { text-decoration: underline; }
.user-card-warn { margin: 12px 0 0; font-size: 12px; color: var(--warn, #8a5a00); }

/* Saved-filter preview modal */
.filter-preview-q { padding: 12px 18px 0; }
.filter-preview-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-4); margin-bottom: 6px; }
.filter-preview-query {
  display: block; padding: 10px 12px;
  background: var(--bg-sunk); border: 1px solid var(--line); border-radius: 6px;
  font-family: var(--font-mono); font-size: 12.5px; color: var(--ink);
  white-space: pre-wrap; word-break: break-word;
}
.filter-preview-hint { padding: 8px 18px 12px; font-size: 12px; color: var(--ink-3); margin: 0; }
.filter-preview-warn { padding: 8px 18px 12px; font-size: 13px; color: var(--warn, #8a5a00); margin: 0; }

.thinking {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--ink-4);
}
.thinking i {
  width: 4px; height: 4px; border-radius: 50%; background: var(--ink-4);
  display: inline-block;
  animation: dot 1.1s infinite ease-in-out;
}
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes dot {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

/* --- composer -------------------------------------------------- */
.composer {
  flex: none;
  padding: 12px 32px 18px;
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.composer-inner {
  max-width: none; margin: 0;
  background: var(--bg-elev);
  border: 1px solid var(--line-2);
  border-radius: 16px;
  padding: 10px 12px 8px;
  transition: border-color .15s, box-shadow .15s;
  box-shadow: var(--sh-2);
  position: relative;
}
.composer-inner:focus-within {
  border-color: var(--ink-3);
  box-shadow: 0 0 0 4px var(--accent-wash), var(--sh-2);
}
.composer textarea {
  width: 100%;
  min-height: 48px;
  max-height: 220px;
  border: 0;
  background: transparent;
  outline: none;
  resize: none;
  font-family: var(--font-sans);
  font-size: 14.5px;
  letter-spacing: -.005em;
  color: var(--ink);
  padding: 4px 4px 4px;
}
.composer textarea::placeholder { color: var(--ink-4); }

/* Rich-text editor — Quill bubble theme: no permanent toolbar, only a
   floating popover on selection. The composer-editor-wrap reserves
   space; the editor itself is borderless and inherits typography. */
.composer-editor-wrap {
  display: flex; flex-direction: column;
  min-height: 84px; max-height: 280px;
  position: relative; /* anchor for the absolutely-positioned bubble */
}
.composer-editor-wrap .ql-container.ql-bubble {
  border: 0; font-family: var(--font-sans);
  font-size: 14.5px; letter-spacing: -.005em;
  color: var(--ink); min-height: 84px;
  /* overflow stays visible so the bubble tooltip can flow above the
     selection without being clipped; the editor itself caps height. */
  overflow: visible;
  position: relative;
}
.composer-editor-wrap .ql-editor {
  padding: 2px 4px; min-height: 84px;
  max-height: 220px; overflow-y: auto;
}
.composer-editor-wrap .ql-editor.ql-blank::before {
  color: var(--ink-4); font-style: normal; left: 4px; right: 4px;
}
/* Fallback placeholder — visible even if Quill's init never marks the
   editor with .ql-blank (corner case on chat thread pages). Uses the
   data-placeholder attribute the host put on #composer-editor, with a
   generic prompt as last-ditch fallback so the field never looks dead. */
.composer-editor-wrap .ql-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-4);
  font-style: normal;
  pointer-events: none;
  position: absolute;
  left: 4px; right: 4px;
}
.composer-editor-wrap .composer-editor[data-placeholder]:not(.ql-container):empty::before {
  content: attr(data-placeholder);
  display: block; padding: 2px 4px;
  color: var(--ink-4);
  pointer-events: none;
}
.composer-editor-wrap .ql-editor h1 { font-size: 1.4em; font-weight: 700; margin: 0; }
.composer-editor-wrap .ql-editor h2 { font-size: 1.2em; font-weight: 700; margin: 0; }
.composer-editor-wrap .ql-editor h3 { font-size: 1.05em; font-weight: 700; margin: 0; }
.composer-editor-wrap .ql-editor blockquote {
  border-left: 3px solid var(--line-2); padding-left: 8px;
  color: var(--ink-3); margin: 4px 0;
}
.composer-editor-wrap .ql-editor pre.ql-syntax,
.composer-editor-wrap .ql-editor pre {
  background: var(--bg-sunk); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.composer-editor-wrap .ql-editor a {
  color: var(--accent-deep); text-decoration: underline;
}
/* Bubble toolbar — float over selection, blend with the DS chrome.
   Hidden by default so the dark bar never flashes on init or when
   Quill hasn't positioned it yet. Quill removes ql-hidden when the
   user selects text — that's when we animate it in. */
.ql-bubble .ql-tooltip {
  background: var(--ink); color: var(--bg);
  border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.18);
  z-index: 1000;
  transition: opacity .12s ease-out;
  display: none !important;
}
.ql-bubble .ql-tooltip:not(.ql-hidden) {
  display: block !important;
  animation: ql-bubble-in .14s ease-out;
}
@keyframes ql-bubble-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ql-bubble .ql-tooltip.ql-hidden { display: none !important; }
.ql-bubble .ql-tooltip-arrow { border-bottom-color: var(--ink); }
.ql-bubble.ql-toolbar button,
.ql-bubble .ql-toolbar button { color: var(--bg); }
.ql-bubble .ql-stroke { stroke: var(--bg); }
.ql-bubble .ql-fill   { fill: var(--bg); }
.ql-bubble .ql-active .ql-stroke,
.ql-bubble button:hover .ql-stroke { stroke: var(--accent-light); }
.ql-bubble .ql-active .ql-fill,
.ql-bubble button:hover .ql-fill { fill: var(--accent-light); }
.ql-bubble .ql-picker-label { color: var(--bg); }
.ql-bubble .ql-picker-options { background: var(--ink); color: var(--bg); }

/* Attachment chips — appear above the editor when files are queued.
   Hidden when empty (JS toggles display) so the composer doesn't
   reserve dead space. */
.composer-attach-strip {
  display: none; flex-wrap: wrap; gap: 6px;
  padding: 4px 0 8px;
}
.composer-attach-strip:not(:empty) { display: flex; }
.composer-attach-chip {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 24px 4px 6px;
  background: var(--bg-sunk); border: 1px solid var(--line);
  border-radius: 8px; font-size: 12px;
  cursor: grab;
}
.composer-attach-chip:active { cursor: grabbing; }
.composer-attach-chip-ghost {
  opacity: .4; background: var(--accent-wash);
  border-color: var(--accent-deep);
}
.composer-attach-chip img {
  width: 32px; height: 32px; object-fit: cover; border-radius: 4px;
}
.composer-attach-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-attach-chip.is-uploading { opacity: .6; }
.composer-attach-x {
  position: absolute; right: 4px; top: 4px;
  width: 16px; height: 16px; padding: 0;
  border: 0; background: transparent; cursor: pointer;
  color: var(--ink-3); font-size: 14px; line-height: 1;
}
.composer-attach-x:hover { color: var(--bad); }
.composer-attach-spin {
  position: absolute; right: 22px; top: 50%;
  width: 10px; height: 10px; margin-top: -5px;
  border: 1.5px solid var(--ink-4); border-top-color: transparent;
  border-radius: 50%; animation: composer-spin .7s linear infinite;
}
@keyframes composer-spin { to { transform: rotate(360deg); } }

/* Mention popover — quill-mention default look adapted to the DS. */
.ql-mention-list-container {
  z-index: 100;
  background: var(--bg-elev) !important; border: 1px solid var(--line) !important;
  border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.10);
  /* max-width 420 → 540: emptystate hint ("Zapisz filtr na liście") obok
     długiej nazwy ("Brak zapisanych filtrów połączeń") nie mieścił się na
     420px — text-overflow: ellipsis ucinał końcówkę hintu
     (#01KVD6GQJW2ADBVZBBQ — Anna, retest 2026-06-19). 540px mieści typowe
     pary nazwa+hint bez ucięcia. */
  min-width: 320px !important; max-width: 540px !important;
  max-height: 280px; overflow-y: auto;
  /* Override vendor's hardcoded width: 270px */
  width: auto !important;
}
.ql-mention-list { padding: 4px; }
.ql-mention-list-item {
  padding: 6px 10px; border-radius: 6px; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 1.4;
  height: auto;
}
.ql-mention-list-item > span {
  display: inline-flex; align-items: center; gap: 6px;
  min-width: 0; flex: 1;
}
.ql-mention-list-item.selected, .ql-mention-list-item:hover {
  background: var(--bg-sunk); cursor: pointer;
}
.ql-mention-list-item:has(.cm-disabled),
.cm-disabled {
  color: var(--ink-4);
  font-style: italic;
}
.cm-kind {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  color: var(--ink-4);
  flex-shrink: 0;
}
.cm-kind svg { display: block; }
.cm-sub { color: var(--ink-4); font-size: 11.5px; margin-left: 4px; }
.cm-hint {
  margin-left: auto; padding: 1px 6px;
  background: var(--bg-sunk); border: 1px solid var(--line);
  border-radius: 4px; font-family: var(--font-mono);
  font-size: 11px; color: var(--ink-4);
  white-space: nowrap;
}
/* Mention chip — same look in the composer and in rendered bubbles.
   The vendor quill-mention CSS hardcodes width/height/padding-y which
   forces the chip to break onto its own line; override all of those so
   the chip flows inline like normal text. */
.mention {
  display: inline !important;
  width: auto !important;
  height: auto !important;
  background: var(--accent-wash) !important;
  color: var(--accent-deep) !important;
  padding: 0 5px !important;
  margin: 0 1px !important;
  border-radius: 4px !important;
  font-weight: 500;
  line-height: inherit;
}
.mention > span { margin: 0 !important; }
/* In rendered bubbles the chip routes to an object drawer/page; make
   the affordance obvious. Composer chips stay neutral since they're
   intrinsic to the textarea. */
.msg-bubble .mention[data-mention-kind],
.msg-body   .mention[data-mention-kind] { cursor: pointer; }
.msg-bubble .mention[data-mention-kind]:hover,
.msg-body   .mention[data-mention-kind]:hover { filter: brightness(.95); }
.mention-knowledge { background: var(--bg-sunk) !important; color: var(--ink-2) !important; }
.mention-task       { background: var(--info-wash, #e7f0ff) !important; color: var(--info, #1c5fb8) !important; }
.mention-workflow   { background: var(--warn-wash, #fff4dc) !important; color: var(--warn, #8a5a00) !important; }
.mention-connection { background: var(--good-wash, #e2f6e9) !important; color: var(--good, #1a7a3f) !important; }
.mention-filter     { background: var(--y-wash, #fff8d6) !important; color: var(--ink, #14130f) !important; border: 1px dashed var(--ink-3, #69695c) !important; }

/* Help drawer styles → help.css (baseline; wydzielone 2026-07-03). */


.kbd {
  background: var(--bg-sunk); border: 1px solid var(--line);
  padding: 1px 6px; border-radius: 4px;
  font-family: var(--font-mono); font-size: 11.5px;
  color: var(--ink);
}

.composer-help-btn.composer-help-btn {
  position: absolute;
  top: 6px; right: 6px;
  width: 26px; height: 26px;
  min-width: 0;
  padding: 0;
  color: var(--ink-4);
  display: inline-flex; align-items: center; justify-content: center;
}
.composer-help-btn:hover { color: var(--accent-deep); }
.composer-trigger-btn.composer-trigger-btn {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-3);
  min-width: 26px; height: 26px;
  padding: 0 6px;
}
.composer-trigger-btn:hover { color: var(--accent-deep); background: var(--bg-sunk); }
/* Snappy CSS tooltip: shows on hover *before* the native title=. */
.composer-trigger-btn[title]:hover::after,
.composer-attach-btn[title]:hover::after,
.composer-help-btn[title]:hover::after {
  content: attr(title);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: var(--ink);
  color: var(--bg);
  font-size: 11.5px;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 50;
  box-shadow: var(--sh-2);
}
.composer-trigger-btn,
.composer-attach-btn { position: relative; }
.composer-tools {
  display: flex; align-items: center;
  margin-top: 4px; gap: 4px;
}
.composer-left  { display: flex; align-items: center; gap: 2px; flex: 1; }
.composer-right { display: flex; align-items: center; gap: 8px; }
.btn-send {
  width: 32px; height: 32px;
  border-radius: 999px;
  border: 0;
  background: var(--ink); color: var(--bg);
  display: grid; place-items: center;
  transition: background .12s, transform .06s, opacity .12s;
  cursor: pointer;
}
.btn-send:hover  { background: var(--ink-2); }
.btn-send:active { transform: scale(.96); }
.btn-send:disabled { opacity: .3; cursor: not-allowed; background: var(--ink-5); }
.composer-foot {
  max-width: 780px; margin: 8px auto 0;
  font-size: 11.5px; color: var(--ink-4);
  text-align: center;
}

/* The chat takes the entire view area — no view-header is rendered. */
.app .view:has(.chat) { padding: 0; }

/* Mobile hamburger toggle dla rail — chowamy na desktop, pokazujemy
   ≤960px w chat-toolbar. Klik toggluje body.chat-rail-open class. */
.chat-rail-mobile-toggle { display: none; }
/* X close button w rail head — visible tylko mobile (na desktop rail
   jest zawsze widoczny, X by myślił). */
.chat-rail-close-mobile { display: none; }

@media (max-width: 960px) {
  .chat { grid-template-columns: 1fr; }
  /* Rail jako fixed overlay slide-in z lewej (zamiast display:none —
     bez tego user nie ma dostępu do listy wątków ani "Nowy wątek"
     buttona). Toggle przez body.chat-rail-open class z hamburger
     buttona w chat-toolbar. Backdrop ciemniejący ::before. */
  .chat-rail {
    display: flex;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 86%; max-width: 360px;
    background: var(--bg-elev, #fff);
    border-right: 1px solid var(--line);
    /* Ponad globalnym kontem (85), żeby przycisk zamknięcia był klikalny. */
    z-index: 90;
    transform: translateX(-100%);
    transition: transform .22s cubic-bezier(.2,.8,.2,1);
    box-shadow: 4px 0 16px rgba(0,0,0,.12);
  }
  body.chat-rail-open .chat-rail { transform: translateX(0); }
  /* Backdrop jako prawdziwy element (div.chat-rail-backdrop) — pseudo
     ::before na body niezawodnie nie łapało click/touch event na iOS
     Safari (pointer-events ignored when not rendered as part of DOM).
     Div z onclick='document.body.classList.remove' działa wszędzie. */
  .chat-rail-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 89;
    cursor: pointer;
  }
  body.chat-rail-open .chat-rail-backdrop {
    display: block;
    animation: chat-rail-bd-in .18s ease-out;
  }
  .chat-rail-mobile-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    margin-right: 4px;
    z-index: 71;
    position: relative;
  }
  .chat-rail-close-mobile { display: inline-flex; }
  /* Na mobile collapse button (PanelLeft) nie ma sensu — rail i tak
     jest overlay z toggle z chat-toolbar. */
  .chat-rail-collapse { display: none; }
  @keyframes chat-rail-bd-in { from { opacity: 0 } to { opacity: 1 } }

  /* Composer — trim outer padding so we keep real estate for typing.
     The inner card stays rounded but loses the 32px side gutters. */
  .composer { padding: 8px 10px 12px; }
  .composer-inner { padding: 8px 10px 6px; border-radius: 12px; }
  .composer-editor-wrap { min-height: 64px; max-height: 200px; }
  .composer-editor-wrap .ql-container.ql-bubble,
  .composer-editor-wrap .ql-editor { min-height: 64px; }
  .composer-editor-wrap .ql-editor { max-height: 160px; }

  /* Attach strip wraps onto multiple rows instead of cropping. */
  .composer-attach-strip { flex-wrap: wrap; }
  .composer-attach-name { max-width: 100px; }

  /* Mention / slash picker — full bleed minus a 12px viewport margin.
     The fixed positioning still anchors to the caret, but the width
     cap keeps it from punching off-screen on narrow phones. */
  .ql-mention-list-container {
    min-width: 0 !important;
    max-width: calc(100vw - 24px) !important;
    width: calc(100vw - 24px) !important;
    left: 12px !important;
  }

  /* Welcome screen — drop the giant top padding so the prompt sits in view.
     Also scale the headline down: 30px in a 358px column breaks the second
     line awkwardly and the trailing "?" can vanish off-screen on very
     narrow phones. */
  .welcome { padding: 24px 16px 40px; }
  .welcome-h { font-size: 22px; line-height: 1.2; }
  .welcome-sub { font-size: 14px; margin-bottom: 18px; }
  .welcome-spark { width: 44px; height: 44px; border-radius: 12px; }
}

/* === chat artifact panel ====================================== */
/* Split layout: artifact panel (60%, left) + chat conversation (40%, right).
 * Active only when ChatMainVM.ArtifactPanel != nil (root gets
 * .has-artifacts). Legacy chat without artefacts uses the original
 * single-column flex layout above. */

/* .chat-main-conv jest wewnętrznym wrapperem konwersacji (toolbar +
 * scroll + composer + foot). Wprowadzony w fazie 0 żeby umożliwić
 * split layout has-artifacts. W trybie legacy single-column musi
 * dziedziczyć flex: 1 od chat-main + sam być flex column, inaczej
 * composer zwija się do góry (chat-scroll z flex: 1 mierzy się przeciwko
 * temu wrapperowi, nie chat-main bezpośrednio). */
.chat-main-conv {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.chat-main.has-artifacts {
  display: grid;
  grid-template-columns: 3fr 2fr;
  grid-template-rows: 100%;
  min-height: 0;
}
.chat-main.has-artifacts .chat-main-conv {
  border-left: 1px solid var(--line);
}

/* Artifact panel — left side */
.chat-artifact-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
}
.chat-artifact-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: thin;
  background: var(--bg-elev);
}
.chat-artifact-tabs::-webkit-scrollbar { height: 6px; }
.chat-artifact-tab {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  background: transparent;
  transition: background .12s ease;
}
.chat-artifact-tab:hover { background: var(--bg-sunk); }
.chat-artifact-tab[data-active="true"] {
  background: var(--accent-wash);
  outline: 1px solid var(--accent-soft);
}
.chat-artifact-tab-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: 0;
  cursor: pointer;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-artifact-tab-label > span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-artifact-kind {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-3);
  flex-shrink: 0;
}
.chat-artifact-tab[data-active="true"] .chat-artifact-kind { color: var(--accent-deep); }
.chat-artifact-tab-close {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 4px;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--r-xs);
}
.chat-artifact-tab-close:hover {
  background: var(--bg-elev);
  color: var(--ink);
}
/* Save-to-workspace button — bookmark icon. Task #13 follow-up. */
.chat-artifact-tab-save {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: transparent;
  color: var(--ink-3); cursor: pointer;
  border-radius: var(--r-xs);
  transition: background .12s, color .12s;
}
.chat-artifact-tab-save:hover {
  background: var(--bg-elev);
  color: var(--ink);
}
.chat-artifact-tab-save[data-saved="1"] {
  background: var(--good-soft);
  color: var(--good-deep);
}

.chat-artifact-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg);
}

/* Empty state — shown when no tab is open. */
.chat-artifact-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  height: 100%;
  min-height: 200px;
  color: var(--ink-3);
  padding: 32px 24px;
  gap: 12px;
}
.chat-artifact-empty-glyph {
  width: 64px;
  height: 64px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--ink-4);
}
.chat-artifact-empty-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-2);
}
.chat-artifact-empty-sub {
  font-size: 13px;
  line-height: 1.5;
  max-width: 320px;
  margin: 0;
}

/* Mobile toggle — desktop hides it (panel always visible in split).
 * Mobile shows it in the toolbar with a badge for active tab count. */
.chat-artifact-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 4px;
  position: relative;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line-2);
  background: var(--bg-elev);
  color: var(--ink-2);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.chat-artifact-toggle:hover { background: var(--bg-sunk); }
.chat-artifact-toggle-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--bg);
}

/* Mobile: collapse split to chat-only, artifact panel slides in
 * full-screen when toggle button flips .is-open class. */
@media (max-width: 960px) {
  .chat-main.has-artifacts {
    grid-template-columns: 1fr;
  }
  .chat-main.has-artifacts .chat-artifact-panel {
    display: none;
  }
  .chat-main.has-artifacts .chat-artifact-panel.is-open {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: var(--bg);
  }
  .chat-main.has-artifacts .chat-main-conv {
    border-left: 0;
  }
  .chat-artifact-toggle {
    display: inline-flex;
  }
}

/* Wizard organism — krokowy formularz generowany przez agenta. Slot
   wewnątrz artifact panelu lub bańki agent message; server-side step
   transition (HTMX outerHTML swap całego .wizard na każdy klik). */
.wizard {
  display: flex; flex-direction: column;
  gap: 14px;
}
.wizard-header { display: flex; flex-direction: column; gap: 8px; }
.wizard-header h3 { margin: 0; font-size: 15px; color: var(--ink); }
.wizard-description { margin: 0; color: var(--ink-3); font-size: 13px; }
.wizard-progress {
  display: flex; flex-direction: row; align-items: center;
  gap: 6px; margin: 0; padding: 0; list-style: none;
  font-size: 12px; color: var(--ink-3);
}
.wizard-progress-step { display: inline-flex; align-items: center; gap: 6px; }
.wizard-progress-step + .wizard-progress-step::before {
  content: ""; width: 12px; height: 1px; background: var(--line);
  margin: 0 2px;
}
.wizard-progress-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 999px;
  background: var(--bg-sunk); border: 1px solid var(--line);
  font-size: 11px; color: var(--ink-4);
}
.wizard-progress-step-active .wizard-progress-dot {
  border-color: var(--accent); color: var(--accent-deep);
  background: var(--accent-wash);
}
.wizard-progress-step-done .wizard-progress-dot {
  background: var(--accent); color: white; border-color: var(--accent);
}
.wizard-progress-label { color: var(--ink-3); }
.wizard-progress-step-active .wizard-progress-label { color: var(--ink); font-weight: 500; }

.wizard-form { display: flex; flex-direction: column; gap: 12px; }
.wizard-step-title { margin: 0; font-size: 13.5px; color: var(--ink-2); }
.wizard-fields { display: flex; flex-direction: column; gap: 10px; }
.wizard-field { display: flex; flex-direction: column; gap: 4px; }
.wizard-field-label { font-size: 12.5px; color: var(--ink-2); }
.wizard-field-required { color: var(--accent-deep); margin-left: 2px; }
.wizard-field-help { color: var(--ink-4); font-size: 11.5px; }
.wizard-error {
  padding: 8px 10px; border-radius: 8px;
  background: var(--bad-soft); color: var(--bad-deep);
  border: 1px solid var(--bad); font-size: 12.5px;
}

.wizard-footer { display: flex; gap: 8px; align-items: center; }

.wizard-completed {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-sunk);
}
.wizard-completed-ok-banner { border-color: var(--good); background: var(--good-soft); }
.wizard-completed-error-banner { border-color: var(--bad); background: var(--bad-soft); }
.wizard-completed-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
  font-size: 13px;
}
.wizard-completed-head strong { color: var(--ink); }
.wizard-completed-time { color: var(--ink-4); font-size: 11.5px; }
.wizard-completed-result, .wizard-completed-error {
  margin: 0; color: var(--ink-2); font-size: 12.5px; line-height: 1.5;
}
.wizard-completed-error { color: var(--bad-deep); }

/* Chat task widget — sekcja w welcome'ie /chat z taskami z filtra
   per-projekt (ustawianego w /settings/ai). Czysty grid 3 karty +
   subtelna lista poniżej. Bez akcji administracyjnych. */
.chat-task-widget {
  display: flex; flex-direction: column; gap: 14px;
}
.chat-task-widget-title {
  font-size: 11px; font-weight: 600;
  color: var(--ink-4);
  margin: 0;
  letter-spacing: .08em;
  text-transform: uppercase;
}
/* Cards — top 3 jako breath-y tiles z subtelnym priorytetowym akcentem. */
.chat-task-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (max-width: 960px) { .chat-task-cards { grid-template-columns: 1fr; } }
.chat-task-card {
  position: relative;
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px 16px 14px 20px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-decoration: none; color: inherit;
  cursor: pointer;
  transition: border-color .15s, transform .12s, box-shadow .15s;
  overflow: hidden;
  min-height: 110px;
  font: inherit; text-align: left;
}
.chat-task-card[data-loading="1"] { opacity: .55; cursor: progress; }
.chat-task-card:hover {
  border-color: var(--line-2);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px -10px rgba(0,0,0,.18);
}
.chat-task-card-bar {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--line-2);
}
.chat-task-card-bar[data-priority="very_high"],
.chat-task-card-bar[data-priority="urgent"] { background: var(--bad); }
.chat-task-card-bar[data-priority="high"] { background: var(--warn); }
.chat-task-card-bar[data-priority="medium"] { background: var(--accent-deep); }
.chat-task-card-title {
  font-size: 14px; color: var(--ink-1); font-weight: 500;
  line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.chat-task-card-meta {
  display: flex; align-items: center; gap: 10px;
  font-size: 11.5px; color: var(--ink-3);
  margin-top: auto;
}
.chat-task-card-prio {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 500;
  background: var(--bg-sunk); color: var(--ink-2);
}
.chat-task-card-prio[data-priority="very_high"],
.chat-task-card-prio[data-priority="urgent"] { background: var(--bad-soft); color: var(--bad-deep); }
.chat-task-card-prio[data-priority="high"] { background: var(--warn-soft); color: var(--warn-deep); }
.chat-task-card-prio[data-priority="medium"] { background: var(--accent-soft); color: var(--accent-deep); }
.chat-task-card-due {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--ink-4);
}
.chat-task-card-due > svg { color: var(--ink-4); }
/* Rows — kompaktowa lista pod kartami: dot kolorem (priorytet) +
   tytuł + ewentualny due. Bez ID, bez tekstu priorytetu. */
.chat-task-rows {
  list-style: none; padding: 0; margin: 4px 0 0 0;
  display: flex; flex-direction: column;
  border-top: 1px solid var(--line);
}
.chat-task-rows > li { border-bottom: 1px solid var(--line); }
.chat-task-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px;
  font-size: 13px; color: var(--ink-2);
  text-decoration: none;
  transition: background .12s, padding-left .12s;
  width: 100%; text-align: left;
  background: transparent; border: 0; font: inherit; cursor: pointer;
}
.chat-task-row[data-loading="1"] { opacity: .55; cursor: progress; }
.chat-task-row:hover { background: var(--bg-sunk); padding-left: 12px; }
.chat-task-row-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--line-2);
  flex: none;
}
.chat-task-row-dot[data-priority="very_high"],
.chat-task-row-dot[data-priority="urgent"] { background: var(--bad); }
.chat-task-row-dot[data-priority="high"] { background: var(--warn); }
.chat-task-row-dot[data-priority="medium"] { background: var(--accent-deep); }
.chat-task-row-title {
  flex: 1; min-width: 0;
  color: var(--ink-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-task-row-due {
  color: var(--ink-4); font-size: 12px;
  flex: none;
}

/* Hint przy długim generowaniu — fade-in po 15s (animation-delay), bez JS. */
.msg-thinking .thinking-hint {
  opacity: 0;
  font-size: 12px;
  color: var(--text-muted, #8a8a8a);
  margin-top: 4px;
  animation: thinking-hint-in 0.4s ease 15s forwards;
}
@keyframes thinking-hint-in {
  to { opacity: 1; }
}

/* ── Wskaźnik pisania na streamującej bańce ─────────────────────────
   Po pierwszym chunku thinking-placeholder jest promowany na
   .msg-streaming i spinner znikał — przy tool-callach agent potrafi
   zamilknąć na kilkanaście sekund i bańka wyglądała jak zamrożona.
   Pulsujące kropki na końcu streamowanego tekstu są widoczne przez
   CAŁY czas streamowania (czysty CSS, zero JS). */
.msg-streaming .msg-streaming-body::after {
  content: '···';
  display: inline-block;
  margin-left: 5px;
  letter-spacing: 2px;
  font-weight: 700;
  color: var(--accent, #b8860b);
  animation: msg-stream-pulse 1.1s ease-in-out infinite;
}
@keyframes msg-stream-pulse {
  0%, 100% { opacity: .25; }
  50% { opacity: .9; }
}

/* Status narzędzia w streamującej bańce („Pobieram dane z Google Ads…") —
   chat-sse.js na event `tool` z SSE marketera; znika przy tekście/końcu. */
.msg-tool-status {
  display: flex; align-items: center; gap: 8px;
  margin-top: 6px;
  font-size: 12.5px; color: var(--ink-3);
}
.msg-tool-status .thinking { font-size: 12px; }
.msg-streaming:has(.msg-tool-status) .msg-streaming-body:empty::after { content: none; }

/* Historia jest nawigacją pomocniczą; pole pytania stanowi punkt startu.
   Reguły startu nie obejmują rozmowy, panelu bocznego ani edytorów zadań. */
@media (min-width: 961px) {
  .chat { grid-template-columns: 240px minmax(0, 1fr); }
}
.chat-rail-heading {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 14px 0;
  font-size: 13px; font-weight: 600; color: var(--ink);
}
.chat-rail-head { padding: 10px 12px 12px; }
.chat-rail-head > .btn { min-height: 36px; justify-content: flex-start; gap: 8px; }
.chat-rail-list { padding: 0 12px 12px; }
.chat-rail .thread-group-h {
  padding: 14px 8px 6px;
  text-transform: none; letter-spacing: normal; font-size: 11px;
}
.chat-rail .thread {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  align-items: center; gap: 8px;
  text-decoration: none;
}
.chat-rail .thread-top { min-width: 0; }
.chat-rail .thread-title { font-size: 13px; }
.chat-rail .thread-meta { margin: 0; font-size: 10px; }
.chat-rail .thread-time { font-family: var(--font-sans); font-size: 10px; }
/* Projekt jest już nazwany w nagłówku aplikacji. Inne zasięgi zachowują znacznik. */
.chat-rail .thread-scope.is-project { display: none; }
.chat-rail .thread-agent { max-width: 64px; }
.chat-rail .thread-unread-dot { top: 50%; right: 3px; width: 4px; height: 4px; transform: translateY(-50%); }
.chat-rail[data-collapsed="true"] .chat-rail-heading > span { display: none; }
.chat-rail[data-collapsed="true"] .chat-rail-heading { padding: 14px 6px 0; }
.chat-rail[data-collapsed="true"] .chat-rail-head { display: none; }
.chat-scroll:has(> .chat-start) { display: flex; flex-direction: column; }
.chat-start {
  width: 100%; max-width: 800px;
  margin: auto;
  padding: clamp(24px, 6vh, 64px) 32px;
  gap: 28px;
  flex-shrink: 0;
}
.chat-start .welcome-hero { flex-direction: column; align-items: center; text-align: center; gap: 18px; }
.chat-start .welcome-spark {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-wash); color: var(--ink);
  box-shadow: none;
}
.chat-start .welcome-h { font-size: clamp(25px, 2.2vw, 32px); letter-spacing: -.035em; line-height: 1.2; }
.chat-start .welcome-sub { font-size: 14px; max-width: 500px; margin: 0 auto; }
.chat-start .welcome-sub b { font-weight: 500; }
.chat-start .composer { padding: 0; border: 0; background: transparent; }
.chat-start .composer-inner { border-color: var(--line-2); box-shadow: var(--sh-1); padding: 16px 16px 10px; }
.chat-start .composer-inner:focus-within { border-color: var(--focus-ring); box-shadow: 0 0 0 3px var(--focus-halo); }
.chat-start .welcome-section-title { font-size: 12px; font-weight: 500; text-transform: none; letter-spacing: normal; margin-bottom: 10px; }
.chat-start .welcome-suggest-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.chat-start .suggest { flex-direction: column; align-items: flex-start; gap: 12px; padding: 14px; border-radius: 12px; background: var(--bg-elev); box-shadow: none; }
.chat-start .suggest:hover { transform: none; border-color: var(--ink-4); background: var(--bg-elev); }
.chat-start .suggest:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.chat-start .suggest-i { width: 20px; height: 20px; border: 0; border-radius: 0; background: transparent; box-shadow: none; color: var(--ink-3); }
.chat-start .suggest-t { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.chat-start .suggest-arrow { display: none; }
@media (max-width: 960px) {
  .chat:has(.chat-rail[data-collapsed="true"]) { grid-template-columns: minmax(0, 1fr); }
  /* Zwijanie dotyczy desktopu; panel mobilny musi odsłonić pełną historię. */
  .chat-rail[data-collapsed="true"] .chat-rail-heading > span { display: inline; }
  .chat-rail[data-collapsed="true"] .chat-rail-heading { padding: 16px 14px 0; }
  .chat-rail[data-collapsed="true"] .chat-rail-list { display: block; }
  .chat-rail[data-collapsed="true"] .chat-rail-head { display: flex; padding: 10px 12px 12px; }
  .chat-rail[data-collapsed="true"] .chat-rail-head .btn-sm { display: inline-flex; }
  .chat-start { max-width: 680px; padding: 24px 20px; gap: 24px; }
}
@media (max-width: 540px) {
  .chat-start { padding: 20px 16px 28px; gap: 20px; }
  .chat-start .welcome-hero { gap: 12px; }
  .chat-start .welcome-h { font-size: 25px; }
  .chat-start .welcome-sub { font-size: 13px; }
  .chat-start .welcome-suggest-grid { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .chat-start .suggest { flex-direction: row; align-items: center; gap: 10px; padding: 10px 12px; }
  .chat-start .suggest-t { font-size: 13px; }
  .chat-start .suggest-arrow { display: inline-flex; }
}

/* Klocek dashboardu w rozmowie (artefakt component/dashboard_widget) —
   ten sam render co na dashboardzie, tylko pełna szerokość bańki. */
.chat-dash-widget { margin: 8px 0; max-width: 100%; }
.chat-dash-widget .dash-widget { width: 100%; }

/* Artefakt inline (klocek danych) — szeroka tabela przewija się w poziomie
   wewnątrz klocka zamiast rozpychać dymek (.msg ma overflow:hidden i
   obcinało prawą część tabeli). */
.msg-inline-artifact { max-width: 100%; min-width: 0; }
/* Kolumna treści dymka jest elementem flex — bez min-width:0 rozciągała
   się do szerokości tabeli klocka (1678 px w dymku 748 px). */
.msg-agent .msg-body-wrap { min-width: 0; }
.msg-inline-artifact + .msg-inline-artifact { margin-top: 10px; }
.chat-dash-widget { min-width: 0; overflow-x: auto; }
.chat-dash-widget table { min-width: max-content; }

/* Wyszukiwanie obejmuje także zwinięte grupy historii. */
.chat-rail-search { padding: 0 12px 6px; }
.chat-rail-search .form-control { min-width: 0; height: 36px; font-size: 12px; background: var(--bg-elev); }
.chat-rail-empty { margin: 14px 8px; color: var(--ink-3); font-size: 12px; line-height: 1.5; }
@media (min-width: 961px) { .chat-rail[data-collapsed="true"] .chat-rail-search { display: none; } }
@media (max-width: 960px) { .chat-rail-search .form-control { height: 40px; font-size: 16px; } }

/* Pigułki „następny krok” (znaczniki <!--sembot:suggest--> z odpowiedzi
   Marketera, proxy chat_suggest.go). Widoczne tylko pod ostatnią
   wiadomością rozmowy — po wysłaniu kolejnej znikają. */
.chat-suggest { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
#chat-stream > .msg:not(:last-child) .chat-suggest { display: none; }
.chat-suggest-pill {
  font: inherit; font-size: 13px; line-height: 1.2;
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line, #e5e7eb); background: var(--surface, #fff);
  color: var(--ink-1, #111); cursor: pointer;
  transition: background .12s, border-color .12s;
}
.chat-suggest-pill:hover { border-color: var(--accent, #b8860b); background: var(--accent-soft, #fff8e6); }
.chat-suggest-pill:focus-visible { outline: 2px solid var(--accent, #b8860b); outline-offset: 2px; }

/* Karta artefaktu z zakładki w dymku odpowiedzi (message_bubble.templ). */
.msg-artifact-ref {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; width: 100%; margin-top: 10px;
  padding: 10px 12px; text-align: left; font: inherit; cursor: pointer;
  border: 1px solid var(--line, #e5e7eb); border-radius: 10px; background: var(--bg, #fafafa); color: inherit;
}
.msg-artifact-ref:hover { border-color: var(--accent, #b8860b); }
.msg-artifact-ref:focus-visible { outline: 2px solid var(--accent, #b8860b); outline-offset: 2px; }
.msg-artifact-ref-icon { display: inline-flex; color: var(--ink-3); flex: none; }
.msg-artifact-ref-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 160px; }
.msg-artifact-ref-text b { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-artifact-ref-text small { font-size: 12px; color: var(--ink-3); }
.msg-artifact-ref-go { font-size: 12px; color: var(--ink-3); white-space: nowrap; flex: none; margin-left: auto; }
.msg-artifact-ref[data-missing] { opacity: .6; cursor: default; }

/* Odpowiedź agenta na pełną szerokość kolumny rozmowy (decyzja usera
   2026-09-30): bez awatara z boku (nazwa jest w nagłówku), tekst ma
   czytelną długość linii, a klocki danych pełną szerokość. */
.chat-stream > .msg-agent:not(.msg-thinking) { align-self: stretch; max-width: none; width: 100%; box-sizing: border-box; padding: 14px 18px; }
.chat-stream > .msg-agent > .msg-avatar { display: none; }
.msg-agent .msg-body > :is(p, ul, ol, h1, h2, h3, h4, blockquote) { max-width: 82ch; }
.msg-agent .msg-body > .msg-inline-artifact { margin: 12px 0 14px; }

/* Tok myślenia — kroki między narzędziami, zwinięte nad odpowiedzią
   (proxy chat_steps.go). */
.msg-process { margin: 0 0 12px; font-size: 13px; color: var(--ink-3); }
.msg-process > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg); user-select: none; }
.msg-process > summary::-webkit-details-marker { display: none; }
.msg-process > summary::before { content: "▸"; font-size: 10px; transition: transform .12s; }
.msg-process[open] > summary::before { transform: rotate(90deg); }
.msg-process-count { color: var(--ink-4); }
.msg-process-steps { margin: 8px 0 0; padding: 0 0 0 20px; border-left: 2px solid var(--line); list-style: decimal; }
.msg-process-steps li { margin: 0 0 6px; padding-left: 4px; }
.msg-process-steps li p { margin: 0; }

/* Obiekt z bazy wiedzy w odpowiedzi (artefakt kb_object: obraz, wideo,
   PDF, dokument) — pokazujemy wynik, nie link. */
.chat-kb-object { margin: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg-elev, var(--bg)); max-width: 720px; }
.chat-kb-object-media { display: block; background: var(--bg-sunk, #f4f4f5); }
.chat-kb-object-media img, video.chat-kb-object-media { display: block; width: 100%; max-height: 560px; object-fit: contain; }
.chat-kb-object-pdf { display: block; width: 100%; height: 520px; border: 0; }
.chat-kb-object-text { max-height: 420px; overflow: auto; padding: 14px 16px; font-size: 13.5px; line-height: 1.55; }
.chat-kb-object-doc > :first-child { margin-top: 0; }
.chat-kb-object-more { padding: 0 16px 10px; color: var(--ink-3); }
.chat-kb-object-caption { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 12.5px; }
.chat-kb-object-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); font-weight: 500; }
.chat-kb-object-action { color: var(--ink-3); text-decoration: none; white-space: nowrap; }
.chat-kb-object-action:hover { color: var(--ink); text-decoration: underline; }
/* Klocek i obiekt KB mają własną kartę — slot bez drugiej ramki i tła. */
.msg-inline-artifact:has(> .chat-kb-object, > .chat-dash-widget) { padding: 0; border: 0; background: none; }
.msg-inline-artifact > .chat-dash-widget { margin: 0; }

/* Kolekcja obrazów (MCP sembot_creative_generate_image z count/models —
   embedy kolejno, bez tekstu pomiędzy): sąsiednie obrazy z bazy wiedzy
   układają się w galerię po dwa w rzędzie. Pojedynczy obraz zostaje
   w pełnej szerokości karty. */
.msg-inline-artifact:has(> .chat-kb-object[data-kind="image"]):has(+ .msg-inline-artifact > .chat-kb-object[data-kind="image"]),
.msg-inline-artifact:has(> .chat-kb-object[data-kind="image"]) + .msg-inline-artifact:has(> .chat-kb-object[data-kind="image"]) {
  display: inline-block; vertical-align: top;
  width: calc(50% - 8px); margin-right: 6px; margin-top: 8px;
}
.msg-inline-artifact:has(> .chat-kb-object[data-kind="image"]):has(+ .msg-inline-artifact > .chat-kb-object[data-kind="image"]) .chat-kb-object-media img,
.msg-inline-artifact:has(> .chat-kb-object[data-kind="image"]) + .msg-inline-artifact:has(> .chat-kb-object[data-kind="image"]) .chat-kb-object-media img { height: 340px; max-height: none; object-fit: contain; }
@media (max-width: 720px) {
  .msg-inline-artifact:has(> .chat-kb-object[data-kind="image"]) + .msg-inline-artifact:has(> .chat-kb-object[data-kind="image"]),
  .msg-inline-artifact:has(> .chat-kb-object[data-kind="image"]):has(+ .msg-inline-artifact > .chat-kb-object[data-kind="image"]) { width: 100%; margin-right: 0; }
}
