/* ============================================================================
 * Zyron CRM — Canlı Destek Modülü (ls-*)
 * İki sütun: konuşma listesi + thread. Konuşma arayüzü WhatsApp benzeri
 * (avatar, gün ayracı, balon kuyruğu, okundu tikleri, doodle duvar kâğıdı).
 * Topbar/liste CRM tema değişkenlerine uyumlu; thread WhatsApp paletinde.
 * ==========================================================================*/

/* ÖNEMLİ: display'i yalnızca .is-active iken ver. Aksi halde #id seçici
   .page{display:none}'ı ezer ve sayfa her zaman görünüp diğerlerinin üstüne biner. */
#page-live-support { height: 100%; min-height: 0; }
#page-live-support.is-active { display: flex; flex-direction: column; }

/* WhatsApp paleti (thread için sabit — göz aşinalığı) */
.ls-thread {
  --wa-bg:        #0b141a;   /* sohbet duvar kâğıdı */
  --wa-head:      #202c33;   /* başlık + compose şeridi */
  --wa-in:        #202c33;   /* gelen (ziyaretçi) balonu */
  --wa-out:       #005c4b;   /* giden (ajan) balonu */
  --wa-txt:       #e9edef;
  --wa-mut:       #8696a0;
  --wa-tick:      #53bdeb;   /* mavi okundu tiki */
  --wa-line:      #2a3942;
}

/* ── Üst bar ──────────────────────────────────────────────────────────────── */
.ls-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--color-surface-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
}
.ls-status { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ls-topbar__actions { display: flex; gap: 8px; }

.ls-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  user-select: none;
  transition: background 0.15s ease, color 0.15s ease;
}
.ls-toggle__dot { width: 10px; height: 10px; border-radius: 50%; background: var(--color-text-muted); transition: background 0.15s ease, box-shadow 0.15s ease; }
.ls-toggle.is-online { background: rgba(34, 197, 94, 0.14); border-color: rgba(34, 197, 94, 0.4); color: #22c55e; }
.ls-toggle.is-online .ls-toggle__dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2); }
.ls-toggle--secondary:not(.is-online):not(.is-muted) { background: rgba(245, 158, 11, 0.14); border-color: rgba(245, 158, 11, 0.4); color: #f59e0b; }
.ls-toggle--secondary:not(.is-online):not(.is-muted) .ls-toggle__dot { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18); }
.ls-toggle.is-muted { opacity: 0.45; pointer-events: none; }

.ls-status__hint { font-size: 12px; color: var(--color-text-muted); }

/* ── Ayarlar paneli ───────────────────────────────────────────────────────── */
.ls-settings {
  background: var(--color-surface-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
}
.ls-settings__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ls-fld { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--color-text-secondary); }
.ls-fld--full { grid-column: 1 / -1; }
.ls-fld--check { flex-direction: row; align-items: center; gap: 8px; grid-column: 1 / -1; }
.ls-fld input[type="text"], .ls-fld textarea {
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  color: var(--color-text-primary);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}
.ls-fld input[type="color"] { width: 56px; height: 34px; padding: 2px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface-3); cursor: pointer; }
.ls-fld input:focus, .ls-fld textarea:focus { outline: none; border-color: var(--color-primary); }
.ls-settings__foot { display: flex; justify-content: flex-end; margin-top: 14px; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.ls-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 12px;
  min-height: 0;
}

/* ── Liste ────────────────────────────────────────────────────────────────── */
.ls-list {
  display: flex;
  flex-direction: column;
  background: var(--color-surface-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 0;
}
.ls-tabs { display: flex; border-bottom: 1px solid var(--color-border); }
.ls-tab {
  flex: 1;
  padding: 12px 8px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.ls-tab:hover { color: var(--color-text-primary); }
.ls-tab.is-active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

.ls-convos { flex: 1; overflow-y: auto; }
.ls-empty {
  padding: 40px 20px; text-align: center; color: var(--color-text-muted);
  font-size: 13px; display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.ls-empty i { font-size: 36px; opacity: 0.4; }

.ls-conv {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--color-border);
  transition: background 0.12s ease;
}
.ls-conv:hover { background: var(--color-surface-2); }
.ls-conv.is-active { background: var(--color-surface-3); }
.ls-conv.is-unread .ls-conv__name { font-weight: 700; color: var(--color-text-primary); }
.ls-conv.is-unread .ls-conv__preview { color: var(--color-text-secondary); }

.ls-conv__avatar {
  position: relative;
  flex: none;
  width: 46px; height: 46px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-size: 16px; font-weight: 700;
  letter-spacing: 0.5px;
}
.ls-conv__statusdot {
  position: absolute; right: -1px; bottom: -1px;
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--color-surface-1);
}
.ls-conv__statusdot.is-open    { background: #22c55e; }
.ls-conv__statusdot.is-offline { background: #f59e0b; }
.ls-conv__statusdot.is-closed  { background: var(--color-text-muted); }

.ls-conv__main { flex: 1; min-width: 0; }
.ls-conv__row { display: flex; align-items: center; gap: 8px; }
.ls-conv__row + .ls-conv__row { margin-top: 3px; }
.ls-conv__name {
  flex: 1; min-width: 0;
  font-size: 14px; font-weight: 600; color: var(--color-text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 5px;
}
.ls-conv__tagicon { color: var(--color-primary); font-size: 14px; flex: none; }
.ls-conv__time { flex: none; font-size: 11px; color: var(--color-text-muted); }
.ls-conv.is-unread .ls-conv__time { color: #22c55e; }
.ls-conv__preview { flex: 1; min-width: 0; font-size: 12.5px; color: var(--color-text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ls-conv__badge {
  flex: none;
  min-width: 20px; height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #25d366;
  color: #0b141a;
  font-size: 11px;
  font-weight: 700;
  display: grid; place-items: center;
}

/* ── Thread (WhatsApp) ──────────────────────────────────────────────────────── */
.ls-thread {
  display: flex;
  flex-direction: column;
  background: var(--wa-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 0;
}

/* Boş durum */
.ls-thread__empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center; padding: 30px;
}
.ls-thread__empty-icon {
  width: 96px; height: 96px; border-radius: 50%;
  background: rgba(255,255,255,0.04);
  display: grid; place-items: center; margin-bottom: 8px;
}
.ls-thread__empty-icon i { font-size: 48px; color: #2a3942; }
.ls-thread__empty-title { font-size: 18px; font-weight: 600; color: var(--wa-txt); margin: 0; }
.ls-thread__empty-sub { font-size: 13px; color: var(--wa-mut); margin: 0; max-width: 320px; }

/* Başlık */
.ls-thread__head {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--wa-head);
  flex: none;
}
.ls-thread__avatar {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: #fff; font-size: 15px; font-weight: 700;
}
.ls-thread__who { flex: 1; min-width: 0; }
.ls-thread__name { font-size: 15px; font-weight: 600; color: var(--wa-txt); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ls-thread__status { font-size: 12px; color: var(--wa-mut); margin-top: 1px; }
.ls-thread__actions { display: flex; gap: 4px; flex: none; }
.ls-iconbtn {
  width: 36px; height: 36px; border: none; border-radius: 50%;
  background: transparent; color: var(--wa-mut); font-size: 20px;
  cursor: pointer; display: grid; place-items: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.ls-iconbtn:hover { background: rgba(255,255,255,0.08); color: var(--wa-txt); }
.ls-iconbtn--danger:hover { color: #f87171; }

/* İletişim çip şeridi */
.ls-thread__info {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 8px 16px;
  background: #111b21;
  border-bottom: 1px solid var(--wa-line);
  flex: none;
}
.ls-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--wa-head); color: var(--wa-txt);
  font-size: 12px; text-decoration: none;
  max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ls-chip i { color: var(--wa-mut); }
.ls-chip:hover { background: #2a3942; }
.ls-chip--mut { color: var(--wa-mut); pointer-events: none; }

/* Mesaj alanı — doodle duvar kâğıdı (hafif) */
.ls-thread__msgs {
  flex: 1; overflow-y: auto; padding: 16px 7%;
  display: flex; flex-direction: column; gap: 3px;
  background-color: var(--wa-bg);
  background-image:
    radial-gradient(rgba(255,255,255,0.022) 1px, transparent 1px),
    radial-gradient(rgba(255,255,255,0.018) 1px, transparent 1px);
  background-size: 28px 28px, 28px 28px;
  background-position: 0 0, 14px 14px;
}

/* Gün ayracı + sistem mesajı (ortada pill) */
.ls-daysep { display: flex; justify-content: center; margin: 12px 0 8px; }
.ls-daysep span {
  background: #182834; color: var(--wa-mut);
  font-size: 11.5px; font-weight: 500;
  padding: 5px 12px; border-radius: 8px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.2);
  text-align: center; max-width: 80%;
}
.ls-daysep--sys span { background: #1d2a32; color: #cfd9de; text-transform: none; }

/* Balonlar */
.ls-msg { display: flex; max-width: 70%; }
.ls-msg.is-visitor { align-self: flex-start; }
.ls-msg.is-agent   { align-self: flex-end; }
.ls-bubble {
  position: relative;
  padding: 6px 9px 8px 10px;
  border-radius: 8px;
  font-size: 13.6px; line-height: 1.4;
  color: var(--wa-txt);
  word-break: break-word; white-space: pre-wrap;
  box-shadow: 0 1px 1px rgba(0,0,0,0.18);
  min-width: 70px;
}
.ls-msg.is-visitor .ls-bubble { background: var(--wa-in);  border-top-left-radius: 0; }
.ls-msg.is-agent   .ls-bubble { background: var(--wa-out); border-top-right-radius: 0; }
/* Balon kuyruğu (üst köşe üçgeni) */
.ls-msg.is-visitor .ls-bubble::before {
  content: ''; position: absolute; top: 0; left: -7px;
  border: 7px solid transparent; border-top-color: var(--wa-in); border-right: 0;
}
.ls-msg.is-agent .ls-bubble::before {
  content: ''; position: absolute; top: 0; right: -7px;
  border: 7px solid transparent; border-top-color: var(--wa-out); border-left: 0;
}
.ls-msg__who { display: block; font-size: 12px; font-weight: 700; color: #53bdeb; margin-bottom: 2px; }
.ls-bubble__txt { }
.ls-msg__meta {
  float: right;
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 10.5px; color: rgba(233,237,239,0.6);
  margin: 4px 0 -2px 10px; user-select: none;
}
.ls-tick { font-size: 14px; color: rgba(233,237,239,0.6); }
.ls-tick.is-seen { color: var(--wa-tick); }

/* Compose */
.ls-reply {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 14px;
  background: var(--wa-head);
  flex: none;
}
.ls-reply textarea {
  flex: 1;
  background: #2a3942;
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--wa-txt);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 140px;
  line-height: 1.4;
}
.ls-reply textarea::placeholder { color: var(--wa-mut); }
.ls-reply textarea:focus { outline: none; }
.ls-reply__send {
  flex: none;
  width: 44px; height: 44px;
  border: none; border-radius: 50%;
  background: #00a884;
  color: #0b141a;
  font-size: 20px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background 0.15s ease, transform 0.15s ease;
}
.ls-reply__send:hover { background: #06cf9c; transform: scale(1.05); }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .ls-layout { grid-template-columns: 1fr; }
  .ls-settings__grid { grid-template-columns: 1fr; }
  .ls-thread__msgs { padding: 14px 16px; }
  .ls-msg { max-width: 85%; }
}
