/* ── Q&A sidecar styles ─────────────────────────────────────────────────────
   Self-contained stylesheet for the "Ask the model" launcher + sliding chat
   panel and the right-click "Ask about this cell" affordance. Loaded via a
   single <link> tag in index.html (served under /opmodel/). Part of the Q&A
   sidecar — deleting this file + qna.js + their tags removes the UI cleanly
   (docs/specs/qna-isolation.md §2.3 / §4). See docs/specs/qna-vocabulary.md.

   The launcher is a 56px circle at bottom-right; the panel slides in from the
   right when opened. */

.qna-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1f2937;
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  z-index: 999;
  transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
}
.qna-launcher:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}
.qna-launcher:focus-visible {
  outline: 2px solid #67e8f9;
  outline-offset: 3px;
}
.qna-launcher.qna-launcher--open {
  /* When the panel is open, dim the launcher so it doesn't compete visually. */
  background: #4b5563;
}

.qna-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 420px;
  max-width: calc(100vw - 48px);
  max-height: min(60vh, 640px);
  background: white;
  border: 1px solid #d1d5db;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  z-index: 998;
  /* Slide-in animation. The hidden state is below; this is the open state. */
  transform: translateX(0);
  transition: transform 0.2s ease-out, opacity 0.2s ease-out;
  opacity: 1;
}
.qna-panel[hidden] {
  display: none !important;
}
.qna-panel.qna-panel--entering {
  /* set by JS on open, removed after raf so the transition fires */
  transform: translateX(440px);
  opacity: 0;
}

.qna-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
}
.qna-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  color: #1f2937;
}
.qna-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #6b7280;
  padding: 0 0.25rem;
  border-radius: 4px;
}
.qna-close:hover { background: #f3f4f6; color: #1f2937; }

.qna-conversation {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.875rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  font-size: 0.875rem;
  line-height: 1.45;
  color: #1f2937;
  min-height: 0;
}

.qna-empty {
  color: #6b7280;
  font-size: 0.825rem;
}
.qna-empty-title { font-weight: 600; margin: 0 0 0.5rem 0; color: #4b5563; }
.qna-empty-suggestions {
  list-style: none;
  padding: 0;
  margin: 0 0 0.75rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.qna-suggestion {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  font-size: 0.825rem;
  text-align: left;
  cursor: pointer;
  color: #1f2937;
  width: 100%;
}
.qna-suggestion:hover { background: #e5e7eb; }
.qna-empty-hint { margin: 0; font-size: 0.75rem; }

.qna-turn {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.qna-bubble {
  padding: 0.625rem 0.875rem;
  border-radius: 12px;
  max-width: 90%;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.qna-bubble--user {
  align-self: flex-end;
  background: #2563eb;
  color: white;
  border-bottom-right-radius: 4px;
}
.qna-bubble--model {
  align-self: flex-start;
  background: #f3f4f6;
  color: #1f2937;
  border-bottom-left-radius: 4px;
}
.qna-bubble--error {
  align-self: stretch;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}
.qna-bubble--thinking {
  align-self: flex-start;
  background: #f3f4f6;
  color: #6b7280;
  font-style: italic;
}
.qna-bubble--thinking::after {
  content: "";
  display: inline-block;
  margin-left: 4px;
  animation: qna-dots 1.2s steps(4) infinite;
}
@keyframes qna-dots {
  0%   { content: ""; }
  25%  { content: "."; }
  50%  { content: ".."; }
  75%  { content: "..."; }
}

.qna-evidence {
  align-self: flex-start;
  max-width: 100%;
  margin-top: -0.25rem;
}
.qna-evidence-summary {
  font-size: 0.75rem;
  color: #6b7280;
  cursor: pointer;
  padding: 0.25rem 0;
  user-select: none;
}
.qna-evidence-summary:hover { color: #1f2937; }
.qna-evidence-body {
  margin-top: 0.4rem;
  background: #1e293b;
  color: #e2e8f0;
  border-radius: 6px;
  padding: 0.625rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem;
  line-height: 1.4;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.qna-evidence-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: #6b7280;
  margin-bottom: 0.35rem;
}
.qna-evidence-tag {
  background: #eef2ff;
  color: #3730a3;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  border: 1px solid #c7d2fe;
}
.qna-evidence-tag--warn {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}
.qna-evidence-tag--cached {
  background: #ecfeff;
  color: #155e75;
  border-color: #a5f3fc;
}

/* ── Caching-tier provenance chips ──────────────────────────────────────────
   One row under each model answer: tier tag + speed + cost (+ similarity on a
   semantic hit). Tasteful, color-coded; matches the panel's pill aesthetic. */
.qna-chips {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: -0.15rem;
}
.qna-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.22rem 0.5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.qna-chip-icon { font-size: 0.8rem; line-height: 1; }
/* Tier tags. */
.qna-chip--exact   { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }   /* blue */
.qna-chip--semantic{ background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }   /* purple */
.qna-chip--miss    { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }   /* green */
/* Time. */
.qna-chip--time    { background: #f3f4f6; color: #374151; border-color: #e5e7eb; }
/* Cost — free (Harper tiers) vs real spend (miss). */
.qna-chip--free    { background: #f0fdfa; color: #0f766e; border-color: #99f6e4; }
.qna-chip--free .qna-chip-cue {
  font-weight: 700;
  font-size: 0.62rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.75;
}
.qna-chip--cost    { background: #fffbeb; color: #92400e; border-color: #fde68a; }
/* Semantic similarity (the wow). */
.qna-chip--similarity { background: #f5f3ff; color: #7c3aed; border-color: #ddd6fe; }

/* Compact footer: one subtle row holding the AI disclaimer (left) and the
   cumulative Harper-cache readout (right). Replaces the old heavy yellow
   disclaimer banner + separate stats band — far less visual noise. */
.qna-footer {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  padding: 0.5rem 1rem 0.6rem;
  border-top: 1px solid #eceef1;
}

/* AI disclaimer — muted one-liner; full text on hover via the same styled
   tooltip the Filters/info-icons use (dark #312556 bubble), but opening UPWARD
   and left-anchored since this sits at the panel's bottom edge. */
.qna-disclaimer {
  position: relative;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.6875rem;
  line-height: 1.3;
  color: #8a8f98;
  cursor: help;
}
.qna-disclaimer-icon { color: #d97706; font-size: 0.8rem; line-height: 1; }
.qna-disclaimer[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: #312556;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}
.qna-disclaimer[data-tooltip]:hover::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 2px);
  left: 0.5rem;
  border: 6px solid transparent;
  border-top-color: #312556;
  z-index: 100;
  pointer-events: none;
}

/* Cumulative "saved so far" readout — quiet by default, the saved figure pops. */
.qna-stats {
  margin: 0;
  font-size: 0.6875rem;
  color: #9ca3af;
  white-space: nowrap;
}
.qna-stats:empty { display: none; }
.qna-stats-line strong { color: #0f766e; font-weight: 600; }

.qna-input-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid #e5e7eb;
  flex-shrink: 0;
}
.qna-input {
  flex: 1 1 auto;
  padding: 0.55rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.875rem;
  outline: none;
}
.qna-input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
.qna-submit {
  background: #2563eb;
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.55rem 1rem;
  font-size: 0.825rem;
  font-weight: 600;
  cursor: pointer;
}
.qna-submit:hover { background: #1d4ed8; }
.qna-submit:disabled { background: #93c5fd; cursor: not-allowed; }

/* Right-click context menu addition (sibling to .cell-history-menu-item).
   Visually distinct primary action under the existing history item. */
.cell-history-menu-item.cell-qna-item {
  color: #1d4ed8;
}
.cell-history-menu-item.cell-qna-item .cell-history-menu-icon {
  color: #2563eb;
}

/* Right-click "Ask about this cell" context chip under the user bubble.
   Confirms which cell the backend will lock the tools to. */
.qna-context-chip {
  align-self: flex-end;
  font-size: 0.7rem;
  color: #4b5563;
  background: #eef2ff;
  border: 1px solid #c7d2fe;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  margin-top: -0.2rem;
}

/* Hide the launcher + panel in print/PDF output. */
@media print {
  .qna-launcher, .qna-panel { display: none !important; }
}
