/**
 * Excel Man Helper Bot - floating widget
 *
 * Palette is taken from the live theme (#388E3C primary, #2E7D32 dark,
 * #e8f5e9 tint) so the bubble reads as part of the site rather than a
 * bolted-on third-party chat. Everything is namespaced .emhb-* and scoped
 * under #emhb-root; the theme ships broad !important rules, so a few
 * declarations here are defensive rather than decorative.
 */

.emhb-root {
  --emhb-green: #388E3C;
  --emhb-green-dark: #2E7D32;
  --emhb-green-deep: #1B5E20;
  --emhb-tint: #e8f5e9;
  --emhb-ink: #1f2a1f;
  --emhb-muted: #6b7a6b;
  --emhb-line: #e4efe4;
  --emhb-radius: 20px;
  --emhb-shadow: 0 18px 50px rgba(16, 48, 20, 0.18), 0 4px 14px rgba(16, 48, 20, 0.08);

  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 99998;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  /* The wrapper must not eat clicks on the page behind it. */
  pointer-events: none;
}

.emhb-root > * {
  pointer-events: auto;
}

.emhb-root *,
.emhb-root *::before,
.emhb-root *::after {
  box-sizing: border-box;
}

/* ─── Greeting bubble ──────────────────────────────────────────────── */

.emhb-greet {
  position: relative;
  max-width: 232px;
  background: #fff;
  color: var(--emhb-ink);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.5;
  padding: 12px 30px 12px 15px;
  border: 1px solid var(--emhb-line);
  border-radius: 16px 16px 5px 16px;
  box-shadow: var(--emhb-shadow);
  opacity: 0;
  transform: translateY(8px) scale(0.94);
  transform-origin: bottom right;
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  pointer-events: none;
}

.emhb-greet.is-in {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Little tail pointing at the launcher. */
.emhb-greet::after {
  content: '';
  position: absolute;
  right: 18px;
  bottom: -7px;
  width: 13px;
  height: 13px;
  background: #fff;
  border-right: 1px solid var(--emhb-line);
  border-bottom: 1px solid var(--emhb-line);
  transform: rotate(45deg);
  border-bottom-right-radius: 3px;
}

.emhb-greet-text::after {
  /* Typing caret while the greeting types itself out. */
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  background: var(--emhb-green);
  vertical-align: -2px;
  animation: emhb-caret 0.9s step-end infinite;
}

.emhb-greet.is-typed .emhb-greet-text::after {
  display: none;
}

@keyframes emhb-caret {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.emhb-greet-close {
  position: absolute;
  top: 5px;
  right: 6px;
  width: 20px;
  height: 20px;
  border: none;
  background: transparent;
  color: #9aa89a;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  padding: 0;
}

.emhb-greet-close:hover {
  background: var(--emhb-tint);
  color: var(--emhb-green-dark);
}

/* ─── Launcher ─────────────────────────────────────────────────────── */

.emhb-launcher {
  position: relative;
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  background: linear-gradient(145deg, #43a047, var(--emhb-green-dark));
  box-shadow: 0 12px 30px rgba(56, 142, 60, 0.42), 0 2px 8px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.3), box-shadow 0.28s ease;
  /* Gentle idle bob so the bot reads as alive without being distracting. */
  animation: emhb-bob 3.6s ease-in-out infinite;
}

.emhb-launcher:hover {
  transform: scale(1.07);
  box-shadow: 0 16px 38px rgba(56, 142, 60, 0.52), 0 3px 10px rgba(0, 0, 0, 0.14);
}

.emhb-launcher:active {
  transform: scale(0.97);
}

.emhb-launcher:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

@keyframes emhb-bob {
  0%, 100% { translate: 0 0; }
  50% { translate: 0 -5px; }
}

/* Expanding ring to draw the eye before first interaction. */
.emhb-launcher-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(56, 142, 60, 0.55);
  animation: emhb-pulse 2.4s ease-out infinite;
  pointer-events: none;
}

@keyframes emhb-pulse {
  0% { transform: scale(1); opacity: 0.75; }
  70% { transform: scale(1.55); opacity: 0; }
  100% { transform: scale(1.55); opacity: 0; }
}

/* Once the panel has been opened the attention-grabbers stop. */
.emhb-root[data-open="true"] .emhb-launcher-pulse,
.emhb-root[data-engaged="true"] .emhb-launcher-pulse {
  display: none;
}

.emhb-root[data-open="true"] .emhb-launcher {
  animation: none;
}

/* ─── The robot face ──────────────────────────────────────────────── */

.emhb-bot {
  position: relative;
  display: block;
  width: 38px;
  height: 34px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.emhb-bot-antenna {
  position: absolute;
  top: -7px;
  left: 50%;
  translate: -50% 0;
  width: 2px;
  height: 7px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 2px;
}

.emhb-bot-antenna i {
  position: absolute;
  top: -4px;
  left: 50%;
  translate: -50% 0;
  width: 5px;
  height: 5px;
  background: #ffd54f;
  border-radius: 50%;
  box-shadow: 0 0 7px #ffd54f;
  animation: emhb-blip 1.7s ease-in-out infinite;
}

@keyframes emhb-blip {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.emhb-bot-head {
  position: absolute;
  inset: 0;
  background: #fff;
  border-radius: 11px;
  display: grid;
  place-items: center;
  gap: 0;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.06);
}

.emhb-bot-eyes {
  display: flex;
  gap: 9px;
  margin-top: 2px;
}

/* The blinking eyes. scaleY collapses the pupil to a closed lid; the long
   pause between blinks is what keeps it feeling natural rather than frantic. */
.emhb-eye {
  width: 6px;
  height: 6px;
  background: var(--emhb-green-dark);
  border-radius: 50%;
  transform-origin: center;
  animation: emhb-blink 4s infinite;
}

.emhb-eye:nth-child(2) {
  /* A hair of delay reads as two eyes, not one shutter. */
  animation-delay: 0.06s;
}

@keyframes emhb-blink {
  0%, 92%, 100% { transform: scaleY(1); }
  94%, 97% { transform: scaleY(0.12); }
}

.emhb-bot-mouth {
  width: 11px;
  height: 5px;
  margin-top: 3px;
  border: 1.6px solid var(--emhb-green-dark);
  border-top: none;
  border-radius: 0 0 9px 9px;
}

/* Small variant used in the panel header. */
.emhb-bot--sm {
  width: 30px;
  height: 27px;
}

.emhb-bot--sm .emhb-bot-eyes {
  gap: 7px;
}

.emhb-bot--sm .emhb-eye {
  width: 5px;
  height: 5px;
}

.emhb-bot--sm .emhb-bot-mouth {
  width: 9px;
  height: 4px;
}

/* Swap bot face for an X when open. */
.emhb-launcher-close {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
  transition: opacity 0.22s ease, transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

.emhb-root[data-open="true"] .emhb-launcher-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

/* Scope the hide-on-open to the LAUNCHER's face only. Unscoped, this matched
   every .emhb-bot on the page - so opening the panel also shrank the header
   avatar and the welcome robot to 60% and faded them out. */
.emhb-root[data-open="true"] .emhb-launcher .emhb-bot {
  opacity: 0;
  transform: scale(0.6);
}

/* ─── Panel ───────────────────────────────────────────────────────── */

.emhb-panel {
  width: 392px;
  max-width: calc(100vw - 32px);
  height: 596px;
  max-height: calc(100vh - 128px);
  background: #fff;
  border: 1px solid var(--emhb-line);
  border-radius: var(--emhb-radius);
  box-shadow: var(--emhb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  animation: emhb-pop 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.emhb-panel[hidden] {
  display: none;
}

@keyframes emhb-pop {
  from { opacity: 0; transform: translateY(14px) scale(0.93); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Header */
.emhb-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 13px 13px 15px;
  background: linear-gradient(135deg, var(--emhb-green), var(--emhb-green-deep));
  color: #fff;
  flex-shrink: 0;
}

.emhb-head-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.emhb-head-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  margin-right: auto;
  min-width: 0;
}

.emhb-head-meta strong {
  font-size: 14.5px;
  font-weight: 600;
  color: #fff;
}

.emhb-head-meta em {
  font-style: normal;
  font-size: 11.5px;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.82);
  display: flex;
  align-items: center;
  gap: 5px;
}

.emhb-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8bf58b;
  box-shadow: 0 0 6px #8bf58b;
  animation: emhb-blip 2s ease-in-out infinite;
}

.emhb-head-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.18s ease;
}

.emhb-head-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* Message log */
.emhb-log {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 15px 8px;
  background: #fbfdfb;
  display: flex;
  flex-direction: column;
  gap: 11px;
  scrollbar-width: thin;
  scrollbar-color: #c9dcc9 transparent;
}

.emhb-log::-webkit-scrollbar { width: 7px; }
.emhb-log::-webkit-scrollbar-thumb {
  background: #cfe0cf;
  border-radius: 99px;
}

/* Rows + bubbles */
.emhb-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: emhb-rise 0.26s ease both;
}

@keyframes emhb-rise {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

.emhb-row--me {
  flex-direction: row-reverse;
}

.emhb-ava {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  background: var(--emhb-tint);
  color: var(--emhb-green-dark);
  font-size: 11px;
  font-weight: 700;
}

.emhb-bubble {
  max-width: 79%;
  padding: 10px 13px;
  border-radius: 15px;
  font-size: 13.8px;
  line-height: 1.62;
  color: var(--emhb-ink);
  background: #fff;
  border: 1px solid var(--emhb-line);
  border-bottom-left-radius: 5px;
  overflow-wrap: break-word;
  word-break: break-word;
}

.emhb-row--me .emhb-bubble {
  background: linear-gradient(135deg, var(--emhb-green), var(--emhb-green-dark));
  border-color: transparent;
  color: #fff;
  border-bottom-left-radius: 15px;
  border-bottom-right-radius: 5px;
}

/* Markdown inside a bubble */
.emhb-bubble > *:first-child { margin-top: 0; }
.emhb-bubble > *:last-child { margin-bottom: 0; }

.emhb-bubble p { margin: 0 0 8px; }

.emhb-bubble h1,
.emhb-bubble h2,
.emhb-bubble h3 {
  font-size: 14.5px;
  font-weight: 600;
  margin: 12px 0 6px;
  color: var(--emhb-green-deep);
  line-height: 1.35;
}

.emhb-bubble ul,
.emhb-bubble ol {
  margin: 0 0 8px;
  padding-left: 19px;
}

.emhb-bubble li { margin: 3px 0; }

.emhb-bubble a {
  color: var(--emhb-green-dark);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.emhb-row--me .emhb-bubble a { color: #fff; }

.emhb-bubble code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
  font-size: 12.2px;
  background: var(--emhb-tint);
  color: var(--emhb-green-deep);
  padding: 1px 5px;
  border-radius: 5px;
}

.emhb-bubble pre {
  margin: 8px 0;
  padding: 11px 12px;
  background: #14261a;
  border-radius: 11px;
  overflow-x: auto;
}

.emhb-bubble pre code {
  background: none;
  color: #c8f0c8;
  font-size: 12.2px;
  padding: 0;
  white-space: pre;
}

.emhb-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 12.5px;
}

.emhb-bubble th,
.emhb-bubble td {
  border: 1px solid var(--emhb-line);
  padding: 5px 8px;
  text-align: left;
}

.emhb-bubble th {
  background: var(--emhb-tint);
  font-weight: 600;
}

.emhb-bubble blockquote {
  margin: 8px 0;
  padding: 2px 0 2px 11px;
  border-left: 3px solid var(--emhb-green);
  color: var(--emhb-muted);
}

/* Typing indicator */
.emhb-typing {
  display: inline-flex;
  gap: 4px;
  padding: 3px 0;
}

.emhb-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9dbb9d;
  animation: emhb-typing 1.3s ease-in-out infinite;
}

.emhb-typing i:nth-child(2) { animation-delay: 0.18s; }
.emhb-typing i:nth-child(3) { animation-delay: 0.36s; }

@keyframes emhb-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.emhb-cursor {
  display: inline-block;
  width: 2px;
  height: 0.95em;
  background: var(--emhb-green);
  vertical-align: -2px;
  animation: emhb-caret 0.9s step-end infinite;
}

.emhb-err {
  color: #c62828;
  font-size: 13px;
}

/* Welcome block */
.emhb-welcome {
  text-align: center;
  padding: 16px 10px 6px;
  color: var(--emhb-muted);
}

.emhb-welcome-bot {
  width: 62px;
  height: 62px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: linear-gradient(145deg, #43a047, var(--emhb-green-dark));
  display: grid;
  place-items: center;
  box-shadow: 0 10px 24px rgba(56, 142, 60, 0.32);
}

.emhb-welcome h4 {
  margin: 0 0 5px;
  font-size: 16px;
  font-weight: 600;
  color: var(--emhb-ink);
}

.emhb-welcome p {
  margin: 0;
  font-size: 12.8px;
  line-height: 1.6;
}

/* Suggestion chips */
.emhb-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 9px 15px 11px;
  background: #fbfdfb;
  flex-shrink: 0;
}

.emhb-chips:empty { display: none; }

.emhb-chip {
  border: 1px solid #cfe4cf;
  background: #fff;
  color: var(--emhb-green-dark);
  font-family: inherit;
  font-size: 12.2px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.emhb-chip:hover {
  background: var(--emhb-tint);
  border-color: var(--emhb-green);
  transform: translateY(-1px);
}

/* Composer */
.emhb-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 11px 12px;
  border-top: 1px solid var(--emhb-line);
  background: #fff;
  flex-shrink: 0;
}

.emhb-form textarea {
  flex: 1 1 auto;
  border: 1.5px solid var(--emhb-line);
  border-radius: 14px;
  padding: 10px 13px;
  font-family: inherit;
  font-size: 13.8px;
  line-height: 1.5;
  color: var(--emhb-ink);
  background: #fbfdfb;
  resize: none;
  max-height: 104px;
  overflow-y: auto;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.emhb-form textarea:focus {
  outline: none;
  border-color: var(--emhb-green);
  background: #fff;
}

.emhb-form textarea::placeholder { color: #9aa89a; }

#emhb-send {
  width: 41px;
  height: 41px;
  flex-shrink: 0;
  border: none;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--emhb-green), var(--emhb-green-dark));
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

#emhb-send:hover:not(:disabled) { transform: scale(1.06); }

#emhb-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.emhb-foot {
  margin: 0;
  padding: 0 14px 10px;
  font-size: 10.5px;
  line-height: 1.4;
  color: #a2b0a2;
  text-align: center;
  background: #fff;
  flex-shrink: 0;
}

/* ─── Responsive ──────────────────────────────────────────────────── */

@media (max-width: 560px) {
  .emhb-root {
    right: 14px;
    bottom: 14px;
    left: 14px;
    align-items: flex-end;
  }

  .emhb-panel {
    width: 100%;
    /* dvh so the panel is not hidden behind mobile browser chrome. */
    height: 78dvh;
    max-height: 78dvh;
  }

  .emhb-launcher {
    width: 58px;
    height: 58px;
  }

  .emhb-greet { max-width: 210px; }

  .emhb-bubble { max-width: 84%; }
}

/* Respect users who ask for less motion: keep the UI, drop the looping
   animation (including the blinking, which is the whole point but also the
   most likely thing to bother someone motion-sensitive). */
@media (prefers-reduced-motion: reduce) {
  .emhb-root *,
  .emhb-root *::before,
  .emhb-root *::after {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── Robot sizing hardening ───────────────────────────────────────────
 * The bot face is a <span> inside a display:grid parent, so the grid was
 * sizing it from content (measured 23x20 and 18x16 instead of the declared
 * 38x34 / 30x27) and the face came out too small to read. Pin the box on
 * both axes and opt out of grid stretching so the declared size wins
 * regardless of what the theme contributes.
 */
.emhb-root .emhb-bot {
  width: 38px !important;
  height: 34px !important;
  min-width: 38px;
  min-height: 34px;
  flex: 0 0 auto;
  place-self: center;
}

.emhb-root .emhb-bot--sm {
  width: 30px !important;
  height: 27px !important;
  min-width: 30px;
  min-height: 27px;
}

/* Welcome circle carries a larger face than the launcher. */
.emhb-welcome-bot .emhb-bot {
  width: 40px !important;
  height: 36px !important;
  min-width: 40px;
  min-height: 36px;
}

/* The head fills its bot box; eyes and mouth keep explicit sizes so no
   inherited font-size or line-height can collapse them. */
.emhb-root .emhb-bot-head {
  position: absolute !important;
  inset: 0 !important;
  width: auto;
  height: auto;
}

.emhb-root .emhb-eye {
  width: 6px !important;
  height: 6px !important;
  min-width: 6px;
  min-height: 6px;
  border-radius: 50% !important;
  flex: 0 0 auto;
}

.emhb-root .emhb-bot--sm .emhb-eye {
  width: 5px !important;
  height: 5px !important;
  min-width: 5px;
  min-height: 5px;
}

.emhb-root .emhb-bot-mouth {
  width: 11px !important;
  height: 5px !important;
  min-width: 11px;
  flex: 0 0 auto;
}

.emhb-root .emhb-bot--sm .emhb-bot-mouth {
  width: 9px !important;
  height: 4px !important;
  min-width: 9px;
}

/* Keep the greeting text and its emoji on one line. */
.emhb-greet-text {
  display: inline;
  white-space: normal;
}

.emhb-greet {
  max-width: 250px;
}

/* ─── Assistant row avatar ────────────────────────────────────────── */
/* The bot face needs a disc behind it, otherwise it reads as a stray
   graphic sitting next to the bubble rather than an avatar. */
.emhb-ava--bot {
  background: linear-gradient(145deg, #43a047, var(--emhb-green-dark)) !important;
  box-shadow: 0 2px 7px rgba(56, 142, 60, 0.3);
}

/* Shrink the face to fit the 27px disc. */
.emhb-ava--bot .emhb-bot {
  width: 20px !important;
  height: 18px !important;
  min-width: 20px;
  min-height: 18px;
}

.emhb-ava--bot .emhb-bot-head {
  border-radius: 7px;
}

.emhb-ava--bot .emhb-eye {
  width: 3.5px !important;
  height: 3.5px !important;
  min-width: 3.5px;
  min-height: 3.5px;
}

.emhb-ava--bot .emhb-bot-eyes {
  gap: 5px;
  margin-top: 1px;
}

.emhb-ava--bot .emhb-bot-mouth {
  width: 6px !important;
  height: 3px !important;
  min-width: 6px;
  margin-top: 2px;
  border-width: 1.2px;
}
