.field-popover {
 position:absolute; top:12px; right:12px; z-index:7;
 width:min(320px,calc(100% - 24px)); max-height:calc(100% - 124px);
 display:flex; flex-direction:column; overflow:hidden;
 color:var(--text); background:var(--panel); border:1px solid var(--line);
 border-radius:var(--radius); text-align:left;
}
.field-popover-heading { display:flex; flex:0 0 auto; align-items:center; justify-content:space-between; gap:8px; padding:10px 10px 10px 14px; border-bottom:1px solid var(--line); }
.field-popover-title { min-width:0; flex:1 1 auto; overflow-wrap:anywhere; }
.field-popover-heading-actions { display:flex; flex:0 0 auto; align-items:center; gap:4px; }
.canvas-stage:has(> .field-popover) > .photo-space-button { display:none; }
.field-popover-heading h3 { margin:0; font-size:16px; line-height:1.3; }
.field-popover-summary { margin:4px 0 0; font-size:12px; color:var(--muted); font-variant-numeric:tabular-nums; }
.field-popover-heading .button { width:44px; height:44px; flex:0 0 44px; padding:10px; }
.field-popover-heading .button span { display:none; }
.field-popover-orientation { flex:0 0 auto; padding:8px 14px; }
.field-popover-orientation .button { min-width:0; padding:8px; }
.field-popover-mounting { flex:0 0 auto; margin:0; padding:0 14px 8px; font-size:12px; color:var(--muted); }
.field-popover-brief { flex:0 0 auto; margin:0; padding:0 14px 8px; font-size:12px; }
.field-details-draft { display:block; margin-top:4px; font-weight:400; color:var(--accent); }
.field-details-draft[hidden] { display:none; }
.field-popover-details { min-height:0; overflow-y:auto; overscroll-behavior:contain; scrollbar-width:thin; }
.field-popover-details:not([open]) { flex:0 0 auto; }
.field-popover-details>summary { min-height:44px; padding:10px 14px; border-top:1px solid var(--line); font-size:14px; font-weight:600; cursor:pointer; }
.field-popover-details>summary:focus-visible { outline:2px solid var(--accent); outline-offset:-3px; }
.field-popover-body { padding:12px 14px; }

.field-popover-body>.hint { margin:0 0 14px; font-size:12px; }
.field-popover .field-empty-message { margin:0 0 14px; }
.field-popover .form-grid { gap:12px; }
.field-popover .field { font-size:12px; }
.field-popover form>.button { width:100%; }
.field-popover-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:4px; margin-top:12px; padding-top:8px; border-top:1px solid var(--line); }
.field-popover-actions .button { min-width:0; justify-content:flex-start; padding-inline:4px; font-size:12px; }
.field-popover-actions [data-action="restore-cells"],.field-popover-actions [data-action="delete-field"] { grid-column:1 / -1; }
@media (max-width:850px) {
 .field-popover { top:8px; right:8px; width:min(320px,calc(100% - 16px)); max-height:calc(100% - 96px); }
 .field-popover-heading { padding-block:0; }
 .field-popover-orientation { padding-block:0; }
 .field-popover-body { padding-block:10px; }
}

@media (max-width:850px) and (max-height:450px) and (orientation:landscape) {
 .field-popover { position:fixed; top:68px; max-height:calc(100dvh - 76px); }
 .canvas-stage:has(> .field-popover)>.canvas-controls { left:12px; right:auto; }
 .field-popover:has(> .field-popover-details[open]) { overflow-y:auto; overscroll-behavior:contain; scrollbar-width:thin; }
 .field-popover:has(> .field-popover-details[open])>.field-popover-heading { position:sticky; top:0; z-index:1; background:var(--panel); }
 .field-popover:has(> .field-popover-details[open])>.field-popover-details { flex:0 0 auto; overflow:visible; }
}

/* The active mobile field has one orientation control group. Closing its
   popup restores the toolbar shortcut, including the expanded photo view. */
@media(max-width:850px){
 .workarea:has(> .canvas-stage > .field-popover[data-compact="true"]) > .orientation-bar > .orientation-choice{display:none;}
 #app.photo-expanded .workarea:not(:has(> .canvas-stage > .field-popover)) > .orientation-bar:has([data-action="field-settings"]){display:flex;}
}

/* Keep the short landscape photo tall when a selected field's popup is closed. */
@media(max-width:850px) and (max-height:450px) and (orientation:landscape){
 #app.photo-expanded .workarea:has(> .orientation-bar [data-action="field-settings"]):not(:has(> .canvas-stage > .field-popover)){display:grid;grid-template-columns:248px minmax(0,1fr);grid-template-rows:auto auto minmax(0,1fr) auto;}
 #app.photo-expanded .workarea:has(> .orientation-bar [data-action="field-settings"]):not(:has(> .canvas-stage > .field-popover)) > .toolbar-shell{grid-column:1 / -1;grid-row:1;}
 #app.photo-expanded .workarea:has(> .orientation-bar [data-action="field-settings"]):not(:has(> .canvas-stage > .field-popover)) > .tool-help{grid-column:1 / -1;grid-row:2;}
 #app.photo-expanded .workarea:has(> .orientation-bar [data-action="field-settings"]):not(:has(> .canvas-stage > .field-popover)) > .orientation-bar{grid-column:1;grid-row:3;align-self:stretch;align-content:start;flex-wrap:wrap;gap:4px;padding:8px;border-bottom:0;border-right:1px solid var(--line);overflow-y:auto;}
 #app.photo-expanded .workarea:has(> .orientation-bar [data-action="field-settings"]):not(:has(> .canvas-stage > .field-popover)) > .canvas-stage{grid-column:2;grid-row:3;min-height:0;}
 #app.photo-expanded .workarea:has(> .orientation-bar [data-action="field-settings"]):not(:has(> .canvas-stage > .field-popover)) > .canvas-footer{grid-column:1 / -1;grid-row:4;}
 #app.photo-expanded .workarea:not(:has(> .canvas-stage > .field-popover)) > .orientation-bar:has([data-action="field-settings"]) .orientation-choice{flex:1 0 100%;}
 #app.photo-expanded .workarea:not(:has(> .canvas-stage > .field-popover)) > .orientation-bar:has([data-action="field-settings"]) .button{min-width:44px;min-height:44px;}
 #app.photo-expanded .workarea:not(:has(> .canvas-stage > .field-popover)) > .orientation-bar:has([data-action="field-settings"]) > [data-action="roof-setup"]{flex:1;}
 #app.photo-expanded .workarea:not(:has(> .canvas-stage > .field-popover)) > .orientation-bar:has([data-action="field-settings"]) > [data-action="direction-turn"]{flex:1 0 100%;}
}

/* On short screens the complete contextual editor must remain reachable. */
@media(max-width:850px) and (max-height:740px){
 .field-popover{display:block;overflow-y:auto;overscroll-behavior:contain;max-height:calc(100% - 16px);}
 .field-popover-details{overflow:visible;}
}

/* Context editor: one inset and consistent gaps for related controls. */
.field-popover-heading{padding:12px 12px 12px 16px;gap:12px}
.field-popover-orientation{padding:12px 16px 0;gap:8px}
.field-popover .field-live-form{margin:0;padding:12px 16px}
.field-popover .field-live-form .form-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}
.field-popover .field{margin:0;min-width:0;gap:6px;line-height:1.4}
.field-popover .field input{min-height:44px;width:100%;min-width:0;padding:8px;font-size:14px}
.field-popover .field-live-form>[data-live-status]{display:block;margin:8px 0 0;font-size:12px;line-height:1.45}
.field-popover>.field-selection-actions{margin:0;padding:8px 16px 0;border-top:1px solid var(--line);gap:8px}
.field-popover .field-selection-actions>.button{min-height:44px}
.field-popover>.object-movement-mode{padding:8px 16px 0;gap:8px}
.field-popover .object-movement-mode>.button{min-height:44px}
.field-popover>.object-movement{padding:8px 16px 16px;gap:12px}
.field-popover .object-movement>label{margin:0;gap:6px;min-width:64px}
.field-popover-details>summary{padding:12px 16px;line-height:1.4}
.field-popover-body{padding:12px 16px}
@media(max-width:850px){.field-popover .field input{font-size:16px}.field-popover-heading{padding-block:8px}.field-popover-orientation{padding-top:8px}}

.field-popover-body>.field-popover-actions{margin-top:0;padding-top:0;border-top:0;gap:8px}

/* A narrow photo can be shorter than the property editor even on a tall
   phone. Scroll the complete sheet, so forms never shrink over its actions. */
.field-popover>.field-live-form{flex:0 0 auto}
@media(max-width:850px) and (orientation:portrait){
 .field-popover{position:fixed;z-index:40;top:auto;right:8px;bottom:72px;width:min(360px,calc(100% - 16px));max-height:min(68dvh,600px);display:block;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin}
 .field-popover-heading{position:sticky;top:0;z-index:2;background:var(--panel)}
 .field-popover-details{overflow:visible}
}

@media(max-width:850px) and (orientation:portrait){
 .canvas-stage:has(>.field-popover){z-index:30}
}

/* Frequent field tasks stay visible; the complete inspector can use the photo height. */
.field-popover{width:min(360px,calc(100% - 24px));max-height:calc(100% - 24px);display:block;overflow-y:auto;overscroll-behavior:contain}
.field-popover-heading{position:sticky;top:0;z-index:2;background:var(--panel)}
.field-popover-details{overflow:visible}.field-direct-actions{display:flex;gap:6px;flex-wrap:wrap;padding:8px 14px;border-top:1px solid var(--line)}
.field-direct-actions .button{min-height:44px;flex:1;font-size:12px;padding:6px}
.field-selection-list{border:0;border-top:1px solid var(--line);margin:0;padding:8px 14px}
.field-selection-list legend{font-weight:600;font-size:13px;padding:0}.field-selection-list p{font-size:12px;margin:4px 0 6px;color:var(--muted)}
.field-check-items{max-height:180px;overflow:auto}.field-check-items label{display:flex;align-items:center;gap:10px;min-height:48px;cursor:pointer;padding:4px 6px;border-radius:4px}
.field-check-items label:has(:checked){background:var(--accent-soft)}.field-check-items input{width:44px;min-height:44px;height:44px;flex:0 0 44px;accent-color:var(--accent)}
.field-check-items strong{font-size:13px}.field-check-items small{display:block;font-size:12px;color:var(--muted)}
.field-selection-list .field-selection-actions{display:flex;margin:4px 0 0;padding:0}.field-selection-list .field-selection-actions .button{font-size:12px;min-height:36px;padding:4px 8px}
@media(max-width:850px) and (orientation:portrait){.field-popover{max-height:min(74dvh,720px)}}

.field-live-form h4{font-size:13px;margin:0 0 6px}

.field-popover>.field-live-form{padding:8px 14px}

.canvas-stage:has(.field-preview)>.source-caption{visibility:hidden}

/* Keep roof dimensions and placement reachable while a field is selected. */
@media (max-width:850px) and (orientation:portrait) {
 .metric-surface .canvas-stage > .field-popover {position:absolute;top:8px;bottom:auto;max-height:calc(100% - 16px)}
}

@media (min-width:851px) {
 .canvas-stage:has(> .field-popover, > .plane-popover) > .canvas-controls {
   left:12px;
   right:auto;
   bottom:36px;
 }
}
