/* ======================================================================
   SATKOM — Canlı destek sohbet kartı
   Site renk değişkenlerini kullanır; tema değişince sohbet de değişir.
   ====================================================================== */

.chat-fab {
  position: fixed;
  right: var(--sp-5, 20px);
  bottom: var(--sp-5, 20px);
  z-index: 900;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: var(--c-primary-600);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .22);
  transition: transform .18s ease, background .18s ease;
}
.chat-fab:hover  { background: var(--c-primary-700); transform: translateY(-2px); }
.chat-fab:focus-visible { outline: 3px solid var(--c-primary-300); outline-offset: 3px; }

.chat-fab__icon { grid-area: 1 / 1; display: grid; place-items: center; transition: opacity .16s, transform .16s; }
.chat-fab__icon--close { opacity: 0; transform: rotate(-90deg) scale(.6); }
.chat-fab.is-open .chat-fab__icon--open  { opacity: 0; transform: rotate(90deg) scale(.6); }
.chat-fab.is-open .chat-fab__icon--close { opacity: 1; transform: none; }

.chat-fab__badge {
  position: absolute; top: -2px; right: -2px;
  min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 99px; background: #dc2626; color: #fff;
  font-size: 12px; font-weight: 700; line-height: 22px; text-align: center;
  border: 2px solid #fff;
}

/* WhatsApp düğmesi sol altta, sohbet sağ altta durur — çakışmazlar.
   Yukarı çık düğmesi sağ altta olduğu için sohbeti onun üstüne alıyoruz. */
.to-top ~ .chat-fab,
.chat-fab { bottom: calc(var(--sp-5, 20px) + 64px); }

/* ---------------------------------------------------------------- */

.chat-panel {
  position: fixed;
  right: var(--sp-5, 20px);
  bottom: calc(var(--sp-5, 20px) + 132px);
  z-index: 901;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  background: var(--c-bg, #fff);
  border: 1px solid var(--c-line, #e2e8f0);
  border-radius: var(--r-lg, 16px);
  box-shadow: 0 24px 60px rgba(15, 23, 42, .26);
  overflow: hidden;
  animation: chatIn .2s ease;
}
.chat-panel[hidden] { display: none; }

@keyframes chatIn {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .chat-panel { animation: none; }
  .chat-fab   { transition: none; }
}

/* ---------------------------------------------------------------- */

.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3, 12px);
  padding: 14px 16px;
  background: var(--c-primary-600);
  color: #fff;
  flex: none;
}
.chat-head__brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-head__brand img { border-radius: 8px; background: #fff; padding: 3px; object-fit: contain; }
.chat-head__mark {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255, 255, 255, .18); display: grid; place-items: center; flex: none;
}
.chat-head__brand strong { display: block; font-size: 15px; line-height: 1.2; }
.chat-head__brand small  { display: block; font-size: 12px; opacity: .82; }
.chat-head__brand small[data-online="1"]::before {
  content: ''; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: #4ade80; margin-right: 6px; vertical-align: middle;
}
.chat-head__actions { display: flex; gap: 4px; flex: none; }

.chat-icon-btn {
  width: 36px; height: 36px; min-width: 36px;
  border: 0; border-radius: 50%; background: transparent; color: inherit;
  cursor: pointer; display: grid; place-items: center; transition: background .15s;
}
.chat-icon-btn:hover { background: rgba(255, 255, 255, .16); }
.chat-icon-btn:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.chat-icon-btn--end  { background: #dc2626; color: #fff; }
.chat-icon-btn--end:hover { background: #b91c1c; }
.chat-icon-btn--mute.is-muted { background: rgba(255, 255, 255, .3); }

/* ---------------------------------------------------------------- */
/* Sesli arama şeridi                                                */

.chat-call {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; flex: none;
  background: var(--c-primary-800, #0f3a63); color: #fff;
}
.chat-call[hidden] { display: none; }
.chat-call__pulse {
  width: 10px; height: 10px; border-radius: 50%; background: #4ade80; flex: none;
  animation: chatPulse 1.6s infinite;
}
@keyframes chatPulse {
  0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, .7); }
  70%  { box-shadow: 0 0 0 9px rgba(74, 222, 128, 0); }
  100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}
@media (prefers-reduced-motion: reduce) { .chat-call__pulse { animation: none; } }
.chat-call__text { flex: 1; min-width: 0; }
.chat-call__text strong { display: block; font-size: 13.5px; }
.chat-call__text small  { font-size: 12px; opacity: .8; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- */

.chat-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.chat-body[hidden] { display: none; }

.chat-intro { padding: 18px 16px; }
.chat-intro__lead { margin: 0 0 16px; font-size: 14.5px; color: var(--c-ink, #0f172a); }

.chat-field { margin-bottom: 12px; }
.chat-field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; }
.chat-field input,
.chat-field textarea {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 14px;
  border: 1px solid var(--c-line, #e2e8f0); border-radius: var(--r-md, 10px);
  background: var(--c-bg, #fff); color: inherit; resize: vertical;
}
.chat-field input:focus, .chat-field textarea:focus {
  outline: 2px solid var(--c-primary-400); outline-offset: -1px; border-color: transparent;
}

.chat-note { font-size: 11.5px; color: var(--c-muted, #64748b); margin: 10px 0 0; text-align: center; }

.chat-offline {
  margin-top: 18px; padding: 14px; border-radius: var(--r-md, 10px);
  background: var(--c-bg-soft, #f8fafc); border: 1px solid var(--c-line, #e2e8f0);
}
.chat-offline p { margin: 0 0 10px; font-size: 13px; }
.chat-offline small { display: block; margin-top: 8px; font-size: 11.5px; color: var(--c-muted); text-align: center; }

/* ---------------------------------------------------------------- */
/* Mesajlar                                                          */

.chat-body--messages { display: flex; flex-direction: column; }
.chat-messages { padding: 16px; display: flex; flex-direction: column; gap: 10px; }

.chat-msg { max-width: 82%; display: flex; flex-direction: column; gap: 3px; }
.chat-msg--ziyaretci { align-self: flex-end; align-items: flex-end; }
.chat-msg--operator  { align-self: flex-start; }
.chat-msg--sistem    { align-self: center; max-width: 92%; align-items: center; }

.chat-msg__bubble {
  padding: 9px 13px; border-radius: 16px; font-size: 14px; line-height: 1.5;
  word-break: break-word; white-space: pre-wrap;
}
.chat-msg--ziyaretci .chat-msg__bubble {
  background: var(--c-primary-600); color: #fff; border-bottom-right-radius: 5px;
}
.chat-msg--operator .chat-msg__bubble {
  background: var(--c-bg-soft, #f1f5f9); color: var(--c-ink, #0f172a); border-bottom-left-radius: 5px;
}
.chat-msg--sistem .chat-msg__bubble {
  background: transparent; color: var(--c-muted, #64748b); font-size: 12.5px;
  text-align: center; padding: 4px 10px; border: 1px dashed var(--c-line);
  border-radius: 99px;
}

.chat-msg__meta {
  font-size: 11px; color: var(--c-muted, #64748b); padding: 0 4px;
  display: flex; align-items: center; gap: 8px;
}

/* Geri alma — mesajın üstüne gelince veya dokununca belirir */
.chat-msg__undo {
  border: 0; background: none; padding: 2px 4px; cursor: pointer;
  font: inherit; font-size: 11px; color: var(--c-primary-600);
  text-decoration: underline; opacity: 0; transition: opacity .15s;
}
.chat-msg:hover .chat-msg__undo,
.chat-msg:focus-within .chat-msg__undo { opacity: 1; }
.chat-msg__undo:disabled { opacity: .5; cursor: default; }
@media (pointer: coarse) { .chat-msg__undo { opacity: 1; } }

/* Geri alınmış mesaj */
.chat-msg__bubble--gone {
  background: transparent !important;
  color: var(--c-muted, #94a3b8) !important;
  border: 1px dashed var(--c-line, #e2e8f0);
  font-style: italic; font-size: 12.5px;
}

.chat-msg__media { border-radius: 12px; overflow: hidden; max-width: 100%; }
.chat-msg__media img,
.chat-msg__media video { display: block; max-width: 100%; height: auto; border-radius: 12px; }
.chat-msg__media audio { width: 240px; max-width: 100%; }

.chat-msg__file {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; text-decoration: none;
  background: var(--c-bg-soft, #f1f5f9); color: inherit;
  border: 1px solid var(--c-line, #e2e8f0);
}
.chat-msg__file:hover { border-color: var(--c-primary-400); }
.chat-msg__file b { display: block; font-size: 13px; }
.chat-msg__file small { color: var(--c-muted); font-size: 11.5px; }

/* Yazıyor göstergesi */
.chat-typing { display: flex; gap: 4px; padding: 0 20px 12px; }
.chat-typing[hidden] { display: none; }
.chat-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--c-muted, #94a3b8);
  animation: chatDot 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .18s; }
.chat-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes chatDot {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30%           { opacity: 1;  transform: translateY(-4px); }
}
@media (prefers-reduced-motion: reduce) { .chat-typing span { animation: none; opacity: .6; } }

/* ---------------------------------------------------------------- */
/* Yazma alanı                                                       */

.chat-compose {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 10px 12px; flex: none;
  border-top: 1px solid var(--c-line, #e2e8f0);
  background: var(--c-bg, #fff);
}
.chat-compose[hidden] { display: none; }
.chat-compose .chat-icon-btn { color: var(--c-muted, #64748b); }
.chat-compose .chat-icon-btn:hover { background: var(--c-bg-soft, #f1f5f9); color: var(--c-primary-600); }

.chat-compose textarea {
  flex: 1; min-height: 40px; max-height: 120px; padding: 10px 12px;
  font: inherit; font-size: 14px; line-height: 1.4; resize: none;
  border: 1px solid var(--c-line, #e2e8f0); border-radius: 20px;
  background: var(--c-bg-soft, #f8fafc); color: inherit;
}
.chat-compose textarea:focus { outline: 2px solid var(--c-primary-400); outline-offset: -1px; }

.chat-send {
  width: 40px; height: 40px; min-width: 40px; border: 0; border-radius: 50%;
  background: var(--c-primary-600); color: #fff; cursor: pointer;
  display: grid; place-items: center; transition: background .15s;
}
.chat-send:hover { background: var(--c-primary-700); }
.chat-send:disabled { opacity: .5; cursor: not-allowed; }

.chat-upload { padding: 8px 14px 10px; flex: none; border-top: 1px solid var(--c-line); }
.chat-upload[hidden] { display: none; }
.chat-upload__bar { height: 4px; border-radius: 99px; background: var(--c-line); overflow: hidden; }
.chat-upload__bar span { display: block; height: 100%; width: 0; background: var(--c-primary-600); transition: width .2s; }
.chat-upload small { display: block; margin-top: 5px; font-size: 11.5px; color: var(--c-muted); }

/* ---------------------------------------------------------------- */
/* Mobil — tam ekran                                                 */

@media (max-width: 640px) {
  .chat-panel {
    right: 0; bottom: 0; left: 0; top: 0;
    width: 100%; max-width: none;
    max-height: none;
    border-radius: 0; border: 0;
    animation: none;

    /* Adres çubuğu açılıp kapandıkça yükseklik değişir. `dvh` bunu takip
       eder; desteklemeyen tarayıcılar için önce `100%` yazılır. */
    height: 100%;
    height: 100dvh;

    /* Çentikli telefonlarda alt çubuğun altında kalmasın */
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-sizing: border-box;
  }

  .chat-fab,
  .to-top ~ .chat-fab { right: 16px; bottom: 76px; width: 54px; height: 54px; }
  .chat-msg { max-width: 88%; }

  /* iOS Safari, 16px'ten küçük yazı alanına dokunulduğunda sayfayı
     otomatik büyütür. Büyüyen sayfada gönder düğmesi ekranın dışında
     kalır ve kullanıcı sohbete geçemez. 16px bunu tamamen engeller. */
  .chat-field input,
  .chat-field textarea,
  .chat-compose textarea { font-size: 16px; }

  /* Başlangıç formu uzun olduğunda kaydırılabilsin */
  .chat-body { -webkit-overflow-scrolling: touch; }

  /* Sohbet açıkken arka planın kaymasını engelle */
  body.chat-open { overflow: hidden; }

  /* Tam ekran sohbetin arkasında kalan yüzen öğeler dokunmayı çalmasın */
  body.chat-open .wa-fab,
  body.chat-open .to-top,
  body.chat-open .cookie-bar { display: none !important; }
}

/* Sağdan sola diller */
[dir="rtl"] .chat-fab,
[dir="rtl"] .chat-panel { right: auto; left: var(--sp-5, 20px); }
[dir="rtl"] .chat-msg--ziyaretci { align-self: flex-start; align-items: flex-start; }
[dir="rtl"] .chat-msg--operator  { align-self: flex-end; align-items: flex-end; }
