/*
 * response-renderer.css — styles for static/js/components/response-renderer.js and the
 * diagram toolbar / viewer in inline-mermaid.js.
 *
 * Shared by the main app's chat and the Frontier PDM, which name their theme tokens
 * differently. This file therefore reads ONLY its own --rr-* tokens, and each page maps
 * them onto its theme once (pdm.css on body; messages.css for the main app). Every
 * colour below is a token or a color-mix of tokens — nothing here reads as one theme only.
 *
 *   --rr-text  --rr-muted  --rr-surface  --rr-surface-2  --rr-border
 *   --rr-accent  --rr-on-accent  --rr-good  --rr-warn  --rr-danger
 */

/* ------------------------------------------------------------ streaming */

.rr-enter { animation: rr-enter .28s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes rr-enter { from { opacity: 0; filter: blur(3px); } to { opacity: 1; filter: none; } }

/* The typing caret sits at the end of the text, inside the last inline-capable element
   of the block that is still arriving — not on a line of its own under the bubble. */
.rr-caret::after {
  content: "\258C"; margin-left: 1px; color: var(--rr-accent);
  animation: rr-caret-blink 1s steps(1) infinite;
}
@keyframes rr-caret-blink { 50% { opacity: 0; } }

.rr-skeleton {
  display: grid; place-items: center; min-height: 132px; margin: 12px 0;
  border: 1px dashed color-mix(in srgb, var(--rr-accent) 35%, var(--rr-border));
  border-radius: 10px; font-size: 12.5px; color: var(--rr-muted);
  background:
    linear-gradient(100deg, transparent 30%, color-mix(in srgb, var(--rr-accent) 8%, transparent) 50%, transparent 70%)
    0 0 / 220% 100%,
    var(--rr-surface-2);
  animation: rr-shimmer 1.4s linear infinite;
}
.rr-skeleton--kpi, .rr-skeleton--chart { min-height: 84px; }
@keyframes rr-shimmer { to { background-position: -220% 0, 0 0; } }

/* ------------------------------------------------------------ callouts */

.rr-callout {
  --rr-callout: var(--rr-accent);
  display: flex; gap: 10px; align-items: flex-start;
  margin: 12px 0; padding: 10px 12px; border-radius: 10px;
  background: color-mix(in srgb, var(--rr-callout) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--rr-callout) 32%, var(--rr-border));
  color: var(--rr-text);
}
.rr-callout--tip { --rr-callout: var(--rr-good); }
.rr-callout--warning { --rr-callout: var(--rr-warn); }
.rr-callout--caution { --rr-callout: var(--rr-danger); }
.rr-callout__icon { flex: none; display: inline-flex; color: var(--rr-callout); margin-top: 2px; }
.rr-callout__body { min-width: 0; }
.rr-callout__label { display: block; font-weight: 650; margin-bottom: 2px; }
.rr-callout__body > p { margin: 0 0 6px; }
.rr-callout__body > p:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------ data blocks */

.rr-data { margin: 12px 0; min-width: 0; }
.rr-data__title { font-size: 12.5px; font-weight: 650; color: var(--rr-muted); margin-bottom: 8px; }
.rr-data__unit { font-weight: 400; }
.rr-data__source {
  margin-top: 8px; font-size: 11.5px; color: var(--rr-muted);
  font-variant-numeric: tabular-nums;
}

.rr-kpi__grid {
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(min(132px, 100%), 1fr));
}
.rr-kpi__tile {
  min-width: 0; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--rr-border); background: var(--rr-surface);
}
.rr-kpi__label { font-size: 12px; color: var(--rr-muted); overflow-wrap: anywhere; }
.rr-kpi__value {
  margin-top: 2px; font-size: 20px; line-height: 1.2; font-weight: 650;
  color: var(--rr-text); font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.rr-kpi__tile.rr-tone-warn .rr-kpi__value { color: var(--rr-warn); }
.rr-kpi__tile.rr-tone-good .rr-kpi__value { color: var(--rr-good); }
.rr-kpi__value.is-missing, .rr-chart__value.is-missing { color: var(--rr-muted); font-weight: 500; }

.rr-chart {
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--rr-border); background: var(--rr-surface);
}
.rr-chart__rows { display: grid; gap: 6px; }
.rr-chart__row {
  display: grid; align-items: center; gap: 10px; font-size: 12.5px;
  grid-template-columns: minmax(3.5em, max-content) minmax(0, 1fr) minmax(2.5em, max-content);
  font-variant-numeric: tabular-nums;
}
.rr-chart__label { color: var(--rr-muted); overflow-wrap: anywhere; max-width: 12em; }
.rr-chart__track {
  height: 10px; border-radius: 5px; overflow: hidden;
  background: color-mix(in srgb, var(--rr-text) 7%, transparent);
}
.rr-chart__fill { display: block; height: 100%; border-radius: 5px; background: var(--rr-accent); transform-origin: left center; }
.rr-chart__fill.rr-grow { animation: rr-grow .6s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes rr-grow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.rr-chart__value { text-align: right; font-weight: 600; color: var(--rr-text); }

/* ------------------------------------------------------------ follow-up chips */

.rr-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.rr-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 6px 12px; border-radius: 999px; cursor: pointer;
  font: inherit; font-size: 12.5px; font-weight: 500; line-height: 1.3; text-align: left;
  color: var(--rr-accent); background: var(--rr-surface);
  border: 1px solid color-mix(in srgb, var(--rr-accent) 38%, var(--rr-border));
}
.rr-chip svg { flex: none; }
.rr-chip span { overflow-wrap: anywhere; }
.rr-chip:hover { background: color-mix(in srgb, var(--rr-accent) 9%, var(--rr-surface)); }
.rr-chip:focus-visible { outline: 2px solid var(--rr-accent); outline-offset: 2px; }

/* ------------------------------------------------------------ long answers */

.rr-more { margin-top: 10px; }
.rr-more__summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--rr-accent);
  list-style: none; display: inline-flex; align-items: center; gap: 6px;
}
.rr-more__summary::-webkit-details-marker { display: none; }
.rr-more__summary::before {
  content: ""; width: 6px; height: 6px; transform: rotate(-45deg); transition: transform .15s;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
}
.rr-more[open] > .rr-more__summary::before { transform: rotate(45deg); }
.rr-more[open] > .rr-more__summary { margin-bottom: 8px; }
.rr-more__summary:focus-visible { outline: 2px solid var(--rr-accent); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------------------------------------ action bar */

.rr-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.rr-action {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 7px;
  border: 0; background: transparent; color: var(--rr-muted); cursor: pointer;
  font: inherit; font-size: 12px; line-height: 1;
}
.rr-action:hover { color: var(--rr-text); background: color-mix(in srgb, var(--rr-text) 7%, transparent); }
.rr-action:focus-visible { outline: 2px solid var(--rr-accent); outline-offset: 1px; }
.rr-action svg { flex: none; }
@media (max-width: 560px) {
  /* Icons only on a phone; the label stays the accessible name (aria-label). */
  .rr-action__label { display: none; }
  .rr-action { padding: 7px; }
}

/* ------------------------------------------------------------ diagram build + toolbar */

.inline-mermaid-diagram svg .im-build-pending { opacity: 0; }
.inline-mermaid-diagram svg .im-build-in { animation: rr-enter-plain .45s ease both; }
.inline-mermaid-diagram svg .im-build-edge { transition: stroke-dashoffset .55s ease; }
.inline-mermaid-diagram .im-build-fade svg { animation: rr-enter-plain .5s ease both; }
@keyframes rr-enter-plain { from { opacity: 0; } to { opacity: 1; } }

.inline-mermaid-diagram__tools {
  display: none; justify-content: flex-end; gap: 2px; padding: 4px 6px;
  border-top: 1px solid var(--rr-border);
}
.inline-mermaid-diagram[data-state="rendered"] > .inline-mermaid-diagram__tools { display: flex; }
.inline-mermaid-diagram__tool {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 6px;
  border: 0; background: transparent; color: var(--rr-muted); cursor: pointer;
  font: inherit; font-size: 12px; line-height: 1;
}
.inline-mermaid-diagram__tool:hover { color: var(--rr-text); background: color-mix(in srgb, var(--rr-text) 7%, transparent); }
.inline-mermaid-diagram__tool:focus-visible { outline: 2px solid var(--rr-accent); outline-offset: 1px; }
.inline-mermaid-diagram__tool:disabled { opacity: .55; cursor: progress; }

.im-lightbox {
  position: fixed; inset: 0; z-index: 10000; display: grid; place-items: center;
  padding: max(16px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--rr-text) 45%, transparent);
}
.im-lightbox__panel {
  display: flex; flex-direction: column; width: min(1200px, 100%); max-height: 100%;
  background: var(--rr-surface); color: var(--rr-text);
  border: 1px solid var(--rr-border); border-radius: 14px; overflow: hidden;
  box-shadow: 0 24px 60px color-mix(in srgb, var(--rr-text) 25%, transparent);
}
.im-lightbox__bar {
  display: flex; justify-content: flex-end; gap: 4px; padding: 6px 8px;
  border-bottom: 1px solid var(--rr-border); background: var(--rr-surface-2);
}
.im-lightbox__bar .inline-mermaid-diagram__tool { padding: 7px; }
.im-lightbox__stage {
  overflow: auto; padding: 16px; min-height: 200px; display: grid; justify-items: safe center;
  touch-action: pan-x pan-y pinch-zoom; overscroll-behavior: contain;
}
.im-lightbox__stage svg { display: block; height: auto; }
@media (max-width: 640px) {
  .im-lightbox { padding: 0; }
  .im-lightbox__panel { width: 100%; height: 100%; border-radius: 0; border: 0; }
  .im-lightbox__stage { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .rr-enter, .rr-skeleton, .rr-chart__fill.rr-grow, .rr-caret::after,
  .inline-mermaid-diagram svg .im-build-in, .inline-mermaid-diagram .im-build-fade svg {
    animation: none !important;
  }
  .inline-mermaid-diagram svg .im-build-edge, .rr-more__summary::before { transition: none !important; }
}
