/* Chatbot Platform Widget Styles */

/* Bubble (FAB) */
.lwa-bubble {
  position: fixed;
  bottom: 24px;
  z-index: 999998;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.lwa-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}
.lwa-bubble--right { right: 24px; }
.lwa-bubble--left  { left: 24px; }

/* Panel */
.lwa-panel {
  position: fixed;
  bottom: 92px;
  z-index: 999999;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
  background: #fff;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  transition: opacity 0.25s, transform 0.25s;
}
.lwa-panel--right { right: 24px; }
.lwa-panel--left  { left: 24px; }
.lwa-panel--hidden {
  opacity: 0;
  pointer-events: none;
}

/* Animation variants */
.lwa-panel--anim-slide.lwa-panel--hidden {
  opacity: 0;
  transform: translateY(16px) scale(0.96);
}
.lwa-panel--anim-fade.lwa-panel--hidden {
  opacity: 0;
  transform: none;
}
.lwa-panel--anim-bounce.lwa-panel--hidden {
  opacity: 0;
  transform: scale(0.8);
}
.lwa-panel--anim-none {
  transition: none !important;
}
.lwa-panel--anim-none.lwa-panel--hidden {
  display: none;
}

/* Bounce animation on show */
.lwa-panel--anim-bounce:not(.lwa-panel--hidden) {
  animation: lwa-bounce-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes lwa-bounce-in {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

/* Header */
.lwa-header {
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.lwa-header__left {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.lwa-header__bot-name {
  font-size: 12px;
  opacity: 0.8;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lwa-header__title { font-weight: 600; font-size: 15px; }
.lwa-header__actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.lwa-header__new {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  font-size: 20px;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}
.lwa-header__new:hover { color: #fff; }
.lwa-header__close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  font-size: 18px;
  padding: 0;
  transition: color 0.15s;
}
.lwa-header__close:hover { color: #fff; }

/* Messages area */
.lwa-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f9fafb;
}

/* Message bubbles */
.lwa-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
}
.lwa-msg--user {
  align-self: flex-end;
  background: #4f46e5;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.lwa-msg--bot {
  align-self: flex-start;
  background: #fff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}
.lwa-msg--bot a {
  color: #4f46e5;
  text-decoration: underline;
}
.lwa-msg--bot strong, .lwa-msg--bot b {
  font-weight: 700;
}
.lwa-msg--bot em, .lwa-msg--bot i {
  font-style: italic;
}
.lwa-msg--bot ul {
  margin: 4px 0;
  padding-left: 20px;
}
.lwa-msg--bot li {
  margin: 2px 0;
}

/* System messages (escalation notices, etc.) */
.lwa-msg--system {
  align-self: center;
  max-width: 90%;
  background: transparent;
  padding: 8px 16px;
  text-align: center;
  font-size: 12px;
  color: #6b7280;
  font-style: italic;
}

/* Agent messages (human agent replies) */
.lwa-msg--agent {
  align-self: flex-start;
  background: #f0fdf4;
  color: #1f2937;
  border: 1px solid #bbf7d0;
  border-bottom-left-radius: 4px;
}
.lwa-msg__agent-label {
  font-size: 11px;
  font-weight: 600;
  color: #16a34a;
  margin-bottom: 4px;
}

/* Rating buttons */
.lwa-msg__rating {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  opacity: 0.5;
  transition: opacity 0.2s;
}
.lwa-msg:hover .lwa-msg__rating,
.lwa-msg__rating:focus-within {
  opacity: 1;
}
.lwa-rate-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  color: #9ca3af;
  transition: color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lwa-rate-btn:hover {
  color: #6b7280;
  background: #f3f4f6;
}
.lwa-rate-up.lwa-rate-active-up {
  color: #22c55e;
  background: #f0fdf4;
}
.lwa-rate-down.lwa-rate-active-down {
  color: #ef4444;
  background: #fef2f2;
}
.lwa-rate-disabled {
  pointer-events: none;
  cursor: default;
}

/* Input area */
.lwa-input-area {
  padding: 12px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  flex-shrink: 0;
}
.lwa-input-wrap {
  flex: 1;
  display: flex;
  gap: 8px;
}
.lwa-input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.4;
}
.lwa-input:focus {
  border-color: #4f46e5;
}
.lwa-send {
  background: #4f46e5;
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.lwa-send:hover { background: #4338ca; }
.lwa-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Typing indicator */
.lwa-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}
.lwa-typing span {
  width: 6px;
  height: 6px;
  background: #9ca3af;
  border-radius: 50%;
  animation: lwa-bounce 1.2s infinite;
}
.lwa-typing span:nth-child(2) { animation-delay: 0.2s; }
.lwa-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes lwa-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* Mobile */
@media (max-width: 480px) {
  .lwa-panel {
    width: 100%;
    height: 100dvh;
    bottom: 0;
    right: 0;
    left: 0;
    border-radius: 0;
    max-height: 100dvh;
    /* Full-screen mobile mode — JS handles keyboard resizing */
  }
  .lwa-panel.lwa-panel--mobile {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    max-height: none;
  }
  /* When keyboard is open, panel sizes to visual viewport */
  .lwa-panel.lwa-panel--keyboard {
    height: var(--lwa-vh, 100%);
    max-height: var(--lwa-vh, 100%);
  }
  .lwa-bubble { bottom: 16px; right: 16px; }
  /* Larger touch targets on mobile */
  .lwa-header { padding: 12px 14px; }
  .lwa-header__close, .lwa-header__new { padding: 8px; }
  .lwa-input { font-size: 16px; /* Prevents iOS zoom on focus */ }
  .lwa-send { width: 44px; height: 44px; }
  .lwa-rate-btn { padding: 8px; }
}

/* ── Contact Form ────────────────────────────── */
.lwa-contact-form {
  padding: 8px 0;
}
.lwa-contact-form__text {
  font-size: 13px;
  color: #475569;
  margin-bottom: 10px;
  line-height: 1.4;
}
.lwa-contact-form__fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lwa-contact-form__fields input {
  padding: 8px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.lwa-contact-form__fields input:focus {
  border-color: #6366f1;
}
.lwa-contact-form__fields button {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}
.lwa-contact-form__fields button:hover {
  opacity: 0.9;
}
.lwa-contact-form__fields button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.lwa-contact-success {
  font-size: 14px;
  color: #15803d;
  text-align: center;
  padding: 8px 0;
}

/* Escalation confirmation */
.lwa-escalation-confirm {
  text-align: center;
}
.lwa-escalation-confirm__text {
  font-size: 14px;
  margin-bottom: 12px;
  color: #374151;
}
.lwa-escalation-confirm__buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.lwa-escalation-confirm__buttons button {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.2s;
}
.lwa-escalation-confirm__buttons button:hover {
  opacity: 0.9;
}
.lwa-escalation-confirm__buttons .lwa-escalation-no {
  background: #f3f4f6;
  color: #374151;
}
.lwa-escalation-confirm__buttons .lwa-escalation-no:hover {
  background: #e5e7eb;
}
