/* MERCURE — website assistant (bubble + panel). Prompt F, phase 2b.
   Self-contained component styles. Consumes the site's design tokens
   (--navy, --blue, --bg, --text, --surface, --line, --shadow-*, --wa, …)
   so light/dark are a variable swap, exactly like the rest of the site.
   Everything is namespaced .mcb-* / #mercure-chatbot to avoid collisions.
   Owned by Worker F. Integrated via one <link> (see HANDOFF-CHATBOT.md). */

#mercure-chatbot,
#mercure-chatbot * { box-sizing: border-box; }

#mercure-chatbot {
  --mcb-size: 64px;            /* bubble diameter (desktop) */
  --mcb-glow: rgba(23,105,170,.45);
  --mcb-panel-w: 380px;
  --mcb-panel-h: 560px;
  position: fixed;
  inset: 0;
  pointer-events: none;        /* the wrapper never blocks the page */
  z-index: 2147483000;         /* above the mobile bottom bar */
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- bubble */
.mcb-bubble {
  pointer-events: auto;
  position: absolute;
  top: 0; left: 0;             /* JS drives translate() for position */
  width: var(--mcb-size);
  height: var(--mcb-size);
  border: none;
  border-radius: 50%;
  cursor: grab;
  padding: 0;
  display: grid;
  place-items: center;
  color: #fff;
  background: radial-gradient(120% 120% at 30% 25%, #2E7CBF 0%, var(--navy) 78%);
  box-shadow:
    0 6px 18px rgba(11,45,77,.34),
    0 2px 6px rgba(11,45,77,.28),
    inset 0 1px 0 rgba(255,255,255,.18);
  touch-action: none;         /* we handle pointer/touch ourselves */
  -webkit-tap-highlight-color: transparent;
  transition: transform .18s cubic-bezier(.34,1.4,.5,1), box-shadow .2s ease;
  will-change: transform;
}
.mcb-bubble:active { cursor: grabbing; }
.mcb-bubble.mcb-dragging { transition: none; }
.mcb-bubble:hover { box-shadow:
    0 10px 26px rgba(11,45,77,.40),
    0 3px 8px rgba(11,45,77,.30),
    inset 0 1px 0 rgba(255,255,255,.22); }
.mcb-bubble:focus-visible {
  outline: 3px solid var(--focus-ring, rgba(23,105,170,.55));
  outline-offset: 3px;
}

/* soft animated aura — the "spark" of intelligence */
.mcb-bubble::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--mcb-glow) 0%, transparent 68%);
  opacity: .55;
  z-index: -1;
  animation: mcb-pulse 3.2s ease-in-out infinite;
}
@keyframes mcb-pulse {
  0%, 100% { transform: scale(1);    opacity: .40; }
  50%      { transform: scale(1.28); opacity: .70; }
}
.mcb-bubble .mcb-ic { width: 30px; height: 30px; display: block; }
/* tiny unread dot for the first-open nudge */
.mcb-bubble .mcb-dot {
  position: absolute; top: 8px; right: 8px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--amber, #D69A2D);
  border: 2px solid var(--navy);
  box-shadow: 0 0 0 2px rgba(11,45,77,.35);
}
.mcb-bubble.mcb-seen .mcb-dot { display: none; }

/* ----------------------------------------------------------------- panel */
.mcb-panel {
  pointer-events: auto;
  position: absolute;
  top: 0; left: 0;             /* JS positions via left/top inline */
  width: var(--mcb-panel-w);
  max-width: calc(100vw - 24px);
  height: var(--mcb-panel-h);
  max-height: calc(100dvh - 24px);
  display: flex;
  flex-direction: column;
  background: var(--surface, #fff);
  color: var(--text, #17212B);
  border: 1px solid var(--line, #DFE7EE);
  border-radius: var(--radius-lg, 20px);
  box-shadow: var(--shadow-lg, 0 8px 24px rgba(11,45,77,.14), 0 24px 64px rgba(11,45,77,.16));
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(10px) scale(.96);
  transition: opacity .18s ease, transform .2s cubic-bezier(.34,1.3,.5,1);
  visibility: hidden;
}
.mcb-panel.mcb-open { opacity: 1; transform: translateY(0) scale(1); visibility: visible; }

/* header */
.mcb-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 14px 16px;
  background: linear-gradient(120deg, var(--navy) 0%, var(--blue-dark, #125685) 100%);
  color: #fff;
  flex: 0 0 auto;
}
.mcb-head .mcb-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; flex: 0 0 auto;
  background: rgba(255,255,255,.14);
}
.mcb-head .mcb-avatar svg { width: 20px; height: 20px; }
.mcb-head .mcb-titles { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.mcb-head .mcb-title { font-weight: 700; font-size: 15px; }
.mcb-head .mcb-sub { font-size: 12px; color: #C8DAEA; display: flex; align-items: center; gap: 5px; }
.mcb-head .mcb-sub::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: #43BD82; box-shadow: 0 0 0 3px rgba(67,189,130,.25);
}
.mcb-head .mcb-spacer { flex: 1 1 auto; }
.mcb-hbtn {
  width: 40px; height: 40px; border: none; border-radius: 10px;
  background: transparent; color: #EAF4FC; cursor: pointer;
  display: grid; place-items: center; flex: 0 0 auto;
}
.mcb-hbtn:hover { background: rgba(255,255,255,.12); }
.mcb-hbtn:focus-visible { outline: 2px solid #EAF4FC; outline-offset: 1px; }
.mcb-hbtn svg { width: 20px; height: 20px; }
.mcb-hbtn.mcb-voice-off .mcb-ic-on { display: none; }
.mcb-hbtn:not(.mcb-voice-off) .mcb-ic-off { display: none; }

/* messages */
.mcb-log {
  flex: 1 1 auto; overflow-y: auto; padding: 16px 14px 6px;
  display: flex; flex-direction: column; gap: 12px;
  background: var(--bg, #fff);
  scroll-behavior: smooth;
}
.mcb-msg { display: flex; gap: 8px; max-width: 100%; animation: mcb-in .22s ease; }
@keyframes mcb-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.mcb-msg.mcb-bot { align-self: flex-start; }
.mcb-msg.mcb-user { align-self: flex-end; }
.mcb-bubble-msg {
  padding: 10px 13px; border-radius: 15px; font-size: 14px; line-height: 1.5;
  max-width: 280px; word-wrap: break-word; overflow-wrap: anywhere;
}
.mcb-bot .mcb-bubble-msg {
  background: var(--surface-alt, #F6F7F8);
  color: var(--text, #17212B);
  border: 1px solid var(--line, #DFE7EE);
  border-bottom-left-radius: 5px;
}
.mcb-user .mcb-bubble-msg {
  background: var(--btn-primary-bg, #1769AA);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.mcb-bubble-msg a { color: inherit; text-decoration: underline; }
.mcb-bot .mcb-bubble-msg a { color: var(--link, #1769AA); }
.mcb-bubble-msg p { margin: 0 0 6px; }
.mcb-bubble-msg p:last-child { margin-bottom: 0; }
.mcb-bubble-msg ul { margin: 6px 0; padding-left: 18px; }

/* typing indicator */
.mcb-typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }
.mcb-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted, #4B5A68);
  opacity: .5; animation: mcb-blink 1.2s infinite ease-in-out;
}
.mcb-typing span:nth-child(2) { animation-delay: .18s; }
.mcb-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes mcb-blink { 0%,80%,100% { transform: scale(.7); opacity: .35; } 40% { transform: scale(1); opacity: .9; } }

/* product result cards */
.mcb-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.mcb-card {
  display: flex; gap: 10px; align-items: center;
  padding: 8px; border: 1px solid var(--line, #DFE7EE); border-radius: 12px;
  background: var(--surface, #fff);
}
.mcb-card img {
  width: 46px; height: 46px; border-radius: 8px; object-fit: cover; flex: 0 0 auto;
  background: var(--surface-alt, #F6F7F8); border: 1px solid var(--line, #DFE7EE);
}
.mcb-card .mcb-cbody { flex: 1 1 auto; min-width: 0; }
.mcb-card .mcb-cname {
  font-size: 13px; font-weight: 600; color: var(--heading, #0B2D4D);
  display: block; line-height: 1.3;
}
.mcb-card .mcb-cprice { font-size: 13px; font-weight: 700; color: var(--text, #17212B); }
.mcb-card .mcb-onreq {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  color: var(--wa, #1E9E5A);
}
.mcb-card .mcb-onreq svg { width: 14px; height: 14px; }
.mcb-card .mcb-cact { display: flex; flex-direction: column; gap: 5px; flex: 0 0 auto; }
.mcb-mini {
  min-height: 34px; padding: 0 10px; border-radius: 8px; font-size: 12px; font-weight: 600;
  cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid transparent; text-decoration: none; justify-content: center;
}
.mcb-mini.mcb-add { background: var(--btn-primary-bg, #1769AA); color: #fff; border: none; }
.mcb-mini.mcb-add:hover { background: var(--btn-primary-hover, #125685); }
.mcb-mini.mcb-add.mcb-added { background: var(--wa, #1E9E5A); }
.mcb-mini.mcb-view { background: transparent; color: var(--link, #1769AA); border-color: var(--ghost-border, rgba(23,105,170,.45)); }
.mcb-mini.mcb-view:hover { background: var(--ghost-hover-bg, rgba(23,105,170,.07)); }
.mcb-mini:focus-visible { outline: 2px solid var(--focus-ring, rgba(23,105,170,.5)); outline-offset: 1px; }

/* quick-reply chips + inline action buttons */
.mcb-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.mcb-chip {
  border: 1px solid var(--ghost-border, rgba(23,105,170,.45));
  background: var(--surface, #fff); color: var(--link, #1769AA);
  border-radius: 999px; padding: 7px 13px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; min-height: 34px; font-family: inherit;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.mcb-chip:hover { background: var(--ghost-hover-bg, rgba(23,105,170,.07)); }
.mcb-chip:focus-visible { outline: 2px solid var(--focus-ring, rgba(23,105,170,.5)); outline-offset: 1px; }
.mcb-chip.mcb-wa { border-color: rgba(37,211,102,.5); color: var(--wa, #1E9E5A); }
.mcb-chip.mcb-wa svg { width: 15px; height: 15px; }

/* input row */
.mcb-foot {
  flex: 0 0 auto; padding: 10px 12px; border-top: 1px solid var(--line, #DFE7EE);
  background: var(--surface, #fff);
}
.mcb-inputrow { display: flex; align-items: flex-end; gap: 8px; }
.mcb-field {
  flex: 1 1 auto; display: flex; align-items: center;
  background: var(--field-bg, #fff); border: 1.5px solid var(--line, #DFE7EE);
  border-radius: 12px; padding: 2px 4px 2px 12px;
}
.mcb-field:focus-within { border-color: var(--blue, #1769AA); box-shadow: 0 0 0 3px var(--field-focus-ring, rgba(23,105,170,.14)); }
.mcb-input {
  flex: 1 1 auto; border: none; background: transparent; outline: none;
  font-family: inherit; font-size: 14px; color: var(--text, #17212B);
  padding: 9px 4px; resize: none; max-height: 96px; line-height: 1.4;
}
.mcb-input::placeholder { color: var(--text-muted, #4B5A68); opacity: .8; }
.mcb-iconbtn {
  width: 38px; height: 38px; flex: 0 0 auto; border: none; border-radius: 10px;
  background: transparent; color: var(--text-muted, #4B5A68); cursor: pointer;
  display: grid; place-items: center;
}
.mcb-iconbtn:hover { background: var(--surface-alt, #F6F7F8); color: var(--blue, #1769AA); }
.mcb-iconbtn:focus-visible { outline: 2px solid var(--focus-ring, rgba(23,105,170,.5)); outline-offset: 1px; }
.mcb-iconbtn svg { width: 20px; height: 20px; }
.mcb-mic.mcb-listening { color: #fff; background: var(--error, #C0392B); animation: mcb-mic 1.1s infinite; }
@keyframes mcb-mic { 0%,100% { box-shadow: 0 0 0 0 rgba(192,57,43,.5); } 50% { box-shadow: 0 0 0 7px rgba(192,57,43,0); } }
.mcb-send { background: var(--btn-primary-bg, #1769AA); color: #fff; }
.mcb-send:hover { background: var(--btn-primary-hover, #125685); color: #fff; }
.mcb-send[disabled] { opacity: .45; cursor: default; }
.mcb-foot-note {
  text-align: center; font-size: 10.5px; color: var(--text-muted, #4B5A68);
  margin: 7px 2px 0; opacity: .8;
}

/* -------------------------------------------------------- mobile: sheet */
@media (max-width: 560px) {
  #mercure-chatbot { --mcb-size: 56px; }
  .mcb-panel.mcb-sheet {
    left: 0 !important; top: auto !important; right: 0; bottom: 0;
    width: 100vw; max-width: 100vw; height: 86dvh; max-height: 86dvh;
    border-radius: 18px 18px 0 0; transform-origin: bottom center;
  }
  .mcb-bubble-msg { max-width: 76vw; }
}

/* --------------------------------------------------- reduced motion a11y */
@media (prefers-reduced-motion: reduce) {
  .mcb-bubble::before { animation: none; }
  .mcb-bubble, .mcb-panel, .mcb-msg, .mcb-mic.mcb-listening { transition: none; animation: none; }
  .mcb-typing span { animation: none; opacity: .6; }
}

/* dark-theme micro-tuning (tokens already flip; a couple of on-brand nudges) */
html[data-theme="dark"] #mercure-chatbot {
  --mcb-glow: rgba(46,124,191,.45);
}
html[data-theme="dark"] .mcb-bubble {
  background: radial-gradient(120% 120% at 30% 25%, #2E7CBF 0%, #0A2B49 82%);
}
