/* =============================================
   ONEPAD — Chat widget
   Класична тематика сайту: світлий преміум-мінімалізм
   ============================================= */

.pd-chat {
  --pd-c-bg:        #FFFFFF;
  --pd-c-surface:   #FFFFFF;
  --pd-c-bg-soft:   #F5F5F7;
  --pd-c-border:    #E3E3E8;
  --pd-c-border-2:  #ECECF0;
  --pd-c-text:      #1D1D1F;
  --pd-c-text-2:    #6E6E73;
  --pd-c-text-3:    #AEAEB2;
  --pd-c-action:    #111214;
  --pd-c-action-hi: #1B1C20;
  --pd-c-online:    #28A745;
  --pd-c-shadow:    0 24px 56px rgba(0,0,0,0.16), 0 2px 8px rgba(0,0,0,0.06);
  --pd-c-radius:    24px;
  --pd-c-ease:      cubic-bezier(0.22, 1, 0.36, 1);

  position: fixed;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ────── Floating action button ────── */
.pd-chat__fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--pd-c-action);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 28px rgba(17,18,20,0.22), 0 2px 6px rgba(17,18,20,0.14);
  transition:
    transform 0.32s var(--pd-c-ease),
    box-shadow 0.32s var(--pd-c-ease),
    background 0.18s ease;
  z-index: 9999;
  will-change: transform;
  overflow: hidden;
}
.pd-chat:not(.pd-chat--open) .pd-chat__fab {
  animation: pd-chat-fab-breathe 3.2s ease-in-out infinite;
}
.pd-chat__fab:hover {
  background: var(--pd-c-action-hi);
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 18px 36px rgba(17,18,20,0.28), 0 3px 8px rgba(17,18,20,0.18);
  animation-play-state: paused;
}
.pd-chat__fab:active { transform: translateY(0) scale(0.96); }
@keyframes pd-chat-fab-breathe {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-1px) scale(1.045); }
}

.pd-chat__fab-icon {
  display: block;
  transition: transform 0.42s var(--pd-c-ease), opacity 0.22s ease;
  width: 29px;
  height: 29px;
  position: absolute;
  left: 50%;
  transform-origin: center;
}
.pd-chat__fab-icon--open {
  top: 50%;
  transform: translate(-50%, -61%) scale(1);
  opacity: 1;
}
.pd-chat__fab-icon--close {
  top: 50%;
  transform: translate(-50%, -50%) rotate(90deg) scale(0.4);
  opacity: 0;
}
.pd-chat--open .pd-chat__fab-icon--open {
  transform: translate(-50%, -61%) rotate(-90deg) scale(0.32);
  opacity: 0;
}
.pd-chat--open .pd-chat__fab-icon--close {
  transform: translate(-50%, -50%) rotate(0) scale(1);
  opacity: 1;
}
.pd-chat__fab-mini {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 7.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.9;
  line-height: 1;
  white-space: nowrap;
  text-rendering: geometricPrecision;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.pd-chat__fab-mini::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #34d26a;
  box-shadow: 0 0 0 0 rgba(52, 210, 106, 0.55);
  animation: pd-chat-mini-dot 1.9s ease-in-out infinite;
}
.pd-chat--open .pd-chat__fab-mini {
  opacity: 0;
  transform: translateY(4px);
}
@keyframes pd-chat-mini-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52, 210, 106, 0.55); }
  50%      { box-shadow: 0 0 0 5px rgba(52, 210, 106, 0); }
}

/* Idle pulse */
.pd-chat__fab::before,
.pd-chat__fab::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid var(--pd-c-action);
  opacity: 0;
  pointer-events: none;
  animation: pd-chat-pulse 3.4s ease-out infinite;
  display: block;
}
.pd-chat__fab::after { animation-delay: 1.7s; }
.pd-chat:hover .pd-chat__fab::before,
.pd-chat:hover .pd-chat__fab::after,
.pd-chat--open .pd-chat__fab::before,
.pd-chat--open .pd-chat__fab::after {
  animation-play-state: paused;
  opacity: 0;
}
@keyframes pd-chat-pulse {
  0%   { opacity: 0.32; transform: scale(1); }
  70%  { opacity: 0; transform: scale(1.38); }
  100% { opacity: 0; transform: scale(1.38); }
}

/* Unread badge */
.pd-chat__fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: #FF3B30;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px rgba(255,59,48,0.4);
  animation: pd-chat-badge-in 0.36s var(--pd-c-ease);
}
.pd-chat--has-unread .pd-chat__fab-badge { display: flex; }
@keyframes pd-chat-badge-in {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* ────── Panel ────── */
.pd-chat__panel {
  position: fixed;
  right: 22px;
  bottom: 96px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 132px);
  background: var(--pd-c-surface);
  border: 1px solid var(--pd-c-border);
  border-radius: var(--pd-c-radius);
  box-shadow: var(--pd-c-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px) scale(0.97);
  transform-origin: bottom right;
  transition:
    opacity 0.24s ease,
    transform 0.36s var(--pd-c-ease);
  z-index: 9998;
}
.pd-chat--open .pd-chat__panel {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Header — title only + close (тематика сайту) */
.pd-chat__header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--pd-c-border-2);
  background: var(--pd-c-surface);
}
.pd-chat__head-meta { flex: 1; min-width: 0; }
.pd-chat__title {
  font-size: 15px;
  font-weight: 700;
  color: var(--pd-c-text);
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.pd-chat__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--pd-c-text-2);
  margin-top: 3px;
  letter-spacing: -0.01em;
}
.pd-chat__status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--pd-c-online);
  box-shadow: 0 0 0 0 rgba(40,167,69,0.45);
  animation: pd-chat-dot 2s ease-in-out infinite;
}
@keyframes pd-chat-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(40,167,69,0.45); }
  50%      { box-shadow: 0 0 0 6px rgba(40,167,69,0); }
}
.pd-chat__close {
  border: 0;
  background: transparent;
  color: var(--pd-c-text-2);
  width: 32px;
  height: 32px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.16s ease, color 0.16s ease, transform 0.18s var(--pd-c-ease);
}
.pd-chat__close:hover { background: var(--pd-c-bg-soft); color: var(--pd-c-text); transform: rotate(90deg); }

/* Body */
.pd-chat__body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(180deg, #FCFCFD 0%, #F7F7F9 100%);
  scroll-behavior: smooth;
  position: relative;
}
.pd-chat__body::-webkit-scrollbar { width: 6px; }
.pd-chat__body::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.14); border-radius: 999px; }
.pd-chat__body::-webkit-scrollbar-track { background: transparent; }

/* Welcome state — центроване вітання, видиме коли немає повідомлень */
.pd-chat__welcome {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  pointer-events: none;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.32s ease, transform 0.4s var(--pd-c-ease);
}
.pd-chat--has-messages .pd-chat__welcome {
  opacity: 0;
  transform: translateY(-8px);
}
.pd-chat__welcome-mark {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  background: var(--pd-c-action);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.04em;
  margin-bottom: 6px;
  box-shadow: 0 10px 24px rgba(17,18,20,0.18);
  animation: none;
}
.pd-chat__welcome-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--pd-c-text);
  letter-spacing: -0.025em;
  line-height: 1.15;
  animation: none;
}
.pd-chat__welcome-sub {
  font-size: 14px;
  color: var(--pd-c-text-2);
  letter-spacing: -0.005em;
  line-height: 1.45;
  max-width: 240px;
  animation: none;
}

/* Messages — wrapper carries sender label, .pd-chat__bubble carries text+time */
.pd-chat__msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: none;
  will-change: transform, opacity;
}
.pd-chat__msg-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--pd-c-text-2);
  letter-spacing: 0.01em;
  margin: 4px 12px 4px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.pd-chat__msg-sender::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pd-c-online);
}
.pd-chat__bubble {
  padding: 10px 14px;
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pd-chat__bubble-text {
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: -0.005em;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.pd-chat__attachments {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pd-chat__attachment {
  display: block;
  text-decoration: none;
}
.pd-chat__attachment--image img {
  display: block;
  width: 100%;
  max-width: 220px;
  max-height: 240px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #f0f0f2;
}
.pd-chat__msg--client .pd-chat__attachment--image img {
  border-color: rgba(255, 255, 255, 0.2);
}
.pd-chat__msg--client {
  align-self: flex-end;
  align-items: flex-end;
}
.pd-chat__msg--client .pd-chat__bubble {
  background: var(--pd-c-action);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.pd-chat__msg--operator {
  align-self: flex-start;
  align-items: flex-start;
}
.pd-chat__msg--operator .pd-chat__bubble {
  background: var(--pd-c-surface);
  color: var(--pd-c-text);
  border: 1px solid var(--pd-c-border-2);
  border-bottom-left-radius: 6px;
}
.pd-chat__msg--system {
  align-self: center;
  align-items: center;
  max-width: 100%;
}
.pd-chat__msg--system .pd-chat__bubble {
  background: transparent;
  color: var(--pd-c-text-3);
  font-size: 12px;
  text-align: center;
  padding: 4px 0;
  border: 0;
}
.pd-chat__msg-time {
  display: block;
  font-size: 10.5px;
  color: var(--pd-c-text-3);
  margin: 4px 6px 0;
  letter-spacing: 0;
}
.pd-chat__msg--client .pd-chat__msg-time { color: var(--pd-c-text-3); }
.pd-chat__msg + .pd-chat__msg { margin-top: 2px; }
.pd-chat__msg--operator + .pd-chat__msg--client,
.pd-chat__msg--client + .pd-chat__msg--operator { margin-top: 10px; }


/* Typing indicator */
.pd-chat__typing {
  align-self: flex-start;
  background: var(--pd-c-surface);
  border: 1px solid var(--pd-c-border-2);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  padding: 10px 14px;
  display: none;
  gap: 4px;
  animation: none;
}
.pd-chat__typing.is-on { display: inline-flex; }
.pd-chat__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pd-c-text-3);
  animation: none;
}

/* Input — без поля контактів */
.pd-chat__input {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--pd-c-border-2);
  background: var(--pd-c-surface);
}
.pd-chat__picked-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--pd-c-border-2);
  background: var(--pd-c-bg-soft);
  border-radius: 12px;
  padding: 7px 10px;
}
.pd-chat__picked-file[hidden] {
  display: none !important;
}
.pd-chat__picked-file-name {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--pd-c-text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pd-chat__picked-file-remove {
  border: 0;
  background: transparent;
  color: var(--pd-c-text-2);
  width: 20px;
  height: 20px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.pd-chat__picked-file-remove:hover {
  background: #ececf0;
  color: var(--pd-c-text);
}
.pd-chat__compose {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--pd-c-bg-soft);
  border: 1px solid var(--pd-c-border-2);
  border-radius: 16px;
  padding: 8px 8px 8px 14px;
  transition: border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}
.pd-chat__compose:focus-within {
  border-color: var(--pd-c-action);
  background: var(--pd-c-surface);
  box-shadow: 0 0 0 3px rgba(17,18,20,0.06);
}
.pd-chat__attach {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--pd-c-text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, transform 0.2s var(--pd-c-ease);
}
.pd-chat__attach:hover {
  background: #ececf0;
  color: var(--pd-c-text);
  transform: translateY(-1px);
}
.pd-chat__textarea {
  flex: 1;
  border: 0;
  background: transparent;
  resize: none;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  color: var(--pd-c-text);
  max-height: 120px;
  min-height: 22px;
  padding: 4px 0;
  letter-spacing: -0.005em;
}
.pd-chat__textarea::placeholder { color: var(--pd-c-text-3); }

.pd-chat__send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 0;
  background: var(--pd-c-action);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.22s var(--pd-c-ease),
    background 0.18s ease,
    opacity 0.18s ease;
  will-change: transform;
}
.pd-chat__send:hover  { background: var(--pd-c-action-hi); transform: scale(1.06); }
.pd-chat__send:active { transform: scale(0.94); }
.pd-chat__send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.pd-chat__send svg { transform: translateX(1px); }

.pd-chat__hint {
  margin-top: 8px;
  text-align: center;
  font-size: 11px;
  color: var(--pd-c-text-3);
  letter-spacing: -0.005em;
}

/* Mobile — фул-скрін, врівноважений з safe-area, FAB ховається коли відкрито */
@media (max-width: 600px) {
  .pd-chat__fab {
    right: 14px;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    width: 56px;
    height: 56px;
    transition:
      transform 0.32s var(--pd-c-ease),
      opacity 0.24s ease,
      background 0.18s ease;
  }
  .pd-chat__fab-mini {
    bottom: 7px;
    font-size: 7px;
    letter-spacing: 0.015em;
    gap: 3px;
  }
  .pd-chat__fab-icon {
    width: 27px;
    height: 27px;
  }
  .pd-chat__fab-icon--open {
    transform: translate(-50%, -59%) scale(1);
  }
  .pd-chat--open .pd-chat__fab-icon--open {
    transform: translate(-50%, -59%) rotate(-90deg) scale(0.32);
  }
  .pd-chat--open .pd-chat__fab {
    transform: translateY(8px) scale(0.7);
    opacity: 0;
    pointer-events: none;
  }

  .pd-chat__panel {
    right: 0;
    left: 0;
    bottom: 0;
    top: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    transform-origin: center;
    transform: translateY(24px) scale(1);
  }
  .pd-chat--open .pd-chat__panel { transform: translateY(0) scale(1); }

  .pd-chat__header {
    padding:
      calc(14px + env(safe-area-inset-top, 0px))
      calc(16px + env(safe-area-inset-right, 0px))
      14px
      calc(16px + env(safe-area-inset-left, 0px));
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--pd-c-surface);
  }
  .pd-chat__title { font-size: 16px; }
  .pd-chat__status { font-size: 12.5px; }
  .pd-chat__close {
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }
  .pd-chat__close svg { width: 22px; height: 22px; }

  .pd-chat__body {
    padding:
      16px
      calc(16px + env(safe-area-inset-right, 0px))
      16px
      calc(16px + env(safe-area-inset-left, 0px));
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  .pd-chat__welcome-mark { width: 64px; height: 64px; font-size: 26px; border-radius: 20px; }
  .pd-chat__welcome-title { font-size: 26px; }
  .pd-chat__welcome-sub { font-size: 15px; max-width: 280px; }

  .pd-chat__msg { max-width: 86%; }
  .pd-chat__bubble { font-size: 15px; padding: 11px 15px; border-radius: 20px; }
  .pd-chat__msg--client .pd-chat__bubble { border-bottom-right-radius: 6px; }
  .pd-chat__msg--operator .pd-chat__bubble { border-bottom-left-radius: 6px; }

  .pd-chat__input {
    padding:
      12px
      calc(12px + env(safe-area-inset-right, 0px))
      calc(14px + env(safe-area-inset-bottom, 0px))
      calc(12px + env(safe-area-inset-left, 0px));
    position: sticky;
    bottom: 0;
    z-index: 2;
  }
  .pd-chat__compose {
    padding: 8px 8px 8px 14px;
    border-radius: 18px;
  }
  .pd-chat__attach {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }
  .pd-chat__attach svg {
    width: 19px;
    height: 19px;
  }
  .pd-chat__textarea {
    font-size: 16px;     /* >=16px щоб iOS не зумив форму */
    min-height: 24px;
    max-height: 140px;
  }
  .pd-chat__send {
    width: 42px;
    height: 42px;
    border-radius: 14px;
  }
  .pd-chat__send svg { width: 20px; height: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  .pd-chat__fab { animation: none !important; }
  .pd-chat__fab-mini::before { animation: none !important; }
  .pd-chat__fab::before,
  .pd-chat__fab::after,
  .pd-chat__status::before,
  .pd-chat__msg,
  .pd-chat__welcome-mark,
  .pd-chat__welcome-title,
  .pd-chat__welcome-sub { animation: none; }
  .pd-chat__panel,
  .pd-chat__fab,
  .pd-chat__send { transition-duration: 0.1s; }
}
