/* GateSig Support Chat Widget — Embedded on all gatesig.com pages */
/* Floating bottom-right chat button + expandable chat window */

:root {
  --gs-primary: #2563eb;
  --gs-primary-hover: #1d4ed8;
  --gs-bg: #ffffff;
  --gs-bg-secondary: #f8fafc;
  --gs-text: #1e293b;
  --gs-text-muted: #64748b;
  --gs-border: #e2e8f0;
  --gs-code-bg: #e2e8f0;
  --gs-code-block-bg: #1e293b;
  --gs-code-block-text: #e2e8f0;
  --gs-radius: 12px;
  --gs-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

/* Dark mode — follows system preference */
@media (prefers-color-scheme: dark) {
  :root {
    --gs-primary: #3b82f6;
    --gs-primary-hover: #2563eb;
    --gs-bg: #1e293b;
    --gs-bg-secondary: #334155;
    --gs-text: #f1f5f9;
    --gs-text-muted: #94a3b8;
    --gs-border: #475569;
    --gs-code-bg: #475569;
    --gs-code-block-bg: #0f172a;
    --gs-code-block-text: #e2e8f0;
    --gs-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  }
}

/* Toggle button — floating bottom-right */
#gs-chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--gs-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: var(--gs-shadow);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
  font-size: 24px;
}
#gs-chat-toggle:hover {
  background: var(--gs-primary-hover);
  transform: scale(1.05);
}
#gs-chat-toggle[data-open="true"] {
  display: none;
}

/* Unread badge */
.gs-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  border-radius: 50%;
  min-width: 20px;
  height: 20px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* Chat window */
#gs-chat-window {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 400px;
  height: 520px;
  background: var(--gs-bg);
  border-radius: var(--gs-radius);
  box-shadow: var(--gs-shadow);
  z-index: 99999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
#gs-chat-window.gs-open {
  display: flex;
}

/* Header */
#gs-chat-header {
  background: var(--gs-primary);
  color: #fff;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#gs-chat-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
#gs-chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 20px;
  padding: 0;
  line-height: 1;
  opacity: 0.8;
}
#gs-chat-close:hover {
  opacity: 1;
}

/* Messages area */
#gs-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Message bubbles */
.gs-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}
.gs-msg-user {
  align-self: flex-end;
  background: var(--gs-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.gs-msg-agent {
  align-self: flex-start;
  background: var(--gs-bg-secondary);
  color: var(--gs-text);
  border: 1px solid var(--gs-border);
  border-bottom-left-radius: 4px;
}

/* Links in agent messages */
.gs-msg-agent a {
  color: var(--gs-primary);
  text-decoration: underline;
}

/* Code blocks in agent messages */
.gs-msg-agent code {
  background: var(--gs-code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.gs-msg-agent pre {
  background: var(--gs-code-block-bg);
  color: var(--gs-code-block-text);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 13px;
  margin: 8px 0;
}
.gs-msg-agent pre code {
  background: none;
  padding: 0;
  color: inherit;
}

/* Code block copy button */
.gs-code-wrapper {
  position: relative;
}
.gs-copy-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(255, 255, 255, 0.15);
  color: var(--gs-code-block-text);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}
.gs-code-wrapper:hover .gs-copy-btn {
  opacity: 1;
}
.gs-copy-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Typing indicator */
.gs-typing {
  align-self: flex-start;
  padding: 10px 14px;
  background: var(--gs-bg-secondary);
  border: 1px solid var(--gs-border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  font-size: 14px;
  color: var(--gs-text-muted);
  animation: gs-pulse 1.5s infinite;
}
@keyframes gs-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Input area */
#gs-chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--gs-border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
#gs-chat-input {
  flex: 1;
  border: 1px solid var(--gs-border);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  font-family: inherit;
  background: var(--gs-bg);
  color: var(--gs-text);
}
#gs-chat-input:focus {
  border-color: var(--gs-primary);
}
#gs-chat-input::placeholder {
  color: var(--gs-text-muted);
}
#gs-chat-send {
  background: var(--gs-primary);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
#gs-chat-send:hover {
  background: var(--gs-primary-hover);
}

/* Powered by footer */
#gs-chat-footer {
  text-align: center;
  padding: 6px;
  font-size: 11px;
  color: var(--gs-text-muted);
  border-top: 1px solid var(--gs-border);
  flex-shrink: 0;
}
#gs-chat-footer a {
  color: var(--gs-primary);
  text-decoration: none;
}

/* Mobile responsive */
@media (max-width: 480px) {
  #gs-chat-window {
    width: calc(100vw - 16px);
    height: calc(100% - 80px);
    bottom: 8px;
    right: 8px;
    border-radius: 16px;
    max-height: calc(100dvh - 80px);
  }
  #gs-chat-input-area {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}
