/* ═══════════════════════════════════════════════════════════════════
   AI assistant widget — launcher, panel, chat, fit report.
   Loaded on every page, after styles.css so it inherits the sky tokens
   (--violet, --card, --rule …) and follows the theme toggle for free.
   Only the surfaces the widget adds are defined here; nothing above is
   overridden.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --ai-bubble:      #eef6fd;  /* assistant bubble — a shade lighter than --card
                                 so a bubble on a card still reads as separate */
  --ai-bubble-text: #1f4d6b;
  --ai-surface:     #ffffff;
  --ai-shadow:      0 2px 6px rgba(31,41,51,.06), 0 24px 48px -20px rgba(31,41,51,.34);
  --ai-good:        #2f7d4f;
  --ai-warn:        #b4671a;
  --ai-bad:         #c2405f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ai-bubble:      #2c3a49;
    --ai-bubble-text: #dce7f2;
    --ai-surface:     #232f3d;
    --ai-shadow:      0 2px 6px rgba(0,0,0,.3), 0 24px 48px -20px rgba(0,0,0,.7);
    --ai-good:        #7ec898;
    --ai-warn:        #e0a765;
    --ai-bad:         #ff8fa8;
  }
}
:root[data-theme="dark"] {
  --ai-bubble:      #2c3a49;
  --ai-bubble-text: #dce7f2;
  --ai-surface:     #232f3d;
  --ai-shadow:      0 2px 6px rgba(0,0,0,.3), 0 24px 48px -20px rgba(0,0,0,.7);
  --ai-good:        #7ec898;
  --ai-warn:        #e0a765;
  --ai-bad:         #ff8fa8;
}

/* An inline text button that reads as a link — used in body copy to open the
   panel. A real <button>, because it performs an action rather than navigating,
   and a link to nowhere would be a lie to a keyboard or screen-reader user. */
.linkish {
  border: 0; padding: 0; background: none; cursor: pointer;
  font: inherit; color: var(--violet); font-weight: 600;
  text-decoration: underline; text-underline-offset: 2px;
  text-decoration-thickness: 1.5px;
}
.linkish:hover { color: var(--pink); }

/* ── launcher ───────────────────────────────────────────────────── */

.ai-launcher {
  position: fixed; right: 22px; bottom: 22px; z-index: 70;
  display: inline-flex; align-items: center; gap: 9px;
  padding: 11px 17px 11px 14px; border: 0; border-radius: 999px;
  font-family: var(--sans); font-size: 14.5px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, #6d28d9, #8b5cf6);
  box-shadow: 0 10px 26px -10px rgba(109,40,217,.68), 0 2px 6px rgba(31,41,51,.16);
  cursor: pointer; transition: transform .16s, box-shadow .16s, opacity .2s;
}
.ai-launcher:hover { transform: translateY(-2px);
  box-shadow: 0 16px 32px -12px rgba(109,40,217,.78), 0 2px 6px rgba(31,41,51,.18); }
.ai-launcher:active { transform: translateY(0); }
.ai-launcher svg { width: 19px; height: 19px; flex: none; }
.ai-launcher .ai-kbd {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  padding: 2px 5px; border-radius: 5px; background: rgba(255,255,255,.2);
}
/* The panel replaces the launcher rather than sitting behind it. */
.ai-open .ai-launcher { opacity: 0; pointer-events: none; transform: translateY(8px); }

/* A live dot, because a chat launcher that looks decorative gets ignored. */
.ai-launcher .ai-dot {
  width: 7px; height: 7px; border-radius: 50%; background: #7ee0a8; flex: none;
  box-shadow: 0 0 0 0 rgba(126,224,168,.7); animation: ai-pulse 2.6s infinite;
}
@keyframes ai-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(126,224,168,.65); }
  70%  { box-shadow: 0 0 0 7px rgba(126,224,168,0); }
  100% { box-shadow: 0 0 0 0 rgba(126,224,168,0); }
}

/* ── panel ──────────────────────────────────────────────────────── */

.ai-panel {
  position: fixed; right: 22px; bottom: 22px; z-index: 71;
  width: 404px; max-width: calc(100vw - 32px);
  height: min(648px, calc(100vh - 44px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--ai-surface); border: 1px solid var(--rule);
  border-radius: 18px; box-shadow: var(--ai-shadow);
  transform-origin: bottom right;
  transition: opacity .18s ease, transform .18s ease;
}
.ai-panel[hidden] { display: none; }
.ai-panel.ai-enter { opacity: 0; transform: translateY(10px) scale(.98); }

.ai-head {
  display: flex; align-items: center; gap: 10px; padding: 13px 14px;
  border-bottom: 1px solid var(--rule); background: var(--page-alt); flex: none;
}
.ai-head .ai-mark { width: 32px; height: 32px; border-radius: 9px; flex: none; }
.ai-head .ai-who { min-width: 0; flex: 1; }
.ai-head h2 {
  margin: 0; font-family: var(--display); font-size: 15px; font-weight: 700;
  color: var(--text); letter-spacing: -.01em;
}
.ai-head .ai-sub {
  margin: 1px 0 0; font-family: var(--mono); font-size: 10.5px;
  color: var(--text-muted); white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
}
.ai-head .ai-x {
  width: 30px; height: 30px; flex: none; display: inline-flex;
  align-items: center; justify-content: center; border: 0; border-radius: 50%;
  background: transparent; color: var(--text-muted); cursor: pointer;
}
.ai-head .ai-x:hover { background: var(--card); color: var(--text); }
.ai-head .ai-x svg { width: 16px; height: 16px; }

/* ── log ────────────────────────────────────────────────────────── */

.ai-log {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 16px 14px; display: flex; flex-direction: column; gap: 11px;
  scrollbar-width: thin;
}
/* The log is a column flex container, so its children default to shrinking to
   fit rather than overflowing it — which silently squashed the fit report to a
   fraction of its height and clipped everything past the role heading. Children
   keep their natural size and the container scrolls, which is the whole idea. */
.ai-log > * { flex: 0 0 auto; }

.ai-log::-webkit-scrollbar { width: 9px; }
.ai-log::-webkit-scrollbar-thumb {
  background: var(--card-border); border-radius: 9px;
  border: 3px solid var(--ai-surface);
}

.ai-msg {
  max-width: 89%; padding: 10px 13px; font-size: 14.5px; line-height: 1.55;
  border-radius: 15px; word-wrap: break-word; overflow-wrap: anywhere;
}
.ai-msg.user {
  align-self: flex-end; background: var(--violet); color: #fff;
  border-bottom-right-radius: 5px;
}
:root[data-theme="dark"] .ai-msg.user,
:root:not([data-theme="light"]) .ai-msg.user { color: #1b1230; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .ai-msg.user { color: #fff; }
}
.ai-msg.bot {
  align-self: flex-start; background: var(--ai-bubble); color: var(--ai-bubble-text);
  border-bottom-left-radius: 5px;
}
.ai-msg p { margin: 0 0 8px; }
.ai-msg p:last-child { margin-bottom: 0; }
.ai-msg ul { margin: 6px 0; padding-left: 18px; }
.ai-msg li { margin: 3px 0; }
.ai-msg code {
  font-family: var(--mono); font-size: 12.5px; padding: 1px 5px;
  border-radius: 5px; background: rgba(31,77,107,.12);
}
.ai-msg a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.ai-msg.err { background: transparent; border: 1px dashed var(--card-border);
  color: var(--text-body); font-size: 13.5px; }

/* Streaming caret: the answer is arriving, and it says so without a spinner. */
.ai-caret {
  display: inline-block; width: 7px; height: 15px; margin-left: 1px;
  vertical-align: -2px; background: currentColor; opacity: .55;
  animation: ai-blink 1s steps(2, start) infinite;
}
@keyframes ai-blink { 50% { opacity: 0; } }

/* Waiting for the first token. Three dots, no library. */
.ai-think { display: inline-flex; gap: 4px; align-items: center; padding: 2px 0; }
.ai-think i {
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
  opacity: .35; animation: ai-bounce 1.25s infinite;
}
.ai-think i:nth-child(2) { animation-delay: .15s; }
.ai-think i:nth-child(3) { animation-delay: .3s; }
@keyframes ai-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .3; }
  30%           { transform: translateY(-4px); opacity: .75; }
}

/* ── suggestion chips ───────────────────────────────────────────── */

.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; align-self: flex-start; }
.ai-chip {
  font-family: var(--sans); font-size: 12.5px; font-weight: 500;
  padding: 7px 12px; border-radius: 999px; cursor: pointer;
  color: var(--text-body); background: transparent;
  border: 1px solid var(--card-border); transition: background .14s, color .14s, transform .14s;
}
.ai-chip:hover { background: var(--card); color: var(--blue-deep); transform: translateY(-1px); }
.ai-chip.ai-chip-fit { border-color: var(--violet); color: var(--violet); font-weight: 600; }

/* ── action cards ───────────────────────────────────────────────── */

.ai-acts { display: flex; flex-direction: column; gap: 6px; align-self: stretch; }
.ai-act {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--card-border); border-radius: 12px;
  background: var(--page-alt); color: var(--text); text-decoration: none;
  font-size: 13.5px; font-weight: 600; transition: transform .14s, border-color .14s;
}
.ai-act:hover { transform: translateX(2px); border-color: var(--violet); }
.ai-act svg { width: 15px; height: 15px; flex: none; color: var(--violet); }
.ai-act .ai-act-go { margin-left: auto; color: var(--text-muted); }

.ai-contact {
  align-self: stretch; padding: 12px; border-radius: 12px;
  border: 1px solid var(--card-border); background: var(--card);
}
.ai-contact p { margin: 0 0 9px; font-size: 13px; color: var(--blue-deep); line-height: 1.5; }
:root[data-theme="dark"] .ai-contact p,
:root:not([data-theme="light"]) .ai-contact p { color: var(--ai-bubble-text); }
.ai-contact .ai-row { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.ai-contact a.ai-mail {
  font-family: var(--mono); font-size: 12.5px; font-weight: 600;
  color: var(--violet); text-decoration: none; word-break: break-all;
}
.ai-contact a.ai-mail:hover { text-decoration: underline; }
.ai-mini {
  font-family: var(--sans); font-size: 11.5px; font-weight: 700; letter-spacing: .02em;
  padding: 5px 10px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--card-border); background: var(--ai-surface); color: var(--text-body);
}
.ai-mini:hover { border-color: var(--violet); color: var(--violet); }

.ai-sources {
  align-self: flex-start; display: flex; flex-wrap: wrap; gap: 5px;
  font-family: var(--mono); font-size: 10.5px; color: var(--text-muted);
}
.ai-sources a { color: var(--text-muted); text-decoration: none;
  border-bottom: 1px dotted var(--card-border); }
.ai-sources a:hover { color: var(--violet); }

/* ── fit report ─────────────────────────────────────────────────── */

.ai-report {
  align-self: stretch; border: 1px solid var(--card-border); border-radius: 14px;
  background: var(--page-alt); overflow: hidden;
}
.ai-report .ai-rhead { padding: 13px 14px 12px; border-bottom: 1px solid var(--rule); }
.ai-report .ai-role {
  margin: 0 0 8px; font-family: var(--display); font-size: 14.5px; font-weight: 700;
  color: var(--text); line-height: 1.3;
}
.ai-verdict {
  display: inline-block; font-family: var(--sans); font-size: 11px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase; padding: 4px 9px;
  border-radius: 999px; background: var(--card); color: var(--blue-deep);
}
.ai-verdict.good { background: rgba(47,125,79,.14); color: var(--ai-good); }
.ai-verdict.mid  { background: rgba(180,103,26,.14); color: var(--ai-warn); }
.ai-verdict.low  { background: rgba(194,64,95,.14);  color: var(--ai-bad); }

.ai-meter {
  display: flex; align-items: center; gap: 9px; margin-top: 11px;
  font-family: var(--mono); font-size: 11.5px; color: var(--text-muted);
}
.ai-meter .ai-track {
  flex: 1; height: 7px; border-radius: 999px; background: var(--card); overflow: hidden;
}
.ai-meter .ai-fill {
  display: block; height: 100%; border-radius: 999px; width: 0;
  background: linear-gradient(90deg, #8b5cf6, #2f9bd6);
  transition: width .7s cubic-bezier(.2,.8,.2,1);
}

.ai-report .ai-rbody { padding: 12px 14px 14px; }
.ai-report .ai-summary {
  margin: 0 0 12px; font-size: 13.5px; line-height: 1.6; color: var(--text-body);
}
.ai-report h4 {
  margin: 12px 0 6px; font-family: var(--sans); font-size: 11px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted);
}
.ai-report h4:first-child { margin-top: 0; }
.ai-report ul { margin: 0; padding: 0; list-style: none; }
.ai-report li {
  position: relative; padding-left: 17px; margin: 6px 0;
  font-size: 13px; line-height: 1.55; color: var(--text-body);
}
.ai-report li::before {
  position: absolute; left: 0; top: 0; font-family: var(--mono); font-weight: 700;
}
.ai-report .ai-plus li::before  { content: "+"; color: var(--ai-good); }
.ai-report .ai-minus li::before { content: "−"; color: var(--ai-bad); }
.ai-report li b { color: var(--text); font-weight: 600; }
.ai-report li a { color: var(--violet); text-decoration: none; font-size: 12px; }
.ai-report li a:hover { text-decoration: underline; }

.ai-pitch {
  margin-top: 13px; padding: 11px 12px; border-radius: 11px;
  background: var(--card); border: 1px solid var(--card-border);
}
.ai-pitch p {
  margin: 0 0 9px; font-size: 13px; line-height: 1.6; color: var(--blue-deep);
  font-style: italic;
}
:root[data-theme="dark"] .ai-pitch p,
:root:not([data-theme="light"]) .ai-pitch p { color: var(--ai-bubble-text); }

/* ── composer ───────────────────────────────────────────────────── */

.ai-foot { flex: none; border-top: 1px solid var(--rule); background: var(--page-alt); }
.ai-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 11px; }
.ai-form textarea {
  flex: 1; min-height: 40px; max-height: 132px; resize: none;
  padding: 10px 12px; border-radius: 12px; border: 1px solid var(--card-border);
  background: var(--ai-surface); color: var(--text);
  font-family: var(--sans); font-size: 14px; line-height: 1.45;
}
.ai-form textarea::placeholder { color: var(--text-muted); }
.ai-form textarea:focus { outline: 2px solid var(--violet); outline-offset: -1px; border-color: var(--violet); }
.ai-send {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--violet); color: #fff; cursor: pointer;
  transition: opacity .14s, transform .14s;
}
.ai-send:hover:not(:disabled) { transform: translateY(-1px); }
.ai-send:disabled { opacity: .4; cursor: default; }
.ai-send svg { width: 17px; height: 17px; }

/* `display` in a stylesheet outranks the UA rule behind the hidden attribute,
   so this needs saying explicitly — without it the fit-check bar sits above the
   composer during ordinary chat. */
.ai-mode[hidden] { display: none; }
.ai-mode {
  display: flex; align-items: center; gap: 8px; padding: 9px 12px;
  border-bottom: 1px solid var(--rule); font-size: 12.5px; color: var(--text-body);
  background: var(--card);
}
.ai-mode b { font-weight: 700; color: var(--blue-deep); }
:root[data-theme="dark"] .ai-mode b,
:root:not([data-theme="light"]) .ai-mode b { color: var(--ai-bubble-text); }
.ai-mode button { margin-left: auto; }

.ai-note {
  margin: 0; padding: 0 12px 9px; font-family: var(--mono); font-size: 10px;
  line-height: 1.5; color: var(--text-muted); text-align: center;
}
.ai-note b { font-weight: 500; color: var(--text-body); }

/* ── mobile: bottom sheet ───────────────────────────────────────── */

@media (max-width: 560px) {
  .ai-launcher { right: 14px; bottom: 14px; padding: 10px 15px 10px 13px; font-size: 14px; }
  .ai-launcher .ai-kbd { display: none; }
  .ai-panel {
    right: 0; left: 0; bottom: 0; width: auto; max-width: none;
    height: min(88vh, calc(100vh - 48px));
    border-radius: 18px 18px 0 0; border-left: 0; border-right: 0; border-bottom: 0;
    transform-origin: bottom center;
  }
  .ai-msg { max-width: 93%; }
}

/* ── preferences and print ──────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .ai-launcher, .ai-panel, .ai-act, .ai-chip, .ai-send, .ai-meter .ai-fill { transition: none; }
  .ai-launcher .ai-dot, .ai-caret, .ai-think i { animation: none; }
  .ai-panel.ai-enter { transform: none; }
}

@media print {
  .ai-launcher, .ai-panel { display: none !important; }
}
