/* ==========================================================================
   ONMA scout Chat Widget — namespaced styles (.onma-chat-*)
   All rules are scoped under .onma-chat-* to avoid clashing with the host
   site's existing CSS. No global element selectors, no resets.
   ========================================================================== */

.onma-chat-root {
  --onma-primary: #0b5fff;
  --onma-primary-dark: #0a4fd1;
  --onma-bg: #ffffff;
  --onma-bg-soft: #f4f6fb;
  --onma-text: #1a1d29;
  --onma-text-muted: #6b7280;
  --onma-border: #e5e7eb;
  --onma-bot-bubble: #f1f3f9;
  --onma-user-bubble: #0b5fff;
  --onma-user-bubble-text: #ffffff;
  --onma-error: #d92d20;
  --onma-radius: 16px;
  --onma-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  position: fixed;
  z-index: 999999;
  right: 20px;
  bottom: 20px;
  font-family: var(--onma-font);
  line-height: 1.4;
}

.onma-chat-root * {
  box-sizing: border-box;
}

/* ---------- Launcher button ---------- */
.onma-chat-launcher {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--onma-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(11, 95, 255, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.onma-chat-launcher:hover {
  background: var(--onma-primary-dark);
  transform: translateY(-2px);
}

.onma-chat-launcher:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.onma-chat-launcher svg {
  width: 26px;
  height: 26px;
}

.onma-chat-launcher-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ff4d4f;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ---------- Panel ---------- */
.onma-chat-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 600px;
  max-height: calc(100vh - 140px);
  background: var(--onma-bg);
  border-radius: var(--onma-radius);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  border: 1px solid var(--onma-border);
}

.onma-chat-panel.onma-chat-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ---------- Header ---------- */
.onma-chat-header {
  background: linear-gradient(135deg, var(--onma-primary), var(--onma-primary-dark));
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.onma-chat-header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.onma-chat-header-title {
  font-weight: 700;
  font-size: 15px;
}

.onma-chat-header-status {
  font-size: 12px;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 6px;
}

.onma-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
}

.onma-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.onma-chat-lang-switch {
  display: flex;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.onma-chat-lang-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 4px 7px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.onma-chat-lang-btn:hover {
  color: #fff;
}

.onma-chat-lang-btn-active {
  background: #fff;
  color: var(--onma-primary-dark);
}

.onma-chat-lang-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

.onma-chat-close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
  flex-shrink: 0;
}

.onma-chat-close:hover {
  background: rgba(255, 255, 255, 0.28);
}

.onma-chat-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ---------- Consent notice (shown until cookie consent accepted) ---------- */
.onma-chat-consent {
  padding: 20px 18px;
  text-align: center;
  color: var(--onma-text-muted);
  font-size: 13px;
  margin: auto;
}

.onma-chat-consent strong {
  display: block;
  color: var(--onma-text);
  font-size: 14px;
  margin-bottom: 6px;
}

/* ---------- Message list ---------- */
.onma-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--onma-bg-soft);
}

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

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

.onma-chat-row {
  display: flex;
  gap: 8px;
  max-width: 88%;
}

.onma-chat-row.onma-chat-row-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.onma-chat-row.onma-chat-row-bot {
  align-self: flex-start;
}

.onma-chat-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--onma-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.onma-chat-row-user .onma-chat-avatar {
  background: #94a3b8;
}

.onma-chat-avatar-bot {
  background: #fff;
  border: 1px solid var(--onma-border);
  overflow: hidden;
  padding: 3px;
}

.onma-chat-avatar-bot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.onma-chat-sources {
  margin-top: 4px;
  font-size: 11px;
  color: var(--onma-text-muted);
  padding: 0 2px;
}

.onma-chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.onma-chat-row-bot .onma-chat-bubble {
  background: var(--onma-bot-bubble);
  color: var(--onma-text);
  border-bottom-left-radius: 4px;
}

.onma-chat-row-user .onma-chat-bubble {
  background: var(--onma-user-bubble);
  color: var(--onma-user-bubble-text);
  border-bottom-right-radius: 4px;
}

.onma-chat-bubble-error {
  background: #fef2f2 !important;
  color: var(--onma-error) !important;
  border: 1px solid #fecaca;
}

.onma-chat-lead-card {
  background: var(--onma-bot-bubble);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  padding: 14px;
  max-width: 280px;
}

.onma-chat-lead-title {
  display: block;
  font-size: 14px;
  color: var(--onma-text);
  margin-bottom: 4px;
}

.onma-chat-lead-body {
  font-size: 13px;
  color: var(--onma-text-muted);
  margin: 0 0 10px;
}

.onma-chat-lead-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.onma-chat-lead-form input[type="text"],
.onma-chat-lead-form input[type="email"],
.onma-chat-lead-form input[type="tel"] {
  border: 1px solid var(--onma-border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--onma-text);
  background: var(--onma-bg);
  outline: none;
}

.onma-chat-lead-form input:focus {
  border-color: var(--onma-primary);
}

.onma-chat-lead-consent-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--onma-text-muted);
  cursor: pointer;
}

.onma-chat-lead-consent-row input {
  margin-top: 2px;
  flex-shrink: 0;
}

.onma-chat-lead-error {
  font-size: 12px;
  color: var(--onma-error);
  margin: 0;
}

.onma-chat-lead-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 2px;
}

.onma-chat-lead-dismiss {
  background: none;
  border: none;
  color: var(--onma-text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 8px;
}

.onma-chat-lead-submit {
  background: var(--onma-primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.onma-chat-lead-submit:hover:not(:disabled) {
  background: var(--onma-primary-dark);
}

.onma-chat-lead-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.onma-chat-lead-thankyou {
  font-size: 13px;
  color: var(--onma-text);
  margin: 0;
}

.onma-chat-retry {
  margin-top: 6px;
  background: none;
  border: 1px solid var(--onma-error);
  color: var(--onma-error);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.onma-chat-retry:hover {
  background: var(--onma-error);
  color: #fff;
}

/* ---------- Typing / loading indicator ---------- */
.onma-chat-typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 2px;
}

.onma-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #94a3b8;
  animation: onma-chat-bounce 1.2s infinite ease-in-out;
}

.onma-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.onma-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes onma-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Input area ---------- */
.onma-chat-inputbar {
  border-top: 1px solid var(--onma-border);
  padding: 10px 12px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--onma-bg);
  flex-shrink: 0;
}

.onma-chat-textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--onma-border);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  max-height: 120px;
  min-height: 40px;
  color: var(--onma-text);
  outline: none;
  transition: border-color 0.15s ease;
}

.onma-chat-textarea:focus {
  border-color: var(--onma-primary);
}

.onma-chat-textarea:disabled {
  background: #f3f4f6;
  cursor: not-allowed;
}

.onma-chat-send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: var(--onma-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.onma-chat-send:hover:not(:disabled) {
  background: var(--onma-primary-dark);
}

.onma-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.onma-chat-send:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.onma-chat-send svg {
  width: 18px;
  height: 18px;
}

.onma-chat-footer-note {
  font-size: 11px;
  color: var(--onma-text-muted);
  text-align: center;
  padding: 6px 10px 10px;
  background: var(--onma-bg);
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
  .onma-chat-root {
    right: 12px;
    bottom: 12px;
  }

  .onma-chat-panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 120px);
    max-height: none;
    bottom: 76px;
    right: 0;
  }

  .onma-chat-launcher {
    width: 56px;
    height: 56px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .onma-chat-panel,
  .onma-chat-launcher,
  .onma-chat-typing span {
    transition: none;
    animation: none;
  }
}
