/* Factory Ops assistant — site-matched chatbot widget */
.fo-chat {
  --fo-beige: #F5F6F7;
  --fo-white: #FFFFFF;
  --fo-ink: #161616;
  --fo-black: #111111;
  --fo-muted: #3F3F3F;
  --fo-blue: #1D4ED8;
  --fo-blue-soft: #60A5FA;
  --fo-gold: #D9A93B;
  --fo-line: rgba(17, 17, 17, 0.16);
  --fo-grid: rgba(17, 17, 17, 0.08);
  --fo-face: #50A8E0;
  --fo-mouth: 0;
  --fo-shadow: 3px 3px 0 #111111;
  position: fixed;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 160;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  font-family: "Space Grotesk", sans-serif;
  color: var(--fo-ink);
  pointer-events: none;
}

body:has(.is-fs-open) .fo-chat {
  visibility: hidden;
  pointer-events: none;
}

.fo-chat * { box-sizing: border-box; }

.fo-chat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Robot head (raster mascot + overlaid jaw) ---- */
.fo-bot-head {
  position: relative;
  display: block;
  width: 64px;
  height: calc(64px * 267 / 276);
  flex-shrink: 0;
  transform-origin: 50% 70%;
  animation: fo-bot-bob 3.4s ease-in-out infinite;
  will-change: transform;
}

.fo-bot-body {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

/* Hide the baked-in smile so the jaw can open */
.fo-bot-mouth-cover {
  position: absolute;
  left: 37.2%;
  top: 66.6%;
  width: 25.6%;
  height: 13.2%;
  background: #000;
  border-radius: 50%;
  pointer-events: none;
}

.fo-bot-mouth {
  position: absolute;
  left: 39.49%;
  top: 68.54%;
  width: 19.93%;
  height: 8.99%;
  transform-origin: 50% 12%;
  transform: scaleY(calc(1 + var(--fo-mouth, 0) * 2.4));
  pointer-events: none;
}

.fo-bot-lip {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--fo-face);
  border-radius: 50% 50% 50% 50% / 28% 28% 90% 90%;
}

.fo-bot-cavity {
  position: absolute;
  left: 18%;
  right: 18%;
  top: 22%;
  bottom: 10%;
  background: #0A0A0A;
  border-radius: 50%;
  opacity: var(--fo-mouth, 0);
  transform: scaleY(calc(0.2 + var(--fo-mouth, 0) * 0.95));
  transform-origin: 50% 0%;
}

.fo-bot-lid {
  position: absolute;
  top: 46.82%;
  width: 26.45%;
  height: 15.36%;
  background: #000;
  border-radius: 50% 50% 40% 40% / 80% 80% 60% 60%;
  transform: scaleY(0);
  transform-origin: 50% 0%;
  pointer-events: none;
}

.fo-bot-lid-l { left: 17.03%; }
.fo-bot-lid-r { left: 55.43%; }

.fo-bot-head.is-blinking .fo-bot-lid {
  transform: scaleY(1);
}

@keyframes fo-bot-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

/* ---- Launcher ---- */
.fo-chat-launcher {
  pointer-events: auto;
  width: 72px;
  height: 72px;
  padding: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--fo-beige);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='48' height='48'><path d='M0 0.5 H48' stroke='rgba(17,17,17,0.08)' stroke-width='1' stroke-dasharray='1.5 6' fill='none'/><path d='M0.5 0 V48' stroke='rgba(17,17,17,0.08)' stroke-width='1' stroke-dasharray='1.5 6' fill='none'/></svg>");
  background-size: 48px 48px;
  border: 1px solid var(--fo-black);
  border-radius: 2px;
  box-shadow: var(--fo-shadow);
  cursor: pointer;
  color: inherit;
}

.fo-chat-launcher:hover { filter: brightness(1.03); }
.fo-chat-launcher:focus-visible,
.fo-chat-iconbtn:focus-visible,
.fo-chat-send:focus-visible,
.fo-chat-input:focus-visible,
.fo-chat-chip:focus-visible {
  outline: 2px solid var(--fo-blue);
  outline-offset: 2px;
}

.fo-chat-launcher .fo-bot-head {
  width: 60px;
  height: calc(60px * 267 / 276);
}


/* ---- Panel ---- */
.fo-chat-panel {
  pointer-events: auto;
  width: min(380px, calc(100vw - 32px));
  max-height: min(560px, calc(100dvh - var(--nav-h, 88px) - 100px));
  display: flex;
  flex-direction: column;
  background-color: var(--fo-beige);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='48' height='48'><path d='M0 0.5 H48' stroke='rgba(17,17,17,0.08)' stroke-width='1' stroke-dasharray='1.5 6' fill='none'/><path d='M0.5 0 V48' stroke='rgba(17,17,17,0.08)' stroke-width='1' stroke-dasharray='1.5 6' fill='none'/></svg>");
  background-size: 48px 48px;
  border: 1px solid var(--fo-black);
  border-radius: 2px;
  box-shadow: var(--fo-shadow);
  overflow: hidden;
}

.fo-chat-panel[hidden] { display: none; }

.fo-chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 8px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--fo-line);
}

.fo-chat-header .fo-bot-head {
  width: 52px;
  height: calc(52px * 267 / 276);
}

.fo-chat-heading {
  flex: 1;
  min-width: 0;
}

.fo-chat-kicker {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fo-muted);
  margin: 0 0 2px;
}

.fo-chat-title {
  font-family: "Archivo Black", sans-serif;
  font-weight: 400;
  font-size: 15px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: -0.04em;
  color: var(--fo-black);
  margin: 0;
}

.fo-chat-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.fo-chat-iconbtn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--fo-white);
  color: var(--fo-black);
  border: 1px solid var(--fo-black);
  border-radius: 2px;
  cursor: pointer;
  padding: 0;
}

.fo-chat-iconbtn:hover { background: var(--fo-beige); }

.fo-chat-iconbtn[aria-pressed="true"] {
  background: var(--fo-black);
  color: var(--fo-beige);
}

.fo-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 180px;
}

.fo-chat-bubble {
  max-width: 92%;
  padding: 10px 12px;
  border: 1px solid var(--fo-black);
  border-radius: 2px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--fo-ink);
}

.fo-chat-bubble a {
  color: var(--fo-blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.fo-chat-bubble.is-bot {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 3px 3px 0 rgba(17, 17, 17, 0.06);
}

.fo-chat-bubble.is-user {
  align-self: flex-end;
  background: var(--fo-gold);
  color: var(--fo-black);
  font-weight: 500;
}

.fo-chat-bubble.is-typing {
  color: var(--fo-muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  letter-spacing: 0.08em;
}

.fo-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 4px;
}

.fo-chat-chip {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--fo-black);
  border-radius: 2px;
  padding: 6px 9px;
  background: var(--fo-white);
  color: var(--fo-black);
  line-height: 1;
  cursor: pointer;
}

.fo-chat-chip:hover { background: var(--fo-blue-soft); }

.fo-chat-composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--fo-line);
  background: rgba(255, 255, 255, 0.86);
}

.fo-chat-input {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  background: var(--fo-white);
  color: var(--fo-ink);
  border: 1px solid var(--fo-black);
  border-radius: 2px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 14px;
}

.fo-chat-input::placeholder { color: #8A8A85; }

.fo-chat-send {
  height: 36px;
  padding: 0 14px;
  background: var(--fo-gold);
  color: var(--fo-black);
  border: 1px solid var(--fo-black);
  border-radius: 2px;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.fo-chat-send:hover { filter: brightness(1.03); }
.fo-chat-send:disabled { opacity: 0.55; cursor: default; filter: none; }

@media (max-width: 430px) {
  .fo-chat {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
  }
  .fo-chat-panel {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - var(--nav-h, 92px) - 92px);
  }
  .fo-chat-launcher {
    width: 64px;
    height: 64px;
  }
  .fo-chat-launcher .fo-bot-head {
    width: 54px;
    height: calc(54px * 267 / 276);
  }
}

@media (prefers-reduced-motion: reduce) {
  .fo-bot-head { animation: none; }
  .fo-bot-mouth,
  .fo-bot-cavity,
  .fo-bot-lid {
    transition: none;
  }
  .fo-bot-head.is-blinking .fo-bot-lid { transform: scaleY(0); }
}
