/* Прошка — помощник на сайте (assets/widget.js).
   Компьютер: кнопка и окно в правом нижнем углу. Телефон: окно на весь экран, высота
   следует за клавиатурой (--pw-vh ставит скрипт по visualViewport). */

.pw {
  --pw-ink: var(--ink, #0d1220);
  --pw-line: var(--line, #dee3eb);
  --pw-muted: var(--muted, #5c6675);
  --pw-brand: var(--brand, #2b8cff);
  --pw-signal: var(--signal, #ff7a18);
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 70;
  font-family: var(--body, "Manrope", system-ui, sans-serif);
  color: var(--text, #0d1220);
}

.pw [hidden] {
  display: none !important;
}

/* --- Кнопка-персонаж ------------------------------------------------------- */

.pw__launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  background: var(--pw-ink);
  box-shadow: 0 14px 34px -12px rgba(13, 18, 32, 0.55), 0 0 0 0 rgba(43, 140, 255, 0.45);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  animation: pw-float 4.5s ease-in-out infinite;
}

.pw__launcher:hover {
  transform: translateY(-2px) scale(1.04);
}

.pw__launcher:focus-visible,
.pw__close:focus-visible,
.pw__send:focus-visible,
.pw__chip:focus-visible,
.pw__act:focus-visible {
  outline: 2px solid var(--pw-brand);
  outline-offset: 2px;
}

.pw__dot {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--pw-signal);
}

/* Лицо: фирменные четыре квадрата, в двух верхних — глаза */
.pw-face {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, 14px);
  grid-template-rows: repeat(2, 14px);
  gap: 3px;
}

.pw-face i {
  position: relative;
  border-radius: 4px;
}

.pw-face i:nth-child(1) { background: var(--pw-brand); }
.pw-face i:nth-child(2) { background: var(--wb, #cb11ab); }
.pw-face i:nth-child(3) { background: var(--oz, #2a1fc9); }
.pw-face i:nth-child(4) { background: var(--pw-signal); }

.pw-face i:nth-child(1)::after,
.pw-face i:nth-child(2)::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 6px;
  margin: -3px 0 0 -2.5px;
  border-radius: 3px;
  background: #fff;
  transform-origin: center;
  animation: pw-blink 5s infinite;
}

.pw-face--sm {
  grid-template-columns: repeat(2, 9px);
  grid-template-rows: repeat(2, 9px);
  gap: 2px;
}

.pw-face--sm i {
  border-radius: 2.5px;
}

.pw-face--sm i:nth-child(1)::after,
.pw-face--sm i:nth-child(2)::after {
  width: 3px;
  height: 4px;
  margin: -2px 0 0 -1.5px;
}

.pw.is-busy .pw-face i:nth-child(n)::after {
  animation: pw-look 0.9s ease-in-out infinite;
}

/* --- Мысль-облачко у кнопки ---------------------------------------------------
   Облако и «пузырьки» — белые фигуры без рамок, общая тень (drop-shadow) у обёртки:
   так они сливаются в один силуэт облака. */

.pw__thought {
  --pw-tag: var(--pw-brand);
  position: absolute;
  right: 6px;
  bottom: 96px;
  width: max-content;
  max-width: min(280px, calc(100vw - 40px));
  filter: drop-shadow(0 14px 22px rgba(13, 18, 32, 0.16)) drop-shadow(0 2px 4px rgba(13, 18, 32, 0.08));
  cursor: pointer;
}

.pw__thought[data-kind="tip"] { --pw-tag: #14935b; }
.pw__thought[data-kind="idea"],
.pw__thought[data-kind="hello"] { --pw-tag: var(--pw-signal); }

.pw__cloud {
  position: relative;
  display: grid;
  gap: 4px;
  padding: 14px 34px 15px 18px;
  border-radius: 26px;
  background: #fff;
  font-size: 14px;
  line-height: 1.42;
  animation: pw-cloud 0.42s cubic-bezier(0.2, 0.9, 0.3, 1.2) 0.16s both;
}

/* Бугорки сверху — силуэт облака */
.pw__cloud::before,
.pw__cloud::after {
  content: "";
  position: absolute;
  z-index: -1;
  border-radius: 50%;
  background: #fff;
}

.pw__cloud::before {
  top: -13px;
  left: 20px;
  width: 46px;
  height: 46px;
}

.pw__cloud::after {
  top: -8px;
  left: 56px;
  width: 34px;
  height: 34px;
}

.pw__tag {
  color: var(--pw-tag);
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.pw__ttext {
  color: var(--text, #0d1220);
}

.pw__thought-x {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--pw-muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.pw__thought-x:hover {
  background: var(--paper, #f1f3f7);
  color: var(--text, #0d1220);
}

/* Пузырьки от облака к Прошке */
.pw__puff {
  position: absolute;
  border-radius: 50%;
  background: #fff;
  animation: pw-puff 0.3s ease-out both;
}

.pw__puff--1 {
  right: 34px;
  bottom: -20px;
  width: 15px;
  height: 15px;
  animation-delay: 0.08s;
}

.pw__puff--2 {
  right: 24px;
  bottom: -33px;
  width: 9px;
  height: 9px;
}

.pw__thought.is-out {
  animation: pw-cloud-out 0.26s ease-in both;
}

/* --- Окно ----------------------------------------------------------------- */

.pw__panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  display: flex;
  flex-direction: column;
  width: 380px;
  height: min(600px, calc(100vh - 120px));
  height: min(600px, calc(100dvh - 120px));
  overflow: hidden;
  border: 1px solid var(--pw-line);
  border-radius: var(--radius-lg, 22px);
  background: var(--paper, #f1f3f7);
  box-shadow: 0 30px 70px -24px rgba(13, 18, 32, 0.45);
  animation: pw-in 0.22s ease-out;
}

.pw__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  background: var(--pw-ink);
  color: #fff;
}

.pw__avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.08);
}

.pw__title {
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}

.pw__name {
  display: block;
  font-family: var(--display, system-ui, sans-serif);
  font-size: 15px;
  font-weight: 600;
}

.pw__sub {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.66);
}

.pw__sub::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2fd27a;
}

.pw__close {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  cursor: pointer;
}

.pw__close:hover {
  background: rgba(255, 255, 255, 0.16);
}

.pw__thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.pw__msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.pw__msg--bot {
  align-self: flex-start;
  border: 1px solid var(--pw-line);
  border-bottom-left-radius: 5px;
  background: #fff;
}

.pw__msg--user {
  align-self: flex-end;
  border-bottom-right-radius: 5px;
  background: var(--pw-ink);
  color: #fff;
}

.pw__msg a {
  color: var(--pw-brand);
}

.pw__typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.pw__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pw-muted);
  animation: pw-dot 1.1s infinite;
}

.pw__typing span:nth-child(2) { animation-delay: 0.15s; }
.pw__typing span:nth-child(3) { animation-delay: 0.3s; }

.pw__acts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-self: flex-start;
  max-width: 100%;
}

.pw__act,
.pw__chip {
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid rgba(13, 18, 32, 0.16);
  border-radius: 999px;
  background: #fff;
  color: var(--text, #0d1220);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.pw__act:hover,
.pw__chip:hover {
  border-color: var(--pw-brand);
}

.pw__act--primary {
  border-color: var(--pw-ink);
  background: var(--pw-ink);
  color: #fff;
}

.pw__act--primary:hover {
  background: #1f2a42;
}

.pw__act:disabled {
  opacity: 0.5;
  cursor: default;
}

.pw__chips {
  display: flex;
  gap: 6px;
  padding: 0 14px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}

.pw__chips::-webkit-scrollbar {
  display: none;
}

.pw__chip {
  flex: none;
  font-weight: 500;
}

.pw__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--pw-line);
  background: #fff;
}

.pw__input {
  flex: 1;
  min-width: 0;
  max-height: 120px;
  padding: 10px 14px;
  border: 1px solid var(--pw-line);
  border-radius: 14px;
  background: var(--paper, #f1f3f7);
  color: inherit;
  font: inherit;
  /* 16px — чтобы iPhone не увеличивал страницу при фокусе */
  font-size: 16px;
  line-height: 1.35;
  resize: none;
}

.pw__input:focus {
  outline: none;
  border-color: var(--pw-brand);
  background: #fff;
}

.pw__send {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: var(--pw-ink);
  color: #fff;
  cursor: pointer;
}

.pw__send:disabled {
  opacity: 0.35;
  cursor: default;
}

.pw__foot {
  margin: 0;
  padding: 0 14px 8px;
  background: #fff;
  font-size: 11.5px;
  color: var(--pw-muted);
  text-align: center;
}

/* --- Телефон: окно на весь экран -------------------------------------------- */

@media (max-width: 640px) {
  .pw {
    right: max(14px, env(safe-area-inset-right));
    bottom: max(14px, env(safe-area-inset-bottom));
  }

  .pw__launcher {
    width: 56px;
    height: 56px;
    border-radius: 18px;
  }

  .pw.is-open .pw__launcher,
  .pw.is-open .pw__thought {
    display: none;
  }

  .pw__thought {
    right: 2px;
    bottom: 90px;
    max-width: min(250px, calc(100vw - 32px));
  }

  .pw__cloud {
    padding: 12px 32px 13px 15px;
    font-size: 13px;
  }

  .pw__panel {
    position: fixed;
    inset: 0 0 auto 0;
    width: 100%;
    height: var(--pw-vh, 100dvh);
    border: 0;
    border-radius: 0;
    animation: pw-up 0.24s ease-out;
  }

  .pw__head {
    padding-top: max(14px, env(safe-area-inset-top));
  }

  .pw__msg {
    max-width: 90%;
  }
}

/* Пока окно открыто на телефоне, страница под ним не прокручивается */
html.pw-lock,
html.pw-lock body {
  overflow: hidden;
}

/* --- Движение --------------------------------------------------------------- */

@keyframes pw-float {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -4px; }
}

@keyframes pw-blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

@keyframes pw-look {
  0%, 100% { translate: -1px 0; }
  50% { translate: 1px 0; }
}

@keyframes pw-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes pw-up {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: none; opacity: 1; }
}

@keyframes pw-puff {
  from { opacity: 0; transform: scale(0); }
  to { opacity: 1; transform: none; }
}

@keyframes pw-cloud {
  from { opacity: 0; transform: translateY(8px) scale(0.85); transform-origin: 85% 100%; }
  to { opacity: 1; transform: none; }
}

@keyframes pw-cloud-out {
  to { opacity: 0; transform: translateY(6px) scale(0.94); }
}

@keyframes pw-dot {
  0%, 60%, 100% { opacity: 0.3; transform: none; }
  30% { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .pw__launcher,
  .pw__panel,
  .pw__cloud,
  .pw__puff,
  .pw__thought.is-out,
  .pw-face i::after,
  .pw__typing span {
    animation: none !important;
  }
}

@media print {
  .pw {
    display: none;
  }
}
