/* R13 interactive visuals (Inspection Ledger).
   Markup: src/views/visuals.tsx (server) and public/assets/fv-visuals.js (live redraw).
   Colors come only from fv-ledger.css tokens, so light and dark follow [data-theme]. */

.fv-vis-card {
  --fv-vis-okbg: rgba(4, 120, 87, 0.12);
  --fv-vis-warnbg: rgba(180, 83, 9, 0.12);
  --fv-vis-badbg: rgba(185, 28, 28, 0.12);
  --fv-vis-hover: rgba(19, 78, 122, 0.16);
  --fv-vis-warn-text: #92400e; /* amber readable on --fv-accent-bg (6:1) */
  min-width: 0;
  margin: 0 0 24px;
  padding: 14px 16px 12px;
  background: var(--fv-surface);
  border: 1px solid var(--fv-line);
  border-top: 3px solid var(--fv-line-strong);
  color: var(--fv-ink);
}

[data-theme="dark"] .fv-vis-card {
  --fv-vis-okbg: rgba(52, 211, 153, 0.14);
  --fv-vis-warnbg: rgba(251, 191, 36, 0.14);
  --fv-vis-badbg: rgba(248, 113, 113, 0.16);
  --fv-vis-hover: rgba(96, 165, 250, 0.2);
  --fv-vis-warn-text: var(--fv-warn);
}

/* Full row inside .fv-tool__split (12-column grid) */
.fv-vis-span {
  grid-column: 1 / -1;
}

/* ---------- Head: title + legend ---------- */

.fv-vis-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px 16px;
  margin: 0 0 10px;
}

.fv-vis-title {
  font-family: var(--fv-font-display);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--fv-ink);
}

.fv-vis-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-family: var(--fv-font-mono);
  font-size: 12px;
  line-height: 1.4;
  color: var(--fv-muted);
}

.fv-vis-key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.fv-vis-key::before {
  content: "";
  flex: none;
  box-sizing: border-box;
  width: 10px;
  height: 10px;
  background: var(--fv-dim);
}

.fv-vis-key--ok::before { background: var(--fv-ok); }
.fv-vis-key--warn::before { background: var(--fv-warn); }
.fv-vis-key--bad::before { background: var(--fv-bad); }
.fv-vis-key--accent::before { background: var(--fv-accent); }
.fv-vis-key--ink::before { background: var(--fv-ink); }
.fv-vis-key--dim::before { background: var(--fv-dim); }
.fv-vis-key--track::before { background: var(--fv-surface-alt); border: 1px solid var(--fv-dim); }
.fv-vis-key--dash::before { background: transparent; border: 1px dashed var(--fv-dim); }
.fv-vis-key--line::before { width: 2px; height: 12px; background: var(--fv-line-strong); }

/* ---------- Readout (live tooltip) ---------- */

.fv-vis-tooltip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "label value"
    "detail detail";
  align-items: baseline;
  gap: 2px 16px;
  min-height: 54px;
  margin: 0 0 10px;
  padding: 7px 12px;
  background: var(--fv-surface);
  border: 1px solid var(--fv-line);
  border-left: 3px solid var(--fv-line-strong);
  font-family: var(--fv-font-ui);
  font-size: 14px;
  line-height: 1.35;
  color: var(--fv-ink);
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.fv-vis-tooltip.is-live {
  background: var(--fv-accent-bg);
  border-color: var(--fv-accent);
}

.fv-vis-tooltip__label {
  grid-area: label;
  min-width: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.fv-vis-tooltip__value {
  grid-area: value;
  font-family: var(--fv-font-mono);
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}

.fv-vis-tooltip__detail {
  grid-area: detail;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  min-width: 0;
  font-size: 13px;
  color: var(--fv-muted);
  overflow-wrap: anywhere;
}

.fv-vis-tooltip__detail:empty {
  display: none;
}

.fv-vis-tooltip[data-tone="ok"] .fv-vis-tooltip__value { color: var(--fv-ok); }
.fv-vis-tooltip[data-tone="warn"] .fv-vis-tooltip__value { color: var(--fv-vis-warn-text); }
.fv-vis-tooltip[data-tone="bad"] .fv-vis-tooltip__value { color: var(--fv-bad); }
.fv-vis-tooltip[data-tone="accent"] .fv-vis-tooltip__value { color: var(--fv-accent); }

/* ---------- SVG box ---------- */

.fv-vis-scroll {
  min-width: 0;
}

.fv-vis-scroll:focus-visible {
  outline: 2px solid var(--fv-focus);
  outline-offset: 3px;
}

.fv-vis-svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

@media (min-width: 901px) {
  .fv-vis-svg {
    min-height: 230px;
    max-height: 260px;
  }
}

/* Narrow screens: keep labels legible, scroll the drawing sideways inside the card */
@media (max-width: 900px) {
  .fv-vis-scroll {
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
  }

  .fv-vis-svg {
    min-width: 760px;
    max-width: none;
  }
}

@media (max-width: 640px) {
  .fv-vis-card {
    padding: 12px 12px 10px;
  }

  .fv-vis-svg {
    width: 760px;
    min-height: 150px;
    max-height: 210px;
  }
}

@media (max-width: 560px) {
  .fv-vis-tooltip {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "label"
      "value"
      "detail";
  }

  .fv-vis-tooltip__value {
    text-align: left;
    white-space: normal;
  }
}

/* ---------- SVG text ---------- */

.fv-vis-svg text {
  font-family: var(--fv-font-mono);
  font-size: 12px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  fill: var(--fv-muted);
}

.fv-vis-svg .fv-t-ui { font-family: var(--fv-font-ui); font-size: 13px; }
.fv-vis-svg .fv-t-m { font-size: 13px; }
.fv-vis-svg .fv-t-l { font-size: 15px; }
.fv-vis-svg .fv-t-xl { font-family: var(--fv-font-display); font-size: 30px; }
.fv-vis-svg .fv-t-b { font-weight: 700; }
.fv-vis-svg .fv-t-ui.fv-t-b { font-weight: 600; }
.fv-vis-svg .fv-t-ink { fill: var(--fv-ink); }
.fv-vis-svg .fv-t-ok { fill: var(--fv-ok); }
.fv-vis-svg .fv-t-warn { fill: var(--fv-warn); }
.fv-vis-svg .fv-t-bad { fill: var(--fv-bad); }
.fv-vis-svg .fv-t-accent { fill: var(--fv-accent); }
.fv-vis-svg .fv-t-inv { fill: var(--fv-surface); }

/* ---------- SVG fills and strokes ---------- */

.fv-v-ok { fill: var(--fv-ok); }
.fv-v-warn { fill: var(--fv-warn); }
.fv-v-bad { fill: var(--fv-bad); }
.fv-v-accent { fill: var(--fv-accent); }
.fv-v-ink { fill: var(--fv-ink); }
.fv-v-dim { fill: var(--fv-dim); }
.fv-v-surface { fill: var(--fv-surface); }
.fv-v-alt { fill: var(--fv-surface-alt); }
.fv-v-track { fill: var(--fv-track); }
.fv-v-bg { fill: var(--fv-bg); }
.fv-v-okbg { fill: var(--fv-vis-okbg); }
.fv-v-warnbg { fill: var(--fv-vis-warnbg); }
.fv-v-badbg { fill: var(--fv-vis-badbg); }
.fv-v-accentbg { fill: var(--fv-accent-bg); }
.fv-v-none { fill: none; }

.fv-s-ok { stroke: var(--fv-ok); }
.fv-s-warn { stroke: var(--fv-warn); }
.fv-s-bad { stroke: var(--fv-bad); }
.fv-s-accent { stroke: var(--fv-accent); }
.fv-s-ink { stroke: var(--fv-ink); }
.fv-s-strong { stroke: var(--fv-line-strong); }
.fv-s-line { stroke: var(--fv-line); }
.fv-s-dim { stroke: var(--fv-dim); }
.fv-s-surface { stroke: var(--fv-surface); }
.fv-dash { stroke-dasharray: 4 3; }

/* ---------- Interactive items ---------- */

.fv-vis-hit {
  cursor: pointer;
}

.fv-vis-hit:focus {
  outline: none;
}

.fv-vis-hitbox {
  fill: transparent;
  stroke: none;
}

.fv-vis-hit:hover .fv-vis-hitbox,
.fv-vis-hit.is-active .fv-vis-hitbox {
  fill: var(--fv-vis-hover);
  stroke: var(--fv-accent);
  stroke-width: 1.5px;
  stroke-dasharray: 4 3;
}

.fv-vis-hit.is-pinned .fv-vis-hitbox {
  stroke-width: 2px;
  stroke-dasharray: none;
}

.fv-vis-scroll:focus-visible .fv-vis-hit.is-active .fv-vis-hitbox {
  fill: var(--fv-vis-hover);
  stroke: var(--fv-focus);
  stroke-width: 2.5px;
  stroke-dasharray: none;
}

.fv-vis-hit:hover .fv-vis-mark,
.fv-vis-hit.is-active .fv-vis-mark {
  stroke: var(--fv-ink);
  stroke-width: 2.5px;
  stroke-dasharray: none;
}

@media (prefers-reduced-motion: reduce) {
  .fv-vis-tooltip {
    transition: none;
  }
}

@media (forced-colors: active) {
  .fv-vis-hit.is-active .fv-vis-hitbox {
    stroke: Highlight;
  }
}

@media print {
  .fv-vis-card {
    break-inside: avoid;
  }

  .fv-vis-scroll {
    overflow: visible;
  }

  .fv-vis-svg {
    width: 100%;
    min-width: 0;
    max-height: none;
  }
}
