/* ===========================================================================
   CHAT BUNDLE - Single-File CSS for Chat Interface
   ===========================================================================
   Structure:
   - PART 1: CSS Variables (Theme System Foundation)
   - PART 2: Base Styles & Resets
   - PART 3: Chat Layout (header, main, footer)
   - PART 4: Chat Messages (bot/user bubbles)
   - PART 5: Chat Input (text input, options, navigation)
   - PART 6: Chat Animations
   - PART 7: Static Pages (about, contact, privacy, terms) - NOT themeable
   - PART 8: Contact Form
   - PART 9: Utility & Responsive
   =========================================================================== */

/* ===========================================================================
   PART 1: CSS VARIABLES (Theme System Foundation)
   ===========================================================================
   These variables can be overridden by themes via inline CSS from Chat::Theme.
   See app/models/chat/theme.rb for theme definitions.
   =========================================================================== */

:root {
  /* -------------------------------------------------------------------------
     THEMEABLE VARIABLES (can be customized per theme)
     ------------------------------------------------------------------------- */

  /* Background color */
  --background-color: #f5f7fa;

  /* Theme main colors (primary theme color and variants) */
  --theme-main: rgb(1, 174, 240);
  --theme-main-hover: #00a0d8;
  --theme-main-shadow: rgb(1, 174, 240, 0.3);
  --theme-main-shadow-medium: rgb(1, 174, 240, 0.6);
  --theme-main-text-color: white;

  /* Chat feedback colors (error/success banners in chat) */
  --theme-danger-bg: rgb(220, 38, 38, 0.9);
  --theme-success-bg: rgb(34, 197, 94, 0.15);
  --theme-success-border: rgb(34, 197, 94, 0.3);

  /* Chat validation (inline under input) */
  --theme-validation-text-color: rgb(220, 38, 38);
  --theme-validation-border-color: rgb(220, 38, 38);

  /* Theme time color (references theme-main-text-color) */
  --theme-time-color: var(--theme-main-text-color);

  /* User bubble colors (references to theme-main-*) */
  --theme-user-bubble-color: var(--theme-main);
  --theme-user-bubble-hover: var(--theme-main-hover);
  --theme-user-bubble-text-color: var(--theme-main-text-color);

  /* Theme alt colors (secondary/bot theme color) */
  --theme-alt-color: white;
  --theme-alt-text-color: rgb(47, 50, 74);

  /* Bot bubble colors (references to theme-alt-*) */
  --theme-bot-bubble-color: var(--theme-alt-color);
  --theme-bot-bubble-text-color: var(--theme-alt-text-color);

  /* Header */
  --theme-header-bg: transparent;

  /* Theme input (chat-input-inline) */
  --theme-input-bg: white;
  --theme-input-border: var(--theme-user-bubble-color);
  --theme-input-radius: 8px;
  --theme-input-text: #2F324A;
  --theme-input-placeholder: #999;

  /* Theme input button (submit inside input) */
  --theme-input-btn-bg: transparent;
  --theme-input-btn-color: var(--theme-user-bubble-color);
  --theme-input-btn-icon: var(--theme-main-shadow-medium);

  /* Theme nav colors (references theme-main-text-color) */
  --theme-nav-color: var(--theme-main-text-color);
  --theme-nav-text-color: var(--theme-nav-color);

  /* Choice button (references theme-user-bubble-*) */
  --theme-choice-btn-bg: var(--theme-user-bubble-color);
  --theme-choice-btn-border: transparent;

  /* Typography */
  --font-family: "Open Sans";
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;

  /* Help text (uses theme-input-placeholder from input section) */
  --theme-help-text-color: var(--theme-input-placeholder);

  /* -------------------------------------------------------------------------
     STATIC PAGE VARIABLES (glass effect overlays - NOT themeable)
     These are used for about, contact, privacy, terms pages
     ------------------------------------------------------------------------- */

  /* Static page accent colors (contact form) */
  --static-primary-color: #667eea;
  --static-secondary-color: #764ba2;

  /* Static page text colors */
  --static-text-color: #333;
  --static-light-text-color: #666;
  --static-placeholder-color: #999;

  /* Static page UI colors */
  --static-border-color: #e1e8ed;
  --static-shadow-color: rgb(0, 0, 0, 0.1);
  --static-danger-color: #dc2626;
  --static-success-color: #22c55e;

  /* Overlay colors */
  --overlay-white-10: rgb(255, 255, 255, 0.1);
  --overlay-white-20: rgb(255, 255, 255, 0.2);
  --overlay-white-80: rgb(255, 255, 255, 0.8);
  --overlay-white-90: rgb(255, 255, 255, 0.9);
  --overlay-white-95: rgb(255, 255, 255, 0.95);
  --text-shadow-light: rgb(0, 0, 0, 0.3);
  --text-shadow-strong: rgb(0, 0, 0, 0.5);
  --box-shadow-sm: rgb(0, 0, 0, 0.1);
  --box-shadow-md: rgb(0, 0, 0, 0.15);
  --box-shadow-lg: rgb(0, 0, 0, 0.2);

  /* Footer glass-style colors */
  --footer-text-muted: rgb(255, 255, 255, 0.7);
}

/* ===========================================================================
   PART 2: BASE STYLES & RESETS
   =========================================================================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-family), system-ui, -apple-system, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: var(--font-size-sm);
  line-height: 1.34;
  background-color: var(--background-color);
  -webkit-font-smoothing: antialiased;
  padding: 1rem;
}

/* ===========================================================================
   PART 3: CHAT LAYOUT (header, main, footer)
   =========================================================================== */

/* === CHAT HEADER ======================================================== */

header {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  color: var(--theme-main-text-color);
  margin-bottom: 1rem;
  background: var(--theme-header-bg);
}

header .header-icon {
  width: 2.5rem;
  height: 2.5rem;
  object-fit: contain;
}

header .header-content {
  flex: 1;
  min-width: 0;
}

header h1 {
  font-size: var(--font-size-xl);
  font-weight: 600;
  text-shadow: 0 2px 8px var(--text-shadow-strong);
  overflow-wrap: break-word;
}

header h2 {
  font-size: var(--font-size-base);
  opacity: 0.95;
  text-shadow: 0 1px 4px var(--text-shadow-strong);
  font-weight: normal;
  overflow-wrap: break-word;
}

header h3.content-text {
  font-size: var(--font-size-sm);
  font-style: italic;
  opacity: 0.9;
  text-shadow: 0 1px 4px var(--text-shadow-strong);
  font-weight: normal;
  margin-top: 0.5rem;
  line-height: 1.4;
}

header h3.content-text p {
  margin: 0.25rem 0;
  font-size: inherit;
  font-style: inherit;
}

header h3.content-text p:first-child {
  margin-top: 0;
}

header h3.content-text p:last-child {
  margin-bottom: 0;
}

/* Close button for static pages */
.page-content .close-button {
  position: sticky;
  top: 0;
  float: right;
  margin: 0 0 0.5rem 1rem;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  background: var(--overlay-white-90);
  backdrop-filter: blur(5px);
  border-radius: 50%;
  box-shadow: 0 2px 8px var(--box-shadow-md);
  color: var(--static-text-color);
  text-decoration: none;
  opacity: 0.9;
  transition: opacity 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.page-content .close-button:hover {
  opacity: 1;
  transform: scale(1.05);
  box-shadow: 0 4px 12px var(--box-shadow-lg);
}

.page-content .close-button .close-icon {
  width: 1.25rem;
  height: 1.25rem;
}

/* Hide from users but visible to SEO bots */
header h3.seo-only {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* === CHAT CONTENT (main container) ========================================= */

main#chat-container {
  display: grid;
  overflow: hidden;

  /* 
    auto 1fr  - start caht from top 
    auto auto - start chat from center 
    1fr auto  - start chat from bottom
  */
  grid-template-rows: auto auto; 
  justify-items: center;
  align-content: center; /* center */
}

main#chat-container section#chat-messages {
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: none;
  max-width: 600px;
  width: 100%;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

main#chat-container section#chat-input-area {
  max-width: 600px;
  width: 100%;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
}

/* Align with bot bubble left edge and user bubble right edge on large screens */
@media (width > 760px) {
  main#chat-container section#chat-messages {
    max-width: 800px;
  }

  main#chat-container section#chat-input-area {
    max-width: 800px;

    /* Left: align with bot bubble (icon 50px + gap 0.75rem) */
    padding-left: calc(50px + 0.75rem);

    /* Right: space for user message time (3rem fixed width + gap 0.75rem) */
    padding-right: calc(2.5rem + 0.75rem);
  }

  article.message--bot .message__bubble {
    /* Width reduced by user time space (3rem fixed width + 0.75rem gap) to align with input area */
    max-width: calc(100% - 2.5rem);
  }

  article.message--user .message__time--user {
    width: 2.5rem;
    text-align: left;
  }
}

/* ===========================================================================
   PART 4: CHAT MESSAGES (bot/user bubbles, timestamps)
   =========================================================================== */

/* Message layouts */
article.message {
  display: grid;
  max-width: 600px;
  width: 100%;
  margin: 0.75rem auto;
  gap: 0.75rem;
  animation: slide-in 0.3s ease;
}

/* Override default animation with custom animations */

/* WITH previous bot message (full sequence) */
article.message.animate-appear-1 {
  animation: slide-in-center-left-up 0.6s ease-out both !important;
  animation-delay: 0s !important;
  opacity: 0;
  transform: translate(50vw, 50vh) scale(0.5);
}

article.message.animate-appear-2 {
  animation: slide-in-right-up 0.4s ease-out both !important;
  animation-delay: 0.3s !important;
  opacity: 0;
  transform: translate(-100px, 50px);
}

article.message.animate-appear-3 {
  animation: slide-in-elliptic-top-fwd 0.6s ease-out both !important;
  animation-delay: 1.8s !important;
  opacity: 1;
  transform: translateY(-30px) rotateX(-10deg) scale(0);
  transform-origin: 50% 0%;
}

/* WITHOUT previous bot message (skip Animation I) */
article.message.animate-appear-2-no-prev {
  animation: slide-in-right-up 0.4s ease-out both !important;
  animation-delay: 0s !important;
  opacity: 0;
  transform: translate(-100px, 50px);
}

article.message.animate-appear-3-no-prev {
  animation: slide-in-elliptic-top-fwd 0.6s ease-out both !important;
  animation-delay: 1.6s !important;
  opacity: 1;
  transform: translateY(-30px) rotateX(-10deg) scale(0);
  transform-origin: 50% 0%;
}

/* Animation for input wrapper */
#input-wrapper.animate-appear-3 {
  animation: slide-in-elliptic-top-fwd 0.6s ease-out both;
  animation-delay: 1.8s;
  opacity: 1;
  transform: translateY(-30px) rotateX(-10deg) scale(0);
  transform-origin: 50% 0%;
}

#input-wrapper.animate-appear-3-no-prev {
  animation: slide-in-elliptic-top-fwd 0.6s ease-out both;
  animation-delay: 1.6s;
  opacity: 1;
  transform: translateY(-30px) rotateX(-10deg) scale(0);
  transform-origin: 50% 0%;
}

/* Increase max-width for messages on large screens */
@media (width > 760px) {
  article.message {
    max-width: 800px;
  }
}

article.message--bot {
  grid-template-columns: 50px auto 1fr;
  grid-template-rows: auto auto;
  grid-template-areas: 
    "icon bubble"
    "time .";
  gap: 0.25rem 0.75rem;
}

article.message--bot .message__icon {
  grid-area: icon;
  width: 2.5rem;
  height: 2.5rem;
  place-self: end center;
}

article.message--bot .message__icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

article.message--bot .message__time {
  grid-area: time;
  color: var(--theme-time-color);
  font-size: var(--font-size-xs);
  white-space: nowrap;
  justify-self: center;
}

article.message--bot .message__bubble {
  grid-area: bubble;
  background: var(--theme-bot-bubble-color);
  color: var(--theme-bot-bubble-text-color);
  padding: 1rem;
  border-radius: 0.75rem;
  border-bottom-left-radius: 0.125rem;
}

article.message--user {
  grid-template-columns: 1fr auto;
  grid-template-areas: "bubble time";
  place-items: center end;
}

article.message--user .message__time--user {
  grid-area: time;
  color: var(--theme-time-color);
  font-size: var(--font-size-xs);
  white-space: nowrap;
}

article.message--user .message__bubble {
  grid-area: bubble;
  background: var(--theme-user-bubble-color);
  color: var(--theme-user-bubble-text-color);
  padding: 1rem;
  border-radius: 0.75rem;
  border-bottom-right-radius: 0.125rem;
}

/* Responsive - Small screens */
@media (width <= 480px) {
  article.message--bot {
    grid-template-columns: 40px 1fr;
    grid-template-areas: 
      "icon bubble"
      "icon bubble";
  }
  
  article.message--bot .message__time {
    display: none;
  }
  
  article.message--user {
    grid-template-columns: 1fr;
    grid-template-areas: "bubble";
  }
  
  article.message--user .message__time--user {
    display: none;
  }
}


/* === CHAT INPUT AREA ===================================== [section] === */



/* === CHAT FOOTER ========================================== [footer] === */

footer {
  background: var(--overlay-white-10);
  backdrop-filter: blur(10px);
  border: 1px solid var(--overlay-white-20);
  border-radius: 8px;
  color: white;
  padding: 0.5rem 1rem;
  font-size: var(--font-size-xs);
}

footer p {
  margin: 0;
  text-shadow: 0 1px 2px var(--text-shadow-light);
}

.session-id {
  font-family: Monaco, Menlo, 'Ubuntu Mono', monospace;
  font-size: var(--font-size-xs);
  color: var(--footer-text-muted);
}

/* Footer Content Layout */
.footer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem 1rem;
}

.footer-links {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
}

.footer-links a {
  color: var(--footer-text-muted);
  text-decoration: none;
  font-weight: 400;
  transition: color 0.2s ease;
  text-shadow: 0 1px 2px var(--text-shadow-light);
}

.footer-links a:hover {
  color: white;
  text-decoration: underline;
}

/* Social Icons */
.social-links {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: center;
}

.social-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: var(--overlay-white-80);
  transition: all 0.2s ease;
  border-radius: 50%;
  background: var(--overlay-white-10);
}

.social-icon:hover {
  color: white;
  background: var(--overlay-white-20);
  transform: translateY(-2px);
}

.social-icon svg {
  width: 20px;
  height: 20px;
}

.copyright {
  margin: 0;
  text-align: center;
  font-size: var(--font-size-xs);
  color: var(--overlay-white-80);
  text-shadow: 0 1px 2px var(--text-shadow-light);
}

/* Dynamic Footer Layout based on visible sections */

/* 1 section: Center alignment */
.footer-content--1-section {
  justify-content: center;
}

/* 2 sections: Left and Right alignment */
.footer-content--2-sections {
  justify-content: space-between;
}

/* 3 sections: Left, Center, Right alignment */
.footer-content--3-sections {
  justify-content: space-between;
}

/* Responsive Footer */
@media (width >= 760px) {
  .footer-content {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  /* Override for single section - center it */
  .footer-content--1-section {
    justify-content: center;
  }

  /* Two sections - space between (left and right) */
  .footer-content--2-sections {
    justify-content: space-between;
  }

  /* Three sections - space between with middle section */
  .footer-content--3-sections {
    justify-content: space-between;
  }

  /* Copyright positioning for different layouts */
  .footer-content--3-sections .copyright {
    order: -1;
  }

  .footer-content--2-sections .copyright {
    order: 1;
  }

  .footer-content--1-section .copyright {
    order: 0;
  }

  /* Footer links positioning */
  .footer-content--3-sections .footer-links {
    order: 0;
  }

  .footer-content--2-sections .footer-links {
    order: 0;
  }

  /* Social links positioning */
  .footer-content--3-sections .social-links {
    order: 1;
  }

  .footer-content--2-sections .social-links {
    order: 1;
  }
}

/* ===========================================================================
   PART 5: CHAT INPUT (text input, options buttons, navigation)
   =========================================================================== */

.avatar-icon {
  width: 2rem;
  height: 2rem;
}

/* Message timestamps - hidden on mobile */
.message-timestamp {
  display: none;
}

/* Completion message */
.completion-message {
  background: var(--theme-success-bg);
  backdrop-filter: blur(10px);
  border: 2px solid var(--theme-success-border);
  color: var(--theme-main-text-color);
  padding: 2rem;
  border-radius: 12px;
  text-align: center;
  width: 100%;
}

.completion-message h2 {
  margin: 0 0 1rem;
  font-size: 1.5rem;
}

/* Error Banner */
.error-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.2rem;
  background: var(--theme-danger-bg);
  color: var(--theme-main-text-color);
  border-radius: 8px;
}

.error-banner button {
  padding: 0.1rem 0.3rem 0.2rem;
  margin: 1rem;
  background: transparent;
  border: 1px solid white;
  border-radius: 4px;
  color: white;
  cursor: pointer;
}

/* ============================================
   Options Container Label
   ============================================ */

.options-label {
  text-align: left;
  color: var(--theme-nav-text-color);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 0.75rem;
}

/* ============================================
   Options Container (Multiple Choice Buttons)
   ============================================ */

.options-container {
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0 8px;
}

.option-button {
  background: var(--theme-choice-btn-bg);
  border: 2px solid var(--theme-choice-btn-border);
  color: var(--theme-user-bubble-text-color);
  padding: 0.75rem 1rem;
  border-radius: 7px;
  font-size: var(--font-size-sm);
  font-weight: 400;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  width: 100%;
  max-width: 100%;
  box-shadow: 0 4px 12px var(--theme-main-shadow);
}

.option-button:hover {
  background: var(--theme-main-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--theme-main-shadow);
}

.option-button:active {
  transform: translateY(0);
}

.option-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Focus state - no outline by default for mouse clicks (but keep outline for keyboard navigation) */
.option-button:focus:not(.keyboard-focus, :focus-visible) {
  outline: none;
}

/* Keyboard navigation - show outline for Tab navigation or programmatic focus */
.option-button:focus-visible,
.option-button.keyboard-focus {
  outline: 3px solid var(--theme-user-bubble-color) !important;
  outline-offset: 2px;
  box-shadow: 0 6px 20px var(--theme-main-shadow);
}

/* Options in row on large screens */
@media (width > 760px) {
  .options-container {
    flex-flow: row wrap;
  }

  .option-button {
    width: auto;
    flex: 1;
    min-width: 150px;
  }
}

.icon-send {
  width: 22px;
  height: 22px;
}

/* ============================================
   Navigation - Back Button Below Input/Options
   ============================================ */

.back-button,
.reset-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  padding: 0.3rem 0.6rem;
  background-color: transparent;
  border: none;
  border-radius: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  color: var(--theme-nav-text-color);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-left: 0.2rem;
}

/* Back button and Reset button - hover */
.back-button:hover,
.reset-button:hover {
  background-color: var(--overlay-white-10);
}

/* Navigation buttons only (for multiple choice) */
.navigation-buttons-only {
  display: flex;
  justify-content: flex-start;
  margin-top: 0.1rem;
  margin-bottom: 0.4rem;
  width: 100%;
}

.navigation-buttons-only form {
  display: inline-block;
  margin: 0;
}

.back-button-text {
  text-transform: uppercase;
}

/* Navigation buttons - forms generated by button_to */
.navigation-buttons-only form,
.navigation-buttons form,
.comment-navigation .navigation-buttons form {
  display: inline-block;
  margin: 0;
}


/* Icons inside buttons */
.back-button .icon-back,
.clear-button .icon-clear,
.reset-button .icon-reset {
  width: 14px;
  height: 14px;
  color: var(--theme-nav-text-color);
}

/* ============================================
   Bot Question with Input (Landbot Design)
   ============================================ */

/* Container for bot message with input inside */
.bot-question-with-input {
  width: 100%;
  max-width: 100%;
}

/* Remove bottom margin from message when it has input inside */
.bot-question-with-input .message {
  margin-bottom: 0;
}

/* Make bubble take more space when it contains input */
.bot-question-with-input article.message--bot {
  grid-template-columns: 50px 1fr;
}

/* Input section inside bot bubble */
.bot-input-inline {
  margin-top: 1rem;
  margin-bottom: 1rem;
  width: 100%;
}

/* Input field container (inline variant) */
.input-container-inline {
  width: 100%;
  position: relative;
  display: flex;
  align-items: center;
}

/* Input field inside bot bubble (inline variant) */
.chat-input-inline {
  width: 100%;
  padding: 0.875rem 3.5rem 0.875rem 1rem;
  background: var(--theme-input-bg);
  border: 2px solid var(--theme-input-border);
  border-radius: var(--theme-input-radius);

  /* 16px minimum prevents iOS Safari auto-zoom on focus */
  font-size: var(--font-size-base);
  transition: border-color 0.2s ease;
  font-family: inherit;
  color: var(--theme-input-text);
}

/* Input focus state */
.chat-input-inline:focus {
  outline: none;
  border-color: var(--theme-input-border);
}

/* Placeholder styling */
.chat-input-inline::placeholder {
  color: var(--theme-input-placeholder);
  opacity: 0.6;
}

/* Textarea specific styles */
.chat-textarea.chat-input-inline {
  resize: vertical;
  min-height: 100px;
  padding-right: 3.5rem;
}

/* Submit button with SVG icon (inline variant) */
.submit-button-inline {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: var(--theme-input-btn-bg);
  color: var(--theme-input-btn-color);
  border: 2px solid transparent;
  padding: 0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
}

/* Submit button hover state */
.submit-button-inline:hover {
  transform: translateY(-50%) scale(1.1);
}

/* Submit button active state */
.submit-button-inline:active {
  transform: translateY(-50%) scale(0.95);
}

/* Submit button disabled state */
.submit-button-inline:disabled,
.submit-button-inline[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* SVG icon sizing */
.submit-button-inline .icon-send {
  width: 24px;
  height: 24px;
}

/* Help text below input */
.input-help {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--theme-help-text-color);
  text-align: left;
  font-style: italic;
}

/* Helpful hint below input (server validation errors) */
.input-hint {
  margin-top: 0.5rem;
  font-size: var(--font-size-sm);
  color: var(--theme-input-placeholder);
  text-align: left;
}

/* Input field with error state */
.chat-input-inline.has-error {
  border-color: var(--theme-validation-border-color);
}

/* Textarea button positioning (bottom instead of center) */
.input-container-inline:has(.chat-textarea) .submit-button-inline {
  top: auto;
  bottom: 0.5rem;
  transform: none;
}

.input-container-inline:has(.chat-textarea) .submit-button-inline:hover {
  transform: scale(1.05);
}

/* Bot bubble with input - extra padding at bottom */
.bot-question-with-input .message__bubble {
  padding-bottom: 1.25rem;
}

/* ===========================================================================
   PART 6: CHAT ANIMATIONS
   =========================================================================== */

/* Slide in animation for messages */
@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

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

/* Slide selected option to top-right corner */
@keyframes slide-to-top-right {
  from {
    opacity: 1;
    transform: translate(0, 0) scale(1);
  }

  to {
    opacity: 0;
    transform: translate(100px, -100px) scale(0.5);
  }
}

/* Fade out and scale down non-selected options */
@keyframes fade-out-scale {
  from {
    opacity: 1;
    transform: scale(1);
    height: auto;
  }

  to {
    opacity: 0;
    transform: scale(0.8);
    height: 0;
    padding: 0;
    margin: 0;
  }
}

/* Slide entire container up */
@keyframes slide-up {
  from {
    opacity: 1;
    transform: translateY(0);
  }

  to {
    opacity: 0;
    transform: translateY(-50px);
  }
}

/* Slide out with elliptic motion going backwards to top */
@keyframes slide-out-elliptic-top-bck {
  0% {
    transform: translateY(0) rotateX(0) scale(1);
    transform-origin: 50% 150%;
    opacity: 1;
  }

  100% {
    transform: translateY(-30px) rotateX(-10deg) scale(0);
    transform-origin: 50% 0%;
    opacity: 1;
  }
}

/* Slide in with elliptic motion from top forwards (reverse of slide-out) */
@keyframes slide-in-elliptic-top-fwd {
  0% {
    transform: translateY(-30px) rotateX(-10deg) scale(0);
    transform-origin: 50% 0%;
    opacity: 1;
  }

  100% {
    transform: translateY(0) rotateX(0) scale(1);
    transform-origin: 50% 150%;
    opacity: 1;
  }
}

/* Focus Mode: delayed slide-in that stays hidden during typing indicator */
@keyframes focus-delayed-appear {
  0% {
    transform: translateY(-30px) rotateX(-10deg) scale(0);
    transform-origin: 50% 0%;
    opacity: 0;
    pointer-events: none;
  }

  69.9% {
    transform: translateY(-30px) rotateX(-10deg) scale(0);
    transform-origin: 50% 0%;
    opacity: 0;
    pointer-events: none;
  }

  70% {
    transform: translateY(-30px) rotateX(-10deg) scale(0.1);
    transform-origin: 50% 0%;
    opacity: 0.1;
    pointer-events: auto;
  }

  100% {
    transform: translateY(0) rotateX(0) scale(1);
    transform-origin: 50% 150%;
    opacity: 1;
    pointer-events: auto;
  }
}

/* Slide in from center to left-up position (for previous bot message) */
@keyframes slide-in-center-left-up {
  0% {
    transform: translate(50vw, 50vh) scale(0.5);
    opacity: 0;
  }

  100% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
}

/* Slide in from bottom-left to top-right (for user answer) */
@keyframes slide-in-right-up {
  0% {
    transform: translate(-100px, 50px);
    opacity: 0;
  }

  100% {
    transform: translate(0, 0);
    opacity: 1;
  }
}

/* Animation classes to apply via Stimulus */
.animate-slide-to-top-right {
  animation: slide-to-top-right 0.6s ease-out forwards;
}

.animate-fade-out-scale {
  animation: fade-out-scale 0.6s ease-out forwards;
}

.animate-slide-up {
  animation: slide-out-elliptic-top-bck 0.6s ease-out forwards;
}

/* Typing indicator (3 dots) */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  opacity: 0;
  max-height: 100px;
  overflow: hidden;
  animation: typing-fade-in-out 1.5s ease-in-out forwards, typing-remove 0.1s ease-in-out forwards !important;
  animation-delay: 0.5s, 1.8s !important;
}

.typing-indicator--no-prev {
  animation-delay: 0.3s, 1.6s !important;
}

.typing-indicator__dot {
  width: 8px;
  height: 8px;
  background-color: var(--theme-user-bubble-color);
  border-radius: 50%;
  animation: typing-dot-pulse 1.4s infinite ease-in-out;
}

.typing-indicator__dot:nth-child(1) {
  animation-delay: 0s;
}

.typing-indicator__dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator__dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing-fade-in-out {
  0% {
    opacity: 0;
  }

  10% {
    opacity: 1;
  }

  90% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@keyframes typing-dot-pulse {
  0% {
    transform: scale(1);
    opacity: 0.7;
  }

  50% {
    transform: scale(1.5);
    opacity: 1;
  }

  100% {
    transform: scale(1);
    opacity: 0.7;
  }
}

@keyframes typing-remove {
  to {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
    margin-bottom: 0;
    opacity: 0;
  }
}

/* Prevent pointer events during animation */
.animating {
  pointer-events: none;
}

/* Disable animations in test environment to fix Capybara visibility issues */
body.test-env *,
body.test-env *::before,
body.test-env *::after {
  animation: none !important;
  animation-duration: 0s !important;
  animation-delay: 0s !important;
  transition: none !important;
}

body.test-env .animate-appear-1,
body.test-env .animate-appear-2,
body.test-env .animate-appear-3,
body.test-env .typing-indicator,
body.test-env * {
  opacity: 1 !important;
}

/* ============================================
   Accessibility
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===========================================================================
   PART 7: STATIC PAGES (about, contact, privacy, terms)
   ===========================================================================
   These pages use glass effect overlays and are NOT part of the theme system.
   They work on any background image with semi-transparent white overlays.
   =========================================================================== */

main:has(.page-content) {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0.75rem 0.5rem;
  overflow-y: auto;
  min-height: 0;
}

.page-content {
  background: var(--overlay-white-95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--overlay-white-20);
  border-radius: 8px;
  padding: 1rem;
  max-width: 800px;
  width: 100%;
  color: var(--static-text-color);
}

.page-content h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--static-text-color);
  margin-bottom: 1rem;
  text-align: center;
  clear: both;
}

.page-content h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--static-text-color);
  margin-top: 1.25rem;
  margin-bottom: 0.75rem;
}

.page-content section {
  margin-bottom: 1rem;
}

.page-content p {
  line-height: 1.6;
  margin-bottom: 0.75rem;
  color: var(--static-text-color);
}

.page-content ul {
  margin-left: 1rem;
  margin-bottom: 0.75rem;
}

.page-content li {
  margin-bottom: 0.375rem;
  line-height: 1.5;
}

.page-content .back-link {
  margin-top: 1.5rem;
  text-align: center;
}

.page-content .back-link a {
  color: var(--static-primary-color);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.2s ease;
}

.page-content .back-link a:hover {
  color: var(--static-secondary-color);
  text-decoration: underline;
}

/* ===========================================================================
   PART 8: CONTACT FORM
   =========================================================================== */

/* Form groups */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: var(--static-light-text-color);
  font-weight: 600;
  font-size: var(--font-size-sm);
}

/* Form controls */
.form-control {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.5;
  color: var(--static-text-color);
  background-color: white;
  border: 2px solid var(--static-border-color);
  border-radius: 8px;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--static-primary-color);
  box-shadow: 0 0 0 3px var(--static-shadow-color);
}

.form-control::placeholder {
  color: var(--static-placeholder-color);
}

/* Textarea specific */
textarea.form-control {
  resize: vertical;
  min-height: 100px;
}

/* Form actions */
.form-actions {
  margin-top: 1.5rem;
}

.form-actions .submit-button {
  width: 100%;
  display: block;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: white;
  background: linear-gradient(135deg, var(--static-primary-color), var(--static-secondary-color));
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.3s ease;
  box-shadow: 0 4px 6px var(--box-shadow-sm);
}

.form-actions .submit-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px var(--box-shadow-md);
}

.form-actions .submit-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px var(--box-shadow-sm);
}

/* Contact success message */
.contact-success {
  text-align: center;
  padding: 1.5rem 1rem;
}

.success-message {
  max-width: 500px;
  margin: 0 auto;
}

.success-message .checkmark {
  margin: 0 auto 1.5rem;
  animation: scale-in 0.5s ease-out;
  width: 48px;
  height: 48px;
}

@keyframes scale-in {
  from {
    transform: scale(0);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

.success-message h2 {
  color: var(--static-success-color);
  margin-bottom: 1rem;
  font-size: 1.5rem;
}

.success-message p {
  color: var(--static-text-color);
  margin-bottom: 1rem;
  line-height: 1.6;
}

.back-link {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.5rem 1.5rem;
  color: var(--static-primary-color);
  text-decoration: none;
  border: 2px solid var(--static-primary-color);
  border-radius: 8px;
  transition: background-color 0.3s ease, color 0.3s ease;
}

.back-link:hover {
  background-color: var(--static-primary-color);
  color: white;
}

/* ===========================================================================
   PART 9: UTILITY & RESPONSIVE
   =========================================================================== */

/* Desktop styles for static pages (769px and up) */

@media screen and (width >= 769px) {
  main:has(.page-content) {
    padding: 2rem 1rem;
  }

  .page-content {
    padding: 2rem;
    border-radius: 12px;
  }

  .page-content h1 {
    font-size: 2rem;
    margin-bottom: 2rem;
  }

  .page-content h2 {
    font-size: 1.5rem;
    margin-top: 2rem;
    margin-bottom: 1rem;
  }

  .page-content ul {
    margin-left: 1.5rem;
  }

  .form-group {
    margin-bottom: 1.5rem;
  }

  .form-control {
    padding: 0.75rem 1rem;
  }

  textarea.form-control {
    min-height: 120px;
  }

  .form-actions {
    margin-top: 2rem;
  }

  .form-actions .submit-button {
    width: auto;
    display: inline-block;
    padding: 0.875rem 2rem;
  }

  .contact-success {
    padding: 3rem 2rem;
  }

  .success-message .checkmark {
    width: 64px;
    height: 64px;
  }
}

/* ===========================================================================
   RESPONSIVE - Hide elements on small devices (Landbot design)
   =========================================================================== */

/* Hide avatar on mobile devices (≤476px) like in Landbot */
@media screen and (width <= 476px) {
  .is-hidden-small-device {
    display: none !important;
  }

  /* When avatar is hidden, remove grid column for icon and extend bubble to full width */
  .bot-question-with-input article.message--bot {
    grid-template-columns: 1fr;
    grid-template-areas: "bubble";
  }
}

/* ===========================================================================
   RESPONSIVE - Large screens alignment (Landbot design)
   =========================================================================== */

/* On large screens (>760px), remove parent padding for bot+input (it has its own icon) */
@media screen and (width > 760px) {
  #chat-input-area .bot-question-with-input {
    margin-left: calc(-50px - 0.75rem);
  }
}

/* On tablet screens (481px - 760px), align Back button with bot message left edge */
@media screen and (481px <= width <= 760px) {
  .navigation-buttons-only {
    margin-left: calc(50px + 0.75rem);
  }
}

/* ===========================================================================
   ANDROID KEYBOARD HANDLING
   =========================================================================== */

/*
 * When Android virtual keyboard appears, viewport shrinks.
 * The viewport-height controller adds data-viewport-adjusted attribute to main#chat-container.
 *
 * Solution:
 * - Change grid layout from `auto auto` to `1fr auto`
 * - #chat-messages takes all available space (scrollable)
 * - #chat-input-area stays auto-sized
 * - Remove center alignment to prevent squishing
 * - Input field stays visible, messages are scrollable (NOT gray area!)
 */

main#chat-container[data-viewport-adjusted="true"] {
  /* Change grid layout: messages take all space, input is auto */
  grid-template-rows: 1fr auto !important;

  /* Remove center alignment (causes squishing) */
  align-content: start !important;
}

/* ===========================================================================
   M2: FOCUS MODE (wizard-style one question at a time)
   =========================================================================== */

/*
 * Focus Mode shows only the current question (wizard-style).
 * Messages are replaced instead of appended on each step.
 * Visual style: centered single question with cleaner appearance.
 */

main#chat-container.focus-mode {
  /* Center content vertically for single-question display */
  align-content: center;
}

main#chat-container.focus-mode section#chat-messages {
  /* Allow messages area to grow but keep it centered */
  flex-grow: 0;
}

/* Focus Mode typing indicator - shows immediately and fades out in ~1s */
.typing-indicator--focus {
  animation: focus-typing-fade 1s ease-in-out forwards !important;
  animation-delay: 0s !important;
}

@keyframes focus-typing-fade {
  0% {
    opacity: 0;
  }

  10% {
    opacity: 1;
  }

  80% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    max-height: 0;
    padding: 0;
    margin: 0;
  }
}

/* In Focus Mode, typing indicator can be simpler */
main#chat-container.focus-mode .typing-indicator {
  margin-top: 0.5rem;
}

/* Focus Mode animations - bot message appears after typing indicator
 * Uses focus-delayed-appear keyframes:
 * - 0-70%: element stays invisible (opacity: 0, scale: 0)
 * - 70-100%: element animates in (typing indicator duration ~1.05s = 70% of 1.5s)
 * Total animation duration 1.5s ensures typing dots finish before message appears
 */
main#chat-container.focus-mode article.message.animate-focus-bot {
  animation: focus-delayed-appear 1.5s ease-out both !important;
  opacity: 0;
  transform: translateY(-30px) rotateX(-10deg) scale(0);
  transform-origin: 50% 0%;
}

/* Focus Mode input wrapper - appears with bot message */
main#chat-container.focus-mode #input-wrapper.animate-focus-input {
  animation: focus-delayed-appear 1.5s ease-out both;
  opacity: 0;
  transform: translateY(-30px) rotateX(-10deg) scale(0);
  transform-origin: 50% 0%;
}
