/* ==========================================================================
   Chat Widget Styles
   Floating AI chatbot widget — persistent across all pages
   ========================================================================== */

/* ── Variables ──────────────────────────────────────────────────────────── */

:root {
  --chat-btn-size: 56px;
  --chat-panel-width: 380px;
  --chat-panel-height: 560px;
  --chat-radius: 16px;
  --chat-msg-radius: 16px;
  --chat-z-button: 300;
  --chat-z-panel: 500;
}

/* ── Floating Button ────────────────────────────────────────────────────── */

.chat-widget__btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: var(--chat-btn-size);
  height: var(--chat-btn-size);
  border-radius: 50%;
  border: none;
  background: linear-gradient(
    135deg,
    var(--gold, #d4a84b),
    var(--gold-600, #b8923f)
  );
  color: #fff;
  cursor: pointer;
  z-index: var(--chat-z-button);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 20px rgba(212, 168, 75, 0.4),
    0 2px 8px rgba(0, 0, 0, 0.2);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.chat-widget__btn:hover {
  transform: scale(1.08);
  box-shadow:
    0 6px 28px rgba(212, 168, 75, 0.5),
    0 3px 12px rgba(0, 0, 0, 0.25);
}

.chat-widget__btn:active {
  transform: scale(0.96);
}

.chat-widget__btn svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-widget__btn .chat-widget__icon-close {
  display: none;
}

.chat-widget__btn.is-open .chat-widget__icon-chat {
  display: none;
}

.chat-widget__btn.is-open .chat-widget__icon-close {
  display: block;
}

/* Unread badge */
.chat-widget__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-family: var(--font-body, Inter, sans-serif);
}

.chat-widget__badge.is-visible {
  display: flex;
}

/* Safe area for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .chat-widget__btn {
    bottom: calc(24px + env(safe-area-inset-bottom));
  }
}

/* ── Panel ──────────────────────────────────────────────────────────────── */

.chat-widget__panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: var(--chat-panel-width);
  height: var(--chat-panel-height);
  max-height: calc(100vh - 120px);
  border-radius: var(--chat-radius);
  background: #fff;
  box-shadow:
    0 12px 48px rgba(0, 0, 0, 0.2),
    0 4px 16px rgba(0, 0, 0, 0.1);
  z-index: var(--chat-z-panel);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(
    --font-body,
    Inter,
    -apple-system,
    BlinkMacSystemFont,
    sans-serif
  );
}

.chat-widget__panel.is-open {
  display: flex;
  animation: chatSlideUp 0.25s ease-out;
}

@keyframes chatSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ── Panel Header ───────────────────────────────────────────────────────── */

.chat-widget__header {
  padding: 16px 20px;
  background: var(--charcoal-800, #1f1f1f);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.chat-widget__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    var(--gold, #d4a84b),
    var(--gold-600, #b8923f)
  );
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.chat-widget__header-info {
  flex: 1;
  min-width: 0;
}

.chat-widget__header-title {
  font-family: var(--font-heading, Outfit, sans-serif);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  margin: 0;
}

.chat-widget__header-subtitle {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  line-height: 1.2;
  margin: 0;
}

.chat-widget__header-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    color 0.15s ease,
    background 0.15s ease;
}

.chat-widget__header-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.chat-widget__header-close svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* ── Messages Area ──────────────────────────────────────────────────────── */

.chat-widget__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f9fafb;
  scroll-behavior: smooth;
}

/* Scrollbar */
.chat-widget__messages::-webkit-scrollbar {
  width: 4px;
}

.chat-widget__messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-widget__messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}

/* ── Message Bubbles ────────────────────────────────────────────────────── */

.chat-widget__msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--chat-msg-radius);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: chatMsgIn 0.2s ease-out;
}

@keyframes chatMsgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-widget__msg--user {
  align-self: flex-end;
  background: linear-gradient(
    135deg,
    var(--gold, #d4a84b),
    var(--gold-600, #b8923f)
  );
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-widget__msg--assistant {
  align-self: flex-start;
  background: #fff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

/* Links inside assistant messages */
.chat-widget__msg--assistant a {
  color: var(--gold-600, #b8923f);
  text-decoration: underline;
  text-decoration-color: rgba(184, 146, 63, 0.4);
  transition: text-decoration-color 0.15s ease;
}

.chat-widget__msg--assistant a:hover {
  text-decoration-color: var(--gold-600, #b8923f);
}

/* Paragraphs in messages */
.chat-widget__msg p {
  margin: 0 0 8px;
}

.chat-widget__msg p:last-child {
  margin-bottom: 0;
}

/* Bold text */
.chat-widget__msg strong {
  font-weight: 600;
}

/* Lists in messages */
.chat-widget__msg ul,
.chat-widget__msg ol {
  margin: 4px 0 8px;
  padding-left: 18px;
}

.chat-widget__msg li {
  margin-bottom: 2px;
}

/* ── Typing Indicator ───────────────────────────────────────────────────── */

.chat-widget__typing {
  align-self: flex-start;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: var(--chat-msg-radius);
  border-bottom-left-radius: 4px;
  padding: 12px 18px;
  display: none;
  align-items: center;
  gap: 5px;
}

.chat-widget__typing.is-visible {
  display: flex;
  animation: chatMsgIn 0.2s ease-out;
}

.chat-widget__typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  animation: chatBounce 1.2s ease-in-out infinite;
}

.chat-widget__typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-widget__typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

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

/* ── Suggested Topics ───────────────────────────────────────────────────── */

.chat-widget__suggestions {
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-widget__suggestion {
  display: inline-block;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--gold-600, #b8923f);
  background: rgba(212, 168, 75, 0.08);
  border: 1px solid rgba(212, 168, 75, 0.25);
  border-radius: 20px;
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease;
  font-family: inherit;
  line-height: 1.3;
}

.chat-widget__suggestion:hover {
  background: rgba(212, 168, 75, 0.15);
  border-color: rgba(212, 168, 75, 0.5);
}

.chat-widget__suggestion:active {
  transform: scale(0.96);
}

/* Follow-up suggestion entrance */
.chat-widget__msg + .chat-widget__suggestions {
  animation: chatMsgIn 0.25s ease-out;
}

/* ── Lead Confirmation Card ─────────────────────────────────────────────── */

.chat-widget__lead-card {
  align-self: flex-start;
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--chat-msg-radius);
  border-bottom-left-radius: 4px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  animation: chatMsgIn 0.2s ease-out;
}

.chat-widget__lead-card-heading {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #16a34a;
  margin-bottom: 4px;
}

.chat-widget__lead-card-heading svg {
  flex-shrink: 0;
}

.chat-widget__lead-card-details {
  font-size: 13px;
  color: #374151;
  margin-bottom: 4px;
}

.chat-widget__lead-card-note {
  font-size: 12px;
  color: #6b7280;
}

/* ── Input Area ─────────────────────────────────────────────────────────── */

.chat-widget__input-area {
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.chat-widget__input {
  flex: 1;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  max-height: 100px;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.15s ease;
  background: #f9fafb;
  color: #1f2937;
}

.chat-widget__input:focus {
  border-color: var(--gold, #d4a84b);
  background: #fff;
}

.chat-widget__input::placeholder {
  color: #9ca3af;
}

.chat-widget__send {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(
    135deg,
    var(--gold, #d4a84b),
    var(--gold-600, #b8923f)
  );
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    opacity 0.15s ease,
    transform 0.15s ease;
  padding: 0;
}

.chat-widget__send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-widget__send:not(:disabled):hover {
  transform: scale(1.05);
}

.chat-widget__send:not(:disabled):active {
  transform: scale(0.95);
}

.chat-widget__send svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Error State ────────────────────────────────────────────────────────── */

.chat-widget__error {
  padding: 8px 16px;
  font-size: 13px;
  color: #ef4444;
  background: #fef2f2;
  text-align: center;
  display: none;
}

.chat-widget__error.is-visible {
  display: block;
}

/* ── Welcome Message ────────────────────────────────────────────────────── */

.chat-widget__welcome {
  padding: 0 16px;
}

.chat-widget__welcome-text {
  font-size: 14px;
  color: #6b7280;
  line-height: 1.5;
  margin: 0 0 4px;
}

/* ── Mobile Responsive ──────────────────────────────────────────────────── */

@media (max-width: 767px) {
  .chat-widget__panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    z-index: var(--chat-z-panel);
  }

  .chat-widget__panel.is-open {
    animation: chatFadeIn 0.2s ease-out;
  }

  @keyframes chatFadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  .chat-widget__input {
    font-size: 16px; /* Prevents iOS zoom */
  }

  .chat-widget__input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .chat-widget__header {
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }
}

/* ── Playbook Nav Avoidance ─────────────────────────────────────────────── */

.nav--playbook ~ .chat-widget__btn {
  bottom: 80px;
}

/* ── Print ──────────────────────────────────────────────────────────────── */

@media print {
  .chat-widget__btn,
  .chat-widget__panel {
    display: none !important;
  }
}
