/* ==========================================================================
   FSCS Live Support Chat Widget - Official Regulatory Theme
   ========================================================================== */

:root {
  --chat-primary: #4b1a6d;
  --chat-primary-dark: #371152;
  --chat-navy: #001f3f;
  --chat-accent: #059669;
  --chat-accent-light: #10b981;
  --chat-bg: #f8fafc;
  --chat-border: #e2e8f0;
  --chat-text-dark: #0f172a;
  --chat-text-muted: #64748b;
  --chat-bubble-user: linear-gradient(135deg, #4b1a6d 0%, #6b21a8 100%);
  --chat-bubble-operator: #ffffff;
}

/* Chat Launcher Button */
.fscs-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9990;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--chat-primary);
  color: #ffffff;
  border: none;
  border-radius: 50px;
  padding: 12px 20px 12px 16px;
  box-shadow: 0 10px 25px rgba(75, 26, 109, 0.4), 0 4px 10px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  outline: none;
}

.fscs-chat-launcher:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 14px 30px rgba(75, 26, 109, 0.5), 0 6px 12px rgba(0, 0, 0, 0.15);
  background: #592280;
}

.fscs-chat-launcher:active {
  transform: translateY(0) scale(0.98);
}

.fscs-launcher-icon-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
}

.fscs-launcher-pulse {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  background: var(--chat-accent-light);
  border-radius: 50%;
  border: 2px solid #ffffff;
  animation: pulseGreen 2s infinite;
}

@keyframes pulseGreen {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1.15); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.fscs-launcher-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  min-width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border-radius: 10px;
  padding: 0 5px;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Chat Backdrop for Mobile */
.fscs-chat-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 9998;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.fscs-chat-backdrop.active {
  display: block;
  opacity: 1;
}

/* Chat Main Window */
.fscs-chat-window {
  position: fixed;
  bottom: 88px;
  right: 24px;
  width: 390px;
  height: 600px;
  max-height: calc(100vh - 110px);
  background: #ffffff;
  border-radius: 18px;
  box-shadow: 0 20px 45px rgba(0, 31, 63, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.06);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.fscs-chat-window.active {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Chat Header */
.fscs-chat-header {
  background: linear-gradient(135deg, #001f3f 0%, #210d3a 50%, #4b1a6d 100%);
  color: #ffffff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
}

.fscs-chat-officer-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.fscs-officer-avatar-wrap {
  position: relative;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
}

.fscs-officer-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #e2e8f0;
  border: 2px solid #ffffff;
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.fscs-officer-status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: #10b981;
  border-radius: 50%;
  border: 2px solid #ffffff;
}

.fscs-officer-name {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  color: #ffffff;
  display: flex;
  align-items: center;
  gap: 6px;
}

.fscs-verified-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  background: #10b981;
  border-radius: 50%;
  color: #fff;
  font-size: 10px;
}

.fscs-officer-role {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 2px;
  display: block;
}

.fscs-case-tag {
  display: inline-block;
  font-size: 10px;
  font-family: monospace;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.15);
  padding: 1px 6px;
  border-radius: 4px;
  color: #f1f5f9;
  margin-top: 3px;
}

.fscs-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fscs-chat-btn-icon {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease;
  font-size: 16px;
}

.fscs-chat-btn-icon:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Security Notice Bar */
.fscs-chat-security-bar {
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
  padding: 6px 14px;
  font-size: 11px;
  color: #475569;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}

/* Messages Area */
.fscs-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.fscs-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.fscs-chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

/* Message Bubbles */
.fscs-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: msgPop 0.2s ease-out;
}

@keyframes msgPop {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fscs-msg-row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.fscs-msg-row.operator {
  align-self: flex-start;
  align-items: flex-start;
}

.fscs-msg-row.system {
  align-self: center;
  align-items: center;
  max-width: 90%;
}

.fscs-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
}

.fscs-msg-row.user .fscs-msg-bubble {
  background: var(--chat-bubble-user);
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 3px 10px rgba(75, 26, 109, 0.25);
}

.fscs-msg-row.operator .fscs-msg-bubble {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.fscs-msg-row.system .fscs-msg-bubble {
  background: #e2e8f0;
  color: #475569;
  font-size: 11.5px;
  padding: 5px 12px;
  border-radius: 20px;
  text-align: center;
}

.fscs-msg-info {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  font-size: 10.5px;
  color: #94a3b8;
}

.fscs-msg-row.user .fscs-msg-info {
  justify-content: flex-end;
}

.fscs-msg-attachment-img {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 6px;
  cursor: pointer;
  border: 1px solid rgba(0,0,0,0.1);
  display: block;
}

/* Typing Indicator */
.fscs-chat-typing {
  display: none;
  align-self: flex-start;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  font-size: 12px;
  color: #64748b;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.fscs-chat-typing.active {
  display: flex;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Quick Suggestion Chips */
.fscs-chat-quick-chips {
  padding: 8px 14px;
  background: #f8fafc;
  border-top: 1px solid #f1f5f9;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  white-space: nowrap;
}

.fscs-chat-quick-chips::-webkit-scrollbar {
  display: none;
}

.fscs-chip-btn {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 16px;
  padding: 5px 12px;
  font-size: 11.5px;
  color: #334155;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.fscs-chip-btn:hover {
  border-color: var(--chat-primary);
  color: var(--chat-primary);
  background: #fbf7ff;
}

/* Chat Input Bar */
.fscs-chat-input-bar {
  padding: 12px 14px;
  background: #ffffff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.fscs-chat-attach-btn {
  background: transparent;
  border: none;
  color: #64748b;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.fscs-chat-attach-btn:hover {
  background: #f1f5f9;
  color: var(--chat-primary);
}

.fscs-chat-input {
  flex: 1;
  border: 1px solid #cbd5e1;
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  background: #f8fafc;
  color: #1e293b;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.fscs-chat-input:focus {
  border-color: var(--chat-primary);
  background: #ffffff;
}

.fscs-chat-send-btn {
  background: var(--chat-primary);
  color: #ffffff;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.fscs-chat-send-btn:hover {
  background: #592280;
  transform: scale(1.05);
}

.fscs-chat-send-btn:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
  transform: none;
}

/* Hidden file input */
.fscs-chat-file-input {
  display: none;
}

/* ==========================================================================
   Mobile Bottom-Sheet Adaptation
   ========================================================================== */
@media (max-width: 600px) {
  .fscs-chat-launcher {
    bottom: max(16px, calc(env(safe-area-inset-bottom) + 8px));
    right: 14px;
    padding: 9px 14px;
    font-size: 12px;
    z-index: 9999;
  }
  .fscs-launcher-text {
    display: inline;
  }

  .fscs-chat-window {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 88vh;
    max-height: 88vh;
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.25);
    transform: translateY(100%);
    z-index: 100000;
  }

  .fscs-chat-window.active {
    transform: translateY(0);
  }

  .fscs-chat-header {
    padding: 14px 16px;
    border-radius: 22px 22px 0 0;
  }

  /* Grab handle on mobile */
  .fscs-chat-header::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
  }

  .fscs-chat-input-bar {
    padding: 10px 12px max(14px, env(safe-area-inset-bottom)) 12px;
  }
}
