/* Kwality Electric — chat widget
   Reuses design tokens from styles.css. Matches the floating CTA's visual
   language (same radii, shadow palette, Geist font) so the chat reads as a
   native continuation of the site, not a foreign widget. */

.kwe-chat {
  position: fixed;
  right: 24px;
  bottom: 96px; /* sits above the floating CTA */
  z-index: 101;
  font-family: inherit;
  pointer-events: none;
}

.kwe-chat-card {
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 120px);
  background: var(--card, #ffffff);
  border-radius: 22px;
  box-shadow:
    0 32px 80px rgba(14, 27, 44, 0.24),
    0 6px 18px rgba(14, 27, 44, 0.08),
    0 0 0 1px rgba(14, 27, 44, 0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.9) translateY(16px);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.22s ease,
    transform 0.36s cubic-bezier(0.34, 1.56, 0.64, 1),
    visibility 0s linear 0.4s;
}

.kwe-chat[data-open="true"] {
  pointer-events: auto;
}
.kwe-chat[data-open="true"] .kwe-chat-card {
  opacity: 1;
  transform: scale(1) translateY(0);
  visibility: visible;
  transition:
    opacity 0.24s ease,
    transform 0.42s cubic-bezier(0.34, 1.56, 0.64, 1),
    visibility 0s;
}

/* ---------- Header ---------- */

.kwe-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line, rgba(14, 27, 44, 0.08));
}

.kwe-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--yellow, #FFC233);
  color: var(--ink, #0E1B2C);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(255, 194, 51, 0.4);
}

.kwe-chat-titleblock { flex: 1; min-width: 0; }
.kwe-chat-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--ink, #0E1B2C);
}
.kwe-chat-sub {
  font-size: 12px;
  color: var(--muted, #6b7785);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}
.kwe-chat-live-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--green, #1E7A3A);
}

.kwe-chat-close,
.kwe-chat-clear {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-2, #2A3848);
  background: transparent;
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}
.kwe-chat-close:hover,
.kwe-chat-clear:hover { background: rgba(14, 27, 44, 0.06); color: var(--ink, #0E1B2C); }

/* ---------- Message list ---------- */

.kwe-chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.kwe-chat-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: kwe-bubble-in 0.22s ease-out;
}
@keyframes kwe-bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.kwe-chat-msg-user { align-items: flex-end; }
.kwe-chat-msg-assistant,
.kwe-chat-msg-human { align-items: flex-start; }

.kwe-chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.kwe-chat-msg-user .kwe-chat-bubble {
  background: var(--ink, #0E1B2C);
  color: #fff;
  border-bottom-right-radius: 6px;
  max-width: 80%;
}
.kwe-chat-msg-assistant .kwe-chat-bubble {
  background: rgba(14, 27, 44, 0.05);
  color: var(--ink, #0E1B2C);
  border-bottom-left-radius: 6px;
}
.kwe-chat-msg-human .kwe-chat-bubble {
  background: var(--yellow-bg, #FFF4D6);
  color: var(--ink, #0E1B2C);
  border-bottom-left-radius: 6px;
  border: 1px solid var(--yellow-soft, #FFE7A8);
}

.kwe-chat-bubble p { margin: 0; }
.kwe-chat-bubble p + p { margin-top: 8px; }
.kwe-chat-bubble ul,
.kwe-chat-bubble ol { margin: 6px 0; padding-left: 20px; }
.kwe-chat-bubble li + li { margin-top: 2px; }
.kwe-chat-bubble a { color: inherit; text-decoration: underline; }
.kwe-chat-bubble code {
  background: rgba(14, 27, 44, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'Geist Mono', ui-monospace, monospace;
  font-size: 0.92em;
}
.kwe-chat-msg-user .kwe-chat-bubble code { background: rgba(255, 255, 255, 0.15); }

.kwe-chat-attr {
  font-size: 11px;
  color: var(--muted, #6b7785);
  padding: 0 4px;
  font-weight: 500;
}

/* ---------- Human-mode banner ---------- */

.kwe-chat-banner {
  background: #F4FBF6;
  border: 1px solid #BFE5C9;
  color: var(--ink, #0E1B2C);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.kwe-chat-banner-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #1E7A3A;
  box-shadow: 0 0 0 0 rgba(30, 122, 58, 0.5);
  animation: kwe-banner-pulse 1.6s ease-out infinite;
}
@keyframes kwe-banner-pulse {
  0% { box-shadow: 0 0 0 0 rgba(30, 122, 58, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(30, 122, 58, 0); }
  100% { box-shadow: 0 0 0 0 rgba(30, 122, 58, 0); }
}

/* ---------- Typing indicator ---------- */

.kwe-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}
.kwe-chat-typing .kwe-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--ink-2, #2A3848);
  opacity: 0.4;
  animation: kwe-typing 1.2s ease-in-out infinite;
}
.kwe-chat-typing .kwe-dot:nth-child(2) { animation-delay: 0.15s; }
.kwe-chat-typing .kwe-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes kwe-typing {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ---------- Callback card (server-saved confirmation) ---------- */

.kwe-chat-msg-callback { align-items: flex-start; }
.kwe-chat-callback {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: #F4FBF6;
  border: 1px solid #BFE5C9;
  border-radius: 14px;
  color: var(--ink, #0E1B2C);
  max-width: 90%;
}
.kwe-chat-callback-pending {
  background: var(--yellow-bg, #FFF4D6);
  border-color: var(--yellow-soft, #FFE7A8);
}
.kwe-chat-callback-icon {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: #DFF4E5;
  color: #1E7A3A;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.kwe-chat-callback-pending .kwe-chat-callback-icon {
  background: var(--yellow, #FFC233);
  color: var(--ink, #0E1B2C);
}
.kwe-chat-callback-title {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.1px;
}
.kwe-chat-callback-meta {
  font-size: 12px;
  color: var(--ink-2, #2A3848);
  margin-top: 2px;
}
.kwe-chat-spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(14, 27, 44, 0.2);
  border-top-color: var(--ink, #0E1B2C);
  animation: kwe-spin 0.7s linear infinite;
}
@keyframes kwe-spin { to { transform: rotate(360deg); } }

/* ---------- Scroll-to-bottom pill ---------- */

.kwe-chat-scroll-pill {
  position: absolute;
  bottom: 158px;
  left: 50%;
  transform: translate(-50%, 8px);
  background: var(--ink, #0E1B2C);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow-md, 0 4px 24px rgba(14, 27, 44, 0.12));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.22s ease;
}
.kwe-chat-scroll-pill.visible {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

/* ---------- Suggested prompts ---------- */

.kwe-chat-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 14px 8px;
}
.kwe-chat-prompts:empty { display: none; }
.kwe-chat-prompt {
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(14, 27, 44, 0.05);
  color: var(--ink-2, #2A3848);
  transition: background 0.15s ease, color 0.15s ease;
}
.kwe-chat-prompt:hover {
  background: var(--yellow-bg, #FFF4D6);
  color: var(--yellow-ink, #7A5A00);
}

/* ---------- Composer ---------- */

.kwe-chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px 8px 14px;
  border-top: 1px solid var(--line, rgba(14, 27, 44, 0.08));
  background: var(--card, #ffffff);
}
.kwe-chat-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  background: rgba(14, 27, 44, 0.04);
  border-radius: 14px;
  padding: 6px 12px;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.kwe-chat-input-wrap:focus-within {
  background: rgba(14, 27, 44, 0.06);
  box-shadow: 0 0 0 2px rgba(255, 194, 51, 0.4);
}
.kwe-chat-input {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-family: inherit;
  font-size: 14.5px;
  line-height: 1.4;
  color: var(--ink, #0E1B2C);
  padding: 6px 0;
  min-height: 24px;
  max-height: 140px;
}
.kwe-chat-input::placeholder { color: var(--muted, #6b7785); }
.kwe-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--yellow, #FFC233);
  color: var(--ink, #0E1B2C);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(255, 194, 51, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.kwe-chat-send:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(255, 194, 51, 0.5); }
.kwe-chat-send:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }

/* ---------- Footer ---------- */

.kwe-chat-footer {
  font-size: 11px;
  color: var(--muted, #6b7785);
  text-align: center;
  padding: 6px 12px 10px;
  background: var(--card, #ffffff);
  letter-spacing: 0.1px;
}
.kwe-chat-footer a { color: var(--ink, #0E1B2C); font-weight: 600; text-decoration: none; }
.kwe-chat-footer a:hover { text-decoration: underline; }

/* ---------- Unread badge on floating-cta trigger ---------- */

.fcta-trigger[data-kwe-unread="true"]::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #E5484D;
  box-shadow: 0 0 0 2px #fff;
}

/* ---------- Mobile: full-screen takeover ---------- */

@media (max-width: 767px) {
  .kwe-chat {
    inset: 0;
    right: 0;
    bottom: 0;
  }
  .kwe-chat-card {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    transform: translateY(100%);
    transition:
      transform 0.28s cubic-bezier(0.34, 1.32, 0.64, 1),
      opacity 0.2s ease,
      visibility 0s linear 0.4s;
  }
  .kwe-chat[data-open="true"] .kwe-chat-card {
    transform: translateY(0);
    visibility: visible;
    transition:
      transform 0.32s cubic-bezier(0.34, 1.32, 0.64, 1),
      opacity 0.22s ease,
      visibility 0s;
  }
  .kwe-chat-close,
  .kwe-chat-clear { width: 44px; height: 44px; }
  .kwe-chat-send { width: 44px; height: 44px; }
  .kwe-chat-scroll-pill { bottom: 170px; }
  /* iOS Safari auto-zooms when a focused input's font-size is < 16px, which
     pushes the send button off-screen. Keep the mobile input at 16px. */
  .kwe-chat-input { font-size: 16px; }
}

/* ---------- Collapse floating CTA while chat is open ---------- */

body[data-kwe-chat-open="true"] .fcta { display: none; }
