:root {
  --bg: #d4d0c8;          /* classic Windows 2000/XP dialog grey */
  --panel: #ece9d8;
  --border: #808080;
  --accent: #0a246a;
  --text: #000;
  --front: #0000ff;
  --back: #e00000;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 13px "MS Sans Serif", Tahoma, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column; height: 100vh; overflow: hidden;
}
button {
  font: inherit; padding: 4px 10px; background: var(--panel);
  border: 1px solid #fff; border-right-color: #404040; border-bottom-color: #404040;
  box-shadow: inset -1px -1px 0 var(--border); cursor: pointer; white-space: nowrap;
}
button:active { border-color: #404040 #fff #fff #404040; }
button.active { background: #fff; outline: 1px dotted #000; outline-offset: -4px; font-weight: bold; }
button.primary { font-weight: bold; }
button:disabled { color: #888; cursor: default; }
input[type=number], input[type=text], textarea { font: inherit; padding: 3px 5px; border: 1px solid var(--border); background: #fff; }
input[type=range] { width: 120px; vertical-align: middle; }
fieldset { border: 1px groove #fff; margin: 0 0 8px; padding: 6px 8px; }
legend { padding: 0 4px; }

.appbar {
  display: flex; align-items: center; gap: 16px; padding: 6px 10px;
  background: linear-gradient(#0a246a, #3a6ea5); color: #fff; flex: 0 0 auto;
}
.brand { font-weight: bold; font-size: 15px; }
.brand .sub { font-weight: normal; font-size: 11px; opacity: .85; margin-left: 8px; }
.tabs { display: flex; gap: 2px; margin-left: auto; }
.tabs .tab { background: #c0c0c0; }
.tabs .tab.active { background: #fff; }
.actions { display: flex; gap: 6px; }

.tabpane { display: none; flex: 1 1 auto; min-height: 0; }
.tabpane.active { display: flex; }

/* ---------- digitize */
.viewer { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.toolbar { display: flex; align-items: center; gap: 10px; padding: 4px 8px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar label { display: inline-flex; align-items: center; gap: 4px; }
.lcd { display: inline-block; min-width: 38px; padding: 1px 4px; background: #9bb; color: #000; font-family: "Courier New", monospace; text-align: right; border: 1px inset #666; }
.lcd.big { min-width: 60px; font-size: 20px; }
.zoomlbl { min-width: 48px; }
.hint { margin-left: auto; color: #333; font-family: monospace; }
.canvas-wrap { flex: 1 1 auto; overflow: auto; background: #333; position: relative; }
.canvas-stack { position: relative; display: inline-block; }
.canvas-stack canvas { display: block; }
#overlay { position: absolute; left: 0; top: 0; cursor: crosshair; }
.dropzone { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #ccc; font-size: 16px; pointer-events: none; }
.dropzone.hidden { display: none; }

.controls { flex: 0 0 340px; overflow: auto; padding: 8px; background: var(--bg); border-left: 1px solid var(--border); }
.btncol { display: flex; flex-direction: column; gap: 4px; }
.btngrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.row { display: flex; gap: 8px; align-items: center; margin: 4px 0; flex-wrap: wrap; }
.row.right { justify-content: flex-end; }
.grp { display: inline-flex; gap: 8px; padding: 2px 6px; border: 1px groove #fff; }
.chk { margin-left: auto; }
.pinfo { font-weight: bold; margin-bottom: 4px; }
.statuslist { display: grid; grid-template-columns: auto 1fr 1fr; gap: 1px 8px; font-size: 12px; }
.statuslist .ok { color: #060; }
.statuslist .miss { color: #a00; }
.statuslist .hd { font-weight: bold; border-bottom: 1px solid #999; }
.helpbox .help { max-height: 260px; overflow: auto; background: #fff; padding: 6px; border: 1px inset #999; font-size: 12px; }
.helpbox.tall .help { max-height: calc(100vh - 140px); }
.help h2, .help h3 { font-size: 13px; margin: 8px 0 4px; }
.help p, .help ol, .help ul { margin: 4px 0; }
.help .hc { text-align: center; }
.help img { image-rendering: pixelated; }

/* ---------- analyse */
.report { flex: 1 1 auto; overflow: auto; background: #fff; padding: 12px 20px; }
.report h2 { margin: 0 0 4px; }
.report h3 { margin: 14px 0 4px; border-bottom: 1px solid #ccc; }
.report canvas { display: block; max-width: 100%; border: 1px solid #ddd; }
.report-head { display: flex; justify-content: space-between; align-items: flex-end; }
.rp { text-align: right; }
.tiltrot { display: flex; gap: 40px; margin: 6px 0; font-weight: bold; }
.results { border-collapse: collapse; width: 100%; max-width: 760px; }
.results th, .results td { border: 1px solid #ccc; padding: 3px 8px; text-align: right; font-family: "Courier New", monospace; }
.results th { background: #eee; font-family: inherit; }
.results td:first-child, .results th:first-child { text-align: left; font-family: inherit; }
.footer { margin-top: 20px; font-size: 11px; color: #666; }
.analyse-controls .sliderrow { display: flex; align-items: center; gap: 10px; }
.analyse-controls input[type=range] { flex: 1; }
.small { font-size: 11px; color: #333; }

/* ---------- measure */
.measure { flex: 1 1 auto; overflow: auto; background: #fff; padding: 12px 20px; }
.measure-table td.unit { text-align: left; font-family: inherit; color: #555; }
.measure-table td:nth-child(2) { text-align: left; font-family: inherit; }
.measure-table td:first-child { text-align: right; font-family: "Courier New", monospace; }

/* ---------- dialogs */
dialog { border: 1px solid var(--border); background: var(--bg); padding: 14px 18px; box-shadow: 4px 4px 0 rgba(0,0,0,.4); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.formgrid { display: grid; grid-template-columns: auto 1fr; gap: 8px 12px; align-items: center; margin: 10px 0; }
.help.small { max-height: 120px; overflow: auto; background: #fff; border: 1px inset #999; padding: 6px; margin: 6px 0; }

@media print {
  body { overflow: visible; height: auto; background: #fff; }
  .appbar, .controls, .toolbar, #tab-digitize, #tab-measure { display: none !important; }
  #tab-analyse { display: block !important; }
  .report { overflow: visible; }
}
