/* ============================================================
   StagePass — AI Chat Widget  (Multi-view: Home | Chat | History)
   ============================================================ */

/* ── Variables ── */
:root {
  --chat-primary:   #2563EB;
  --chat-secondary: #475569;
  --chat-gradient:  linear-gradient(135deg, #2563EB 0%, #334155 100%);
  --chat-bg:        #0d0d1a;
  --chat-surface:   #13131f;
  --chat-border:    rgba(255,255,255,0.22);
  --chat-text:      #e2e8f0;
  --chat-muted:     #94a3b8;
  --chat-faint:     #475569;
  --chat-radius:    16px;
  --chat-radius-sm: 10px;
  --chat-shadow:    0 25px 60px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.14);
}

/* ── FAB Button ── */
#sp-chat-fab {
  position: fixed;
  bottom: 24px; right: 24px;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--chat-gradient);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 32px rgba(37,99,235,0.5), 0 0 0 0 rgba(37,99,235,0.4);
  z-index: 9998;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: sp-chat-pulse 2.5s ease-in-out infinite;
}
#sp-chat-fab:hover { transform: scale(1.1); }
#sp-chat-fab svg { width: 28px; height: 28px; fill: #fff; transition: transform 0.3s ease; }
#sp-chat-fab .sp-fab-icon-chat  { display: block; }
#sp-chat-fab .sp-fab-icon-close { display: none;  }
#sp-chat-fab.open .sp-fab-icon-chat  { display: none;  }
#sp-chat-fab.open .sp-fab-icon-close { display: block; }

#sp-chat-badge {
  position: absolute; top: -2px; right: -2px;
  width: 20px; height: 20px;
  background: #EF4444; border-radius: 50%;
  border: 2px solid var(--chat-bg, #080810);
  font-size: 0.65rem; font-weight: 700; color: #fff;
  display: none; align-items: center; justify-content: center;
}

/* ── Chat Window ── */
#sp-chat-window {
  position: fixed;
  bottom: 96px; right: 24px;
  width: 380px;
  height: min(580px, calc(100dvh - 120px));
  max-height: calc(100dvh - 120px);
  background: var(--chat-bg);
  border: 1.5px solid rgba(255,255,255,0.3);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex; flex-direction: column;
  z-index: 9999;
  overflow: hidden;
  transform: scale(0.85) translateY(20px);
  transform-origin: bottom right;
  opacity: 0; pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.34,1.56,0.64,1), opacity 0.25s ease;
}
#sp-chat-window.open {
  transform: scale(1) translateY(0);
  opacity: 1; pointer-events: all;
}

/* ── Header ── */
.sp-chat-header {
  background: var(--chat-gradient);
  padding: 0.8rem 0.875rem;
  display: flex; align-items: center; gap: 0.6rem;
  flex-shrink: 0; position: relative;
}
.sp-chat-header::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0;
  height: 1px; background: rgba(255,255,255,0.15);
}
.sp-chat-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.62rem; font-weight: 800; color: #fff; letter-spacing: 0.03em; flex-shrink: 0;
  border: 2px solid rgba(255,255,255,0.3);
}
.sp-chat-header-info { flex: 1; min-width: 0; }
.sp-chat-header-name  { font-weight: 700; font-size: 0.9rem; color: #fff; }
.sp-chat-header-status {
  font-size: 0.72rem; color: rgba(255,255,255,0.8);
  display: flex; align-items: center; gap: 0.3rem; margin-top: 0.1rem;
}
.sp-chat-header-status::before {
  content: ''; width: 6px; height: 6px;
  background: #4ADE80; border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 5px #4ADE80;
  animation: sp-chat-blink 2s ease-in-out infinite;
}
.sp-header-btn {
  background: rgba(255,255,255,0.15); border: none; border-radius: 50%;
  width: 32px; height: 32px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #fff; transition: background 0.2s; flex-shrink: 0;
}
.sp-header-btn:hover { background: rgba(255,255,255,0.28); }
.sp-header-btn svg   { width: 18px; height: 18px; fill: #fff; }

/* ── View System ── */
.sp-view { display: none; }
.sp-view.active {
  display: flex; flex: 1; flex-direction: column;
  overflow: hidden; min-height: 0;
}

/* ─────────────────── VIEW: HOME ─────────────────── */
#sp-view-home.active {
  overflow: hidden;
}
.sp-home-content {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  scrollbar-width: thin; scrollbar-color: rgba(37,99,235,0.3) transparent;
}
.sp-home-content::-webkit-scrollbar       { width: 4px; }
.sp-home-content::-webkit-scrollbar-thumb { background: rgba(37,99,235,0.3); border-radius: 2px; }
.sp-home-hero {
  padding: 1.75rem 1.25rem 1rem;
  text-align: center; flex-shrink: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(37,99,235,0.18) 0%, transparent 70%);
}

/* Logo orb */
.sp-home-logo {
  position: relative;
  width: 64px; height: 64px;
  margin: 0 auto 1rem;
  display: flex; align-items: center; justify-content: center;
}
.sp-home-logo-ring {
  position: absolute; inset: 0;
  border-radius: 50%;
  background: var(--chat-gradient);
  opacity: 0.18;
  animation: sp-logo-pulse 2.8s ease-in-out infinite;
}
.sp-home-logo-ring::before {
  content: '';
  position: absolute; inset: -6px;
  border-radius: 50%;
  border: 1.5px solid rgba(37,99,235,0.3);
  animation: sp-logo-pulse 2.8s ease-in-out infinite 0.4s;
}
.sp-home-logo-inner {
  position: relative;
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--chat-gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; font-weight: 900; color: #fff; letter-spacing: 0.04em;
  box-shadow: 0 8px 28px rgba(37,99,235,0.55), 0 0 0 2px rgba(255,255,255,0.12);
}
@keyframes sp-logo-pulse {
  0%,100% { transform: scale(1); opacity: 0.18; }
  50%      { transform: scale(1.12); opacity: 0.28; }
}

.sp-home-hero h3 {
  font-size: 1.05rem; font-weight: 800; color: #f1f5f9;
  margin: 0 0 0.3rem; letter-spacing: -0.01em;
}
.sp-home-hero p {
  font-size: 0.78rem; color: var(--chat-muted); margin: 0 0 0.75rem; line-height: 1.5;
}
.sp-home-status-pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  background: rgba(74,222,128,0.1); border: 1px solid rgba(74,222,128,0.25);
  border-radius: 20px; padding: 0.2rem 0.7rem;
  font-size: 0.68rem; color: #4ADE80; font-weight: 600;
}
.sp-home-status-pill::before {
  content: ''; width: 5px; height: 5px; border-radius: 50%;
  background: #4ADE80; box-shadow: 0 0 5px #4ADE80;
  animation: sp-chat-blink 2s ease-in-out infinite;
}

.sp-home-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(124,58,237,0.25), transparent);
  margin: 0 1.25rem 0.75rem;
  flex-shrink: 0;
}

/* ── Session-manager state ── */
.sp-home-compact-hero {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.85rem 1.25rem 0.7rem; flex-shrink: 0;
}
.sp-home-logo-sm {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--chat-gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.63rem; font-weight: 900; color: #fff; letter-spacing: 0.04em;
  box-shadow: 0 4px 14px rgba(37,99,235,0.45); flex-shrink: 0;
}
.sp-home-compact-info { flex: 1; min-width: 0; }
.sp-home-compact-title { font-size: 0.92rem; font-weight: 800; color: #f1f5f9; }
.sp-home-compact-status {
  display: flex; align-items: center; gap: 0.3rem;
  font-size: 0.68rem; color: #60a5fa; margin-top: 0.12rem;
}
.sp-status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #4ADE80; box-shadow: 0 0 5px #4ADE80;
  animation: sp-chat-blink 2s ease-in-out infinite; flex-shrink: 0;
}
.sp-home-sess-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1.1rem 0.35rem; flex-shrink: 0;
}
.sp-home-sess-label {
  font-size: 0.7rem; font-weight: 700; color: var(--chat-muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.sp-home-hist-btn {
  background: none; border: none; color: #93c5fd;
  font-size: 0.72rem; font-weight: 600; cursor: pointer; padding: 0; transition: color 0.2s;
}
.sp-home-hist-btn:hover { color: #bfdbfe; }
.sp-home-sess-list { padding: 0 0.65rem; flex: 1; }
.sp-home-sess-card {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.7rem; border-radius: 10px; cursor: pointer;
  transition: background 0.18s; border: 1px solid transparent; margin-bottom: 0.25rem;
}
.sp-home-sess-card:hover { background: rgba(37,99,235,0.1); border-color: rgba(37,99,235,0.2); }
.sp-home-sess-card.sp-sess-active {
  background: rgba(37,99,235,0.12); border-color: rgba(37,99,235,0.28);
}
.sp-home-sess-icon {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: rgba(37,99,235,0.15);
  display: flex; align-items: center; justify-content: center;
}
.sp-home-sess-icon svg { width: 15px; height: 15px; fill: #93c5fd; }
.sp-home-sess-card.sp-sess-active .sp-home-sess-icon { background: rgba(37,99,235,0.25); }
.sp-home-sess-body { flex: 1; min-width: 0; }
.sp-home-sess-preview {
  font-size: 0.8rem; color: var(--chat-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0.12rem;
}
.sp-home-sess-meta { font-size: 0.67rem; color: var(--chat-faint); }
.sp-sess-cur { color: #93c5fd; font-weight: 600; }
.sp-home-sess-chevron { width: 17px; height: 17px; fill: var(--chat-faint); flex-shrink: 0; }
.sp-home-new-wrap { padding: 0.45rem 0.65rem 0.55rem; flex-shrink: 0; }
.sp-home-new-chat-btn {
  width: 100%; background: rgba(37,99,235,0.1); border: 1px solid rgba(37,99,235,0.28);
  border-radius: 10px; padding: 0.62rem 1rem;
  color: #93c5fd; font-size: 0.82rem; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  transition: background 0.2s, border-color 0.2s;
}
.sp-home-new-chat-btn:hover { background: rgba(37,99,235,0.2); border-color: rgba(37,99,235,0.45); }
.sp-home-new-chat-btn svg { width: 16px; height: 16px; fill: #93c5fd; }

.sp-chat-suggestions {
  padding: 0 1rem 0.75rem; display: flex; flex-wrap: wrap; gap: 0.4rem; flex-shrink: 0;
  justify-content: center;
}
.sp-suggestion {
  background: rgba(37,99,235,0.1); border: 1px solid rgba(37,99,235,0.22);
  border-radius: 20px; padding: 0.32rem 0.75rem;
  font-size: 0.76rem; color: #93c5fd; cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s; white-space: nowrap; font-weight: 500;
}
.sp-suggestion:hover { background: rgba(37,99,235,0.22); border-color: rgba(37,99,235,0.4); transform: translateY(-1px); }

/* Widget-level bottom bar — always pinned, shown on Home view only */
.sp-widget-bottom { border-top: 1px solid var(--chat-border); background: var(--chat-bg); flex-shrink: 0; }

.sp-home-input-area {
  padding: 0.5rem 1rem 0.65rem;
  display: flex; gap: 0.5rem; align-items: center;
  background: var(--chat-bg); flex-shrink: 0;
}
.sp-home-input {
  flex: 1; background: rgba(255,255,255,0.05);
  border: 1px solid var(--chat-border); border-radius: 22px;
  padding: 0.55rem 1rem; color: var(--chat-text);
  font-size: 16px; font-family: inherit;
  outline: none; transition: border-color 0.2s;
}
.sp-home-input:focus { border-color: rgba(37,99,235,0.5); background: rgba(255,255,255,0.07); }
.sp-home-input::placeholder { color: var(--chat-faint); }
.sp-home-send {
  width: 38px; height: 38px; background: var(--chat-gradient);
  border: none; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: transform 0.2s, opacity 0.2s;
  box-shadow: 0 4px 12px rgba(37,99,235,0.35);
}
.sp-home-send:hover    { transform: scale(1.08); }
.sp-home-send:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.sp-home-send svg { width: 17px; height: 17px; fill: #fff; }

.sp-home-footer { padding: 0.5rem 1rem 0.2rem; flex-shrink: 0; }
.sp-human-btn {
  width: 100%;
  background: rgba(37,99,235,0.1); border: 1px solid rgba(37,99,235,0.3);
  border-radius: var(--chat-radius-sm); padding: 0.7rem 1rem;
  color: #93c5fd; font-size: 0.83rem; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  transition: background 0.2s, border-color 0.2s;
}
.sp-human-btn:hover { background: rgba(37,99,235,0.2); border-color: rgba(37,99,235,0.5); }
.sp-human-btn svg { width: 17px; height: 17px; fill: #93c5fd; }

/* ─────────────────── VIEW: CHAT ─────────────────── */
.sp-chat-messages {
  flex: 1; overflow-y: auto; padding: 1rem;
  display: flex; flex-direction: column; gap: 0.75rem;
  scroll-behavior: smooth; min-height: 0;
}
.sp-chat-messages::-webkit-scrollbar       { width: 4px; }
.sp-chat-messages::-webkit-scrollbar-track { background: transparent; }
.sp-chat-messages::-webkit-scrollbar-thumb { background: rgba(37,99,235,0.3); border-radius: 2px; }

/* Message Bubbles */
.sp-msg {
  display: flex; flex-direction: column; gap: 0.3rem;
  animation: sp-msg-in 0.25s ease both;
  width: 100%;
}
.sp-msg.bot  { align-items: flex-start; }
.sp-msg.user { align-items: flex-end; }

.sp-msg-header {
  display: flex; align-items: center; gap: 0.4rem;
}
.sp-msg.user .sp-msg-header { flex-direction: row-reverse; }

.sp-msg-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--chat-gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.5rem; font-weight: 800; color: #fff; letter-spacing: 0.03em;
  flex-shrink: 0;
}
.sp-msg-sender {
  font-size: 0.68rem; font-weight: 600; color: var(--chat-muted);
}
.sp-msg.bot  .sp-msg-sender { color: #93c5fd; }
.sp-msg.user .sp-msg-sender { color: rgba(255,255,255,0.7); }

.sp-msg-bubble {
  display: inline-block; max-width: 100%; padding: 0.65rem 0.9rem; border-radius: 14px;
  font-size: 0.875rem; line-height: 1.55;
  word-wrap: break-word; word-break: break-word;
  box-sizing: border-box;
}
.sp-msg.bot  .sp-msg-bubble { background: var(--chat-surface); border: 1px solid var(--chat-border); color: var(--chat-text); border-top-left-radius: 4px; }
.sp-msg.user .sp-msg-bubble { background: var(--chat-gradient); color: #fff; border-top-right-radius: 4px; box-shadow: 0 4px 12px rgba(37,99,235,0.3); }
.sp-msg-time { font-size: 0.65rem; color: var(--chat-faint); padding: 0 0.2rem; }
.sp-msg.user .sp-msg-time { text-align: right; }
/* Grouped messages: hide header, reduce top gap */
.sp-msg.sp-grouped { margin-top: -0.35rem; }
.sp-msg.sp-grouped .sp-msg-header { display: none; }
.sp-msg.sp-grouped .sp-msg-bubble { border-radius: 14px; }
.sp-msg.bot .sp-msg-bubble strong { color: #93c5fd; font-weight: 700; }
.sp-msg.bot .sp-msg-bubble em     { color: #c4b5fd; }

/* Typing */
.sp-typing-dots {
  background: var(--chat-surface); border: 1px solid var(--chat-border);
  border-radius: 14px; border-top-left-radius: 4px;
  padding: 0.65rem 1rem; display: inline-flex; gap: 4px; align-items: center;
}
.sp-typing-dot { width: 7px; height: 7px; background: var(--chat-muted); border-radius: 50%; animation: sp-dot-bounce 1.2s ease-in-out infinite; }
.sp-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.sp-typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Streaming cursor */
.sp-msg-bubble.sp-streaming::after {
  content: '▋';
  display: inline-block;
  color: #93c5fd;
  opacity: 1;
  animation: sp-cursor-blink 0.7s ease-in-out infinite;
  margin-left: 1px;
}
@keyframes sp-cursor-blink {
  0%,100% { opacity: 1; }
  50%      { opacity: 0; }
}

/* Input Area */
.sp-chat-input-area {
  padding: 0.75rem 1rem; border-top: 1px solid var(--chat-border);
  display: flex; gap: 0.5rem; align-items: flex-end;
  background: var(--chat-surface); flex-shrink: 0;
}
.sp-chat-input {
  flex: 1; background: rgba(255,255,255,0.05);
  border: 1px solid var(--chat-border); border-radius: 22px;
  padding: 0.6rem 1rem; color: var(--chat-text); font-size: 16px; font-family: inherit;
  resize: none; outline: none; line-height: 1.4; max-height: 100px; min-height: 40px;
  transition: border-color 0.2s; scrollbar-width: none;
}
.sp-chat-input::-webkit-scrollbar { display: none; }
.sp-chat-input:focus       { border-color: rgba(37,99,235,0.5); background: rgba(255,255,255,0.07); }
.sp-chat-input::placeholder { color: var(--chat-faint); }
.sp-chat-send {
  width: 40px; height: 40px; background: var(--chat-gradient);
  border: none; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: transform 0.2s, opacity 0.2s;
  box-shadow: 0 4px 12px rgba(37,99,235,0.35);
}
.sp-chat-send:hover    { transform: scale(1.08); }
.sp-chat-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.sp-chat-send svg { width: 18px; height: 18px; fill: #fff; }

/* ─────────────────── VIEW: HISTORY ─────────────────── */
.sp-history-header {
  padding: 0.7rem 1rem 0.5rem;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--chat-border); flex-shrink: 0;
}
.sp-history-header span { font-size: 0.78rem; font-weight: 700; color: var(--chat-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.sp-hist-clear-btn {
  background: none; border: none; color: #f87171; font-size: 0.72rem;
  cursor: pointer; padding: 0.2rem 0.5rem; border-radius: 6px; transition: background 0.2s;
}
.sp-hist-clear-btn:hover { background: rgba(248,113,113,0.1); }

.sp-history-list {
  flex: 1; overflow-y: auto; padding: 0.5rem;
  scrollbar-width: thin; scrollbar-color: rgba(37,99,235,0.3) transparent; min-height: 0;
}
.sp-history-list::-webkit-scrollbar       { width: 4px; }
.sp-history-list::-webkit-scrollbar-thumb { background: rgba(37,99,235,0.3); border-radius: 2px; }

.sp-hist-item {
  display: flex; gap: 0.75rem; align-items: flex-start;
  padding: 0.75rem; border-radius: var(--chat-radius-sm); cursor: pointer;
  transition: background 0.2s; border: 1px solid transparent; margin-bottom: 0.25rem;
}
.sp-hist-item:hover  { background: rgba(37,99,235,0.08); border-color: rgba(37,99,235,0.15); }
.sp-hist-item.active { background: rgba(37,99,235,0.12); border-color: rgba(37,99,235,0.25); }
.sp-hist-icon {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(37,99,235,0.15);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
}
.sp-hist-info { flex: 1; min-width: 0; }
.sp-hist-preview { font-size: 0.82rem; color: var(--chat-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0.2rem; }
.sp-hist-meta   { font-size: 0.7rem; color: var(--chat-faint); }
.sp-hist-empty  { text-align: center; padding: 2.5rem 1rem; color: var(--chat-muted); font-size: 0.82rem; line-height: 1.8; }
.sp-hist-empty-icon { font-size: 2rem; display: block; margin-bottom: 0.5rem; }

.sp-history-footer { padding: 0.75rem 1rem; border-top: 1px solid var(--chat-border); flex-shrink: 0; }
.sp-new-chat-btn {
  width: 100%; background: var(--chat-gradient);
  border: none; border-radius: var(--chat-radius-sm);
  padding: 0.7rem; color: #fff; font-size: 0.83rem; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 0.4rem;
  transition: opacity 0.2s, transform 0.15s;
  box-shadow: 0 4px 15px rgba(37,99,235,0.4);
}
.sp-new-chat-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.sp-new-chat-btn svg { width: 18px; height: 18px; fill: #fff; }

/* ─────────────────── HUMAN SUPPORT OVERLAY ─────────────────── */
/* ── Human Support Full View ── */
.sp-support-view {
  position: absolute; inset: 0;
  background: var(--chat-bg);
  display: flex; flex-direction: column;
  z-index: 10;
  animation: sp-msg-in 0.2s ease both;
}
.sp-support-view-header {
  background: var(--chat-surface);
  border-bottom: 1px solid var(--chat-border);
  padding: 0.7rem 0.875rem;
  display: flex; align-items: center; gap: 0.6rem;
  flex-shrink: 0;
}
.sp-support-back {
  width: 32px; height: 32px; border-radius: 8px;
  background: rgba(255,255,255,0.06); border: 1px solid var(--chat-border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: background 0.15s;
}
.sp-support-back:hover { background: rgba(255,255,255,0.12); }
.sp-support-back svg { width: 18px; height: 18px; fill: var(--chat-muted); }
.sp-support-view-agent { display: flex; align-items: center; gap: 0.6rem; }
.sp-support-view-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #10B981, #059669);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sp-support-view-avatar svg { width: 20px; height: 20px; fill: #fff; }
.sp-support-view-name { font-size: 0.875rem; font-weight: 700; color: var(--chat-text); }
.sp-support-view-status { font-size: 0.72rem; color: var(--chat-muted); display: flex; align-items: center; gap: 4px; margin-top: 1px; }
.sp-sv-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.sp-sv-dot.waiting { background: #F59E0B; animation: sp-sv-pulse 1.4s ease-in-out infinite; }
.sp-sv-dot.online  { background: #10B981; }
.sp-sv-dot.offline { background: #6B7280; }
@keyframes sp-sv-pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

.sp-support-view-msgs {
  flex: 1; overflow-y: auto; padding: 0.75rem 0.875rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  scroll-behavior: smooth;
}
.sp-sv-history-label {
  text-align: center; font-size: 0.68rem; color: var(--chat-faint);
  padding: 0.25rem 0; letter-spacing: 0.04em;
}
.sp-sv-hist { opacity: 0.6; }

/* Waiting bar */
.sp-sv-waiting-bar {
  padding: 0.625rem 0.875rem;
  border-top: 1px solid var(--chat-border);
  display: flex; align-items: center; gap: 0.6rem;
  font-size: 0.78rem; color: var(--chat-muted);
  flex-shrink: 0;
}
.sp-sv-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(37,99,235,0.2);
  border-top-color: var(--chat-primary);
  animation: sp-spin 0.8s linear infinite; flex-shrink: 0;
}
@keyframes sp-spin { to { transform: rotate(360deg); } }

/* Typing indicator in support view */
.sp-sv-typing {
  display: none; flex-direction: row; align-items: center; gap: 5px;
  padding: 4px 0.875rem 2px;
  font-size: 0.72rem; color: var(--chat-muted); font-style: italic;
  flex-shrink: 0;
}
.sp-sv-typing-dot {
  display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--chat-muted);
  animation: sp-dot-bounce 1.2s ease-in-out infinite;
}
.sp-sv-typing-dot:nth-child(2) { animation-delay: .2s; }
.sp-sv-typing-dot:nth-child(3) { animation-delay: .4s; }

/* Input area */
.sp-support-view-input {
  border-top: 1px solid var(--chat-border);
  padding: 0.4rem 0.875rem 0.6rem;
  display: flex; flex-direction: column; gap: 0; align-items: stretch;
  flex-shrink: 0; background: var(--chat-surface);
}
.sp-support-view-input-row {
  display: flex; align-items: flex-end; gap: 0.5rem;
}
.sp-support-view-input textarea {
  flex: 1; background: rgba(255,255,255,0.05);
  border: 1px solid var(--chat-border); border-radius: 10px;
  padding: 0.55rem 0.75rem; color: var(--chat-text);
  font-size: 16px; outline: none; resize: none; /* 16px prevents iOS zoom */
  max-height: 80px; line-height: 1.45;
  transition: border-color 0.2s;
  font-family: inherit;
}
.sp-support-view-input textarea:focus { border-color: var(--chat-primary); }
.sp-support-view-input textarea::placeholder { color: var(--chat-faint); }
.sp-support-view-input button {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--chat-gradient); border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
}
.sp-support-view-input button:hover { opacity: 0.9; }
.sp-support-view-input button:active { transform: scale(0.93); }
.sp-support-view-input button svg { width: 18px; height: 18px; fill: #fff; }

/* Legacy overlay styles kept for any other usage */
.sp-support-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.75); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 10; animation: sp-msg-in 0.2s ease both;
}
.sp-support-card {
  background: var(--chat-surface); border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius); padding: 1.5rem; margin: 1rem;
  text-align: center; box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  width: 100%;
}
.sp-support-icon  { font-size: 2.25rem; margin-bottom: 0.5rem; }
.sp-support-card h3 { color: #e2e8f0; font-size: 1.05rem; margin: 0 0 0.4rem; }
.sp-support-card p  { color: var(--chat-muted); font-size: 0.8rem; margin: 0 0 1.1rem; line-height: 1.6; }
.sp-support-contacts { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.875rem; }
.sp-support-link {
  display: flex; align-items: center; gap: 0.625rem;
  padding: 0.7rem 1rem; border-radius: var(--chat-radius-sm);
  font-size: 0.83rem; font-weight: 600; text-decoration: none; transition: background 0.2s;
}
.sp-support-link.email    { background: rgba(37,99,235,0.15); color: #93c5fd; }
.sp-support-link.email:hover    { background: rgba(37,99,235,0.25); }
.sp-support-link.telegram { background: rgba(0,136,204,0.15); color: #67c0e3; }
.sp-support-link.telegram:hover { background: rgba(0,136,204,0.25); }
.sp-support-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.sp-support-link.email    svg { fill: #93c5fd; }
.sp-support-link.telegram svg { fill: #67c0e3; }
.sp-support-hours { font-size: 0.73rem; color: var(--chat-faint); margin-bottom: 0.875rem; }
.sp-support-close {
  background: rgba(255,255,255,0.08); border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius-sm); padding: 0.6rem 1.5rem;
  color: var(--chat-text); font-size: 0.83rem; cursor: pointer; transition: background 0.2s;
}
.sp-support-close:hover { background: rgba(255,255,255,0.12); }

/* ── Mobile bar adjustments ── */
body.has-mobile-bar #sp-chat-fab    { bottom: calc(68px + env(safe-area-inset-bottom) + 12px); }
body.has-mobile-bar #sp-chat-window { bottom: calc(68px + env(safe-area-inset-bottom) + 80px); }
body.has-mobile-bar #sp-chat-window { max-height: calc(100dvh - 68px - env(safe-area-inset-bottom) - 96px); }

/* ── Maximized: lock body scroll on iOS Safari ── */
body.sp-chat-maximized { -webkit-overflow-scrolling: touch; }

/* ── Animations ── */
@keyframes sp-chat-pulse {
  0%,100% { box-shadow: 0 8px 32px rgba(37,99,235,0.5), 0 0 0 0 rgba(37,99,235,0.4); }
  50%      { box-shadow: 0 8px 32px rgba(37,99,235,0.5), 0 0 0 8px rgba(37,99,235,0); }
}
@keyframes sp-chat-blink { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes sp-msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes sp-dot-bounce { 0%,80%,100% { transform: translateY(0); opacity: 0.6; } 40% { transform: translateY(-5px); opacity: 1; } }

/* ── Close button safe-area gap on mobile ── */
@media (max-width: 480px) {
  .sp-btn-close-gap { margin-left: 2px; }
}

/* ── Maximize / Minimize icon toggle ── */
.sp-header-btn .sp-icon-maximize,
.sp-header-btn .sp-icon-minimize { display: block; }

/* ── Prevent background scroll when maximized ── */
body.sp-chat-maximized {
  overflow: hidden !important;
  /* position:fixed + top set by JS (_lockBodyScroll) prevents scroll while keeping position */
  position: fixed !important;
  width: 100% !important;
  height: 100% !important;
  left: 0; right: 0;
}

/* ── Maximized state — Desktop: right half panel ── */
/* Use top/bottom anchoring (not dvh) so mobile browser chrome doesn't shift layout */
#sp-chat-window.sp-maximized {
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 50vw !important;
  height: auto !important;
  max-height: none !important;
  border-radius: 0 !important;
  transform: none !important;
  transition: width 0.3s ease, border-radius 0.3s ease;
  z-index: 10000;
}
body.sp-chat-maximized #sp-chat-fab {
  display: none;
}

/* ── Maximized state — Mobile: true fullscreen ── */
@media (max-width: 768px) {
  #sp-chat-window.sp-maximized {
    left: 0 !important;
    width: 100% !important;
  }
}

/* ── Responsive ── */
@media (max-width: 480px) {
  #sp-chat-window {
    width: calc(100vw - 16px);
    height: min(calc(100dvh - 110px), 520px);
    max-height: calc(100dvh - 110px);
    right: 8px; bottom: calc(76px + env(safe-area-inset-bottom));
    border-radius: var(--chat-radius) var(--chat-radius) var(--chat-radius-sm) var(--chat-radius-sm);
  }
  body.has-mobile-bar #sp-chat-window {
    bottom: calc(68px + env(safe-area-inset-bottom) + 76px);
    max-height: calc(100dvh - 68px - env(safe-area-inset-bottom) - 92px);
  }
  #sp-chat-fab { right: 16px; bottom: 20px; }
  body.has-mobile-bar #sp-chat-fab { bottom: calc(68px + env(safe-area-inset-bottom) + 12px); }
}
