/* ═══════════════════════════════════════════════════
   Elmer · AI-guide — Chat Widget Styles
   Dark theme matching aeomotor.se design system
   ═══════════════════════════════════════════════════ */

:root {
  --elmer-bg: #0e1520;
  --elmer-card: #121a26;
  --elmer-surface: #1b2838;
  --elmer-line: #243044;
  --elmer-ink: #e8eef7;
  --elmer-muted: #a6b3c6;
  --elmer-brand: #ff7a00;
  --elmer-brand-dark: #e06a00;
  --elmer-brand-dim: rgba(255, 122, 0, 0.15);
  --elmer-error: #ff4d4f;
  --elmer-success: #1fd1a1;
  --elmer-radius: 16px;
  --elmer-radius-sm: 10px;
  --elmer-shadow: 0 12px 40px rgba(0,0,0,.45);
  --elmer-font: system-ui, -apple-system, 'Segoe UI', Roboto, Inter, Arial, sans-serif;
  --elmer-z: 99990;
  --elmer-glow: rgba(255, 122, 0, 0.2);
  --elmer-glow-bright: rgba(255, 122, 0, 0.35);
}

/* ── Launcher button ── */
#elmer-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--elmer-brand);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: var(--elmer-z);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(255, 122, 0, 0.4);
  transition: transform 0.2s, box-shadow 0.2s;
}
#elmer-launcher:hover,
#elmer-launcher:focus-visible {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(255, 122, 0, 0.55);
}
#elmer-launcher:focus-visible {
  outline: 2px solid var(--elmer-brand);
  outline-offset: 3px;
}
#elmer-launcher svg {
  width: 28px;
  height: 28px;
  fill: currentColor;
}
#elmer-launcher[aria-expanded="true"] {
  display: none;
}

/* ── Chat panel ── */
#elmer-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 48px);
  background: var(--elmer-bg);
  border: 1px solid var(--elmer-line);
  border-radius: var(--elmer-radius);
  box-shadow: var(--elmer-shadow), 0 0 25px var(--elmer-glow);
  z-index: calc(var(--elmer-z) + 1);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--elmer-font);
  font-size: 15px;
  color: var(--elmer-ink);
  line-height: 1.5;
  transition: box-shadow 0.8s ease;
}
#elmer-panel.is-open {
  display: flex;
  animation: elmerPanelIn 0.25s ease-out;
}
#elmer-panel.is-inactive {
  box-shadow: var(--elmer-shadow), 0 0 12px rgba(255, 122, 0, 0.08);
}
#elmer-panel.is-thinking {
  box-shadow: var(--elmer-shadow), 0 0 30px var(--elmer-glow-bright);
}

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

/* ── Header ── */
.elmer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--elmer-line);
  background: var(--elmer-card);
  flex-shrink: 0;
}
.elmer-header-text {
  flex: 1;
  min-width: 0;
}
.elmer-header-name {
  font-weight: 800;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.01em;
}
.elmer-badge {
  font-size: 11px;
  font-weight: 600;
  background: var(--elmer-brand-dim);
  color: var(--elmer-brand);
  padding: 2px 8px;
  border-radius: 99px;
  white-space: nowrap;
}
.elmer-online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--elmer-success);
  display: inline-block;
  flex-shrink: 0;
  box-shadow: 0 0 4px rgba(31, 209, 161, 0.5);
}
.elmer-header-sub {
  font-size: 13px;
  color: var(--elmer-muted);
  margin-top: 1px;
}
.elmer-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--elmer-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.elmer-close:hover,
.elmer-close:focus-visible {
  background: var(--elmer-surface);
  color: var(--elmer-ink);
}
.elmer-close:focus-visible {
  outline: 2px solid var(--elmer-brand);
  outline-offset: 1px;
}
.elmer-close svg {
  width: 18px;
  height: 18px;
}

/* ── Avatar (shared) ── */
.elmer-avatar {
  border-radius: 50%;
  background: var(--elmer-brand-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  position: relative;
  overflow: visible;
}
.elmer-avatar--img {
  overflow: visible;
}
.elmer-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}
.elmer-avatar-fallback {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--elmer-brand-dim);
  color: var(--elmer-brand);
  font-weight: 700;
}
/* ── Inline avatar (message rows) ── */
.elmer-inline-avatar {
  align-self: flex-end;
  margin-bottom: 0;
}
.elmer-inline-avatar.is-thinking .elmer-avatar-img,
.elmer-inline-avatar.is-thinking .elmer-avatar-fallback {
  animation: elmerPulseAura 2s ease-in-out infinite;
}
@keyframes elmerPulseAura {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 122, 0, 0.15); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 122, 0, 0.4); }
}

/* ── Messages area ── */
.elmer-messages-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
}
.elmer-scroll-fade {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: linear-gradient(to bottom, var(--elmer-bg), transparent);
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.elmer-scroll-fade.is-visible {
  opacity: 1;
}
.elmer-messages {
  height: 100%;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.elmer-messages::-webkit-scrollbar {
  width: 6px;
}
.elmer-messages::-webkit-scrollbar-track {
  background: transparent;
}
.elmer-messages::-webkit-scrollbar-thumb {
  background: var(--elmer-surface);
  border-radius: 3px;
}

/* ── Message rows ── */
.elmer-msg-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.elmer-msg-row--bot {
  justify-content: flex-start;
}
.elmer-msg-row--user {
  justify-content: flex-end;
}
.elmer-msg-row--system {
  justify-content: center;
}

/* ── Message bubbles ── */
.elmer-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--elmer-radius-sm);
  word-break: break-word;
  white-space: pre-wrap;
}
.elmer-msg--bot {
  align-self: flex-start;
  background: var(--elmer-card);
  border: 1px solid var(--elmer-line);
  animation: elmerBotMsgIn 0.3s ease-out;
  white-space: normal;
}
.elmer-msg--bot p { margin: 0 0 0.6em; }
.elmer-msg--bot p:last-child { margin-bottom: 0; }
.elmer-msg--bot ul,
.elmer-msg--bot ol { margin: 0.4em 0 0.6em; padding-left: 1.4em; }
.elmer-msg--bot li { margin-bottom: 0.25em; }
.elmer-msg--bot code {
  background: rgba(255,255,255,0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: ui-monospace, 'SF Mono', Monaco, 'Cascadia Code', monospace;
}
.elmer-msg--bot strong { font-weight: 700; }
.elmer-inline-cta {
  display: inline-flex;
  align-items: center;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--elmer-brand);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
}
.elmer-inline-cta:hover { filter: brightness(1.08); }
.elmer-msg--user {
  align-self: flex-end;
  background: var(--elmer-brand);
  color: #fff;
  border: none;
  animation: elmerUserMsgIn 0.2s ease-out;
}
.elmer-msg--system {
  align-self: center;
  font-size: 13px;
  color: var(--elmer-muted);
  text-align: center;
  background: none;
  padding: 4px 0;
  max-width: 100%;
}

@keyframes elmerBotMsgIn {
  0% {
    opacity: 0;
    background-position: 0% 50%;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 1;
    background-position: 100% 50%;
  }
}
@keyframes elmerUserMsgIn {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

.elmer-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}
.elmer-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--elmer-muted);
  animation: elmerBounce 1.4s infinite ease-in-out;
}
.elmer-typing span:nth-child(2) { animation-delay: 0.16s; }
.elmer-typing span:nth-child(3) { animation-delay: 0.32s; }

@keyframes elmerBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Input area ── */
.elmer-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--elmer-line);
  background: var(--elmer-card);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}
.elmer-input-wrap {
  flex: 1;
  position: relative;
}
.elmer-input-wrap textarea {
  width: 100%;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 12px;
  border: 1px solid var(--elmer-line);
  border-radius: var(--elmer-radius-sm);
  background: var(--elmer-bg);
  color: var(--elmer-ink);
  font-family: var(--elmer-font);
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}
.elmer-input-wrap textarea:focus {
  border-color: var(--elmer-brand);
  box-shadow: 0 0 0 2px rgba(255, 122, 0, 0.15);
}
.elmer-input-wrap textarea::placeholder {
  color: var(--elmer-muted);
}
.elmer-send {
  width: 40px;
  height: 40px;
  border-radius: var(--elmer-radius-sm);
  border: none;
  background: var(--elmer-brand);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}
.elmer-send:hover:not(:disabled) {
  transform: scale(1.08);
}
.elmer-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.elmer-send:focus-visible {
  outline: 2px solid var(--elmer-brand);
  outline-offset: 2px;
}
.elmer-send svg {
  width: 18px;
  height: 18px;
}

/* ── Contact button ── */
.elmer-contact-btn {
  height: 40px;
  padding: 0 14px;
  border-radius: var(--elmer-radius-sm);
  border: 1px solid var(--elmer-line);
  background: linear-gradient(135deg, var(--elmer-brand), var(--elmer-brand-dark));
  color: #fff;
  font-family: var(--elmer-font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  transition: transform 0.15s, box-shadow 0.15s;
  border: none;
}
.elmer-contact-btn:hover,
.elmer-contact-btn:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 3px 12px rgba(255, 122, 0, 0.3);
}
.elmer-contact-btn:focus-visible {
  outline: 2px solid var(--elmer-brand);
  outline-offset: 2px;
}

/* ── Consent gate ── */
.elmer-consent {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 32px 24px;
  text-align: center;
  gap: 20px;
}
.elmer-consent p {
  font-size: 14px;
  color: var(--elmer-muted);
  line-height: 1.6;
  margin: 0;
}
.elmer-consent-actions {
  display: flex;
  gap: 12px;
}
.elmer-btn-primary {
  padding: 10px 24px;
  border-radius: var(--elmer-radius-sm);
  border: none;
  background: var(--elmer-brand);
  color: #fff;
  font-family: var(--elmer-font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.elmer-btn-primary:hover { opacity: 0.9; }
.elmer-btn-primary:focus-visible {
  outline: 2px solid var(--elmer-brand);
  outline-offset: 2px;
}
.elmer-btn-ghost {
  padding: 10px 24px;
  border-radius: var(--elmer-radius-sm);
  border: 1px solid var(--elmer-line);
  background: transparent;
  color: var(--elmer-muted);
  font-family: var(--elmer-font);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.elmer-btn-ghost:hover {
  background: var(--elmer-surface);
}
.elmer-btn-ghost:focus-visible {
  outline: 2px solid var(--elmer-brand);
  outline-offset: 2px;
}

/* ── Lead form (inline in chat) ── */
.elmer-lead-form {
  padding: 16px;
  background: var(--elmer-card);
  border: 1px solid var(--elmer-line);
  border-radius: var(--elmer-radius-sm);
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  align-self: stretch;
  max-width: 100%;
}
.elmer-lead-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--elmer-line);
  margin-bottom: 4px;
}
.elmer-lead-title {
  font-weight: 700;
  font-size: 15px;
  flex: 1;
}
.elmer-lead-close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--elmer-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
  padding: 0;
}
.elmer-lead-close:hover,
.elmer-lead-close:focus-visible {
  background: var(--elmer-surface);
  color: var(--elmer-ink);
}
.elmer-lead-close:focus-visible {
  outline: 2px solid var(--elmer-brand);
  outline-offset: 1px;
}
.elmer-lead-close svg {
  width: 16px;
  height: 16px;
}
.elmer-lead-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--elmer-muted);
}
.elmer-lead-form input[type="text"],
.elmer-lead-form input[type="email"],
.elmer-lead-form textarea {
  padding: 8px 10px;
  border: 1px solid var(--elmer-line);
  border-radius: 8px;
  background: var(--elmer-bg);
  color: var(--elmer-ink);
  font-family: var(--elmer-font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.elmer-lead-form input:focus,
.elmer-lead-form textarea:focus {
  border-color: var(--elmer-brand);
  box-shadow: 0 0 0 2px rgba(255, 122, 0, 0.15);
}
.elmer-lead-form textarea {
  min-height: 60px;
  resize: vertical;
}
.elmer-lead-consent {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 12px;
  color: var(--elmer-muted);
  line-height: 1.5;
}
.elmer-lead-consent input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--elmer-brand);
  flex-shrink: 0;
}
.elmer-lead-consent a {
  color: var(--elmer-brand);
  text-decoration: underline;
}
.elmer-lead-submit {
  padding: 10px 20px;
  border-radius: var(--elmer-radius-sm);
  border: none;
  background: linear-gradient(135deg, var(--elmer-brand), var(--elmer-brand-dark));
  color: #fff;
  font-family: var(--elmer-font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}
.elmer-lead-submit:hover:not(:disabled) {
  transform: translateY(-1px);
}
.elmer-lead-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.elmer-lead-error {
  font-size: 13px;
  color: var(--elmer-error);
}
.elmer-lead-success {
  font-size: 14px;
  color: var(--elmer-success);
  text-align: center;
  padding: 16px;
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  #elmer-panel,
  #elmer-panel.is-open,
  .elmer-msg--bot,
  .elmer-msg--user,
  .elmer-typing span,
  .elmer-send,
  .elmer-contact-btn,
  .elmer-lead-submit,
  .elmer-inline-avatar.is-thinking .elmer-avatar-img,
  .elmer-inline-avatar.is-thinking .elmer-avatar-fallback,
  .elmer-scroll-fade {
    animation: none !important;
    transition: none !important;
  }
}

/* ── Mobile responsive ── */
@media (max-width: 480px) {
  #elmer-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }
  #elmer-launcher {
    bottom: 16px;
    right: 16px;
  }
}
