/* ============================================================
   W-Garage онлайн-чат — стилі віджета
   Кольори/радіуси/тіні — з css/style.css (:root): --navy, --orange,
   --gray-*, --radius, --shadow-lg. Шрифт успадковується (Inter).
   z-index: кнопка 1150, вікно 1200 — вище за .mobile-cta-bar (400),
   .sticky-mobile-cta, header (500), after-hours overlay (1000) і
   .back-to-top (1100): чат має працювати і в неробочі години.
   ============================================================ */

/* ===== Плаваюча кнопка ===== */
.wg-chat-btn {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--orange, #e8792b);
  color: var(--white, #fff);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1150;
  box-shadow: 0 6px 20px rgba(232, 121, 43, .45), 0 2px 6px rgba(0, 0, 0, .15);
  transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
  padding: 0;
}
.wg-chat-btn-ico { width: 26px; height: 26px; }
@media (hover: hover) {
  .wg-chat-btn:hover {
    background: var(--orange-hover, #d06820);
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(232, 121, 43, .55), 0 3px 8px rgba(0, 0, 0, .2);
  }
}
.wg-chat-btn:focus-visible {
  outline: 2px solid var(--navy, #1e2a3a);
  outline-offset: 3px;
}

/* бейдж непрочитаних */
.wg-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #e53935;
  color: #fff;
  font-size: .6875rem;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
}

/* ===== Вікно чату (десктоп: картка справа внизу) ===== */
.wg-chat-win {
  position: fixed;
  right: 24px;
  bottom: 92px; /* над кнопкою */
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--white, #fff);
  border-radius: var(--radius-lg, 16px);
  box-shadow: var(--shadow-lg, 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05)), 0 18px 50px rgba(0, 0, 0, .18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1200;
}
.wg-chat-win[hidden] { display: none; }

/* шапка */
.wg-chat-head {
  background: var(--navy, #1e2a3a);
  color: var(--white, #fff);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.wg-chat-head-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.wg-chat-head-txt strong { font-size: .9375rem; line-height: 1.25; }
.wg-chat-head-txt span { font-size: .75rem; color: var(--gray-300, #cbd5e1); }
.wg-chat-close {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-sm, 8px);
  background: transparent;
  color: var(--gray-300, #cbd5e1);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, color .15s ease;
}
.wg-chat-close:hover { background: var(--navy-light, #2d3b4e); color: var(--white, #fff); }
.wg-chat-close:focus-visible { outline: 2px solid var(--orange, #e8792b); outline-offset: 2px; }

/* стрічка повідомлень */
.wg-chat-msgs {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 12px;
  background: var(--gray-50, #f8fafc);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wg-msg { display: flex; flex-direction: column; max-width: 85%; }
.wg-msg--me { align-self: flex-end; align-items: flex-end; }
.wg-msg--them { align-self: flex-start; align-items: flex-start; }
.wg-msg--sys { align-self: center; align-items: center; max-width: 95%; }

.wg-msg-author {
  font-size: .6875rem;
  color: var(--gray-500, #64748b);
  margin: 0 6px 2px;
}
.wg-msg-bubble {
  padding: 8px 12px;
  border-radius: var(--radius, 12px);
  font-size: .875rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.wg-msg--me .wg-msg-bubble {
  background: var(--orange, #e8792b);
  color: var(--white, #fff);
  border-bottom-right-radius: 4px;
}
.wg-msg--them .wg-msg-bubble {
  background: var(--gray-200, #e2e8f0);
  color: var(--gray-800, #1e293b);
  border-bottom-left-radius: 4px;
}
.wg-msg-link { text-decoration: underline; word-break: break-all; font-weight: 600; }
.wg-msg--them .wg-msg-link { color: var(--orange, #e8792b); }
.wg-msg--me .wg-msg-link { color: #fff; }
.wg-msg--sys .wg-msg-bubble {
  background: transparent;
  color: var(--gray-500, #64748b);
  font-size: .75rem;
  text-align: center;
  padding: 2px 8px;
}

/* м'яка пропозиція телефону */
.wg-chat-phone {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: #fdf3ea;
  border-top: 1px solid var(--gray-200, #e2e8f0);
  flex-shrink: 0;
}
.wg-chat-phone[hidden] { display: none; }
.wg-chat-phone input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--gray-300, #cbd5e1);
  border-radius: var(--radius-sm, 8px);
  font: inherit;
  font-size: .8125rem;
  color: var(--gray-800, #1e293b);
  background: var(--white, #fff);
}
.wg-chat-phone input:focus-visible { outline: 2px solid var(--orange, #e8792b); outline-offset: 1px; }
.wg-chat-phone-send {
  height: 40px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius-sm, 8px);
  background: var(--orange, #e8792b);
  color: var(--white, #fff);
  font: inherit;
  font-size: .8125rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}
.wg-chat-phone-send:hover { background: var(--orange-hover, #d06820); }
.wg-chat-phone-send:focus-visible { outline: 2px solid var(--navy, #1e2a3a); outline-offset: 2px; }
.wg-chat-phone-close {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm, 8px);
  background: transparent;
  color: var(--gray-500, #64748b);
  font-size: .875rem;
  cursor: pointer;
  flex-shrink: 0;
}
.wg-chat-phone-close:hover { color: var(--gray-800, #1e293b); background: var(--gray-100, #f1f5f9); }
.wg-chat-phone-close:focus-visible { outline: 2px solid var(--orange, #e8792b); outline-offset: 2px; }

/* поле вводу */
.wg-chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: var(--white, #fff);
  border-top: 1px solid var(--gray-200, #e2e8f0);
  flex-shrink: 0;
}
.wg-chat-input input {
  flex: 1;
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--gray-300, #cbd5e1);
  border-radius: var(--radius, 12px);
  font: inherit;
  font-size: .875rem;
  color: var(--gray-800, #1e293b);
  background: var(--gray-50, #f8fafc);
}
.wg-chat-input input:focus-visible { outline: 2px solid var(--orange, #e8792b); outline-offset: 1px; }
.wg-chat-send {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius, 12px);
  background: var(--orange, #e8792b);
  color: var(--white, #fff);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}
.wg-chat-send svg { width: 18px; height: 18px; }
.wg-chat-send:hover { background: var(--orange-hover, #d06820); }
.wg-chat-send:focus-visible { outline: 2px solid var(--navy, #1e2a3a); outline-offset: 2px; }

/* ===== Розведення з кнопкою «наверх» (.back-to-top, style.css:
   десктоп bottom:20 right:20, ≤1400px bottom:76px right:16).
   Чат займає нижній правий кут → back-to-top піднімаємо НАД чатом.
   Цей файл підключається ПІСЛЯ style.css — override спрацює. ===== */
.back-to-top { bottom: 94px; } /* 24 + 56 (кнопка чату) + 14 зазор */

/* ===== Планшет/малий ноут (≤1400px): унизу живе .sticky-mobile-cta —
   кнопка чату над ним (bottom ~80px), back-to-top ще вище ===== */
@media (max-width: 1400px) {
  .wg-chat-btn {
    right: 16px;
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    width: 52px;
    height: 52px;
  }
  .wg-chat-btn-ico { width: 24px; height: 24px; }
  .wg-chat-win {
    right: 16px;
    bottom: calc(142px + env(safe-area-inset-bottom, 0px));
    max-height: calc(100vh - 170px);
  }
  .back-to-top { bottom: calc(144px + env(safe-area-inset-bottom, 0px)); } /* 80 + 52 + 12 */
}

/* ===== Мобільний (<768px): вікно майже на весь екран ===== */
@media (max-width: 767px) {
  .wg-chat-btn {
    /* над .mobile-cta-bar / .sticky-mobile-cta (z-index ≤500) */
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    right: 14px;
  }
  .wg-chat-win {
    top: 8vh;
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
  }
}
