/* ============================================================
   Freexy Chatbot — UI styles only (no JavaScript yet)
   Colors match the site: #051b4e (navy), #00d4ff (cyan)
   ============================================================ */

/* --- 1. Root container ---
   position: fixed  → floats above the page, does not scroll away
   bottom / right    → anchored to bottom-right corner
   z-index: 9999     → sits on top of React app content
   font-family       → clean system fonts, independent of React styles */
#chatbot {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  max-height: calc(100vh - 16px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* --- 2. Floating toggle button (robot mascot) --- */
#chatbot-toggle {
  position: relative;
  width: 68px;
  height: 68px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #05080f;
  cursor: pointer;
  overflow: hidden;
  box-shadow:
    0 4px 18px rgba(0, 0, 0, 0.35),
    0 0 0 2px rgba(0, 212, 255, 0.35),
    0 0 22px rgba(0, 212, 255, 0.4);
  animation:
    chatbot-float 2.8s ease-in-out infinite,
    chatbot-glow 2.2s ease-in-out infinite;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-toggle-icon {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
  user-select: none;
  animation: chatbot-icon-pulse 2.2s ease-in-out infinite;
}

/* Soft cyan ring around the button */
#chatbot-toggle::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(0, 212, 255, 0.45);
  opacity: 0.7;
  pointer-events: none;
  animation: chatbot-ring 2.2s ease-in-out infinite;
}

/* Hover: pop + stronger glow */
#chatbot-toggle:hover {
  animation: chatbot-wiggle 0.55s ease-in-out;
  transform: scale(1.1);
  box-shadow:
    0 8px 28px rgba(0, 0, 0, 0.4),
    0 0 0 3px rgba(0, 212, 255, 0.55),
    0 0 34px rgba(0, 212, 255, 0.65);
}

#chatbot-toggle:active {
  transform: scale(0.94);
}

#chatbot-toggle:focus-visible {
  outline: 2px solid #00d4ff;
  outline-offset: 4px;
}

/* When chat is open, calm the float a bit */
#chatbot.chatbot-open #chatbot-toggle {
  animation: chatbot-glow 2.2s ease-in-out infinite;
}

@keyframes chatbot-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-7px);
  }
}

@keyframes chatbot-glow {
  0%,
  100% {
    box-shadow:
      0 4px 18px rgba(0, 0, 0, 0.35),
      0 0 0 2px rgba(0, 212, 255, 0.3),
      0 0 18px rgba(0, 212, 255, 0.35);
  }
  50% {
    box-shadow:
      0 6px 24px rgba(0, 0, 0, 0.4),
      0 0 0 3px rgba(0, 212, 255, 0.55),
      0 0 30px rgba(0, 212, 255, 0.7);
  }
}

@keyframes chatbot-icon-pulse {
  0%,
  100% {
    filter: brightness(1);
    transform: scale(1);
  }
  50% {
    filter: brightness(1.12);
    transform: scale(1.03);
  }
}

@keyframes chatbot-ring {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(1);
  }
  50% {
    opacity: 0.85;
    transform: scale(1.06);
  }
}

@keyframes chatbot-wiggle {
  0%,
  100% {
    transform: scale(1.1) rotate(0deg);
  }
  25% {
    transform: scale(1.12) rotate(-6deg);
  }
  50% {
    transform: scale(1.14) rotate(6deg);
  }
  75% {
    transform: scale(1.12) rotate(-3deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  #chatbot-toggle,
  .chatbot-toggle-icon,
  #chatbot-toggle::after {
    animation: none !important;
  }
}

/* When open, stack the window above the button */
#chatbot.chatbot-open {
  display: flex;
  flex-direction: column-reverse;
  align-items: flex-end;
}

/* --- 3. Chat window (hidden until JS adds .chatbot-open) ---
   display: none      → invisible by default; JS will toggle a class
   flex-direction      → stacks header, messages, input vertically
   width / height      → fixed panel size on desktop
   border-radius       → rounded corners for a modern look
   overflow: hidden    → clips content to rounded corners
   box-shadow          → depth so the panel floats above the page */
#chatbot-window {
  display: none;
  flex-direction: column;
  width: min(840px, calc(100vw - 36px));
  height: min(860px, calc(100vh - 36px));
  max-height: calc(100vh - 36px);
  margin-bottom: 12px;
  background: #ffffff;
  border-radius: 28px;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(5, 27, 78, 0.22);
}

/* When JS adds .chatbot-open to #chatbot, show the window as a flex column */
#chatbot.chatbot-open #chatbot-window {
  display: flex;
}

/* Maximized — wide premium canvas, content stays centered (Freexy navy/cyan) */
#chatbot.chatbot-maximized {
  left: 0;
  right: 0;
  bottom: 0;
  top: 0;
  align-items: center;
  justify-content: center;
  background: rgba(2, 8, 24, 0.4);
}

#chatbot.chatbot-maximized #chatbot-window {
  width: min(1180px, calc(100vw - 40px));
  height: min(900px, calc(100vh - 40px));
  max-height: calc(100vh - 40px);
  margin: 0;
  border-radius: 28px;
}

#chatbot.chatbot-maximized #chatbot-toggle {
  display: none;
}

/* --- 4. Header bar + window controls (high specificity so site CSS cannot hide them) --- */
#chatbot #chatbot-header {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 12px !important;
  min-height: 52px !important;
  padding: 10px 12px 10px 16px !important;
  background: #051b4e !important;
  color: #ffffff !important;
  font-size: 16px !important;
  font-weight: 600 !important;
  flex-shrink: 0 !important;
  visibility: visible !important;
  opacity: 1 !important;
  z-index: 2 !important;
}

#chatbot #chatbot-header .chatbot-header-identity {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  min-width: 0;
}

#chatbot #chatbot-header .chatbot-header-avatar {
  display: grid !important;
  place-items: center !important;
  width: 32px !important;
  height: 32px !important;
  border-radius: 50% !important;
  background: linear-gradient(135deg, #00d4ff, #007a9a) !important;
  color: #051b4e !important;
  font-size: 14px !important;
  font-weight: 800 !important;
  flex-shrink: 0 !important;
}

#chatbot #chatbot-header .chatbot-header-copy {
  display: flex !important;
  flex-direction: column !important;
  min-width: 0;
  line-height: 1.15 !important;
}

#chatbot #chatbot-header .chatbot-header-title {
  display: block !important;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #ffffff !important;
  font-size: 15px !important;
  font-weight: 600 !important;
}

#chatbot #chatbot-header .chatbot-header-status {
  display: block !important;
  color: #7ee9ff !important;
  font-size: 11px !important;
  font-weight: 500 !important;
}

#chatbot #chatbot-header .chatbot-header-actions {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  flex-shrink: 0 !important;
  visibility: visible !important;
}

#chatbot #chatbot-header .chatbot-header-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 32px !important;
  height: 32px !important;
  min-width: 32px !important;
  min-height: 32px !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 1px solid rgba(255, 255, 255, 0.35) !important;
  border-radius: 8px !important;
  background: rgba(255, 255, 255, 0.12) !important;
  color: #ffffff !important;
  font-size: 18px !important;
  font-weight: 700 !important;
  line-height: 1 !important;
  cursor: pointer !important;
  visibility: visible !important;
  opacity: 1 !important;
  box-shadow: none !important;
  text-indent: 0 !important;
  overflow: visible !important;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

#chatbot #chatbot-header .chatbot-header-btn:hover {
  background: rgba(0, 212, 255, 0.28) !important;
  color: #00d4ff !important;
  border-color: rgba(0, 212, 255, 0.7) !important;
}

#chatbot #chatbot-header .chatbot-header-btn:active {
  transform: scale(0.92);
}

#chatbot #chatbot-header .chatbot-header-btn--close:hover {
  background: rgba(239, 68, 68, 0.35) !important;
  color: #fecaca !important;
  border-color: rgba(248, 113, 113, 0.8) !important;
}

#chatbot #chatbot-header .chatbot-header-btn:focus-visible {
  outline: 2px solid #00d4ff !important;
  outline-offset: 1px !important;
}

#chatbot #chatbot-header .chatbot-icon-maximize,
#chatbot #chatbot-header .chatbot-icon-restore {
  display: inline !important;
  color: inherit !important;
  font-size: 16px !important;
  line-height: 1 !important;
}

#chatbot #chatbot-header .chatbot-icon-restore {
  display: none !important;
}

#chatbot.chatbot-maximized #chatbot-header .chatbot-icon-maximize {
  display: none !important;
}

#chatbot.chatbot-maximized #chatbot-header .chatbot-icon-restore {
  display: inline !important;
}

/* --- 5. Message area ---
   flex: 1           → fills all space between header and input
   overflow-y: auto  → scrolls when messages overflow
   background        → light gray so message bubbles stand out later */
#chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px 16px;
  background: #f7fafc;
  display: none;
  flex-direction: column;
  gap: 16px;
}

#chatbot.chatbot-has-thread #chatbot-messages {
  display: flex;
}

#chatbot-home {
  flex: 1;
  overflow-y: auto;
  padding: 48px 40px 24px;
  background:
    radial-gradient(circle at 18% 8%, rgba(0, 212, 255, 0.16), transparent 38%),
    radial-gradient(circle at 92% 0%, rgba(5, 27, 78, 0.06), transparent 32%),
    #ffffff;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
}

#chatbot.chatbot-has-thread #chatbot-home {
  display: none;
}

.chatbot-home-inner {
  width: min(920px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chatbot-home-hello {
  margin: 0;
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.04em;
  background: linear-gradient(90deg, #051b4e 0%, #00d4ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.chatbot-home-title {
  margin: 8px 0 28px;
  font-size: 18px;
  font-weight: 500;
  color: #94a3b8;
}

.chatbot-home-cards {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

#chatbot.chatbot-maximized #chatbot-home {
  padding: 56px 48px 20px;
}

#chatbot.chatbot-maximized .chatbot-home-inner {
  width: min(980px, 100%);
}

#chatbot.chatbot-maximized .chatbot-home-hello {
  font-size: 48px;
}

#chatbot.chatbot-maximized .chatbot-home-title {
  font-size: 22px;
  margin-bottom: 40px;
}

#chatbot.chatbot-maximized .chatbot-home-cards {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

#chatbot.chatbot-maximized .chatbot-home-card {
  min-height: 180px;
  padding: 20px;
}

#chatbot.chatbot-maximized .chatbot-composer {
  max-width: 720px;
}

#chatbot.chatbot-maximized #chatbot-messages {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
}

.chatbot-home-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  min-height: 148px;
  border: 1px solid rgba(0, 158, 198, 0.14);
  border-radius: 20px;
  padding: 16px;
  background: linear-gradient(180deg, rgba(0, 212, 255, 0.16), rgba(244, 247, 251, 0.9));
  color: #051b4e;
  cursor: pointer;
}

.chatbot-home-card:hover {
  border-color: rgba(0, 212, 255, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(5, 27, 78, 0.08);
}

.chatbot-home-card-icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #051b4e, #0a3a7a);
  color: #00d4ff;
}

.chatbot-home-card-icon svg {
  width: 20px;
  height: 20px;
  display: block;
}

.chatbot-home-card strong {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 6px;
}

.chatbot-home-card span:last-child {
  font-size: 12px;
  line-height: 1.45;
  color: #64748b;
}

/* --- 5b. Message rows (ChatGPT-style thread) --- */
.chatbot-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  width: 100%;
  max-width: 100%;
  flex: 0 0 auto;
  align-self: stretch;
  box-sizing: border-box;
}

.chatbot-row--user {
  justify-content: flex-end;
}

.chatbot-row--bot {
  justify-content: flex-start;
}

.chatbot-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: linear-gradient(135deg, #051b4e, #0a3a7a);
  color: #00d4ff;
  font-size: 12px;
  font-weight: 700;
}

.chatbot-message {
  width: fit-content;
  max-width: min(72%, 560px);
  min-width: 0;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
}

/* User messages: right-aligned, cyan background */
.chatbot-message--user {
  align-self: flex-end;
  background: linear-gradient(135deg, #00d4ff, #009ec6);
  color: #051b4e;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

/* Bot messages: left-aligned, easier to scan */
.chatbot-message--bot {
  align-self: flex-start;
  background: #ffffff;
  color: #051b4e;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.chatbot-message--bot strong {
  font-weight: 700;
  color: #051b4e;
}

.chatbot-message--bot a {
  color: #009ec6;
  text-decoration: underline;
  word-break: break-all;
}

.chatbot-message--bot a:hover {
  color: #007a9a;
}

.chatbot-stream-text {
  white-space: pre-wrap;
}

.chatbot-caret {
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: #009ec6;
  animation: chatbot-caret-blink 0.85s steps(1, end) infinite;
}

@keyframes chatbot-caret-blink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0;
  }
}

.chatbot-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 52px;
  padding-top: 14px;
  padding-bottom: 14px;
}

.chatbot-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #009ec6;
  animation: chatbot-dot 1.1s ease-in-out infinite;
}

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

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

@keyframes chatbot-dot {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chatbot-caret,
  .chatbot-typing span {
    animation: none;
  }
}

/* --- 6. Input row ---
   display: flex      → places input and Send button side by side
   gap               → space between input and button
   border-top        → visual separator from message area
   flex-shrink: 0    → never collapses when messages grow */
.chatbot-input-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 28px 22px;
  border-top: none;
  background: #ffffff;
  flex-shrink: 0;
}

.chatbot-composer {
  width: 100%;
  max-width: 720px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 18px;
  border: 1px solid rgba(5, 27, 78, 0.08);
  border-radius: 24px;
  background: #f4f7fb;
  box-shadow: 0 8px 24px rgba(5, 27, 78, 0.06);
}

#chatbot-input {
  flex: 1;
  min-height: 24px;
  max-height: 140px;
  padding: 10px 8px;
  border: none;
  background: transparent;
  border-radius: 0;
  font-size: 15px;
  line-height: 1.45;
  color: #051b4e;
  outline: none;
  resize: none;
  font-family: inherit;
}

#chatbot-input:focus {
  border-color: transparent;
}

#chatbot-input:disabled,
#chatbot-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#chatbot-send {
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #051b4e;
  color: #00d4ff;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

#chatbot-send:hover {
  opacity: 0.92;
  transform: scale(1.04);
}

#chatbot-send:focus-visible {
  outline: 2px solid #00d4ff;
  outline-offset: 2px;
}

/* --- 9. Responsive: mobile screens (≤ 480px) ---
   Window stretches nearly full width
   Button moves slightly inward to avoid screen edge */
@media (max-width: 480px) {
  #chatbot {
    bottom: 16px;
    right: 16px;
    left: 16px;
  }

  #chatbot-window {
    width: 100%;
    height: min(88vh, calc(100vh - 28px));
    max-height: none;
    border-radius: 20px;
  }

  .chatbot-home-hello {
    font-size: 30px;
  }

  .chatbot-home-cards {
    grid-template-columns: 1fr;
  }

  #chatbot.chatbot-maximized .chatbot-home-cards {
    grid-template-columns: 1fr;
  }

  .chatbot-home-card {
    min-height: 0;
  }

  #chatbot-home {
    padding: 28px 16px 16px;
    justify-content: flex-start;
  }

  #chatbot-toggle {
    position: fixed;
    bottom: 16px;
    right: 16px;
  }
}
