/* Native dialogs stay in the viewport; wide form content must shrink, not move the menu. */
@media screen and (max-width:800px){
 body dialog{position:fixed;inset:0;margin:auto;min-width:0;min-inline-size:0;max-width:calc(100vw - 24px);max-inline-size:calc(100vw - 24px);max-height:calc(100dvh - 24px);box-sizing:border-box;overflow-x:hidden;overflow-y:auto;overscroll-behavior-x:none;overflow-wrap:break-word}
 body dialog :is(form,fieldset,.fields,.row,.actions,.modal-actions,.notice,.card){min-width:0;min-inline-size:0;max-width:100%;max-inline-size:100%;box-sizing:border-box}
 body dialog :is(form,fieldset){width:100%}
 body dialog :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),select,textarea){display:block;width:100%;min-width:0;min-inline-size:0;max-width:100%;max-inline-size:100%;box-sizing:border-box;font-size:16px}
 body dialog input:is([type="month"],[type="date"]){appearance:none;-webkit-appearance:none;contain:inline-size}
 body dialog input:is([type="month"],[type="date"])::-webkit-date-and-time-value{min-width:0;max-width:100%;text-align:left}
 body dialog .row{flex-wrap:wrap}
 body dialog :is(.fields,.row,.actions,.modal-actions)>*{min-width:0;max-width:100%;box-sizing:border-box}
 body dialog :is(button,a.button-link){max-width:100%;white-space:normal;overflow-wrap:break-word}
 body dialog #google-address-lookup,body dialog #address-suggestions{min-width:0;max-width:100%;box-sizing:border-box}
 body dialog .address-suggestion{white-space:normal;overflow-wrap:anywhere}
}
/* The Customer select previously expanded to the longest option's intrinsic width. */
#property-form>#customer{display:block;width:100%;min-width:0;max-width:100%;box-sizing:border-box}
@media print{body dialog{position:static;overflow:visible;max-height:none}}
/* Inspection groups use one complete row when it fits, otherwise equal pairs. */
#modal .inspection-choices{display:grid;grid-template-columns:repeat(var(--choice-columns,2),minmax(0,1fr));grid-auto-rows:1fr}
#modal .inspection-choices>button{width:100%;min-width:0;min-height:44px;height:auto;padding:10px 8px;line-height:1.3;white-space:normal;overflow-wrap:normal;word-break:normal}

/* Keep inspection answers distinct from action buttons and show a non-colour selection cue. */
#modal .inspection-choices>button {
  position: relative;
  padding-block-start: 16px;
  overflow-wrap: anywhere;
  font-weight: 700;
  background: #f5f7f5;
  color: #173b2f;
  border: 1px solid #789486;
}
#modal .inspection-choices>button:not(:is(.selected,[aria-pressed="true"])):hover {
  background: #e8f0eb;
}
#modal .inspection-choices>button:is(.selected,[aria-pressed="true"]) {
  background: #d9ecaa;
  color: #173b2f;
  border-color: #276548;
  box-shadow: inset 0 0 0 1px #276548;
  font-weight: 700;
}
#modal .inspection-choices>button:is(.selected,[aria-pressed="true"])::before {
  content: "";
  position: absolute;
  inset-inline-end: 8px;
  top: 4px;
  width: 5px;
  height: 9px;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  pointer-events: none;
}

/* Narrow two-column rows must accommodate a wrapped label in mobile Safari. */
@media (max-width: 480px) {
  #modal .inspection-choices > button {
    min-height: calc(2.6em + 28px);
    appearance: none;
  }
}

/* Portal choices use a large checkbox immediately below its label. */
#employee-permissions>label{margin:18px 0 6px}
#employee-permissions>input[type="checkbox"]{display:block;width:28px;height:28px;min-width:28px;max-width:28px;margin:0 0 20px;padding:0;accent-color:#163d32;cursor:pointer}

/* Shared menu navigation keeps Back and Close aligned at every dialog width. */
#modal .menu-navigation{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;margin:0 0 18px;min-width:0}
#modal .menu-navigation>.menu-back{margin:0;flex:0 1 auto}
#modal .menu-navigation>button.close{display:inline-flex;align-items:center;justify-content:center;text-align:center;padding:0;line-height:1;box-sizing:border-box;position:static;float:none;margin:0;flex:0 0 44px;width:44px;height:44px;min-height:44px}

.directory-transfer-action{position:relative;display:inline-flex;align-items:center;gap:4px;max-width:100%;min-width:0}
.directory-transfer-action>button:first-child{min-width:0}
.directory-transfer-tip{position:absolute;z-index:20;bottom:calc(100% + 8px);left:0;width:270px;max-width:min(100%,calc(100vw - 96px));box-sizing:border-box;padding:10px;background:#163d32;color:white;border-radius:8px;font-size:13px;line-height:1.4;white-space:normal;visibility:hidden;pointer-events:none}
.directory-transfer-action:is(:hover,:focus-within)>.directory-transfer-tip{visibility:visible}
.directory-transfer-action:focus-visible{outline:3px solid #8bb8a5;outline-offset:3px;border-radius:8px}

/* Keep the Office estimate switcher within one touch-height row on phones. */
@media (max-width: 600px) {
  #modal[open]:has([data-estimate-page]) {
    display: grid;
    grid-template: 48px minmax(0, 1fr) / auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px;
    padding: 4px;
    width: 96vw;
    height: 94dvh;
    overflow: hidden;
  }
  #modal:has([data-estimate-page]) > .menu-navigation { display: contents; }
  #modal:has([data-estimate-page]) .menu-back { grid-area: 1 / 1; }
  #modal:has([data-estimate-page]) .close { grid-area: 1 / 3; }
  #modal:has([data-estimate-page]) > :is(.eyebrow, h2) { display: none; }
  #modal:has([data-estimate-page]) .estimate-office-tabs {
    grid-area: 1 / 2;
    display: grid;
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.3fr) minmax(0, 1fr);
    min-width: 0;
    gap: 4px;
    margin: 0;
  }
  #modal:has([data-estimate-page]) :is(.menu-back, [data-estimate-page]) {
    width: auto;
    min-width: 0;
    min-height: 44px;
    padding: 4px 6px;
    font-size: 14px;
  }
  #modal:has([data-estimate-page]) .estimate-office-tabs button {
    width: 100%;
    height: 48px;
    margin: 0;
    min-width: 0;
    padding: 2px 3px;
    font-size: 13px;
    line-height: 1.1;
    white-space: normal;
  }
  #modal:has([data-estimate-page]) [data-estimate-page="single-service-pricing"] {
    padding: 2px 4px;
    font-size: 13px;
    line-height: 1.1;
  }
  #modal .estimate-office-tabs .pricing-full { display: none; }
  #modal .estimate-office-tabs .pricing-short { display: inline; }
  #modal:has([data-estimate-page]) #estimate-office-frame {
    grid-area: 2 / 1 / 3 / -1;
    height: 100% !important;
    margin: 0 !important;
  }
  #modal:has([data-estimate-page]) > .action-feedback { position: absolute; z-index: 1; top: 54px; }
}

#directory-linked-review .linked-record-table {
 width:100%; border-collapse:collapse; table-layout:fixed; margin:0;
}
#directory-linked-review .linked-record-table :is(th,td) {
 border:1px solid #bccbc1; padding:.65rem .8rem; text-align:left; vertical-align:middle;
 overflow-wrap:anywhere;
}
#directory-linked-review .linked-record-table th { background:#edf3ee; color:#183e31; }
#directory-linked-review .linked-record-table :is(th,td):last-child { width:6rem; text-align:center; }
#directory-linked-review .linked-record-table label {
 display:flex; flex-direction:column; align-items:center; gap:.35rem; margin:0; cursor:pointer;
}
#directory-linked-review .linked-record-table input[type=checkbox] {
 display:inline-block; width:1.2rem; height:1.2rem; min-height:0; padding:0; margin:0;
 vertical-align:middle; accent-color:#163d32;
}
#directory-linked-review .linked-record-table :is(span,small) { display:block; }
#directory-linked-review .linked-record-table small { color:#485c50; }
#directory-linked-review .linked-record-footer {
 display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:.75rem; margin-top:1rem;
}

#modal .staff-login-tiles {
 display: grid;
 grid-template-columns: minmax(0, 1fr);
 justify-items: center;
 gap: .65rem;
}
#modal .staff-login-tiles > button {
 box-sizing: border-box;
 inline-size: 6rem;
 block-size: 6rem;
 display: grid;
 align-content: center;
 justify-items: center;
 gap: .4rem;
 padding: .35rem;
 margin: 0;
 border: 1px solid currentColor;
 border-radius: .5rem;
 text-align: center;
}
#modal .staff-login-tiles > button svg { width: 1.5rem; height: 1.5rem; }

@media screen {
 .workspace > header:has(#technician-site-name:not([hidden])) {
   position: sticky;
   top: 0;
   z-index: 4;
   height: auto;
   min-height: 64px;
 }
 #technician-site-name, #modal[data-site-name]::before {
   font-weight: 700;
   color: var(--green);
   overflow-wrap: anywhere;
 }
 #modal[data-site-name]::before {
   content: attr(data-site-name);
   display: block;
   position: sticky;
   top: 0;
   z-index: 12;
   background: white;
   border-bottom: 1px solid var(--line);
   padding: 6px 0;
   margin-bottom: 8px;
 }
}

@media screen {
 #modal[open][data-site-name]:has(> .project-gallery-scroll) {
   display: flex;
   flex-direction: column;
   overflow: hidden;
 }
 #modal[data-site-name]:has(> .project-gallery-scroll)::before {
   position: static;
   flex: none;
 }
 #modal[data-site-name] > .project-gallery-scroll {
   min-height: 0;
   overflow-y: auto;
   overscroll-behavior-y: contain;
 }
}


/* The site name occupies its own row. Only inspection content scrolls below it. */
@media screen {
 #modal[open].inspection-modal {
  display:flex; flex-direction:column; overflow:hidden;
  height:min(900px,calc(100dvh - 24px)); min-height:0;
 }
 #modal.inspection-modal[data-site-name]::before {
  position:static; flex:none; margin:0 0 8px;
 }
 #modal.inspection-modal > .inspection-scroll {
  flex:1; min-height:0; overflow-y:auto; overflow-x:hidden;
  overscroll-behavior:contain; scroll-padding-block:12px;
 }
}


/* Trash selection keeps each checkbox and label within one touch target. */
#modal .trash-choice {
 display:flex; align-items:center; gap:12px; min-height:48px; margin:8px 0;
 cursor:pointer; overflow-wrap:anywhere;
}
#modal .trash-choice input[type="checkbox"] {
 flex:0 0 28px; width:28px; height:28px; min-width:28px; min-height:28px;
 margin:0; padding:0; accent-color:#163d32;
}

/* Keep employee portal choices distinct at phone and desktop widths. */
#modal .employee-portal-choices {
 display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,160px),1fr));
 gap:12px; margin-top:16px; min-width:0;
}
#modal .employee-portal-choices > button { margin:0; width:100%; min-width:0; min-height:44px; white-space:normal; }
#modal .employee-overview-heading { gap:12px; margin-bottom:12px; }
#modal #employee-portal-list { margin:0 0 12px; }


#modal .staff-signin-options{display:grid;grid-template-columns:1fr 1fr;gap:12px;width:100%;max-width:none;margin:18px 0}
#modal .staff-signin-options button{width:100%;max-width:none;height:auto;aspect-ratio:auto;min-height:48px;display:flex;flex-direction:row;justify-content:center;align-items:center;gap:8px}
#modal .staff-signin-options #staff-passkey{grid-column:1/-1}
#modal .staff-signin-options :is(#staff-phone-passkey,#staff-reset-passkey){background:#eef3ef;color:#163d32;border:1px solid #a3b6aa}

#modal :is(.sales-portal-options,.staff-portal-options){display:grid;gap:8px;margin-top:16px}
#modal :is([data-sales-portal],[data-staff-portal]){display:flex;align-items:center;justify-content:space-between;text-align:left;padding:12px 16px;border-radius:8px;background:#f3f7f3;color:#153e30;border:1px solid #bfcdc3}
#modal :is([data-sales-portal],[data-staff-portal])::after{content:'›';margin-inline-start:auto}

#modal:has(.staff-portal-options, .sales-portal-options) :is(.menu-back, .close, #staff-chooser-sign-out, #sales-chooser-sign-out) {
  background: transparent;
  color: #214838;
  border: 1px solid transparent;
  box-shadow: none;
  min-height: 44px;
  min-width: 44px;
}
#modal :is(#staff-chooser-sign-out, #sales-chooser-sign-out) {
  margin-top: 8px;
  border-block-start: 1px solid #bfcdc3 !important;
  border-radius: 0;
}
#modal:has(.staff-portal-options, .sales-portal-options) :is(.menu-back, .close, #staff-chooser-sign-out, #sales-chooser-sign-out):hover {
  background: #edf3ee;
}
#modal:has(.staff-portal-options, .sales-portal-options) button:focus-visible {
  outline: 2px solid #326a50;
  outline-offset: 2px;
}

/* Present the signed-in chooser on a clean surface during staff entry. */
body:has(#workspace-lock-screen:not([hidden])) #modal[open]:has(.staff-portal-options)::backdrop {
  background: #f7f8f4;
  backdrop-filter: none;
}

/* Icon-only close controls share one square hit target across portal menus. */
dialog button:is(.close, #next-visit-close, #portal-email-close),
#modal .menu-navigation > button.close {
  box-sizing: border-box;
  display: grid !important;
  grid-template: 1fr / 1fr;
  place-items: center !important;
  place-content: center !important;
  text-align: center !important;
  width: 44px !important;
  min-width: 44px;
  height: 44px !important;
  min-height: 44px;
  padding: 0 !important;
  line-height: 1;
}
