/* Widżet czatu — styl iMessage (Mint Apartments) */

#chat-widget-root {
  position: fixed;
  z-index: 9999;
  bottom: 0;
  right: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: #1c1c1e;
}

/* FAB — przycisk otwarcia czatu */
.chat-widget-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #0B93F6;
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(11, 147, 246, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s, left 0.35s ease, top 0.35s ease, right 0.35s ease, bottom 0.35s ease;
  z-index: 10000;
}
.chat-widget-fab:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 20px rgba(11, 147, 246, 0.5);
}
.chat-widget-fab:focus {
  outline: 2px solid #0B93F6;
  outline-offset: 2px;
}
.chat-widget-fab svg {
  width: 24px;
  height: 24px;
}
.chat-widget-fab.chat-widget-open svg.chat-widget-icon-chat { display: none; }
.chat-widget-fab svg.chat-widget-icon-close { display: none; }
.chat-widget-fab.chat-widget-open svg.chat-widget-icon-close { display: block; }

/* Gdy widoczny "Sprawdź dostępność" — FAB 20 px na lewo od przycisku (left/top z JS), płynna animacja z transition */
.chat-widget-fab.chat-widget-fab-aligned {
  right: auto;
  bottom: auto;
}

/* Okno czatu */
.chat-widget-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 480px;
  max-height: 80vh;
  background: #F2F2F7;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  animation: chat-widget-slideUp 0.25s ease-out;
}
@keyframes chat-widget-slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-widget-panel.hidden {
  display: none;
}

/* Przycisk zamknięcia — prawy górny róg panelu (nie zasłania wysyłania) */
.chat-widget-close-corner {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 50%;
  cursor: pointer;
  color: #8e8e93;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  z-index: 10;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}
.chat-widget-close-corner:hover {
  background: #E5E5EA;
  color: #1c1c1e;
}
.chat-widget-close-corner svg { width: 20px; height: 20px; }

/* Nagłówek */
.chat-widget-header {
  padding: 16px 52px 16px 20px;
  background: #fff;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.chat-widget-header h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: #1c1c1e;
}
.chat-widget-header p {
  margin: 2px 0 0;
  font-size: 13px;
  color: #8e8e93;
}
.chat-widget-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  color: #8e8e93;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.chat-widget-close:hover {
  background: #E5E5EA;
  color: #1c1c1e;
}
.chat-widget-close svg { width: 18px; height: 18px; }

/* Lista wiadomości */
.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-widget-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-widget-messages::-webkit-scrollbar-thumb {
  background: #c7c7cc;
  border-radius: 3px;
}

/* Bąbelek — user (po prawej, niebieski) */
.chat-widget-bubble-wrap {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
}
.chat-widget-bubble-wrap.agent {
  justify-content: flex-start;
}

.chat-widget-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  word-wrap: break-word;
  white-space: pre-wrap;
  position: relative;
}
.chat-widget-bubble.user {
  background: #0B93F6;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-widget-bubble.agent {
  background: #E5E5EA;
  color: #1c1c1e;
  border-bottom-left-radius: 4px;
}

.chat-widget-bubble .chat-widget-bubble-text {
  margin: 0;
}
.chat-widget-bubble .chat-widget-bubble-text .chat-widget-inline-link {
  color: #0B93F6;
  text-decoration: underline;
  word-break: break-all;
}
.chat-widget-bubble .chat-widget-bubble-text .chat-widget-inline-link:hover {
  text-decoration: underline;
  opacity: 0.9;
}
.chat-widget-bubble .chat-widget-quick-replies {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chat-widget-bubble .chat-widget-quick-reply-btn {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 14px;
  text-decoration: none;
  transition: opacity 0.15s;
}
.chat-widget-bubble.user .chat-widget-quick-reply-btn {
  background: rgba(255, 255, 255, 0.3);
  color: #fff;
}
.chat-widget-bubble.agent .chat-widget-quick-reply-btn {
  background: #fff;
  color: #0B93F6;
  border: 1px solid rgba(11, 147, 246, 0.4);
}
.chat-widget-bubble .chat-widget-quick-reply-btn:hover {
  opacity: 0.9;
}

/* Przycisk WhatsApp w czacie — nadpisanie domyślnego quick-reply (zielony, ikona + tekst) */
.chat-widget-bubble .chat-widget-quick-reply-btn.contact-btn-whatsapp {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #25D366 !important;
  color: #fff !important;
  border: none !important;
  box-shadow: 0 4px 12px rgba(37, 211, 102, 0.4);
  padding: 10px 16px;
}
.chat-widget-bubble .chat-widget-quick-reply-btn.contact-btn-whatsapp:hover {
  background: #20BA5A !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37, 211, 102, 0.5);
}
.chat-widget-bubble .chat-widget-quick-reply-btn.contact-btn-whatsapp svg {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

/* Przyciski do stron apartamentów (propozycje z udogodnieniem) */
.chat-widget-bubble .chat-widget-apartment-btn {
  background: linear-gradient(135deg, rgba(11, 147, 246, 0.12), rgba(11, 147, 246, 0.06));
  color: #0B93F6;
  border: 1px solid rgba(11, 147, 246, 0.35);
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(11, 147, 246, 0.12);
}
.chat-widget-bubble .chat-widget-apartment-btn:hover {
  background: linear-gradient(135deg, rgba(11, 147, 246, 0.2), rgba(11, 147, 246, 0.1));
  border-color: rgba(11, 147, 246, 0.5);
  box-shadow: 0 4px 12px rgba(11, 147, 246, 0.2);
}

/* Stan ładowania (pisze…) */
.chat-widget-bubble.typing {
  padding: 14px 18px;
}
.chat-widget-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}
.chat-widget-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
  animation: chat-widget-dot 1.2s ease-in-out infinite;
}
.chat-widget-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-widget-typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-widget-dot {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
  40% { transform: scale(1.2); opacity: 1; }
}

/* Szybkie akcje (sugestie) */
.chat-widget-quick-actions {
  padding: 8px 16px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}
.chat-widget-quick-action-btn {
  padding: 8px 14px;
  border-radius: 16px;
  font-size: 13px;
  border: 1px solid #c7c7cc;
  background: #fff;
  color: #1c1c1e;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.chat-widget-quick-action-btn:hover {
  background: #E5E5EA;
  border-color: #aeaeb2;
}

/* Pasek wpisywania */
.chat-widget-input-wrap {
  padding: 12px 16px 16px;
  background: #fff;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.chat-widget-input {
  flex: 1;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid #c7c7cc;
  border-radius: 20px;
  font-size: 16px;
  font-family: inherit;
  resize: none;
  transition: border-color 0.15s;
}
.chat-widget-input:focus {
  outline: none;
  border-color: #0B93F6;
}
.chat-widget-input::placeholder {
  color: #8e8e93;
}
.chat-widget-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #0B93F6;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}
.chat-widget-send:hover {
  opacity: 0.9;
  transform: scale(1.05);
}
.chat-widget-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.chat-widget-send svg {
  width: 20px;
  height: 20px;
}

/* Mobile: całe okno rozmowy od razu widoczne, klawiatura nie zasłania, zamknięcie w rogu */
@media (max-width: 480px) {
  .chat-widget-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 75dvh;
    min-height: 320px;
    max-height: 75dvh;
    border-radius: 16px 16px 0 0;
  }
  .chat-widget-panel.chat-widget-panel-keyboard {
    position: fixed;
    bottom: auto;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
  }
  .chat-widget-messages {
    padding: 12px;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
  }
  .chat-widget-input-wrap {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    flex-shrink: 0;
  }
  .chat-widget-close-corner {
    top: 8px;
    right: 8px;
    width: 44px;
    height: 44px;
    z-index: 11;
  }
  .chat-widget-close-corner svg {
    width: 22px;
    height: 22px;
  }
  .chat-widget-header {
    padding: 14px 56px 14px 16px;
  }
  .chat-widget-fab {
    bottom: 20px;
    right: 20px;
  }
  /* Na mobile przycisk czatu zawsze po prawej (ignoruj wyrównanie do CTA) */
  .chat-widget-fab.chat-widget-fab-aligned {
    left: auto !important;
    right: 20px !important;
    bottom: 20px !important;
    top: auto !important;
  }
  .chat-widget-fab.chat-widget-open {
    display: none;
  }
}
