/* Floating Kaizen chat — uses page :root tokens when present */
#kaizen-chat-root {
  --chat-accent: var(--accent, #ff4d2d);
  --chat-panel: var(--panel, #11131b);
  --chat-text: var(--text, #eceef3);
  --chat-muted: var(--muted, #a9aebb);
  --chat-line: var(--line, rgba(255, 255, 255, 0.12));
  --chat-font: var(--font-secondary, "Inter", system-ui, sans-serif);
  position: fixed;
  z-index: 9999;
  right: 1rem;
  bottom: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0;
  font-family: var(--chat-font);
  font-size: 0.9375rem;
  line-height: 1.45;
}

#kaizen-chat-root *,
#kaizen-chat-root *::before,
#kaizen-chat-root *::after {
  box-sizing: border-box;
}

.kaizen-chat-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 3rem;
  padding: 0 1.1rem;
  border: 1px solid var(--chat-line);
  border-radius: 999px;
  background: linear-gradient(145deg, rgba(255, 77, 45, 0.95), rgba(255, 77, 45, 0.75));
  color: #0c0d10;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kaizen-chat-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
}

.kaizen-chat-toggle:focus-visible {
  outline: 2px solid var(--chat-accent);
  outline-offset: 3px;
}

.kaizen-chat-panel {
  display: none;
  flex-direction: column;
  width: min(100vw - 2rem, 22rem);
  max-height: min(70dvh, 28rem);
  margin-bottom: 0.75rem;
  border: 1px solid var(--chat-line);
  border-radius: 12px;
  background: rgba(17, 19, 27, 0.96);
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

#kaizen-chat-root.is-open .kaizen-chat-panel {
  display: flex;
}

#kaizen-chat-root.is-open .kaizen-chat-toggle {
  background: var(--chat-panel);
  color: var(--chat-text);
  border-color: var(--chat-line);
}

.kaizen-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--chat-line);
  background: rgba(0, 0, 0, 0.2);
}

.kaizen-chat-header h2 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--chat-text);
}

.kaizen-chat-close {
  border: none;
  background: transparent;
  color: var(--chat-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
}

.kaizen-chat-close:hover {
  color: var(--chat-text);
}

.kaizen-chat-close:focus-visible {
  outline: 2px solid var(--chat-accent);
  outline-offset: 2px;
}

.kaizen-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 10rem;
}

.kaizen-chat-msg {
  max-width: 92%;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.kaizen-chat-msg--assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.06);
  color: var(--chat-text);
  border: 1px solid var(--chat-line);
}

.kaizen-chat-msg--user {
  align-self: flex-end;
  background: rgba(255, 77, 45, 0.18);
  border: 1px solid rgba(255, 77, 45, 0.35);
  color: var(--chat-text);
}

.kaizen-chat-msg--system {
  align-self: center;
  font-size: 0.8125rem;
  color: var(--chat-muted);
  background: transparent;
  border: none;
  padding: 0.25rem;
}

.kaizen-chat-msg--error {
  align-self: center;
  color: #ffb4a8;
  background: rgba(180, 40, 20, 0.25);
  border: 1px solid rgba(255, 100, 80, 0.35);
  font-size: 0.8125rem;
}

.kaizen-chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-top: 1px solid var(--chat-line);
  background: rgba(0, 0, 0, 0.15);
}

.kaizen-chat-input {
  flex: 1;
  min-height: 2.5rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--chat-line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--chat-text);
  font: inherit;
  resize: none;
  max-height: 6rem;
}

.kaizen-chat-input::placeholder {
  color: var(--chat-muted);
  opacity: 0.85;
}

.kaizen-chat-input:focus {
  outline: none;
  border-color: rgba(255, 77, 45, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 77, 45, 0.25);
}

.kaizen-chat-send {
  flex-shrink: 0;
  min-width: 4.5rem;
  padding: 0 0.75rem;
  border: none;
  border-radius: 8px;
  background: var(--chat-accent);
  color: #0c0d10;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.kaizen-chat-send:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.kaizen-chat-send:focus-visible {
  outline: 2px solid var(--chat-accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .kaizen-chat-toggle {
    transition: none;
  }
}
