/* VIIDES.AI Floating Chat Widget Styles */

/* New pill-shaped button styles */
.viides-ai-pill-button {
  cursor: pointer;
  transition: all 0.3s ease;
}

.viides-ai-pill-button:hover {
  transform: scale(1.03);
}

.viides-ai-pill-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--viidesai-bg, #282828);
  border: 2px solid var(--viidesai-accent, #e61e23);
  border-radius: 35px;
  padding: 8px 4px 8px 18px;
  height: 60px;
  max-width: 270px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
}

.viides-ai-pill-button:hover .viides-ai-pill-container {
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  border-color: var(--viidesai-accent, #e61e23);
}

.viides-ai-pill-text {
  color: var(--viidesai-text, #ffffff);
  font-size: 13px;
  font-weight: 500;
  margin: 0;
  padding-right: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.viides-ai-pill-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  transition: all 0.3s ease;
  animation: viides-ai-pulse 2s infinite;
}

.viides-ai-pill-button:hover .viides-ai-pill-icon {
  background-color: color-mix(in srgb, var(--viidesai-accent, #e61e23) 10%, transparent);
  transform: scale(1.05);
}

/* Byline under the button */
.viides-ai-byline {
  font-size: 10px;
  color: #777;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  margin: -2px 28px;
}

.viides-ai-byline img {
  height: 10px;
  width: auto;
  opacity: 0.75;
}

@keyframes viides-ai-pulse {
  0% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--viidesai-accent, #e61e23) 60%, transparent);
  }
  70% {
    box-shadow: 0 0 0 8px color-mix(in srgb, var(--viidesai-accent, #e61e23) 0%, transparent);
  }
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--viidesai-accent, #e61e23) 0%, transparent);
  }
}

/* Floating Chat Container */
.viidesai-floating-chat {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 380px;
  height: 500px;
  z-index: 2147483646;
  display: none;
  flex-direction: column;
}

/* Close button for floating chat */
.viidesai-floating-chat .viidesai-chat-close {
  position: absolute;
  top: -18px;
  right: -18px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ffffff;
  border: 1px solid #e1e1e1;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  color: #000;
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2147483647;
}

.viidesai-floating-chat .viidesai-chat-close:hover {
  filter: brightness(0.98);
}

/* Floating Chat Styles */
.viidesai-floating-chat .tootsie-chat {
  position: relative;
  max-width: none;
  margin: 0;
  border: 1px solid #ddd;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  width: 100%;
  z-index: 2147483646;
}

/* Mobile responsive floating chat */
@media (max-width: 768px) {
  /* Mobile styles for pill button */
  .viides-ai-pill-container {
    max-width: 200px !important;
    height: 50px !important;
    padding: 6px 3px 6px 15px !important;
  }
  
  .viides-ai-pill-text {
    font-size: 11px !important;
  }
  
  .viides-ai-pill-icon {
    height: 40px !important;
    width: 40px !important;
  }
  
  .viides-ai-pill-icon img {
    width: 20px !important;
    height: 20px !important;
  }
  
  .viidesai-floating-chat {
    bottom: 75px;
    right: 10px;
    left: 10px;
    width: auto;
    height: 70vh;
    max-height: 500px;
  }

  .viidesai-floating-chat .viidesai-chat-close {
    top: -14px;
    right: -14px;
    width: 32px;
    height: 32px;
    font-size: 20px;
  }
  
  .viidesai-floating-chat .tootsie-chat {
    height: 100%;
    border-radius: 12px;
  }
}

/* Hide mobile toggle in floating mode */
.viidesai-floating-chat .mobile-toggle {
  display: none !important;
}

/* Traditional Chat Widget Styles */

.tootsie-chat {
  position: relative;
  max-width: 720px;
  margin: 1rem auto;
  border: 1px solid #ddd;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  background: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 600px; /* Kiinteä korkeus desktopille */
  min-height: 500px; /* Minimikorkeus */
  z-index: 2147483640; /* Nosta widget yli teemakomponenttien */
}

/* Piilota mobiilipainikkeet oletuksena (desktop) */
.tootsie-chat .mobile-toggle {
  display: none;
}

/* Desktop responsiiviset korkeudet */
@media (min-width: 769px) {
  .tootsie-chat {
    height: 600px;
    min-height: 500px;
  }
}

@media (min-width: 769px) and (max-height: 800px) {
  .tootsie-chat {
    height: 500px;
    min-height: 400px;
  }
}

@media (min-width: 769px) and (max-height: 600px) {
  .tootsie-chat {
    height: 400px;
    min-height: 350px;
  }
}

/* Mobiili-optimointi - viewport ja keyboard handling */
@media (max-width: 768px) {
  .tootsie-chat {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: 0;
    margin: 0;
    border-radius: 0;
    z-index: 2147483646; /* Maksimi-alue mobiilissa */
    max-width: none;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
  }
  
  /* Mobiili widget-tila - ei peitä koko sivua */
  .tootsie-chat.widget-mode {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    top: auto;
    height: 400px;
    max-height: 60vh;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    z-index: 2147483645;
  }
  
  /* Varmista että sivun sisältö näkyy widget-tilassa */
  .tootsie-chat.widget-mode ~ * {
    position: relative;
    z-index: 1;
  }
  
  /* Lisää padding sivun alaosaan widget-tilassa */
  body:has(.tootsie-chat.widget-mode) {
    padding-bottom: 440px; /* Chat korkeus + marginaali */
  }
  
  /* Mobiili widget-tila kun keyboard on auki */
  .tootsie-chat.widget-mode.keyboard-open {
    height: 300px;
    max-height: 50vh;
  }
  
  /* Kun keyboard on auki, käytä dynamic viewport height */
  @media (max-height: 500px) {
    .tootsie-chat {
      height: 100vh;
      height: 100dvh;
    }
  }
  
  /* Poistettu mobile close -nappi */
  
  /* Näytä mobiilipainikkeet vain mobiilissa */
  .tootsie-chat .mobile-close,
  .tootsie-chat .mobile-toggle {
    display: flex;
  }
  
  /* Mobiili toggle button - vaihda fullscreen/widget tilan välillä */
  .tootsie-chat .mobile-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 30px;
    height: 30px;
    background: rgba(0, 0, 0, 0.5);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 16px;
    cursor: pointer;
    z-index: 2147483647;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  .tootsie-chat .mobile-toggle:hover {
    background: rgba(0, 0, 0, 0.7);
  }
  
  /* Mobiili header positioning */
  .tootsie-chat .header {
    position: relative;
    padding-right: 50px; /* Tilaa toggle buttonille */
  }
  
  /* Mobiili form positioning - varmista että pysyy keyboardin yläpuolella */
  .tootsie-chat .form {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #eee;
    padding: 0.75rem;
    z-index: 10;
  }
}

.tootsie-chat .header {
  padding: 0.75rem 1rem;
  font-weight: 600;
  border-bottom: 1px solid #eee;
  background-image: url('./img/tootsie_header.jpg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  min-height: 60px;
  display: flex;
  align-items: center;
  flex-shrink: 0; /* Estä headerin kutistuminen */
}

.tootsie-chat .msgs {
  padding: 1rem;
  overflow-y: auto; /* Varmista että skrollaus toimii */
  background: #fafafa;
  flex: 1;
  min-height: 0; /* Tärkeä flexbox:lle */
}

/* Mobiili-optimointi viestialueelle */
@media (max-width: 768px) {
  .tootsie-chat .msgs {
    height: auto;
    flex: 1;
    min-height: 0;
    max-height: calc(100vh - 200px);
    max-height: calc(100dvh - 200px);
  }
}

.tootsie-chat .msg {
  display: flex;
  margin-bottom: 0.6rem;
}

.tootsie-chat .msg.user {
  justify-content: flex-end;
}

.tootsie-chat .msg .bubble {
  max-width: 80%;
  padding: 0.6rem 0.8rem;
  border-radius: 14px;
  line-height: 1.35;
  font-size: 15px;
  white-space: pre-wrap;
}

.tootsie-chat .msg.user .bubble {
  background: #dff1ff;
  border: 1px solid #c4e4ff;
}

.tootsie-chat .msg.bot .bubble {
  background: #fff;
  border: 1px solid #e7e7e7;
}

/* Linkit chat-vastauksissa */
.tootsie-chat .msg.bot .bubble a {
  color: #0073aa;
  text-decoration: underline;
}

.tootsie-chat .msg.bot .bubble a:hover {
  color: #005a87;
}

/* Luettelot chat-vastauksissa */
.tootsie-chat .msg.bot .bubble ul,
.tootsie-chat .msg.bot .bubble ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.tootsie-chat .msg.bot .bubble li {
  margin-bottom: 0.25rem;
}

.tootsie-chat .msg.thinking .bubble {
  opacity: 0.6;
  font-style: italic;
  background: #e8f4fd !important;
  border-color: #b3d9ff !important;
}

/* Loading animaatio */
.tootsie-chat .thinking-dots {
  display: inline-block;
  position: relative;
  width: 20px;
  height: 20px;
}

.tootsie-chat .thinking-dots::after {
  content: '';
  display: block;
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #007bff;
  animation: thinking 1.2s infinite;
}

.tootsie-chat .thinking-dots::before {
  content: '';
  display: block;
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #007bff;
  animation: thinking 1.2s infinite 0.2s;
  left: 12px;
}

.tootsie-chat .thinking-dots span {
  display: block;
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #007bff;
  animation: thinking 1.2s infinite 0.4s;
  left: 24px;
}

@keyframes thinking {
  0%, 80%, 100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Valmiit kysymykset */
.tootsie-chat .quick-questions {
  padding: 0.75rem;
  border-top: 1px solid #eee;
  background: #f8f9fa;
  flex-shrink: 0; /* Estä kutistuminen */
}

.tootsie-chat .quick-questions h4 {
  margin: 0 0 0.5rem 0;
  font-size: 14px;
  color: #666;
  font-weight: 500;
}

.tootsie-chat .quick-questions .buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.tootsie-chat .quick-questions button {
  padding: 0.4rem 0.8rem;
  border: 1px solid #ddd;
  background: #fff;
  color: #333;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
  white-space: nowrap;
}

/* Mobiili-optimointi */
@media (max-width: 768px) {
    .tootsie-chat .quick-questions button {
      font-size: 9px !important;
      padding: 0.2rem 0.9rem !important;
    }
  }

.tootsie-chat .quick-questions button:hover {
  background: #f0f0f0;
  border-color: #ccc;
}

.tootsie-chat .quick-questions button:active {
  transform: scale(0.95);
}

/* Valmiit vastaukset - eri väri */
.tootsie-chat .quick-questions button.has-quick-answer {
  background: #e8f5e8;
  border-color: #4caf50;
  color: #2e7d32;
}

.tootsie-chat .quick-questions button.has-quick-answer:hover {
  background: #c8e6c9;
  border-color: #388e3c;
}

.tootsie-chat .form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid #eee;
  background: #fff;
  flex-shrink: 0; /* Estä kutistuminen */
}

.tootsie-chat .form input {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border: 1px solid #ddd !important;
  border-radius: 10px !important;
  outline: none !important;
  box-shadow: none !important;
  background: #fff !important;
  color: #333 !important;
  font-size: 15px !important;
}

.tootsie-chat .form input:focus {
  outline: none !important;
  box-shadow: 0 0 0 2px #2b6cff !important;
  border-color: #2b6cff !important;
}

.tootsie-chat .form button {
  padding: 0.6rem 0.9rem;
  border: 1px solid #1b5cff !important;
  background: #2b6cff !important;
  color: #fff !important;
  border-radius: 10px !important;
  cursor: pointer;
  font-size: 15px !important;
  font-weight: 500 !important;
}

.tootsie-chat .form button:hover {
  filter: brightness(0.96) !important;
  background: #1b5cff !important;
}

.tootsie-chat .form button:focus {
  outline: none !important;
  box-shadow: 0 0 0 2px rgba(43, 108, 255, 0.3) !important;
}

/* --- Mobile inline mode: chat kiinni sivussa, ei leiju --- */
@media (max-width: 768px) {
  .tootsie-chat {
    position: static !important;
    margin: 0 0 16px 0 !important;
    border-radius: 12px !important;
    z-index: auto !important;
    max-width: none !important;
    height: auto !important;
    min-height: 380px !important;
  }

  .tootsie-chat.widget-mode {
    position: static !important;
    height: auto !important;
    max-height: none !important;
    border-radius: 12px !important;
    box-shadow: none !important;
    z-index: auto !important;
  }

  /* Ei lisätä paddingia bodyyn inline-tilassa */
  body:has(.tootsie-chat.widget-mode) {
    padding-bottom: 0 !important;
  }

  /* Input-alue pysyy näkyvissä ilman leijuntaa */
  .tootsie-chat .form {
    position: static !important;
    z-index: 1 !important;
  }

  /* Valinnainen FULLSCREEN-tila mobiilissa: lisää .fullscreen-mobile juureen jos haluat peittävän tilan */
  .tootsie-chat.fullscreen-mobile {
    position: fixed !important;
    inset: 0 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    z-index: 2147483646 !important;
    height: 100vh !important;
    height: 100dvh !important;
  }
}
