/*
 * Kapable Chat Widget — Sidebar AI assistant
 * Uses --kp-* tokens from kapable-theme.css exclusively. Text and icons on the accent fill take
 * --kp-on-accent (white, or a look's own ink where its dark button turns light: presets D45).
 * The fills read --kp-accent-fill first: the theme bridge sets it to the accent fill in dark mode,
 * where its --kp-accent is the light accent text colour (PLAT-1359). Without it, --kp-accent.
 *
 * chat-widget-v0.6.1 (PLAT-1359): in dark mode the fills read the accent fill (see above).
 *
 * chat-widget-v0.6.0 (PLAT-1342): the widget follows the org's look (taste presets). Its type
 * sizes, corners, padding and gaps, control weights and its prose face read the design
 * language's tokens, which a look changes. Each read carries the value the widget had as its
 * fallback, so a page without the language, and every page under the default look, draws
 * exactly as before (presets D36). A value no role holds is a role times a fixed ratio, or stays
 * literal with its reason on the line. A look changes values only, never layout (presets D8).
 */

/* The padding factor for a page without the language's tokens (or one older than
   1.30.0): 1. Any tokens.css or look that sets it wins: this rule has no specificity. */
:where(:root) { --pad-factor: 1; }

/* ── Toggle button ── */
.kp-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10001;
  width: 48px;
  height: 48px; /* raw: a square icon button, width and height one size, not a density value */
  border-radius: 50%;
  background: var(--kp-accent-fill, var(--kp-accent));
  color: var(--kp-on-accent, #fff);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25); /* raw: the floating launcher's lift; no shadow role draws a round button's drop */
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), background 0.15s; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
.kp-chat-toggle:hover {
  transform: scale(1.08);
  background: var(--kp-accent-fill, var(--kp-accent-hi));
}
.kp-chat-toggle svg {
  width: 22px;
  height: 22px; /* raw: size of an icon, mark or avatar, not a density value (PLAT-1147) */
}
.kp-chat-toggle[aria-expanded="true"] {
  transform: scale(0.9);
  opacity: 0.7;
}

/* ── Unread badge ── */
.kp-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 18px;
  height: 18px; /* raw: size of an icon, mark or avatar, not a density value (PLAT-1147) */
  border-radius: calc(var(--radius-tag, 6px) * 9 / 6);
  background: var(--kp-danger);
  color: #fff; /* raw: white count on the red badge; the language has no text-on-status role */
  font-size: var(--type-tag, 11px);
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 calc(5px * var(--pad-factor));
  font-family: var(--kp-font);
}
.kp-chat-badge.visible {
  display: flex;
}

/* ── Unread pulse ── */
@keyframes kp-chat-pulse {
  0%, 100% { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25); } /* raw: the floating launcher's lift; no shadow role draws a round button's drop */
  50% { box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25), 0 0 0 8px var(--kp-accent-bg); } /* raw: the launcher's lift plus an unread ring in the accent wash; no shadow role holds it */
}
.kp-chat-toggle.unread {
  animation: kp-chat-pulse 2s ease-in-out infinite; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}

/* ── Backdrop ── */
.kp-chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.3); /* raw: the scrim behind the open panel; no role holds a scrim */
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
.kp-chat-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Sidebar ── */
.kp-chat-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 400px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  background: var(--kp-bg);
  border-left: 1px solid var(--kp-border);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1); /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
  font-family: var(--kp-font);
}
.kp-chat-sidebar.open {
  transform: translateX(0);
}

/* ── Sidebar header ── */
.kp-chat-header {
  display: flex;
  align-items: center;
  gap: calc(8px * var(--pad-factor));
  height: 48px; /* raw: the panel's title row, one size with the 48px launcher; no role holds it */
  padding: 0 calc(16px * var(--pad-factor));
  border-bottom: 1px solid var(--kp-border);
  background: var(--kp-surface);
  flex-shrink: 0;
}
.kp-chat-header-title {
  font-size: var(--type-body, 14px);
  font-weight: var(--control-weight, 600);
  color: var(--kp-text);
  flex: 1;
}
.kp-chat-status {
  width: 8px;
  height: 8px; /* raw: size of an icon, mark or avatar, not a density value (PLAT-1147) */
  border-radius: 50%;
  flex-shrink: 0;
  box-sizing: border-box; /* keep footprint constant when ring/border is applied */
  transition: background 0.3s; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
/*
 * WCAG 1.4.1 — connection state is NOT conveyed by color alone.
 * connected     = solid dot (baseline)
 * reconnecting  = pulsing dot (motion cue)
 * disconnected  = hollow ring (shape cue: transparent fill + colored border)
 */
.kp-chat-status.connected {
  background: var(--kp-success);
  border: 1px solid var(--kp-success);
}
.kp-chat-status.reconnecting {
  background: var(--kp-warn);
  border: 1px solid var(--kp-warn);
  animation: kp-chat-status-reconnect-pulse 1.2s ease-in-out infinite; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
.kp-chat-status.disconnected {
  background: transparent;
  border: 2px solid var(--kp-danger);
}

@keyframes kp-chat-status-reconnect-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.45); opacity: 0.55; }
}

/* Reduced-motion: swap the pulse for a static ring-glow so the cue persists. */
@media (prefers-reduced-motion: reduce) {
  .kp-chat-status.reconnecting {
    animation: none;
    background: transparent;
    border: 2px solid var(--kp-warn);
    box-shadow: 0 0 0 2px var(--kp-warn-bg, rgba(245, 158, 11, 0.3)); /* raw: a static ring standing in for the pulse under reduced motion, a state cue, not a lift */
  }
}

.kp-chat-close {
  width: 32px;
  height: 32px; /* raw: a square icon button, width and height one size, not a density value */
  border-radius: calc(var(--radius-icon-button, 8px) * 6 / 8);
  border: none;
  background: none;
  color: var(--kp-text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
.kp-chat-close:hover {
  background: var(--kp-surface-hi);
  color: var(--kp-text);
}
.kp-chat-close svg {
  width: 16px;
  height: 16px; /* raw: size of an icon, mark or avatar, not a density value (PLAT-1147) */
}

.kp-chat-copy {
  height: 32px; /* raw: a square icon button, width and height one size, not a density value */
  min-width: 32px;
  padding: 0 calc(6px * var(--pad-factor));
  border-radius: calc(var(--radius-icon-button, 8px) * 6 / 8);
  border: none;
  background: none;
  color: var(--kp-text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(4px * var(--pad-factor));
  transition: background 0.15s, color 0.15s; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
.kp-chat-copy:hover {
  background: var(--kp-surface-hi);
  color: var(--kp-text);
}
.kp-chat-copy svg {
  width: 16px;
  height: 16px; /* raw: size of an icon, mark or avatar, not a density value (PLAT-1147) */
}
.kp-chat-copy.copied {
  color: var(--kp-success);
}
.kp-chat-copy.copy-failed {
  color: var(--kp-danger);
}
.kp-chat-copy-label {
  font-size: var(--type-tag, 11px);
  white-space: nowrap;
}

/* New chat + previous-chats header buttons (match .kp-chat-copy) */
.kp-chat-new,
.kp-chat-history {
  height: 32px; /* raw: a square icon button, width and height one size, not a density value */
  min-width: 32px;
  padding: 0 calc(6px * var(--pad-factor));
  border-radius: calc(var(--radius-icon-button, 8px) * 6 / 8);
  border: none;
  background: none;
  color: var(--kp-text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
.kp-chat-new:hover,
.kp-chat-history:hover {
  background: var(--kp-surface-hi);
  color: var(--kp-text);
}
.kp-chat-new svg,
.kp-chat-history svg {
  width: 16px;
  height: 16px; /* raw: size of an icon, mark or avatar, not a density value (PLAT-1147) */
}
.kp-chat-history[aria-expanded="true"] {
  background: var(--kp-surface-hi);
  color: var(--kp-text);
}

/* ── Prior-conversation picker panel ── */
.kp-chat-conv-panel {
  display: none;
  max-height: 260px;
  overflow-y: auto;
  border-bottom: 1px solid var(--kp-border);
  background: var(--kp-surface);
  flex-direction: column;
  padding: calc(4px * var(--pad-factor));
}
.kp-chat-conv-panel.open {
  display: flex;
}
.kp-chat-conv-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: calc(8px * var(--pad-factor));
  width: 100%;
  padding: calc(8px * var(--pad-factor)) calc(10px * var(--pad-factor));
  border: none;
  border-radius: calc(var(--radius-row, 7px) * 6 / 7);
  background: none;
  color: var(--kp-text);
  cursor: pointer;
  text-align: left;
  font-size: var(--type-secondary, 12.5px);
  transition: background 0.15s; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
.kp-chat-conv-item:hover {
  background: var(--kp-surface-hi);
}
.kp-chat-conv-item.current {
  background: var(--kp-surface-hi);
}
.kp-chat-conv-title {
  font-family: var(--kp-font-body, var(--kp-font)); /* prose reads the look's body face (presets D45) */
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kp-chat-conv-date {
  flex-shrink: 0;
  font-size: calc(var(--type-meta, 12px) * 10.5 / 12);
  color: var(--kp-text-dim);
}
.kp-chat-conv-empty {
  padding: calc(10px * var(--pad-factor));
  font-size: var(--type-meta, 12px);
  color: var(--kp-text-dim);
  text-align: center;
}

/* ── Messages area ── */
.kp-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: calc(16px * var(--pad-factor));
  display: flex;
  flex-direction: column;
  gap: calc(12px * var(--pad-factor));
  overscroll-behavior: contain;
}

/* ── Message bubbles ── */
.kp-chat-msg {
  font-family: var(--kp-font-body, var(--kp-font)); /* prose reads the look's body face (presets D45) */
  max-width: 85%;
  padding: calc(10px * var(--pad-factor)) calc(14px * var(--pad-factor));
  font-size: var(--type-body, 14px);
  line-height: 1.5;
  word-break: break-word;
}
.kp-chat-msg.user {
  align-self: flex-end;
  background: var(--kp-accent-fill, var(--kp-accent));
  color: var(--kp-on-accent, #fff);
  border-radius: calc(var(--radius-card, 12px) * 16 / 12) calc(var(--radius-card, 12px) * 16 / 12) calc(var(--radius-card, 12px) * 4 / 12) calc(var(--radius-card, 12px) * 16 / 12);
}
.kp-chat-msg.assistant {
  align-self: flex-start;
  background: var(--kp-surface);
  color: var(--kp-text);
  border-radius: calc(var(--radius-card, 12px) * 16 / 12) calc(var(--radius-card, 12px) * 16 / 12) calc(var(--radius-card, 12px) * 16 / 12) calc(var(--radius-card, 12px) * 4 / 12);
  border: 1px solid var(--kp-border);
}

/* ── Streaming cursor ── */
@keyframes kp-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
.kp-chat-msg.streaming::after {
  content: "\25CF";
  display: inline;
  margin-left: 2px;
  color: var(--kp-accent);
  animation: kp-blink 1s step-end infinite; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}

/* ── Markdown in messages ── */
.kp-chat-msg a { color: inherit; text-decoration: underline; }
.kp-chat-msg.user a { color: var(--kp-on-accent, #fff); }
.kp-chat-msg code {
  font-family: var(--kp-font-mono);
  font-size: var(--type-control, 13px);
  background: rgba(0, 0, 0, 0.15); /* raw: a darkening tint over whichever bubble fill holds the code; no role holds it */
  padding: calc(1px * var(--pad-factor)) calc(5px * var(--pad-factor));
  border-radius: calc(var(--radius-tag, 6px) * 4 / 6);
}
.kp-chat-msg.assistant code {
  background: var(--kp-surface-hi);
}
.kp-chat-msg pre {
  margin: 8px 0 4px;
  padding: calc(10px * var(--pad-factor)) calc(12px * var(--pad-factor));
  border-radius: var(--radius-tag, 6px);
  background: var(--kp-bg);
  overflow-x: auto;
  position: relative;
}
.kp-chat-msg.assistant pre {
  border: 1px solid var(--kp-border);
}
.kp-chat-msg pre code {
  background: none;
  padding: 0;
  font-size: var(--type-meta, 12px);
  line-height: 1.6;
}
.kp-chat-msg ul, .kp-chat-msg ol {
  margin: 4px 0;
  padding-left: calc(20px * var(--pad-factor));
}
.kp-chat-msg li {
  margin: 2px 0;
}
.kp-chat-msg strong { font-weight: 700; }
.kp-chat-msg em { font-style: italic; }
.kp-chat-msg p { margin: 0 0 8px; }
.kp-chat-msg p:last-child { margin-bottom: 0; }

/* ── Copy button on code blocks ── */
.kp-code-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: calc(3px * var(--pad-factor)) calc(8px * var(--pad-factor));
  border-radius: calc(var(--radius-button, 8px) * 4 / 8);
  border: 1px solid var(--kp-border);
  background: var(--kp-surface);
  color: var(--kp-text-dim);
  font-size: var(--type-tag, 11px);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
  font-family: var(--kp-font);
}
.kp-chat-msg pre:hover .kp-code-copy { opacity: 1; }
.kp-code-copy:hover { color: var(--kp-text); background: var(--kp-surface-hi); }

/* ── Tool calls ── */
.kp-tool-call {
  max-width: 85%;
  align-self: flex-start;
  padding: calc(8px * var(--pad-factor)) calc(12px * var(--pad-factor));
  border-radius: calc(var(--radius-card, 12px) * 8 / 12);
  background: var(--kp-surface);
  border: 1px solid var(--kp-border);
  font-size: var(--type-control, 13px);
}
.kp-tool-call-name {
  font-weight: var(--row-title-weight, 600);
  font-family: var(--kp-font-body, var(--kp-font)); /* a row title reads the look's body face and row-title weight (presets D45) */
  color: var(--kp-text);
  font-size: var(--type-meta, 12px);
  display: flex;
  align-items: center;
  gap: calc(6px * var(--pad-factor));
}
.kp-tool-call-name svg {
  width: 14px;
  height: 14px; /* raw: size of an icon, mark or avatar, not a density value (PLAT-1147) */
  color: var(--kp-accent);
}
.kp-tool-call-summary {
  font-family: var(--kp-font-body, var(--kp-font)); /* prose reads the look's body face (presets D45) */
  color: var(--kp-text-dim);
  font-size: var(--type-meta, 12px);
  margin-top: 4px;
}

/* ── Tool result (collapsible) ── */
.kp-tool-result {
  margin-top: 6px;
  border-top: 1px solid var(--kp-border);
  padding-top: calc(6px * var(--pad-factor));
}
.kp-tool-result-toggle {
  font-size: var(--type-tag, 11px);
  color: var(--kp-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: calc(2px * var(--pad-factor)) 0;
  font-family: var(--kp-font);
}
.kp-tool-result-toggle:hover { color: var(--kp-text-dim); }
.kp-tool-result-body {
  display: none;
  margin-top: 4px;
  padding: calc(8px * var(--pad-factor));
  border-radius: calc(var(--radius-tag, 6px) * 4 / 6);
  background: var(--kp-bg);
  font-family: var(--kp-font-mono);
  font-size: var(--type-meta, 12px);
  line-height: 1.5;
  color: var(--kp-text-dim);
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.kp-tool-result-body.expanded { display: block; }

/* ── Tool description ── */
.kp-tool-call-desc {
  font-family: var(--kp-font-body, var(--kp-font)); /* prose reads the look's body face (presets D45) */
  color: var(--kp-text-dim);
  font-size: var(--type-meta, 12px);
  margin-top: 4px;
  line-height: 1.4;
}

/* ── Tool input detail (collapsible) ── */
.kp-tool-input-detail {
  margin-top: 6px;
}
.kp-tool-input-toggle {
  font-size: var(--type-tag, 11px);
  color: var(--kp-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: calc(2px * var(--pad-factor)) 0;
  font-family: var(--kp-font);
}
.kp-tool-input-toggle:hover { color: var(--kp-text-dim); }
.kp-tool-input-body {
  display: none;
  margin-top: 4px;
  padding: calc(6px * var(--pad-factor)) calc(8px * var(--pad-factor));
  border-radius: calc(var(--radius-tag, 6px) * 4 / 6);
  background: var(--kp-bg);
  font-family: var(--kp-font-mono);
  font-size: var(--type-tag, 11px);
  line-height: 1.4;
  color: var(--kp-text-dim);
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.kp-tool-input-body.expanded { display: block; }

/* ── Risk-level border accent ── */
.kp-tool-call.kp-risk-sensitive {
  border-color: var(--kp-warn);
}

/* ── Approval buttons ── */
.kp-tool-approval {
  display: flex;
  flex-wrap: wrap;
  gap: calc(6px * var(--pad-factor));
  margin-top: 8px;
  align-items: center;
}
.kp-tool-approval button {
  padding: calc(5px * var(--pad-factor)) calc(12px * var(--pad-factor));
  border-radius: calc(var(--radius-button, 8px) * 6 / 8);
  font-size: var(--type-meta, 12px);
  font-weight: 500;
  cursor: pointer;
  font-family: var(--kp-font);
  transition: filter 0.15s, opacity 0.15s; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
.kp-tool-approval button:hover { filter: brightness(1.1); }
.kp-tool-approval button:focus-visible { outline: 2px solid var(--kp-accent); outline-offset: 2px; }
.kp-approve { background: var(--kp-accent-fill, var(--kp-accent)); color: var(--kp-on-accent, #fff); border: none; }
.kp-approve-always { background: transparent; color: var(--kp-success); border: 1px solid var(--kp-success); }
.kp-approve-always:hover { background: var(--kp-success); color: #fff; } /* raw: white on the green fill; the language has no text-on-status role */
.kp-deny { background: transparent; color: var(--kp-text-muted); border: 1px solid var(--kp-border); }
.kp-deny:hover { background: var(--kp-danger); color: #fff; border-color: var(--kp-danger); } /* raw: white on the red fill; the language has no text-on-status role */

/* ── Approval countdown ── */
.kp-approval-countdown {
  font-size: var(--type-tag, 11px);
  color: var(--kp-text-muted);
  margin-left: auto;
}

/* ── Auto-approve toast ── */
.kp-auto-approve-toast {
  align-self: center;
  padding: calc(4px * var(--pad-factor)) calc(12px * var(--pad-factor));
  border-radius: calc(var(--radius-tag, 6px) * 2);
  background: var(--kp-success);
  color: #fff; /* raw: white on the green toast; the language has no text-on-status role */
  font-size: var(--type-tag, 11px);
  opacity: 0.9;
  animation: kp-toast-fade 3s ease forwards; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
@keyframes kp-toast-fade {
  0%, 70% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* ── Amber pulse on toggle when approval pending ── */
@keyframes kp-approval-pulse {
  0%, 100% { box-shadow: 0 4px 12px rgba(0,0,0,0.25); } /* raw: the floating launcher's lift; no shadow role draws a round button's drop */
  50% { box-shadow: 0 4px 12px rgba(0,0,0,0.25), 0 0 0 8px rgba(245,158,11,0.3); } /* raw: the launcher's lift plus an amber 'approval waiting' ring; no shadow role holds it */
}
.kp-chat-toggle.kp-approval-pending {
  animation: kp-approval-pulse 1.5s ease-in-out infinite; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}

/* ── Input area ── */
.kp-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: calc(8px * var(--pad-factor));
  padding: calc(12px * var(--pad-factor)) calc(16px * var(--pad-factor));
  border-top: 1px solid var(--kp-border);
  background: var(--kp-surface);
  flex-shrink: 0;
}
.kp-chat-textarea {
  flex: 1;
  min-height: 40px; /* raw: a growing message field's one-line height, sized for its 14px text; not a control height */
  max-height: 120px;
  padding: calc(9px * var(--pad-factor)) calc(12px * var(--pad-factor));
  border-radius: var(--radius-field, 8px);
  border: 1px solid var(--kp-border);
  background: var(--kp-bg);
  color: var(--kp-text);
  font-family: var(--kp-font);
  font-size: var(--type-body, 14px);
  line-height: 1.4;
  resize: none;
  outline: none;
  overflow-y: auto;
}
.kp-chat-textarea:focus {
  border-color: var(--kp-accent);
}
.kp-chat-textarea::placeholder {
  color: var(--kp-text-muted);
}
.kp-chat-send {
  width: 36px;
  height: 36px; /* raw: a square icon button, width and height one size, not a density value */
  border-radius: var(--radius-button, 8px);
  border: none;
  background: var(--kp-accent-fill, var(--kp-accent));
  color: var(--kp-on-accent, #fff);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
.kp-chat-send:hover { background: var(--kp-accent-fill, var(--kp-accent-hi)); }
.kp-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.kp-chat-send svg { width: 18px; height: 18px; } /* raw: size of an icon, mark or avatar, not a density value (PLAT-1147) */

/* ── Empty state ── */
.kp-chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(32px * var(--pad-factor)) calc(24px * var(--pad-factor));
  text-align: center;
  gap: calc(16px * var(--pad-factor));
}
.kp-chat-empty-icon {
  width: 48px;
  height: 48px; /* raw: size of an icon, mark or avatar, not a density value (PLAT-1147) */
  color: var(--kp-text-muted);
  opacity: 0.5;
}
.kp-chat-empty-text {
  font-family: var(--kp-font-body, var(--kp-font)); /* prose reads the look's body face (presets D45) */
  font-size: var(--type-body, 14px);
  color: var(--kp-text-dim);
}
.kp-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: calc(8px * var(--pad-factor));
  justify-content: center;
}
.kp-chat-chip {
  padding: calc(6px * var(--pad-factor)) calc(14px * var(--pad-factor));
  border-radius: calc(var(--radius-button, 8px) * 2);
  border: 1px solid var(--kp-border);
  background: var(--kp-surface);
  color: var(--kp-text-dim);
  font-size: var(--type-control, 13px);
  cursor: pointer;
  font-family: var(--kp-font);
  transition: border-color 0.15s, color 0.15s; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
.kp-chat-chip:hover {
  border-color: var(--kp-accent);
  color: var(--kp-accent);
}

/* ── Mobile ── */
@media (max-width: 639px) {
  .kp-chat-sidebar { width: 100%; }
  .kp-chat-toggle { bottom: 16px; right: 16px; }
}

/* ── Scrollbar ── */
.kp-chat-messages::-webkit-scrollbar { width: 6px; }
.kp-chat-messages::-webkit-scrollbar-track { background: transparent; }
.kp-chat-messages::-webkit-scrollbar-thumb {
  background: var(--kp-border);
  border-radius: 3px; /* raw: a round end on the 6px scrollbar thumb, half its width; no shape role */
}

/* ── Staged status line + per-answer timings meta ── */
.kp-chat-status-line {
  align-self: flex-start;
  font-size: var(--type-control, 13px);
  font-style: italic;
  color: var(--kp-text-dim);
  padding: calc(4px * var(--pad-factor)) calc(8px * var(--pad-factor));
  animation: kp-status-pulse 1.4s ease-in-out infinite; /* raw: no motion token holds it; motion is not a preset dimension (presets D7) */
}
@keyframes kp-status-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}
.kp-chat-meta {
  margin-top: 6px;
  font-size: var(--type-tag, 11px);
  color: var(--kp-text-dim);
  opacity: 0.8;
  user-select: none;
}
