.roof-layout-dialog {
  width: min(1520px, 98vw);
  max-width: 98vw;
  max-height: 96dvh;
  padding: 0;
  border: 1px solid #d5dee8;
  border-radius: 18px;
  color: #172b43;
  background: #f8fafc;
  font: 14px/1.5 system-ui, sans-serif;
  box-shadow: 0 30px 100px #0b223b55;
}
.roof-layout-dialog::backdrop { background: #0c1d34a6; }
.roof-layout-dialog header, .roof-layout-dialog footer, .layout-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  flex-wrap: wrap;
  border-bottom: 1px solid #dce4ed;
}
.roof-layout-dialog header { justify-content: space-between; background: white; }
.roof-layout-dialog h2 { margin: 0; font-size: 21px; }
.roof-layout-dialog small { color: #64748b; letter-spacing: .12em; }
.roof-layout-dialog button, .roof-layout-dialog input, .roof-layout-dialog select {
  font: inherit;
  color: inherit;
  background: white;
  border: 1px solid #bac9da;
  border-radius: 7px;
  min-height: 40px;
  padding: 7px 11px;
}
.roof-layout-dialog button { cursor: pointer; }
.roof-layout-dialog button:disabled { opacity: .45; cursor: default; }
.roof-layout-dialog button[aria-pressed="true"], .roof-layout-dialog .layout-primary {
  background: #1260aa;
  border-color: #1260aa;
  color: white;
}
.layout-workspace { display: grid; grid-template-columns: minmax(0, 1fr) 310px; }
.layout-drawing { position: relative; background: #f1f5f9; min-width: 0; }
.layout-drawing > svg { display: block; width: 100%; height: 100%; min-height: 0; touch-action: none; }
.layout-workspace aside { padding: 12px; background: white; min-height: 0; overflow: auto; }
.layout-workspace label { display: grid; gap: 4px; margin: 8px 0; }
.layout-workspace input, .layout-workspace select { width: 100%; box-sizing: border-box; }
.layout-workspace fieldset { border: 1px solid #dce4ed; border-radius: 10px; margin: 10px 0; padding: 10px; }
.layout-workspace p { color: #52657a; font-size: 12px; }
.layout-workspace .layout-help { font-size: 14px; color: #172b43; }
.layout-summary { display: block; margin-top: 0; font-weight: 600; }
.layout-status { flex: 1; min-width: 180px; }
.layout-grid { stroke: #dfe7ef; stroke-width: 1; }
.layout-face { stroke: #47759c; stroke-width: 2; }
.layout-triangle { stroke: #7494af; stroke-width: 1; stroke-dasharray: 5 5; fill: none; pointer-events: none; }
.layout-node { fill: #1764ad; stroke: white; stroke-width: 2; }
.layout-node.selected { fill: #ea580c; r: 9; }
.layout-drawing text { font: 12px system-ui; fill: #183b59; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.layout-path { fill: none; stroke: #ea580c; stroke-width: 3; }
.layout-launch { margin-top: 12px; }
.layout-launch button { width: 100%; padding: 12px; border: 0; border-radius: 8px; background: #1260aa; color: white; cursor: pointer; }
.layout-launch p { font-size: 12px; color: #64748b; }
@media (max-width: 680px) {
  .roof-layout-dialog { max-height: 96dvh; width: 98vw; max-width: 98vw; border-radius: 10px; }
  .layout-workspace { grid-template-columns: 1fr; }
  .layout-drawing svg { height: 45dvh; min-height: 260px; }
  .layout-workspace aside { max-height: none; }
  .roof-layout-dialog header, .roof-layout-dialog footer, .layout-toolbar { padding: 10px; }
}
/* Existing panel controls use display:grid, so explicitly preserve hidden state. */
.range-control[hidden], .layout-launch[hidden] { display: none; }
@media (max-width: 680px) {
  .layout-drawing text { font-size: 20px; }
  .layout-node { r: 10; }
  .layout-node.selected { r: 12; }
  .layout-toolbar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .layout-toolbar button { padding: 6px; font-size: 12px; }
}
.layout-node { cursor: grab; }
.layout-drawing svg:active .layout-node.selected { cursor: grabbing; }

.layout-face.attached { stroke: #ea580c; stroke-width: 3; }
#layoutSplitFaces label { display: flex; align-items: center; font-size: 12px; }
#layoutSplitFaces input { width: auto; min-height: 0; }
#layoutCopyInfo { display: block; font-size: 12px; color: #52657a; }

.layout-meet[hidden], #meetHeightControls[hidden], #meetPreview[hidden] { display: none; }
.layout-meet { background: #f0fdff; }
.layout-face.meet-target { fill: #a5f3fc; stroke: #0891b2; stroke-width: 4; }
.layout-meet-guide { stroke: #ea580c; stroke-width: 3; stroke-dasharray: 6 4; pointer-events: none; }
.layout-meet-ghost { fill: #fb923c66; stroke: #ea580c; stroke-width: 3; pointer-events: none; }
#meetResult { display: block; margin: 10px 0; font-size: 12px; }
#meetPreview { width: 100%; height: 190px; background: #f8fafc; border: 1px solid #cbd5e1; border-radius: 8px; }

/* Keep drawing, properties and footer within the desktop viewport. */
.roof-layout-dialog[open] { display: flex; flex-direction: column; height: min(940px, 96dvh); overflow: hidden; }
.roof-layout-dialog header, .layout-toolbar, .roof-layout-dialog footer { flex: none; }
.layout-workspace { flex: 1; min-height: 0; grid-template-rows: minmax(0, 1fr); }
.layout-drawing { overflow: hidden; }
.layout-toolbar { gap: 6px; background: #fff; }
.layout-toolbar button { display: inline-flex; align-items: center; gap: 7px; padding: 6px 10px; font-size: 13px; }
.layout-tool-icon { font-size: 19px; line-height: 1; width: 18px; text-align: center; }
.roof-layout-dialog button:hover:not(:disabled) { border-color: #1260aa; background: #edf5ff; color: #164d7c; }
.roof-layout-dialog :focus-visible { outline: 3px solid #38bdf8; outline-offset: 2px; }
.layout-toolbar [data-action="delete"] { margin-left: auto; color: #b42318; }
.layout-canvas-controls { position: absolute; top: 12px; display: flex; gap: 3px; padding: 4px; border: 1px solid #dce4ed; border-radius: 10px; background: #ffffffed; box-shadow: 0 2px 8px #17385812; }
.layout-history { left: 12px; }
.layout-zoom { right: 12px; }
.layout-canvas-controls button { min-width: 36px; min-height: 36px; padding: 4px 9px; border-color: transparent; font-size: 13px; }
.layout-canvas-controls [data-action="zoomIn"], .layout-canvas-controls [data-action="zoomOut"] { font-size: 21px; }
.layout-mode-hint { position: absolute; left: 12px; bottom: 10px; max-width: calc(100% - 24px); display: flex; align-items: center; gap: 8px; background: #ffffffed; border: 1px solid #dce4ed; border-radius: 8px; padding: 5px 9px; font-size: 12px; }
.layout-panel-heading { display: flex; align-items: center; justify-content: space-between; font-weight: 600; gap: 8px; }
.layout-select-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.layout-coordinate-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.layout-coordinate-row input { min-width: 0; padding: 7px 5px; }
.layout-workspace label { font-size: 12px; }
.layout-workspace legend { font-weight: 600; font-size: 13px; }
.layout-point > button { width: 100%; }
.layout-setup { margin: 12px 0; border-block: 1px solid #dce4ed; padding: 10px 0; }
.layout-setup > summary { cursor: pointer; font-weight: 600; }
.layout-setup > button { width: 100%; }
.layout-totals { font-size: 12px; color: #52657a; }
.layout-help-wrap { display: inline-flex; vertical-align: middle; }
.roof-layout-dialog .layout-info { display: inline-flex; justify-content: center; align-items: center; min-height: 24px; width: 24px; padding: 0; border-radius: 50%; font: 600 13px Georgia, serif; color: #52657a; }
.layout-tip { position: fixed; inset: auto; margin: 0; width: min(300px, calc(100vw - 32px)); box-sizing: border-box; padding: 12px 14px; border: 1px solid #aebed0; border-radius: 10px; background: #172b43; color: white; box-shadow: 0 8px 30px #10254033; font: 13px/1.55 system-ui, sans-serif; }
.layout-tip .layout-help { color: inherit; font-size: inherit; }
.roof-layout-dialog [hidden] { display: none !important; }
@media (max-width: 1000px) {
  .layout-toolbar { gap: 4px; }
  .layout-toolbar button { font-size: 12px; padding: 5px 7px; }
  .layout-workspace { grid-template-columns: minmax(0, 1fr) 280px; }
}
@media (max-width: 680px) {
  .roof-layout-dialog[open] { height: 96dvh; }
  .roof-layout-dialog h2 { font-size: 18px; }
  .roof-layout-dialog small { font-size: 9px; }
  .layout-workspace { display: block; overflow: auto; }
  .layout-drawing { height: 43dvh; min-height: 280px; }
  .layout-drawing > svg { height: 100%; min-height: 0; }
  .layout-toolbar { display: flex; flex-wrap: wrap; }
  .layout-toolbar button { flex: 1 0 auto; min-height: 36px; gap: 4px; }
  .layout-toolbar [data-action="delete"] { margin-left: 0; }
  .layout-tool-icon { font-size: 16px; width: 14px; }
  .layout-canvas-controls { top: 8px; }
  .layout-history { left: 8px; }
  .layout-zoom { right: 8px; }
  .layout-canvas-controls button { min-height: 36px; padding: 4px 6px; }
  .layout-workspace aside { overflow: visible; }
  .layout-status { font-size: 12px; min-width: 100%; }
  .roof-layout-dialog footer { justify-content: flex-end; gap: 6px; }
}

/* Explicit icon boxes keep wide glyphs clear of their button labels. */
.roof-layout-dialog .layout-tool-icon { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 22px; width: 22px; font-size: 18px; }
.layout-toolbar .layout-tool-label { display: inline-block; }
.layout-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; font-weight: 600; font-size: 13px; }
.layout-drawing .layout-surface-label { font: 700 20px system-ui, sans-serif; fill: #244763; stroke: #ffffffed; stroke-width: 6px; stroke-linejoin: round; pointer-events: none; }
@media (max-width: 680px) {
  .roof-layout-dialog .layout-tool-icon { flex-basis: 18px; width: 18px; font-size: 16px; }
  .layout-drawing .layout-surface-label { font-size: 25px; }
}

.layout-node.division-eligible { fill: #0891b2; stroke: #cffafe; stroke-width: 4; r: 10; cursor: crosshair; }
.layout-node.division-muted { opacity: .35; }
.layout-node.division-path { fill: #ea580c; stroke: white; stroke-width: 3; pointer-events: none; }

.layout-face.detach-selected { fill: #fed7aa; stroke: #ea580c; stroke-width: 4; }
.layout-face.detach-unavailable { opacity: .35; }

.layout-overlays { top: 66px; right: 12px; }
.layout-slope-arrow { fill: none; stroke: #0f4f78; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; filter: drop-shadow(0 0 2px white); }
@media (max-width: 680px) { .layout-overlays { right: 8px; top: 62px; } }

.roof-type-grid [data-roof-type="layout"] { grid-column: 1 / -1; }

.layout-drawing > svg.pan-enabled, .layout-drawing > svg.pan-enabled .layout-node { cursor: grab; }
.layout-drawing > svg.panning, .layout-drawing > svg.panning .layout-node { cursor: grabbing; }
@media (max-width: 680px) {
  .layout-history button { font-size: 11px; min-width: 30px; padding-inline: 4px; }
  .layout-zoom button { min-width: 30px; padding-inline: 4px; font-size: 12px; }
}

.layout-dormer { background: #eff6ff; }
.layout-dormer-outline { fill: #38bdf844; stroke: #0284c7; stroke-width: 3; stroke-dasharray: 7 4; pointer-events: none; }
#dormerPreview { width: 100%; height: 170px; background: #f8fafc; border: 1px solid #cbd5e1; border-radius: 8px; }
#dormerResult { display: block; font-size: 12px; margin: 10px 0; }

.layout-feature-actions { display: flex; gap: 6px; margin: 8px 0; }
.layout-feature-actions button { flex: 1; }
@media (min-width: 1001px) { .layout-toolbar button { padding-inline: 8px; gap: 8px; font-size: 12px; } }
