/**
 * Muoversi Liberi — Native Chat Widget Styles
 * Integrated UIkit 3 & YOOtheme Pro Design System
 */

:root {
  --ml-chat-primary: #e74266;
  --ml-chat-primary-hover: #db4061;
  --ml-chat-secondary: #20b69e;
  --ml-chat-secondary-hover: #1ca08a;
  --ml-chat-secondary-light: #f0fdfa;
  --ml-chat-dark: #101330;
  --ml-chat-dark-rgb: 16, 19, 48;
  --ml-chat-bg: #f8fafc;
  --ml-chat-card-bg: #ffffff;
  --ml-chat-border: #e2e8f0;
  --ml-chat-text: #1e293b;
  --ml-chat-text-muted: #64748b;
  --ml-chat-radius: 16px;
  --ml-chat-shadow: 0 12px 36px -6px rgba(16, 19, 48, 0.18), 0 4px 12px -2px rgba(16, 19, 48, 0.08);
}

/* ==========================================================================
   Widget Container & Base
   ========================================================================== */
.ml-chat-widget-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ml-chat-text);
  box-sizing: border-box;
}

.ml-chat-widget-container *,
.ml-chat-widget-container *::before,
.ml-chat-widget-container *::after {
  box-sizing: border-box;
}

/* ==========================================================================
   Floating Toggle Button
   ========================================================================== */
.ml-chat-toggle-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ml-chat-primary) 0%, var(--ml-chat-primary-hover) 100%);
  color: #ffffff;
  border: none;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(231, 66, 102, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  outline: none;
  position: relative;
}

.ml-chat-toggle-btn:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 10px 28px rgba(231, 66, 102, 0.55);
}

.ml-chat-toggle-btn:active {
  transform: scale(0.96);
}

.ml-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  background: var(--ml-chat-secondary);
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #ffffff;
}

/* ==========================================================================
   Proactive Teaser Balloon
   ========================================================================== */
.ml-chat-teaser {
  position: absolute;
  bottom: 74px;
  right: 0;
  width: 280px;
  background: var(--ml-chat-card-bg);
  border: 1px solid var(--ml-chat-border);
  border-radius: 12px;
  box-shadow: var(--ml-chat-shadow);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  animation: mlTeaserSlide 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  transition: transform 0.2s ease;
}

.ml-chat-teaser:hover {
  transform: translateY(-2px);
}

.ml-chat-teaser::after {
  content: "";
  position: absolute;
  bottom: -8px;
  right: 24px;
  border-width: 8px 8px 0 8px;
  border-style: solid;
  border-color: var(--ml-chat-card-bg) transparent transparent transparent;
}

.ml-chat-teaser-close {
  position: absolute;
  top: 4px;
  right: 6px;
  background: none;
  border: none;
  font-size: 16px;
  color: var(--ml-chat-text-muted);
  cursor: pointer;
  line-height: 1;
}

.ml-chat-teaser-content {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.ml-chat-teaser-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.ml-chat-teaser-text strong {
  color: var(--ml-chat-primary);
}

/* ==========================================================================
   Chat Window (Drawer)
   ========================================================================== */
.ml-chat-window {
  position: absolute;
  bottom: 76px;
  right: 0;
  width: 380px;
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--ml-chat-bg);
  border-radius: var(--ml-chat-radius);
  border: 1px solid var(--ml-chat-border);
  box-shadow: var(--ml-chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: mlWindowPop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom right;
}

/* ==========================================================================
   Header
   ========================================================================== */
.ml-chat-header {
  background: linear-gradient(135deg, var(--ml-chat-dark) 0%, #1a1e48 100%);
  color: #ffffff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top-left-radius: var(--ml-chat-radius);
  border-top-right-radius: var(--ml-chat-radius);
  flex-shrink: 0;
}

.ml-chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ml-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.ml-chat-avatar-icon {
  font-size: 20px;
}

.ml-chat-status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid var(--ml-chat-dark);
}

.ml-chat-title-wrap {
  display: flex;
  flex-direction: column;
}

.ml-chat-header-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.2px;
}

.ml-chat-header-sub {
  font-size: 11px;
  color: #94a3b8;
}

.ml-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ml-chat-action-btn {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #ffffff;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.ml-chat-action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   Messages Stream
   ========================================================================== */
.ml-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.ml-chat-messages::-webkit-scrollbar {
  width: 6px;
}

.ml-chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

/* Message Bubble Wrap */
.ml-msg-wrap {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: mlMsgAppear 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.ml-msg-wrap-ai {
  align-self: flex-start;
}

.ml-msg-wrap-user {
  align-self: flex-end;
}

.ml-msg-bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.48;
  word-wrap: break-word;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.ml-msg-wrap-ai .ml-msg-bubble {
  background: var(--ml-chat-card-bg);
  border: 1px solid var(--ml-chat-border);
  color: var(--ml-chat-text);
  border-bottom-left-radius: 4px;
}

.ml-msg-wrap-ai .ml-msg-bubble a {
  color: var(--ml-chat-secondary);
  font-weight: 600;
  text-decoration: underline;
}

.ml-msg-wrap-user .ml-msg-bubble {
  background: var(--ml-chat-secondary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.ml-msg-time {
  font-size: 10px;
  color: var(--ml-chat-text-muted);
  margin-top: 3px;
  padding: 0 4px;
}

.ml-msg-wrap-user .ml-msg-time {
  text-align: right;
}

/* ==========================================================================
   Quick-Reply Chips / Action Pills
   ========================================================================== */
.ml-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  animation: mlChipsAppear 0.3s ease;
}

.ml-chip-btn {
  background: var(--ml-chat-secondary-light);
  color: #0f766e;
  border: 1.5px solid #99f6e4;
  border-radius: 20px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  outline: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  line-height: 1.2;
}

.ml-chip-btn:hover {
  background: var(--ml-chat-secondary);
  color: #ffffff;
  border-color: var(--ml-chat-secondary);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(32, 182, 158, 0.3);
}

.ml-chip-btn:active {
  transform: scale(0.96);
}

.ml-chips-container.ml-chips-disabled {
  opacity: 0.6;
  pointer-events: none;
}

/* ==========================================================================
   Typing Indicator
   ========================================================================== */
.ml-chat-typing {
  padding: 0 16px 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--ml-chat-text-muted);
  flex-shrink: 0;
}

.ml-typing-bubble {
  background: var(--ml-chat-card-bg);
  border: 1px solid var(--ml-chat-border);
  padding: 6px 10px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.ml-typing-bubble span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ml-chat-secondary);
  animation: mlTypingJump 1.2s infinite ease-in-out;
}

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

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

/* ==========================================================================
   Input Footer
   ========================================================================== */
.ml-chat-footer {
  background: var(--ml-chat-card-bg);
  border-top: 1px solid var(--ml-chat-border);
  padding: 10px 14px;
  flex-shrink: 0;
}

.ml-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ml-chat-bg);
  border: 1.5px solid var(--ml-chat-border);
  border-radius: 24px;
  padding: 4px 6px 4px 14px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ml-chat-input-row:focus-within {
  border-color: var(--ml-chat-secondary);
  box-shadow: 0 0 0 3px rgba(32, 182, 158, 0.15);
  background: #ffffff;
}

.ml-chat-textarea {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--ml-chat-text);
  resize: none;
  max-height: 80px;
  line-height: 1.4;
  padding: 6px 0;
}

.ml-chat-textarea::placeholder {
  color: #94a3b8;
}

.ml-chat-send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--ml-chat-secondary);
  color: #ffffff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.ml-chat-send-btn:hover {
  background: var(--ml-chat-secondary-hover);
  transform: scale(1.05);
}

.ml-chat-send-btn:active {
  transform: scale(0.95);
}

.ml-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.ml-chat-gdpr-notice {
  font-size: 10.5px;
  color: #94a3b8;
  text-align: center;
  margin-top: 6px;
}

.ml-chat-gdpr-notice a {
  color: #64748b;
  text-decoration: underline;
}

.ml-chat-gdpr-notice a:hover {
  color: var(--ml-chat-secondary);
}

/* ==========================================================================
   Animations & Responsive
   ========================================================================== */
@keyframes mlWindowPop {
  0% {
    opacity: 0;
    transform: scale(0.85) translateY(20px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes mlTeaserSlide {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes mlMsgAppear {
  0% {
    opacity: 0;
    transform: translateY(8px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes mlChipsAppear {
  0% {
    opacity: 0;
    transform: translateY(4px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes mlTypingJump {
  0%, 60%, 100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-4px);
  }
}

/* Mobile Fullscreen Drawer */
@media (max-width: 480px) {
  .ml-chat-widget-container {
    bottom: 16px;
    right: 16px;
  }

  .ml-chat-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
    z-index: 9999999;
  }

  .ml-chat-header {
    border-radius: 0;
    padding: 16px;
  }

  .ml-chat-teaser {
    width: calc(100vw - 32px);
    right: -8px;
  }
}
