/* ==========================================================================
   Magarage — AI chat widget
   Loaded by templates/partials/scripts.php only when setting('chat_enabled')
   is '1', so a disabled chat costs zero bytes.

   Restyled from the engine's original (a different design system) onto the
   base.css token set: red #E30613 accent, ink #0E1117, Public Sans, 10–24px
   radii, --sh-* shadows, --e-out easing. Every value below either references
   a base.css custom property or falls back to its literal, so the widget still
   renders correctly if it is ever loaded on a page without base.css.

   DOM contract — assets/js/chat-widget.js reads these IDs/classes:
     #mg-chat-widget, #chat-btn, #chat-bubble, .chat-bubble-text,
     .chat-bubble-close, #chat-window, #chat-messages, #chat-input,
     #chat-send, #chat-close, #chat-escalate, #chat-escalate-modal,
     #chat-escalate-form, #chat-escalate-cancel,
     .chat-msg, .chat-msg-user, .chat-msg-assistant, .chat-msg-text,
     .chat-quick-replies, .chat-quick-reply, .chat-contact-card,
     .chat-contact-form, .chat-contact-input, .chat-contact-actions,
     .chat-contact-skip, .chat-contact-submit, .chat-contact-title,
     .chat-typing, .chat-typing-dots, .chat-products, .chat-product-card,
     .chat-product-img, .chat-product-name, .chat-product-price,
     .chat-modal-cancel, .chat-modal-submit
   Plus: #chat-btn toggles .open to swap the close icon.
   ========================================================================== */

#mg-chat-widget {
  --mg-c-bg:       var(--c-bg,      #FFFFFF);
  --mg-c-bg-alt:   var(--c-bg-alt,  #F4F5F8);
  --mg-c-ink:      var(--c-ink,     #0E1117);
  --mg-c-ink-700:  var(--c-ink-700, #1E232C);
  --mg-c-red:      var(--c-red,     #E30613);
  --mg-c-red-hover:var(--c-red-hover, #B8050F);
  --mg-c-red-ink:  var(--c-red-ink, #C1050F);
  --mg-c-red-ring: var(--c-red-ring, rgba(227,6,19,.22));
  --mg-c-slate:    var(--c-slate,   #4C5462);
  --mg-c-line:     var(--c-line,    #DFE3EC);
  --mg-c-line-2:   var(--c-line-2,  #C6CCD8);
  --mg-ff:         var(--font-b, 'Public Sans', system-ui, -apple-system, sans-serif);
  --mg-ff-d:       var(--font-d, 'Bricolage Grotesque', system-ui, sans-serif);
  --mg-r-sm:       var(--r-sm, 10px);
  --mg-r-md:       var(--r-md, 14px);
  --mg-r-lg:       var(--r-lg, 18px);
  --mg-r-full:     var(--r-full, 999px);
  --mg-e:          var(--e-out, cubic-bezier(.32,.72,0,1));
  --mg-t:          var(--t-fast, 180ms);
  --mg-tap:        var(--tap, 44px);

  font-family: var(--mg-ff);
  color: var(--mg-c-ink);
  -webkit-font-smoothing: antialiased;
}

/* ── Floating action button ────────────────────────────────────── */
#mg-chat-widget .chat-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: var(--mg-r-full);
  background: var(--mg-c-ink);
  color: #fff;
  border: 1px solid var(--mg-c-ink);
  cursor: pointer;
  z-index: 96;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--sh-2, 0 1px 2px rgba(14,17,23,.06), 0 10px 28px rgba(14,17,23,.08));
  transition: transform var(--mg-t) var(--mg-e), box-shadow var(--mg-t) var(--mg-e), background var(--mg-t) var(--mg-e);
  padding: 0;
  font-family: inherit;
}
#mg-chat-widget .chat-btn:hover { background: var(--mg-c-ink-700); transform: translateY(-1px); }
#mg-chat-widget .chat-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--mg-c-red-ring), var(--sh-2, 0 10px 28px rgba(14,17,23,.08));
}
#mg-chat-widget .chat-btn svg { display: block; }
#mg-chat-widget .chat-btn:not(.open) .chat-btn-close { display: none; }
#mg-chat-widget .chat-btn.open svg:first-of-type { display: none; }

/* One short attention pulse on first paint. Never for reduced-motion users. */
@keyframes mgChatPulse {
  0%   { box-shadow: 0 10px 28px rgba(14,17,23,.10), 0 0 0 0   rgba(227,6,19,.50); }
  70%  { box-shadow: 0 10px 28px rgba(14,17,23,.10), 0 0 0 14px rgba(227,6,19,0); }
  100% { box-shadow: 0 10px 28px rgba(14,17,23,.10), 0 0 0 0   rgba(227,6,19,0); }
}
@media (prefers-reduced-motion: no-preference) {
  #mg-chat-widget .chat-btn:not(.open) { animation: mgChatPulse 1.6s var(--mg-e) 1.5s 2; }
}

/* ── Auto-greeting bubble ──────────────────────────────────────── */
#mg-chat-widget .chat-bubble {
  position: fixed;
  bottom: 92px;
  right: 24px;
  max-width: 288px;
  background: var(--mg-c-bg);
  color: var(--mg-c-ink);
  border: 1px solid var(--mg-c-line);
  border-left: 3px solid var(--mg-c-red);
  border-radius: var(--mg-r-md);
  padding: 14px 40px 14px 16px;
  box-shadow: var(--sh-2, 0 10px 28px rgba(14,17,23,.08));
  z-index: 95;
  font-size: .9375rem;
  line-height: 1.45;
  cursor: pointer;
  animation: mgChatIn .3s var(--mg-e);
}
#mg-chat-widget .chat-bubble-close {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 32px;
  min-height: 32px;
  background: none;
  border: 0;
  font-size: 20px;
  line-height: 1;
  color: var(--mg-c-slate);
  cursor: pointer;
  font-family: inherit;
  border-radius: var(--mg-r-sm);
}
#mg-chat-widget .chat-bubble-close:hover { color: var(--mg-c-ink); }

/* ── Chat window ───────────────────────────────────────────────── */
#mg-chat-widget .chat-window {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 380px;
  height: 540px;
  max-height: calc(100dvh - 130px);
  background: var(--mg-c-bg);
  border: 1px solid var(--mg-c-line);
  border-radius: var(--mg-r-lg);
  box-shadow: var(--sh-3, 0 26px 64px rgba(14,17,23,.20));
  z-index: 95;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: mgChatIn .22s var(--mg-e);
}
@keyframes mgChatIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Header (dark ink bar) ─────────────────────────────────────── */
#mg-chat-widget .chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--mg-c-ink);
  color: #fff;
  flex-shrink: 0;
}
#mg-chat-widget .chat-header-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
#mg-chat-widget .chat-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .75rem;
  letter-spacing: .04em;
  color: rgba(255,255,255,.72);
  line-height: 1;
}
#mg-chat-widget .chat-eyebrow::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--c-green-on-dark, #3DDC84);
  flex-shrink: 0;
}
#mg-chat-widget .chat-wordmark {
  font-family: var(--mg-ff-d);
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -.01em;
  color: #fff;
  line-height: 1.15;
}
#mg-chat-widget .chat-wordmark .dot { color: var(--c-red-on-dark, #FF5A64); }
#mg-chat-widget .chat-close {
  background: none;
  border: 0;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  min-width: 36px;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--mg-r-sm);
  transition: color var(--mg-t) var(--mg-e), background var(--mg-t) var(--mg-e);
  font-family: inherit;
  flex-shrink: 0;
}
#mg-chat-widget .chat-close:hover { color: #fff; background: rgba(255,255,255,.10); }
#mg-chat-widget .chat-close:focus-visible { outline: 2px solid var(--c-focus-dark, #fff); outline-offset: 2px; }

/* ── Messages area ─────────────────────────────────────────────── */
/* Pinned AI-disclosure line (EU AI Act Art. 50) — continuation of the ink
   header bar, sits between header and log so it can never scroll away. */
#mg-chat-widget .chat-ai-note {
  flex-shrink: 0;
  background: var(--mg-c-ink, #12151A);
  color: rgba(255, 255, 255, .62);
  font-size: .72rem;
  line-height: 1.4;
  padding: 0 16px 10px;
}

#mg-chat-widget .chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--mg-c-bg-alt);
  scrollbar-width: thin;
  scrollbar-color: var(--mg-c-line-2) transparent;
  overscroll-behavior: contain;
}
#mg-chat-widget .chat-messages::-webkit-scrollbar { width: 6px; }
#mg-chat-widget .chat-messages::-webkit-scrollbar-track { background: transparent; }
#mg-chat-widget .chat-messages::-webkit-scrollbar-thumb { background: var(--mg-c-line-2); border-radius: var(--mg-r-full); }

/* ── Message bubbles ───────────────────────────────────────────── */
#mg-chat-widget .chat-msg {
  max-width: 88%;
  font-size: .9375rem;
  line-height: 1.55;
  animation: mgChatIn .2s var(--mg-e);
}
#mg-chat-widget .chat-msg-text { word-wrap: break-word; overflow-wrap: anywhere; }

/* Rendered Markdown built by chat-widget.js (real nodes, never innerHTML). */
#mg-chat-widget .chat-msg-text .chat-md-p { margin: 0 0 8px; }
#mg-chat-widget .chat-msg-text > *:last-child { margin-bottom: 0; }
#mg-chat-widget .chat-msg-text .chat-md-h {
  font-family: var(--mg-ff-d);
  font-weight: 700;
  font-size: .9375rem;
  letter-spacing: -.01em;
  margin: 10px 0 6px;
}
#mg-chat-widget .chat-msg-text .chat-md-h:first-child { margin-top: 0; }
#mg-chat-widget .chat-msg-text .chat-md-list { margin: 0 0 8px; padding-left: 18px; }
#mg-chat-widget .chat-msg-text .chat-md-list li { margin: 0 0 5px; }
#mg-chat-widget .chat-msg-text .chat-md-list li:last-child { margin-bottom: 0; }
#mg-chat-widget .chat-msg-text .chat-md-list li::marker { color: var(--mg-c-red); }
#mg-chat-widget .chat-msg-text strong { font-weight: 700; }
#mg-chat-widget .chat-msg-text em { font-style: italic; }
#mg-chat-widget .chat-msg-text code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8125rem;
  background: rgba(14,17,23,.06);
  padding: 1px 5px;
  border-radius: 6px;
}
#mg-chat-widget .chat-msg-text .chat-link {
  color: var(--mg-c-red-ink);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
  overflow-wrap: anywhere;
  transition: color var(--mg-t) var(--mg-e);
}
#mg-chat-widget .chat-msg-text .chat-link:hover { color: var(--mg-c-ink); text-decoration-thickness: 2px; }
#mg-chat-widget .chat-msg-text .chat-link:focus-visible { outline: 2px solid var(--mg-c-ink); outline-offset: 2px; border-radius: 3px; }

/* Visitor — red, right-aligned */
#mg-chat-widget .chat-msg-user {
  align-self: flex-end;
  background: var(--mg-c-red);
  color: #fff;
  border-radius: var(--mg-r-md) var(--mg-r-md) 4px var(--mg-r-md);
  padding: 10px 14px;
}
#mg-chat-widget .chat-msg-user .chat-link { color: #fff; }

/* Assistant — white card with a small label above */
#mg-chat-widget .chat-msg-assistant {
  align-self: flex-start;
  background: var(--mg-c-bg);
  color: var(--mg-c-ink);
  border: 1px solid var(--mg-c-line);
  border-radius: var(--mg-r-md) var(--mg-r-md) var(--mg-r-md) 4px;
  padding: 10px 14px;
  position: relative;
  margin-top: 16px;
  box-shadow: var(--sh-1, 0 1px 2px rgba(14,17,23,.06));
}
#mg-chat-widget .chat-msg-assistant::before {
  content: 'MAGARAGE';
  position: absolute;
  top: -15px;
  left: 2px;
  font-size: .625rem;
  letter-spacing: .12em;
  font-weight: 700;
  color: var(--mg-c-slate);
  line-height: 1;
}

/* ── Quick replies ─────────────────────────────────────────────── */
#mg-chat-widget .chat-quick-replies { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
#mg-chat-widget .chat-quick-reply {
  background: var(--mg-c-bg);
  border: 1px solid var(--mg-c-line-2);
  color: var(--mg-c-ink);
  border-radius: var(--mg-r-full);
  padding: 8px 14px;
  min-height: 36px;
  font-size: .8125rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--mg-t) var(--mg-e), color var(--mg-t) var(--mg-e), border-color var(--mg-t) var(--mg-e);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#mg-chat-widget .chat-quick-reply:hover { background: var(--mg-c-ink); border-color: var(--mg-c-ink); color: #fff; }
#mg-chat-widget .chat-quick-reply:focus-visible { outline: 2px solid var(--mg-c-ink); outline-offset: 2px; }

/* ── Typing indicator ──────────────────────────────────────────── */
#mg-chat-widget .chat-typing {
  align-self: flex-start;
  background: var(--mg-c-bg);
  border: 1px solid var(--mg-c-line);
  border-radius: var(--mg-r-md);
  padding: 12px 16px;
}
#mg-chat-widget .chat-typing-dots { display: flex; gap: 4px; }
#mg-chat-widget .chat-typing-dots span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--mg-c-slate);
  animation: mgChatDot 1.2s infinite;
}
#mg-chat-widget .chat-typing-dots span:nth-child(2) { animation-delay: .2s; }
#mg-chat-widget .chat-typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes mgChatDot {
  0%, 60%, 100% { transform: translateY(0);    opacity: .4; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

/* ── Contact collection card ───────────────────────────────────── */
#mg-chat-widget .chat-contact-card {
  background: var(--mg-c-bg);
  border: 1px solid var(--mg-c-line);
  border-radius: var(--mg-r-md);
  padding: 16px;
  box-shadow: var(--sh-1, 0 1px 2px rgba(14,17,23,.06));
  animation: mgChatIn .22s var(--mg-e);
}
#mg-chat-widget .chat-contact-title {
  font-family: var(--mg-ff-d);
  font-weight: 700;
  font-size: 1rem;
  color: var(--mg-c-ink);
  margin-bottom: 12px;
  letter-spacing: -.01em;
}
#mg-chat-widget .chat-contact-form { display: flex; flex-direction: column; gap: 8px; }
#mg-chat-widget .chat-contact-input {
  width: 100%;
  min-height: var(--mg-tap);
  padding: 10px 12px;
  border: 1px solid var(--mg-c-line-2);
  border-radius: var(--mg-r-sm);
  font-size: 16px;                 /* 16px stops iOS zooming the page on focus */
  font-family: inherit;
  background: var(--mg-c-bg);
  color: var(--mg-c-ink);
  outline: none;
  box-sizing: border-box;
  transition: border-color var(--mg-t) var(--mg-e), box-shadow var(--mg-t) var(--mg-e);
}
#mg-chat-widget .chat-contact-input:focus { border-color: var(--mg-c-ink); box-shadow: 0 0 0 3px var(--mg-c-red-ring); }
#mg-chat-widget .chat-contact-input::placeholder { color: var(--mg-c-slate); }
#mg-chat-widget .chat-contact-actions { display: flex; gap: 8px; margin-top: 4px; }
#mg-chat-widget .chat-contact-skip,
#mg-chat-widget .chat-contact-submit {
  flex: 1;
  min-height: var(--mg-tap);
  padding: 10px 12px;
  font-size: .8125rem;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  border-radius: var(--mg-r-full);
  transition: background var(--mg-t) var(--mg-e), color var(--mg-t) var(--mg-e), border-color var(--mg-t) var(--mg-e);
}
#mg-chat-widget .chat-contact-skip {
  background: transparent;
  border: 1px solid var(--mg-c-line-2);
  color: var(--mg-c-slate);
}
#mg-chat-widget .chat-contact-skip:hover { color: var(--mg-c-ink); border-color: var(--mg-c-ink); }
#mg-chat-widget .chat-contact-submit {
  background: var(--mg-c-red);
  color: #fff;
  border: 1px solid var(--mg-c-red);
}
#mg-chat-widget .chat-contact-submit:hover { background: var(--mg-c-red-hover); border-color: var(--mg-c-red-hover); }

/* ── Reservation status card (deterministic, zero-data path) ───── */
#mg-chat-widget .chat-track-error { font-size: .8125rem; line-height: 1.45; color: var(--mg-c-red-ink); margin-top: 2px; }
#mg-chat-widget .chat-track-status {
  background: var(--mg-c-bg);
  border: 1px solid var(--mg-c-line);
  border-radius: var(--mg-r-md);
  padding: 14px 16px;
  margin-top: 8px;
  animation: mgChatIn .22s var(--mg-e);
}
#mg-chat-widget .chat-track-status-head {
  font-family: var(--mg-ff-d);
  font-size: .9375rem;
  font-weight: 700;
  color: var(--mg-c-ink);
  margin-bottom: 10px;
}
#mg-chat-widget .chat-track-row { display: flex; justify-content: space-between; gap: 12px; font-size: .8125rem; padding: 3px 0; }
#mg-chat-widget .chat-track-label { color: var(--mg-c-slate); }
#mg-chat-widget .chat-track-value { font-weight: 600; color: var(--mg-c-ink); text-align: right; }
#mg-chat-widget .chat-track-cta {
  display: block;
  margin-top: 10px;
  min-height: var(--mg-tap);
  padding: 12px;
  text-align: center;
  background: var(--mg-c-ink);
  color: #fff;
  text-decoration: none;
  font-size: .8125rem;
  font-weight: 700;
  border-radius: var(--mg-r-full);
  transition: background var(--mg-t) var(--mg-e);
}
#mg-chat-widget .chat-track-cta:hover { background: var(--mg-c-ink-700); }
#mg-chat-widget .chat-track-cta-pay { background: var(--mg-c-red); }
#mg-chat-widget .chat-track-cta-pay:hover { background: var(--mg-c-red-hover); }

/* ── Part cards (AI suggestions) ───────────────────────────────── */
#mg-chat-widget .chat-products { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
#mg-chat-widget .chat-product-card {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--mg-c-bg);
  border: 1px solid var(--mg-c-line);
  border-radius: var(--mg-r-md);
  padding: 8px;
  text-decoration: none;
  color: inherit;
  min-height: var(--mg-tap);
  transition: border-color var(--mg-t) var(--mg-e), box-shadow var(--mg-t) var(--mg-e);
}
#mg-chat-widget .chat-product-card:hover { border-color: var(--mg-c-ink); box-shadow: var(--sh-2, 0 10px 28px rgba(14,17,23,.08)); }
#mg-chat-widget .chat-product-card:focus-visible { outline: 2px solid var(--mg-c-ink); outline-offset: 2px; }
#mg-chat-widget .chat-product-img {
  width: 56px; height: 56px;
  border-radius: var(--mg-r-sm);
  object-fit: cover;
  background: var(--mg-c-bg-alt);
  flex-shrink: 0;
}
#mg-chat-widget .chat-product-info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
#mg-chat-widget .chat-product-name {
  font-size: .875rem;
  font-weight: 600;
  color: var(--mg-c-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#mg-chat-widget .chat-product-price { font-size: .8125rem; color: var(--mg-c-slate); font-weight: 600; }

/* ── Input area ────────────────────────────────────────────────── */
#mg-chat-widget .chat-input-area {
  display: flex;
  align-items: flex-end;
  padding: 12px 14px;
  border-top: 1px solid var(--mg-c-line);
  gap: 10px;
  background: var(--mg-c-bg);
  flex-shrink: 0;
}
#mg-chat-widget .chat-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 10px 0;
  font-size: 16px;                 /* keep iOS from zooming */
  resize: none;
  outline: none;
  max-height: 96px;
  min-height: 24px;
  line-height: 1.45;
  font-family: inherit;
  color: var(--mg-c-ink);
}
#mg-chat-widget .chat-input::placeholder { color: var(--mg-c-slate); }
#mg-chat-widget .chat-send {
  width: var(--mg-tap); height: var(--mg-tap);
  border-radius: var(--mg-r-full);
  background: var(--mg-c-red);
  color: #fff;
  border: 1px solid var(--mg-c-red);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--mg-t) var(--mg-e), opacity var(--mg-t) var(--mg-e);
  padding: 0;
  font-family: inherit;
}
#mg-chat-widget .chat-send:hover:not(:disabled) { background: var(--mg-c-red-hover); border-color: var(--mg-c-red-hover); }
#mg-chat-widget .chat-send:focus-visible { outline: 2px solid var(--mg-c-ink); outline-offset: 2px; }
#mg-chat-widget .chat-send:disabled { opacity: .4; cursor: default; }

/* ── Footer (escalate) ─────────────────────────────────────────── */
#mg-chat-widget .chat-footer {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 14px 12px;
  text-align: center;
  background: var(--mg-c-bg);
  flex-shrink: 0;
}
#mg-chat-widget .chat-escalate-btn {
  width: 100%;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--mg-c-line);
  padding: 12px 0 8px;
  min-height: var(--mg-tap);
  font-family: inherit;
  font-size: .8125rem;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--mg-c-slate);
  cursor: pointer;
  transition: color var(--mg-t) var(--mg-e);
}
#mg-chat-widget .chat-escalate-btn:hover { color: var(--mg-c-red-ink); }
#mg-chat-widget .chat-escalate-btn:focus-visible { outline: 2px solid var(--mg-c-ink); outline-offset: -2px; }

/* ── Escalation modal ──────────────────────────────────────────── */
#mg-chat-widget .chat-modal {
  position: fixed;
  inset: 0;
  background: rgba(14,17,23,.55);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: mgChatFade .18s var(--mg-e);
  padding: 20px;
  box-sizing: border-box;
  overflow-y: auto;
}
#mg-chat-widget .chat-modal-content {
  background: var(--mg-c-bg);
  border: 1px solid var(--mg-c-line);
  border-radius: var(--mg-r-lg);
  padding: 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--sh-3, 0 26px 64px rgba(14,17,23,.20));
  box-sizing: border-box;
}
#mg-chat-widget .chat-modal-content h3 {
  margin: 0 0 6px;
  font-family: var(--mg-ff-d);
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -.012em;
  color: var(--mg-c-ink);
}
#mg-chat-widget .chat-modal-content p {
  margin: 0 0 16px;
  font-size: .875rem;
  line-height: 1.5;
  color: var(--mg-c-slate);
}
#mg-chat-widget .chat-modal-content input,
#mg-chat-widget .chat-modal-content textarea {
  display: block;
  width: 100%;
  min-height: var(--mg-tap);
  padding: 11px 12px;
  margin-bottom: 10px;
  border: 1px solid var(--mg-c-line-2);
  border-radius: var(--mg-r-sm);
  font-size: 16px;
  font-family: inherit;
  color: var(--mg-c-ink);
  background: var(--mg-c-bg);
  outline: none;
  box-sizing: border-box;
  transition: border-color var(--mg-t) var(--mg-e), box-shadow var(--mg-t) var(--mg-e);
}
#mg-chat-widget .chat-modal-content input::placeholder,
#mg-chat-widget .chat-modal-content textarea::placeholder { color: var(--mg-c-slate); }
#mg-chat-widget .chat-modal-content input:focus,
#mg-chat-widget .chat-modal-content textarea:focus { border-color: var(--mg-c-ink); box-shadow: 0 0 0 3px var(--mg-c-red-ring); }
#mg-chat-widget .chat-modal-actions { display: flex; gap: 10px; margin-top: 6px; }
#mg-chat-widget .chat-modal-cancel,
#mg-chat-widget .chat-modal-submit {
  flex: 1;
  min-height: var(--mg-tap);
  padding: 11px 14px;
  font-size: .8125rem;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  border-radius: var(--mg-r-full);
  transition: background var(--mg-t) var(--mg-e), color var(--mg-t) var(--mg-e), border-color var(--mg-t) var(--mg-e);
}
#mg-chat-widget .chat-modal-cancel {
  background: transparent;
  border: 1px solid var(--mg-c-line-2);
  color: var(--mg-c-slate);
}
#mg-chat-widget .chat-modal-cancel:hover { color: var(--mg-c-ink); border-color: var(--mg-c-ink); }
#mg-chat-widget .chat-modal-submit {
  background: var(--mg-c-red);
  color: #fff;
  border: 1px solid var(--mg-c-red);
}
#mg-chat-widget .chat-modal-submit:hover { background: var(--mg-c-red-hover); border-color: var(--mg-c-red-hover); }
@keyframes mgChatFade { from { opacity: 0; } to { opacity: 1; } }

/* ── Mobile: full-screen sheet (375px-safe, no horizontal overflow) ─ */
@media (max-width: 640px) {
  #mg-chat-widget .chat-window {
    inset: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
    animation: mgChatSlideUp .24s var(--mg-e);
  }
  #mg-chat-widget .chat-input-area { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  #mg-chat-widget .chat-footer     { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  /* Clear of the sticky mobile CTA bar (--mcta-h) so the FAB stays tappable. */
  #mg-chat-widget .chat-btn    { bottom: calc(var(--mcta-h, 72px) + 12px); right: 16px; }
  #mg-chat-widget .chat-bubble { bottom: calc(var(--mcta-h, 72px) + 76px); right: 16px; left: 16px; max-width: none; }
  #mg-chat-widget .chat-msg    { max-width: 92%; }

  /* Touch targets ≥ 44px on mobile (--tap). Chips can be denser on desktop. */
  #mg-chat-widget .chat-quick-reply  { min-height: var(--mg-tap); padding: 10px 16px; }
  #mg-chat-widget .chat-close        { min-width: var(--mg-tap); min-height: var(--mg-tap); }
  #mg-chat-widget .chat-bubble-close { min-width: var(--mg-tap); min-height: var(--mg-tap); top: 2px; right: 2px; }
  #mg-chat-widget .chat-bubble       { padding-right: 52px; }

  /* Deliberately a SHORT offset, not translateY(100%): if the animation never
     advances (tab opened while backgrounded / compositing paused), a stuck
     first frame must not park the sheet off-screen. */
  @keyframes mgChatSlideUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
}

/* ── Reduced motion ────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #mg-chat-widget *,
  #mg-chat-widget *::before,
  #mg-chat-widget *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* ── Lock the page behind the mobile full-screen sheet ─────────── */
body.mg-chat-open { overflow: hidden !important; }
@media (min-width: 641px) { body.mg-chat-open { overflow: auto !important; } }
