/* =========================================================
   Fallahi Exchange — Support chat widget
   ========================================================= */

.chat-fab {
  position: fixed;
  right: 22px; bottom: 22px;
  z-index: 9999;
  width: 60px; height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--gold-grad);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.25s;
  animation:
    chatFabIn 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) 0.6s backwards,
    chatFabNudge 5s ease-in-out 2.5s infinite;
}
@keyframes chatFabIn {
  from { transform: scale(0) translateY(40px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
@keyframes chatFabNudge {
  0%, 28%, 100% { transform: translateY(0); box-shadow: var(--shadow-lg); }
  8% { transform: translateY(-12px); box-shadow: 0 22px 44px rgba(0, 0, 0, 0.18); }
  16% { transform: translateY(0); box-shadow: var(--shadow-lg); }
  22% { transform: translateY(-6px); }
}
.chat-fab:hover {
  animation-play-state: paused;
  transform: translateY(-3px) scale(1.07);
}
.chat-fab:active { transform: scale(0.94); }
.chat-fab svg { width: 26px; height: 26px; }

.chat-panel {
  position: fixed;
  right: 22px; bottom: 94px;
  z-index: 9999;
  width: 340px;
  max-width: calc(100vw - 24px);
  height: 460px;
  max-height: calc(100vh - 120px);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.chat-panel.open { opacity: 1; transform: none; pointer-events: auto; }

.chat-header {
  background: linear-gradient(135deg, #1a1a1a, #0a0a0a);
  color: #fff;
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 2px solid var(--gold);
  gap: 10px;
}
.chat-head-text { display: flex; flex-direction: column; min-width: 0; }
.chat-title { font-weight: 700; font-size: 1rem; }
.chat-agent-line {
  font-size: 0.72rem;
  color: var(--gold-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: 1.1em;
}
.chat-head-actions { display: flex; align-items: center; gap: 8px; }
.chat-end {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.25s;
  white-space: nowrap;
}
.chat-end:hover { background: rgba(198, 40, 40, 0.85); border-color: transparent; }
.chat-close {
  background: none; border: none;
  color: #fff; font-size: 1.4rem; line-height: 1;
  cursor: pointer; padding: 0 2px;
}
.chat-closed-note {
  align-self: center;
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink-soft);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 0.85rem;
  text-align: center;
  max-width: 90%;
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex; flex-direction: column; gap: 8px;
  background: transparent;
}

.chat-identify { display: flex; flex-direction: column; gap: 10px; }
.chat-identify input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.65);
  outline: none;
}
.chat-identify input:focus { border-color: var(--gold); background: rgba(255, 255, 255, 0.9); }
.chat-submit {
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--gold-grad);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
}
.chat-captcha-row { display: flex; align-items: center; gap: 8px; }
.chat-captcha-row img {
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 8px;
  cursor: pointer;
  background: #ffffff;
}
.chat-captcha-row input { flex: 1; min-width: 0; text-align: center; letter-spacing: 0.15em; text-transform: uppercase; }

.chat-msg {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}
.chat-msg.visitor {
  align-self: flex-end;
  background: var(--gold-grad);
  color: #fff;
  border-bottom-right-radius: 3px;
  box-shadow: 0 4px 14px rgba(234, 179, 8, 0.25);
}
.chat-msg.support {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.75);
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-bottom-left-radius: 3px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.chat-input-row {
  display: flex; gap: 8px;
  padding: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.45);
  flex-shrink: 0;
}
.chat-input-row input {
  flex: 1; min-width: 0;
  padding: 11px 13px;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.65);
  outline: none;
}
.chat-input-row input:focus { border-color: var(--gold); }
.chat-send {
  width: 44px; flex-shrink: 0;
  border: none;
  border-radius: 10px;
  background: var(--gold-grad);
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.chat-send svg { width: 18px; height: 18px; }

/* ---------- Dark mode ---------- */
html[data-theme="dark"] .chat-panel {
  background: rgba(16, 16, 20, 0.72);
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
html[data-theme="dark"] .chat-body { background: transparent; }
html[data-theme="dark"] .chat-identify input {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--ink);
}
html[data-theme="dark"] .chat-identify input:focus { background: rgba(255, 255, 255, 0.14); border-color: var(--gold); }
html[data-theme="dark"] .chat-msg.support {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--ink);
}
html[data-theme="dark"] .chat-msg.visitor { color: #0a0a0a; }
html[data-theme="dark"] .chat-input-row {
  border-top-color: rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.05);
}
html[data-theme="dark"] .chat-input-row input {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--ink);
}
html[data-theme="dark"] .chat-closed-note {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--ink-soft);
}
html[data-theme="dark"] .chat-captcha-row img { background: #ffffff; }
