/* The drawing module (/tekenen.html). Tokens, buttons and form controls come from base.css.
   Wide screen: the file bar on top, the tools on the left, the drawing in the middle, the panel on the right, all of
   it filling the window under the header. From 1000 px down the panel goes under the drawing; on a phone the tools
   become one row that scrolls by itself, so the page never gets a sideways scrollbar. */

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.tekenen .site-footer { margin-top: 0; }

.teken {
  --cut: #15191e;           /* Snijden: the colour of the ink */
  --engrave: #c2187a;       /* Graveren: magenta, as in the DXF (colour 6) */
  --sel: #1f5fd6;           /* what is selected or being drawn */
  --snap: #d26a00;
  position: relative;
  display: grid; grid-template-columns: 78px minmax(0, 1fr) 330px; grid-template-rows: auto minmax(0, 1fr);
  height: calc(100vh - var(--header-h)); min-height: 560px; background: var(--card);
}
.teken-wait { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; margin: 0; background: var(--card); }
.teken-failed { position: absolute; left: 50%; top: 80px; transform: translateX(-50%); z-index: 6; max-width: min(560px, calc(100% - 32px)); }

/* ---- the file bar ---- */
.teken-bar { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 12px; border-bottom: 1px solid var(--line); min-width: 0; }
.bar-name { display: flex; align-items: center; gap: 10px; flex: 1 1 240px; min-width: 0; }
.name-input { font-weight: 600; max-width: 340px; min-width: 0; padding: 7px 10px; }
.save-state { font-size: 12.5px; color: var(--steel); white-space: nowrap; }
.save-state[data-dirty="1"] { color: var(--warn); font-weight: 600; }
.bar-group { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-btn { padding: 6px 9px; }
.icon-btn svg { width: 18px; height: 18px; display: block; }
/* What a visitor who is not logged in is told at the buttons, and the line after the login: a row of its own under
   the buttons (the bar wraps), so the drawing only moves down a little while it stands there. */
.teken-note { flex: 1 1 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0; padding: 8px 10px; min-width: 0; }
.teken-note p { margin: 0; flex: 1 1 260px; min-width: 0; font-weight: 600; }
.note-ok { background: #e3f4ea; border-color: #b9dfc8; color: #14532d; }
.note-close { margin-left: auto; border: 0; background: none; font: inherit; font-size: 20px; line-height: 1; padding: 2px 7px; color: inherit; cursor: pointer; border-radius: 6px; }
.note-close:hover { background: rgba(21, 25, 30, .07); }
.note-close:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 1px; }

/* ---- the tools ---- */
.teken-tools { grid-column: 1; grid-row: 2; display: flex; flex-direction: column; gap: 2px; padding: 8px 6px; border-right: 1px solid var(--line);
  overflow-y: auto; background: #fafbfc; min-height: 0; }
.teken-tools button { display: grid; justify-items: center; gap: 1px; padding: 6px 2px; border: 1px solid transparent; border-radius: 8px; background: none;
  font: inherit; font-size: 11.5px; line-height: 1.2; color: var(--ink-2); cursor: pointer; flex: none; }
.teken-tools button svg { width: 22px; height: 22px; }
.teken-tools button:hover { border-color: var(--line); background: #fff; }
.teken-tools button[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.teken-tools button:focus-visible, .snaps button:focus-visible, .stage-tools button:focus-visible, .seg button:focus-visible,
.check-list button:focus-visible, .link-btn:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: 1px; }
.tool-layer { margin-top: auto; padding-top: 10px; display: grid; gap: 2px; }
.tool-layer label { font-size: 11px; margin: 0; text-align: center; }
.tool-layer select { padding: 4px 2px; font-size: 12px; }

/* ---- the drawing ---- */
.teken-stage { grid-column: 2; grid-row: 2; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage-top { padding: 8px 12px; border-bottom: 1px solid var(--line); display: grid; gap: 6px; min-width: 0; }
.tool-hint { margin: 0; font-size: 14px; font-weight: 600; color: var(--ink); }
.tool-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; min-width: 0; }
.tool-options { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; font-size: 13px; min-width: 0; }
.tool-options:empty { display: none; }
.tool-options label { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-size: 13px; }
.tool-options input[type=text] { width: 76px; padding: 5px 8px; }
.tool-options .field-error { flex-basis: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; font: inherit; font-size: 12.5px; padding: 5px 10px; cursor: pointer; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.tool-entry { display: flex; align-items: center; gap: 6px; min-width: 0; }
.tool-entry label { margin: 0; font-size: 13px; white-space: nowrap; }
.tool-entry input { width: 190px; min-width: 0; padding: 6px 9px; font-family: var(--mono); }
.entry-error { margin: 0; color: var(--err); font-size: 13px; font-weight: 600; }

.canvas-wrap { position: relative; flex: 1 1 auto; min-height: 0; background: #fff; overflow: hidden; }
.teken-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; user-select: none; -webkit-user-select: none; }
.teken-canvas[data-tool="kiezen"] { cursor: default; }
.teken-canvas.pan-ready { cursor: grab; }
.teken-canvas.panning { cursor: grabbing; }
.teken-canvas:focus { outline: none; }
.teken-canvas:focus-visible { outline: 2px solid var(--accent-dark); outline-offset: -2px; }
/* One width on screen at every zoom: the viewBox is in mm, the strokes in pixels. */
.teken-canvas path, .teken-canvas rect, .teken-canvas circle { vector-effect: non-scaling-stroke; }
.grid-minor { fill: none; stroke: #eef1f4; stroke-width: 1; }
.grid-major { fill: none; stroke: #dde2e7; stroke-width: 1; }
.grid-axis { fill: none; stroke: #b9c1ca; stroke-width: 1; }
.part-fill { fill: rgba(255, 194, 26, .12); stroke: none; }
.ent { fill: none; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.ent.layer-snijden { stroke: var(--cut); }
.ent.layer-graveren { stroke: var(--engrave); stroke-dasharray: 7 3; }
.ent.hover { stroke-width: 3.2; }
.ent.selected { stroke: var(--sel); stroke-width: 2.8; }
.dim-line { fill: none; stroke: #6b7682; stroke-width: 1; }
.dim-arrow { fill: #6b7682; stroke: none; }
.dim-text { fill: #2a313a; font-family: var(--font); font-weight: 600; paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round; }
.dim-overall .dim-line { stroke: #9a7400; }
.dim-overall .dim-arrow { fill: #9a7400; }
.dim-overall .dim-text { fill: #6b5000; }
.dim-own .dim-line, .dim-preview .dim-line { stroke: var(--sel); }
.dim-own .dim-arrow, .dim-preview .dim-arrow { fill: var(--sel); }
.dim-own .dim-text, .dim-preview .dim-text { fill: var(--sel); }
.dim-entity.hover .dim-line { stroke-width: 2; }
.dim-entity.selected .dim-line { stroke: var(--sel); stroke-width: 1.6; }
.dim-entity.selected .dim-arrow { fill: var(--sel); }
.dim-entity.selected .dim-text { fill: var(--sel); }
.loose-end { fill: #fff; stroke: var(--err); stroke-width: 2.2; }
.flagged { fill: none; stroke: var(--err); stroke-width: 6; stroke-opacity: .35; stroke-linecap: round; }
.preview { fill: none; stroke: var(--sel); stroke-width: 1.4; stroke-dasharray: 6 4; }
.preview.guide { stroke: #9aa4af; }
.moving { fill: none; stroke: var(--sel); stroke-width: 1.4; opacity: .75; }
.select-box.window { fill: rgba(31, 95, 214, .07); stroke: var(--sel); stroke-width: 1; }
.select-box.crossing { fill: rgba(31, 138, 76, .07); stroke: var(--ok); stroke-width: 1; stroke-dasharray: 5 3; }
.snap path { fill: none; stroke: var(--snap); stroke-width: 2; }
.snap text { fill: #8a4600; font-family: var(--font); font-weight: 700; paint-order: stroke; stroke: #fff; stroke-width: 3px; }

.stage-tools { position: absolute; right: 10px; top: 10px; display: flex; gap: 6px; }
.stage-tools button { height: 34px; min-width: 34px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; font: inherit; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; box-shadow: var(--shadow); }
.stage-tools button svg { width: 18px; height: 18px; }
.stage-tools button:hover { border-color: var(--steel); }
.cursor-pos { position: absolute; left: 10px; bottom: 8px; font-size: 12.5px; background: rgba(255, 255, 255, .92); padding: 2px 8px; border-radius: 6px;
  color: var(--ink-2); pointer-events: none; white-space: nowrap; }
.cursor-pos:empty { display: none; }

.snaps { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 12px; border-top: 1px solid var(--line); font-size: 12.5px; }
.snaps-label { font-weight: 600; color: var(--ink-2); margin-right: 2px; }
.snaps button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 3px 10px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--steel); }
.snaps button[aria-pressed="true"] { background: #e8effc; border-color: #b8ccf2; color: var(--blue); font-weight: 600; }
.grid-size { font-weight: 400; }
.snaps-tip { margin-left: 4px; }

/* ---- the panel ---- */
.teken-panel { grid-column: 3; grid-row: 2; border-left: 1px solid var(--line); overflow-y: auto; background: var(--bg); padding: 10px;
  display: grid; gap: 10px; align-content: start; min-height: 0; }
.panel-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.panel-card h2 { font-size: 15px; margin: 0 0 8px; }
.panel-card h3 { font-size: 13px; margin: 12px 0 6px; color: var(--ink-2); }
.panel-card p { margin: 0 0 8px; font-size: 13.5px; }
.panel-empty { color: var(--steel); }
.num-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; }
.num-grid .wide { grid-column: 1 / -1; }
.num-field label { font-size: 12px; margin: 0 0 2px; font-weight: 600; color: var(--ink-2); }
.num-field input, .num-field select { padding: 6px 8px; font-variant-numeric: tabular-nums; }
.num-field input[readonly] { background: var(--bg); color: var(--ink-2); }
.num-field.invalid input { border-color: var(--err); }
.field-error { color: var(--err); font-size: 12.5px; margin: 4px 0 0; }
.check-field { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.check-field input { width: auto; margin: 0; }
.edit-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; margin-bottom: 8px; }
.edit-row .num-field { flex: 1 1 110px; min-width: 0; }
.edit-row .btn { flex: none; }
.edit-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--blue); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }

.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.check-list li { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 8px; font-size: 13px; align-items: start; }
.check-dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; background: var(--ok); }
.check-list li[data-level="fout"] .check-dot { background: var(--err); }
.check-list li[data-level="let op"] .check-dot { background: #e0a800; }
.check-list button { background: none; border: 0; padding: 0; font: inherit; text-align: left; color: inherit; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.keys { margin: 0; display: grid; gap: 4px; font-size: 12.5px; }
.keys div { display: flex; justify-content: space-between; gap: 10px; }
.keys dt { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.keys dd { margin: 0; color: var(--steel); text-align: right; }

/* ---- dialogs ---- */
.teken-dialog { border: 0; border-radius: var(--radius); box-shadow: 0 20px 60px rgba(16, 24, 40, .35); padding: 0; width: min(600px, calc(100vw - 32px)); color: var(--ink); }
.teken-dialog::backdrop { background: rgba(21, 25, 30, .55); }
.dialog-body { padding: 20px 22px; display: grid; gap: 12px; }
.dialog-body h2 { font-size: 19px; margin: 0; }
.dialog-body p { margin: 0; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.drawing-list { list-style: none; margin: 0; padding: 0; max-height: min(420px, 60vh); overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.drawing-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.drawing-list li:last-child { border-bottom: 0; }
.drawing-list li.current { background: #fff9e6; }
.drawing-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawing-facts { font-size: 12.5px; color: var(--steel); grid-column: 1; }
.drawing-actions { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 6px; }
.problem-list { margin: 0; padding-left: 20px; display: grid; gap: 4px; font-size: 14px; }

/* ---- print: the drawing in black on white A4, its name, the date and the overall size; none of the site ----
   Only for who is logged in: page.js fills the sheet then (data-filled="1"). For anybody else, also through Ctrl+P or
   the print menu of the browser, the sheet holds the one sentence to log in and nothing of the drawing. */
.print-sheet { display: none; }
.print-login { display: none; }
@media print {
  @page { size: A4 portrait; margin: 12mm; }
  body { background: #fff; }
  body > :not(.print-sheet) { display: none !important; }
  .print-sheet { display: block; color: #000; font-family: var(--font); }
  .print-head h1 { font-size: 18pt; margin: 0 0 2mm; }
  .print-head p { margin: 0 0 6mm; font-size: 10.5pt; }
  .print-drawing { display: block; width: 100%; height: 225mm; }
  .print-drawing path { vector-effect: non-scaling-stroke; }
  .print-ent { fill: none; stroke: #000; stroke-width: 1.1; stroke-linejoin: round; }
  .print-graveren { stroke-dasharray: 5 2.5; stroke-width: .8; }
  .print-dim .dim-line { stroke: #000; stroke-width: .5; }
  .print-dim .dim-arrow { fill: #000; }
  .print-dim .dim-text { fill: #000; font-weight: 400; }
  .print-note { font-size: 9pt; margin-top: 4mm; }
  .print-sheet:not([data-filled="1"]) > :not(.print-login) { display: none; }
  .print-sheet:not([data-filled="1"]) .print-login { display: block; margin: 0; font-size: 13pt; }
}

/* ---- smaller screens ---- */
@media (max-width: 1000px) {
  .teken { grid-template-columns: 66px minmax(0, 1fr); grid-template-rows: auto auto auto; height: auto; min-height: 0; }
  .teken-stage { height: 72vh; min-height: 440px; }
  .teken-panel { grid-column: 1 / -1; grid-row: 3; border-left: 0; border-top: 1px solid var(--line); grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
  .teken-tools { min-height: 0; }
}
@media (max-width: 600px) {
  .teken { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto auto; }
  .teken-tools { grid-column: 1; grid-row: 2; flex-direction: row; overflow-x: auto; overflow-y: hidden; border-right: 0; border-bottom: 1px solid var(--line); padding: 4px 6px; }
  .teken-tools button { min-width: 58px; }
  .tool-layer { margin: 0 0 0 6px; padding: 0; flex: none; align-content: center; }
  .teken-stage { grid-column: 1; grid-row: 3; height: 68vh; min-height: 380px; }
  .teken-panel { grid-row: 4; grid-template-columns: minmax(0, 1fr); }
  .tool-entry input { width: 140px; }
  .name-input { max-width: none; }
  .snaps-tip { display: none; }
}
