:root {
  --chrome: #1f2328;
  --chrome-2: #2b3036;
  --border: #3a4048;
  --text: #e6e8eb;
  --muted: #9aa3ad;
  --accent: #2f81f7;
  --accent-hover: #4c94f8;
  --canvas-bg: #6b7178;
  --error: #e5534b;
  --toolbar-h: 52px;
  --status-h: 30px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* beat .btn etc. display rules */

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--chrome);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.muted { color: var(--muted); }

/* ---- Toolbar ---------------------------------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--toolbar-h);
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}

.group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.doc-name {
  flex: 1;
  min-width: 60px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--chrome-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.field {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--chrome);
  color: var(--text);
  font: inherit;
  text-align: center;
  -webkit-user-select: text;
  user-select: text;
}
.field:disabled { opacity: 0.4; }
.page-field { width: 48px; }
.zoom-field { width: 68px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- Viewport and page ------------------------------------------------ */

.workspace {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
}

.viewport {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: var(--canvas-bg);
  touch-action: none; /* we handle pinch and pan ourselves */
}
/* Cursor follows the active tool; Space or a pan always shows the hand. */
body.has-doc .viewport { cursor: default; }
body.has-doc .viewport[data-tool="pan"],
body.has-doc .viewport.space-pan { cursor: grab; }
body.has-doc .viewport[data-tool="text"] { cursor: text; }
body.has-doc .viewport:is([data-tool="line"], [data-tool="arrow"], [data-tool="rect"], [data-tool="cloud"],
  [data-tool="pen"], [data-tool="measure"], [data-tool="area"], [data-tool="calibrate"],
  [data-tool="callout"], [data-tool="count"], [data-tool="highlight"], [data-tool="polylength"],
  [data-tool="symbol"], [data-tool="stamp"], [data-tool="photo"]) { cursor: crosshair; }
body.has-doc .viewport.is-panning { cursor: grabbing; }

.stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  will-change: transform;
}

.page-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
/* Sharp tile of the visible area on big sheets (positioned in page points). */
.detail-canvas { position: absolute; pointer-events: none; }

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center; /* "safe": a long list scrolls instead of being cut off at the top */
  overflow-y: auto;
  gap: 12px;
  color: #fff;
  text-align: center;
  padding: 16px;
}
.empty-state > svg { width: 56px; height: 56px; stroke-width: 1.2; opacity: 0.8; }
.empty-state p { margin: 0; font-size: 16px; }
.empty-state .muted { color: #dde1e5; font-size: 13px; }
body.has-doc .empty-state { display: none; }

/* Markup layers: sized to the page in PDF points, drawn above the canvas. */
.markup-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none; /* the tools hit-test in JavaScript instead */
  /* Undo the toolbar-icon defaults set on every <svg> above (they gave
     text a grey outline); each markup class sets its own stroke/fill. */
  fill: none;
  stroke: none;
  stroke-width: 1;
}

/* Markups take their colour from their layer ("ByLayer"). */
.mk-stroke {
  fill: none;
  stroke: var(--layer-color);
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mk-fill { fill: var(--layer-color); }
.mk-fill-tint { stroke: none; }
.mk-area { fill: var(--layer-color); fill-opacity: 0.12; } /* same as AREA_FILL_OPACITY in export.js */
.mk-label-bg { fill: #fff; }
.mk-callout-box { fill: #fff; }
/* Opacities match HIGHLIGHT_OPACITY / COUNT_BOX_OPACITY in shapes.js. */
.mk-highlight { fill: var(--layer-color); fill-opacity: 0.3; stroke: none; }
.mk-count-box { fill: var(--layer-color); fill-opacity: 0.25; stroke: var(--layer-color); }
.mk-count-check { fill: none; stroke: #fff; stroke-linecap: round; stroke-linejoin: round; }
.mk-photo * { stroke: none; }
.mk-photo .mk-photo-glyph { fill: #fff; }

/* New callout being typed: white box like the finished one. */
.text-editor.callout-editor { background: #fff; }
.mk-text {
  fill: var(--layer-color);
  font-family: Arial, Helvetica, sans-serif;
  white-space: pre;
}
.draft { opacity: 0.75; }

/* Sheet links: a light blue box round sheet references you can click. */
.sheet-link { fill: rgba(47, 129, 247, 0.12); stroke: #2f81f7; stroke-width: 1; stroke-dasharray: 3 2; vector-effect: non-scaling-stroke; }

/* Snap marker: bright green so it stands out on any drawing. */
.snap-marker path { fill: none; stroke: #00c853; stroke-width: 2; vector-effect: non-scaling-stroke; }

/* Text search (Ctrl+F) matches: yellow, the current one orange. */
.text-hit { fill: rgba(255, 214, 0, 0.35); stroke: #d4a72c; stroke-width: 1; vector-effect: non-scaling-stroke; }
.text-hit.is-current { fill: rgba(255, 140, 0, 0.45); stroke: #ff8c00; stroke-width: 2.5; }

.search-bar {
  position: absolute;
  top: 10px;
  left: 50%;
  z-index: 6;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(560px, calc(100% - 24px));
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--chrome);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
.search-bar .field { flex: 1; min-width: 0; height: 32px; padding: 0 8px; text-align: left; user-select: text; }
.search-status { font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Symbol search matches under review: kept = orange, dropped = grey dashed. */
.search-hit {
  fill: rgba(255, 140, 0, 0.28);
  stroke: #ff8c00;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.search-hit.is-dropped {
  fill: rgba(120, 120, 120, 0.12);
  stroke: #888;
  stroke-dasharray: 4 3;
}

.rotate-stem {
  stroke: var(--accent);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}
.rotate-handle {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.resize-handle {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.selection-box {
  fill: rgba(47, 129, 247, 0.08);
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 5 3;
  vector-effect: non-scaling-stroke; /* same thickness at any zoom */
}

/* On-page text box; sized in page points so it zooms with the drawing. */
.text-editor {
  position: absolute;
  margin: 0;
  padding: 0;
  border: none;
  outline: 1px dashed var(--accent);
  background: rgba(255, 255, 255, 0.85);
  resize: none;
  overflow: hidden;
  white-space: pre;
  -webkit-user-select: text;
  user-select: text;
}

/* ---- Tools bar -------------------------------------------------------- */

/* Wraps onto a second row on narrower screens instead of scrolling. */
.toolsbar {
  height: auto;
  min-height: 46px;
  flex-wrap: wrap;
  row-gap: 6px;
  padding-top: 6px;
  padding-bottom: 6px;
  overflow-x: visible;
  background: var(--chrome-2);
}
.tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tool-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.divider {
  width: 1px;
  height: 24px;
  margin: 0 4px;
  background: var(--border);
}
.prop {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.prop .field {
  height: 30px;
  padding: 0 4px;
  text-align: left;
}
.rotate-field { width: 58px; }

#snap-btn[aria-pressed="true"] { color: #00c853; border-color: #00c853; }
.fmt-btn[aria-pressed="true"],
#bylayer-btn[aria-pressed="true"] {
  background: rgba(47, 129, 247, 0.25);
  border-color: var(--accent);
}
.btn.small { height: 30px; padding: 0 8px; font-size: 12px; }

/* Colour well: a rounded swatch wrapping the native colour picker. */
.color-swatch {
  display: inline-flex;
  width: 34px;
  height: 34px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--chrome);
  cursor: pointer;
}
.color-swatch input {
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.color-swatch input::-webkit-color-swatch-wrapper { padding: 0; }
.color-swatch input::-webkit-color-swatch { border: 0; border-radius: 3px; }

/* iPad portrait and small laptops: top toolbar buttons show icons only
   (tooltips keep the names). */
@media (max-width: 1100px) {
  #save-btn span, #export-btn span, #takeoff-btn span, #layers-btn span, #install-btn span { display: none; }
  #fit-width-btn { display: none; }
  .doc-name { min-width: 0; }
}

/* Labels make the tools bar too wide on mid-size screens; tooltips remain. */
@media (max-width: 1280px) {
  .toolsbar .prop > .muted:first-child { display: none; }
}

/* ---- Layers panel ----------------------------------------------------- */

.layers-panel {
  display: flex;
  flex-direction: column;
  width: 260px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--chrome);
  overflow-y: auto; /* short windows: scroll the panel rather than squash it */
}
body.layers-closed .layers-panel { display: none; }

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 12px 8px;
}
.panel-header h2 { margin: 0; font-size: 14px; font-weight: 600; }
.panel-hint { font-size: 11px; }

.layer-list {
  flex: 1;
  min-height: 96px; /* never squeezed away by the sections below */
  margin: 0;
  padding: 0 6px;
  list-style: none;
  overflow-y: auto;
}

.layer-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 4px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}
.layer-row:hover { background: var(--chrome-2); }
.layer-row.is-active { background: rgba(47, 129, 247, 0.18); border-color: var(--accent); }
.layer-row.is-hidden .layer-name { color: var(--muted); text-decoration: line-through; }
.layer-row.is-locked .layer-name { font-style: italic; }
.layer-row.is-dragging { opacity: 0.5; }
.layer-row.drop-before::before,
.layer-row.drop-after::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  height: 2px;
  background: var(--accent);
}
.layer-row.drop-before::before { top: -2px; }
.layer-row.drop-after::after { bottom: -2px; }

.layer-grip {
  display: flex;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  padding: 8px 0;
}
.layer-grip svg { stroke-width: 3; }

.layer-swatch {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.8);
  border-radius: 4px;
  cursor: pointer;
}

.layer-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.layer-name-input {
  flex: 1;
  min-width: 0;
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--chrome);
  color: var(--text);
  font: inherit;
  -webkit-user-select: text;
  user-select: text;
}

.layer-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.layer-toggle:hover { background: var(--border); }
.layer-toggle[aria-pressed="true"] { color: var(--muted); }
.layer-toggle svg { width: 16px; height: 16px; }

/* ---- Side panel tabs: Layers | List ----------------------------------- */

.panel-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-tab-btn {
  flex: 1;
  padding: 8px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.panel-tab-btn[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tab-badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--error);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
}
.panel-tab { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* ---- Markups list / punch list ---------------------------------------- */

.list-filters { display: flex; flex-direction: column; gap: 6px; padding: 10px 10px 4px; }
.list-filters .field, .item-details .field {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  text-align: left;
  -webkit-user-select: text;
  user-select: text;
}
.filter-row { display: flex; gap: 6px; }
.list-summary { margin: 0; padding: 2px 12px 6px; }
.list-empty { margin: 0; padding: 8px 12px; }
.item-list {
  flex: 1;
  min-height: 120px;
  margin: 0;
  padding: 0 6px;
  list-style: none;
  overflow-y: auto;
}
.item-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}
.item-row:hover { background: var(--chrome-2); }
.item-row.is-selected { background: rgba(47, 129, 247, 0.18); border-color: var(--accent); }
.item-num {
  flex-shrink: 0;
  min-width: 30px;
  height: 22px;
  border-radius: 11px;
  background: var(--chrome-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
}
.item-num[data-status] { background: var(--status-color, #8b949e); color: var(--status-text, #fff); }
.item-main { flex: 1; min-width: 0; }
.item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.item-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 11px; }
.item-photo-count { flex-shrink: 0; color: var(--muted); font-size: 11px; }

.item-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--chrome-2);
  flex-shrink: 0;
}
.item-details h3 { margin: 0; font-size: 14px; }
.item-details label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.item-details textarea.field { height: auto; padding: 6px 8px; resize: vertical; font: inherit; }
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photo-thumbs { display: flex; flex-wrap: wrap; gap: 6px; }
.photo-thumbs img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: zoom-in;
}
.photo-add { align-self: flex-start; cursor: pointer; flex-direction: row !important; color: var(--text) !important; }
.list-actions { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--border); flex-shrink: 0; }

/* Full-screen photo viewer */
.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.88);
}
.photo-viewer img { max-width: 100%; max-height: calc(100% - 70px); object-fit: contain; border-radius: 4px; }
.photo-viewer-actions { display: flex; gap: 8px; }

/* Punch item number badges on the drawing (sized in screen pixels). */
.item-badge circle { stroke: #fff; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.item-badge text { fill: var(--badge-text, #fff); font-weight: bold; font-family: Arial, Helvetica, sans-serif; text-anchor: middle; }

/* Sheets tab */
.sheet-list { flex: 1; min-height: 120px; margin: 0; padding: 8px 6px; list-style: none; overflow-y: auto; }
.sheet-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}
.sheet-row:hover { background: var(--chrome-2); }
.sheet-row.is-current { background: rgba(47, 129, 247, 0.18); border-color: var(--accent); }
.sheet-row img { width: 72px; height: 48px; object-fit: contain; background: #fff; border-radius: 3px; flex-shrink: 0; }
.sheet-row div { display: flex; flex-direction: column; min-width: 0; }
.sheet-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-sub { font-size: 11px; }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.sheet-actions label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.sheet-actions .btn { align-self: flex-start; }

/* "This PDF has N comments" bar under the layers. */
.pdf-comments {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: rgba(47, 129, 247, 0.08);
  flex-shrink: 0;
}
.pdf-comments p { margin: 0; }
.pdf-comments .btn { align-self: flex-start; }
.pdf-comments label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* Counts summary under the layers. */
.counts-section {
  border-top: 1px solid var(--border);
  max-height: 40%;
  overflow-y: auto;
  flex-shrink: 0;
}
.count-list { margin: 0; padding: 0 6px 8px; list-style: none; }
.count-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
}
.count-row:hover { background: var(--chrome-2); }
.count-row.is-current { background: rgba(47, 129, 247, 0.18); }
.count-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.count-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count-num { font-variant-numeric: tabular-nums; color: var(--muted); }
.count-num strong { color: var(--text); }
.count-empty { margin: 0; padding: 0 12px 12px; font-size: 12px; }

/* The count name box only matters while counting. */
body:not([data-tool="count"]) .count-prop { display: none; }
.count-field { width: 130px; text-align: left; padding: 0 6px; }

.layer-actions {
  display: flex;
  gap: 4px;
  padding: 8px;
  border-top: 1px solid var(--border);
}
.btn.danger:hover:not(:disabled) { border-color: var(--error); color: var(--error); }

.layer-color-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

/* ---- Status bar ------------------------------------------------------- */

.statusbar {
  display: flex;
  align-items: center;
  gap: 20px;
  height: var(--status-h);
  padding: 0 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}
.coords { font-variant-numeric: tabular-nums; min-width: 190px; }
.render-indicator { color: var(--muted); visibility: hidden; }
.render-indicator.is-active { visibility: visible; }
.save-status { color: var(--muted); }
.save-status.is-error { color: var(--error); }
.hint { margin-left: auto; }

/* ---- Recent drawings -------------------------------------------------- */

.drawing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  width: 100%;
  max-height: 55vh;
  overflow-y: auto;
}
.empty-state .drawing-grid { max-width: 820px; color: var(--text); }
.empty-recent-title { margin: 18px 0 0; font-size: 14px; font-weight: 600; }
.drawing-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--chrome);
  cursor: pointer;
  text-align: left;
}
.drawing-card:hover, .drawing-card:focus-visible { border-color: var(--accent); }
.drawing-card img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: contain;
  background: #fff;
  border-radius: 4px;
}
.drawing-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawing-meta { font-size: 11px; }
.drawing-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.drawing-remove:hover { background: var(--error); }

.offline-badge {
  padding: 4px 8px;
  border-radius: 10px;
  background: #9a6700;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

/* ---- Dialogs ---------------------------------------------------------- */

.dialog.dialog-wide { width: min(760px, calc(100% - 32px)); }

.dialog {
  width: min(440px, calc(100% - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--chrome);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog h2 { margin: 0 0 6px; font-size: 17px; }
.dialog > form > p { margin: 0 0 14px; font-size: 13px; }
.dialog fieldset {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.dialog legend { padding: 0 4px; color: var(--muted); font-size: 12px; }
.dialog label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
}
.export-layers { max-height: 200px; overflow-y: auto; }
.export-layers .swatch {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  border-radius: 3px;
}
.export-summary { min-height: 1.4em; }
.dialog label.stacked { flex-direction: column; align-items: stretch; gap: 4px; cursor: default; }
.dialog .field { height: 32px; padding: 0 6px; text-align: left; }
.dialog select.field { width: 100%; }
.dialog fieldset > .btn { margin-top: 8px; }
.dialog .spacer { flex: 1; }
.calibrate-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.calibrate-row select.field { width: auto; }
.field.num { width: 80px; }
.error-text { margin: 0 0 10px; color: var(--error); font-size: 13px; }

.scale-btn { margin-left: 4px; }
.scale-btn.is-unset { color: var(--muted); border-style: dashed; }
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ---- Symbol search panel ---------------------------------------------- */

.symbol-panel {
  position: fixed;
  left: 16px;
  bottom: calc(var(--status-h) + 16px);
  z-index: 10;
  width: min(300px, calc(100% - 32px));
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--chrome);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
}
.symbol-panel h2 { margin: 0 0 6px; font-size: 15px; }
.symbol-panel p { margin: 0 0 10px; font-size: 13px; }
.symbol-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 13px;
  cursor: pointer;
}
.symbol-panel label.stacked { flex-direction: column; align-items: stretch; gap: 4px; cursor: default; }
.symbol-panel .field { height: 30px; padding: 0 6px; text-align: left; }
.symbol-sample { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 10px; }
.symbol-sample label { flex: 1; margin: 0; }
.symbol-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}
.symbol-preview canvas { max-width: 56px; max-height: 56px; image-rendering: pixelated; }
.range-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.range-row input { flex: 1; }
.symbol-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.symbol-footer { justify-content: flex-end; margin-top: 10px; }
.symbol-status { font-variant-numeric: tabular-nums; }
.small-note { font-size: 12px; margin: 4px 0 0; }

/* ---- Revision compare ------------------------------------------------- */

.compare-panel { width: min(330px, calc(100% - 32px)); }
.compare-layer { position: absolute; inset: 0; pointer-events: none; image-rendering: auto; }
.compare-recent { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; max-height: 30vh; overflow-y: auto; }
.compare-recent-btn { justify-content: flex-start; overflow: hidden; text-overflow: ellipsis; }
.compare-page { width: auto !important; height: 26px !important; margin-left: 4px; }
.compare-legend { display: flex; align-items: center; gap: 6px; }
.compare-legend span { display: inline-block; width: 12px; height: 12px; border-radius: 2px; }
.swatch-removed { background: rgb(225, 40, 40); }
.swatch-added { background: rgb(0, 170, 70); }
.swatch-same { background: rgb(150, 155, 160); }

/* ---- Tool chest ------------------------------------------------------- */

.chest-panel { left: auto; right: 16px; width: min(320px, calc(100% - 32px)); }
.chest-list { margin: 0 0 10px; padding: 0; list-style: none; max-height: 50vh; overflow-y: auto; }
.chest-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 34px 6px 6px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}
.chest-item:hover { background: var(--chrome-2); border-color: var(--border); }
.chest-item .drawing-remove { top: 50%; transform: translateY(-50%); }
.chest-preview {
  position: static;
  width: 70px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 4px;
  background: #fff;
}
.chest-name { font-size: 13px; }

/* ---- Takeoff dialog --------------------------------------------------- */

.takeoff-table-wrap { max-height: 55vh; overflow: auto; margin-bottom: 12px; }
.takeoff-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.takeoff-table th, .takeoff-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.takeoff-table th { color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--chrome); }
.takeoff-table .num { text-align: right; }
.takeoff-table input { width: 90px; height: 28px; padding: 0 6px; text-align: right; }
.takeoff-table tfoot td { font-weight: 700; border-bottom: 0; }

/* ---- Help ------------------------------------------------------------- */

.help-body { max-height: 65vh; overflow-y: auto; font-size: 13px; }
.help-body h3 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.help-body table { width: 100%; border-collapse: collapse; }
.help-body td { padding: 3px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.help-body td:first-child { width: 38%; white-space: nowrap; }
.help-body kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--chrome-2);
  font: 12px ui-monospace, Consolas, monospace;
  text-align: center;
}
.help-body p { margin: 6px 0; }

/* ---- Messages and drag overlay ---------------------------------------- */

.message {
  position: fixed;
  left: 50%;
  bottom: calc(var(--status-h) + 16px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--chrome-2);
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.message.is-error { border-color: var(--error); }

.drop-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(47, 129, 247, 0.25);
  border: 3px dashed var(--accent);
  color: #fff;
  font-size: 22px;
  pointer-events: none;
}
body.is-dragging .drop-overlay { display: flex; }

/* ---- Narrow screens --------------------------------------------------- */

@media (max-width: 720px) {
  .toolbar { gap: 8px; padding: 0 8px; }
  .group { padding-left: 8px; }
  #open-btn span, #save-btn span, #export-btn span, #takeoff-btn span, #layers-btn span, .doc-name, .hint { display: none; }
  #fit-width-btn { display: none; }
  .prop > span { display: none; }
  /* Panel floats over the drawing as a drawer on phones. */
  .layers-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(280px, 85vw);
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.4);
    z-index: 5;
  }
}

/* ---- Team -------------------------------------------------------------------- */
#team-btn { position: relative; }
.team-dot {
  position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); box-shadow: 0 0 0 2px var(--chrome);
}
.team-dot[data-state="synced"] { background: #2da44e; }
.team-dot[data-state="offline"] { background: #d4a72c; }
.team-dot[data-state="error"] { background: var(--error); }
.team-dot[data-state="unshared"] { background: transparent; box-shadow: inset 0 0 0 2px var(--muted); }
#team-dialog { width: min(520px, calc(100% - 32px)); }
#team-dialog fieldset { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
#team-dialog fieldset > .btn { align-self: flex-start; margin-top: 0; }
#team-setup, #team-join { display: flex; flex-direction: column; gap: 10px; }
#team-setup > .btn { align-self: flex-start; }
#team-join > .btn.small { align-self: flex-start; }
#team-joined > .btn.small { margin-top: 10px; }
.team-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.team-code { font: 600 20px/1.3 ui-monospace, Consolas, monospace; letter-spacing: 0.04em; user-select: all; }
.team-status { font-size: 13px; margin: 10px 0; }
.team-status[data-state="offline"] { color: #d4a72c; }
.team-status[data-state="error"] { color: var(--error); }
.team-this {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.team-subtitle { font-size: 14px; margin: 16px 0 6px; }
.team-drawings { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow-y: auto; }
.team-drawings li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.team-drawings li > div { min-width: 0; }
.team-drawings .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-drawings .sub { color: var(--muted); font-size: 12px; }
.team-error { color: var(--error); font-size: 13px; margin: 10px 0 0; }

/* ---- Item extras (item-extras.js) -------------------------------------------------- */
.details-meta { margin: -2px 0 8px; font-size: 12px; color: var(--muted); }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.mic-btn { width: 28px; height: 28px; padding: 0; }
.mic-btn svg { width: 16px; height: 16px; }
.mic-btn.is-listening { color: #fff; background: var(--error); border-color: var(--error); }
.details-section { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.details-section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; font-size: 12px; font-weight: 600; }
.details-section-head .field { width: auto; max-width: 60%; height: 26px; font-size: 12px; }
.inline-row { display: flex; gap: 6px; align-items: flex-end; margin-top: 6px; }
.inline-row .field { flex: 1; min-width: 0; }
.checklist, .attach-list, .replies { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.checklist li { display: flex; align-items: center; gap: 6px; padding: 3px 0; flex-wrap: wrap; }
.checklist li > span:first-of-type { flex: 1; min-width: 0; }
.check-who { flex-basis: 100%; padding-left: 22px; font-size: 11px; color: var(--muted); }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0 2px; font: inherit; font-size: 12px; }
.link-btn:hover { text-decoration: underline; }
.signoff { margin-top: 8px; }
.signature-img { display: block; max-width: 180px; max-height: 60px; background: #fff; border-radius: 4px; margin-bottom: 4px; }
.signature-pad { display: block; width: 100%; height: auto; aspect-ratio: 3 / 1; background: #fff; border-radius: 6px; touch-action: none; margin-bottom: 10px; }
.attach-list li { display: flex; align-items: center; gap: 4px; padding: 2px 0; }
.attach-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 75%; text-align: left; }
.replies li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.reply-head { font-size: 11px; color: var(--muted); }
.reply-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Photo info and photo markup (photos.js) */
.photo-info { color: #dde1e5; font-size: 13px; }
.photo-info a { color: #8cc2ff; }
.photo-editor { justify-content: flex-start; }
.photo-editor-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.photo-editor .photo-editor-tools .btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.photo-editor-colors { display: inline-flex; gap: 4px; margin: 0 6px; }
.photo-editor-colors .swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #555; cursor: pointer; padding: 0; }
.photo-editor-colors .swatch[aria-pressed="true"] { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
.photo-editor-stage { flex: 1; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
.photo-editor-stage canvas { max-width: 100%; max-height: 100%; touch-action: none; cursor: crosshair; border-radius: 4px; }

/* View-only link: hide the editing controls. */
/* (No :has() here: one unsupported selector would void the whole rule.) */
body.read-only .tool-btn:not([data-tool="select"]):not([data-tool="pan"]),
body.read-only #camera-btn, body.read-only #chest-btn, body.read-only #snap-btn,
body.read-only .toolsbar > .group, body.read-only .toolsbar .divider,
body.read-only .photo-add, body.read-only .layer-actions { display: none !important; }
body.read-only .rotate-handle, body.read-only .rotate-stem { display: none; }

/* Team dialog: invites, who's online, activity, recently deleted */
.team-invites { display: flex; gap: 6px; flex-wrap: wrap; }
.team-viewonly { margin: 10px 0 0; padding: 8px 10px; border-radius: 6px; background: rgba(212, 167, 44, 0.15); color: #e3b341; font-size: 13px; }
.team-online { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 0; font-size: 12px; }
.team-online .person { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; background: var(--chrome-2); }
.team-online .person::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #2da44e; }
.team-online .person.viewer::before { background: var(--muted); }
.team-activity { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; font-size: 13px; }
.team-activity li { padding: 5px 0; border-bottom: 1px solid var(--border); }
.team-activity li.can-jump { cursor: pointer; }
.team-activity li.can-jump:hover { color: var(--accent-hover); }
.team-activity .when { color: var(--muted); font-size: 11px; }
.team-deleted { margin-top: 12px; font-size: 13px; }
.team-deleted summary { cursor: pointer; color: var(--muted); }
.team-deleted ul { list-style: none; margin: 6px 0 0; padding: 0; max-height: 180px; overflow-y: auto; }
.team-deleted li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--border); }
.team-drawings li.superseded .name { text-decoration: line-through; color: var(--muted); }
.team-this .btn { margin-left: auto; }

/* You are here (gps.js) */
.location-accuracy { fill: rgba(47, 129, 247, 0.15); stroke: rgba(47, 129, 247, 0.5); stroke-width: 1; vector-effect: non-scaling-stroke; }
.location-dot { fill: #2f81f7; stroke: #fff; stroke-width: 3; vector-effect: non-scaling-stroke; }

/* Search all drawings (search-all.js) */
.search-all { display: flex; gap: 6px; margin: 0 0 8px; }
.search-all .field { flex: 1; height: 32px; padding: 0 8px; text-align: left; }
.search-all-results { list-style: none; margin: 0 0 12px; padding: 0; max-height: 260px; overflow-y: auto; font-size: 13px; }
.search-all-results li { padding: 6px 8px; border-bottom: 1px solid var(--border); cursor: pointer; }
.search-all-results li:hover { background: var(--chrome-2); }
.search-all-results .where { font-weight: 600; }
.search-all-results .snippet { color: var(--muted); }
.search-all-results mark { background: rgba(212, 167, 44, 0.45); color: inherit; }

.gps-steps { padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 10px; }
.gps-steps p { margin: 0 0 8px; font-size: 13px; }
#daily-dialog { width: min(560px, calc(100% - 32px)); }
#daily-dialog textarea.field { height: auto; padding: 6px 8px; font: inherit; resize: vertical; }
#print-dialog fieldset label, #backup-dialog label { font-size: 13px; }

/* Communications devices (devices.js) */
.mk-device-shape { fill: #fff; stroke: var(--layer-color); }
.mk-device-wedge { fill: var(--layer-color); fill-opacity: 0.25; stroke: var(--layer-color); stroke-linejoin: round; }
.mk-device-code { fill: var(--layer-color); font-weight: bold; font-family: Arial, Helvetica, sans-serif; }
.mk-device .mk-text { stroke: none; }
.dev-stage { stroke: #fff; stroke-width: 1; vector-effect: non-scaling-stroke; }
.markup-overlay:not(.show-stage) .dev-stage { display: none; }
.markup-overlay.hide-dev-labels .dev-label { display: none; }
.mk-legend-box { fill: #fff; stroke: #333; stroke-width: 1; }
.mk-legend .mk-text, .mk-legend-text { fill: #222; stroke: none; font-family: Arial, Helvetica, sans-serif; }

/* Devices panel (device-panel.js) */
.devices-panel { left: auto; right: 16px; width: min(380px, calc(100% - 32px)); max-height: calc(100% - 140px); overflow-x: hidden; overflow-y: auto; }
.device-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px 6px; }
.device-list li { min-width: 0; }
.device-system { grid-column: 1 / -1; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; margin: 6px 0 2px; }
.device-pick { display: flex; align-items: center; gap: 6px; width: 100%; padding: 3px 4px; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--text); font: inherit; font-size: 12px; text-align: left; cursor: pointer; }
.device-pick:hover { background: var(--chrome-2); }
.device-pick[aria-pressed="true"] { border-color: var(--accent); background: rgba(47, 129, 247, 0.15); }
.device-pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-icon { width: 42px; height: 26px; flex: none; background: #fff; border-radius: 4px; }
.dev-section { margin: 6px 0; font-size: 13px; }
.dev-section summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
.dev-settings { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 6px 0; }
.dev-settings label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
.dev-settings label.check { justify-content: flex-start; }
.dev-settings .field { width: 110px; height: 28px; }
.dev-table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 4px 0 8px; }
.dev-table th, .dev-table td { padding: 3px 4px; border-bottom: 1px solid var(--border); text-align: left; }
.dev-table .num { text-align: right; }
.dev-checks { list-style: none; margin: 0; padding: 0; font-size: 12px; max-height: 180px; overflow-y: auto; }
.dev-check { padding: 4px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.dev-check.warn { color: #f0883e; }
.dev-check.info { color: var(--muted); }
.dev-badge:not(:empty) { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #f0883e; color: #111; font-size: 11px; text-align: center; }
.dev-info { white-space: pre-wrap; font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.dev-info.is-warn { color: #f0883e; }
body.has-doc .viewport[data-tool="device"] { cursor: crosshair; }
body.read-only .devices-panel .device-list, body.read-only #dev-legend, body.read-only #dev-renumber { display: none; }
.mk-device-code { stroke: none; }
.device-icon .mk-device-shape { stroke-linejoin: round; }

.door-hw { margin: 6px 0; }
.door-hw label { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 0; }
.item-details .door-hw label { flex-direction: row; align-items: center; justify-content: flex-start; gap: 6px; text-align: left; }

/* "Placing: Data drop" bar while the Devices tool is on */
.device-hint {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 6;
  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 24px);
  padding: 4px 12px 4px 6px; border-radius: 999px; background: rgba(31, 35, 40, 0.92); color: #fff;
  font-size: 13px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); pointer-events: none;
}
.device-hint[hidden] { display: none; }
.device-hint span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-hint .device-icon { width: 34px; height: 22px; }
.draft .mk-device { opacity: 0.6; }
body.has-doc .viewport[data-tool="device"] { cursor: none; } /* the device preview is the pointer */

.selection-box.extra { stroke-dasharray: 4 3; }
.marquee { fill: rgba(47, 129, 247, 0.08); stroke: var(--accent); stroke-width: 1; stroke-dasharray: 5 4; vector-effect: non-scaling-stroke; }
.mk-device.filled-solid .mk-device-code { fill: #fff; }
.dev-colors { display: flex; flex-direction: column; gap: 4px; padding: 4px 0 8px; }
.dev-colors label { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.dev-colors label span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-colors input[type="color"] { width: 32px; height: 24px; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: none; }
.dev-colors .device-icon { width: 34px; height: 22px; }
.dev-multi { margin: 4px 0; padding: 6px 8px; border-radius: 6px; background: rgba(47, 129, 247, 0.15); font-size: 12px; }

/* Devices from the legend (legend-takeoff.js) */
.dev-legend-btn { width: 100%; margin: 0 0 8px; }
.legend-table-wrap { max-height: 50vh; overflow: auto; margin-bottom: 10px; }
.legend-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.legend-table th, .legend-table td { padding: 4px 6px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.legend-table .field { width: 100%; height: 30px; }
.legend-sym { display: flex; align-items: center; gap: 6px; min-height: 30px; }
.legend-sym canvas { max-width: 48px; max-height: 32px; background: #fff; border-radius: 3px; image-rendering: pixelated; }
.legend-options { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 13px; }
.legend-options label { display: flex; align-items: center; gap: 6px; }
#legend-dialog { width: min(900px, calc(100% - 32px)); }

.search-row { display: flex; align-items: center; gap: 6px; }
.search-options { flex-wrap: wrap; gap: 4px; }
.search-options .btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.search-options .spacer { flex: 1; }
.search-results { list-style: none; margin: 0; padding: 0; max-height: min(320px, 45vh); overflow-y: auto; border-top: 1px solid var(--border); }
.search-results li { display: flex; gap: 8px; padding: 6px 4px; border-bottom: 1px solid var(--border); font-size: 12px; cursor: pointer; }
.search-results li:hover { background: var(--chrome-2); }
.search-results li.is-current { background: rgba(255, 140, 0, 0.18); }
.search-where { flex: none; width: 74px; color: var(--muted); }
.search-snippet { min-width: 0; overflow-wrap: anywhere; }
.search-snippet mark { background: rgba(255, 214, 0, 0.5); color: inherit; border-radius: 2px; }

/* Auto-hiding side panel: pin, and the tab on the right edge that brings it back */
.panel-pin { flex: none; width: 34px; margin-left: auto; border: 0; background: none; color: var(--muted); cursor: pointer; }
.panel-pin svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.panel-pin[aria-pressed="true"] { color: var(--accent); }
.panel-pin[aria-pressed="true"] svg { fill: currentColor; }
.panel-edge {
  position: fixed; right: 0; top: 50%; z-index: 7; transform: translateY(-50%);
  display: none; align-items: center; justify-content: center;
  width: 22px; height: 72px; padding: 0; border: 1px solid var(--border); border-right: 0;
  border-radius: 8px 0 0 8px; background: var(--chrome); color: var(--text); cursor: pointer;
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.3);
}
.panel-edge svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
body.has-doc.layers-closed .panel-edge { display: flex; }

/* Task pins (Fieldwire style) */
.mk-task-pin { stroke: #fff; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.mk-task-num { font-weight: bold; font-family: Arial, Helvetica, sans-serif; stroke: none; }
body.has-doc .viewport[data-tool="task"] { cursor: crosshair; }

/* ---- Tasks view: board, calendar, RFIs, settings (tasks-view.js) ---- */
.tasks-view { position: absolute; inset: 0; z-index: 8; display: flex; flex-direction: column; background: var(--chrome); color: var(--text); }
.tasks-view[hidden] { display: none; }
.tv-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.tv-tabs { display: flex; gap: 2px; }
.tv-tab { padding: 6px 12px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--muted); font: inherit; font-size: 14px; cursor: pointer; }
.tv-tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.tv-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; flex: 1; }
.tv-filters[hidden] { display: none; }
.tv-filters .field { height: 30px; width: auto; max-width: 170px; }
.tv-search { min-width: 140px; }
.tv-check { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; }
.tv-close { margin-left: auto; }
.tv-body { flex: 1; min-height: 0; overflow: auto; padding: 12px; }
.tv-board { display: flex; gap: 10px; align-items: flex-start; min-height: 100%; }
.tv-col { flex: 0 0 260px; display: flex; flex-direction: column; gap: 8px; padding: 8px; border-radius: 8px; background: var(--chrome-2); min-height: 120px; }
.tv-col.is-over { outline: 2px dashed var(--accent); }
.tv-col-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 2px 6px; border-top: 4px solid var(--muted); border-radius: 4px 4px 0 0; font-weight: 600; font-size: 13px; }
.tv-count { color: var(--muted); font-weight: normal; }
.tv-card { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--chrome); cursor: pointer; font-size: 13px; }
.tv-card:hover { border-color: var(--accent); }
.tv-card-top { display: flex; gap: 6px; align-items: flex-start; }
.tv-num { flex: none; padding: 1px 6px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.tv-title { min-width: 0; overflow-wrap: anywhere; }
.tv-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.tv-chips:empty { display: none; }
.tv-chip { padding: 0 6px; border: 1px solid var(--border); border-radius: 10px; font-size: 11px; color: var(--muted); }
.tv-chip.tag { border-style: dashed; }
.tv-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 11px; color: var(--muted); }
.tv-due.overdue, .tv-table .overdue { color: #f85149; font-weight: 600; }
.tv-move { height: 26px; font-size: 12px; }
@media (pointer: fine) { .tv-move { display: none; } }
.tv-cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.tv-month { min-width: 160px; text-align: center; font-weight: 600; }
.tv-cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.tv-dow { padding: 4px; font-size: 11px; color: var(--muted); text-align: center; }
.tv-day { min-height: 92px; padding: 4px; border-radius: 4px; background: var(--chrome-2); font-size: 11px; overflow: hidden; }
.tv-day.other { opacity: 0.45; }
.tv-day.today { outline: 2px solid var(--accent); }
.tv-daynum { display: block; color: var(--muted); margin-bottom: 2px; }
.tv-cal-item { margin-bottom: 2px; padding: 1px 4px; border-left: 3px solid var(--muted); border-radius: 2px; background: var(--chrome); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.tv-cal-item.overdue { color: #f85149; }
.tv-rfi-bar { display: flex; gap: 8px; margin-bottom: 10px; }
.tv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tv-table th, .tv-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.tv-table tbody tr { cursor: pointer; }
.tv-table tbody tr:hover { background: var(--chrome-2); }
.tv-pill { padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.tv-settings { max-width: 640px; }
.tv-settings h3 { font-size: 15px; margin: 4px 0 6px; }
.tv-status-rows { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.tv-status-row { display: flex; align-items: center; gap: 6px; }
.tv-status-row input[type="color"] { width: 36px; height: 30px; padding: 0; border: 1px solid var(--border); border-radius: 4px; background: none; }
.tv-status-row .field { flex: 1; min-width: 0; height: 30px; }
.tv-used { width: 64px; font-size: 11px; color: var(--muted); }
.tv-cats { width: 100%; height: auto; padding: 6px 8px; font: inherit; resize: vertical; }
.tv-settings-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; }
.rfi-fields label { display: flex; flex-direction: column; gap: 2px; margin: 6px 0; font-size: 12px; }
.rfi-fields textarea.field { height: auto; padding: 6px 8px; font: inherit; resize: vertical; }

/* Highlighter (a see-through marker) */
.mk-marker { stroke-opacity: 0.4; mix-blend-mode: multiply; }
body.has-doc .viewport[data-tool="marker"] { cursor: crosshair; }
/* Multi-selection frame */
.selection-box.group { stroke-dasharray: 8 4; fill: none; }
/* Hover tips */
.hover-tip {
  position: fixed; z-index: 60; max-width: 300px; padding: 6px 9px; border: 1px solid var(--border); border-radius: 6px;
  background: rgba(31, 35, 40, 0.96); color: var(--text); font-size: 12px; line-height: 1.35; pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.hover-tip[hidden] { display: none; }
.hover-tip-title { font-weight: 600; font-size: 13px; margin-bottom: 2px; }
.hover-tip div:not(.hover-tip-title) { color: var(--muted); }
.dev-naming { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0 0 8px; font-size: 12px; }
.dev-naming label { display: flex; align-items: center; gap: 6px; }
.dev-naming .field { width: 110px; height: 28px; }
.dev-head-actions { display: flex; gap: 4px; }
