/**
 * PW – Three.js Engine — Shared 3D Viewer styles (PW3D)
 * v1.0.4
 *
 * Lifted verbatim from pw-production-workflow board.css (the board viewer
 * styles) so the customer viewer is pixel-identical to the board. .pw-hidden
 * is a global utility the board assumes exists; included here for the arrows.
 */
/* The engine tags whatever element the consumer passes to renderFileGrid with
   .pw-file-grid-host so the engine owns the containment. We clamp max-width and
   clip overflow, but deliberately do NOT set min-width:0 here — some hosts are
   flex items with their own min-width floor (e.g. the board's .pw-body-files has
   min-width:150px to keep the files column from collapsing). Forcing min-width:0
   would let that column collapse to zero. Clamping max-width + overflow is enough
   for the wrap inside to bound itself. */
.pw-file-grid-host {
    max-width: 100%;
    overflow: hidden;
}
.pw-file-grid {
    display: flex;
    gap: 6px;
    margin: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding-bottom: 4px;
    flex: 1;
    min-width: 0;
}
.pw-file-grid::-webkit-scrollbar {
    display: none;
}
.pw-file-grid-wrap {
    display: flex;
    align-items: stretch;
    margin: 8px 0 4px;
    position: relative;
    /* Width is set explicitly by JS (pwFitGrid) which measures the host's
       available content width on mount + on resize, then pins this wrap to it.
       This is container-agnostic by construction — works in the board's flex
       column and the cart's table cell identically, with no host CSS — and maps
       1:1 to the planned React <FileGrid> (measure-then-fit via ResizeObserver).
       Only the non-width bits live here; do not add a CSS width/min-width that
       would fight the measured value. */
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    gap: 6px;
}
.pw-file-grid-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    min-width: 28px;
    background: #e0e0e0;
    border: none;
    cursor: pointer;
    font-size: 12px;
    color: #50575e;
    transition: background 0.15s;
    z-index: 2;
    padding: 0;
    line-height: 1;
    border-radius: 6px;
}
.pw-file-grid-arrow:hover {
    background: #c3c4c7;
}
.pw-file-thumb {
    border-radius: 6px;
    overflow: hidden;
    border: 1.5px solid #3d3660;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #2a2540;
    flex-shrink: 0;
    width: 130px;
}
.pw-file-thumb:hover {
    border-color: #5a4fa0;
}
.pw-file-thumb--active {
    border-color: #7c6fd0;
    box-shadow: 0 0 0 1px rgba(124,111,208,0.3);
}
.pw-file-thumb-canvas {
    width: 100%;
    height: 80px;
    background: #F0EDE8;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pw-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.pw-file-thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}
.pw-ftp-ext {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
}
.pw-ftp-3d {
    background: rgba(110,200,160,0.25);
    color: #1d7a52;
}
.pw-ftp-img {
    background: rgba(120,180,230,0.25);
    color: #1a5a8a;
}
.pw-file-thumb-label {
    display: flex;
    align-items: center;
    padding: 3px 6px;
    gap: 4px;
    text-decoration: none;
    cursor: pointer;
}
.pw-file-thumb-label:hover {
    background: rgba(255,255,255,0.08);
}
.pw-file-thumb-label:hover .pw-ftl-name {
    color: #fff;
}
.pw-file-thumb-label:hover .pw-ftl-download {
    opacity: 1;
}
.pw-ftl-name {
    flex: 1;
    min-width: 0;
    font-size: 10px;
    color: #e0dce8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-decoration: none;
}
.pw-ftl-download {
    flex-shrink: 0;
    font-size: 12px;
    text-decoration: none;
    opacity: 0.4;
    transition: opacity 0.15s;
    line-height: 1;
}
.pw-ftl-download:hover {
    opacity: 1;
}

/* ── Large Viewer (shared, below grid) ───────────── */
.pw-file-viewer-large {
    max-width: 500px;
    aspect-ratio: 4 / 3;
    border-radius: 6px;
    overflow: hidden;
    background: #F0EDE8;
    margin: 6px 0 8px;
    position: relative;
}
.pw-body-files .pw-file-viewer-large {
    max-width: 100%;
}
.pw-file-viewer-large canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}
.pw-fv-image {
    max-width: 100%;
    max-height: 100%;
    display: block;
    margin: 0 auto;
    object-fit: contain;
}
.pw-fv-msg {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #666;
    font-size: 13px;
}

/* ── Progress Bar ────────────────────────────────── */
.pw-fv-progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 8px;
    padding: 20px;
}
.pw-fv-progress-label {
    font-size: 12px;
    color: #666;
}
.pw-fv-progress-track {
    width: 60%;
    max-width: 200px;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
    overflow: hidden;
}
.pw-fv-progress-bar {
    width: 0;
    height: 100%;
    background: #6ec8a0;
    border-radius: 3px;
    transition: width 0.2s;
}

/* ── 3D Preview Modal ─────────────────────────────── */
.pw-preview-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3vh 3vw;
}
.pw-preview-dialog {
    background: #fff;
    border-radius: 8px;
    width: 95vmin;
    height: 95vmin;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.pw-preview-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid #e0e0e0;
    flex-shrink: 0;
}
.pw-preview-title {
    font-weight: 600;
    font-size: 15px;
    color: #1d2327;
}
.pw-preview-counter {
    font-size: 13px;
    color: #888;
    margin-left: auto;
}
.pw-preview-close {
    background: none;
    border: none;
    font-size: 20px;
    color: #888;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    margin-left: 8px;
}
.pw-preview-close:hover { color: #333; }
.pw-preview-body {
    display: flex;
    flex: 1;
    min-height: 0;
}
.pw-preview-sidebar {
    width: 12vw;
    min-width: 90px;
    max-width: 130px;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.pw-preview-arrow {
    width: 100%;
    height: 36px;
    border: none;
    background: #f5f5f5;
    color: #666;
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
}
.pw-preview-arrow:hover { background: #e8e8e8; }
.pw-preview-arrow--up { border-bottom: 1px solid #e0e0e0; }
.pw-preview-arrow--down { border-top: 1px solid #e0e0e0; }
.pw-preview-thumbstrip {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
}
.pw-preview-thumbstrip::-webkit-scrollbar { width: 0; }
.pw-preview-thumb {
    border: 2px solid transparent;
    border-radius: 6px;
    background: #f5f0eb;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 4px 4px;
    flex-shrink: 0;
    aspect-ratio: 1;
}
.pw-preview-thumb:hover { border-color: #c3c4c7; }
.pw-preview-thumb--active { border-color: #2271b1; }
.pw-preview-thumb-img {
    width: 100%;
    height: auto;
    max-height: 70%;
    object-fit: contain;
    border-radius: 3px;
}
.pw-preview-thumb-ext {
    font-size: 11px;
    font-weight: 600;
    color: #888;
    flex: 1;
    display: flex;
    align-items: center;
}
.pw-preview-thumb-name {
    font-size: 9px;
    color: #666;
    text-align: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    width: 100%;
    margin-top: auto;
}
.pw-preview-viewer {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}
.pw-preview-viewer-inner {
    flex: 1;
    background: #F0EDE8;
    min-height: 0;
    position: relative;
}
.pw-preview-viewer-inner canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}
.pw-preview-viewer-inner .pw-fv-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.pw-preview-viewer-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-top: 1px solid #e0e0e0;
    font-size: 12px;
    flex-shrink: 0;
}
.pw-preview-filename {
    color: #444;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pw-preview-download {
    color: #2271b1;
    text-decoration: none;
    white-space: nowrap;
    font-weight: 500;
}
.pw-preview-download:hover { text-decoration: underline; }

/* (The global .pw-hidden utility was removed: the grid arrows use the scoped
   .pw-file-grid-arrow.pw-arrow-hidden below, and a global display:none rule would
   leak onto other plugins' elements — e.g. the board's station-tab arrows and
   .pw-manager-detail — now that the board loads this engine stylesheet. Each
   consumer keeps its own scoped hide rules; the engine ships only viewer-scoped CSS.) */
/* Arrow hide must KEEP the arrow's 28px slot (visibility, not display:none) so the
   grid doesn't reflow wider when an arrow disappears at a scroll end — otherwise the
   thumbnails shift over into where the arrow was, right under the cursor, and you
   accidentally click the last thumbnail. Arrow-specific so it doesn't touch the
   global .pw-hidden utility. */
.pw-file-grid-arrow.pw-arrow-hidden { visibility: hidden; pointer-events: none; }
