#messenger-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2147483647;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

#messenger-popup {
  position: fixed;
  right: 20px;
  bottom: 92px;
  width: min(420px, calc(100vw - 24px));
  max-height: min(74vh, 680px);
  display: none;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.14);
  box-shadow: 0 20px 48px rgba(2, 6, 23, 0.35);
  z-index: 2147483647;
}

#messenger-popup.active {
  display: flex;
}

#messenger-header,
.messenger-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  color: #ffffff;
  background: linear-gradient(135deg, #16a34a, #10b981);
}

.messenger-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
}

.messenger-subtitle {
  margin-top: 2px;
  font-size: 12px;
  opacity: 0.9;
}

#messenger-close {
  appearance: none;
  border: 0;
  background: transparent;
  color: #ffffff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.messenger-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.messenger-start {
  border-bottom: 1px solid rgba(15, 23, 42, 0.08);
  padding: 12px 14px;
}

/* Chat-first layout (hide the intake form) */
.messenger-start {
  display: none;
}

.messenger-chat {
  display: block;
}

.messenger-start-title {
  margin: 0 0 10px;
  font-size: 13px;
  color: #1f2937;
  font-weight: 700;
}

.messenger-start-form {
  display: grid;
  gap: 8px;
}

.form-field {
  display: grid;
  gap: 4px;
}

.form-field label {
  font-size: 12px;
  color: #475569;
  font-weight: 600;
}

.form-field input,
.form-field textarea {
  width: 100%;
  border: 1px solid rgba(15, 23, 42, 0.16);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

.form-field textarea {
  resize: vertical;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
}

.btn-primary {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  background: #16a34a;
  cursor: pointer;
}

.messenger-chat {
  min-height: 0;
}

#messages-view,
.messages-view {
  min-height: 100px;
  max-height: 300px;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f8fafc;
}

.message-row {
  display: flex;
  width: 100%;
}

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

.message-row--admin {
  justify-content: flex-start;
}

.message-content {
  max-width: 82%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: fit-content;
}

.message-row--user .message-content {
  align-items: flex-end;
}

.message-bubble {
  display: inline-block;
  width: fit-content;
  max-width: 100%;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
  
}

.message-bubble.user {
  background: #dcfce7;
  color: #14532d;
}

.message-bubble.admin {
  background: #e2e8f0;
  color: #0f172a;
}

.message-time {
  margin-top: 4px;
  font-size: 11px;
  color: #64748b;
}

#message-form,
.message-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  background: #ffffff;
}

#message-input {
  flex: 1;
  border: 1px solid rgba(15, 23, 42, 0.18);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  min-height: 36px;
  resize: vertical;
  overflow-wrap: anywhere;
  word-break: break-word;
}

#send-message {
  appearance: none;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  color: #ffffff;
  background: #16a34a;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

#send-message:disabled,
#message-input:disabled,
.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  #messenger-popup {
    right: 12px;
    bottom: 84px;
    width: calc(100vw - 24px);
    max-height: 72vh;
  }
}
