/* ============================================================================
 * Gerber layer view (frontend/js/files/gerber-view.js).
 *
 * The canvas is KiCad's; everything on it is the page's own: the Display
 * panel is the 3D viewer's (.trame-in-content .trame-file-list with its
 * .trame-rail-collapse bar, and the rows of #sceneTree through the
 * .display-rows class those rules also match), and the row of buttons is the
 * image preview's.
 * ========================================================================== */

/* The pane holds the view edge to edge (a text file's pane scrolls instead). */
.file-content-body:has(> .gerber-view) {
  display: flex !important;
  flex-direction: column;
  overflow: hidden !important;
}

.gerber-view {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
}

.gerber-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* A file of the folder that could not be drawn. */
.gerber-left {
  min-width: 0;
  padding-bottom: 8px;
  color: var(--b2-ink-3, #6B7280);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gerber-frame {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

/* KiCad's canvas runs under the panel; the board keeps clear of it. */
.gerber-viewport {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 320px;
  box-sizing: border-box;
  padding-right: 248px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 8px;
  cursor: grab;
  touch-action: none;
  outline: none;
}
.gerber-viewport:focus-visible { box-shadow: 0 0 0 2px var(--b2-acc-focus, rgba(42,120,214,0.22)); }
.gerber-viewport.gerber-grab { cursor: grabbing; }

.gerber-stage {
  flex: 0 0 auto;
  transform-origin: 50% 50%;
  will-change: transform;
}
.gerber-svg { display: block; width: 100%; height: 100%; }
.gerber-defs { position: absolute; }

/* ---- the Display panel, floating over the canvas as over the 3D view ---- */
.gerber-panel-wrap {
  position: absolute !important;
  top: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  display: block !important;
  width: var(--gerber-panel-w, 228px);
  height: auto !important;
  flex: none !important;
  overflow: visible !important;
  background: none !important;
  pointer-events: none;
}
.gerber-panel-wrap .trame-file-list.gerber-panel {
  position: static !important;
  display: flex !important;
  flex-direction: column;
  width: var(--gerber-panel-w, 228px) !important;
  min-width: var(--gerber-panel-w, 228px) !important;
  height: auto !important;
  max-height: 100% !important;
  flex: none !important;
  overflow: auto;
  pointer-events: auto;
  background: var(--b2-surface, #fff);
  border: 1px solid var(--b2-line, #E5E7EB) !important;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(17, 18, 22, 0.18);
}
/* The panel moves by its bar (the move cursor comes with the bar's own styles);
   frontend/js/files/gerber-view.js sets where it stands. */
/* Its two upright edges set its width (--gerber-panel-w): the 3D view's
   handles, here beside the panel in its wrap, as tall as the panel. */
.gerber-panel-wrap .gerber-panel-edge {
  top: 0;
  pointer-events: auto;
}
.gerber-panel-wrap .gerber-panel-edge.trame-rail-resize-left { left: -3.5px; }
.gerber-panel-wrap .gerber-panel-edge.trame-rail-resize-right { right: -3.5px; }
.gerber-panel.is-collapsed .gerber-panel-body { display: none; }

.gerber-panel .gerber-row {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.gerber-panel .gerber-row.selected { background: var(--b2-acc-soft, rgba(42,120,214,0.10)); }
.gerber-panel .gerber-row.selected .file-name {
  color: var(--b2-ink, #111216);
  font-weight: 600;
}
/* The layers while the finished board is shown instead. */
.gerber-panel .gerber-row.gerber-muted { opacity: 0.45; }

.gerber-swatch {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  margin-right: 7px;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(17, 18, 22, 0.16);
}

.gerber-inactive {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 !important;
  padding: 8px 10px !important;
  border-top: 1px solid var(--b2-line, #E5E7EB);
  background: var(--b2-surface, #fff);
}
.gerber-inactive .slice-label { margin: 0; white-space: nowrap; }
.gerber-inactive select { flex: 0 0 auto; width: auto; min-width: 92px; }

/* ---- the image preview's row of buttons -----------------------------------
 * Same markup and class names as that row. Its own rules are not in the
 * page's styles yet, so the ones this view needs are here, under .gerber-view
 * only; they go when the row's rules arrive.
 * ------------------------------------------------------------------------ */
.gerber-view .file-preview-zoom {
  display: flex;
  flex: 0 0 auto;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  padding-bottom: 8px;
}
.gerber-view .file-preview-zoom button {
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid #DADDE3;
  border-radius: 7px;
  background: var(--b2-surface, #fff);
  color: #1F2937;
  font-size: 12px;
  cursor: pointer;
}
.gerber-view .file-preview-zoom button:hover:not(:disabled) { background: #F3F4F6; }
.gerber-view .file-tool-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.gerber-view .file-tool-icon svg {
  width: 18px;
  height: 18px;
  flex: none;
  stroke-width: 1.9;
}
.gerber-view .file-preview-zoom .file-tool-icon {
  width: 30px;
  min-width: 30px;
  padding: 0;
}
.gerber-view .file-preview-zoom-pair { display: inline-flex; }
.gerber-view .file-preview-zoom-pair button:first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.gerber-view .file-preview-zoom-pair button:last-child {
  margin-left: -1px;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.gerber-view .file-preview-zoom-pair button:hover:not(:disabled) { position: relative; }
/* the pen while marking is on */
.gerber-view .file-preview-zoom button.is-on {
  background: #E8EEF9;
  color: #1D5FBF;
  border-color: #BFD3F2;
}
/* The zoom level, for a moment after a change of zoom (frontend/js/files/
   gerber-view.js flashZoomLevel). The same chip as the image and document
   previews show; these rules go when theirs are in the page's styles. */
.gerber-view .file-zoom-level {
  position: fixed;
  z-index: 1200;
  transform: translate(-100%, -50%);
  padding: 3px 9px;
  border: 1px solid #DADDE3;
  border-radius: 7px;
  background: var(--white, #FFFFFF);
  color: #1F2937;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 6px rgba(17, 18, 22, 0.10);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease-out;
}
.gerber-view .file-zoom-level.is-shown {
  opacity: 1;
  transition-duration: 60ms;
}
