/* SpectrumCodes Live Chat — front-end widget.
   Mirrors the theme's dark / cyan aesthetic (spectrum.css tokens). */
#spectrum-chat {
  --sc-bg:       #020817;
  --sc-bg-2:     #0D1117;
  --sc-surface:  rgba(255, 255, 255, 0.04);
  --sc-surface2: rgba(255, 255, 255, 0.07);
  --sc-border:   rgba(255, 255, 255, 0.08);
  --sc-cyan:     #06B6D4;
  --sc-pink:     #EC4899;
  --sc-text:     #F1F5F9;
  --sc-muted:    #94A3B8;
  --sc-subtle:   #475569;

  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 99990;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  direction: ltr;
}

html[dir="rtl"] #spectrum-chat { right: auto; left: 24px; }

/* ── Launcher bubble ─────────────────────────────────────────── */
.spectrum-chat-launcher {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, var(--sc-cyan), #0891b2);
  box-shadow: 0 10px 30px rgba(6, 182, 212, 0.4), 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.spectrum-chat-launcher:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 14px 38px rgba(6, 182, 212, 0.5); }
.spectrum-chat-launcher:active { transform: translateY(-1px) scale(0.99); }

.spectrum-chat-launcher-icon {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease, transform 0.25s ease;
}
.spectrum-chat-icon-close { opacity: 0; transform: rotate(-45deg) scale(0.6); }
#spectrum-chat.is-open .spectrum-chat-icon-chat { opacity: 0; transform: rotate(45deg) scale(0.6); }
#spectrum-chat.is-open .spectrum-chat-icon-close { opacity: 1; transform: rotate(0) scale(1); }

.spectrum-chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--sc-pink);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--sc-bg);
}

/* Attention pulse when a new message arrives while closed */
@keyframes spectrum-chat-pulse {
  0%   { box-shadow: 0 10px 30px rgba(6, 182, 212, 0.4), 0 0 0 0 rgba(236, 72, 153, 0.5); }
  70%  { box-shadow: 0 10px 30px rgba(6, 182, 212, 0.4), 0 0 0 14px rgba(236, 72, 153, 0); }
  100% { box-shadow: 0 10px 30px rgba(6, 182, 212, 0.4), 0 0 0 0 rgba(236, 72, 153, 0); }
}
#spectrum-chat.has-unread:not(.is-open) .spectrum-chat-launcher { animation: spectrum-chat-pulse 1.8s infinite; }

/* ── Teaser bubble (above the launcher) ──────────────────────── */
.spectrum-chat-teaser {
  position: absolute;
  bottom: 76px;
  right: 0;
  max-width: 244px;
  padding: 12px 32px 12px 15px;
  background: var(--sc-bg-2);
  border: 1px solid var(--sc-border);
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
  color: var(--sc-text);
  font-size: 0.85rem;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.spectrum-chat-teaser.is-in { opacity: 1; transform: none; }
.spectrum-chat-teaser[hidden] { display: none; }
.spectrum-chat-teaser::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 24px;
  width: 12px;
  height: 12px;
  background: var(--sc-bg-2);
  border-right: 1px solid var(--sc-border);
  border-bottom: 1px solid var(--sc-border);
  transform: rotate(45deg);
}
html[dir="rtl"] .spectrum-chat-teaser { right: auto; left: 0; padding: 12px 15px 12px 32px; text-align: right; }
html[dir="rtl"] .spectrum-chat-teaser::after { right: auto; left: 24px; }

.spectrum-chat-teaser-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--sc-muted);
  cursor: pointer;
  padding: 0;
  transition: color 0.2s, background 0.2s;
}
.spectrum-chat-teaser-close:hover { color: var(--sc-text); background: var(--sc-surface); }
html[dir="rtl"] .spectrum-chat-teaser-close { right: auto; left: 6px; }

/* ── Panel ───────────────────────────────────────────────────── */
.spectrum-chat-panel {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  background: var(--sc-bg-2);
  border: 1px solid var(--sc-border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55), 0 1px 0 rgba(255, 255, 255, 0.05) inset;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
html[dir="rtl"] .spectrum-chat-panel { right: auto; left: 0; transform-origin: bottom left; }
#spectrum-chat.is-open .spectrum-chat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.spectrum-chat-panel[hidden] { display: none; }

/* Header */
.spectrum-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(180deg, rgba(6, 182, 212, 0.10), transparent);
  border-bottom: 1px solid var(--sc-border);
}
.spectrum-chat-brand { display: flex; flex-direction: column; gap: 3px; }
.spectrum-chat-logo {
  font-family: 'Space Grotesk', 'Inter', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--sc-text);
  letter-spacing: -0.01em;
}
.spectrum-chat-logo span { color: var(--sc-cyan); }
.spectrum-chat-status { display: flex; align-items: center; gap: 6px; font-size: 0.72rem; color: var(--sc-muted); }
.spectrum-chat-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--sc-subtle); }
#spectrum-chat.is-online .spectrum-chat-dot {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.spectrum-chat-close {
  background: transparent;
  border: none;
  color: var(--sc-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  display: flex;
  transition: color 0.2s, background 0.2s;
}
.spectrum-chat-close:hover { color: var(--sc-text); background: var(--sc-surface); }

/* Body / messages */
.spectrum-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--sc-subtle) transparent;
}
.spectrum-chat-body::-webkit-scrollbar { width: 7px; }
.spectrum-chat-body::-webkit-scrollbar-thumb { background: var(--sc-subtle); border-radius: 4px; }

/* Empty-state placeholder (shown when there are no messages yet) */
.spectrum-chat-empty {
  margin: auto;
  text-align: center;
  color: var(--sc-muted);
  padding: 20px;
  max-width: 260px;
}
.spectrum-chat-empty-icon {
  display: inline-flex;
  width: 54px;
  height: 54px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(6, 182, 212, 0.12);
  color: var(--sc-cyan);
  margin-bottom: 14px;
}
.spectrum-chat-empty-text {
  font-size: 0.85rem;
  line-height: 1.55;
  margin: 0;
}

.spectrum-chat-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--sc-text);
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: spectrum-chat-in 0.25s ease;
}
@keyframes spectrum-chat-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.spectrum-chat-msg-visitor {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--sc-cyan), #0891b2);
  color: #fff;
  border-bottom-right-radius: 4px;
}
html[dir="rtl"] .spectrum-chat-msg-visitor { border-bottom-right-radius: 14px; border-bottom-left-radius: 4px; }

.spectrum-chat-msg-admin {
  align-self: flex-start;
  background: var(--sc-surface2);
  border: 1px solid var(--sc-border);
  border-bottom-left-radius: 4px;
}
html[dir="rtl"] .spectrum-chat-msg-admin { border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }

.spectrum-chat-msg-notice {
  align-self: center;
  max-width: 90%;
  text-align: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--sc-border);
  border-radius: 999px;
  color: var(--sc-muted);
  font-size: 0.75rem;
  padding: 6px 16px;
}

.spectrum-chat-time {
  display: block;
  margin-top: 4px;
  font-size: 0.65rem;
  opacity: 0.65;
}

/* Form */
.spectrum-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--sc-border);
  background: var(--sc-bg);
}
/* Scoped + !important so the parent theme's input/button styles can't win. */
#spectrum-chat .spectrum-chat-input {
  flex: 1;
  min-width: 0;
  background: transparent !important;
  border: 1px solid rgba(255, 255, 255, 0.18) !important;
  border-radius: 10px !important;
  padding: 11px 14px !important;
  color: #fff !important;
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1.4;
  outline: none !important;
  box-shadow: none !important;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#spectrum-chat .spectrum-chat-input::placeholder { color: var(--sc-muted) !important; opacity: 1; }
#spectrum-chat .spectrum-chat-input:focus {
  background: transparent !important;
  border-color: var(--sc-cyan) !important;
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.15) !important;
  color: #fff !important;
}

#spectrum-chat .spectrum-chat-send {
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  flex-shrink: 0;
  border: none !important;
  border-radius: 10px !important;
  padding: 0 !important;
  cursor: pointer;
  color: #fff !important;
  background: linear-gradient(135deg, var(--sc-cyan), #0891b2) !important;
  display: flex !important;
  align-items: center;
  justify-content: center;
  box-shadow: none !important;
  transition: transform 0.15s, opacity 0.2s;
}
#spectrum-chat .spectrum-chat-send:hover { transform: scale(1.06); }
#spectrum-chat .spectrum-chat-send:disabled { opacity: 0.5; cursor: default; transform: none; }
#spectrum-chat .spectrum-chat-send svg {
  display: block;
  width: 20px;
  height: 20px;
  stroke: #fff !important;
  color: #fff !important;
  fill: none !important;
}
html[dir="rtl"] #spectrum-chat .spectrum-chat-send svg { transform: scaleX(-1); }

@media (max-width: 480px) {
  #spectrum-chat { right: 16px; bottom: 16px; }
  html[dir="rtl"] #spectrum-chat { left: 16px; }
  .spectrum-chat-panel { width: calc(100vw - 24px); height: calc(100vh - 100px); }
}
