/**
 * chat-experts.css — AG-F-9 + AG-F-10 + Phase 5c
 *
 * Styles for:
 *   - Specialist pill headers (.ai-expert-header / .ai-expert-avatar / etc.)
 *   - Citation footer chips (.ai-expert-citations / .ai-expert-citation-chip)
 *   - Workflow step trace card (.ai-wf-*)
 *
 * Uses --expert-color / --expert-color-bg CSS custom properties set inline
 * per-bubble since each specialist has its own signature color.
 * All other colors/spacing/radii/motion use --guide-* design tokens.
 */

/* ── Specialist pill header ─────────────────────────────────────────────── */

/* Container for multi-specialist side-by-side layout */
.ai-expert-headers {
  display: flex;
  flex-direction: column;
  gap: var(--guide-sp-1, 4px);
  margin-bottom: var(--guide-sp-2, 8px);
}

/* The expert header is a raised sheet with a 1px rule: no frost, no accent
   bar, no glow. The specialist is named in its text and icon. */
.ai-expert-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--guide-sp-2, 8px);
  padding: var(--guide-sp-2, 8px) var(--guide-sp-3, 12px);
  background: var(--guide-color-raised);
  border: 1px solid var(--guide-color-line);
  border-radius: var(--guide-radius-sm, 6px);
  overflow: hidden;
  margin-bottom: 0;  /* spacing handled by .ai-expert-headers gap */
  cursor: help;
  box-shadow: var(--guide-shadow-rest);
  transition:
    border-color var(--guide-dur-base, 180ms) var(--guide-ease-out, ease),
    box-shadow var(--guide-dur-base, 180ms) var(--guide-ease-out, ease);
  /* Rise-in entrance — the card appears the moment a specialist is routed. */
  animation: guideRiseIn var(--guide-dur-base, 180ms) var(--guide-ease-out, ease-out) both;
}
.ai-expert-header:hover {
  border-color: var(--guide-color-line-strong);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .ai-expert-header { background: var(--guide-color-bg-3, #F7F5F0); }
}

/* Staggered arrival when several specialists fan out side-by-side. */
.ai-expert-headers .ai-expert-header:nth-child(2) { animation-delay: 60ms; }
.ai-expert-headers .ai-expert-header:nth-child(3) { animation-delay: 120ms; }
.ai-expert-headers .ai-expert-header:nth-child(4) { animation-delay: var(--guide-dur-base); }

@media (prefers-reduced-motion: reduce) {
  .ai-expert-header { animation: none; }
}

/* Standalone header (no container) keeps its own bottom margin */
.ai-expert-header:not(.ai-expert-headers *) {
  margin-bottom: var(--guide-sp-2, 8px);
}

/* Solid accent disc with a soft halo ring + glow — the human counterpart to the
   tool medallion (matches its glow, distinct fill to signal person vs tool). */
.ai-expert-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--expert-color, #0284c7);
  color: var(--guide-color-white, #fff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--guide-fs-11, 11px);
  font-weight: var(--guide-fw-semi, 600);
  flex-shrink: 0;
  letter-spacing: 0.02em;
  box-shadow:
    0 0 0 2px color-mix(in srgb, var(--expert-color, transparent) 16%, transparent), var(--ait-glow-sm, 0 4px 14px color-mix(in srgb, var(--expert-color, transparent) 22%, transparent));
}

.ai-expert-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.ai-expert-name {
  font-weight: var(--guide-fw-semi, 600);
  font-size: var(--guide-fs-13, 13px);
  color: var(--guide-color-ink, #1a1a1f);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-expert-reason {
  font-size: var(--guide-fs-11, 11px);
  color: var(--guide-color-status-mute, #6b6b73);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Per-specialist cost chip (Phase 5b) ────────────────────────────────── */

.ai-expert-cost-chip {
  margin-left: auto;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  font-size: var(--guide-fs-11, 11px);
  font-weight: var(--guide-fw-semi, 600);
  color: var(--expert-color, #0284c7);
  background: color-mix(in srgb, var(--expert-color, #0284c7) 13%, transparent);
  border: 1px solid transparent;
  border-radius: var(--guide-radius-pill, 999px);
  padding: 2px 8px;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
  cursor: default;
  white-space: nowrap;
}

/* Final cost signal — slightly more prominent border */
.ai-expert-cost-chip--final {
  border-color: var(--expert-color, #0284c7);
}

/* ── Citation footer chips (AG-F-9) ─────────────────────────────────────── */

.ai-expert-citations {
  display: flex;
  flex-wrap: wrap;
  gap: var(--guide-sp-1, 4px);
  border-top: 1px solid var(--guide-color-line, #e5e0d2);
  margin-top: var(--guide-sp-2, 8px);
  padding-top: var(--guide-sp-2, 8px);
}

.ai-expert-citation-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--guide-sp-1, 4px);
  background: transparent;
  border: 1px solid var(--guide-color-line, #e5e0d2);
  border-radius: var(--guide-radius-xs, 4px);
  font-size: var(--guide-fs-11, 11px);
  color: var(--guide-color-status-mute, #6b6b73);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}

.ai-expert-citation-chip--more {
  color: var(--expert-color, #0284c7);
  border-color: var(--expert-color, #0284c7);
  font-weight: var(--guide-fw-semi, 600);
  cursor: default;
}

/* AG-E-1 — linked citation chip: <a> variant with hover affordance */
a.ai-expert-citation-chip--link {
  text-decoration: none;
  cursor: pointer;
  border-color: var(--guide-color-line, #e5e0d2);
  color: var(--guide-color-status-mute, #6b6b73);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
a.ai-expert-citation-chip--link::after {
  content: '\2197'; /* ↗ */
  font-size: var(--guide-fs-2xs);
  margin-left: 3px;
  opacity: 0.5;
  flex-shrink: 0;
}
a.ai-expert-citation-chip--link:hover,
a.ai-expert-citation-chip--link:focus {
  border-color: var(--expert-color, #0284c7);
  color: var(--expert-color, #0284c7);
  background: var(--expert-color-bg, rgba(2, 132, 199, 0.07));
  text-decoration: none;
  outline: none;
}
a.ai-expert-citation-chip--link:focus-visible {
  outline: 2px solid var(--expert-color, #0284c7);
  outline-offset: 1px;
}

/* ── Workflow trace card (Phase 5c) ─────────────────────────────────────── */

.ai-wf-trace-host {
  margin-top: var(--guide-sp-2, 8px);
}

details.ai-wf-trace {
  border: 1px solid var(--guide-color-line, #e5e0d2);
  border-radius: var(--guide-radius-sm, 6px);
  overflow: hidden;
  font-size: var(--guide-fs-12, 12px);
}

summary.ai-wf-summary {
  display: flex;
  align-items: center;
  gap: var(--guide-sp-2, 8px);
  padding: var(--guide-sp-1, 4px) var(--guide-sp-2, 8px);
  background: var(--guide-color-surface, #f9f7f2);
  cursor: pointer;
  user-select: none;
  list-style: none;
  font-size: var(--guide-fs-12, 12px);
  color: var(--guide-color-ink, #1a1a1f);
}

summary.ai-wf-summary::-webkit-details-marker { display: none; }
summary.ai-wf-summary::marker { display: none; }

.ai-wf-summary-icon {
  color: var(--guide-color-status-mute, #6b6b73);
  flex-shrink: 0;
  transition: transform 0.15s var(--guide-ease-out, ease-out);
}

details[open] .ai-wf-summary-icon {
  transform: rotate(90deg);
}

.ai-wf-summary-name {
  font-weight: var(--guide-fw-semi, 600);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-wf-summary-meta {
  display: flex;
  align-items: center;
  gap: var(--guide-sp-1, 4px);
  flex-shrink: 0;
}

.ai-wf-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: var(--guide-fs-2xs);
  font-weight: var(--guide-fw-semi, 600);
  line-height: 1.5;
}

.ai-wf-badge--ok {
  background: var(--guide-color-status-ok-bg, #dcfce7);
  color: var(--guide-color-status-ok, #15803d);
}

.ai-wf-badge--error {
  background: var(--guide-color-status-danger-bg, #fee2e2);
  color: var(--guide-color-status-crit, var(--guide-color-status-crit));
}

.ai-wf-badge--steps {
  background: var(--guide-color-line, #e5e0d2);
  color: var(--guide-color-status-mute, #6b6b73);
}

.ai-wf-badge--ms {
  background: var(--guide-color-line, #e5e0d2);
  color: var(--guide-color-status-mute, #6b6b73);
}

/* Table of steps */

.ai-wf-table-wrap {
  overflow-x: auto;
  padding: var(--guide-sp-2, 8px);
  border-top: 1px solid var(--guide-color-line, #e5e0d2);
}

table.ai-wf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--guide-fs-11, 11px);
  color: var(--guide-color-ink, #1a1a1f);
  table-layout: auto;
}

.ai-wf-table th {
  text-align: left;
  font-weight: var(--guide-fw-semi, 600);
  color: var(--guide-color-status-mute, #6b6b73);
  padding: 2px 6px;
  border-bottom: 1px solid var(--guide-color-line, #e5e0d2);
  white-space: nowrap;
}

.ai-wf-table td {
  padding: 3px 6px;
  vertical-align: middle;
  border-bottom: 1px solid var(--guide-color-line, #e5e0d2);
}

.ai-wf-table tr:last-child td {
  border-bottom: none;
}

.ai-wf-table tr:hover td {
  background: var(--guide-color-surface, #f9f7f2);
}

.ai-wf-td-id {
  font-family: var(--guide-font-mono, monospace);
  font-size: var(--guide-fs-2xs);
  color: var(--guide-color-status-mute, #6b6b73);
}

.ai-wf-td-tool {
  font-family: var(--guide-font-mono, monospace);
  font-size: var(--guide-fs-2xs);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ai-wf-td-status { white-space: nowrap; }

.ai-wf-td-latency {
  text-align: right;
  color: var(--guide-color-status-mute, #6b6b73);
  white-space: nowrap;
}

.ai-wf-td-cache {
  text-align: center;
}

.ai-wf-cache-hit {
  color: var(--guide-color-status-ok, #15803d);
  font-size: var(--guide-fs-2xs);
}

/* Action buttons row */

.ai-wf-actions {
  display: flex;
  gap: var(--guide-sp-2, 8px);
  padding: var(--guide-sp-1, 4px) var(--guide-sp-2, 8px) var(--guide-sp-2, 8px);
  border-top: 1px solid var(--guide-color-line, #e5e0d2);
}

.ai-wf-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--guide-radius-xs, 4px);
  font-size: var(--guide-fs-11, 11px);
  font-weight: var(--guide-fw-semi, 600);
  cursor: pointer;
  border: 1px solid var(--guide-color-line, #e5e0d2);
  background: var(--guide-color-surface, #f9f7f2);
  color: var(--guide-color-ink, #1a1a1f);
  transition: background 0.1s, border-color 0.1s;
}

.ai-wf-btn:hover {
  background: var(--guide-color-line, #e5e0d2);
  border-color: var(--guide-color-border-default, rgba(0, 0, 0, 0.10));
}

.ai-wf-btn:active {
  opacity: 0.75;
}

/* ── Phase 5a Slice 3b — Map screenshot inline display ──────────────────── */

.ai-map-screenshot-wrapper {
  margin-top: var(--guide-sp-3, 12px);
  position: relative;
  display: inline-block;
  max-width: 100%;
}

.ai-map-screenshot {
  display: block;
  max-width: 100%;
  border-radius: var(--guide-radius-md, 8px);
  border: 1px solid var(--guide-color-border-default, rgba(0, 0, 0, 0.10));
  box-shadow: var(--guide-shadow-raised);
  background: var(--guide-color-surface, #f9f7f2);
}

.ai-map-screenshot-dl {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--guide-radius-xs, 4px);
  background: var(--guide-color-raised);
  border: 1px solid var(--guide-color-line-strong);
  color: var(--guide-color-action);
  font-size: var(--guide-fs-2xs);
  font-weight: var(--guide-fw-semi, 600);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.1s;
}

.ai-map-screenshot-dl:hover {
  background: var(--guide-color-raised);
  border-color: var(--guide-color-ink-soft);
}

/* ── Expert CV hover popover (Phase 5b) ─────────────────────────────── */
/* A raised sheet with the elevation shadow. --expert-color is set inline by
   app-main.js and still marks the name. */
.ai-expert-cv-popover {
  position: absolute;
  z-index: var(--guide-z-popover, 300);
  width: min(320px, calc(100vw - 16px));
  background: var(--guide-color-raised);
  border: 1px solid var(--guide-color-line);
  border-radius: var(--guide-radius-md, 8px);
  box-shadow: var(--guide-shadow-overlay);
  padding: 14px 14px 11px;
  font-size: var(--guide-fs-12, 12px);
  line-height: 1.5;
  color: var(--guide-color-ink, #1a1a1f);
  overflow: hidden;
  pointer-events: none; /* hover events stay on the trigger */
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .ai-expert-cv-popover { background: var(--guide-color-surface, #f9f7f2); }
}
.ai-expert-cv-popover::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg,
    var(--expert-color, #0284c7) 0%,
    color-mix(in srgb, var(--expert-color, #0284c7) 35%, transparent) 45%,
    transparent 82%);
}

.ai-cv-header {
  font-size: var(--guide-fs-13, 13px);
  font-weight: var(--guide-fw-bold, 700);
  color: var(--expert-color, var(--guide-color-ink, #1a1a1f));
  margin-bottom: 4px;
}

.ai-cv-desc {
  color: var(--guide-color-text-muted, #5E5D5B);
  font-size: var(--guide-fs-11, 11px);
  margin-bottom: 6px;
}

.ai-cv-excerpt {
  font-style: italic;
  font-size: var(--guide-fs-11, 11px);
  color: var(--guide-color-text-muted, #5E5D5B);
  padding-left: 8px;
  margin-bottom: 6px;
  white-space: pre-wrap;
}

.ai-cv-row {
  margin-bottom: 4px;
  font-size: var(--guide-fs-11, 11px);
}

.ai-cv-row strong {
  font-weight: var(--guide-fw-semi, 600);
}

.ai-cv-cite {
  display: inline-block;
  background: var(--guide-color-accent-bg, rgba(59, 130, 246, 0.08));
  border-radius: var(--guide-radius-xs, 3px);
  padding: 0 4px;
  margin-right: 3px;
  font-size: var(--guide-fs-10, 10px);
  color: var(--guide-color-mt-teal, #0F766E);
}

/* Make the specialist header focusable with visible focus ring */
.ai-expert-header[tabindex] {
  cursor: help;
}
.ai-expert-header[tabindex]:focus {
  outline: 2px solid var(--guide-color-mt-teal, #0F766E);
  outline-offset: 2px;
  border-radius: var(--guide-radius-xs, 3px);
}

/* ── Narrow viewports (phones) ─────────────────────────────────────────
   The headers already stack (flex-direction: column). On very small screens
   let the specialist name wrap rather than ellipsis-truncate (so the full
   name stays readable), and let the header row wrap so the cost/citation
   chips drop below the avatar instead of forcing horizontal overflow. */
@media (max-width: 480px) {
  .ai-expert-header {
    flex-wrap: wrap;
  }
  .ai-expert-name {
    white-space: normal;
  }
  .ai-expert-cv-popover {
    width: calc(100vw - 16px);
  }
}
