/* The 3D viewer of the client portal (portal/viewer.js) – designed for a phone first: the scene on top, the sheet
   with the size and the price of a carcass under it; on a wide screen the sheet stands beside the scene.
   Light and dark by the tokens below (the viewer sets data-theme on its root); the accent is the workshop's – a page
   sets --pv-accent on the viewer or above it. Nothing is loaded from another server.
   Source of truth: docs/view_model_reference.md, section 7 */

@font-face {
  font-family: "Inter Tight";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../vendor/inter-tight/inter-tight-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter Tight";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url("../vendor/inter-tight/inter-tight-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

.pv {
  /* (The accent is the page's when it sets one – the colour of the workshop –, else the portal's own.) */
  --pv-accent: var(--portal-accent, #0b63ce);
  --pv-accent-ink: var(--portal-accent-ink, #ffffff);
  --pv-text: #1e2228;
  --pv-muted: #5d6570;
  --pv-line: #d5dae1;
  --pv-surface: #ffffff;
  --pv-raised: rgba(255, 255, 255, 0.94);
  --pv-stage-top: #dde3ea;
  --pv-stage-bottom: #f4f5f7;
  --pv-shadow: 0 2px 10px rgba(20, 28, 40, 0.14);
  --pv-halo: #ffffff;
  --pv-note: #b26a00;
  --cube-face: rgba(250, 251, 252, 0.94);
  --cube-edge: #9aa3ae;
  --pv-radius: 12px;
  --pv-font: "Inter Tight", system-ui, -apple-system, "Segoe UI", sans-serif;

  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  color: var(--pv-text);
  background: var(--pv-surface);
  font-family: var(--pv-font);
  font-size: 15px;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.pv[data-theme="dark"] {
  --pv-accent: var(--portal-accent, #4d95ea);
  --pv-accent-ink: var(--portal-accent-ink, #0d1116);
  --pv-text: #e5e8ec;
  --pv-muted: #a0a8b3;
  --pv-line: #3a4049;
  --pv-surface: #1d2025;
  --pv-raised: rgba(38, 42, 49, 0.94);
  --pv-stage-top: #2d3239;
  --pv-stage-bottom: #17191d;
  --pv-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  --pv-halo: #111316;
  --pv-note: #f0b54a;
  --cube-face: rgba(52, 56, 64, 0.94);
  --cube-edge: #7c8591;
}

.pv *,
.pv *::before,
.pv *::after {
  box-sizing: border-box;
}

.pv button {
  font: inherit;
  color: inherit;
}

.pv [hidden] {
  display: none !important;
}

/* ----- The stage: the canvas and what lies over it ----- */

.pv-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(var(--pv-stage-top), var(--pv-stage-bottom));
}

.pv-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

.pv-stage canvas:active {
  cursor: grabbing;
}

.pv.is-measuring .pv-stage canvas {
  cursor: crosshair;
}

.pv-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.pv-measure-halo {
  stroke: var(--pv-halo);
  stroke-width: 5;
  stroke-linecap: round;
  opacity: 0.85;
}

.pv-measure-line {
  stroke: var(--pv-accent);
  stroke-width: 2.25;
  stroke-linecap: round;
}

.pv-mark {
  fill: var(--pv-accent);
  stroke: var(--pv-halo);
  stroke-width: 2;
}

.pv-mark.is-hover {
  fill: none;
  stroke: var(--pv-accent);
  stroke-width: 2.25;
}

.pv-measure-label {
  position: absolute;
  top: 0;
  left: 0;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--pv-accent);
  color: var(--pv-accent-ink);
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--pv-shadow);
}

/* What an active tool says: over the tools at the bottom of the stage – never over the middle of the scene, and
   where a thumb ends the tool. */
.pv-tray {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 72px;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 470px;
  margin: 0 auto;
  padding: 7px 7px 7px 12px;
  border: 1px solid var(--pv-line);
  border-radius: var(--pv-radius);
  background: var(--pv-raised);
  box-shadow: var(--pv-shadow);
  font-size: 13.5px;
}

.pv-tray-text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.pv-tray-text strong {
  font-size: 15px;
}

.pv-tray-text span {
  color: var(--pv-muted);
}

.pv-tray-more {
  font-size: 12.5px;
}

.pv-tray-end {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--pv-line);
  border-radius: 10px;
  background: var(--pv-surface);
  cursor: pointer;
}

/* What a page pins to points of the model (the comments of the client): a small bubble with their count. */
.pv-marks {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.pv-badge {
  position: absolute;
  top: 0;
  left: 0;
  min-width: 28px;
  height: 28px;
  padding: 0 7px;
  border: 2px solid var(--pv-halo);
  border-radius: 14px 14px 14px 3px;
  background: var(--pv-accent);
  color: var(--pv-accent-ink);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  box-shadow: var(--pv-shadow);
  cursor: pointer;
  pointer-events: auto;
}

/* (A finger needs more than 28 px.) */
.pv-badge::after {
  position: absolute;
  inset: -9px;
  content: "";
}

.pv-badge.is-done {
  background: var(--pv-muted);
  color: var(--pv-surface);
}

.pv.is-measuring .pv-badge {
  opacity: 0.45;
  pointer-events: none;
}

/* The corner of the view: the cube and the way of looking under it. */
.pv-corner {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  justify-items: center;
  gap: 0;
}

.pv-mode {
  min-height: 30px;
  margin-top: -6px;
  padding: 0 10px;
  border: 1px solid var(--pv-line);
  border-radius: 999px;
  background: var(--pv-raised);
  color: var(--pv-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

/* The view cube (src/viewer_cube.js draws it; its rules are those of the desktop app in the tokens of this page). */
.view-cube {
  position: relative;
  width: 144px;
  height: 132px;
  cursor: grab;
  touch-action: none;
}

.view-cube.is-turning {
  cursor: grabbing;
}

.view-cube-scene {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
}

.view-cube-box {
  position: absolute;
  transform-style: preserve-3d;
}

.view-cube-face {
  position: absolute;
  top: -38px;
  left: -38px;
  display: grid;
  grid-template: 15px 1fr 15px / 15px 1fr 15px;
  width: 76px;
  height: 76px;
  border: 1px solid var(--cube-edge);
  background: var(--cube-face);
  backface-visibility: hidden;
}

.view-cube-cell {
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--pv-muted);
  font-family: var(--pv-font);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: inherit;
}

.pv .view-cube-cell {
  color: var(--pv-muted);
}

.view-cube-face.is-facing .view-cube-cell.is-face {
  color: var(--pv-text);
}

.pv .view-cube-cell.is-hot {
  background: var(--pv-accent);
  color: var(--pv-accent-ink);
}

.view-cube-axes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.view-cube-axis {
  stroke-width: 1.6;
  stroke-linecap: round;
}

.view-cube-axis-label {
  font-family: var(--pv-font);
  font-size: 9px;
  font-weight: 700;
  text-anchor: middle;
}

.view-cube-axis.is-x { stroke: #e5484d; }
.view-cube-axis.is-y { stroke: #30a46c; }
.view-cube-axis.is-z { stroke: #3b82f6; }
.view-cube-axis-label.is-x { fill: #e5484d; }
.view-cube-axis-label.is-y { fill: #30a46c; }
.view-cube-axis-label.is-z { fill: #3b82f6; }

/* The tools: at the bottom of the stage, within reach of a thumb. */
.pv-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  display: flex;
  justify-content: center;
  padding: 0 10px;
  pointer-events: none;
}

.pv-tools {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--pv-line);
  border-radius: 14px;
  background: var(--pv-raised);
  box-shadow: var(--pv-shadow);
  pointer-events: auto;
}

.pv-tool {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 13px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.pv-tool.is-on {
  background: var(--pv-accent);
  color: var(--pv-accent-ink);
}

.pv-icon {
  flex: none;
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pv button:focus-visible {
  outline: 2px solid var(--pv-accent);
  outline-offset: 2px;
}

/* ----- The sheet: the whole assembly, or the selected carcass ----- */

.pv-sheet {
  min-height: 0;
  max-height: 40vh;
  overflow-y: auto;
  border-top: 1px solid var(--pv-line);
  background: var(--pv-surface);
  overscroll-behavior: contain;
}

.pv-card {
  display: grid;
  gap: 8px;
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom, 0px));
}

.pv-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pv-back {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  margin-left: -8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

.pv-kicker {
  margin: 0;
  color: var(--pv-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pv-title {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.2;
}

.pv-dims {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px 10px;
  margin: 0;
}

.pv-dims dt {
  grid-row: 1;
  color: var(--pv-muted);
  font-size: 12.5px;
}

.pv-dims dd {
  grid-row: 2;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.pv-facts {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 8px;
  margin: 0;
}

.pv-facts strong {
  font-size: 17px;
}

.pv-facts span {
  color: var(--pv-muted);
  font-size: 12.5px;
}

.pv-price {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  padding: 8px 12px;
  border: 1px solid var(--pv-line);
  border-radius: var(--pv-radius);
}

.pv-price-label {
  color: var(--pv-muted);
  font-size: 13px;
}

.pv-price-value {
  font-size: 22px;
  font-weight: 800;
}

.pv-price-note {
  color: var(--pv-muted);
  font-size: 13px;
}

.pv-note,
.pv-hint {
  flex-basis: 100%;
  margin: 0;
  color: var(--pv-muted);
  font-size: 13px;
}

/* The carcasses: on a phone a row that is swiped, on a wide screen a list. */
.pv-list {
  display: flex;
  gap: 8px;
  margin: 0 -14px;
  padding: 2px 14px 4px;
  overflow-x: auto;
  list-style: none;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}

.pv-list li {
  flex: none;
  scroll-snap-align: start;
}

.pv-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 2px 9px;
  min-width: 132px;
  max-width: 210px;
  min-height: 52px;
  padding: 7px 12px 7px 8px;
  border: 1px solid var(--pv-line);
  border-radius: var(--pv-radius);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.pv-row-number {
  display: grid;
  grid-row: 1 / span 2;
  place-items: center;
  min-width: 30px;
  height: 30px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--pv-line);
  font-size: 13.5px;
  font-weight: 700;
}

.pv-row-name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pv-row-price {
  grid-column: 2;
  color: var(--pv-muted);
  font-size: 13px;
}

.pv-row-price.is-optional {
  font-style: italic;
}

/* A phone in a narrow window: the tools without their words would be a riddle – they keep them, smaller. */
@media (max-width: 400px) {
  .pv-tool {
    gap: 5px;
    padding: 0 9px;
    font-size: 13px;
  }

  .pv-corner {
    transform: scale(0.86);
    transform-origin: top right;
  }

}

/* What the page adds to the sheet (the comments of the client). */
.pv-extra {
  min-width: 0;
}

/* A phone: what the tray says fits two lines. */
@media (max-width: 600px) {
  .pv-tray-more {
    display: none;
  }
}

/* A wide screen: the sheet stands beside the scene. */
@media (min-width: 860px) {
  .pv {
    grid-template-columns: minmax(0, 1fr) 340px;
    grid-template-rows: minmax(0, 1fr);
  }

  .pv-sheet {
    max-height: none;
    border-top: 0;
    border-left: 1px solid var(--pv-line);
  }

  .pv-card {
    gap: 14px;
    padding: 18px;
  }

  .pv-list {
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  .pv-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
    width: 100%;
    max-width: none;
    min-height: 44px;
  }

  .pv-row-number {
    grid-row: 1;
  }

  .pv-row-price {
    grid-column: 3;
    color: var(--pv-text);
    font-weight: 600;
  }

  .pv-price-label {
    flex-basis: 100%;
  }

  .pv-facts {
    flex-direction: column;
  }

  .pv-row:hover {
    border-color: var(--pv-accent);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .pv-tool,
  .pv-row {
    transition: background-color 0.12s, border-color 0.12s;
  }
}
