/* =========================================================================
   Krispy Clean — chat widget.
   Uses the same tokens as styles.css. Sits above the sticky mobile call bar.
   ========================================================================= */

#kc-chat {
  --kc-gap: 16px;
  --kc-bottom: calc(58px + var(--kc-gap));   /* clears the sticky call bar */
  position: fixed;
  right: var(--kc-gap);
  bottom: var(--kc-bottom);
  z-index: 95;
  font-family: var(--f-body, system-ui, sans-serif);
}
@media (min-width: 900px) {
  #kc-chat { --kc-bottom: var(--kc-gap); --kc-gap: 24px; }
}

/* before JS boots, nothing renders: avoids a flash of a closed widget */
#kc-chat:not(.kc-ready) { display: none; }

/* ------------------------------------------------------------ launcher -- */
.kc-launch {
  display: flex; align-items: center; gap: .55rem;
  margin-left: auto;
  padding: 0; width: 60px; height: 60px;
  border: 0; border-radius: 999px; cursor: pointer;
  background: var(--c-green, #1c6842); color: #fff;
  box-shadow: 0 10px 28px rgba(18,42,30,.32);
  transition: transform .18s, background .18s;
}
.kc-launch:hover { transform: translateY(-2px); background: var(--c-green-deep, #124a2e); }
.kc-launch svg { width: 27px; height: 27px; fill: currentColor; margin: auto; }
.kc-launch__dot {
  position: absolute; top: 2px; right: 2px;
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--c-red, #c91733); border: 2.5px solid #fff;
}
.kc-launch-wrap { position: relative; display: flex; justify-content: flex-end; }

/* ---------------------------------------------------------- teaser ------ */
.kc-teaser {
  width: min(295px, calc(100vw - 2 * var(--kc-gap)));
  margin-bottom: .65rem;
  background: #fff; border: 1px solid var(--c-line, #e2e8e4);
  border-radius: 16px; box-shadow: 0 14px 34px rgba(18,42,30,.18);
  padding: .85rem .9rem .9rem;
  animation: kc-pop .28s ease both;
}
.kc-teaser__head {
  display: flex; align-items: flex-start; gap: .5rem; margin-bottom: .6rem;
}
.kc-teaser__head p {
  margin: 0; font-size: .875rem; line-height: 1.45; color: var(--c-ink, #1b2420);
}
.kc-teaser__close {
  margin-left: auto; flex: none; width: 26px; height: 26px; padding: 0;
  border: 0; background: none; cursor: pointer; border-radius: 50%;
  color: var(--c-muted, #6f7a74); font-size: 17px; line-height: 1;
}
.kc-teaser__close:hover { background: var(--c-cream-deep, #eef3f0); color: var(--c-ink, #1b2420); }
.kc-teaser__chips { display: flex; flex-direction: column; gap: .4rem; }

@keyframes kc-pop { from { opacity: 0; transform: translateY(8px) scale(.97); } }

/* -------------------------------------------------------------- chips --- */
.kc-chip {
  display: block; width: 100%; text-align: left;
  font: inherit; font-size: .84rem; line-height: 1.4;
  padding: .55rem .8rem; cursor: pointer;
  background: var(--c-green-soft, #e8f1ec);
  color: var(--c-green-deep, #124a2e);
  border: 1px solid transparent; border-radius: 999px;
  transition: background .15s, border-color .15s;
}
.kc-chip:hover { background: #fff; border-color: var(--c-green, #1c6842); }

/* -------------------------------------------------------------- panel --- */
.kc-panel {
  display: none; flex-direction: column;
  width: min(378px, calc(100vw - 2 * var(--kc-gap)));
  height: min(600px, calc(100vh - var(--kc-bottom) - var(--kc-gap) - 8px));
  background: #fff;
  border-radius: 18px; overflow: hidden;
  box-shadow: 0 26px 64px rgba(18,42,30,.32);
  border: 1px solid var(--c-line, #e2e8e4);
}
#kc-chat.is-open .kc-panel { display: flex; animation: kc-pop .22s ease both; }
#kc-chat.is-open .kc-launch-wrap,
#kc-chat.is-open .kc-teaser { display: none; }

/* full-height sheet on phones */
@media (max-width: 559px) {
  #kc-chat.is-open {
    inset: 0; right: 0; bottom: 0;
    --kc-gap: 0px;
  }
  #kc-chat.is-open .kc-panel {
    width: 100vw; height: 100dvh; border-radius: 0; border: 0;
  }
}

.kc-head {
  display: flex; align-items: center; gap: .65rem;
  padding: .8rem .9rem; flex: none;
  background: var(--c-green, #1c6842); color: #fff;
}
.kc-head__avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: #fff; display: grid; place-items: center; overflow: hidden;
}
.kc-head__avatar img { width: 32px; height: auto; }
.kc-head__txt { min-width: 0; }
.kc-head__txt strong {
  display: block; color: #fff; font-family: var(--f-head, inherit);
  font-size: .98rem; font-weight: 600; line-height: 1.2;
}
.kc-head__txt span {
  display: flex; align-items: center; gap: .35rem;
  font-size: .76rem; color: rgba(255,255,255,.82);
}
.kc-head__txt span::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: #7ee2a8;
}
.kc-head__close {
  margin-left: auto; flex: none;
  width: 36px; height: 36px; padding: 0; cursor: pointer;
  background: rgba(255,255,255,.14); border: 0; border-radius: 50%; color: #fff;
}
.kc-head__close:hover { background: rgba(255,255,255,.26); }
.kc-head__close svg { width: 17px; height: 17px; fill: currentColor; margin: auto; }

/* --------------------------------------------------------------- log ---- */
.kc-log {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 1rem .9rem; background: var(--c-cream, #f6f9f7);
  display: flex; flex-direction: column; gap: .6rem;
}
.kc-msg {
  max-width: 85%; padding: .65rem .85rem;
  font-size: .89rem; line-height: 1.55;
  border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.kc-msg a { color: inherit; text-decoration: underline; }
.kc-msg--bot {
  align-self: flex-start; background: #fff; color: var(--c-ink, #1b2420);
  border: 1px solid var(--c-line, #e2e8e4); border-bottom-left-radius: 5px;
}
.kc-msg--me {
  align-self: flex-end; background: var(--c-green, #1c6842); color: #fff;
  border-bottom-right-radius: 5px;
}
.kc-msg--err {
  align-self: flex-start; background: var(--c-red-soft, #fdeaed);
  color: var(--c-red-deep, #a5112a);
  border: 1px solid var(--c-red, #c91733); border-bottom-left-radius: 5px;
}

/* inline CTA the assistant can surface */
.kc-cta { align-self: flex-start; display: flex; flex-wrap: wrap; gap: .4rem; max-width: 92%; }
.kc-cta a {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .84rem; font-weight: 600; text-decoration: none;
  padding: .55rem .9rem; border-radius: 999px;
}
.kc-cta a svg { width: 15px; height: 15px; fill: currentColor; }
.kc-cta__call  { background: var(--c-red, #c91733); color: #fff; }
.kc-cta__quote { background: #fff; color: var(--c-green-deep, #124a2e); border: 1.5px solid var(--c-green, #1c6842); }

/* typing indicator */
.kc-typing { align-self: flex-start; display: flex; gap: 4px; padding: .75rem .9rem;
  background: #fff; border: 1px solid var(--c-line, #e2e8e4);
  border-radius: 16px; border-bottom-left-radius: 5px; }
.kc-typing i {
  width: 6px; height: 6px; border-radius: 50%; background: #9aa8a1;
  animation: kc-blink 1.3s infinite both;
}
.kc-typing i:nth-child(2) { animation-delay: .18s; }
.kc-typing i:nth-child(3) { animation-delay: .36s; }
@keyframes kc-blink { 0%, 60%, 100% { opacity: .28; } 30% { opacity: 1; } }

/* starter chips inside the log */
.kc-starters { display: flex; flex-direction: column; gap: .4rem; margin-top: .2rem; }

/* ------------------------------------------------------------- compose -- */
.kc-compose {
  flex: none; border-top: 1px solid var(--c-line, #e2e8e4); background: #fff;
  padding: .6rem .6rem .45rem;
  padding-bottom: calc(.45rem + env(safe-area-inset-bottom));
}
.kc-compose__row { display: flex; align-items: flex-end; gap: .45rem; }
.kc-compose textarea {
  flex: 1; font: inherit; font-size: .9rem; line-height: 1.45;
  padding: .6rem .75rem; max-height: 120px; min-height: 44px;
  border: 1.5px solid var(--c-line, #e2e8e4); border-radius: 14px;
  resize: none; color: var(--c-ink, #1b2420); background: #fff;
}
.kc-compose textarea:focus {
  outline: none; border-color: var(--c-green, #1c6842);
  box-shadow: 0 0 0 3px rgba(28,104,66,.14);
}
.kc-send {
  flex: none; width: 44px; height: 44px; padding: 0; cursor: pointer;
  border: 0; border-radius: 50%;
  background: var(--c-green, #1c6842); color: #fff;
}
.kc-send:disabled { opacity: .4; cursor: default; }
.kc-send svg { width: 19px; height: 19px; fill: currentColor; margin: auto; }
.kc-foot {
  margin: .4rem 0 0; text-align: center;
  font-size: .68rem; color: var(--c-muted, #6f7a74);
}
.kc-foot a { color: inherit; text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  .kc-teaser, #kc-chat.is-open .kc-panel { animation: none; }
  .kc-typing i { animation: none; opacity: .6; }
  .kc-launch:hover { transform: none; }
}
