/* =========================================================
   OyunKirala — Canlı Destek Widget'ı
   ========================================================= */

.live-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: "Inter", sans-serif;
}

.support-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* Chat Balonu (Açma Butonu) */
.chat-toggle-btn {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(12, 12, 12, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.3);
  animation: chatBtnAppear 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s, border-color 0.3s;
}

.support-actions .chat-toggle-btn:nth-child(2) {
  animation-delay: 0.08s;
}

.whatsapp-toggle-btn {
  color: #25d366;
}

.whatsapp-toggle-btn:hover {
  box-shadow: 0 12px 30px rgba(37, 211, 102, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border-color: rgba(37, 211, 102, 0.38);
}

@keyframes chatBtnAppear {
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.chat-toggle-btn::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  pointer-events: none;
  animation: chatBtnRingPulse 3s infinite;
}

.chat-toggle-btn:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 12px 30px rgba(253, 93, 0, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border-color: rgba(253, 93, 0, 0.4);
}

.live-chat-widget.open .site-chat-toggle::after {
  animation: none;
}

@keyframes chatBtnRingPulse {
  0% {
    transform: scale(1);
    opacity: 0.6;
  }
  70% {
    transform: scale(1.3);
    opacity: 0;
  }
  100% {
    transform: scale(1.3);
    opacity: 0;
  }
}

.chat-toggle-btn:active {
  transform: scale(0.95);
}

.chat-toggle-btn svg {
  width: 28px;
  height: 28px;
  transition: transform 0.3s, opacity 0.3s;
}

.chat-toggle-btn .icon-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

.live-chat-widget.open .site-chat-toggle .icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.live-chat-widget.open .site-chat-toggle .icon-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* Okunmamış rozeti */
.chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--ok-color-status-error);
  color: var(--ok-color-text-primary);
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--ok-color-bg-surface);
  transform: scale(0);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chat-badge.show { transform: scale(1); }

/* Sohbet Penceresi */
.chat-window {
  position: absolute;
  bottom: calc(100% + 18px);
  right: 0;
  width: 340px;
  height: 480px;
  max-height: calc(100vh - 120px);
  background: rgba(12, 12, 12, 0.90);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-top: 2px solid var(--accent, var(--ok-color-brand-primary));
  border-radius: 16px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(20px) scale(0.95);
  transform-origin: bottom right;
  transition: opacity 0.3s, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@media (max-width: 480px) {
  .chat-window {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  .live-chat-widget.open .support-actions {
    display: none; /* Mobilde pencere açılınca destek butonlarını gizle */
  }
}

.live-chat-widget.open .chat-window {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Header */
.chat-header {
  padding: 14px 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ok-color-bg-surface-3);
  border: none;
  display: block;
  object-fit: cover;
  object-position: center;
  padding: 0;
  flex-shrink: 0;
  /* Logo zaten dairesel; ekstra padding/border çift halka bozuyordu */
}

.chat-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ok-color-text-primary);
}

.chat-status {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.chat-status-dot {
  width: 6px;
  height: 6px;
  background: #2ecc71;
  border-radius: 50%;
  animation: chatPulse 2s infinite;
}
@keyframes chatPulse {
  0% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.4); }
  70% { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

.chat-close-mobile {
  background: none;
  border: none;
  color: var(--text-2);
  display: none;
  padding: 8px;
  margin: -8px;
  cursor: pointer;
}
@media (max-width: 480px) {
  .chat-close-mobile { display: block; }
}

/* Messages Area */
.chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--glass-bg-3); border-radius: 6px; }

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  animation: chatMsgIn 0.3s var(--ease) forwards;
  opacity: 0;
  transform: translateY(10px);
}
@keyframes chatMsgIn {
  to { opacity: 1; transform: none; }
}

.chat-msg.admin {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-bottom-left-radius: 4px;
}

.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), var(--accent-2, var(--ok-color-brand-secondary)));
  color: var(--ok-color-text-primary);
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 12px rgba(253, 93, 0, 0.25);
}

.chat-msg-time {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
  display: block;
}

/* State Boxes (Login required, loading, etc) */
.chat-state-box {
  margin: auto;
  text-align: center;
  padding: 20px;
  background: rgba(255, 255, 255, 0.015);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-state-box h4 {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--ok-color-text-primary);
}
.chat-state-box p {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--muted);
}

/* Input Area */
.chat-input-area {
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.015);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--ok-color-text-primary);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input:focus {
  border-color: rgba(253, 93, 0, 0.6);
  box-shadow: 0 0 10px rgba(253, 93, 0, 0.15);
  background: rgba(0, 0, 0, 0.4);
}

.chat-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2, var(--ok-color-brand-secondary)));
  color: var(--ok-color-text-primary);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(253, 93, 0, 0.2);
  transition: transform 0.2s, opacity 0.2s, box-shadow 0.2s;
}

.chat-send-btn:hover:not(:disabled) {
  transform: scale(1.1);
}
.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Görsel Ekleme (Ataç) Butonu */
.chat-attach-btn {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.2s, background 0.2s, transform 0.2s;
}
.chat-attach-btn:hover:not(:disabled) {
  color: var(--accent-2);
  background: rgba(255, 94, 0, 0.12);
  transform: scale(1.05);
}
.chat-attach-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Gönderim Öncesi Görsel Önizleme */
.chat-image-preview {
  position: relative;
  margin: 0 16px;
  padding: 8px;
  background: var(--glass-bg-2);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  width: fit-content;
  animation: chatMsgIn 0.25s var(--ease) forwards;
}
.chat-image-preview img {
  max-width: 120px;
  max-height: 90px;
  border-radius: 8px;
  display: block;
  object-fit: cover;
}
.chat-preview-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ok-color-status-error);
  color: var(--ok-color-text-primary);
  border: 2px solid var(--ok-color-bg-surface, #0c0c0c);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.chat-preview-remove:hover { transform: scale(1.1); }

/* Mesaj İçindeki Görsel */
.chat-msg.has-image {
  padding: 6px;
}
.chat-msg-img-link {
  display: block;
  line-height: 0;
}
.chat-msg-img {
  max-width: 220px;
  max-height: 240px;
  width: auto;
  border-radius: 12px;
  display: block;
  object-fit: cover;
  cursor: zoom-in;
  transition: opacity 0.2s;
}
.chat-msg-img:hover { opacity: 0.92; }
.chat-msg.has-image .chat-msg-text {
  padding: 6px 8px 0;
}
.chat-msg.has-image .chat-msg-time {
  padding: 0 8px 4px;
}

/* Yükleme İskeleti (anlık his için) */
.chat-skeleton {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px;
}
.sk-bubble {
  height: 34px;
  border-radius: 16px;
  background: linear-gradient(90deg, var(--glass-bg-2) 25%, var(--glass-bg-3) 37%, var(--glass-bg-2) 63%);
  background-size: 400% 100%;
  animation: skShimmer 1.2s ease-in-out infinite;
}
.sk-admin { align-self: flex-start; width: 70%; border-bottom-left-radius: 4px; }
.sk-user  { align-self: flex-end;   width: 55%; border-bottom-right-radius: 4px; }
@keyframes skShimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* ===== Mobile Safe-Area, Spacing & Sticky Bar Avoidance ===== */
@media (max-width: 768px) {
  .live-chat-widget {
    /* Düz bottom fallback + env kademelendirmesi: env()'i bilmeyen eski
       motorlarda bildirimin tamamı düşmesin. Fallback 0px — gerçek iOS'ta
       env=0 dönerse çift boşluk oluşmasın. */
    bottom: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    right: 16px !important;
    z-index: 950 !important;
  }
  .chat-toggle-btn {
    width: 50px !important;
    height: 50px !important;
  }

  /* Kiralama barı görünürken chat'i barın üstüne kaldır; ancak sepet çekmecesi
     açıkken bar gizlendiği (is-hidden-by-modal) için chat havada asılı
     kalmasın. page-game-detail olü seçicidir (hicbir yerde set edilmiyor). */
  body.has-sticky-bar:not(.cart-open) .live-chat-widget {
    bottom: calc(86px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Çerez banner'ı görünürken FAB (chat/WhatsApp) banner'ın butonlarının
     üstüne binmesin (360-480px'de banner neredeyse tam genişlik) — banner
     kapanana kadar FAB'ı gizle (cart-open deseninin aynısı). */
  body.cookie-open .live-chat-widget {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }
}

/* Masaüstünde sepet çekmecesi açıkken chat/WhatsApp FAB çekmece panelinin
   üzerinde kalinmasin (mobildeki cookie-banner gizleme deseniyle ayni). */
body.cart-open .live-chat-widget {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
