/* ── Design Tokens ── */
#gc-chatbot-root :is(.gc-chatbot-window, .gc-chatbot-toggle) {
  --gc-bg-primary: #032340;
  --gc-btn-accent: #06a9ec;
  --gc-bg-surface: #ffffff;
  --gc-btn-info: #06a9ec;
  --gc-text-light: #ffffff;

  /* Derived tokens */
  --gc-bg-chat: #f0f4f8;
  --gc-text-body: #1e293b;
  --gc-text-muted: #64748b;
  --gc-border-subtle: rgba(3, 35, 64, 0.08);
  --gc-shadow-sm: 0 1px 3px rgba(3, 35, 64, 0.06);
  --gc-shadow-md: 0 8px 30px rgba(3, 35, 64, 0.12);
  --gc-shadow-lg: 0 16px 48px rgba(3, 35, 64, 0.18);
  --gc-radius: 16px;
  --gc-radius-sm: 12px;
  --gc-radius-pill: 24px;
  --gc-transition: cubic-bezier(0.4, 0, 0.2, 1);
  --gc-msg-gap: 10px;
}

@property --gc-gradient-angle {
  syntax: "<angle>";
  initial-value: 135deg;
  inherits: false;
}

/* ── Global Reset for Chatbot Components ── */
#gc-chatbot-root .gc-chatbot-window *,
#gc-chatbot-root .gc-chatbot-toggle * {
  box-sizing: border-box;
  margin: 0;
}

/* ── Floating Toggle Button ── */
#gc-chatbot-root .gc-chatbot-toggle {
  all: unset;
  position: fixed;
  bottom: 90px;
  right: 24px;
  z-index: 99999 !important;
  padding: 14px 22px;
  border-radius: var(--gc-radius-pill);
  background: linear-gradient(
    var(--gc-gradient-angle),
    var(--gc-btn-accent),
    #e7005e
  ) !important;
  color: var(--gc-text-light);
  box-shadow: 0 4px 16px rgba(3, 35, 64, 0.35);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition:
    transform 0.25s var(--gc-transition),
    box-shadow 0.25s var(--gc-transition);
  animation:
    gc-toggle-pulse 3s ease-in-out infinite,
    gc-rotate-gradient 6s linear infinite;
  will-change: transform, box-shadow, --gc-gradient-angle;
}

#gc-chatbot-root .gc-toggle-label {
  all: unset;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
  display: block;
}

#gc-chatbot-root .gc-chatbot-toggle:hover {
  transform: scale(1.08);
  box-shadow:
    0 6px 24px rgba(3, 35, 64, 0.45),
    0 0 0 6px rgba(3, 35, 64, 0.1);
}

#gc-chatbot-root .gc-chatbot-toggle:focus-visible {
  outline: 2px solid var(--gc-btn-accent);
  outline-offset: 3px;
}

#gc-chatbot-root .gc-chatbot-toggle svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  transition: transform 0.3s var(--gc-transition);
  stroke: currentColor;
  fill: none;
}

#gc-chatbot-root .gc-chatbot-toggle.active svg {
  transform: rotate(90deg) scale(0.9);
}

@keyframes gc-toggle-pulse {
  0%,
  100% {
    box-shadow:
      0 4px 16px rgba(3, 35, 64, 0.35),
      0 0 0 0 rgba(3, 35, 64, 0.25);
  }

  50% {
    box-shadow:
      0 4px 16px rgba(3, 35, 64, 0.35),
      0 0 0 8px rgba(3, 35, 64, 0);
  }
}

@keyframes gc-rotate-gradient {
  to {
    --gc-gradient-angle: 495deg;
  }
}

/* ── Chat Window ── */
#gc-chatbot-root .gc-chatbot-window {
  position: fixed;
  bottom: 160px;
  right: 24px;
  z-index: 999999 !important;
  width: 380px;
  height: 580px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 180px);
  /* 160px bottom offset + 20px top margin */
  border-radius: var(--gc-radius);
  box-shadow: var(--gc-shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(16px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.35s var(--gc-transition),
    opacity 0.35s var(--gc-transition);
  will-change: transform, opacity;
  font-family: inherit;
  border: 1px solid var(--gc-border-subtle);
}

#gc-chatbot-root .gc-chatbot-window.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* ── Header ── */
#gc-chatbot-root .gc-chat-header {
  background: linear-gradient(135deg, var(--gc-bg-primary), #0a3a5e) !important;
  color: var(--gc-text-light);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}

#gc-chatbot-root .gc-chat-header::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(6, 169, 236, 0.3),
    transparent
  ) !important;
}

#gc-chatbot-root .gc-chat-header-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

#gc-chatbot-root .gc-chat-header-avatar svg {
  all: unset;
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
}

#gc-chatbot-root .gc-chat-header-info {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

#gc-chatbot-root .gc-chat-header-info span {
  all: unset;
  font-size: 12px;
  opacity: 0.75;
  font-weight: 400;
  letter-spacing: 0.2px;
  display: block;
}

#gc-chatbot-root .gc-chat-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: white;
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.01em;
  display: block;
}

#gc-chatbot-root .gc-chat-close {
  all: unset;
  margin-left: auto;
  cursor: pointer;
  color: white;
  opacity: 0.6;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 20px;
  transition: all 0.2s ease-out;
}

#gc-chatbot-root .gc-chat-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
}

#gc-chatbot-root .gc-chat-close:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 1px;
}

#gc-chatbot-root .gc-chat-close svg {
  stroke: currentColor;
  fill: none;
}

/* ── Messages Area ── */
#gc-chatbot-root .gc-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  background: var(--gc-bg-chat);
  display: flex;
  flex-direction: column;
  gap: var(--gc-msg-gap);
  scroll-behavior: smooth;
}

/* Custom scrollbar */
#gc-chatbot-root .gc-chat-messages::-webkit-scrollbar {
  width: 4px;
}

#gc-chatbot-root .gc-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

#gc-chatbot-root .gc-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(3, 35, 64, 0.15);
  border-radius: 4px;
}

#gc-chatbot-root .gc-chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(3, 35, 64, 0.25);
}

/* ── Message Bubbles ── */
#gc-chatbot-root .gc-msg {
  all: unset;
  max-width: 82%;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.55;
  animation: gc-msg-appear 0.3s ease-out;
  position: relative;
  display: block;
}

@keyframes gc-msg-appear {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#gc-chatbot-root .gc-msg.bot {
  background: var(--gc-bg-surface);
  color: var(--gc-text-body);
  align-self: flex-start;
  border-radius: 4px 18px 18px 18px;
  box-shadow: var(--gc-shadow-sm);
  border: 1px solid var(--gc-border-subtle);
}

#gc-chatbot-root .gc-msg.user {
  background: linear-gradient(135deg, var(--gc-btn-info), #0590c9) !important;
  color: white;
  align-self: flex-end;
  border-radius: 18px 18px 4px 18px;
  box-shadow: 0 2px 8px rgba(6, 169, 236, 0.2);
}

/* ── System Messages (Disclaimers/Notices) ── */
#gc-chatbot-root .gc-msg-system {
  all: unset;
  text-align: center;
  font-size: 11.5px;
  color: var(--gc-text-muted);
  margin: 4px 24px 12px;
  line-height: 1.45;
  font-family: inherit;
  animation: gc-msg-appear 0.4s ease-out;
  display: block;
}

/* ── Input Wrapper & Quick Replies ── */
#gc-chatbot-root .gc-chat-input-wrapper {
  background: var(--gc-bg-surface);
  border-top: 1px solid var(--gc-border-subtle);
  display: flex;
  flex-direction: column;
}

#gc-chatbot-root .gc-quick-replies {
  display: flex;
  overflow-x: auto;
  gap: 8px;
  padding: 12px 16px 8px;
  scrollbar-width: none;
  /* Firefox */
}

/* Hide scrollbar for Chrome, Safari and Opera */
#gc-chatbot-root .gc-quick-replies::-webkit-scrollbar {
  display: none;
}

#gc-chatbot-root .gc-quick-reply {
  all: unset;
  padding: 6px 12px;
  border-radius: var(--gc-radius-pill);
  border: 1px solid var(--gc-btn-info);
  background: rgba(6, 169, 236, 0.05);
  color: var(--gc-btn-info);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: grab;
  transition: all 0.2s ease-out;
  white-space: nowrap;
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

#gc-chatbot-root .gc-quick-reply:hover {
  background: var(--gc-btn-info);
  color: white;
  box-shadow: 0 2px 8px rgba(6, 169, 236, 0.25);
  cursor: grab;
}

#gc-chatbot-root .gc-quick-reply:active {
  cursor: grabbing;
}

#gc-chatbot-root .gc-quick-reply:focus-visible {
  outline: 2px solid var(--gc-btn-info);
  outline-offset: 2px;
}

/* ── Input Area ── */
#gc-chatbot-root .gc-chat-input-area {
  padding: 8px 16px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

#gc-chatbot-root .gc-chat-input {
  all: unset;
  box-sizing: border-box;
  flex: 1;
  background: var(--gc-bg-chat);
  padding: 0 18px;
  border-radius: var(--gc-radius-pill);
  font-size: 14px;
  font-family: inherit;
  color: var(--gc-text-body);
  border: 1px solid transparent;
  transition:
    border-color 0.2s ease-out,
    box-shadow 0.2s ease-out;
  height: 44px;
}

#gc-chatbot-root .gc-chat-input:focus {
  border-color: var(--gc-btn-info);
  box-shadow: 0 0 0 3px rgba(6, 169, 236, 0.12);
}

#gc-chatbot-root .gc-chat-input::placeholder {
  color: var(--gc-text-muted);
  opacity: 0.7;
}

#gc-chatbot-root .gc-chat-send {
  all: unset;
  background: linear-gradient(135deg, var(--gc-btn-info), #0590c9) !important;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition:
    transform 0.2s ease-out,
    box-shadow 0.2s ease-out;
}

#gc-chatbot-root .gc-chat-send:hover {
  transform: scale(1.06);
  box-shadow: 0 4px 12px rgba(6, 169, 236, 0.3);
}

#gc-chatbot-root .gc-chat-send:active {
  transform: scale(0.95);
}

#gc-chatbot-root .gc-chat-send:focus-visible {
  outline: 2px solid var(--gc-btn-info);
  outline-offset: 2px;
}

#gc-chatbot-root .gc-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

#gc-chatbot-root .gc-chat-send svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
}

/* ── Typing Indicator ── */
#gc-chatbot-root .gc-typing-indicator {
  display: flex;
  gap: 5px;
  padding: 14px 18px;
  background: var(--gc-bg-surface);
  border-radius: 4px 18px 18px 18px;
  align-self: flex-start;
  box-shadow: var(--gc-shadow-sm);
  border: 1px solid var(--gc-border-subtle);
  width: fit-content;
  animation: gc-msg-appear 0.3s ease-out;
}

#gc-chatbot-root .gc-typing-indicator span {
  padding: 0;
  margin: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gc-btn-info);
  animation: gc-typingBounce 1.4s infinite ease-in-out both;
  will-change: transform, opacity;
  display: inline-block;
}

#gc-chatbot-root .gc-typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}

#gc-chatbot-root .gc-typing-indicator span:nth-child(2) {
  animation-delay: 0.16s;
}

#gc-chatbot-root .gc-typing-indicator span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes gc-typingBounce {
  0%,
  80%,
  100% {
    transform: scale(0.5);
    opacity: 0.35;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ── Markdown Content in Bot Messages ── */
#gc-chatbot-root .gc-msg-content {
  all: unset;
  word-wrap: break-word;
  overflow-wrap: break-word;
  display: block;
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content strong {
  font-weight: 700;
  color: var(--gc-bg-primary);
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content em {
  font-style: italic;
  color: var(--gc-text-muted);
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content code {
  background: var(--gc-bg-chat);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid var(--gc-border-subtle);
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content a {
  color: var(--gc-btn-info);
  text-decoration: underline;
  text-decoration-color: rgba(6, 169, 236, 0.3);
  text-underline-offset: 2px;
  word-break: break-word;
  transition: text-decoration-color 0.2s ease-out;
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content a:hover {
  text-decoration-color: var(--gc-btn-info);
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content ul,
#gc-chatbot-root .gc-msg.bot .gc-msg-content ol {
  all: unset;
  margin: 6px 0;
  padding-left: 20px;
  display: block;
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content li {
  all: unset;
  margin: 4px 0;
  line-height: 1.5;
  display: list-item;
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content h1,
#gc-chatbot-root .gc-msg.bot .gc-msg-content h2,
#gc-chatbot-root .gc-msg.bot .gc-msg-content h3,
#gc-chatbot-root .gc-msg.bot .gc-msg-content h4,
#gc-chatbot-root .gc-msg.bot .gc-msg-content h5,
#gc-chatbot-root .gc-msg.bot .gc-msg-content h6 {
  color: var(--gc-bg-primary);
  margin: 10px 0 4px;
  line-height: 1.3;
  font-weight: 600;
  display: block;
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content h1 {
  font-size: 18px;
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content h2 {
  font-size: 16px;
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content h3 {
  font-size: 15px;
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content h4 {
  font-size: 14px;
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content h5 {
  font-size: 13px;
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content h6 {
  font-size: 12px;
}

#gc-chatbot-root .gc-msg.bot .gc-msg-content hr {
  all: unset;
  border: none;
  height: 1px;
  background: var(--gc-border-subtle);
  margin: 8px 0;
  display: block;
}

/* ── Message Timestamps ── */
#gc-chatbot-root .gc-msg-time {
  all: unset;
  display: block;
  font-size: 10px;
  color: var(--gc-text-muted);
  opacity: 0.5;
  margin-top: 4px;
}

#gc-chatbot-root .gc-msg.user .gc-msg-time {
  color: rgba(255, 255, 255, 0.6);
}

/* ── Status Dot ── */
#gc-chatbot-root .gc-status-dot {
  all: unset;
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #032340;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
  animation: gc-status-glow 2s ease-in-out infinite;
  z-index: 2;
  display: block;
}

@keyframes gc-status-glow {
  0%,
  100% {
    box-shadow: 0 0 4px rgba(34, 197, 94, 0.3);
  }

  50% {
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
  }
}

/* ── Accessibility: Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
  #gc-chatbot-root .gc-chatbot-toggle,
  #gc-chatbot-root .gc-chatbot-window,
  #gc-chatbot-root .gc-msg,
  #gc-chatbot-root .gc-typing-indicator span,
  #gc-chatbot-root .gc-status-dot,
  #gc-chatbot-root .gc-chat-send,
  #gc-chatbot-root .gc-quick-reply,
  #gc-chatbot-root .gc-chat-close,
  #gc-chatbot-root .gc-chatbot-toggle svg {
    animation: none !important;
    transition: none !important;
  }
}

/* ── Mobile ── */
@media (max-width: 480px) {
  #gc-chatbot-root .gc-chatbot-window {
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-height: 100dvh;
    /* Use dynamic viewport height */
    border-radius: 0;
    border: none;
    transform: translateY(100%);
    /* Slide from bottom on mobile */
  }

  #gc-chatbot-root .gc-chatbot-window.open {
    transform: translateY(0);
  }

  #gc-chatbot-root .gc-chat-header {
    border-radius: 0;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  #gc-chatbot-root .gc-chat-messages {
    padding: 16px 12px;
  }

  #gc-chatbot-root .gc-chat-input-area {
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  #gc-chatbot-root .gc-msg {
    max-width: 90%;
    /* Allow bubbles to be wider on small screens */
  }

  /* Reduce rendering cost on mobile */
  #gc-chatbot-root .gc-chatbot-toggle {
    animation: none !important;
    box-shadow: 0 4px 12px rgba(3, 35, 64, 0.3);
    will-change: auto;
    padding: 14px;
    border-radius: 50%;
  }

  #gc-chatbot-root .gc-toggle-label {
    display: none !important;
  }

  #gc-chatbot-root .gc-msg.bot,
  #gc-chatbot-root .gc-typing-indicator {
    box-shadow: none;
  }
}

/*
 * @author Lathrell Pagsuguiron
 * @copyright 2026 Inventive Media - Web Developer Intern
 * @link https://linkedin.com/in/lathrell
 */
