/* labelslot desktop instrument panel. Palette values are shared with Open Rig Programmer
   (same author) but this stylesheet's rules are written independently. */
:root {
  color-scheme: dark;

  --bg: #10161f;
  --panel: #1b2636;
  --panel-hi: #233047;
  --panel-lo: #141b26;
  --edge: #324160;
  --edge-soft: #263349;

  --ink: #eef2f8;
  --ink-dim: #93a1b8;
  --ink-faint: #8593ab; /* 4.9:1 on --panel #1b2636 (WCAG), was #66748c at 3.2:1 */

  --amber: #f5a623;
  --amber-strong: #ffc966;
  --red: #ff7a7a;
  --red-bg: #3a2027;
  --yellow: #e8c547;

  --ui: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;

  --radius-s: 4px;
  --radius-m: 8px;

  --gap-xs: 4px;
  --gap-s: 8px;
  --gap-m: 12px;
  --gap-l: 16px;
}

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

/* Several elements below set `display` unconditionally (flex layouts); without this an
   authored display rule outranks the UA [hidden]{display:none} default at equal specificity. */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
html { background: var(--bg); color: var(--ink); color-scheme: dark; }
body {
  font-family: var(--ui);
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
}

.mono { font-family: var(--mono); }
.dim { color: var(--ink-faint); }

/* A small uppercase tracked label, reused for toolbar group names and pane/section headings. */
.eyebrow {
  font: 700 10px/1.2 var(--ui);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

button, input, select { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

/* One visible focus treatment everywhere, including SVG rects (which box-shadow can't ring). */
:focus-visible {
  outline: 2px solid var(--amber-strong);
  outline-offset: 2px;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ---- toolbars ---- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap-l);
  padding: var(--gap-s) var(--gap-l);
  background: var(--panel);
  border-bottom: 1px solid var(--edge);
  flex-shrink: 0;
}

.tool-group {
  display: flex;
  gap: var(--gap-s);
  align-items: center;
  padding-inline-end: var(--gap-l);
  border-inline-end: 1px solid var(--edge-soft);
}
.tool-group:last-child { border-inline-end: none; padding-inline-end: 0; }

.field { display: flex; align-items: center; gap: var(--gap-xs); }
.field-label { color: var(--ink-dim); font-size: 12px; white-space: nowrap; }
.checkbox-label { white-space: nowrap; }
.field .unit { color: var(--ink-dim); font-size: 12px; }

input[type="text"], input[type="number"], select {
  background: var(--panel-lo);
  border: 1px solid var(--edge);
  border-radius: var(--radius-s);
  padding: var(--gap-xs) var(--gap-s);
  max-width: 100%;
}
input[type="number"] { width: 5.5em; }
#printer-name { width: 220px; }
#assume-pos { width: 4em; }

.checkbox-label { display: flex; align-items: center; gap: var(--gap-xs); font-weight: normal; }
.checkbox-label input { width: auto; }

.hint { font-size: 11.5px; color: var(--ink-faint); }

.readout { color: var(--ink); }

/* ---- buttons ---- */
.btn {
  padding: var(--gap-xs) var(--gap-m);
  border-radius: var(--radius-s);
  border: 1px solid var(--edge);
  background: var(--panel-hi);
  color: var(--ink);
  font-weight: 600;
  font-size: 12.5px;
}
.btn:hover:not(:disabled) { background: var(--edge-soft); }
.btn-primary {
  background: transparent;
  border-color: var(--amber);
  color: var(--amber);
}
.btn-primary:hover:not(:disabled) {
  color: var(--amber-strong);
  background: rgba(245, 166, 35, .08);
}

/* ---- main: two panes ---- */
main.panes {
  flex: 1 1 auto;
  display: flex;
  gap: var(--gap-l);
  padding: var(--gap-l);
  min-height: 0;
  overflow: hidden;
}

.pane {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius-m);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.pane-sheet { flex: 0 0 340px; width: 340px; }
.pane-preview { flex: 1 1 auto; min-width: 0; }

.pane-header {
  padding: var(--gap-s) var(--gap-l);
  border-bottom: 1px solid var(--edge);
  flex-shrink: 0;
}
.pane-header h2 { margin: 0; }

.pane-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--gap-l);
  min-height: 0;
}

.pane-caption {
  flex-shrink: 0;
  margin: 0;
  padding: var(--gap-s) var(--gap-l);
  border-top: 1px solid var(--edge);
  color: var(--ink-faint);
  font-size: 11.5px;
}

/* ---- sheet pane: position grid ---- */
#grid-svg { width: 100%; height: auto; display: block; }
.sheet-page { fill: var(--panel-lo); }
.label-box {
  fill: var(--panel-hi);
  stroke: var(--edge);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
}
.label-box.selected { stroke: var(--amber); stroke-width: 2; }
.label-box.used { fill: url(#used-hatch); }
.label-box:focus-visible { outline-offset: -2px; }
.used-hatch-bg { fill: var(--edge-soft); }
.used-hatch-line { stroke: var(--ink-faint); stroke-width: 2; }
.label-box-number, .label-box-used-text {
  font-family: var(--mono);
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}
.label-box-number { fill: var(--ink-dim); }
.label-box-used-text { fill: var(--ink-faint); }

/* grid-template-columns is set inline in JS to match the sheet's column count. */
#used-list {
  display: grid;
  gap: 2px var(--gap-s);
  font-family: var(--mono);
  font-size: 12px;
  margin-top: var(--gap-m);
}
#used-list label { display: flex; align-items: center; gap: var(--gap-xs); font-weight: normal; }

#reset-sheet { margin-top: var(--gap-m); }

/* A fixed footer of .pane-sheet (sibling of .pane-body, not inside its scroll area) so Files
   and Clear stay on screen regardless of how tall the grid/used-list content grows. */
.files-section {
  flex-shrink: 0;
  padding: var(--gap-m) var(--gap-l);
  border-top: 1px solid var(--edge);
}
.files-section h3 { margin: 0 0 var(--gap-s); }
#file-list {
  list-style: none;
  margin: 0 0 var(--gap-s);
  padding: 0;
  font-family: var(--mono);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#file-list li { display: flex; align-items: center; justify-content: space-between; gap: var(--gap-s); }
#file-list li.empty-state { color: var(--ink-faint); font-family: var(--ui); white-space: normal; }
.file-remove-btn {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--ink-faint);
  font-size: 12px;
  line-height: 1;
}
.file-remove-btn:hover { color: var(--red); background: var(--edge-soft); }

/* ---- preview pane ---- */
#preview-body {
  background: var(--panel-lo);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-l);
}
#preview-hint { margin: auto; color: var(--ink-faint); }
.preview-page {
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .5);
}
.preview-page canvas { display: block; max-width: 100%; }
.preview-page svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.overlay-box { fill: none; stroke: var(--amber); stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; }

/* ---- status bar ---- */
.status-bar {
  flex-shrink: 0;
  background: var(--panel);
  border-top: 1px solid var(--edge);
  font-size: 12px;
}
.status-normal {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-l);
  padding: var(--gap-s) var(--gap-l);
  min-height: 32px;
}
.status-left { flex: 1 1 auto; min-width: 0; overflow: hidden; }
#report-lines { color: var(--ink-dim); max-height: 3.5em; overflow-y: auto; }
.status-right { display: flex; align-items: center; gap: var(--gap-m); flex-shrink: 0; }

/* In normal flow (not absolutely positioned over .status-normal) so the bar grows to fit a
   wrapped message instead of collapsing to its own min-height while the sibling is hidden.
   Stacked above .status-normal, which stays visible (printing reminder, "runs locally"). */
.status-error {
  display: flex;
  align-items: center;
  background: var(--red-bg);
  color: var(--red);
  padding: var(--gap-s) var(--gap-l);
  white-space: pre-wrap;
  font-family: var(--mono);
  border-bottom: 1px solid var(--edge);
}

/* Dedicated, non-scrolling warning line (Non-negotiable 5): always visible, never buried in
   #report-lines' 3.5em scroll box. Stacked above the error box and the normal status line. */
.status-warning {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(245, 166, 35, .12);
  color: var(--amber-strong);
  padding: var(--gap-s) var(--gap-l);
  font-family: var(--mono);
  white-space: pre-wrap;
  border-bottom: 1px solid var(--edge);
}

/* ---- help popover ---- */
.help-details { position: relative; }
.help-details summary {
  list-style: none;
  cursor: pointer;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--edge);
  border-radius: 50%;
  color: var(--ink-dim);
  font-size: 11px;
}
.help-details summary::-webkit-details-marker { display: none; }
.help-details[open] summary { border-color: var(--ink-dim); color: var(--ink); }
.help-popover {
  position: absolute;
  bottom: 28px;
  right: 0;
  background: var(--panel-hi);
  border: 1px solid var(--edge);
  border-radius: var(--radius-s);
  padding: var(--gap-m);
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
  min-width: 220px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .5);
  z-index: 10;
}
.help-popover a { color: var(--ink-dim); }
.help-popover a:hover { color: var(--ink); }
.help-popover p { margin: 0; color: var(--ink-faint); font-size: 11px; }

/* ---- full-window drop highlight ---- */
body.drag-over::after {
  content: '';
  position: fixed;
  inset: 0;
  border: 3px dashed var(--amber);
  background: rgba(245, 166, 35, .08);
  pointer-events: none;
  z-index: 100;
}

/* ---- narrow screens: stack panes, allow the document to scroll ---- */
@media (max-width: 640px) {
  html, body { height: auto; overflow: visible; }
  #app { height: auto; }
  main.panes { flex-direction: column; overflow: visible; }
  .pane-sheet { width: 100%; flex: 0 0 auto; }
  .pane-preview { flex: 0 0 auto; }
  .pane-body { overflow: visible; }
  .toolbar { flex-direction: column; align-items: stretch; flex-wrap: nowrap; }
  .tool-group {
    border-inline-end: none;
    padding-inline-end: 0;
    padding-bottom: var(--gap-s);
    border-bottom: 1px solid var(--edge-soft);
    flex-wrap: wrap;
    width: 100%;
    min-width: 0;
  }
  .tool-group select,
  .tool-group input[type="text"] { min-width: 0; flex: 1 1 auto; width: 100%; }
  .status-normal { flex-direction: column; align-items: flex-start; gap: var(--gap-xs); }
}
