.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; } }

.layout-roof-window { fill:#91d8ed; fill-opacity:.85; stroke:#17608e; stroke-width:3; cursor:pointer; }
.layout-window p,.layout-window output { font-size:12px; line-height:1.45; }
.layout-window output { display:block; margin:8px 0; }
.layout-window[hidden] { display:none; }

.layout-window svg { display:block; width:100%; height:150px; background:#f1f5f9; border-radius:8px; margin:8px 0; }
.layout-window svg[hidden] { display:none; }

.layout-window .layout-coordinate-row { grid-template-columns:repeat(2,minmax(0,1fr)); }

.layout-window input[type="range"] { width:100%; padding:0; accent-color:#1261a9; }
.layout-window .window-snap { display:flex; flex-direction:row; align-items:center; gap:8px; }
.layout-window .window-snap input { width:auto; }
.window-move-controls { display:flex; flex-wrap:wrap; gap:5px; }
.window-move-controls button:first-child { flex-basis:100%; }
.layout-roof-window.selected { fill:#fde68a; stroke:#d97706; stroke-width:4; }
.window-selection-handle { fill:#fff; stroke:#d97706; stroke-width:3; pointer-events:none; }
.window-label { paint-order:stroke; stroke:#fff; stroke-width:4px; font-weight:700; }

/* Keep validation visible even when the properties panel is scrolled. */
.layout-feedback {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: none;
  max-height: 22dvh;
  overflow: auto;
  margin: 8px 12px;
  padding: 12px;
  border: 1px solid #f0a49e;
  border-left: 5px solid #b42318;
  border-radius: 8px;
  background: #fff1f0;
  color: #8a1c13;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.layout-feedback > div { flex: 1; min-width: 0; }
.layout-feedback-title { display: block; margin-bottom: 3px; }
.layout-feedback-icon {
  display: grid;
  place-items: center;
  flex: 0 0 24px;
  height: 24px;
  border: 2px solid currentColor;
  border-radius: 50%;
  font-weight: 800;
}
.layout-feedback .layout-feedback-dismiss { min-height: 32px; padding: 0 9px; background: transparent; border-color: currentColor; }
.layout-feedback[data-severity="warning"], .layout-validation[data-severity="warning"] {
  color: #713f12;
  background: #fffbeb;
  border-color: #d97706;
}
.layout-validation { display: block; padding: 10px; margin-top: 8px; border: 1px solid; border-radius: 8px; line-height: 1.5; }
.layout-validation[data-severity="error"] { color: #8a1c13; background: #fff1f0; border-color: #d92d20; }
.layout-validation[data-severity="success"] { color: #166534; background: #f0fdf4; border-color: #86b99a; }
.layout-issue-marker { pointer-events: none; }
.layout-issue-marker circle { fill: #fff1f0; stroke: #b42318; stroke-width: 3px; stroke-dasharray: 4 2; }
.layout-drawing .layout-issue-marker text { fill: #b42318; stroke: none; font-size: 19px; font-weight: 800; }
@media (max-width: 680px) {
  .layout-feedback { margin: 5px 8px; padding: 8px; font-size: 12px; gap: 7px; }
}
.roof-layout-dialog input[aria-invalid="true"] { border: 2px solid #b42318; background: #fff1f0; }
.layout-launch p.layout-launch-error { padding: 12px; border: 1px solid #d92d20; border-left-width: 4px; border-radius: 8px; color: #8a1c13; background: #fff1f0; font-weight: 500; }

/* Five primary tools, with one compact options panel and contextual actions. */
.layout-toolbar { flex-wrap: nowrap; }
.layout-toolbar > button { flex: 0 1 auto; }
.layout-toolbar [data-tool-group]::after { content: '\25BE'; font-size: 11px; }
.layout-toolbar [data-tool-group][data-active="true"] { border-color: #1260aa; color: #1260aa; background: #edf5ff; }
.layout-toolbar [data-tool-group][aria-expanded="true"] { background: #1260aa; color: white; }
.layout-tool-options, .layout-context-actions {
  flex: none;
  padding: 8px 16px;
  border-bottom: 1px solid #dce4ed;
  background: #edf5ff;
}
.layout-tool-options > div, .layout-context-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.layout-tool-options button, .layout-context-actions button { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; }
.layout-context-actions { background: #fff; }
.layout-context-actions [data-action="delete"] { color: #b42318; }
.layout-current-tool { position: static; flex: none; max-width: none; margin: 0; padding: 7px 16px; border: 0; border-bottom: 1px solid #dce4ed; border-radius: 0; background: #f8fafc; }
@media (max-width: 680px) {
  .layout-toolbar { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 8px; gap: 5px; }
  .layout-toolbar > button { justify-content: center; min-width: 0; font-size: 11px; padding: 6px 4px; white-space: normal; }
  .layout-toolbar > button .layout-tool-icon { display: none; }
  .layout-tool-options { order: 10; border-top: 1px solid #bac9da; max-height: 23dvh; overflow: auto; padding: 10px; }
  .layout-context-actions { order: 9; padding: 7px 10px; max-height: 18dvh; overflow: auto; }
  .roof-layout-dialog footer { order: 11; }
  .layout-tool-options button { flex: 1 1 auto; }
  .layout-current-tool { font-size: 12px; padding: 6px 10px; }
}
@media (max-width: 680px) {
}

/* Feedback overlays the drawing without changing its pointer coordinate system. */
.layout-drawing > .layout-feedback {
  position: absolute;
  z-index: 5;
  bottom: 8px;
  left: 8px;
  right: 8px;
  margin: 0;
  max-height: min(22dvh, 50%);
  box-sizing: border-box;
  pointer-events: none;
}
.layout-feedback-dismiss { pointer-events: auto; }

.layout-axes line { stroke: #475569; stroke-width: 1.5; stroke-dasharray: 7 4; }
.layout-drawing .layout-axes text { font: 600 13px system-ui; fill: #334155; }

/* Keep mobile chrome compact while giving the plan most of the workspace. */
@media (max-width: 680px) {
  .roof-layout-dialog[open] { height:98dvh; max-height:98dvh; border-radius:10px; }
  .roof-layout-dialog header { padding:6px 10px; }
  .roof-layout-dialog header small { display:none; }
  .roof-layout-dialog h2 { font-size:16px; }
  .roof-layout-dialog header button { min-height:34px; padding:3px 10px; }
  .layout-toolbar { padding:5px 8px; gap:4px; }
  .layout-toolbar > button { min-height:34px; font-size:12px; padding:4px; line-height:1.2; }
  .layout-current-tool { padding:4px 8px; font-size:11px; line-height:1.3; }
  .layout-drawing { height:58dvh; min-height:320px; }
  .layout-tool-options, .layout-context-actions { padding:5px 8px; }
  .layout-tool-options button, .layout-context-actions button { min-height:34px; padding:4px 7px; font-size:12px; }
  .roof-layout-dialog footer { padding:5px 8px; gap:4px; }
  .roof-layout-dialog footer button { min-height:34px; padding:4px 9px; font-size:12px; }
  .layout-status { font-size:11px; line-height:1.2; }
  .layout-status:empty { display:none; }
}

.layout-mobile-properties { display:none; }
@media (max-width:680px) {
  .roof-layout-dialog header > div { flex:1; min-width:0; }
  .roof-layout-dialog header h2 { font-size:14px; }
  .layout-mobile-properties { display:block; font-size:12px !important; }
  .layout-mobile-properties[aria-expanded="true"] { background:#1260aa; color:white; }
  .layout-workspace aside { display:none; }
  .mobile-properties-open .layout-workspace aside {
    display:block; position:absolute; z-index:20; left:6px; right:6px; bottom:70px;
    max-height:55dvh; overflow:auto; border:1px solid #bac9da; border-radius:12px;
    box-shadow:0 -6px 24px #172b4333;
  }
}
.editor-drainage { border: 1px solid #7dd3fc; border-radius: 8px; padding: 10px; margin-bottom: 12px; background: #f0f9ff; }
.editor-drainage summary { cursor: pointer; font-weight: 700; }
.editor-drainage label { display: block; margin: 8px 0; }
.editor-drainage select, .editor-drainage input[type=number] { width: 100%; min-width: 0; }
.editor-drainage button { margin: 3px 2px 3px 0; }
