/* ============================
   SETUP DESIGNER
   Loaded after style.css; reuses its theme variables.
   ============================ */
.designer {
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
}

.designer-intro h1 {
  margin: 0 0 0.25rem;
}

.designer-intro p {
  max-width: 600px;
  margin: 0 0 1.25rem;
  color: var(--ink);
}

/* ---------- Top bar ---------- */
.designer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.5rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.bar-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  border: 0;
  font-weight: 600;
}

.bar-group label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 400;
}

.bar-end { margin-left: auto; }

.designer-bar input[type="number"],
.designer-bar select,
.inspector input[type="number"],
.inspector input[type="text"] {
  padding: 0.35rem 0.5rem;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background-color: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}

.designer-bar input[type="number"] { width: 4.2rem; }

#zoomLevel {
  min-width: 3.4rem;
  font-weight: 400;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  width: 2.1rem;
  height: 2.1rem;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  font: 700 1.15rem/1 system-ui, sans-serif;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--code-bg);
}

.btn-small {
  padding: 0.35rem 0.9rem;
}

button.btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.designer :is(button, select, input, summary, a):focus-visible,
#plan .item:focus-visible {
  outline: 3px solid var(--border);
  outline-offset: 2px;
}

/* File menu */
.file-menu { position: relative; }

.file-menu summary {
  margin-top: 0;
  list-style: none;
  cursor: pointer;
}

.file-menu summary::-webkit-details-marker { display: none; }

.file-menu-list {
  position: absolute;
  right: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  min-width: 13rem;
  margin-top: 0.4rem;
  padding: 0.35rem;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 6px 18px rgba(10, 108, 153, 0.18);
}

.file-menu-list button {
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.file-menu-list button:hover { background: var(--code-bg); }
.file-menu-list .danger { color: var(--danger); }

/* ---------- Workspace ---------- */
.designer-workspace {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr) 260px;
  gap: 1rem;
  height: max(520px, calc(100vh - 300px));
  user-select: none;
  -webkit-user-select: none;
}

.inspector input { user-select: text; -webkit-user-select: text; }

.palette,
.inspector {
  overflow-y: auto;
  /* Keep scrolling inside the panel at its top and bottom instead of handing it to the page.
     Otherwise the browser latches the rest of the gesture onto the page, so scrolling back
     the other way moves the page rather than the panel. */
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* Palette */
.palette details { border-bottom: 1px solid var(--border); }
.palette details:last-child { border-bottom: 0; }

.palette summary {
  padding: 0.6rem 0.8rem;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
}

.palette-items {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
  padding: 0 0.6rem 0.8rem;
}

.palette-items.compact { grid-template-columns: repeat(4, 1fr); }

.palette-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.45rem 0.25rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--surface-tint);
  color: var(--ink);
  font: inherit;
  font-size: 0.78rem;
  line-height: 1.25;
  text-align: center;
  cursor: grab;
  touch-action: manipulation;
  user-select: none;
}

.palette-item:hover { border-color: var(--border); }
.palette-item:active { cursor: grabbing; }

.palette-item[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--code-bg);
}

.palette-item svg {
  width: 100%;
  height: 34px;
  overflow: visible;
  pointer-events: none;
}

.compact .palette-item svg { height: 22px; }

/* Canvas */
.canvas-wrap {
  position: relative;
  overflow: auto;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  overscroll-behavior: contain;
}

/* Padding round the plan (set in JS) acts as a pasteboard so you can pan past the edges */
.canvas-stage { box-sizing: content-box; }

#plan {
  display: block;
  margin: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#plan .item { cursor: move; outline: none; }
#plan.drawing, #plan.drawing .item { cursor: crosshair; }
#plan.space-pan, #plan.space-pan .item { cursor: grab; }
#plan.panning, #plan.panning .item { cursor: grabbing; }
#plan [data-handle] { cursor: grab; }

/* Inspector */
.inspector { padding: 1rem; }

.inspector h2 {
  margin: 0 0 0.15rem;
  font-size: 1.05rem;
  line-height: 1.3;
}

.inspector .meta {
  margin: 0 0 1rem;
  color: var(--ink);
  font-size: 0.85rem;
}

.field { margin-bottom: 0.9rem; }

.field > label,
.field > .field-label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.field-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.field-row input[type="number"] { width: 100%; min-width: 0; }

.inspector input[type="text"] { width: 100%; }

.inspector input[type="color"] {
  width: 2.6rem;
  height: 2.2rem;
  padding: 2px;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
}

.mini-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.mini-swatches button {
  width: 1.5rem;
  height: 1.5rem;
  border: 1px solid rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  cursor: pointer;
}

.field-error {
  margin: 0.3rem 0 0;
  color: var(--danger);
  font-size: 0.8rem;
}

.inspector-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.inspector-actions .btn {
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}

.inspector-actions .btn-danger {
  grid-column: 1 / -1;
  border-color: var(--danger);
  background: var(--surface);
  color: var(--danger);
}

.inspector-actions .btn-danger:not(:disabled):hover {
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: var(--danger);
}

.kit-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.88rem;
}

.kit-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid #e3f4fd;
}

.kit-list .qty {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.cable-group + .cable-group { margin-top: 0.75rem; }

.cable-type {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
  font-weight: 700;
}

.cable-type .qty { font-weight: 400; color: var(--ink); }

.cable-list li { padding-left: 0.75rem; }

.empty-note {
  margin: 0 0 1rem;
  color: var(--ink);
  font-size: 0.9rem;
}

.inspector h3 {
  margin: 1.25rem 0 0.4rem;
  font-size: 0.95rem;
}

/* Hint line under the workspace */
.designer .tool-hint {
  min-height: 1.6em;
}

.designer .tool-hint button {
  margin-left: 0.5rem;
  padding: 0.15rem 0.7rem;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.designer .tool-hint .warn { color: var(--danger); }

/* ---------- Full screen: the bar, workspace and hint fill the window ---------- */
#fullscreen svg {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#fullscreen .fs-exit,
#fullscreen[aria-pressed="true"] .fs-enter { display: none; }
#fullscreen[aria-pressed="true"] .fs-exit { display: block; }

html.designer-full,
html.designer-full body { overflow: hidden; }

.designer.is-full {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: auto;
  max-width: none;
  margin: 0;
  padding: max(0.75rem, env(safe-area-inset-top)) max(0.75rem, env(safe-area-inset-right))
           max(0.25rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
  background: var(--page-background);
}

.designer.is-full::backdrop { background: var(--page-background); }

.designer.is-full .designer-intro,
.designer.is-full .tool-credit { display: none; }

.designer.is-full .designer-bar { flex: none; margin-bottom: 0.75rem; }

.designer.is-full .designer-workspace {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
}

.designer.is-full .tool-hint { flex: none; margin: 0.4rem 0 0; }

/* ---------- Narrow screens ---------- */
@media (max-width: 960px) {
  .designer-workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .palette { max-height: 45vh; }

  .palette details[open] .palette-items {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
  }

  .palette-item { flex: 0 0 4.8rem; }
  .compact .palette-item { flex-basis: 2.8rem; }

  .canvas-wrap { height: 58vh; }

  .space-size { flex-wrap: nowrap; }
  .designer-bar input[type="number"] { width: 3.6rem; }

  .inspector { max-height: none; }

  .bar-end { margin-left: 0; }

  /* Stacked panels keep their natural heights; the full-screen view scrolls instead */
  .designer.is-full { overflow-y: auto; overscroll-behavior: contain; }
  .designer.is-full .designer-workspace { flex: none; }
}

/* ---------- Print: the export artwork (plan, plus key if chosen) ---------- */
#printArea { display: none; }

@media print {
  body > *:not(#printArea) { display: none !important; }

  html, body { background: #ffffff; }
  html.designer-full, html.designer-full body { overflow: visible; }

  body { display: block; min-height: 0; }

  #printArea { display: block; }

  #printArea > svg {
    display: block;
    width: 100%;
    height: auto;
    max-height: 100vh;
  }
}


/* The dashed selection frame already marks the focused item */
#plan .item:focus-visible { outline: none; }
#plan:focus { outline: none; }

/* ---------- Toolbar toggles ---------- */
/* Group titles (Space, Snap to) share one weight; .bar-group label would otherwise thin them */
.designer-bar .bar-label { font-weight: 600; white-space: nowrap; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
  cursor: pointer;
}

.check input {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.toggle-btn[aria-pressed="true"],
.toggle-btn[aria-pressed="true"]:not(:disabled):hover {
  background-color: var(--accent);
  color: var(--on-accent);
}

/* ---------- Rotation pivot picker ---------- */
.pivot-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.pivot-grid {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: repeat(3, 1.45rem);
  grid-template-rows: repeat(3, 1.45rem);
  border: 2px solid var(--accent);
  border-radius: 4px;
  background: var(--surface-tint);
}

.pivot-grid button {
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.pivot-grid button::after {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--surface);
}

.pivot-grid button:hover::after { background: var(--border); }

.pivot-grid button[aria-checked="true"]::after {
  width: 0.65rem;
  height: 0.65rem;
  background: var(--accent);
}

.pivot-note {
  margin: 0;
  color: var(--ink);
  font-size: 0.8rem;
  line-height: 1.35;
}

.inspector-actions [data-act="deselect"] { grid-column: 1 / -1; }

/* ---------- Reset and the "are you sure?" dialog ---------- */
.btn-reset {
  border-color: var(--danger) !important;
  color: var(--danger);
}

.btn-reset:not(:disabled):hover {
  background-color: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

/* The confirm dialog's styles live in style.css so every page shares them */

/* "Include a key" option in the File menu */
.menu-check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  padding: 0.5rem 0.75rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  line-height: 1.35;
  cursor: pointer;
}

.menu-check input {
  flex: 0 0 auto;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0.1rem 0 0;
  accent-color: var(--accent);
}

/* ---------- Toolbar: one row, every control the same height ---------- */
.designer-bar {
  --bar-h: 2.1rem;
  gap: 0.5rem 1.25rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  line-height: 1;
}

.designer-bar .bar-group { gap: 0.4rem; }

.designer-bar input[type="number"],
.designer-bar select,
.designer-bar .btn,
.designer-bar .icon-btn,
.designer-bar summary {
  box-sizing: border-box;
  height: var(--bar-h);
  margin: 0;
  font-size: inherit;
  line-height: 1;
}

.designer-bar input[type="number"] {
  width: 3.4rem;
  padding: 0 0.4rem;
}

.designer-bar select { padding: 0 0.4rem; }

.designer-bar .btn,
.designer-bar summary {
  display: inline-flex;
  align-items: center;
  padding: 0 0.75rem;
}

.designer-bar .icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--bar-h);
  padding: 0;
}

.designer-bar #zoomLevel { min-width: 2.9rem; }

.designer-bar .check { height: var(--bar-h); }


@media (max-width: 480px) {
  .designer-bar .space-size { gap: 0.3rem; }
  .designer-bar input[type="number"] { width: 2.7rem; padding: 0 0.3rem; }
}

.field-note {
  margin: 0.3rem 0 0;
  color: var(--ink);
  font-size: 0.8rem;
}

/* ---------- Number fields: type sums, ▲▼ to step ---------- */
.num-field {
  position: relative;
  display: flex;
  flex: 1 1 0;
  min-width: 0;
}

.num-field input[type="text"] {
  width: 100%;
  min-width: 0;
  padding-right: 1.9rem;
  font-variant-numeric: tabular-nums;
}

.num-field input[aria-invalid="true"] {
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
}

.num-steps {
  position: absolute;
  top: 2px;
  right: 2px;
  bottom: 2px;
  display: flex;
  flex-direction: column;
  width: 1.4rem;
  overflow: hidden;
  border-left: 1px solid var(--border);
  border-radius: 0 4px 4px 0;
}

.num-steps button {
  flex: 1 1 50%;
  padding: 0;
  border: 0;
  background: var(--surface-tint);
  color: var(--accent);
  font-size: 0.5rem;
  line-height: 1;
  cursor: pointer;
}

.num-steps button + button { border-top: 1px solid var(--border); }
.num-steps button:hover { background: #dff3ff; }
.num-steps button:active { background: var(--border); }

/* ---------- Colour picker: presets, custom colour, hex ---------- */
.colour-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.swatch {
  position: relative;
  width: 1.65rem;
  height: 1.65rem;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.3);
  border-radius: 50%;
  background: var(--c);
  cursor: pointer;
}

.swatch[aria-pressed="true"],
.swatch-custom[data-on="true"] {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Rainbow ring = "pick any colour"; the middle shows the current colour */
.swatch-custom {
  display: inline-block;
  background: conic-gradient(#ff3b30, #ffcc00, #34c759, #00c7be, #007aff, #af52de, #ff3b30);
}

.swatch-custom::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1.5px solid #ffffff;
  border-radius: 50%;
  background: var(--c);
  pointer-events: none;
}

.swatch-custom input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

.swatch-custom:focus-within {
  outline: 3px solid var(--border);
  outline-offset: 2px;
}

.hex-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.inspector .hex-row input[type="text"] {
  width: 6.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  text-transform: lowercase;
}

/* Rotate handle on the plan */
#plan [data-rot-handle] { cursor: grab; }
#plan [data-rot-handle]:active { cursor: grabbing; }

/* ---------- Dark mode plan: deep teal space, light teal grid, white rulers ----------
   (teal to match the S13 header) 
   Screen only; downloads and prints keep the light colours. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #plan .plan-bg { fill: #0e3536; }
  :root:not([data-theme="light"]) #plan .grid-minor { stroke: #1f5859; }
  :root:not([data-theme="light"]) #plan .grid-major { stroke: #6cc2bf; }
  :root:not([data-theme="light"]) #plan .plan-edge { stroke: #3a9e9b; }
  :root:not([data-theme="light"]) #plan .plan-rulers { fill: #ffffff; }
}
:root[data-theme="dark"] #plan .plan-bg { fill: #0e3536; }
:root[data-theme="dark"] #plan .grid-minor { stroke: #1f5859; }
:root[data-theme="dark"] #plan .grid-major { stroke: #6cc2bf; }
:root[data-theme="dark"] #plan .plan-edge { stroke: #3a9e9b; }
:root[data-theme="dark"] #plan .plan-rulers { fill: #ffffff; }
