/* The AI chat (chat.js): a round button at the bottom right that opens a compact panel; one size larger on request,
   never the whole screen. Colours are the site's own tokens, so dark mode follows. */
/* shaped like the tab you are on (.apptab.on): the page's own background, navy text, the blue line along its top edge,
   with a small sparkle before "AI Search" */
#aic-btn { position: fixed; right: 20px; bottom: 20px; z-index: 60; height: 40px; padding: 0 16px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--accent);
  box-shadow: inset 0 2px 0 var(--accent-2), 0 4px 14px rgba(20, 25, 35, .12);
  display: flex; align-items: center; gap: 7px; font: 600 13.5px/1 var(--sans); white-space: nowrap;
  transition: transform .15s, border-color .15s; }
#aic-btn svg { width: 15px; height: 15px; flex: none; }
/* unavailable (budget spent, or the API refusing): greyed, still opens to say why */
#aic-btn.off { color: var(--ink-3); box-shadow: 0 4px 14px rgba(20, 25, 35, .08); }
#aic-btn.off:hover { border-color: var(--line); transform: none; }
#aic-btn:hover { transform: translateY(-1px); border-color: var(--accent-2); }
@media (prefers-reduced-motion: reduce) { #aic-btn { transition: none; } }
:root[data-theme="dark"] #aic .send { color: #10151f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #aic .send { color: #10151f; } }

#aic { position: fixed; right: 20px; bottom: 20px; z-index: 60; width: min(600px, calc(100vw - 40px)); height: min(760px, calc(100vh - 90px)); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 36px rgba(20, 25, 35, .22);
  font-family: var(--sans); color: var(--ink); overflow: hidden; }
#aic[hidden] { display: none; }
/* the larger size: wider and taller, but always with the page showing around it */
#aic.big { width: min(900px, calc(100vw - 80px)); height: min(1000px, calc(100vh - 60px)); }
@media (max-width: 680px) { #aic, #aic.big { right: 8px; left: 8px; width: auto; bottom: 8px; height: min(560px, calc(100vh - 80px)); } }

#aic header { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
#aic header .ti { font-weight: 650; font-size: 14px; flex: 1; min-width: 0; }
#aic header .ti small { display: block; font-weight: 400; font-size: 11.5px; color: var(--ink-3); }
#aic header button { border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 7px; width: 28px; height: 28px; cursor: pointer; font-size: 14px; line-height: 1; }
#aic header button:hover { color: var(--accent); border-color: var(--accent-2); }
#aic header button.tx { width: auto; padding: 0 6px; font: 600 12px/1 var(--sans); }
#aic header button:disabled { opacity: .4; cursor: default; color: var(--ink-2); border-color: var(--line); }

#aic .msgs { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 14px; display: flex; flex-direction: column; gap: 12px; font-size: 13.5px; line-height: 1.5; }
#aic .hello { color: var(--ink-2); font-size: 13px; }
#aic .hello p { margin: 0 0 8px; }
#aic .hello .eg { display: block; width: 100%; text-align: left; margin: 0 0 6px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2);
  color: var(--ink); font: inherit; font-size: 12.5px; cursor: pointer; }
#aic .hello .eg:hover { border-color: var(--accent-2); }
#aic .q { align-self: flex-end; max-width: 85%; background: var(--accent-soft); color: var(--ink); padding: 8px 11px; border-radius: 12px 12px 3px 12px; white-space: pre-wrap; }
/* the answers' and questions' text at the size chosen in the header (A− / A+); the rest of an answer in proportion */
#aic .q, #aic .a .txt { font-size: var(--aic-text, 13.5px); }
#aic .a h4 { font-size: 1em; margin: 10px 0 4px; }
#aic .a p { margin: 0 0 8px; }
#aic .a ul, #aic .a ol { margin: 0 0 8px; padding-left: 18px; }
#aic .a li { margin: 0 0 4px; }
#aic .a table { border-collapse: collapse; margin: 0 0 8px; font-size: .93em; }
#aic .a td, #aic .a th { border: 1px solid var(--line); padding: 3px 6px; vertical-align: top; text-align: left; }
/* what no source answers: a quiet note under the answer, a thin rule above it, not a box */
#aic .a .gap { font-size: .93em; color: var(--ink-2); border-top: 1px solid var(--line); padding: 8px 0 0; margin: 10px 0 6px; }
#aic .a .gap h4 { margin: 0 0 4px; font-size: .88em; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
#aic .a .gap ul { margin-bottom: 0; }
#aic .a .note { font-size: .82em; color: var(--ink-3); margin: 8px 0 0; }
#aic .a .xref.aic-cite { cursor: pointer; overflow-wrap: anywhere; }
#aic .a .pending { color: var(--ink-3); }
#aic .refused { color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; }
#aic .err { color: var(--warn); background: var(--warn-soft); border-radius: 9px; padding: 8px 10px; font-size: 12.5px; word-break: break-word; }
#aic .meta { font-size: 11.5px; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 4px; }
#aic .meta .cost { background: var(--chip); padding: 1px 7px; border-radius: 10px; cursor: help; }
/* what the research did: "3 searches · read" and a chip per thing read; a spinning chip for the step under way */
#aic .steps { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin: 0 0 8px; }
#aic .steps .sum { font-size: 11px; color: var(--ink-3); margin-right: 1px; }
#aic .steps .chip { font-size: 11px; color: var(--ink-2); background: var(--chip); border-radius: 6px; padding: 2px 7px; display: inline-flex; gap: 5px; align-items: center;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: default; }
#aic .steps .chip b { font-weight: 600; color: var(--ink-3); font-size: 9.5px; text-transform: uppercase; letter-spacing: .05em; }
#aic .steps .live { font-size: 11px; color: var(--ink-3); display: inline-flex; gap: 6px; align-items: center; padding: 2px 4px; }
#aic .steps .live i { width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--line); border-top-color: var(--accent-2); animation: aic-spin .8s linear infinite; }
@keyframes aic-spin { to { transform: rotate(360deg); } }
/* while it works: grey lines where the answer will be, a soft light passing over them; then the answer fades in */
#aic .aic-wait { display: flex; flex-direction: column; gap: 9px; padding: 4px 0 6px; }
#aic .aic-wait .ln { display: block; margin: 0; height: 10px; border-radius: 5px; background: var(--chip);
  background-image: linear-gradient(90deg, transparent 0, color-mix(in srgb, var(--surface) 70%, transparent) 50%, transparent 100%);
  background-size: 40% 100%; background-repeat: no-repeat; animation: aic-shimmer 1.6s ease-in-out infinite; }
#aic .aic-wait .ln:nth-child(2) { animation-delay: .1s; } #aic .aic-wait .ln:nth-child(3) { animation-delay: .2s; }
#aic .aic-wait .ln:nth-child(4) { animation-delay: .3s; } #aic .aic-wait .ln:nth-child(5) { animation-delay: .4s; }
@keyframes aic-shimmer { from { background-position: -40% 0; } to { background-position: 140% 0; } }
/* how far the answer has got: four stages, the bar, the time left */
#aic .prog { margin: 2px 0 14px; }
#aic .prog .st { display: flex; align-items: flex-start; margin: 0 0 10px; }
#aic .prog .st > div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; position: relative; text-align: center;
  font-size: 11px; color: var(--ink-3); }
#aic .prog .st > div::before { content: ''; position: absolute; top: 6px; left: -50%; right: 50%; height: 2px; background: var(--chip); transition: background .3s; }
#aic .prog .st > div:first-child::before { display: none; }
#aic .prog .st > div.done::before, #aic .prog .st > div.on::before { background: var(--accent-2); }
#aic .prog .st span { position: relative; z-index: 1; width: 14px; height: 14px; border-radius: 50%; box-sizing: border-box;
  background: var(--chip); border: 2px solid var(--chip); transition: background .3s, border-color .3s; }
#aic .prog .st > div.done span { background: var(--accent-2); border-color: var(--accent-2); }
#aic .prog .st > div.on span { background: var(--surface); border-color: var(--accent-2); }
#aic .prog .st > div.on { color: var(--accent); font-weight: 600; }
#aic .prog .bar { height: 4px; border-radius: 2px; background: var(--chip); overflow: hidden; }
#aic .prog .bar i { display: block; height: 100%; width: 0; border-radius: 2px; background: var(--accent-2); transition: width .3s linear; }
#aic .prog .lbl { display: flex; justify-content: flex-end; margin-top: 6px; font-size: 11.5px; color: var(--ink-3); }
@media (prefers-reduced-motion: reduce) { #aic .prog * { transition: none !important; } }
#aic .a.reveal > :not(.steps) { animation: aic-reveal .45s ease-out both; }
@keyframes aic-reveal { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #aic .aic-wait .ln, #aic .a.reveal > * { animation: none; } }
#aic .working { font-size: 12px; color: var(--ink-3); display: flex; flex-direction: column; gap: 3px; margin-bottom: 6px; }
#aic .working span::before { content: '✓ '; color: var(--ok); }
#aic .working span.now::before { content: '… '; color: var(--ink-3); }

#aic footer { border-top: 1px solid var(--line); padding: 9px 10px 8px; background: var(--surface); }
#aic footer .row { display: flex; gap: 6px; }
#aic footer textarea { flex: 1; resize: none; height: 40px; max-height: 120px; border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
  font: inherit; font-size: 13.5px; background: var(--surface-2); color: var(--ink); }
#aic footer textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent-2); }
#aic .send { border: 0; background: var(--accent); color: #fff; border-radius: 9px; padding: 0 14px; font-weight: 600; cursor: pointer; font: 600 13px var(--sans); }
#aic .send.stop { background: var(--ink-3); }
#aic .send:disabled { background: var(--chip); color: var(--ink-3); cursor: default; }
#aic footer textarea:disabled { opacity: .6; cursor: not-allowed; }
#aic .notice { margin: 0 14px 10px; padding: 9px 11px; border-radius: 9px; font-size: 12.5px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); }
#aic .notice[hidden] { display: none; }
#aic footer .sub { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 11px; color: var(--ink-3); }
#aic footer select { font: inherit; font-size: 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink-2); padding: 1px 4px; }

/* the citation menu: only "Open in window 1, 2 or 3" (the site's own menu look) */
.ctx-menu.aic-menu { z-index: 75; min-width: 220px; }

/* the password card, while AI Search is open only to testers: small, above the button */
#aic-lock { position: fixed; right: 20px; bottom: 72px; z-index: 61; width: min(320px, calc(100vw - 40px)); padding: 12px 14px 14px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 36px rgba(20, 25, 35, .2);
  font: 13px/1.45 var(--sans); }
#aic-lock[hidden] { display: none; }
#aic-lock .top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
#aic-lock .top b { font-size: 13.5px; font-weight: 650; color: var(--accent); }
#aic-lock .x { border: 0; background: none; color: var(--ink-3); font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; }
#aic-lock .x:hover { color: var(--ink); }
#aic-lock p { margin: 0 0 10px; color: var(--ink-2); }
#aic-lock .row { display: flex; gap: 6px; }
#aic-lock input { flex: 1; min-width: 0; height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--ink); font: inherit; }
#aic-lock input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent-2); }
#aic-lock .send { border: 0; background: var(--accent); color: #fff; border-radius: 8px; padding: 0 14px; font: 600 13px var(--sans); cursor: pointer; }
#aic-lock .send:disabled { opacity: .6; cursor: default; }
#aic-lock .err { margin-top: 8px; color: var(--warn); font-size: 12.5px; }
#aic-lock .err[hidden] { display: none; }
:root[data-theme="dark"] #aic-lock .send { color: #10151f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #aic-lock .send { color: #10151f; } }
#aic footer .sub.privacy { display: block; line-height: 1.4; }
