/* Klinck Software — site chat widget.
   Reuses the palette/typography variables defined in style.css
   (--bg, --card, --card-border, --accent, --accent-on, --fg, --muted,
   --shadow, --radius). No new colors introduced. */

#kw-chat-bubble {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent-on);
  color: #fff;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
  transition: transform 0.15s ease, background 0.15s ease;
}
#kw-chat-bubble:hover { background: var(--accent-on-strong); transform: translateY(-2px); }
#kw-chat-bubble svg { width: 26px; height: 26px; }
#kw-chat-bubble .kw-chat-close-icon { display: none; }
#kw-chat-bubble[aria-expanded="true"] .kw-chat-open-icon { display: none; }
#kw-chat-bubble[aria-expanded="true"] .kw-chat-close-icon { display: block; }

#kw-chat-panel {
  position: fixed;
  right: 22px;
  bottom: 90px;
  width: min(360px, calc(100vw - 32px));
  height: min(520px, calc(100vh - 140px));
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
  font: 15px/1.55 Charter, "Bitstream Charter", "Iowan Old Style", Georgia, Cambria, "Times New Roman", serif;
}
#kw-chat-panel.open { display: flex; }

#kw-chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#kw-chat-header .kw-chat-title { font-weight: 700; color: var(--fg); font-size: 15.5px; }
#kw-chat-header .kw-chat-subtitle { color: var(--muted); font-size: 12.5px; margin-top: 2px; }

#kw-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg);
}

.kw-msg {
  max-width: 88%;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.kw-msg-user {
  align-self: flex-end;
  background: var(--accent-on);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.kw-msg-assistant {
  align-self: flex-start;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  color: var(--fg);
  border-bottom-left-radius: 4px;
}
.kw-msg-system {
  align-self: center;
  color: var(--muted);
  font-size: 12.5px;
  font-style: italic;
  text-align: center;
  max-width: 100%;
}
.kw-msg-assistant.kw-msg-pending::after {
  content: "\2009\2026";
  color: var(--muted);
}

#kw-chat-form {
  border-top: 1px solid var(--border);
  padding: 10px;
  display: flex;
  gap: 8px;
  background: var(--card);
}
#kw-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  font-size: 14.5px;
  color: var(--fg);
  background: var(--bg);
  max-height: 90px;
}
#kw-chat-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
#kw-chat-send {
  border: none;
  background: var(--accent-on);
  color: #fff;
  border-radius: 10px;
  width: 40px;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
#kw-chat-send:hover { background: var(--accent-on-strong); }
#kw-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }
#kw-chat-send svg { width: 18px; height: 18px; }

#kw-chat-footer {
  padding: 6px 14px 10px;
  text-align: center;
  background: var(--card);
}
#kw-chat-footer .kw-chat-footnote {
  font-size: 11.5px;
  color: var(--muted);
}
#kw-chat-footer .kw-chat-footnote a { color: var(--muted); text-decoration-color: color-mix(in srgb, var(--muted) 40%, transparent); }

@media (max-width: 480px) {
  #kw-chat-panel {
    right: 16px;
    left: 16px;
    width: auto;
    bottom: 84px;
  }
  #kw-chat-bubble { right: 16px; bottom: 16px; }
}
