/* FM4 Live & AI Chat Modern Stylesheet (< 7 KB) */
:root {
  --fm4-chat-primary: var(--fm4-primary-color, #f05f24);
  --fm4-chat-bg: var(--fm4-surface-color, #121316);
  --fm4-chat-card-bg: color-mix(in srgb, var(--fm4-surface-color, #121316) 94%, #ffffff);
  --fm4-chat-text: var(--fm4-text-color, #f4f4f5);
  --fm4-chat-muted: #94a3b8;
  --fm4-chat-border: rgba(255, 255, 255, 0.12);
  --fm4-chat-radius: var(--fm4-global-radius, 14px);
}

@media (prefers-color-scheme: light) {
  :root {
    --fm4-chat-bg: var(--fm4-surface-color, #ffffff);
    --fm4-chat-card-bg: #f8fafc;
    --fm4-chat-text: var(--fm4-text-color, #0f172a);
    --fm4-chat-muted: #64748b;
    --fm4-chat-border: rgba(0, 0, 0, 0.1);
  }
}

/* Chat Launcher Floating Button */
#fm4-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 2147483000;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 50px;
  padding: 0 20px;
  border-radius: 999px;
  background: var(--fm4-chat-primary);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  font: 700 13px/1 Inter, -apple-system, system-ui, sans-serif;
  letter-spacing: 0.01em;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
}

#fm4-chat-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.42);
}

#fm4-chat-launcher .fm4-chat-pulse {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: fm4ChatPulse 2s infinite;
}

@keyframes fm4ChatPulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 7px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Chat Window Modal */
#fm4-chat-window {
  position: fixed;
  bottom: 86px;
  right: 24px;
  z-index: 2147483000;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
  background: var(--fm4-chat-bg);
  border: 1px solid var(--fm4-chat-border);
  border-radius: var(--fm4-chat-radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  font-family: Inter, -apple-system, system-ui, sans-serif;
}

#fm4-chat-window.fm4-chat-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Chat Header */
.fm4-chat-header {
  padding: 16px 18px;
  background: var(--fm4-chat-card-bg);
  border-bottom: 1px solid var(--fm4-chat-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.fm4-chat-header-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.fm4-chat-header-title strong {
  color: var(--fm4-chat-text);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fm4-chat-header-title span {
  color: var(--fm4-chat-muted);
  font-size: 11.5px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.fm4-chat-close-btn {
  background: transparent;
  border: none;
  color: var(--fm4-chat-muted);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}
.fm4-chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--fm4-chat-text);
}

.fm4-chat-dot-offline {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  display: inline-block;
}

/* Messages Area */
.fm4-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fm4-chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  word-break: break-word;
}

.fm4-chat-msg.msg-operator,
.fm4-chat-msg.msg-ai {
  align-self: flex-start;
}

.fm4-chat-msg.msg-visitor {
  align-self: flex-end;
}

.fm4-chat-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.45;
}

.msg-operator .fm4-chat-bubble {
  background: rgba(255, 255, 255, 0.08);
  color: var(--fm4-chat-text);
  border: 1px solid var(--fm4-chat-border);
  border-bottom-left-radius: 4px;
}

.msg-ai .fm4-chat-bubble {
  background: rgba(240, 95, 36, 0.1);
  color: var(--fm4-chat-text);
  border: 1px solid rgba(240, 95, 36, 0.25);
  border-bottom-left-radius: 4px;
}

.msg-visitor .fm4-chat-bubble {
  background: var(--fm4-chat-primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.fm4-chat-attachment {
  margin-top: 6px;
  border-radius: 8px;
  overflow: hidden;
  max-width: 100%;
}
.fm4-chat-attachment img {
  width: 100%;
  height: auto;
  display: block;
  cursor: pointer;
  border-radius: 8px;
}

.fm4-chat-time {
  font-size: 10px;
  color: var(--fm4-chat-muted);
  margin-top: 4px;
  align-self: flex-start;
}
.msg-visitor .fm4-chat-time {
  align-self: flex-end;
}

/* Offline Contact Card / Form */
.fm4-chat-offline-form {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  flex: 1;
}

.fm4-chat-offline-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: flex-start;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--fm4-chat-border);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--fm4-chat-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.fm4-chat-offline-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--fm4-chat-text);
  margin: 0;
  line-height: 1.3;
}

.fm4-chat-offline-desc {
  font-size: 12.5px;
  color: var(--fm4-chat-muted);
  margin: 0;
  line-height: 1.45;
}

.fm4-chat-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.fm4-chat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fm4-chat-muted);
}

.fm4-chat-field input,
.fm4-chat-field textarea {
  width: 100%;
  box-sizing: border-box;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--fm4-chat-border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--fm4-chat-text);
  font: 13px/1.4 Inter, -apple-system, system-ui, sans-serif;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

@media (prefers-color-scheme: light) {
  .fm4-chat-field input,
  .fm4-chat-field textarea {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.14);
  }
}

.fm4-chat-field input:focus,
.fm4-chat-field textarea:focus {
  border-color: var(--fm4-chat-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--fm4-chat-primary) 25%, transparent);
}

.fm4-chat-field textarea {
  resize: none;
  min-height: 78px;
}

.fm4-chat-submit-btn {
  background: var(--fm4-chat-primary);
  color: #ffffff;
  border: none;
  border-radius: 8px;
  height: 40px;
  font: 700 13px/1 Inter, -apple-system, system-ui, sans-serif;
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
  margin-top: 4px;
}

.fm4-chat-submit-btn:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.fm4-chat-submit-btn:active:not(:disabled) {
  transform: translateY(0);
}

.fm4-chat-submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.fm4-chat-error-banner {
  background: rgba(225, 29, 72, 0.12);
  border: 1px solid rgba(225, 29, 72, 0.35);
  color: #fb7185;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 11.5px;
  line-height: 1.4;
  display: none;
}

/* Chat Footer / Quick Input */
.fm4-chat-footer {
  padding: 12px;
  background: var(--fm4-chat-card-bg);
  border-top: 1px solid var(--fm4-chat-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fm4-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fm4-chat-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--fm4-chat-border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--fm4-chat-text);
  font: 13px/1.4 Inter, sans-serif;
  outline: none;
  transition: border-color 0.15s ease;
}

@media (prefers-color-scheme: light) {
  .fm4-chat-input {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.12);
  }
}

.fm4-chat-input:focus {
  border-color: var(--fm4-chat-primary);
}

.fm4-chat-action-btn {
  background: transparent;
  border: none;
  color: var(--fm4-chat-muted);
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.fm4-chat-action-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  color: var(--fm4-chat-text);
}
.fm4-chat-action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.fm4-chat-send-btn {
  background: var(--fm4-chat-primary);
  color: #ffffff;
  border: none;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.fm4-chat-send-btn:hover {
  transform: scale(1.05);
}

.fm4-chat-hint {
  font-size: 10.5px;
  color: var(--fm4-chat-muted);
  text-align: center;
  line-height: 1.3;
}
