/* Kurash AI — saytdagi "qushcha" yordamchi */
.kb {
  --kb-primary: #F5A83C;
  --kb-primary-dark: #E0932A;
  --kb-soft: #FCEBD0;
  --kb-ink: #2D2A26;
  --kb-ink-2: #6F6A61;
  --kb-line: #EAE4D8;
  --kb-bg: #FBF7F0;
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--kb-ink);
  -webkit-font-smoothing: antialiased;
}
.kb *, .kb *::before, .kb *::after { box-sizing: border-box; }
.kb [hidden] { display: none !important; }
.kb button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- floating bird ---------- */
.kb-fab {
  position: relative;
  width: 68px;
  height: 68px;
  padding: 6px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 12px 30px rgba(224, 147, 42, .28), 0 2px 6px rgba(45, 42, 38, .08);
  display: grid;
  place-items: center;
  transition: transform .25s cubic-bezier(.2, .8, .2, 1), box-shadow .25s;
  animation: kb-bob 3.2s ease-in-out infinite;
}
.kb-fab::after {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  border: 2px solid var(--kb-primary);
  opacity: 0;
  animation: kb-ring 3.2s ease-out infinite;
  pointer-events: none;
}
.kb-fab:hover { transform: translateY(-3px) scale(1.05); box-shadow: 0 16px 36px rgba(224, 147, 42, .36); }
.kb-fab:focus-visible { outline: 3px solid var(--kb-primary); outline-offset: 3px; }
.kb--open .kb-fab { animation: none; }
.kb--open .kb-fab::after { display: none; }
.kb-bird { width: 100%; height: 100%; overflow: visible; }
.kb-shadow { fill: rgba(45, 42, 38, .12); }
.kb-tuft { fill: var(--kb-primary-dark); }
.kb-wing { transform-origin: 24px 30px; animation: kb-flap 3.2s ease-in-out infinite; }
.kb-eye { transform-origin: 39px 26px; animation: kb-blink 4.5s infinite; }
.kb-spark { transform-origin: 54px 10px; animation: kb-spark 2.4s ease-in-out infinite; }
.kb-fab:hover .kb-wing { animation-duration: .5s; }

@keyframes kb-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes kb-ring { 0% { opacity: .55; transform: scale(.9); } 60%, 100% { opacity: 0; transform: scale(1.25); } }
@keyframes kb-flap { 0%, 70%, 100% { transform: rotate(0); } 78% { transform: rotate(-16deg); } 86% { transform: rotate(4deg); } 92% { transform: rotate(-10deg); } }
@keyframes kb-blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(.1); } }
@keyframes kb-spark { 0%, 100% { opacity: .2; transform: scale(.6) rotate(0); } 50% { opacity: 1; transform: scale(1) rotate(45deg); } }

/* ---------- greeting bubble ---------- */
.kb-bubble {
  position: absolute;
  right: 6px;
  bottom: 84px;
  display: flex;
  align-items: flex-start;
  gap: 4px;
  width: max-content;
  max-width: min(260px, calc(100vw - 40px));
  padding: 12px 8px 12px 16px;
  background: #fff;
  border: 1px solid var(--kb-line);
  border-radius: 18px 18px 6px 18px;
  box-shadow: 0 14px 34px rgba(45, 42, 38, .14);
  transform-origin: bottom right;
  animation: kb-pop .45s cubic-bezier(.2, .9, .3, 1.3) both;
}
.kb-bubble::after {
  content: '';
  position: absolute;
  right: 22px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-right: 1px solid var(--kb-line);
  border-bottom: 1px solid var(--kb-line);
  transform: rotate(45deg);
}
.kb-bubble__text {
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.35;
}
.kb-bubble__x {
  flex: none;
  width: 24px;
  height: 24px;
  margin-top: -4px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--kb-ink-2) !important;
  font-size: 18px;
  line-height: 1;
}
.kb-bubble__x:hover { background: var(--kb-bg); }
@keyframes kb-pop { from { opacity: 0; transform: translateY(10px) scale(.9); } to { opacity: 1; transform: none; } }

/* ---------- chat panel ---------- */
.kb-panel {
  position: absolute;
  right: 0;
  bottom: 84px;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: min(540px, calc(100vh - 130px));
  height: min(540px, calc(100dvh - 130px));
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--kb-line);
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(45, 42, 38, .18);
  overflow: hidden;
  transform-origin: bottom right;
  animation: kb-open .32s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes kb-open { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }

.kb-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  background: linear-gradient(135deg, #FCEBD0 0%, #FFF6E8 100%);
  border-bottom: 1px solid var(--kb-line);
}
.kb-avatar {
  flex: none;
  width: 42px;
  height: 42px;
  padding: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 4px 12px rgba(224, 147, 42, .2);
}
.kb-avatar .kb-shadow, .kb-avatar .kb-spark { display: none; }
.kb-head__text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.kb-title { font-size: 16px; font-weight: 800; }
.kb-left { font-size: 13px; color: var(--kb-ink-2); font-weight: 600; }
.kb-close {
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .7);
  font-size: 22px;
  line-height: 1;
  transition: background .2s;
}
.kb-close:hover { background: #fff; }

.kb-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--kb-bg);
  overscroll-behavior: contain;
}
.kb-msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: kb-msg .28s ease-out both;
}
.kb-msg--bot { align-self: flex-start; background: #fff; border: 1px solid var(--kb-line); border-bottom-left-radius: 6px; }
.kb-msg--user { align-self: flex-end; background: var(--kb-primary); color: #fff; font-weight: 600; border-bottom-right-radius: 6px; }
.kb-msg--err { background: #FFF1EE; border-color: #F6CFC6; color: #9A3B28; }
@keyframes kb-msg { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.kb-typing { display: flex; gap: 5px; padding: 14px 16px; }
.kb-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--kb-primary);
  animation: kb-dot 1s ease-in-out infinite;
}
.kb-typing i:nth-child(2) { animation-delay: .15s; }
.kb-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes kb-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

.kb-sugg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 10px;
  background: var(--kb-bg);
}
.kb-sugg:empty { display: none; }
.kb-chip {
  padding: 7px 12px;
  border: 1px solid #F3D3A4;
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
  font-weight: 700;
  color: var(--kb-primary-dark) !important;
  transition: background .2s, transform .2s;
}
.kb-chip:hover { background: var(--kb-soft); transform: translateY(-1px); }

.kb-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--kb-line);
  background: #fff;
}
.kb-input {
  flex: 1;
  min-width: 0;
  height: 46px;
  padding: 0 16px;
  border: 1px solid var(--kb-line);
  border-radius: 999px;
  background: var(--kb-bg);
  font: inherit;
  font-size: 16px; /* iOS: no zoom on focus */
  color: var(--kb-ink);
  outline: none;
  transition: border-color .2s, background .2s;
}
.kb-input:focus { border-color: var(--kb-primary); background: #fff; }
.kb-send {
  flex: none;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 50%;
  background: var(--kb-primary);
  display: grid;
  place-items: center;
  transition: background .2s, transform .2s;
}
.kb-send:hover { background: var(--kb-primary-dark); transform: scale(1.05); }
.kb-send svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- download call-to-action (after 2 questions) ---------- */
.kb-cta {
  padding: 16px;
  border-top: 1px solid var(--kb-line);
  background: linear-gradient(135deg, #FCEBD0 0%, #FFF6E8 100%);
  text-align: center;
  animation: kb-msg .35s ease-out both;
}
.kb-cta__title { display: block; font-size: 17px; font-weight: 800; }
.kb-cta__text { margin: 6px 0 12px; font-size: 14px; line-height: 1.45; color: var(--kb-ink-2); }
.kb-cta__btn {
  display: block;
  padding: 13px 16px;
  border-radius: 999px;
  background: var(--kb-primary);
  color: #fff !important;
  font-weight: 800;
  text-decoration: none;
  box-shadow: 0 8px 20px rgba(224, 147, 42, .3);
  transition: background .2s, transform .2s;
}
.kb-cta__btn:hover { background: var(--kb-primary-dark); transform: translateY(-1px); }
.kb-cta__link {
  display: inline-block;
  margin-top: 10px;
  font-size: 14px;
  font-weight: 700;
  color: var(--kb-primary-dark) !important;
  text-decoration: none;
}
.kb-cta__link:hover { text-decoration: underline; }

/* ---------- phones ---------- */
@media (max-width: 520px) {
  .kb { right: 14px; bottom: 14px; }
  .kb-fab { width: 60px; height: 60px; }
  .kb-bubble { bottom: 74px; }
  .kb-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 86px;
    width: auto;
    max-width: none;
    height: calc(100vh - 110px);
    height: calc(100dvh - 110px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .kb *, .kb *::before, .kb *::after { animation: none !important; transition: none !important; }
}
