/* =============================================
   Chat Widget
   ============================================= */

/* --- Toggle Button --- */

.chat-toggle-wrap {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 950;
}

.chat-toggle-btn {
  position: relative;
  height: 44px;
  border-radius: 22px;
  background: #bcd2e2;
  color: #1a1a2e;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  transition: box-shadow 0.3s ease-in-out, background 0.3s ease-in-out;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
  font-family: var(--font-syne), sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
}

.chat-toggle-btn i {
  font-size: 16px;
}

/* Intro text that shrinks away */
.chat-toggle-label {
  white-space: nowrap;
}

.chat-intro-text {
  display: inline-block;
  overflow: hidden;
  white-space: nowrap;
  max-width: 160px;
  margin-left: 0.3em;
  opacity: 1;
  transition: max-width 0.5s ease-in-out, opacity 0.3s ease-in-out, margin-left 0.5s ease-in-out;
  vertical-align: bottom;
}

.chat-intro-hidden {
  max-width: 0;
  margin-left: 0;
  opacity: 0;
}

.chat-toggle-btn:hover {
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.22);
  background: #a8c3d6;
}

.chat-toggle-btn.chat-toggle-open {
  background: #bcd2e2;
  color: #1a1a2e;
  padding: 0;
  width: 44px;
  justify-content: center;
}

.chat-badge {
  display: none;
  position: absolute;
  top: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #e53935;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 1;
}

/* --- Overlay Backdrop --- */

.chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 960;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: chatFadeIn 0.2s ease-out;
}

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

/* --- Modal --- */

.chat-modal {
  width: 700px;
  max-width: calc(100vw - 48px);
  height: 80vh;
  max-height: 800px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 16px 64px rgba(0, 0, 0, 0.24);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-syne), sans-serif;
  animation: chatModalIn 0.25s ease-out;
}

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

/* --- Header --- */

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  flex-shrink: 0;
}

.chat-header-info h6 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: #18191d;
  line-height: 1.3;
}

.chat-header-subtitle {
  font-size: 12px;
  color: #868a9b;
  letter-spacing: 0.02em;
}

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

.chat-clear-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #b0b3c0;
  font-size: 13px;
  padding: 6px;
  line-height: 1;
  transition: color 0.2s ease;
}

.chat-clear-btn:hover {
  color: #868a9b;
}

.chat-close-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #868a9b;
  font-size: 16px;
  padding: 6px;
  line-height: 1;
  transition: color 0.2s ease;
}

.chat-close-btn:hover {
  color: #18191d;
}

/* --- Welcome Card (inside messages scroll) --- */

.chat-welcome {
  background: #fff;
  border: 1px solid #e4e5e8;
  border-left: 3px solid #bcd2e2;
  border-radius: 4px 12px 12px 4px;
  padding: 16px 20px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Intro text */
.chat-welcome-intro {
  margin: 0;
  font-size: 14px;
  line-height: 1.7;
  color: #2d2f36;
}

.chat-welcome-intro strong {
  color: #18191d;
  font-weight: 700;
}

/* Action rows — inline compact */
.chat-welcome-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-welcome-action {
  font-size: 13px;
  line-height: 1.5;
  color: #4a4d58;
}

.chat-welcome-action strong {
  color: #18191d;
  font-weight: 700;
}

/* Trust note */
.chat-welcome-trust {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: #2d2f36;
  border-top: 1px solid #ecedf0;
  padding-top: 10px;
}

.chat-welcome-trust-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: #3a7a5e;
  background: #e6f4ed;
  border-radius: 10px;
  padding: 2px 9px;
  margin-right: 7px;
  vertical-align: middle;
  font-style: normal;
}

/* --- Suggestion Chips --- */

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-suggestion-chip {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 20px;
  padding: 7px 14px;
  font-family: var(--font-syne), sans-serif;
  font-size: 12px;
  color: #555;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.chat-suggestion-chip:hover:not(:disabled) {
  background: #f0f0f2;
  border-color: #ccc;
}

.chat-suggestion-chip:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* --- Messages --- */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

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

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

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

.chat-message.assistant {
  display: flex;
  justify-content: flex-start;
}

.chat-message.user {
  display: flex;
  justify-content: flex-end;
}

.chat-bubble {
  all: initial;
  display: block;
  padding: 10px 14px;
  border-radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.6;
  max-width: 80%;
  word-wrap: break-word;
  color: inherit;
}

.chat-bubble h1,
.chat-bubble h2,
.chat-bubble h3,
.chat-bubble h4,
.chat-bubble h5,
.chat-bubble h6,
.chat-bubble p,
.chat-bubble ul,
.chat-bubble ol,
.chat-bubble li,
.chat-bubble strong,
.chat-bubble em,
.chat-bubble a,
.chat-bubble code,
.chat-bubble blockquote {
  all: unset;
  display: revert;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  color: inherit;
}

.chat-bubble p {
  margin-bottom: 6px;
}

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

.chat-bubble strong {
  font-weight: 600;
}

.chat-bubble em {
  font-style: italic;
}

.chat-bubble ul,
.chat-bubble ol {
  padding-left: 18px;
  margin: 4px 0;
}

.chat-bubble li {
  margin-bottom: 2px;
  list-style: revert;
}

.chat-bubble code {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 3px;
}

.chat-message.user .chat-bubble code {
  background: rgba(255, 255, 255, 0.15);
}

.chat-message.assistant .chat-bubble {
  background: #f4f5f7;
  color: #18191d;
  border-bottom-left-radius: 4px;
}

.chat-message.user .chat-bubble {
  background: #18191d;
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Match rating colored bubbles — specificity must beat .chat-message.assistant .chat-bubble */
.chat-message.assistant .chat-bubble.chat-match-strong {
  border-left: 3px solid #2d8a4e;
  background: #f0faf4;
}

.chat-message.assistant .chat-bubble.chat-match-partial {
  border-left: 3px solid #c89100;
  background: #fefaf0;
}

.chat-message.assistant .chat-bubble.chat-match-poor {
  border-left: 3px solid #c0392b;
  background: #fdf2f1;
}

/* Markdown inside chat bubbles */
.chat-message p {
  margin: 0 0 6px;
}

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

.chat-message ul,
.chat-message ol {
  margin: 4px 0;
  padding-left: 18px;
}

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

.chat-message strong {
  font-weight: 600;
}

.chat-message code {
  font-size: 12px;
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 3px;
}

.chat-message.user code {
  background: rgba(255, 255, 255, 0.15);
}

.chat-copy-email {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #e8eaff;
  border: 1px solid #c5caff;
  border-radius: 4px;
  padding: 2px 8px;
  font: inherit;
  font-size: inherit;
  color: #4a6cf7;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  text-decoration: none;
}

.chat-copy-email:hover {
  background: #d8dcff;
  border-color: #a8aeff;
}

.chat-copy-email .copy-icon {
  font-size: 11px;
  opacity: 0.7;
}

.chat-message a {
  color: #4a6cf7;
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* --- Status / Typing Indicator --- */

.chat-status-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #f4f5f7;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 10px 16px;
  width: fit-content;
}

.chat-status-text {
  font-size: 12px;
  color: #868a9b;
  white-space: nowrap;
}

.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  width: fit-content;
}

.chat-typing-indicator span {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #868a9b;
  animation: chatTypingDot 1.4s infinite;
}

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

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

@keyframes chatTypingDot {
  0%, 60%, 100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* --- Input Area --- */

.chat-input-area {
  padding: 16px 24px;
  border-top: 1px solid #f0f0f2;
  flex-shrink: 0;
}

.chat-form {
  display: flex;
  gap: 10px;
}

.chat-input {
  flex: 1;
  border: 1px solid #e8e9ec;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  font-family: var(--font-syne), sans-serif;
  color: #18191d;
  background: #fafafa;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
  resize: vertical;
  min-height: 44px;
  max-height: 300px;
  overflow-y: auto;
}

.chat-input::placeholder {
  color: #b0b3c0;
}

.chat-input:focus {
  border-color: #cccfd6;
  background: #fff;
}

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

.chat-send-btn {
  height: 38px;
  border-radius: 8px;
  border: none;
  background: #18191d;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-family: var(--font-syne), sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 0 16px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.2s ease;
}

.chat-send-btn:hover:not(:disabled) {
  opacity: 0.85;
}

.chat-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.chat-match-btn {
  width: 100%;
  height: 36px;
  border-radius: 8px;
  border: 1px solid #a8c3d6;
  background: #bcd2e2;
  color: #1a1a2e;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-syne), sans-serif;
  font-size: 12px;
  font-weight: 500;
  margin-top: 10px;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.chat-match-btn:hover:not(:disabled) {
  background: #a8c3d6;
  border-color: #8fb3c8;
}

.chat-match-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.chat-match-btn i {
  font-size: 11px;
}

.chat-counters {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
}

.chat-counter {
  font-size: 10px;
  color: #b0b3c0;
}

.chat-limit-message {
  margin: 0;
  font-size: 13px;
  color: #868a9b;
  text-align: center;
  padding: 8px 0;
}

/* --- Mobile --- */

@media (max-width: 768px) {
  .desktop-only-chip {
    display: none;
  }
  .chat-toggle-wrap {
    bottom: 16px;
    right: 16px;
  }

  .chat-toggle-btn {
    width: 44px;
    padding: 0;
    justify-content: center;
  }

  .chat-toggle-label {
    display: none;
  }

  .chat-badge {
    display: flex;
  }

  .chat-header {
    padding: 14px 16px 10px;
  }

  .chat-header-subtitle {
    font-size: 12px;
    line-height: 1.5;
    letter-spacing: 0;
    display: block;
    margin-top: 2px;
  }

  .chat-form {
    flex-direction: column;
  }

  .chat-send-btn {
    width: 100%;
  }

  .chat-input-area {
    padding: 12px 16px;
  }

  .chat-modal {
    width: calc(100vw - 32px);
    height: 80vh;
    max-height: none;
  }

  .chat-header {
    align-items: flex-start;
  }

  .chat-close-btn {
    background: #f0f0f2;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 18px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .chat-input-area {
    padding: 12px 16px;
  }
}
