/* Biver Royalty Homes — AI Chat Assistant */

:root {
  --brh-chat-gold: #D4AF37;
  --brh-chat-gold-light: #FFD700;
  --brh-chat-brown: #371801;
  --brh-chat-brown-soft: #5c3d1e;
  --brh-chat-glass: rgba(255, 255, 255, 0.72);
  --brh-chat-glass-dark: rgba(30, 21, 8, 0.88);
  --brh-chat-shadow: 0 20px 60px rgba(55, 24, 1, 0.22);
  --brh-chat-radius: 20px;
  --brh-chat-font: 'Outfit', system-ui, sans-serif;
  --brh-chat-display: 'Cormorant Garamond', Georgia, serif;
  --brh-chat-z: 99990;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brh-chat-glass: rgba(30, 21, 8, 0.92);
    --brh-chat-text: #f5f0e8;
    --brh-chat-muted: rgba(245, 240, 232, 0.65);
    --brh-chat-bubble-bot: rgba(55, 24, 1, 0.55);
    --brh-chat-bubble-user: linear-gradient(135deg, #B8860B, #D4AF37);
    --brh-chat-input-bg: rgba(0, 0, 0, 0.35);
  }
}

@media (prefers-color-scheme: light), (prefers-color-scheme: no-preference) {
  :root {
    --brh-chat-text: #2c2418;
    --brh-chat-muted: #6c5e4e;
    --brh-chat-bubble-bot: rgba(255, 255, 255, 0.95);
    --brh-chat-bubble-user: linear-gradient(135deg, #D4AF37, #FFD700);
    --brh-chat-input-bg: rgba(255, 255, 255, 0.85);
  }
}

#brh-chat-root {
  position: fixed;
  inset: auto 24px 24px auto;
  z-index: var(--brh-chat-z);
  font-family: var(--brh-chat-font);
  pointer-events: none;
}

#brh-chat-root * {
  box-sizing: border-box;
}

#brh-chat-root .brh-pointer {
  pointer-events: auto;
}

/* Launcher */
.brh-chat-launcher {
  position: relative;
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: linear-gradient(145deg, var(--brh-chat-gold-light), var(--brh-chat-gold), #B8860B);
  box-shadow: 0 8px 32px rgba(212, 175, 55, 0.45), 0 0 0 0 rgba(212, 175, 55, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.35s ease;
  animation: brh-pulse 2.8s ease-in-out infinite;
}

.brh-chat-launcher:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 12px 40px rgba(212, 175, 55, 0.55);
}

.brh-chat-launcher:active {
  transform: scale(0.96);
}

.brh-chat-launcher svg {
  width: 30px;
  height: 30px;
  fill: var(--brh-chat-brown);
}

.brh-chat-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: #dc3545;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  animation: brh-badge-pop 0.35s ease;
}

.brh-chat-badge.is-visible {
  display: flex;
}

@keyframes brh-pulse {
  0%, 100% { box-shadow: 0 8px 32px rgba(212, 175, 55, 0.45), 0 0 0 0 rgba(212, 175, 55, 0.35); }
  50% { box-shadow: 0 8px 32px rgba(212, 175, 55, 0.55), 0 0 0 12px rgba(212, 175, 55, 0); }
}

@keyframes brh-badge-pop {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

/* Welcome bubbles — disabled (launcher only) */
.brh-welcome-stack {
  display: none !important;
}

.brh-welcome-bubble {
  padding: 14px 18px;
  border-radius: 16px 16px 4px 16px;
  background: var(--brh-chat-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(212, 175, 55, 0.35);
  box-shadow: var(--brh-chat-shadow);
  color: var(--brh-chat-text);
  font-size: 14px;
  line-height: 1.5;
  cursor: pointer;
  opacity: 0;
  transform: translateY(12px) scale(0.96);
  transition: opacity 0.45s ease, transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.brh-welcome-bubble.is-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.brh-welcome-bubble:hover {
  border-color: var(--brh-chat-gold);
}

/* Chat window */
.brh-chat-window {
  position: absolute;
  bottom: 78px;
  right: 0;
  width: min(400px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  border-radius: var(--brh-chat-radius);
  background: var(--brh-chat-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(212, 175, 55, 0.3);
  box-shadow: var(--brh-chat-shadow);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.4s;
}

.brh-chat-window.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.brh-chat-window.is-minimized {
  height: 64px;
  overflow: hidden;
}

/* Header */
.brh-chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--brh-chat-brown), var(--brh-chat-brown-soft));
  color: #fff;
  flex-shrink: 0;
}

.brh-chat-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--brh-chat-gold);
}

.brh-chat-header-info {
  flex: 1;
  min-width: 0;
}

.brh-chat-header-title {
  font-family: var(--brh-chat-display);
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brh-chat-header-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
}

.brh-online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.8);
  animation: brh-online-blink 2s ease infinite;
}

@keyframes brh-online-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.brh-chat-header-actions {
  display: flex;
  gap: 4px;
}

.brh-chat-icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.brh-chat-icon-btn:hover {
  background: rgba(212, 175, 55, 0.35);
}

.brh-chat-icon-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Messages */
.brh-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.brh-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.brh-chat-messages::-webkit-scrollbar-thumb {
  background: var(--brh-chat-gold);
  border-radius: 4px;
}

.brh-msg-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: brh-msg-in 0.35s ease;
}

.brh-msg-row.is-user {
  flex-direction: row-reverse;
}

@keyframes brh-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.brh-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(212, 175, 55, 0.4);
}

.brh-msg-avatar.is-user {
  background: linear-gradient(135deg, #5c3d1e, #371801);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brh-chat-gold-light);
  font-size: 14px;
  font-weight: 600;
}

.brh-msg-body {
  max-width: 78%;
}

.brh-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--brh-chat-text);
  white-space: pre-wrap;
  word-break: break-word;
}

.brh-msg-row:not(.is-user) .brh-msg-bubble {
  background: var(--brh-chat-bubble-bot);
  border: 1px solid rgba(212, 175, 55, 0.2);
  border-bottom-left-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.brh-msg-row.is-user .brh-msg-bubble {
  background: var(--brh-chat-bubble-user);
  color: var(--brh-chat-brown);
  border-bottom-right-radius: 4px;
  font-weight: 500;
}

.brh-msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 10px;
  color: var(--brh-chat-muted);
}

.brh-msg-row.is-user .brh-msg-meta {
  justify-content: flex-end;
}

.brh-read-icon {
  font-size: 11px;
  color: var(--brh-chat-gold);
}

/* Typing */
.brh-typing {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 0 16px 8px;
}

.brh-typing.is-visible {
  display: flex;
}

.brh-typing-dots {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--brh-chat-bubble-bot);
  border-radius: 16px;
  border: 1px solid rgba(212, 175, 55, 0.2);
}

.brh-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brh-chat-gold);
  animation: brh-typing 1.2s ease infinite;
}

.brh-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.brh-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes brh-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Escalation button */
.brh-support-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.brh-agent-connect-btn,
.brh-support-form-btn,
.brh-resume-bot-btn,
.brh-escalate-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 16px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brh-chat-brown), var(--brh-chat-brown-soft));
  color: var(--brh-chat-gold-light);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.brh-resume-bot-btn {
  background: linear-gradient(135deg, var(--brh-chat-gold), var(--brh-chat-gold-light)) !important;
  color: var(--brh-chat-brown) !important;
}

.brh-agent-connect-btn:hover,
.brh-support-form-btn:hover,
.brh-resume-bot-btn:hover,
.brh-escalate-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(55, 24, 1, 0.3);
}

/* Input area */
.brh-chat-footer {
  padding: 12px 14px 14px;
  border-top: 1px solid rgba(212, 175, 55, 0.2);
  background: rgba(255, 255, 255, 0.05);
  flex-shrink: 0;
}

.brh-chat-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.brh-toolbar-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: var(--brh-chat-input-bg);
  color: var(--brh-chat-muted);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
}

.brh-toolbar-btn:hover {
  color: var(--brh-chat-gold);
  background: rgba(212, 175, 55, 0.15);
}

.brh-chat-input-wrap {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.brh-chat-input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 11px 14px;
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 14px;
  background: var(--brh-chat-input-bg);
  color: var(--brh-chat-text);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.brh-chat-input:focus {
  border-color: var(--brh-chat-gold);
  box-shadow: 0 0 0 3px rgba(212, 175, 55, 0.15);
}

.brh-chat-send {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brh-chat-gold), var(--brh-chat-gold-light));
  color: var(--brh-chat-brown);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.brh-chat-send:hover:not(:disabled) {
  transform: scale(1.05);
}

.brh-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.brh-chat-send svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* Emoji picker */
.brh-emoji-panel {
  display: none;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  margin-bottom: 8px;
  max-height: 120px;
  overflow-y: auto;
  background: var(--brh-chat-input-bg);
  border-radius: 12px;
  border: 1px solid rgba(212, 175, 55, 0.2);
}

.brh-emoji-panel.is-open {
  display: flex;
}

.brh-emoji-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
}

.brh-emoji-btn:hover {
  background: rgba(212, 175, 55, 0.2);
}

/* Search panel */
.brh-search-panel {
  display: none;
  padding: 8px;
  margin-bottom: 8px;
}

.brh-search-panel.is-open {
  display: block;
}

.brh-search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 10px;
  background: var(--brh-chat-input-bg);
  color: var(--brh-chat-text);
  font-size: 13px;
}

/* Inspection modal */
.brh-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: calc(var(--brh-chat-z) + 10);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.brh-modal-overlay.is-open {
  display: flex;
}

.brh-modal {
  width: min(420px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  border-radius: var(--brh-chat-radius);
  background: var(--brh-chat-glass);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(212, 175, 55, 0.35);
  box-shadow: var(--brh-chat-shadow);
}

.brh-modal h3 {
  font-family: var(--brh-chat-display);
  font-size: 1.4rem;
  color: var(--brh-chat-text);
  margin: 0 0 16px;
}

.brh-form-group {
  margin-bottom: 14px;
}

.brh-form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--brh-chat-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.brh-form-group input,
.brh-form-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: 10px;
  background: var(--brh-chat-input-bg);
  color: var(--brh-chat-text);
  font-family: inherit;
  font-size: 14px;
}

.brh-form-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.brh-btn-primary {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brh-chat-gold), var(--brh-chat-gold-light));
  color: var(--brh-chat-brown);
  font-weight: 600;
  cursor: pointer;
}

.brh-btn-secondary {
  padding: 12px 18px;
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 12px;
  background: transparent;
  color: var(--brh-chat-text);
  cursor: pointer;
}

/* Mobile */
@media (max-width: 480px) {
  #brh-chat-root {
    inset: auto 16px 16px auto;
  }

  .brh-chat-window {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    bottom: 0;
    right: 0;
  }

  .brh-chat-window.is-open + .brh-chat-launcher,
  .brh-chat-window.is-open ~ .brh-welcome-stack {
    display: none;
  }

  .brh-welcome-stack {
    bottom: 72px;
    max-width: calc(100vw - 32px);
  }
}

/* Scroll-to-top sits above the chat launcher when chat is closed */
body.brh-chat-present #scrollToTop,
body:has(#brh-chat-root) #scrollToTop {
  right: 28px !important;
  left: auto !important;
  bottom: calc(24px + 64px + 14px) !important;
  z-index: calc(var(--brh-chat-z) - 1) !important;
}

/* When chat panel is open, keep scroll-to-top on the left */
body.brh-chat-active #scrollToTop {
  right: auto !important;
  left: 24px !important;
  bottom: 30px !important;
}

@media (max-width: 480px) {
  body.brh-chat-present #scrollToTop,
  body:has(#brh-chat-root) #scrollToTop {
    right: 20px !important;
    bottom: calc(16px + 64px + 12px) !important;
  }

  body.brh-chat-active #scrollToTop {
    left: 16px !important;
    bottom: 24px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .brh-chat-launcher,
  .brh-online-dot,
  .brh-typing-dots span {
    animation: none;
  }

  .brh-chat-window,
  .brh-welcome-bubble,
  .brh-msg-row {
    transition: none;
  }
}
