/*
 * CANLOW factory image viewer.
 * The controller supplies original source dimensions in pixels and transforms
 * only .cfv-stage. The source image and overlay share those dimensions.
 * Native <dialog> visibility belongs to showModal()/close(); CSS never opens it.
 */

.cfv,
.cfv-large-dialog {
  --cfv-background: #080d0e;
  --cfv-panel: #101919;
  --cfv-panel-raised: #142020;
  --cfv-text: #eff5f0;
  --cfv-muted: #a1aeaa;
  --cfv-accent: #b8f64f;
  --cfv-border: #253230;
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  color: var(--cfv-text);
  background: var(--cfv-panel);
  border: 1px solid var(--cfv-border);
  border-radius: 12px;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.factory-step-media {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  min-width: 0;
}

.factory-step-media[hidden] { display: none; }

.factory-step-media-item {
  min-width: 0;
  max-width: 100%;
}

.factory-step-media > .notice {
  padding: 24px 20px;
  color: #a1aeaa;
  background: #101919;
  border: 1px solid #253230;
  border-radius: 12px;
  overflow-wrap: anywhere;
}

.cfv *,
.cfv *::before,
.cfv *::after,
.cfv-large-dialog *,
.cfv-large-dialog *::before,
.cfv-large-dialog *::after {
  box-sizing: border-box;
}

.cfv-heading {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px 18px;
  min-width: 0;
  padding: 20px 22px 16px;
}

.cfv-heading > div {
  min-width: 0;
  flex: 1 1 220px;
}

.cfv-heading :is(h2, h3) {
  margin: 0;
  color: var(--cfv-text);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.cfv-heading :is(p, small) {
  display: block;
  margin: 6px 0 0;
  color: var(--cfv-muted);
  font-size: 12px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.cfv-status {
  flex: 0 1 auto;
  max-width: 100%;
  padding: 5px 9px;
  color: var(--cfv-muted);
  background: var(--cfv-panel-raised);
  border: 1px solid var(--cfv-border);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.cfv-status.is-verified {
  color: var(--cfv-accent);
  border-color: #496137;
}

.cfv-status.is-pending {
  color: #dfc187;
  border-color: #514530;
}

.cfv-toolbar,
.cfv-toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.cfv-toolbar {
  padding: 12px 22px;
  background: var(--cfv-background);
  border-top: 1px solid var(--cfv-border);
}

.cfv-toolbar button,
.cfv-contact-buttons button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  max-width: 100%;
  margin: 0;
  padding: 10px 13px;
  color: var(--cfv-text);
  background: var(--cfv-panel-raised);
  border: 1px solid var(--cfv-border);
  border-radius: 7px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  overflow-wrap: anywhere;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.cfv-toolbar button:hover,
.cfv-contact-buttons button:hover {
  background: #1a2923;
  border-color: #627b48;
}

.cfv-toolbar button:active,
.cfv-contact-buttons button:active {
  background: #22331b;
}

.cfv-toolbar button:focus-visible,
.cfv-contact-buttons button:focus-visible,
.cfv-large-dialog .cfv-close:focus-visible {
  outline: 2px solid var(--cfv-accent);
  outline-offset: 3px;
}

.cfv-toolbar button:disabled,
.cfv-contact-buttons button:disabled {
  opacity: .42;
  cursor: default;
}

.cfv-toolbar button:disabled:hover,
.cfv-contact-buttons button:disabled:hover {
  background: var(--cfv-panel-raised);
  border-color: var(--cfv-border);
}

.cfv-toolbar button svg,
.cfv-contact-buttons button svg {
  display: block;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
}

.cfv-toolbar [data-cfv-action="zoom-in"],
.cfv-toolbar [data-cfv-action="zoom-out"] {
  flex: 0 0 44px;
  width: 44px;
  padding: 10px;
}

.cfv-toolbar [data-cfv-action="large"] {
  margin-left: auto;
}

.cfv-zoom-status {
  min-width: 48px;
  color: var(--cfv-muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.cfv-toolbar-label {
  flex: 1 1 150px;
  min-width: 0;
  color: var(--cfv-muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.cfv-viewport {
  position: relative;
  width: 100%;
  min-width: 0;
  height: clamp(280px, 45vw, 520px);
  overflow: hidden;
  background: #fff;
  border-top: 1px solid var(--cfv-border);
  border-bottom: 1px solid var(--cfv-border);
  cursor: grab;
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-tap-highlight-color: transparent;
}

.cfv-viewport.is-grabbing,
.cfv-viewport.is-panning,
.cfv-viewport:active {
  cursor: grabbing;
}

.cfv-viewport:focus-visible {
  outline: 2px solid var(--cfv-accent);
  outline-offset: -3px;
}

.cfv-stage {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--cfv-source-width, max-content);
  height: var(--cfv-source-height, max-content);
  max-width: none;
  max-height: none;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-select: none;
}

.cfv-source-image {
  position: relative;
  z-index: 1;
  display: block;
  width: var(--cfv-source-width, auto);
  height: var(--cfv-source-height, auto);
  min-width: 0;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  image-rendering: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
}

.cfv-overlay {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  max-width: none;
  overflow: visible;
  pointer-events: none;
}

.cfv-overlay :is(path, line, polyline, polygon, circle, ellipse, rect) {
  vector-effect: non-scaling-stroke;
}

.cfv-hotspot,
.cfv-hotspot :is(path, line, polyline, polygon, circle, ellipse, rect) {
  fill: transparent;
  stroke: transparent;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  pointer-events: all;
  cursor: pointer;
}

.cfv-hotspot {
  outline: none;
}

.cfv-hotspot:is(:hover, :focus-visible, .is-selected, [aria-pressed="true"]),
.cfv-hotspot:is(:hover, :focus-visible, .is-selected, [aria-pressed="true"]) :is(path, line, polyline, polygon, circle, ellipse, rect) {
  fill: transparent;
  stroke: var(--cfv-accent);
  stroke-width: 2.5;
}

.cfv-hotspot:focus-visible,
.cfv-hotspot:focus-visible :is(path, line, polyline, polygon, circle, ellipse, rect) {
  stroke-width: 3;
  stroke-dasharray: 5 3;
}

/* Hit regions are interaction only. Visible marks are separate geometry. */
.cfv-hitbox {
  fill: transparent !important;
  stroke: none !important;
  stroke-width: 0 !important;
  pointer-events: all;
}

/* Keyboard focus uses the same protected external corners, never the hit rect. */
.cfv-hotspot .cfv-focus-mark {
  display: none;
  fill: none !important;
  stroke: var(--cfv-accent);
  pointer-events: none !important;
}

.cfv-hotspot:focus-visible .cfv-focus-mark {
  display: block;
}

.cfv-ru-label,
.cfv-ru-label *,
.cfv-selection-mark {
  pointer-events: none;
}

.cfv-caption {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 7px 16px;
  min-width: 0;
  padding: 14px 22px;
  color: var(--cfv-muted);
  font-size: 12px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.cfv-caption p {
  margin: 0;
}

.cfv-caption strong {
  color: var(--cfv-text);
  font-weight: 600;
}

.cfv-contact-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
  padding: 0 22px 18px;
}

.cfv-contact-buttons button {
  flex: 1 1 140px;
  justify-content: flex-start;
  text-align: left;
}

.cfv-contact-buttons button:is(.is-selected, [aria-pressed="true"]) {
  color: var(--cfv-accent);
  background: #1a2918;
  border-color: #627b48;
}

.cfv-contact-buttons button > span {
  min-width: 0;
}

.cfv-contact-buttons button :is(strong, small) {
  display: block;
}

.cfv-contact-buttons button strong {
  font-size: 12px;
  font-weight: 700;
}

.cfv-contact-buttons button small {
  margin-top: 3px;
  color: var(--cfv-muted);
  font-size: 11px;
  font-weight: 400;
  line-height: 1.5;
}

.cfv-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  min-width: 0;
  padding: 14px 22px;
  color: var(--cfv-muted);
  background: var(--cfv-background);
  border-top: 1px solid var(--cfv-border);
  border-radius: 0 0 11px 11px;
  font-size: 11px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.cfv-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.cfv-legend-swatch {
  flex: 0 0 16px;
  width: 16px;
  height: 12px;
  border: 2px solid var(--cfv-accent);
  border-radius: 3px;
  background: transparent;
}

.cfv-empty,
.cfv-error {
  min-width: 0;
  padding: 32px 22px;
  color: var(--cfv-muted);
  background: var(--cfv-panel);
  text-align: center;
  overflow-wrap: anywhere;
}

.cfv-empty :is(h2, h3),
.cfv-error :is(h2, h3) {
  margin: 0 0 9px;
  color: var(--cfv-text);
  font-size: 17px;
  line-height: 1.45;
}

.cfv-empty p,
.cfv-error p {
  max-width: 460px;
  margin: 0 auto;
  font-size: 13px;
  line-height: 1.8;
}

.cfv-error {
  border-top: 1px solid #514530;
}

.cfv-large-dialog {
  width: min(1400px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  overflow: auto;
  box-shadow: 0 25px 100px #0009;
}

.cfv-large-dialog::backdrop {
  background: #030806df;
}

.cfv-large-dialog .cfv-viewport {
  height: clamp(320px, 68dvh, 840px);
}

.cfv-large-dialog > .cfv-heading {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--cfv-panel);
  border-bottom: 1px solid var(--cfv-border);
}

.cfv-large-dialog .cfv-close {
  display: inline-flex;
  flex: 0 0 44px;
  justify-content: center;
  align-items: center;
  width: 44px;
  min-height: 44px;
  padding: 10px;
  color: var(--cfv-text);
  background: var(--cfv-panel-raised);
  border: 1px solid var(--cfv-border);
  border-radius: 7px;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.cfv-large-dialog .cfv-close:hover {
  border-color: #627b48;
}

.cfv-large-dialog .cfv-close svg {
  display: block;
  width: 18px;
  height: 18px;
}

@media (max-width: 760px) {
  .cfv-heading {
    padding: 17px 15px 14px;
    gap: 10px;
  }

  .cfv-heading :is(h2, h3) {
    font-size: 15px;
  }

  .cfv-toolbar {
    padding: 10px 12px;
    gap: 7px;
  }

  .cfv-toolbar button {
    padding-inline: 11px;
    font-size: 11px;
  }

  .cfv-toolbar-label {
    flex-basis: 100%;
    font-size: 11px;
  }

  .cfv-caption {
    padding: 12px 15px;
    font-size: 11px;
  }

  .cfv-contact-buttons {
    padding: 0 15px 15px;
    gap: 7px;
  }

  .cfv-contact-buttons button {
    flex-basis: 125px;
    padding: 10px;
  }

  .cfv-legend {
    padding: 12px 15px;
  }

  .cfv-empty,
  .cfv-error {
    padding: 26px 16px;
  }

  .cfv-large-dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: 10px;
  }

  .cfv-large-dialog .cfv-viewport {
    height: clamp(240px, 60dvh, 660px);
  }
}

@media (max-width: 360px) {
  .cfv-toolbar [data-cfv-action="large"] {
    flex: 1 1 100%;
    margin-left: 0;
  }

  .cfv-contact-buttons button {
    flex-basis: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cfv-stage {
    scroll-behavior: auto;
  }
}
