/* ============================================================================
   GPTGRIDX — Shared themeable chat widget
   Configured per page via window.GRIDX_CONFIG. Scoped under #gxw-root.
   ============================================================================ */

#gxw-root, #gxw-root *, #gxw-fab, #gxw-fab * { box-sizing: border-box; }

#gxw-root {
  /* Defaults — overridden inline by chat-widget.js from GRIDX_CONFIG */
  --gxw-accent: #d7ad54;
  --gxw-accent2: #f0c76d;
  --gxw-ink: #140d00;
  --gxw-panel: #0f0e0c;
  --gxw-panel2: #181410;
  --gxw-text: #f4efe6;
  --gxw-muted: rgba(244, 239, 230, 0.5);
  --gxw-border: rgba(255, 255, 255, 0.09);
  --gxw-bot-bubble: rgba(255, 255, 255, 0.055);
  --gxw-header: rgba(255, 255, 255, 0.025);
  --gxw-input-bg: rgba(255, 255, 255, 0.055);
  --gxw-shadow: 0 32px 90px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255,255,255,0.06);
  --gxw-radius: 22px;
  --gxw-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --gxw-font: "Manrope", "DM Sans", system-ui, -apple-system, sans-serif;
}
#gxw-root.gxw-light {
  --gxw-panel: #ffffff;
  --gxw-panel2: #f7f5f1;
  --gxw-text: #1c1a17;
  --gxw-muted: rgba(28, 26, 23, 0.5);
  --gxw-border: rgba(0, 0, 0, 0.08);
  --gxw-bot-bubble: rgba(0, 0, 0, 0.04);
  --gxw-header: rgba(0, 0, 0, 0.015);
  --gxw-input-bg: rgba(0, 0, 0, 0.04);
  --gxw-shadow: 0 32px 90px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(0,0,0,0.06);
}

/* FAB entrance + float animations */
@keyframes gxwFabIn {
  from { opacity: 0; transform: translateY(36px) scale(0.6); }
  to   { opacity: 1; transform: none; }
}
@keyframes gxwFabBob {
  0%, 100% { transform: translateY(0) scale(1); }
  50%       { transform: translateY(-7px) scale(1.03); }
}

/* ── FAB ── */
#gxw-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 62px;
  height: 62px;
  border: none;
  border-radius: 50%;
  background: #d7ad54;
  background: linear-gradient(150deg, var(--gxw-accent2, #f0c76d), var(--gxw-accent, #d7ad54));
  color: var(--gxw-ink, #140d00);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2147483000;
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.32), 0 0 0 1.5px rgba(255,255,255,0.12);
  transition: transform 0.3s var(--gxw-ease), box-shadow 0.3s var(--gxw-ease), opacity 0.35s ease;
  font-family: var(--gxw-font);
}
#gxw-fab:hover { transform: translateY(-4px) scale(1.06); box-shadow: 0 18px 50px rgba(0, 0, 0, 0.4); }
#gxw-fab:active { transform: scale(0.96); }
#gxw-fab svg { width: 26px; height: 26px; position: relative; z-index: 2; }

#gxw-fab .gxw-fab-ring {
  position: absolute; inset: -7px; border-radius: 50%;
  border: 1.5px solid var(--gxw-accent, #d7ad54);
  opacity: 0;
  animation: gxwPulse 3s ease-out infinite;
  pointer-events: none;
}
#gxw-fab .gxw-fab-badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 999px; background: #ff3b53; color: #fff;
  font-size: 11px; font-weight: 800; display: grid; place-items: center;
  box-shadow: 0 2px 10px rgba(255, 59, 83, 0.6); z-index: 3;
  animation: gxwBadgePop 0.5s var(--gxw-ease) both 0.8s;
}
@keyframes gxwBadgePop { from { transform: scale(0); } to { transform: scale(1); } }
@keyframes gxwPulse {
  0%   { transform: scale(0.94); opacity: 0.65; }
  80%  { transform: scale(1.55); opacity: 0; }
  100% { transform: scale(1.55); opacity: 0; }
}
body.gxw-open #gxw-fab { opacity: 0; transform: scale(0.8) translateY(10px); pointer-events: none; }
@media (max-width: 520px) { body.gxw-open { overflow: hidden; } }

/* ── Teaser bubble: invites the visitor to chat (once per session) ── */
#gxw-teaser {
  position: fixed;
  right: 24px;
  bottom: calc(24px + 62px + 14px); /* sits just above the FAB */
  z-index: 2147482999;
  display: flex; align-items: flex-start; gap: 10px;
  max-width: 300px;
  padding: 13px 34px 13px 13px;
  background: #14110b;
  border: 1px solid rgba(201, 168, 76, 0.35);
  border-radius: 18px; border-bottom-right-radius: 5px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  font-family: "Manrope", system-ui, -apple-system, sans-serif;
  animation: gxwTeaserIn 0.45s cubic-bezier(0.16, 1, 0.3, 1) both;
}
#gxw-teaser.gxw-no-anim { animation: none; }
#gxw-teaser.gxw-teaser-out { opacity: 0; transform: translateY(8px) scale(0.96); transition: opacity 0.3s, transform 0.3s; }
@keyframes gxwTeaserIn {
  from { opacity: 0; transform: translateY(14px) scale(0.92); }
  to   { opacity: 1; transform: none; }
}
#gxw-teaser .gxw-teaser-av {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 13px; font-weight: 800;
}
#gxw-teaser .gxw-teaser-txt { min-width: 0; }
#gxw-teaser .gxw-teaser-txt b { display: block; font-size: 12px; color: #f0c76d; margin-bottom: 2px; }
#gxw-teaser .gxw-teaser-txt span { font-size: 12.5px; line-height: 1.5; color: rgba(244, 239, 230, 0.85); display: block; }
#gxw-teaser .gxw-teaser-x {
  position: absolute; top: 6px; right: 6px;
  width: 22px; height: 22px; border: none; border-radius: 7px;
  background: transparent; color: rgba(244, 239, 230, 0.45);
  font-size: 11px; cursor: pointer; display: grid; place-items: center;
  font-family: inherit;
}
#gxw-teaser .gxw-teaser-x:hover { color: #f4efe6; background: rgba(255, 255, 255, 0.08); }

/* ── Panel ── */
#gxw-root {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 640px;
  max-height: calc(100svh - 40px);
  z-index: 2147483001;
  font-family: var(--gxw-font);
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--gxw-panel2) 0%, var(--gxw-panel) 100%);
  border: 1px solid var(--gxw-border);
  border-radius: var(--gxw-radius);
  box-shadow: var(--gxw-shadow);
  overflow: hidden;
  opacity: 0;
  transform: translateY(24px) scale(0.92);
  transform-origin: 100% 100%; /* grow out of the FAB corner */
  pointer-events: none;
  transition: opacity 0.32s var(--gxw-ease), transform 0.42s var(--gxw-ease);
}
#gxw-root.gxw-show {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
/* while the on-screen keyboard drives layout, transitions just add lag */
#gxw-root.gxw-kb { transition: none; }
/* skip entrance animations when restoring a saved conversation */
#gxw-root.gxw-restoring .gxw-msg { animation: none !important; }

/* accent glow on top edge */
#gxw-root::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent 0%, var(--gxw-accent2) 40%, var(--gxw-accent) 60%, transparent 100%);
  opacity: 0.85; z-index: 5;
}

/* ── Header ── */
#gxw-root .gxw-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px 13px;
  background: var(--gxw-header);
  border-bottom: 1px solid var(--gxw-border);
  flex-shrink: 0;
}
#gxw-root .gxw-mark {
  width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
  background: linear-gradient(150deg, var(--gxw-accent2), var(--gxw-accent));
  color: var(--gxw-ink);
  display: grid; place-items: center;
  font-weight: 800; font-size: 17px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.22);
}
#gxw-root .gxw-htext { min-width: 0; flex: 1; }
#gxw-root .gxw-htext h4 {
  margin: 0; font-size: 15px; font-weight: 700; color: var(--gxw-text);
  line-height: 1.2; display: flex; align-items: center; gap: 0; flex-wrap: wrap;
}
#gxw-root .gxw-htext p { margin: 3px 0 0; font-size: 11.5px; color: var(--gxw-muted); display: flex; align-items: center; gap: 6px; }
#gxw-root .gxw-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #3ddc84; flex-shrink: 0; position: relative;
}
#gxw-root .gxw-dot::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%;
  background: #3ddc84;
  animation: gxwDotPing 2.8s ease-out infinite;
  pointer-events: none;
}
@keyframes gxwDotPing {
  0%   { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(3); opacity: 0; }
}

/* AI Agent badge */
#gxw-root .gxw-ai-badge {
  display: inline-flex; align-items: center;
  padding: 2px 7px; border-radius: 100px; margin-left: 7px;
  font-size: 8.5px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase;
  background: linear-gradient(135deg, var(--gxw-accent2), var(--gxw-accent));
  color: var(--gxw-ink); line-height: 1.9; vertical-align: middle;
}

/* Get Connected button — main bot only */
#gxw-root .gxw-connect-btn {
  padding: 6px 13px; border-radius: 100px; border: none;
  background: linear-gradient(135deg, var(--gxw-accent2, #f0c76d), var(--gxw-accent, #d7ad54));
  color: var(--gxw-ink, #140d00); font-size: 11px; font-weight: 800;
  cursor: pointer; font-family: inherit; letter-spacing: 0.04em; text-transform: uppercase;
  transition: transform 0.2s, opacity 0.2s; white-space: nowrap;
}
#gxw-root .gxw-connect-btn:hover { transform: scale(1.05); opacity: 0.88; }
#gxw-root .gxw-connect-btn:active { transform: scale(0.97); }

#gxw-root .gxw-hbtns { display: flex; gap: 6px; align-items: center; }
#gxw-root .gxw-icon-btn {
  width: 32px; height: 32px; border-radius: 9px; border: 1px solid var(--gxw-border);
  background: transparent; color: var(--gxw-muted); cursor: pointer;
  display: grid; place-items: center; font-size: 14px;
  transition: all 0.18s; font-family: inherit;
}
#gxw-root .gxw-icon-btn:hover { color: var(--gxw-text); border-color: var(--gxw-accent); background: var(--gxw-bot-bubble); }

/* ── Messages ── */
#gxw-root .gxw-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth;
  background-image: radial-gradient(circle, var(--gxw-border) 1px, transparent 1px);
  background-size: 22px 22px;
}
#gxw-root .gxw-body::-webkit-scrollbar { width: 4px; }
#gxw-root .gxw-body::-webkit-scrollbar-thumb { background: var(--gxw-border); border-radius: 2px; }

#gxw-root .gxw-msg {
  display: flex; gap: 8px; align-items: flex-end;
  max-width: 88%;
}
#gxw-root .gxw-msg.gxw-bot  { align-self: flex-start; animation: gxwMsgInLeft  0.3s var(--gxw-ease) both; }
#gxw-root .gxw-msg.gxw-user { align-self: flex-end; flex-direction: row-reverse; animation: gxwMsgInRight 0.3s var(--gxw-ease) both; }

@keyframes gxwMsgInLeft  { from { opacity: 0; transform: translateX(-10px) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes gxwMsgInRight { from { opacity: 0; transform: translateX(10px) translateY(6px); } to { opacity: 1; transform: none; } }

#gxw-root .gxw-avatar {
  width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(150deg, var(--gxw-accent2), var(--gxw-accent));
  color: var(--gxw-ink); display: grid; place-items: center;
  font-size: 11px; font-weight: 800;
}
#gxw-root .gxw-bubble {
  padding: 10px 14px; border-radius: 18px; font-size: 14px; line-height: 1.58;
  white-space: pre-wrap; word-wrap: break-word;
}
#gxw-root .gxw-bot .gxw-bubble {
  background: var(--gxw-bot-bubble); color: var(--gxw-text);
  border: 1px solid var(--gxw-border); border-bottom-left-radius: 4px;
}
#gxw-root .gxw-user .gxw-bubble {
  background: linear-gradient(150deg, var(--gxw-accent2), var(--gxw-accent));
  color: var(--gxw-ink); font-weight: 500; border-bottom-right-radius: 4px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
}
#gxw-root .gxw-bubble a { color: inherit; font-weight: 700; text-decoration: underline; }
#gxw-root .gxw-cursor { display: inline-block; width: 6px; height: 14px; background: var(--gxw-accent); margin-left: 2px; border-radius: 2px; animation: gxwBlink 0.9s steps(2) infinite; vertical-align: text-bottom; }
@keyframes gxwBlink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

/* typing */
#gxw-root .gxw-typing {
  display: flex; gap: 5px; padding: 12px 14px; align-self: flex-start;
  background: var(--gxw-bot-bubble); border: 1px solid var(--gxw-border);
  border-radius: 18px; border-bottom-left-radius: 4px;
  animation: gxwMsgInLeft 0.3s var(--gxw-ease) both;
}
#gxw-root .gxw-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--gxw-muted);
  animation: gxwBounce 1.4s ease-in-out infinite;
}
#gxw-root .gxw-typing span:nth-child(2) { animation-delay: 0.18s; }
#gxw-root .gxw-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes gxwBounce {
  0%,60%,100% { transform: translateY(0); opacity: 0.35; }
  30% { transform: translateY(-7px); opacity: 1; }
}
.gxw-hidden { display: none !important; }

/* ── Inline contact card ── */
#gxw-root .gxw-card {
  align-self: stretch; margin: 4px 2px;
  background: var(--gxw-bot-bubble); border: 1px solid var(--gxw-border);
  border-radius: 18px; padding: 16px;
  animation: gxwMsgInLeft 0.3s var(--gxw-ease) both;
}
#gxw-root .gxw-card h5 { margin: 0 0 4px; font-size: 14px; color: var(--gxw-text); font-weight: 700; }
#gxw-root .gxw-card p { margin: 0 0 12px; font-size: 12.5px; color: var(--gxw-muted); line-height: 1.5; }
#gxw-root .gxw-card p.gxw-card-err { color: #ff6b7d; }
#gxw-root .gxw-card input {
  width: 100%; margin-bottom: 9px; padding: 11px 14px;
  background: var(--gxw-input-bg); border: 1px solid var(--gxw-border);
  border-radius: 12px; color: var(--gxw-text); font-size: 16px; font-family: inherit; outline: none;
  transition: border-color 0.18s;
}
#gxw-root .gxw-card input:focus { border-color: var(--gxw-accent); box-shadow: 0 0 0 3px rgba(215,173,84,0.12); }
#gxw-root .gxw-card-submit {
  width: 100%; padding: 12px; border: none; border-radius: 12px; cursor: pointer;
  background: linear-gradient(150deg, var(--gxw-accent2), var(--gxw-accent));
  color: var(--gxw-ink); font-weight: 700; font-size: 14px; font-family: inherit;
  transition: transform 0.15s, box-shadow 0.15s;
}
#gxw-root .gxw-card-submit:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(0,0,0,0.2); }
#gxw-root .gxw-card-submit:active { transform: scale(0.98); }
#gxw-root .gxw-card-skip { display: block; margin: 8px auto 0; background: none; border: none; color: var(--gxw-muted); font-size: 12px; cursor: pointer; text-decoration: underline; font-family: inherit; }

/* ── Quick replies ── */
#gxw-root .gxw-quick {
  display: flex; flex-wrap: wrap; gap: 7px;
  padding: 4px 14px 10px; flex-shrink: 0;
}
#gxw-root .gxw-chip {
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  background: transparent; border: 1px solid var(--gxw-border);
  color: var(--gxw-text); font-size: 12.5px; font-weight: 500; font-family: inherit;
  transition: all 0.2s var(--gxw-ease); white-space: nowrap;
}
#gxw-root .gxw-chip:hover {
  border-color: var(--gxw-accent); background: var(--gxw-bot-bubble);
  transform: translateY(-1px);
}
#gxw-root .gxw-chip:active { transform: scale(0.97); }
#gxw-root .gxw-chip.gxw-primary {
  background: linear-gradient(150deg, var(--gxw-accent2), var(--gxw-accent));
  color: var(--gxw-ink); border-color: transparent; font-weight: 700;
}
#gxw-root .gxw-chip.gxw-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,0.2); }

/* ── Input ── */
#gxw-root .gxw-input-wrap {
  display: flex; gap: 8px; padding: 10px 12px 12px;
  border-top: 1px solid var(--gxw-border); background: var(--gxw-header); flex-shrink: 0;
}
#gxw-root .gxw-input {
  flex: 1; min-width: 0; padding: 11px 16px; border-radius: 999px;
  background: var(--gxw-input-bg); border: 1px solid var(--gxw-border);
  color: var(--gxw-text); font-size: 16px; /* ≥16px stops iOS Safari zooming on focus */
  font-family: inherit; outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}
#gxw-root .gxw-input::placeholder { color: var(--gxw-muted); }
#gxw-root .gxw-input:focus { border-color: var(--gxw-accent); box-shadow: 0 0 0 3px rgba(215,173,84,0.1); }
#gxw-root .gxw-send {
  width: 44px; height: 44px; flex-shrink: 0; border: none; border-radius: 999px; cursor: pointer;
  background: linear-gradient(150deg, var(--gxw-accent2), var(--gxw-accent));
  color: var(--gxw-ink); display: grid; place-items: center;
  transition: transform 0.15s, opacity 0.2s, box-shadow 0.15s;
}
#gxw-root .gxw-send:hover { transform: translateY(-1px) scale(1.04); box-shadow: 0 5px 16px rgba(0,0,0,0.2); }
#gxw-root .gxw-send:active { transform: scale(0.95); }
#gxw-root .gxw-send:disabled { opacity: 0.4; cursor: default; transform: none; box-shadow: none; }
#gxw-root .gxw-send svg { width: 17px; height: 17px; }

#gxw-root .gxw-footer { text-align: center; font-size: 10.5px; color: var(--gxw-muted); padding: 0 0 8px; letter-spacing: 0.02em; opacity: 0.7; }
#gxw-root .gxw-footer a { color: var(--gxw-muted); text-decoration: none; }

/* ── Mobile ── */
@media (max-width: 480px) {
  #gxw-root {
    right: 0; bottom: 0; width: 100vw; max-width: 100vw;
    height: 100svh; max-height: 100svh; border-radius: 0;
  }
  #gxw-root::before { border-radius: 0; }
  /* keep the input clear of the iPhone home indicator */
  #gxw-root .gxw-input-wrap { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  #gxw-root .gxw-footer { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px) / 2); }
  /* comfortable 40px+ touch targets */
  #gxw-root .gxw-icon-btn { width: 40px; height: 40px; }
  #gxw-fab {
    right: 18px;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    width: 56px; height: 56px;
  }
  #gxw-teaser {
    right: 16px; left: 16px; max-width: none;
    bottom: calc(18px + 56px + 14px + env(safe-area-inset-bottom, 0px));
  }
}
