/* ============================================================
   Mira — the site assistant

   Nothing here introduces a colour, a radius, a font or a motion curve. Every
   value comes from the custom properties at the top of styles.css, and the
   accent is --pc rather than --accent, so the launcher is verdigris on the
   diagnosis page and ochre on cost estimation — the per-product tint the site
   already carries through crumbs, chips and hero rules.
   ============================================================ */

/* ---------- the launcher ---------- */

.mira-launch {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: clamp(16px, 3vw, 28px);
  z-index: 60;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 10px 12px;
  border: 1px solid var(--text);
  border-radius: var(--r);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: 0;
  cursor: pointer;
  box-shadow: 4px 4px 0 rgba(var(--pc-rgb), 0.22);
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.mira-launch:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 rgba(var(--pc-rgb), 0.3);
}
.mira-launch .mira-mark { width: 22px; height: 22px; color: var(--pc); }

/* Open: the launcher is the thing the panel is docked above, so it steps back
   rather than competing with it. On a phone the panel is a full sheet and the
   launcher would be underneath it — hidden outright. */
.mira-launch[aria-expanded="true"] { opacity: 0.55; }

/* ---------- moving the launcher ---------- */
/*
   The launcher is fixed to a corner, so at the bottom of a long page it sits on
   top of the footer — which is now a row of policy links pinned to the same
   right edge it is. mira.js lifts it clear of the footer on scroll, and lets it
   be dragged somewhere else entirely.

   `touch-action` is scoped to the docked viewport because the drag is: below
   761px the panel is a full sheet and the launcher stays where it is, so this
   never takes a swipe away from the page on a phone. */
@media (min-width: 761px) {
  .mira-launch { touch-action: none; cursor: grab; }
}
.mira-launch.mira-moving {
  cursor: grabbing;
  user-select: none;
  /* The hover lift is a 0.3s transform, and leaving it on during a drag makes
     the button lag the pointer by exactly that long. */
  transition: none;
}
/* Same reason, for the panel that follows it. */
.mira-panel.mira-moving { transition: none; animation: none; }

/* ---------- the panel ---------- */

.mira-panel {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: calc(clamp(16px, 3vw, 28px) + 62px);
  z-index: 61;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  max-height: min(640px, 100dvh - 7rem);
  border: 1px solid var(--text);
  border-radius: var(--r);
  background: var(--surface-2);
  box-shadow: 8px 8px 0 rgba(var(--ink-rgb), 0.1);
  overflow: hidden;
  animation: mira-in 0.34s var(--ease);
}
.mira-panel[hidden] { display: none; }

/* ---------- resize grip ---------- */
/*
   Top-left, because the panel is anchored bottom-right: dragging away from the
   anchor grows it and the two edges the reader is dragging are the only two
   that move. `position: absolute` inside the panel rather than a flex child,
   so it sits over the header's corner without taking a row of its own.

   The panel keeps `overflow: hidden`, so this has to stay inside the radius —
   hence the inset rather than a corner-hugging 0,0. */
.mira-resize {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text-mute);
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s, background 0.2s;
  /* The glyph points down-right; the grip lives at the top-left. */
  transform: rotate(90deg);
  touch-action: none;
}
/* Revealed on hover over the panel, and always once focused — a control that
   only appears on hover is one a keyboard never finds. */
.mira-panel:hover .mira-resize,
.mira-resize:focus-visible,
.mira-panel.mira-resizing .mira-resize { opacity: 1; }
.mira-resize:hover,
.mira-panel.mira-resizing .mira-resize { color: var(--pc); background: var(--bg-alt); }
.mira-resize:focus-visible { outline: 2px solid var(--pc); outline-offset: -2px; }

/* While dragging: kill the text selection and the pointer-events chatter the
   drag would otherwise generate inside the thread. */
.mira-panel.mira-resizing { user-select: none; }
.mira-panel.mira-resizing .mira-thread { pointer-events: none; }

@keyframes mira-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to   { opacity: 1; transform: none; }
}

.mira-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 14px 12px 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-alt);
}
.mira-head .mira-mark { width: 26px; height: 26px; color: var(--pc); flex: none; }
.mira-id { flex: 1; min-width: 0; line-height: 1.3; }
.mira-id strong { display: block; font-family: var(--serif); font-size: 1.05rem; font-weight: 600; }
.mira-id span { font-size: 0.76rem; color: var(--text-mute); }

.mira-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: var(--r);
  background: none;
  color: var(--text-mute);
  cursor: pointer;
  transition: color 0.25s, border-color 0.25s, background 0.25s;
}
.mira-icon:hover { color: var(--text); border-color: var(--line); background: var(--surface); }

/* ---------- the thread ---------- */

.mira-thread {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 6px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.mira-empty p { margin: 0 0 14px; color: var(--text-dim); font-size: 0.93rem; }
.mira-suggests { display: flex; flex-direction: column; gap: 8px; }
.mira-suggest {
  text-align: left;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.86rem;
  line-height: 1.45;
  cursor: pointer;
  transition: border-color 0.25s, color 0.25s, transform 0.25s var(--ease);
}
.mira-suggest:hover {
  border-color: var(--pc);
  color: var(--text);
}

/* The visitor's own turn is short and reads as an aside; Mira's reply is prose
   in --text. A two-paragraph grounded answer in a chat bubble looks like a
   text message, which is the wrong register for the thing being demonstrated. */
.mira-q {
  align-self: flex-end;
  max-width: 86%;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.87rem;
  line-height: 1.5;
}

.mira-a { font-size: 0.9rem; line-height: 1.62; color: var(--text); }
.mira-a p { margin: 0 0 0.7em; }
.mira-a p:last-child { margin-bottom: 0; }

/* The streaming caret: a caret rather than a spinner, because a spinner says
   "waiting" and the answer is already arriving. */
.mira-a.streaming::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--pc);
  animation: mira-caret 1.1s steps(2) infinite;
}
@keyframes mira-caret { 50% { opacity: 0; } }

/* ---------- sources ---------- */

.mira-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 11px;
}
.mira-sources a {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.74rem;
  line-height: 1.4;
  transition: border-color 0.25s, color 0.25s;
}
.mira-sources a:hover { border-color: rgba(var(--pc-rgb), 0.45); color: var(--text); }

/* ---------- the abstention state ---------- */

/* Visually distinct because it is the interesting outcome: a buyer who watches
   an AI vendor's assistant refuse to invent a compliance claim has learned more
   about us than a paragraph could tell them, and the next thing under their
   cursor is our address. */
.mira-decline {
  padding: 15px 16px;
  border: 1px solid rgba(var(--pc-rgb), 0.4);
  border-left: 3px solid var(--pc);
  border-radius: var(--r);
  background: rgba(var(--pc-rgb), 0.06);
}
.mira-decline-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  color: var(--pc);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}
.mira-decline .mira-a { color: var(--text-dim); }
.mira-decline .btn { margin-top: 13px; }

/* ---------- the bot check ---------- */

/* A zero-height strip until Turnstile wants a click, then a band above the
   composer. The widget is a fixed-size iframe, so it is centred, not stretched. */
.mira-check {
  display: flex;
  justify-content: center;
  background: var(--surface-2);
}
.mira-check.open {
  padding: 10px 12px 0;
  border-top: 1px solid var(--line);
}

/* ---------- the composer ---------- */

.mira-compose {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 12px 8px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
}
.mira-compose textarea {
  flex: 1;
  max-height: 132px;
  padding: 9px 12px;
  /* SC 1.4.11: --line is 1.19:1 here, which left nothing marking where the
     field was. The focus state below was always fine (3.73:1); it was the
     RESTING state that failed. */
  border: 1px solid var(--line-field);
  border-radius: var(--r);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.88rem;
  line-height: 1.5;
  resize: none;
}
.mira-compose textarea::placeholder { color: var(--text-mute); }
.mira-compose textarea:focus { outline: none; border-color: var(--pc); box-shadow: 0 0 0 1px var(--pc); }

.mira-send {
  flex: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: var(--r);
  background: var(--text);
  color: var(--bg);
  cursor: pointer;
  transition: transform 0.25s var(--ease), opacity 0.25s;
}
.mira-send:hover { background: var(--pc); }
.mira-send:disabled { opacity: 0.4; cursor: default; transform: none; }

.mira-fineprint {
  margin: 0;
  padding: 0 16px 13px;
  background: var(--surface-2);
  color: var(--text-mute);
  font-size: 0.7rem;
  line-height: 1.5;
}
.mira-fineprint a { color: var(--text-dim); border-bottom: 1px solid var(--line); }
.mira-fineprint a:hover { color: var(--text); }

/* ---------- phone ---------- */

/* 760px is where the nav stops being dropdowns; the panel becomes a sheet at
   the same point rather than at a breakpoint of its own. */
@media (max-width: 760px) {
  .mira-panel {
    inset: 0;
    width: 100%;
    max-height: none;
    border: 0;
    border-radius: 0;
  }
  .mira-launch[aria-expanded="true"] { display: none; }
  /* The panel is a full-screen sheet here, so there is nothing to resize —
     and a media query cannot beat the inline width/height the drag writes,
     which is why mira.js clears them below this breakpoint rather than
     relying on this rule to win. */
  .mira-resize { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .mira-panel { animation: none; }
  .mira-a.streaming::after { animation: none; }
}
