/* KECA U.S.A. — product assistant widget.
 *
 * Built on the site's own tokens (--bg, --paper, --line, --surface, --tint,
 * --head-font) so it inherits any future palette change for free. Where a
 * token might not exist on an older cached page, each var() carries the
 * literal fallback from site.css.
 *
 * House style, held to deliberately: square corners (--radius is 0px), warm
 * neutral greys, Montserrat uppercase micro-labels at .2em tracking, Nunito
 * Sans for reading text, one accent — near-black. No colour, no gradients,
 * no bouncing bubble.
 */

.keca-ai {
  --ka-bg: var(--bg, #f7f5f2);
  --ka-step: var(--bg-step, #ece8e3);
  --ka-surface: var(--surface, #ffffff);
  --ka-ink: var(--paper, #1c1b1b);
  --ka-soft: var(--paper-soft, rgba(28, 27, 27, .78));
  --ka-muted: var(--paper-muted, #6a6a6a);
  --ka-line: var(--line, #d6d4d2);
  --ka-tint: var(--tint, #efece7);
  --ka-head: var(--head-font, 'Montserrat', -apple-system, sans-serif);
  --ka-body: 'Nunito Sans', -apple-system, 'Segoe UI', sans-serif;
}

/* ---------- launcher ---------- */

.keca-ai-launch {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 80;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  background: var(--ka-ink);
  color: #fff;
  border: 1px solid var(--ka-ink);
  border-radius: 0;
  font-family: var(--ka-head);
  font-size: .6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .18em;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(28, 27, 27, .16);
  transition: background .2s ease, transform .2s ease;
}

.keca-ai-launch:hover { background: #000; }
.keca-ai-launch:focus-visible { outline: 2px solid var(--ka-ink); outline-offset: 3px; }
.keca-ai-launch[hidden] { display: none; }

.keca-ai-launch .ka-mark {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #fff;
  flex: 0 0 auto;
}

/* The product pages carry a fixed .mobile-cta bar (z-index 70) below 760px.
 * Sit above it rather than on top of it. */
@media (max-width: 760px) {
  body.has-mcta .keca-ai-launch {
    bottom: calc(72px + env(safe-area-inset-bottom));
  }
}

/* ---------- panel ---------- */

.keca-ai-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 90;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  background: var(--ka-surface);
  border: 1px solid var(--ka-line);
  border-radius: 0;
  box-shadow: 0 18px 48px rgba(28, 27, 27, .18);
  font-family: var(--ka-body);
  color: var(--ka-ink);
  overflow: hidden;
}

.keca-ai-panel[hidden] { display: none; }

.keca-ai-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 14px;
  background: var(--ka-bg);
  border-bottom: 1px solid var(--ka-line);
}

.keca-ai-head .ka-title {
  font-family: var(--ka-head);
  font-size: .6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .16em;
  color: var(--ka-ink);
  margin: 0;
}

.keca-ai-head .ka-sub {
  display: block;
  margin-top: 4px;
  font-family: var(--ka-body);
  font-size: .75rem;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ka-muted);
}

.keca-ai-close {
  margin-left: auto;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 0;
  color: var(--ka-muted);
  font-size: 1.125rem;
  line-height: 1;
  cursor: pointer;
}

.keca-ai-close:hover { color: var(--ka-ink); border-color: var(--ka-line); }
.keca-ai-close:focus-visible { outline: 2px solid var(--ka-ink); outline-offset: 2px; }

/* ---------- transcript ---------- */

.keca-ai-log {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  -webkit-overflow-scrolling: touch;
}

.keca-ai-msg { font-size: .875rem; line-height: 1.6; }

.keca-ai-msg.user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--ka-step);
  border: 1px solid var(--ka-line);
  padding: 10px 13px;
  color: var(--ka-ink);
}

.keca-ai-msg.bot {
  align-self: stretch;
  border-left: 2px solid var(--ka-ink);
  padding-left: 13px;
  color: var(--ka-soft);
}

.keca-ai-msg.bot p { margin: 0 0 10px; }
.keca-ai-msg.bot p:last-child { margin-bottom: 0; }

.keca-ai-msg .ka-who {
  display: block;
  font-family: var(--ka-head);
  font-size: .5625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .18em;
  color: var(--ka-muted);
  margin-bottom: 6px;
}

/* ---------- cited product cards ---------- */

.keca-ai-cites {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-top: 12px;
  background: var(--ka-line);
  border: 1px solid var(--ka-line);
}

.keca-ai-cite {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--ka-surface);
  text-decoration: none;
  color: var(--ka-ink);
  transition: background .15s ease;
}

.keca-ai-cite:hover { background: var(--ka-tint); }
.keca-ai-cite:focus-visible { outline: 2px solid var(--ka-ink); outline-offset: -2px; }

.keca-ai-cite .ka-cite-name {
  font-family: var(--ka-head);
  font-size: .75rem;
  font-weight: 500;
  letter-spacing: .04em;
}

.keca-ai-cite .ka-cite-go {
  margin-left: auto;
  color: var(--ka-muted);
  font-size: .875rem;
}

/* ---------- thinking ---------- */

.keca-ai-wait {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  padding-left: 15px;
}

.keca-ai-wait span {
  width: 5px;
  height: 5px;
  background: var(--ka-muted);
  animation: keca-ai-pulse 1.1s ease-in-out infinite;
}

.keca-ai-wait span:nth-child(2) { animation-delay: .16s; }
.keca-ai-wait span:nth-child(3) { animation-delay: .32s; }

@keyframes keca-ai-pulse {
  0%, 100% { opacity: .25; }
  50% { opacity: 1; }
}

/* ---------- composer ---------- */

.keca-ai-form {
  flex: 0 0 auto;
  border-top: 1px solid var(--ka-line);
  padding: 12px 12px 10px;
  background: var(--ka-surface);
}

.keca-ai-row { display: flex; gap: 8px; align-items: flex-end; }

.keca-ai-input {
  flex: 1 1 auto;
  min-height: 46px;
  max-height: 120px;
  resize: none;
  padding: 11px 12px;
  border: 1px solid var(--ka-line);
  border-radius: 0;
  background: var(--ka-surface);
  color: var(--ka-ink);
  font-family: var(--ka-body);
  font-size: .875rem;
  line-height: 1.45;
}

.keca-ai-input:focus { outline: none; border-color: var(--ka-ink); }
.keca-ai-input::placeholder { color: var(--ka-muted); }

.keca-ai-send {
  flex: 0 0 auto;
  padding: 13px 18px;
  background: var(--ka-ink);
  color: #fff;
  border: 1px solid var(--ka-ink);
  border-radius: 0;
  font-family: var(--ka-head);
  font-size: .625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .16em;
  line-height: 1;
  cursor: pointer;
}

.keca-ai-send:hover:not(:disabled) { background: #000; }
.keca-ai-send:disabled { opacity: .4; cursor: default; }
.keca-ai-send:focus-visible { outline: 2px solid var(--ka-ink); outline-offset: 2px; }

.keca-ai-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-top: 10px;
}

.keca-ai-quote {
  flex: 0 0 auto;
  padding: 9px 16px;
  border: 1px solid var(--ka-ink);
  border-radius: 0;
  color: var(--ka-ink);
  background: transparent;
  text-decoration: none;
  font-family: var(--ka-head);
  font-size: .5625rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .16em;
  transition: background .2s ease, color .2s ease;
}

.keca-ai-quote:hover { background: var(--ka-ink); color: #fff; }
.keca-ai-quote:focus-visible { outline: 2px solid var(--ka-ink); outline-offset: 2px; }
.keca-ai-quote.secondary { border-color: #247a46; color: #247a46; }
.keca-ai-quote.secondary:hover { background: #247a46; color: #fff; }

/* Its own line. Squeezed beside the button in a 380px panel it wrapped to two
 * ragged fragments and read as clutter rather than as fine print. */
.keca-ai-note {
  flex: 1 1 100%;
  margin: 0;
  font-size: .625rem;
  line-height: 1.45;
  color: var(--ka-muted);
}

/* ---------- suggestions ---------- */

.keca-ai-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }

.keca-ai-chip {
  padding: 7px 11px;
  border: 1px solid var(--ka-line);
  border-radius: 0;
  background: var(--ka-surface);
  color: var(--ka-soft);
  font-family: var(--ka-body);
  font-size: .75rem;
  cursor: pointer;
  text-align: left;
}

.keca-ai-chip:hover { border-color: var(--ka-ink); color: var(--ka-ink); }
.keca-ai-chip:focus-visible { outline: 2px solid var(--ka-ink); outline-offset: 2px; }

/* ---------- mobile: full-screen sheet ---------- */

@media (max-width: 640px) {
  .keca-ai-panel {
    right: 0;
    left: 0;
    top: 0;
    bottom: 0;
    width: auto;
    height: auto;
    max-width: none;
    max-height: none;
    border: none;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .keca-ai-launch {
    right: 16px;
    padding: 13px 18px;
    font-size: .625rem;
    letter-spacing: .14em;
  }
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .keca-ai-launch,
  .keca-ai-cite,
  .keca-ai-quote,
  .keca-ai-send { transition: none; }
  .keca-ai-wait span { animation: none; opacity: .6; }
}

/* ---------- print ---------- */

@media print {
  .keca-ai-launch, .keca-ai-panel { display: none !important; }
}
