/* Split box dovetail planner. Palette and type follow base.css and the
   bandsaw gauge; the drawing's own colours live in dovetails.js. */

/* The drawing needs room beside the controls, so this page widens the
   column (and the nav, to keep them aligned), as the blog reader does. */
main:has(.dovetail),
body:has(.dovetail) > nav {
  max-width: 880px;
}

.dovetail {
  --ui: "Inter", -apple-system, sans-serif;
  --ink: #1a1a1a;
  --muted: #666;
  --faint: #888;
  --line: #ddd;
  --hairline: #eee;
  --blue: #1a6fb5;
  --blue-pale: #b0d0e8;
  --warn: #b5471d;
  /* Legend swatches; keep in step with SCREEN in dovetails.js. */
  --pin: #b8b8b8;
  --pin-edge: #7a7a7a;
  --tail: #4d4d4d;
  --kerf: #b5471d;
  --cleanup: #e8bba6;
  margin: 0 0 2.5rem;
}

.dt-layout {
  display: grid;
  grid-template-columns: 19rem minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
}

.dt-main {
  min-width: 0;
}

/* --- Control groups, separated by space alone --- */

.dovetail fieldset {
  border: 0;
  padding: 0;
  margin: 0 0 1.5rem;
  min-width: 0;
}

/* --- Rows: label left, input right, hairline between --- */

.dovetail .row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.35rem 0.75rem;
  align-items: center;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--hairline);
}

.dovetail .row:last-child {
  border-bottom: 0;
}

.dovetail .name {
  font-size: 0.95rem;
  line-height: 1.35;
  color: var(--ink);
}

.dovetail .unit {
  color: var(--muted);
  font-size: 0.85em;
  white-space: nowrap;
}

.dovetail .ub {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.dovetail .u {
  font-family: var(--ui);
  font-size: 0.78rem;
  color: var(--faint);
  min-width: 1.8em;
}

/* --- Inputs --- */

.dovetail input[type=number] {
  width: 5rem;
  font-family: var(--ui);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}

.dovetail input[type=number]:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-pale);
}

/* step= sets the arrow increment; typed values off that grid are still fine,
   so hide the browser's invalid glow. */
.dovetail input:invalid {
  box-shadow: none;
}

.dovetail .slider {
  grid-column: 1 / -1;
  width: 100%;
  margin: 0.1rem 0 0.2rem;
  accent-color: var(--ink);
  cursor: pointer;
}

/* --- Buttons: solid ink for the main export, outlined otherwise --- */

.dovetail button {
  font-family: var(--ui);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--ink);
  border-radius: 3px;
  background: var(--ink);
  color: #fcfcfc;
  cursor: pointer;
  white-space: nowrap;
}

.dovetail button:hover {
  background: #333;
  border-color: #333;
}

.dovetail button.secondary {
  background: #fff;
  border-color: #ccc;
  color: var(--ink);
}

.dovetail button.secondary:hover {
  background: #f0f0f0;
  border-color: #bbb;
}

.dovetail button:disabled,
.dovetail button:disabled:hover {
  background: #f0f0f0;
  border-color: #ddd;
  color: #999;
  cursor: not-allowed;
}

.dovetail button:focus-visible,
.dovetail .slider:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--blue-pale);
}

.dt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.9rem;
}

/* --- Drawing --- */

#drawing {
  display: block;
  width: 100%;
  height: auto;
  max-height: 85vh;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 3px;
  user-select: none;
}

/* Handles are interactive, so they take the link blue. They are stripped
   from SVG exports. */
.dovetail .drag-target {
  cursor: ns-resize;
  touch-action: none;
  outline: none;
}

.dovetail .handle-line {
  stroke: var(--blue-pale);
  stroke-width: 1.5;
}

.dovetail .handle-dot {
  fill: #fff;
  stroke: var(--blue);
  stroke-width: 2;
}

.dovetail .handle-move {
  fill: #fff;
  stroke: var(--blue);
  stroke-width: 1.5;
}

.dovetail .handle-glyph {
  fill: var(--blue);
}

.dovetail .drag-target:hover .handle-dot,
.dovetail .drag-target:focus-visible .handle-dot,
.dovetail .drag-target.dragging .handle-dot,
.dovetail .drag-target:hover .handle-move,
.dovetail .drag-target:focus-visible .handle-move,
.dovetail .drag-target.dragging .handle-move {
  fill: var(--blue-pale);
  stroke-width: 2.5;
}

/* --- Legend --- */

.dt-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
  margin: 0.6rem 0 0;
  font-family: var(--ui);
  font-size: 0.78rem;
  color: var(--muted);
}

.dt-legend .swatch {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-right: 0.4rem;
  border-radius: 1px;
  vertical-align: -0.05rem;
}

.swatch.pin { background: var(--pin); box-shadow: inset 0 0 0 1px var(--pin-edge); }
.swatch.tail { background: var(--tail); }
.swatch.kerf { background: var(--kerf); }
.swatch.cleanup { background: var(--cleanup); }

/* --- Results --- */

.dt-results {
  margin-top: 1.75rem;
}

.dt-readouts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem 2.5rem;
  padding-top: 0.6rem;
  margin-bottom: 1.25rem;
  border-top: 1px solid var(--line);
}

.dt-readouts .k {
  font-family: var(--ui);
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.dt-readouts .v {
  font-family: var(--ui);
  font-size: 1.05rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.dt-msg {
  font-family: var(--ui);
  font-size: 0.82rem;
  line-height: 1.5;
  padding: 0.15rem 0 0.15rem 0.7rem;
  margin: 0 0 0.5rem;
  border-left: 2px solid var(--line);
  color: var(--muted);
}

.dt-msg.error {
  border-color: var(--warn);
  color: var(--warn);
}

.dt-msg.warning {
  border-color: var(--cleanup);
  color: #444;
}

/* --- Responsive --- */

/* Too narrow for the drawing beside the controls: stack them, and let the
   control groups flow into columns while there is room. */
@media (max-width: 880px) {
  .dt-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem;
  }
  .dt-controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    column-gap: 2rem;
  }
  .dt-controls > .dt-actions {
    grid-column: 1 / -1;
    margin: 0 0 1rem;
  }
}

/* --- Print: the drawing alone, at 1:1 --- */

@page {
  margin: 12mm;
}

@media print {
  body > nav,
  article > header,
  .dt-controls,
  .dt-legend,
  .dt-actions,
  .dt-results {
    display: none !important;
  }
  body {
    background: #fff;
  }
  main:has(.dovetail) {
    max-width: none;
    margin: 0;
    padding: 0;
  }
  .dovetail {
    margin: 0;
  }
  .dt-layout {
    display: block;
  }
  /* dovetails.js redraws for paper and sizes the drawing in mm. */
  #drawing {
    max-width: none;
    max-height: none;
    border: 0;
  }
}
