/* ================================================================
   CHATBOT.CSS
     1. Robot   the 3D assistant: staged in the hero, docked in the
                corner, or in flight between the two
     2. Chat window
   Colour tokens come from the compatibility shim at the end of :root
   in main.css (--clr-*), plus the Bone & Ink tokens themselves.
   ================================================================ */

/* Dock geometry. chatbot.js reads both values from :root to work out
   where a flight to the corner should land, so keep them in px. */
:root {
  --dock-size: 132px;
  --dock-gap: 20px;
}
@media (max-width: 480px) {
  :root { --dock-size: 92px; --dock-gap: 12px; }
}

/* ================================================================
   1. ROBOT
   #cb-robot is a single element that chatbot.js moves between states:
     .is-staged   inside #stageSlot in the hero, standing on the plinth
     .is-docked   fixed bottom-right, the chat launcher
     .is-transit  fixed at 0,0 and positioned by an inline transform
                  while it flies between the two
   plus .is-ready once the model has loaded, and .is-chat while the
   chat window is open.
   ================================================================ */
#cb-robot {
  position: fixed;
  z-index: 10001;
  cursor: pointer;
  overflow: visible;
  -webkit-tap-highlight-color: transparent;
}
#cb-robot.is-docked {
  right: var(--dock-gap);
  bottom: var(--dock-gap);
  width: var(--dock-size);
  height: var(--dock-size);
}
/* Inside .stage-slot, which sets the size and creates the stacking
   context, so the staged robot scrolls under the fixed nav. */
#cb-robot.is-staged {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: auto;
}
#cb-robot.is-transit {
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
  pointer-events: none;
}
#cb-robot:focus-visible {
  outline: 2px solid var(--signal-deep, #C2410C);
  outline-offset: 2px;
  border-radius: var(--r-sm, 4px);
}

.robot-inner {
  position: absolute;
  inset: 0;
}

/* The canvas is 113.1% of the box, centred, and chatbot.js sizes the
   drawing buffer from whatever this renders at. At that ratio the
   model's feet land 13.25% up from the box's bottom edge, which is
   what .stage-slot in main.css and the ground shadow below rely on.
   Change the percentage and both of those drift. */
#robotCanvas {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 113.1%;
  height: 113.1%;
  transform: translate(-50%, -50%);
  display: block;
  pointer-events: none;
  opacity: 0;
  transition: opacity .6s ease;
}
#cb-robot.is-ready #robotCanvas { opacity: 1; }

/* ---- Ground shadow ----
   --sh-x / --sh-scale / --sh-alpha are written every frame by
   chatbot.js from the model's own position, so the shadow cannot drift
   away from the feet. z-index -1 keeps it behind the canvas. No
   rotation, deliberately: a shadow on the ground does not tilt when
   the robot above it banks. */
#cb-robot::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 10%;
  width: 38%;
  height: 8%;
  transform: translateX(-50%)
             translateX(var(--sh-x, 0px))
             scale(var(--sh-scale, 1));
  background: radial-gradient(ellipse at center,
              rgba(11, 11, 11, var(--sh-alpha, .18)) 0%,
              rgba(11, 11, 11, calc(var(--sh-alpha, .18) * .55)) 38%,
              transparent 70%);
  filter: blur(1.5px);
  pointer-events: none;
  z-index: -1;
  opacity: 0;
  transition: opacity .6s ease;
}
#cb-robot.is-ready::after { opacity: 1; }

/* ---- Notification badge (docked only) ---- */
#cb-badge {
  position: absolute;
  top: 8%;
  right: 22%;
  z-index: 3;
  width: 22px;
  height: 22px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--signal, #E8541F);
  border: 2px solid var(--paper, #FAF8F5);
  box-shadow: 0 2px 8px rgba(232, 84, 31, .38);
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  color: #FFFFFF;
}
/* chatbot.js adds .hidden once the chat has been opened. */
#cb-robot.is-docked.is-ready #cb-badge:not(.hidden) {
  display: flex;
  animation: badge-pop .4s cubic-bezier(.34, 1.56, .64, 1) both;
}
@keyframes badge-pop { from { transform: scale(0); } to { transform: scale(1); } }

/* ---- Close button (docked, chat open) ---- */
.robot-close-x {
  position: absolute;
  top: 4%;
  right: 12%;
  z-index: 5;
  width: 26px;
  height: 26px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--ink, #0B0B0B);
  cursor: pointer;
  transition: background .2s ease;
}
.robot-close-x svg { width: 14px; height: 14px; fill: #FAF8F5; }
.robot-close-x:hover { background: var(--signal-deep, #C2410C); }
#cb-robot.is-docked.is-chat .robot-close-x { display: flex; }

/* ---- Speech bubble ----
   Staged: centred above the head, inside the stage, so it can never
   land on the hero copy. Docked: to the left of the head. Hidden in
   flight and while the chat is open (chatbot.js removes .show). */
.robot-speech {
  position: absolute;
  z-index: 4;
  width: max-content;
  max-width: 240px;
  padding: 10px 14px;
  background: var(--band, #111110);
  color: #FAF8F5;
  border-radius: 4px;
  box-shadow: 0 6px 22px rgba(11, 11, 11, .22);
  font-family: var(--font-body);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.45;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s ease, transform .45s cubic-bezier(.34, 1.56, .64, 1);
}
.robot-speech::after {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  background: inherit;
  transform: rotate(45deg);
}
#cb-robot.is-staged .robot-speech {
  left: 50%;
  bottom: 89%;
  text-align: center;
  transform-origin: 50% 100%;
  transform: translate(-50%, 8px) scale(.96);
}
#cb-robot.is-staged .robot-speech.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
#cb-robot.is-staged .robot-speech::after { left: calc(50% - 5px); bottom: -5px; }

#cb-robot.is-docked .robot-speech {
  right: 86%;
  top: 12%;
  transform-origin: 100% 50%;
  transform: translateX(8px) scale(.96);
}
#cb-robot.is-docked .robot-speech.show { opacity: 1; transform: none; }
#cb-robot.is-docked .robot-speech::after { right: -5px; top: calc(50% - 5px); }
#cb-robot.is-transit .robot-speech { display: none; }

/* ---- No WebGL ----
   chatbot.js adds .no-3d when a renderer cannot be created. The box
   becomes a plain round launcher so the chat is still reachable. */
#cb-robot.no-3d #robotCanvas,
#cb-robot.no-3d::after { display: none; }
#cb-robot.no-3d.is-docked .robot-inner {
  inset: 20%;
  border-radius: 50%;
  background: var(--ink, #0B0B0B) no-repeat center / 44%
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23FAF8F5' d='M4 4h16v12H7l-3 3z'/%3E%3C/svg%3E");
  box-shadow: 0 6px 20px rgba(11, 11, 11, .22);
}
#cb-robot.no-3d.is-staged { display: none; }

/* The mobile menu is a full-screen overlay; the launcher must not float
   on top of it. main.js sets .menu-open on <body>. */
body.menu-open #cb-robot { display: none; }

/* Staged on a phone, the robot stands in a narrow column beside the
   headline — there is nowhere to put a 240px bubble that does not cover
   the headline or run off the screen. The plinth caption labels it
   there instead; the bubble speaks once it docks to the corner. */
@media (max-width: 768px) {
  /* Staged on a phone, the label goes BELOW the robot, in the same slot
     as the plinth caption — above it would cover the "See our work"
     button. chatbot.js hides the caption while a line is showing, so the
     two never stack (see .is-speaking in main.css). */
  /* The label lives in the slot the stage reserves under the robot, and
     is RIGHT-aligned: the robot's column is far narrower than a label, so
     the card extends left into the empty space below the headline's short
     last line instead of overflowing the screen. */
  #cb-robot.is-staged .robot-speech {
    top: calc(100% + 12px);
    bottom: auto;
    left: auto;
    right: 0;
    max-width: min(250px, 76vw);
    text-align: left;
    transform-origin: 100% 0;
    transform: translate(0, -6px) scale(.96);
    /* While a line is showing it covers the caption's slot, so it has to
       be tappable itself — it is inside #cb-robot, so the tap opens the
       chat like tapping the robot does. */
    pointer-events: auto;
  }
  #cb-robot.is-staged .robot-speech.show { transform: translate(0, 0) scale(1); }
  /* Tail points up at the robot, which sits half its own width from the
     card's right edge. Top-left edges are the visible ones. */
  #cb-robot.is-staged .robot-speech::after {
    top: -5px;
    bottom: auto;
    left: auto;
    right: calc(var(--stage-robot, 140px) / 2 - 5px);
    border-top: 1px solid var(--rule-strong, rgba(11, 11, 11, .26));
    border-left: 1px solid var(--rule-strong, rgba(11, 11, 11, .26));
  }

  /* Blended, not shouted: a paper card with ink text and a hairline,
     matching the chips and cards on the page. Ink on paper is 18.8:1,
     so this reads better than the near-black box it replaces. */
  .robot-speech {
    background: var(--paper, #FAF8F5);
    color: var(--ink, #0B0B0B);
    border: 1px solid var(--rule-strong, rgba(11, 11, 11, .26));
    box-shadow: 0 4px 16px rgba(11, 11, 11, .12);
  }
  /* The tail inherits the fill; it needs the hairline on the two edges
     that actually show — for the docked bubble, its top and right. */
  #cb-robot.is-docked .robot-speech::after {
    border-top: 1px solid var(--rule-strong, rgba(11, 11, 11, .26));
    border-right: 1px solid var(--rule-strong, rgba(11, 11, 11, .26));
  }
}

@media (prefers-reduced-motion: reduce) {
  #robotCanvas,
  #cb-robot::after,
  .robot-speech { transition: opacity .2s ease; }
  #cb-robot.is-docked.is-ready #cb-badge:not(.hidden) { animation: none; }
}

/* ================================================================
   2. CHAT WINDOW
   The base rules were written for the old near-black theme; the
   "Bone & Ink" overrides after them retarget the surfaces. Later
   source order wins at equal specificity.
   ================================================================ */

/* Chat container */
#cb-container {
  position: fixed;
  bottom: 102px;
  right: 28px;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: rgba(13, 13, 32, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: var(--radius);
  border: 1px solid rgba(124, 58, 237, 0.35);
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.7),
              0 0 60px rgba(124, 58, 237, 0.15),
              inset 0 1px 0 rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 10002;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
#cb-container.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

.cb-header {
  background: linear-gradient(135deg, rgba(24, 24, 56, 0.95), rgba(30, 30, 68, 0.95));
  padding: 16px 18px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid rgba(124, 58, 237, 0.2);
  flex-shrink: 0;
}
.cb-header-close {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.5);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s ease;
}
.cb-header-close:hover {
  background: rgba(255, 71, 87, 0.2);
  border-color: rgba(255, 71, 87, 0.4);
  color: #FF4757;
}
.cb-header-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-accent));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; position: relative;
}
.cb-header-avatar svg { width: 20px; height: 20px; fill: white; }
.cb-header-avatar::after {
  content: '';
  position: absolute; bottom: 1px; right: 1px;
  width: 10px; height: 10px;
  background: var(--clr-accent);
  border-radius: 50%;
  border: 2px solid var(--clr-surface);
}
.cb-header-info { flex: 1; }
.cb-header-name {
  font-family: var(--font-primary);
  font-size: 14px; font-weight: 700; color: var(--clr-text);
}
.cb-header-status {
  font-size: 12px; color: var(--clr-accent);
  display: flex; align-items: center; gap: 5px; margin-top: 1px;
}
.cb-status-dot {
  width: 6px; height: 6px;
  background: var(--clr-accent);
  border-radius: 50%;
  animation: cb-status 1.5s infinite;
}
@keyframes cb-status {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.cb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.cb-messages::-webkit-scrollbar { width: 4px; }
.cb-messages::-webkit-scrollbar-track { background: transparent; }
.cb-messages::-webkit-scrollbar-thumb { background: var(--clr-text-muted); border-radius: 10px; }

.cb-msg {
  display: flex; gap: 8px; max-width: 88%;
  animation: cb-msg-in 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
@keyframes cb-msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.cb-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.cb-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
}
.cb-msg.bot .cb-msg-avatar {
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-primary-light));
}
.cb-msg.bot .cb-msg-avatar svg { width: 14px; height: 14px; fill: white; }
.cb-msg.user .cb-msg-avatar {
  background: rgba(255,255,255,0.06);
}
.cb-msg.user .cb-msg-avatar svg { width: 14px; height: 14px; fill: var(--clr-text-3); }

.cb-bubble {
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 13.5px; line-height: 1.55;
}
.cb-msg.bot .cb-bubble {
  background: rgba(19, 19, 43, 0.8);
  color: var(--clr-text);
  border-radius: 4px 14px 14px 14px;
  border: 1px solid rgba(124, 58, 237, 0.12);
}
.cb-msg.user .cb-bubble {
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-primary-light));
  color: white;
  border-radius: 14px 4px 14px 14px;
}
.cb-time {
  font-size: 10px; color: var(--clr-text-muted);
  margin-top: 4px;
}
.cb-msg.user .cb-time { text-align: right; }

.cb-typing {
  display: flex; gap: 8px; max-width: 85%;
  animation: cb-msg-in 0.3s ease;
}
.cb-typing .cb-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-primary-light));
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.cb-typing .cb-msg-avatar svg { width: 14px; height: 14px; fill: white; }
.cb-dots {
  background: var(--clr-surface);
  border-radius: 4px 14px 14px 14px;
  border: 1px solid rgba(255,255,255,0.04);
  padding: 12px 18px;
  display: flex; align-items: center; gap: 5px;
}
.cb-dots span {
  width: 6px; height: 6px;
  background: var(--clr-text-muted);
  border-radius: 50%;
  animation: cb-dot 1.4s infinite ease-in-out;
}
.cb-dots span:nth-child(2) { animation-delay: 0.16s; }
.cb-dots span:nth-child(3) { animation-delay: 0.32s; }
@keyframes cb-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.cb-quick {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 14px 8px; flex-shrink: 0;
}
.cb-quick-btn {
  padding: 7px 14px;
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid rgba(124, 58, 237, 0.2);
  border-radius: 18px;
  color: var(--clr-primary-light);
  font-family: var(--font-body);
  font-size: 12px; cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
}
.cb-quick-btn:hover {
  background: rgba(124, 58, 237, 0.2);
  border-color: var(--clr-primary-light);
}

.cb-input-area {
  padding: 12px 14px;
  background: rgba(19, 19, 43, 0.6);
  border-top: 1px solid rgba(124, 58, 237, 0.15);
  display: flex; gap: 8px; align-items: flex-end;
  flex-shrink: 0;
}
.cb-input-wrap {
  flex: 1;
  background: var(--clr-bg-3);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 10px;
  padding: 0 12px;
  display: flex; align-items: center;
  transition: var(--transition-fast);
}
.cb-input-wrap:focus-within {
  border-color: var(--clr-primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}
#cb-input {
  flex: 1; border: none; background: none;
  color: var(--clr-text);
  font-family: var(--font-body);
  font-size: 13.5px; padding: 11px 0;
  outline: none; resize: none;
  max-height: 80px; line-height: 1.4;
}
#cb-input::placeholder { color: var(--clr-text-muted); }

/* Required-but-empty state. The textarea has no <form> owner, so `required`
   is never enforced by the browser — chatbot.js toggles this class instead. */
/* Split from the :has() rules below on purpose — a selector list containing an
   unsupported selector is dropped whole, which would take the shake with it. */
#cb-input.cb-input-error {
  animation: cb-input-shake 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}
.cb-input-wrap:has(#cb-input.cb-input-error) {
  border-color: var(--clr-error, #FF4757);
  background: rgba(255, 71, 87, 0.1);
  box-shadow: 0 0 0 3px rgba(255, 71, 87, 0.15);
}
#cb-input.cb-input-error::placeholder {
  color: var(--clr-error-light, #FF6B81);
  opacity: 0.9;
}
@keyframes cb-input-shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}
@media (prefers-reduced-motion: reduce) {
  #cb-input.cb-input-error { animation: none; }
}
#cb-send {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--clr-primary), var(--clr-primary-light));
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition); flex-shrink: 0;
}
#cb-send:hover { transform: scale(1.05); box-shadow: 0 4px 16px rgba(124, 58, 237, 0.4); }
#cb-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
#cb-send svg { width: 16px; height: 16px; fill: white; }

.cb-footer {
  text-align: center; padding: 6px;
  background: rgba(19, 19, 43, 0.6);
  font-size: 11px; color: var(--clr-text-3);
  font-family: var(--font-body);
  border-top: 1px solid rgba(124, 58, 237, 0.08);
  flex-shrink: 0;
}
/* --clr-primary (deep orange) not --clr-primary-light: the bright signal
   is 3.4:1 on paper, under the floor for text this size. */
.cb-footer span { color: var(--clr-primary); }

/* ---- Chat window ---- */
#cb-container {
  background: #FFFFFF;
  border: 1px solid rgba(11, 11, 11, .16);
  box-shadow: 0 24px 64px rgba(11, 11, 11, .22);
}
.cb-header {
  background: var(--band, #111110);
  border-bottom-color: rgba(250, 248, 245, .14);
}
.cb-header-name { color: #FAF8F5; }
.cb-header-status { color: rgba(250, 248, 245, .62); }
.cb-header-close { background: rgba(250, 248, 245, .1); color: #FAF8F5; }
/* border-color was left on the retired red (rgba(255,71,87,.4)) by the
   base rule — the background and text were overridden here but the
   border was not, so a red hairline flashed on hover. */
.cb-header-close:hover {
  background: rgba(232, 84, 31, .3);
  border-color: rgba(232, 84, 31, .5);
  color: #FFFFFF;
}

.cb-messages { background: #FAF8F5; }
.cb-msg.bot .cb-bubble {
  background: #FFFFFF;
  border: 1px solid rgba(11, 11, 11, .12);
  color: #0B0B0B;
}
.cb-msg.user .cb-bubble { background: var(--clr-primary, #C2410C); color: #FFFFFF; }
.cb-msg.user .cb-msg-avatar { background: rgba(11, 11, 11, .1); color: #0B0B0B; }

.cb-quick { background: #FAF8F5; }
.cb-quick-btn {
  background: rgba(194, 65, 12, .07);
  border-color: rgba(194, 65, 12, .26);
  color: #3A3A38;
}
.cb-quick-btn:hover { background: rgba(194, 65, 12, .16); color: #0B0B0B; }

.cb-input-area {
  background: #FFFFFF;
  border-top: 1px solid rgba(11, 11, 11, .12);
}
.cb-input-wrap {
  background: #FAF8F5;
  border-color: rgba(11, 11, 11, .16);
}
.cb-input-wrap:has(#cb-input.cb-input-error) {
  background: rgba(232, 84, 31, .09);
  border-color: #C2410C;
  box-shadow: 0 0 0 3px rgba(232, 84, 31, .16);
}
.cb-footer {
  background: #FAF8F5;
  border-top-color: rgba(11, 11, 11, .1);
}

/* Two purple focus/hover glows the overrides above missed. */
.cb-input-wrap:focus-within {
  border-color: var(--signal-deep, #C2410C);
  box-shadow: 0 0 0 3px rgba(232, 84, 31, .14);
}
#cb-send:hover { box-shadow: 0 4px 14px rgba(194, 65, 12, .35); }

/* Sit the window above the docked robot rather than on top of it.
   responsive.css makes it fullscreen at 480px and below. */
#cb-container {
  right: var(--dock-gap);
  bottom: calc(var(--dock-gap) + var(--dock-size) + 8px);
  max-height: calc(100vh - var(--dock-size) - var(--dock-gap) * 2 - 40px);
}
