/* Open Sans, all UI text. Teko Medium, the DocTakeoff wordmark. */
@font-face {
  font-family: 'OpenSansVar';
  font-style: normal;
  font-weight: 300 800;
  font-display: swap;
  src: url('../fonts/opensans-var.woff2') format('woff2');
}
@font-face {
  font-family: 'Teko';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('../fonts/teko-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Teko';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/teko-700.woff2') format('woff2');
}

:root {
  --ui-font: 'OpenSansVar', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --brand-font: 'Teko', 'OpenSansVar', sans-serif;
  /* Kastle REDI brand palette, Dark Grey #3D3D3D, Light Grey #B0B0B0, White #FFFFFF.
     Supporting darker shades are derived from the same neutral family for a dark UI.
     Markup/takeoff colors stay chromatic on purpose: they identify categories on the
     drawing and must remain distinguishable from one another. */
  --bg: #1f1f1f;
  --bg-2: #2a2a2a;
  --bg-3: #3d3d3d;        /* brand Dark Grey, controls & inputs */
  --line: #4f4f4f;
  --text: #ffffff;        /* brand White */
  --text-dim: #b0b0b0;    /* brand Light Grey */
  --accent: #ffffff;      /* brand White, primary actions & active states */
  --accent-2: #e6e6e6;
  --accent-ink: #1f1f1f;  /* text/icons drawn on top of --accent */
  --danger: #d95c4a;
  --stage: #4a4a4a;
  --radius: 7px;
  --rail: 74px;
  --panel: 300px;
  --topbar: 52px;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  display: flex; flex-direction: column;
  font-family: var(--ui-font);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Top bar ---------- */
#topbar {
  height: var(--topbar); flex: 0 0 auto;
  display: flex; align-items: center; gap: 18px;
  padding: 0 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  user-select: none;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-stack { display: flex; flex-direction: column; line-height: 1; }
.brand-name { font-family: var(--brand-font); font-weight: 500; font-size: 26px; line-height: .95; letter-spacing: .6px; }
.brand-by { font-size: 9.5px; letter-spacing: .3px; color: var(--text-dim); text-decoration: none; margin-top: 2px; }
.brand-by:hover { color: var(--text); text-decoration: underline; }
.brand .logo { color: var(--accent); font-size: 21px; position: relative; top: -1px; }
.group { display: flex; align-items: center; gap: 6px; }
.group.nav .page-indicator { color: var(--text-dim); font-variant-numeric: tabular-nums; }
#pageNum { width: 46px; background: var(--bg-3); border: 1px solid var(--line); color: var(--text); border-radius: 5px; padding: 3px 6px; text-align: center; }
.group.zoom #zoomLabel { min-width: 46px; text-align: center; color: var(--text-dim); font-variant-numeric: tabular-nums; }
/* recent projects dropdown */
.open-wrap { position: relative; display: inline-flex; }
.recent-menu {
  display: none; position: absolute; top: 100%; left: 0; margin-top: 4px; min-width: 230px; z-index: 40;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 5px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.open-wrap:hover .recent-menu { display: block; }
.recent-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 9px; border-radius: 6px; cursor: pointer; font-size: 12.5px; }
.recent-item:hover { background: #4a4a4a; }
.recent-item .r-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-item .r-date { color: var(--text-dim); font-size: 11px; white-space: nowrap; }
.recent-empty { padding: 10px; color: var(--text-dim); font-size: 12px; text-align: center; }

.scale-box { margin-left: auto; }
.scale-status { font-size: 12.5px; color: var(--text-dim); padding: 4px 10px; background: var(--bg-3); border-radius: 20px; border: 1px solid var(--line); }
.scale-status.set { color: var(--text); border-color: #5a5a5a; background: #303030; }

/* ---------- Buttons ---------- */
.btn {
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 13px;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #4a4a4a; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.icon { padding: 6px; font-size: 17px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.btn.tiny { padding: 4px 9px; font-size: 12px; }
.btn.danger { color: #ff9b8b; }
.btn.danger:hover { background: #3a2723; border-color: #5c352c; }
.btn:disabled { opacity: .4; cursor: default; }

/* ---------- Tab bar (multiple open PDFs) ---------- */
.tabbar {
  display: flex; align-items: stretch; gap: 2px; padding: 4px 8px 0; overflow-x: auto;
  background: var(--bg); border-bottom: 1px solid var(--line); flex: 0 0 auto; user-select: none;
}
.tabbar[hidden] { display: none; }
.tabbar::-webkit-scrollbar { height: 0; }
.tab {
  display: flex; align-items: center; gap: 8px; max-width: 220px; padding: 7px 8px 7px 12px;
  background: var(--bg-2); border: 1px solid var(--line); border-bottom: none;
  border-radius: 8px 8px 0 0; cursor: pointer; color: var(--text-dim); font-size: 12.5px;
  white-space: nowrap; position: relative; top: 1px;
}
.tab:hover { background: var(--bg-3); color: var(--text); }
.tab.active { background: var(--stage); color: #fff; border-color: var(--line); }
.tab .tab-name { overflow: hidden; text-overflow: ellipsis; }
.tab .tab-close { display: inline-flex; align-items: center; justify-content: center; border: none; background: none; color: inherit; cursor: pointer; opacity: .55; border-radius: 4px; padding: 1px; }
.tab .tab-close:hover { opacity: 1; background: rgba(255,255,255,.15); }

/* ---------- Guided tour ---------- */
.tour-spot {
  position: fixed; z-index: 70; border-radius: 10px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(8,10,13,.74), 0 0 0 3px var(--accent);
  transition: top .22s ease, left .22s ease, width .22s ease, height .22s ease;
}
.tour-spot[hidden] { display: none; }
.tour-tip {
  position: fixed; z-index: 71; width: 300px; background: var(--bg-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 16px;
  box-shadow: 0 18px 50px rgba(0,0,0,.6);
}
.tour-tip[hidden] { display: none; }
.tour-tip h4 { margin: 4px 0 6px; font-family: var(--brand-font); font-weight: 700; font-size: 19px; letter-spacing: .4px; }
.tour-tip p { margin: 0 0 14px; font-size: 13px; color: var(--text-dim); line-height: 1.5; }
.tt-step { font-size: 10.5px; letter-spacing: .6px; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.tt-btns { display: flex; align-items: center; gap: 6px; }
.tt-spacer { flex: 1; }

/* ---------- Feedback button + dialogs ---------- */
.feedback-fab {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 14px; z-index: 45;
  background: var(--accent); color: var(--accent-ink); border: none; border-radius: 22px;
  padding: 10px 18px; font: 600 12.5px var(--ui-font); letter-spacing: .3px;
  text-transform: uppercase; cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.45);
  transition: background .12s, transform .12s;
}
.feedback-fab:hover { background: var(--accent-2); transform: translateX(-50%) translateY(-2px); }
.feedback-fab[hidden] { display: none; }
#panel .item-list { padding-bottom: 12px; }

.modal.gate { background: rgba(12,14,17,.82); }
.gate-card { width: 460px; text-align: left; }
.gate-logo { font-size: 34px; color: var(--accent); line-height: 1; margin-bottom: 6px; }
.gate-lead { color: var(--text) !important; line-height: 1.5; }
.gate-lead strong { color: #fff; }
.gate-by { text-align: center; margin-top: 14px; font-size: 11px; }
.gate-by a { color: var(--text-dim); text-decoration: none; }
.gate-by a:hover { color: var(--text); text-decoration: underline; }
.gate-error { color: #ff9b8b; font-size: 12.5px; margin: -6px 0 10px; }
.fb-text {
  width: 100%; background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 9px 10px; font: 14px var(--ui-font); margin-bottom: 12px;
  resize: vertical; min-height: 64px;
}
.fb-text:focus, .full-select:focus { border-color: var(--accent); outline: none; }
.fb-status { font-size: 13px; margin-bottom: 10px; }
.fb-status.ok { color: #d6d6d6; }
.fb-status.err { color: #ff9b8b; }

/* ---------- Restore (crash recovery) banner ---------- */
.restore-bar {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%); z-index: 55;
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  background: var(--bg-2); border: 1px solid var(--accent); border-radius: 24px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  font-size: 13px;
}
.restore-bar[hidden] { display: none; }
.btn.tiny.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

/* ---------- Workspace layout ---------- */
#workspace { display: flex; flex: 1 1 auto; min-height: 0; }

/* ---------- Tool rail ---------- */
#toolrail {
  width: var(--rail); background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 6px;
}
.tool {
  width: 58px; height: 56px; border: 1px solid transparent; background: transparent;
  color: var(--text-dim); border-radius: 10px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  font-size: 10.5px; font-weight: 500; letter-spacing: 0; transition: background .12s, color .12s;
}
.tool .ico { display: flex; }
.tool .ico svg { width: 21px; height: 21px; }
.tool:hover { background: var(--bg-3); color: var(--text); }
.tool.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.rail-spacer { flex: 1; }
.rail-gear { width: 40px; height: 40px; border: 1px solid transparent; background: transparent; color: var(--text-dim); border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.rail-gear:hover { background: var(--bg-3); color: var(--text); }
.rail-gear svg { width: 20px; height: 20px; }
/* generic icon-in-button */
.btn.icon svg { width: 18px; height: 18px; display: block; }

/* show/hide tools popover */
.tool-menu {
  position: fixed; z-index: 60; min-width: 180px; background: var(--bg-3);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px; box-shadow: 0 12px 34px rgba(0,0,0,.5);
}
.tool-menu-head { font-size: 10.5px; letter-spacing: .6px; text-transform: uppercase; color: var(--text-dim); padding: 5px 8px; }
.tool-menu-item { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.tool-menu-item:hover { background: #4a4a4a; }
.tool-menu-item input { accent-color: var(--accent); cursor: pointer; }
.tool-menu-item .tm-ico { display: flex; color: var(--text-dim); }
.tool-menu-item .tm-ico svg { width: 16px; height: 16px; }

/* ---------- Page thumbnails sidebar ---------- */
#pages {
  width: 168px; background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
}
#workspace.pages-collapsed #pages { display: none; }
.pages-head { padding: 9px 12px; font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--text-dim); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.pages-x { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; }
.pages-x:hover { color: var(--text); }
.pages-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.thumb { cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.thumb-canvas {
  width: 100%; border: 2px solid transparent; border-radius: 3px; overflow: hidden;
  background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); line-height: 0;
}
.thumb.active .thumb-canvas { border-color: var(--accent); }
.thumb-canvas canvas { width: 100%; height: auto; display: block; }
.thumb-label { font-size: 11.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.thumb.active .thumb-label { color: var(--text); font-weight: 600; }
.thumb-skeleton { width: 100%; aspect-ratio: 8.5 / 11; background: var(--bg-3); border-radius: 3px; }

/* ---------- Stage ---------- */
#stage { flex: 1; position: relative; background: var(--stage); overflow: hidden; }
#workspace.split #stage { flex: 1 1 50%; min-width: 0; }

/* ---------- Split-view right pane ---------- */
#rightPane { display: none; }
#workspace.split #rightPane { display: flex; flex-direction: column; flex: 1 1 50%; min-width: 0; border-left: 2px solid var(--line); background: var(--stage); }
.rp-head { display: flex; align-items: center; gap: 8px; padding: 5px 8px; background: var(--bg-2); border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.rp-select { flex: 1; min-width: 0; background: var(--bg-3); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 4px 6px; font-size: 12.5px; }
.rp-nav { display: flex; align-items: center; gap: 4px; }
.rp-page { font-size: 11.5px; color: var(--text-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
.rp-viewport { flex: 1; overflow: auto; position: relative; }
.rp-wrap { position: relative; margin: 20px auto; width: max-content; background: #fff; box-shadow: 0 6px 30px rgba(0,0,0,.5); }
.rp-wrap canvas { display: block; }
#rpOverlay { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }
#viewport { position: absolute; inset: 0; overflow: auto; }
#pageWrap { display: none; position: relative; margin: 30px auto; width: max-content; box-shadow: 0 6px 30px rgba(0,0,0,.5); background: #fff; user-select: none; -webkit-user-select: none; }
#pdfCanvas { display: block; }
#overlay { position: absolute; top: 0; left: 0; overflow: visible; }

/* cursor per tool */
#stage.tool-select #overlay { cursor: default; }
#stage.tool-calibrate #overlay,
#stage.tool-linear #overlay,
#stage.tool-area #overlay,
#stage.tool-angle #overlay { cursor: crosshair; }
#stage.tool-count #overlay { cursor: copy; }
#stage.tool-text #overlay { cursor: text; }
#stage.tool-callout #overlay { cursor: crosshair; }
#stage.tool-auto #overlay,
#stage.tool-rect #overlay, #stage.tool-ellipse #overlay, #stage.tool-cloud #overlay { cursor: crosshair; }
#overlay .auto-rect { fill: rgba(255,255,255,.10); stroke: #ffffff; stroke-width: 1.5; stroke-dasharray: 5 4; }
#overlay .auto-prev { fill: #37c26b; stroke: #fff; stroke-width: 1.5; }
.full-range { width: 100%; margin: 4px 0 2px; accent-color: var(--accent); }
.auto-sens-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); margin-bottom: 12px; }
.calib-row input[type="text"] { flex: 1; background: var(--bg-3); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 8px 10px; font-size: 14px; }
#stage.tool-pan #overlay, #stage.tool-pan, #stage.can-pan #overlay, #stage.can-pan { cursor: grab; }
#stage.panning, #stage.panning #overlay { cursor: grabbing !important; }

/* ---------- Text boxes (annotations on the page) ---------- */
.text-layer { position: absolute; inset: 0; pointer-events: none; z-index: 8; }
.text-box { position: absolute; left: 0; top: 0; transform-origin: top left; pointer-events: auto; }
.tb-content {
  min-width: 16px; min-height: 1em; padding: 2px 4px; white-space: pre-wrap;
  font: 600 14px -apple-system, sans-serif; line-height: 1.25; cursor: move;
  border: 1px solid transparent; border-radius: 3px; outline: none;
}
.tb-content:empty::before { content: 'Text'; opacity: .45; }
.text-box.editing .tb-content { cursor: text; background: rgba(255,255,255,.9); border-color: currentColor; }
.text-box.locked .tb-content { cursor: default; }
.text-box.selected .tb-content { border: 1px dashed currentColor; }
/* handles: only when selected */
.tb-color, .tb-bg, .tb-resize { display: none; }
.text-box.selected .tb-color, .text-box.selected .tb-bg, .text-box.selected .tb-resize { display: block; }
.tb-color, .tb-bg { position: absolute; top: -11px; width: 22px; height: 20px; border-radius: 5px; background: #fff; border: 1px solid rgba(0,0,0,.45); box-shadow: 0 1px 4px rgba(0,0,0,.4); overflow: hidden; cursor: pointer; }
.tb-color { left: -11px; } .tb-bg { right: -11px; }
.tb-color .tb-ico, .tb-bg .tb-ico { position: absolute; top: 1px; left: 0; right: 0; display: flex; justify-content: center; color: #2a2d33; pointer-events: none; }
.tb-color .tb-ico svg, .tb-bg .tb-ico svg { width: 12px; height: 12px; }
.tb-color .tb-bar, .tb-bg .tb-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 5px; pointer-events: none; }
.tb-bar.none { background: repeating-linear-gradient(45deg, #ddd 0 3px, #fff 3px 6px) !important; }
.tb-color input, .tb-bg input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: none; padding: 0; }
.tb-resize { position: absolute; right: -7px; bottom: -7px; width: 12px; height: 12px; border-radius: 3px; background: var(--accent); border: 2px solid #fff; cursor: nwse-resize; }

/* ---------- Summary / legend box (lives on the page) ---------- */
.summary-box {
  position: absolute; left: 0; top: 0; z-index: 10; width: 230px; height: auto;
  background: #ffffff; color: #1a1d22; border: 1px solid #222;
  transform-origin: top left; box-shadow: 0 3px 16px rgba(0,0,0,.35);
  display: flex; flex-direction: column; overflow: hidden;
}
.summary-box[hidden] { display: none; }
.sb-header {
  display: flex; align-items: center; justify-content: space-between;
  background: #2f343c; color: #fff; padding: 5px 8px; cursor: move;
  font: 600 12.5px -apple-system, sans-serif; user-select: none;
}
.sb-tools { display: flex; gap: 2px; }
.sb-btn { background: transparent; border: none; color: #cbd2db; cursor: pointer; font-size: 14px; line-height: 1; padding: 1px 5px; border-radius: 4px; }
.sb-btn:hover { color: #fff; background: rgba(255,255,255,.12); }
.sb-body { padding: 6px 9px; overflow: auto; flex: 1; font: 12px -apple-system, sans-serif; }
.sb-empty { color: #888; text-align: center; padding: 14px 6px; }
.sb-resize { position: absolute; right: 0; bottom: 0; width: 15px; height: 15px; cursor: nwse-resize; background: linear-gradient(135deg, transparent 45%, #9aa0a8 45%, #9aa0a8 55%, transparent 55%, transparent 70%, #9aa0a8 70%, #9aa0a8 80%, transparent 80%); }
.sb-table { width: 100%; border-collapse: collapse; }
.sb-table th { text-align: left; padding: 5px 6px 2px; font-size: 10.5px; letter-spacing: .5px; text-transform: uppercase; color: #6a7078; border-bottom: 1px solid #d7dade; }
.sb-table td { padding: 3px 6px; border-bottom: 1px solid #eceef0; }
.sb-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sb-swatch { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: baseline; }
.sb-grand td { border-top: 2px solid #cfd2d6; border-bottom: none; font-weight: 700; padding-top: 5px; }

/* ---------- Print: isolate the drawing + summary, hide the app chrome ---------- */
@media print {
  @page { margin: 10mm; }
  #topbar, #tabbar, #toolrail, #pages, #panel, #hint, .drop-hint, #rightPane, .no-print,
  .markup-bar, .restore-bar, .tool-menu, .recent-menu { display: none !important; }
  /* editing chrome must never print: previews, handles, selection dashes, text-box controls */
  #overlay .mk-preview, #overlay .mk-handle, #overlay .snap-ring, #overlay .auto-prev, #overlay .auto-rect,
  .tb-color, .tb-bg, .tb-resize { display: none !important; }
  #overlay .selected .mk-line, #overlay .selected .mk-area { stroke-dasharray: none !important; }
  .text-box.selected .tb-content { border-color: transparent !important; }
  html, body { height: auto !important; overflow: visible !important; background: #fff !important; display: block !important; }
  #workspace { display: block !important; height: auto !important; }
  #stage { position: static !important; background: #fff !important; overflow: visible !important; flex: none !important; }
  #viewport { position: static !important; overflow: visible !important; }
  /* zoom (set by JS at print time) scales the whole drawing, canvas, markups, text,
     and summary, as one unit so it fits a single page instead of paginating. */
  #pageWrap { position: static !important; margin: 0 !important; box-shadow: none !important; }
  .summary-box { box-shadow: none !important; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* ---------- Drop hint ---------- */
.drop-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  pointer-events: none; text-align: center; color: var(--text-dim);
}
.drop-hint.dragover { background: rgba(76,141,255,.12); }
.drop-inner .drop-icon { font-size: 60px; color: var(--accent); opacity: .7; }
.drop-inner h2 { margin: 10px 0 4px; color: var(--text); font-weight: 600; }
.drop-inner p { margin: 3px 0; font-size: 13.5px; }
.drop-inner .tip { margin-top: 14px; opacity: .8; }

/* ---------- Hint bar ---------- */
.hint-bar {
  position: absolute; bottom: 68px; left: 50%; transform: translateX(-50%);
  background: rgba(20,20,20,.92); border: 1px solid var(--line);
  padding: 7px 14px; border-radius: 20px; font-size: 12.5px; color: var(--text);
  pointer-events: none; z-index: 15; white-space: nowrap;
}

/* ---------- SVG markup styling ---------- */
#overlay .mk-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
#overlay .mk-area { fill-opacity: .18; stroke-width: 2; stroke-linejoin: round; }
#overlay .mk-vertex { stroke: #fff; stroke-width: 1.5; }
#overlay .mk-count { stroke: #fff; stroke-width: 1.5; }
#overlay .mk-count-txt { fill: #fff; font: 600 11px sans-serif; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
#overlay .mk-label {
  font: 600 12px -apple-system, sans-serif; paint-order: stroke;
  stroke: rgba(15,17,20,.85); stroke-width: 3.5px; stroke-linejoin: round;
}
#overlay .mk-seg { font-weight: 500; font-size: 11px; }
#overlay .mk-total { font-weight: 700; font-size: 12.5px; stroke-width: 4px; }
#overlay .mk-hit { fill: none; stroke: transparent; stroke-width: 14; cursor: pointer; }
#overlay .mk-pen { fill: none; stroke-linecap: round; stroke-linejoin: round; }
#overlay .mk-hl { fill: none; stroke-linecap: round; stroke-linejoin: round; opacity: .35; mix-blend-mode: multiply; }

/* markup line contextual options bar */
.markup-bar {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); z-index: 16;
  display: none; align-items: center; gap: 10px; padding: 6px 8px;
  background: rgba(20,22,26,.95); border: 1px solid var(--line); border-radius: 24px;
}
.seg { display: flex; background: var(--bg-3); border-radius: 16px; padding: 2px; }
.seg-btn { border: none; background: none; color: var(--text-dim); cursor: pointer; font-size: 12.5px; padding: 4px 12px; border-radius: 14px; }
.seg-btn.active { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.mb-toggle { border: 1px solid var(--line); background: var(--bg-3); color: var(--text-dim); cursor: pointer; font-size: 12.5px; padding: 5px 12px; border-radius: 14px; }
.mb-toggle.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.mb-fill { background: var(--bg-3); border: 1px solid var(--line); color: var(--text); border-radius: 14px; font-size: 12.5px; padding: 5px 10px; cursor: pointer; }
.mb-color { position: relative; overflow: hidden; width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.3); cursor: pointer; background: #e5533d; }
.mb-color input { position: absolute; inset: -4px; width: calc(100% + 8px); height: calc(100% + 8px); opacity: 0; cursor: pointer; border: none; }
#overlay .mk-handle { fill: #fff; stroke: #1a1a1a; stroke-width: 2; cursor: grab; }
#overlay .mk-handle:hover { fill: #d0d0d0; }
#overlay .snap-ring { fill: none; stroke: #37c26b; stroke-width: 2; }
#stage.tool-select #overlay .selected .mk-hit { cursor: move; }
#overlay .selected .mk-line, #overlay .selected .mk-area { stroke-dasharray: 7 4; }
#overlay .mk-preview { stroke-dasharray: 5 4; opacity: .8; }

/* ---------- Right panel ---------- */
#panel { width: var(--panel); background: var(--bg-2); border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-family: var(--brand-font); font-weight: 700; font-size: 20px; letter-spacing: .5px; }
.panel-actions { display: flex; gap: 6px; }
.dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ---------- Conditions (named takeoff categories) ---------- */
.cond-add { display: flex; gap: 6px; padding: 10px 14px 6px; }
.cond-add .addcond { flex: 1; }
.cond-list { list-style: none; margin: 0; padding: 4px 8px 8px; border-bottom: 1px solid var(--line); max-height: 44%; overflow-y: auto; }
.cond {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 7px;
  cursor: pointer; border: 1px solid transparent;
}
.cond:hover { background: var(--bg-3); }
.cond.active { background: #333333; border-color: var(--accent); }
.cond .c-dot { position: relative; overflow: hidden; width: 15px; height: 15px; border-radius: 4px; flex: 0 0 auto; cursor: pointer; border: 2px solid rgba(255,255,255,.25); }
.cond .c-color { position: absolute; inset: -4px; width: calc(100% + 8px); height: calc(100% + 8px); opacity: 0; border: none; padding: 0; cursor: pointer; }
.cond .c-fill { background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 4px; font-size: 10.5px; padding: 0 1px; cursor: pointer; text-transform: capitalize; }
.cond .c-body { flex: 1; min-width: 0; }
.cond .c-name {
  width: 100%; background: transparent; border: 1px solid transparent; color: var(--text);
  font-size: 13.5px; font-weight: 600; padding: 2px 4px; border-radius: 4px;
}
.cond .c-name:hover { border-color: var(--line); }
.cond .c-name:focus { background: var(--bg); border-color: var(--accent); outline: none; }
.cond .c-sub { display: flex; align-items: center; gap: 8px; padding: 0 4px; flex-wrap: wrap; }
.cond .c-meta { font-size: 11px; color: var(--text-dim); }
.cond .c-costwrap { font-size: 11px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 2px; }
.cond .c-cost, .cond .c-depth { width: 46px; background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 4px; padding: 1px 4px; font-size: 11px; text-align: right; }
.cond .c-cost:focus, .cond .c-depth:focus { border-color: var(--accent); outline: none; }
.cond .c-uom { background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 4px; font-size: 10.5px; padding: 0 1px; cursor: pointer; }
.cond .c-eye { background: none; border: none; cursor: pointer; color: var(--text-dim); padding: 2px 3px; opacity: .85; flex: 0 0 auto; display: inline-flex; align-items: center; }
.cond .c-eye:hover { opacity: 1; color: var(--text); }
.cond.chidden { opacity: .55; }
.cond.chidden .c-total, .cond.chidden .c-ext { text-decoration: line-through; }
.cond .c-nums { text-align: right; white-space: nowrap; }
.cond .c-total { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.cond .c-ext { font-variant-numeric: tabular-nums; font-size: 11.5px; color: #cfcfcf; font-weight: 600; }
.cond .c-del { opacity: 0; color: var(--text-dim); border: none; background: none; cursor: pointer; padding: 2px 4px; display: inline-flex; align-items: center; }
.cond:hover .c-del { opacity: .8; }
.cond .c-del:hover { color: #ff8b76; opacity: 1; }
.cond .c-eye svg, .cond .c-del svg { display: block; }
.cond-empty { color: var(--text-dim); font-size: 12.5px; text-align: center; padding: 12px 10px; line-height: 1.5; }
.active-cond-bar { padding: 6px 14px; font-size: 12px; color: var(--text-dim); border-bottom: 1px solid var(--line); }
.active-cond-bar b { color: var(--text); }

.panel-subhead { padding: 10px 14px 6px; font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--text-dim); display: flex; justify-content: space-between; }
#pageTag { text-transform: none; letter-spacing: 0; }
.item-list { list-style: none; margin: 0; padding: 0 8px 20px; overflow-y: auto; flex: 1; }
.item {
  display: flex; align-items: center; gap: 9px; padding: 8px 8px; border-radius: 6px;
  cursor: pointer; font-size: 13px;
}
.item:hover { background: var(--bg-3); }
.item.selected { background: #333333; outline: 1px solid var(--accent); }
.item .i-dot { flex: 0 0 auto; }
.item .i-main { flex: 1; min-width: 0; }
.item .i-type { color: var(--text-dim); font-size: 11px; }
.item .i-val { font-variant-numeric: tabular-nums; }
.item .i-del { opacity: 0; color: var(--text-dim); border: none; background: none; cursor: pointer; font-size: 15px; padding: 2px 5px; }
.item:hover .i-del { opacity: 1; }
.item .i-del:hover { color: #ff8b76; }
.item-empty { color: var(--text-dim); font-size: 12.5px; text-align: center; padding: 20px 10px; }

/* ---------- Layers panel ---------- */
.layers-section { border-top: 1px solid var(--line); }
.layers-section > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 8px; font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--text-dim); }
.layers-section > summary::-webkit-details-marker { display: none; }
.layers-section > summary::before { content: '▸'; margin-right: 6px; transition: transform .15s; }
.layers-section[open] > summary::before { transform: rotate(90deg); }
.layers-section > summary #addLayer { text-transform: none; letter-spacing: 0; }
.layer-list { list-style: none; margin: 0; padding: 0 8px 14px; }
.layer { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.layer:hover { background: var(--bg-3); }
.layer.active { background: #333333; border-color: var(--accent); }
.layer .l-eye, .layer .l-lock, .layer .l-del { background: none; border: none; color: var(--text-dim); cursor: pointer; padding: 2px 3px; display: inline-flex; align-items: center; opacity: .8; }
.layer .l-eye:hover, .layer .l-lock:hover { color: var(--text); opacity: 1; }
.layer .l-del { opacity: 0; }
.layer:hover .l-del { opacity: .8; }
.layer .l-del:hover { color: #ff8b76; opacity: 1; }
.layer .l-name { flex: 1; min-width: 0; background: transparent; border: 1px solid transparent; color: var(--text); font-size: 13px; padding: 2px 4px; border-radius: 4px; }
.layer .l-name:hover { border-color: var(--line); }
.layer .l-name:focus { background: var(--bg); border-color: var(--accent); outline: none; }
.layer.lhidden .l-name { color: var(--text-dim); }
.layer .l-eye svg, .layer .l-lock svg, .layer .l-del svg { width: 15px; height: 15px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-card h3 { margin: 0 0 8px; font-family: var(--brand-font); font-weight: 700; font-size: 24px; letter-spacing: .5px; }
.modal-card p { color: var(--text-dim); font-size: 13.5px; margin: 0 0 14px; }
.calib-row { display: flex; gap: 8px; margin-bottom: 12px; }
.calib-row input, .calib-row select { background: var(--bg-3); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 8px 10px; font-size: 14px; }
.calib-row input { flex: 1; }
.calib-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); margin-bottom: 16px; }
.field-label { display: block; font-size: 11px; letter-spacing: .5px; text-transform: uppercase; color: var(--text-dim); margin: 4px 0 6px; }
.full-select { width: 100%; background: var(--bg-3); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 9px 10px; font-size: 14px; margin-bottom: 12px; }
.full-select optgroup { color: var(--text-dim); }
.full-select option { color: var(--text); }
.fine-print { font-size: 12px; color: var(--text-dim); line-height: 1.4; margin: 0 0 16px; }
.sheet-info { font-size: 13px; color: var(--text); background: var(--bg-3); border: 1px solid var(--line); border-radius: 6px; padding: 8px 11px; margin-bottom: 10px; }
.sheet-info .sz { color: var(--accent); font-weight: 600; }
.half-hint { font-size: 12.5px; color: #ffd18a; background: #33291a; border: 1px solid #5c4626; border-radius: 6px; padding: 8px 11px; margin-bottom: 12px; line-height: 1.4; }
.dim-note { color: var(--text-dim); font-size: 12px; }
.scale-status { cursor: pointer; }
.scale-status:hover { border-color: var(--accent); color: var(--text); }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; }
