/* =========================================================
   KOSI — виджет чата (кнопка + окно)
   Использует переменные из style.css (:root)
   ========================================================= */

.kosi-chat-launcher{
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9998;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--burgundy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform .22s var(--ease), background .22s var(--ease);
}
.kosi-chat-launcher:hover{ background: var(--burgundy-ink); transform: translateY(-2px) scale(1.04); }
.kosi-chat-launcher:active{ transform: scale(.96); }
.kosi-chat-launcher svg{ width: 26px; height: 26px; }
.kosi-chat-launcher .kosi-chat-launcher__icon-close{ display:none; }
.kosi-chat-launcher.is-open .kosi-chat-launcher__icon-chat{ display:none; }
.kosi-chat-launcher.is-open .kosi-chat-launcher__icon-close{ display:block; }

.kosi-chat-launcher__badge{
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--terracotta);
  color: #fff;
  font: 700 11px/20px var(--f-body);
  text-align: center;
  box-shadow: 0 0 0 2px var(--cream);
}
.kosi-chat-launcher__badge:empty{ display:none; }

.kosi-chat-launcher__pulse{
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--burgundy);
  opacity: .55;
  animation: kosi-pulse 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes kosi-pulse{
  0%{ transform: scale(1); opacity: .45; }
  100%{ transform: scale(1.7); opacity: 0; }
}
@media (prefers-reduced-motion: reduce){
  .kosi-chat-launcher__pulse{ animation: none; display:none; }
}

.kosi-chat-window{
  position: fixed;
  right: 20px;
  bottom: 92px;
  z-index: 9999;
  width: 372px;
  max-width: calc(100vw - 24px);
  height: min(600px, calc(100vh - 120px));
  background: var(--paper);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(.98);
  pointer-events: none;
  transition: opacity .2s var(--ease), transform .22s var(--ease);
  font-family: var(--f-body);
}
.kosi-chat-window.is-open{
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.kosi-chat-header{
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--burgundy);
  color: #fff;
}
.kosi-chat-header__avatar{
  width: 38px;
  height: 38px;
  border-radius: 50%;
  overflow: hidden;
  flex: 0 0 auto;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.kosi-chat-header__avatar img{ width: 100%; height: 100%; object-fit: cover; }
.kosi-chat-header__info{ flex: 1 1 auto; min-width: 0; }
.kosi-chat-header__name{
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .02em;
}
.kosi-chat-header__status{
  font-size: 12px;
  opacity: .82;
  display: flex;
  align-items: center;
  gap: 5px;
}
.kosi-chat-header__status::before{
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6FCF97;
  display: inline-block;
}
.kosi-chat-header__close{
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: none;
  background: rgba(255,255,255,.14);
  color: #fff;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .18s;
}
.kosi-chat-header__close:hover{ background: rgba(255,255,255,.26); }

.kosi-chat-body{
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(circle at 15% 8%, rgba(194,139,139,.10), transparent 45%),
    var(--cream);
  scroll-behavior: smooth;
}
.kosi-chat-body::-webkit-scrollbar{ width: 6px; }
.kosi-chat-body::-webkit-scrollbar-thumb{ background: var(--line-rose); border-radius: 999px; }

.kosi-msg{
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.48;
  white-space: pre-line;
  animation: kosi-msg-in .22s var(--ease);
}
@keyframes kosi-msg-in{
  from{ opacity: 0; transform: translateY(6px); }
  to{ opacity: 1; transform: translateY(0); }
}
.kosi-msg--bot{
  align-self: flex-start;
  background: var(--paper);
  color: var(--graphite);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.kosi-msg--user{
  align-self: flex-end;
  background: var(--burgundy);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.kosi-msg a{ color: inherit; text-decoration: underline; }
.kosi-msg--bot a{ color: var(--terracotta); font-weight: 600; }

.kosi-msg-time{
  font-size: 10px;
  color: var(--graphite-60);
  margin: -4px 4px 0;
  align-self: flex-start;
}
.kosi-msg-time--user{ align-self: flex-end; color: rgba(46,43,41,.4); }

.kosi-typing{
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.kosi-typing span{
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rose);
  animation: kosi-typing-bounce 1.1s infinite ease-in-out;
}
.kosi-typing span:nth-child(2){ animation-delay: .15s; }
.kosi-typing span:nth-child(3){ animation-delay: .3s; }
@keyframes kosi-typing-bounce{
  0%, 60%, 100%{ transform: translateY(0); opacity: .5; }
  30%{ transform: translateY(-4px); opacity: 1; }
}

.kosi-chat-quick{
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  background: var(--cream);
  border-top: 1px solid var(--line);
}
.kosi-chip{
  border: 1px solid var(--line-rose);
  background: var(--paper);
  color: var(--burgundy-ink);
  font: 500 12px/1.3 var(--f-body);
  padding: 7px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .16s, color .16s, border-color .16s;
  white-space: nowrap;
}
.kosi-chip:hover{
  background: var(--burgundy);
  border-color: var(--burgundy);
  color: #fff;
}

.kosi-chat-form{
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.kosi-chat-form textarea{
  flex: 1 1 auto;
  resize: none;
  max-height: 90px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 9px 12px;
  font: 400 13.5px/1.4 var(--f-body);
  color: var(--graphite);
  background: var(--cream);
  outline: none;
  transition: border-color .16s;
}
.kosi-chat-form textarea:focus{ border-color: var(--rose); }
.kosi-chat-form__send{
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--terracotta);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .16s, transform .16s;
}
.kosi-chat-form__send:hover{ background: var(--burgundy-ink); }
.kosi-chat-form__send:active{ transform: scale(.92); }
.kosi-chat-form__send svg{ width: 17px; height: 17px; }
.kosi-chat-form__send:disabled{ opacity: .5; cursor: default; }

.kosi-chat-note{
  flex: 0 0 auto;
  font-size: 10.5px;
  color: var(--graphite-60);
  text-align: center;
  padding: 0 12px 9px;
  background: var(--paper);
}

@media (max-width: 560px){
  .kosi-chat-window{
    right: 10px;
    left: 10px;
    bottom: 84px;
    width: auto;
    max-width: none;
    height: min(76vh, 620px);
  }
  .kosi-chat-launcher{ right: 14px; bottom: 14px; }
}

@media (max-width: 380px){
  .kosi-chat-window{ height: min(80vh, 620px); bottom: 78px; }
}
