/* Door Finish Visualizer (owner, 6 Nov 2026). Loaded only by
   apps/portal/door-visualizer.html, on top of the shared quick-tools.css, so
   every rule is scoped to this tool's own classes and changing it never moves
   another quick tool's cache token. */

body[data-tool="door-visualizer"] .tool-shell {
  width: min(1320px, calc(100vw - 32px));
}

.door-visualizer-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.door-visualizer-controls label {
  margin: 4px 0;
}

.door-visualizer-controls output {
  float: right;
  color: var(--ink);
  text-transform: none;
}

.door-visualizer-segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--soft-2);
}

.door-visualizer-segmented button {
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.door-visualizer-segmented button.active {
  background: #ffffff;
  box-shadow: 0 4px 14px rgba(24, 33, 31, 0.12);
}

.door-visualizer-size-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.door-visualizer-note {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.35;
  text-transform: none;
}

#doorVisualizerRailsNote.warn {
  color: var(--danger);
  font-weight: 700;
}

.door-visualizer-preview {
  min-width: 0;
}

.door-visualizer-preview h2 {
  margin: 0;
  font-size: 18px;
}

.door-visualizer-preview-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.door-visualizer-preview-header p {
  margin: 6px 0 0;
}

.door-visualizer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.door-visualizer-style-note {
  padding: 8px 10px;
  border: 1px solid #e8d6b8;
  background: #fbf3e4;
  color: #6b5233;
  font-size: 13px;
}

/* Zoomable preview: the canvas is scaled and moved with a CSS transform, then
   re-rendered at the new resolution once the zoom settles. */
.door-visualizer-canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 55vh;
  overflow: hidden;
  border: 1px solid var(--line);
  background: linear-gradient(135deg, #f4efe6, #ffffff);
  touch-action: none;
  user-select: none;
}

.door-visualizer-canvas-wrap canvas {
  display: block;
  width: min(100%, 900px);
  height: auto;
  aspect-ratio: 1;
  transform-origin: 0 0;
  cursor: zoom-in;
}

.door-visualizer-canvas-wrap.zoomed canvas {
  cursor: grab;
}

.door-visualizer-canvas-wrap.dragging canvas {
  cursor: grabbing;
}

.door-visualizer-canvas-wrap.needs-connection canvas {
  visibility: hidden;
}

.door-visualizer-connection {
  position: absolute;
  inset: auto 24px 50% 24px;
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
  text-align: center;
}

.door-visualizer-zoom-bar {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.door-visualizer-zoom-bar button {
  min-width: 36px;
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.door-visualizer-zoom-hint {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  pointer-events: none;
}

/* Tablets (owner, 10 Nov 2026: "you can't see the control section along with
   the picture"). Up to 1280 px wide, and on any touch screen, the controls and
   the whole picture fit the window together: the page's top is tighter, the
   picture is no taller than the window leaves for it, and the preview stays in
   view beside the controls while they scroll. Wider desktops keep the layout
   above unchanged. */
@media (max-width: 1280px), (pointer: coarse) {
  body[data-tool="door-visualizer"] .tool-shell {
    padding-top: 12px;
  }

  body[data-tool="door-visualizer"] .tool-intro {
    margin-top: 12px;
    margin-bottom: 10px;
  }

  body[data-tool="door-visualizer"] .tool-intro .eyebrow {
    display: none;
  }

  body[data-tool="door-visualizer"] .tool-intro h1 {
    font-size: 28px;
  }

  .door-visualizer-grid {
    grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
    gap: 12px;
  }

  .door-visualizer-grid .tool-card-body {
    gap: 10px;
    padding: 14px;
  }

  /* The controls, tighter (the 44 px touch targets stay), and never taller
     than the window leaves below where they start: --door-controls-room is
     measured by the page module (fitPreviewToWindow). In a short window, or
     where the system font sets the notes taller (Linux sets them about 18 px
     taller than Windows), the controls scroll inside their card instead of
     running past the bottom (Coordinator, 10 Nov 2026: 14 px over at
     1385 x 780). */
  .door-visualizer-controls .tool-card-body {
    gap: 8px;
  }

  .door-visualizer-controls label {
    margin: 0;
  }

  .door-visualizer-controls {
    max-height: var(--door-controls-room, none);
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .door-visualizer-preview {
    position: sticky;
    top: 8px;
  }

  .door-visualizer-canvas-wrap {
    min-height: 0;
  }

  /* --door-preview-room is the window height left below where the picture
     starts, measured by the page module (fitPreviewToWindow) because the
     preview heading grows with its notes. Before it is measured, 250 px is the
     page above the picture at its tightest. The picture never goes below 280 px. */
  .door-visualizer-canvas-wrap canvas {
    width: min(100%, 900px, max(280px, var(--door-preview-room, calc(100vh - 250px))));
  }
}

@media (max-width: 699px) {
  .door-visualizer-grid {
    grid-template-columns: 1fr;
  }

  .door-visualizer-preview {
    position: static;
  }

  /* One column: the page scrolls, so the controls take their full height. */
  .door-visualizer-controls {
    max-height: none;
    overflow-y: visible;
  }

  /* One column: the picture sits under the controls and takes the full width,
     as before the tablet block. */
  .door-visualizer-canvas-wrap canvas {
    width: min(100%, 900px);
  }

  .door-visualizer-preview-header {
    flex-direction: column;
  }
}

@media (max-width: 760px) {
  body[data-tool="door-visualizer"] .tool-shell {
    width: 100%;
  }

  .door-visualizer-canvas-wrap {
    min-height: 0;
  }
}
