:root {
  --kcai-navy: #05264f;
  --kcai-navy-2: #031d3e;
  --kcai-blue: #1485f7;
  --kcai-cyan: #1ecae8;
  --kcai-text: #172436;
  --kcai-muted: #6f7e91;
  --kcai-line: #e7edf4;
  --kcai-message: #f1f3f7;
  --kcai-white: #ffffff;
  --kcai-danger: #b42318;
  --kcai-shadow: 0 24px 80px rgba(1,31,66,.22), 0 8px 28px rgba(1,31,66,.11);
}

#kcai-root,
#kcai-root * { box-sizing: border-box; }

#kcai-root {
  position: fixed;
  z-index: 999999;
  right: 30px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
  width: auto;
  max-width: none;
  color: var(--kcai-text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
  text-align: left;
}

#kcai-root[data-position="left"] { right: auto; left: 30px; align-items: flex-start; }

#kcai-root button,
#kcai-root input,
#kcai-root textarea {
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
}

#kcai-root button {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
  max-width: none;
  line-height: normal;
  text-decoration: none;
}

/* ===== Panel — accepted HTML look ===== */
#kcai-root .kcai-panel {
  position: absolute;
  right: 0;
  bottom: 86px;
  width: min(446px, calc(100vw - 28px));
  height: min(663px, calc(100vh - 126px));
  min-height: 0;
  margin: 0;
  background: #fff;
  border-radius: 29px;
  overflow: hidden;
  box-shadow: var(--kcai-shadow);
  border: 1px solid rgba(5,38,79,.08);
  display: grid;
  grid-template-rows: 98px minmax(0,1fr) auto;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px) scale(.975);
  transform-origin: bottom right;
  transition: opacity .22s ease, transform .22s ease, visibility .22s ease;
}

#kcai-root[data-position="left"] .kcai-panel {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}

#kcai-root.is-open .kcai-panel {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* ===== Header ===== */
#kcai-root .kcai-header {
  min-height: 0;
  height: 98px;
  margin: 0;
  padding: 0 20px 0 19px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: linear-gradient(135deg, var(--kcai-navy), var(--kcai-navy-2));
  color: #fff;
  position: relative;
}

#kcai-root .kcai-brand {
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 0;
  flex: 1;
}

#kcai-root .kcai-brandmark {
  width: 58px;
  height: 58px;
  min-width: 58px;
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  border: 0;
  box-shadow: 0 2px 9px rgba(0,0,0,.11);
  overflow: hidden;
}

#kcai-root .kcai-brandmark img {
  display: block;
  width: 37px;
  height: 37px;
  object-fit: contain;
  margin: 0;
  padding: 0;
}

#kcai-root .kcai-brand-copy { min-width: 0; }

#kcai-root .kcai-brand strong {
  display: block;
  margin: 0 0 8px;
  padding: 0;
  color: #fff;
  font-size: 18px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -.02em;
  white-space: nowrap;
}

#kcai-root .kcai-brand span {
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  color: #e7eef7;
  font-size: 13px;
  line-height: 1.2;
  font-weight: 400;
  white-space: nowrap;
}

#kcai-root .kcai-brand span i {
  width: 9px;
  height: 9px;
  min-width: 9px;
  border-radius: 50%;
  background: #19d57b;
  box-shadow: 0 0 0 4px rgba(25,213,123,.10), 0 0 11px rgba(25,213,123,.42);
}

#kcai-root .kcai-close {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  margin-left: 14px;
  border-radius: 50%;
  background: #fff;
  color: #173964;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
  transition: transform .16s ease, background .16s ease;
}

#kcai-root .kcai-close:hover { transform: scale(1.04); background: #f6f9fc; }
#kcai-root .kcai-close:focus-visible { outline: 3px solid rgba(30,202,232,.35); outline-offset: 2px; }

#kcai-root .kcai-close svg {
  width: 19px;
  height: 19px;
  display: block;
  fill: none;
  stroke: #173964;
  stroke-width: 2.1;
  stroke-linecap: round;
}

/* Loading line is overlaid, so it never changes the accepted layout. */
#kcai-root .kcai-progress {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  top: 97px;
  height: 2px;
  overflow: hidden;
  pointer-events: none;
  background: transparent;
}

#kcai-root .kcai-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--kcai-blue), var(--kcai-cyan));
  transition: width .2s ease;
}

#kcai-root.is-loading .kcai-progress span { animation: kcaiLoading 1.05s ease-in-out infinite; }

/* ===== Main body ===== */
#kcai-root .kcai-body {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow: hidden;
}

#kcai-root .kcai-messages {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  margin: 0;
  padding: 27px 17px 12px;
  overflow-y: auto;
  overflow-x: hidden;
  background: #fff;
  scrollbar-width: thin;
  scrollbar-color: #dce6f0 transparent;
}

#kcai-root .kcai-messages::-webkit-scrollbar { width: 7px; }
#kcai-root .kcai-messages::-webkit-scrollbar-track { background: transparent; }
#kcai-root .kcai-messages::-webkit-scrollbar-thumb { background: #dce6f0; border-radius: 20px; }

#kcai-root .kcai-row {
  width: 100%;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 0 0 14px;
  padding: 0;
  animation: kcaiIn .2s ease both;
}

#kcai-root .kcai-row-user { justify-content: flex-end; }
#kcai-root .kcai-row-bot { justify-content: flex-start; }

#kcai-root .kcai-avatar {
  width: 48px;
  height: 48px;
  min-width: 48px;
  flex: 0 0 48px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid #e6edf5;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 9px rgba(10,35,60,.05);
  overflow: hidden;
}

#kcai-root .kcai-avatar img {
  display: block;
  width: 26px;
  height: 26px;
  object-fit: contain;
  margin: 0;
  padding: 0;
}

#kcai-root .kcai-bubble {
  width: auto;
  max-width: 318px;
  margin: 0;
  padding: 17px 18px 16px;
  border: 0;
  border-radius: 24px 24px 24px 8px;
  background: var(--kcai-message);
  color: #202c3c;
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
  font-size: 14.5px;
  line-height: 1.52;
  font-weight: 400;
  overflow-wrap: anywhere;
}

#kcai-root .kcai-bubble p { margin: 0 0 10px; }
#kcai-root .kcai-bubble p:last-child { margin-bottom: 0; }
#kcai-root .kcai-bubble a { color: #0877df; text-decoration: underline; text-underline-offset: 2px; }
#kcai-root .kcai-bubble strong { color: inherit; font-weight: 800; }

#kcai-root .kcai-row-user .kcai-bubble {
  max-width: 300px;
  border-radius: 24px 24px 8px 24px;
  background: linear-gradient(135deg,#158af7,#0a74df);
  color: #fff;
}

#kcai-root .kcai-typing {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-height: 20px;
  min-width: 54px;
}

#kcai-root .kcai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8aa0b7;
  animation: kcaiDot 1s infinite ease-in-out;
}
#kcai-root .kcai-typing span:nth-child(2) { animation-delay: .12s; }
#kcai-root .kcai-typing span:nth-child(3) { animation-delay: .24s; }

/* ===== Quick actions — fixed 2 x 2, no overflow ===== */
#kcai-root .kcai-quick-wrap {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 16px 12px;
  background: #fff;
}

#kcai-root .kcai-quick {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1fr);
  gap: 9px 10px;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: visible;
  border: 0;
  background: #fff;
}

#kcai-root .kcai-quick:empty,
#kcai-root .kcai-quick-wrap:has(.kcai-quick:empty) { display: none; }

#kcai-root .kcai-quick button {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 10px 12px;
  border: 0;
  border-radius: 24px;
  background: #e8f3ff;
  color: #0764cb;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  cursor: pointer;
  font-size: 13.5px;
  line-height: 1.15;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}

#kcai-root .kcai-quick button:hover {
  transform: translateY(-1px);
  background: #dceeff;
  box-shadow: 0 5px 15px rgba(21,133,247,.10);
}

#kcai-root .kcai-quick button:focus-visible { outline: 3px solid rgba(20,133,247,.18); outline-offset: 2px; }

#kcai-root .kcai-quick button svg {
  width: 18px;
  height: 18px;
  min-width: 18px;
  flex: 0 0 18px;
  display: block;
  fill: none;
  stroke: #1183ef;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#kcai-root .kcai-quick button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Composer ===== */
#kcai-root .kcai-compose {
  margin: 0;
  padding: 15px 16px 11px;
  border: 0;
  border-top: 1px solid var(--kcai-line);
  background: #fff;
  display: block;
}

#kcai-root .kcai-input-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) 56px;
  gap: 9px;
  align-items: center;
  width: 100%;
  margin: 0;
  padding: 0;
}

#kcai-root .kcai-input-shell {
  width: 100%;
  height: 56px;
  margin: 0;
  padding: 0 18px;
  border-radius: 29px;
  border: 1px solid #d9e5ef;
  background: #fff;
  box-shadow: 0 4px 18px rgba(5,38,79,.08), inset 0 0 0 1px rgba(255,255,255,.7);
  display: flex;
  align-items: center;
  transition: border-color .15s ease, box-shadow .15s ease;
}

#kcai-root .kcai-input-shell:focus-within {
  border-color: #7ab7f8;
  box-shadow: 0 0 0 3px rgba(20,133,247,.10), 0 4px 18px rgba(5,38,79,.07);
}

#kcai-root .kcai-input-shell textarea {
  display: block;
  width: 100%;
  height: 24px;
  min-height: 24px;
  max-height: 24px;
  margin: 0;
  padding: 0;
  resize: none;
  overflow: hidden;
  border: 0 !important;
  outline: 0 !important;
  border-radius: 0;
  background: transparent !important;
  box-shadow: none !important;
  color: #25354a;
  font-size: 14px;
  line-height: 24px;
  font-weight: 400;
}

#kcai-root .kcai-input-shell textarea::placeholder { color: #8794a5; opacity: 1; }

#kcai-root .kcai-send {
  width: 56px;
  height: 56px;
  min-width: 56px;
  min-height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg,#1485f7 8%,#16c7e8 92%);
  box-shadow: 0 8px 18px rgba(17,143,229,.25);
  transition: transform .16s ease, box-shadow .16s ease;
}

#kcai-root .kcai-send:hover { transform: translateY(-1px) scale(1.025); box-shadow: 0 10px 22px rgba(17,143,229,.32); }
#kcai-root .kcai-send:disabled { opacity: .55; cursor: default; }
#kcai-root .kcai-send:focus-visible { outline: 3px solid rgba(20,133,247,.20); outline-offset: 2px; }

#kcai-root .kcai-send svg {
  width: 22px;
  height: 22px;
  display: block;
  fill: none;
  stroke: #fff;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  transform: translateX(-1px);
}

#kcai-root .kcai-footnote {
  margin: 0;
  padding: 8px 0 0;
  text-align: center;
  color: #8b98a8;
  background: #fff;
  font-size: 10.5px;
  line-height: 1.35;
  font-weight: 400;
}

/* ===== Sticky launcher — intentionally a little smaller than HTML mockup ===== */
#kcai-root .kcai-launcher {
  position: relative;
  width: 72px;
  height: 72px;
  min-width: 72px;
  min-height: 72px;
  padding: 0;
  border-radius: 50%;
  background: #fff;
  color: inherit;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 0 0 1px rgba(10,120,210,.07), 0 10px 28px rgba(0,131,233,.28), 0 0 22px rgba(26,206,233,.16);
  overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
}

#kcai-root .kcai-launcher:hover {
  transform: translateY(-2px) scale(1.025);
  box-shadow: 0 0 0 1px rgba(10,120,210,.08), 0 14px 32px rgba(0,131,233,.32), 0 0 26px rgba(26,206,233,.20);
}

#kcai-root .kcai-launcher:focus-visible { outline: 3px solid rgba(30,202,232,.35); outline-offset: 3px; }

#kcai-root .kcai-launcher img {
  display: block;
  width: 42px;
  height: 42px;
  object-fit: contain;
  margin: 0;
  padding: 0;
}

/* ===== Contact form inside messages ===== */
#kcai-root .kcai-contact-card {
  margin: 0 0 15px 58px;
  padding: 14px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid #dfe9f3;
  box-shadow: 0 8px 20px rgba(32,58,86,.06);
  animation: kcaiIn .2s ease both;
}

#kcai-root .kcai-contact-title { margin: 0 0 4px; font-size: 14px; line-height: 1.3; font-weight: 800; color: #172033; }
#kcai-root .kcai-contact-note { margin: 0 0 11px; font-size: 11px; line-height: 1.45; font-weight: 400; color: #758194; }
#kcai-root .kcai-contact-form { display: grid; gap: 9px; margin: 0; padding: 0; }
#kcai-root .kcai-contact-form label { display: grid; gap: 5px; margin: 0; color: #39465a; font-size: 11px; line-height: 1.3; font-weight: 650; }

#kcai-root .kcai-contact-form input[type="text"],
#kcai-root .kcai-contact-form textarea {
  width: 100%;
  margin: 0;
  padding: 9px 10px;
  border: 1px solid #dce4ed;
  border-radius: 11px;
  outline: none;
  background: #fbfdff;
  color: #172033;
  box-shadow: none;
  font-size: 12px;
  line-height: 1.4;
  font-weight: 400;
}

#kcai-root .kcai-contact-form textarea { resize: vertical; min-height: 74px; }
#kcai-root .kcai-contact-form input:focus,
#kcai-root .kcai-contact-form textarea:focus { border-color: #9bc9f8; box-shadow: 0 0 0 3px rgba(8,125,243,.07); }

#kcai-root .kcai-contact-form .kcai-consent { display: flex; align-items: flex-start; gap: 7px; font-weight: 450; line-height: 1.35; }
#kcai-root .kcai-contact-form .kcai-consent input { width: auto; margin: 2px 0 0; }

#kcai-root .kcai-contact-form button {
  width: 100%;
  padding: 11px 13px;
  border-radius: 14px;
  background: #05264f;
  color: #fff;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 750;
  cursor: pointer;
}
#kcai-root .kcai-contact-form button:disabled { opacity: .6; cursor: default; }
#kcai-root .kcai-form-error { font-size: 11px; line-height: 1.4; color: var(--kcai-danger); }
#kcai-root .kcai-hp { position: absolute !important; left: -10000px !important; width: 1px !important; height: 1px !important; opacity: 0 !important; pointer-events: none !important; }

#kcai-root .screen-reader-text {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0,0,0,0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@keyframes kcaiLoading {
  0% { transform: translateX(-100%); width: 42%; }
  50% { transform: translateX(85%); width: 58%; }
  100% { transform: translateX(240%); width: 42%; }
}
@keyframes kcaiIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes kcaiDot { 0%,80%,100% { opacity: .35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

@media (max-width: 760px) {
  #kcai-root { right: 12px; bottom: 14px; gap: 12px; }
  #kcai-root[data-position="left"] { left: 12px; right: auto; }

  #kcai-root .kcai-panel {
    position: fixed;
    left: 12px !important;
    right: 12px !important;
    bottom: 92px;
    width: auto;
    height: min(650px, calc(100vh - 110px));
    border-radius: 24px;
    transform-origin: bottom center;
  }

  #kcai-root .kcai-header { height: 98px; padding-left: 15px; padding-right: 15px; }
  #kcai-root .kcai-brandmark { width: 52px; height: 52px; min-width: 52px; }
  #kcai-root .kcai-brandmark img { width: 33px; height: 33px; }
  #kcai-root .kcai-brand strong { font-size: 17px; }
  #kcai-root .kcai-brand span { font-size: 12px; }
  #kcai-root .kcai-close { width: 39px; height: 39px; min-width: 39px; min-height: 39px; }

  #kcai-root .kcai-messages { padding-left: 12px; padding-right: 12px; }
  #kcai-root .kcai-avatar { width: 42px; height: 42px; min-width: 42px; flex-basis: 42px; }
  #kcai-root .kcai-avatar img { width: 23px; height: 23px; }
  #kcai-root .kcai-bubble { max-width: calc(100vw - 106px); }
  #kcai-root .kcai-row-user .kcai-bubble { max-width: calc(100vw - 74px); }

  #kcai-root .kcai-quick-wrap { padding-left: 12px; padding-right: 12px; }
  #kcai-root .kcai-quick button { min-height: 43px; padding-left: 9px; padding-right: 9px; font-size: 12.4px; }
  #kcai-root .kcai-quick button svg { width: 17px; height: 17px; min-width: 17px; flex-basis: 17px; }

  #kcai-root .kcai-compose { padding-left: 12px; padding-right: 12px; }
  #kcai-root .kcai-input-row { grid-template-columns: minmax(0,1fr) 52px; }
  #kcai-root .kcai-input-shell { height: 52px; }
  #kcai-root .kcai-send { width: 52px; height: 52px; min-width: 52px; min-height: 52px; }

  #kcai-root .kcai-launcher { width: 64px; height: 64px; min-width: 64px; min-height: 64px; }
  #kcai-root .kcai-launcher img { width: 38px; height: 38px; }
  #kcai-root .kcai-contact-card { margin-left: 52px; }
}

@media (max-width: 390px) {
  #kcai-root .kcai-panel { height: calc(100vh - 104px); }
  #kcai-root .kcai-quick { grid-template-columns: 1fr; }
  #kcai-root .kcai-quick button { justify-content: flex-start; padding-left: 18px; }
  #kcai-root .kcai-contact-card { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  #kcai-root *, #kcai-root *::before, #kcai-root *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
