/* Mobile contract: header, scrollable workspace, then dock in separate layout rows.
   Keep these rules last so older page styles cannot put content beneath the dock. */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
:root{--app-height:100dvh;--visual-top:0px}
#app :is(form,fieldset,.field,.fields,.aw-fields,.admin-card,.card,.ce-slot,.ce-blocked),
#modal :is(form,fieldset,.field,.fields,.aw-fields,.ce-slot,.ce-blocked){min-width:0}
#app :is(p,small,.note,.settings-row-label),#modal :is(p,small,.note){overflow-wrap:anywhere}
/* A row's metadata is content, not an inline suffix of its heading. */
.settingsrow>span:has(b,small){flex:1;min-width:0;overflow-wrap:anywhere}
.settingsrow>span:has(b,small)>b,.settingsrow>span>small{display:block}
.settingsrow>span>small{margin-top:6px}
.settingsrow>svg,.settingsrow>span:last-child:not(:first-child):not(:has(b,small)){flex-shrink:0}
.aw-table-scroll{max-width:100%;overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch}
.aw-table-scroll:focus-visible{outline:3px solid var(--brand);outline-offset:3px}
body input:is([type=date],[type=time],[type=datetime-local]){min-width:0;max-width:100%;width:100%;-webkit-appearance:none;appearance:none}
body input::-webkit-date-and-time-value{text-align:left;min-height:1.5em}

@media(max-width:1049px){
 body:has(#nav:not(:empty)){height:var(--app-height);top:var(--visual-top);bottom:auto;padding-left:0}
 body:has(#nav:not(:empty))>header.app-header{width:100%;margin:0;max-width:none;min-height:64px;grid-template-columns:52px minmax(0,1fr) 44px;gap:12px;padding:calc(8px + env(safe-area-inset-top,0px)) max(16px,env(safe-area-inset-right,0px)) 8px max(16px,env(safe-area-inset-left,0px))}
 body header.app-header>span{max-width:none;overflow-wrap:anywhere}
 body:has(#nav:not(:empty))>#app{flex:1 1 0;min-height:0;width:100%;max-width:100%;padding:20px max(16px,env(safe-area-inset-right,0px)) 24px max(16px,env(safe-area-inset-left,0px));scroll-padding-block:20px;overscroll-behavior-y:contain}
 body:has(#nav:not(:empty))>#nav,body[data-workspace=admin]:has(#nav:not(:empty))>#nav{
  position:relative;inset:auto;transform:none;flex:0 0 auto;align-self:center;width:calc(100% - 24px - env(safe-area-inset-left,0px) - env(safe-area-inset-right,0px));max-width:680px;margin:8px auto max(8px,env(safe-area-inset-bottom,0px));padding:8px 6px;border-radius:26px;gap:2px;
 }
 body #nav button,body[data-workspace=admin] #nav button{width:auto;min-width:0;min-height:60px;height:auto;max-width:none;padding:4px 2px;line-height:1.3;gap:4px;justify-content:center;font-size:.75rem;overflow-wrap:normal}
 body[data-workspace=admin] #nav button>span{overflow-wrap:normal;word-break:normal}
 body.mobile-keyboard:has(#nav:not(:empty))>#nav{display:none!important}
 body.mobile-keyboard:has(#nav:not(:empty))>#app{padding-bottom:24px}
 body .ce-savebar{position:static;margin:20px 0;padding:16px;box-shadow:none;flex-wrap:wrap}
 body .ce-savebar>button{flex:1 1 220px}
 body .ce-savebar>span{flex:1 1 180px}
 body #toast{bottom:calc(104px + env(safe-area-inset-bottom,0px));max-width:calc(100% - 32px);overflow-wrap:anywhere}
 body.mobile-keyboard #toast{top:calc(var(--visual-top) + 8px + env(safe-area-inset-top,0px));bottom:auto}
 /* Map controls stay within the remaining workspace; navigation no longer overlays it. */
 body.map-page:has(#nav:not(:empty))>#app{padding:0;position:relative;overflow:hidden}
 body.map-page #fieldmap{height:100%;min-height:0;max-height:none}
 body.map-page .housepanel{top:auto;bottom:12px;left:max(12px,env(safe-area-inset-left,0px));right:max(12px,env(safe-area-inset-right,0px));width:auto;max-width:none;max-height:60%;overflow-y:auto;overscroll-behavior:contain;scroll-padding:16px}
 body.map-page .housepanel:has(.map-idle-actions){left:50%;right:auto;width:max-content;max-width:calc(100% - 24px)}
 body.map-page .map-idle-actions{white-space:normal;flex-wrap:wrap;justify-content:center}
 body.map-page .leaflet-bottom{bottom:4px}
 body.map-page .locationbar{left:12px;right:66px;top:12px;max-width:calc(100% - 90px);max-height:28%;overflow:auto}
 body.map-page .fieldheader{left:auto;right:max(12px,env(safe-area-inset-right,0px));top:12px}
 body.map-page .houseaddress>div{grid-template-columns:minmax(72px,.35fr) minmax(0,1fr)}
 /* No nested sticky footers or full-screen heights extending behind the keyboard. */
 body #modal,body #modal:is(.detail-page,.member-page,.filter-sheet,.call-workspace){
  inset:var(--visual-top) 0 auto;margin: max(8px,env(safe-area-inset-top,0px)) auto 0!important;
  width:calc(100% - 16px - env(safe-area-inset-left,0px) - env(safe-area-inset-right,0px));max-width:700px;
  height:auto;max-height:calc(var(--app-height) - max(8px,env(safe-area-inset-top,0px)) - max(8px,env(safe-area-inset-bottom,0px)))!important;
  padding:20px 16px;border-radius:24px;overflow-y:auto;overscroll-behavior:contain;scroll-padding:20px;
 }
 body #modal>.title{position:static;display:flex;flex-direction:row;align-items:flex-start;gap:12px;padding:0;background:transparent}
 body #modal>.title h2{font-size:1.5rem;line-height:1.3;flex:1;min-width:0}
 body #modal>.title>button{flex:0 0 44px;min-height:44px}
 body #modal .actions,body #modal .ce-plan-actions{position:static;inset:auto;padding:0;flex-wrap:wrap}
 body #modal .actions>button,body #modal .ce-plan-actions>button{flex:1 1 180px;white-space:normal}
 body #modal.call-workspace .customer-panel{float:none;width:auto;margin:16px 0}
 body #modal.call-workspace .testflow{margin:16px 0;padding:18px}
 body #modal .detailrow{flex-wrap:wrap;gap:6px 16px}
 body #modal .detailrow>span{flex:1 1 100px;min-width:0}
 body #modal .detailrow>b{flex:1 1 140px;max-width:100%;overflow-wrap:anywhere}
 body #modal :is(.fields,.aw-fields){grid-template-columns:1fr}
 body #modal :is(.ce-section,.ce-plan-section){padding:16px}
}
@media(max-width:650px){
 body :is(.title,.sectionhead,.aw-heading,.directory-heading,.admin-section-heading,.perf-timer-head,.list-toolbar){flex-wrap:wrap;min-width:0;gap:12px}
 body :is(.title,.aw-heading,.directory-heading)>:is(h1,div){min-width:0;flex:1 1 180px}
 body .title>button:has(.ui-symbol){flex:0 0 44px}
 body :is(.workspace-heading,.lead-heading) h1{font-size:clamp(1.6rem,7vw,2rem)!important;line-height:1.2}
 body .aw-heading h1{font-size:clamp(1.6rem,7vw,2rem)}
 body :is(.primary,.secondary,.textbutton){white-space:normal;overflow-wrap:anywhere;max-width:100%}
 body :is(.card.formcard,.admin-card,.ce-section){padding:18px}
 body :is(.fields,.two,.aw-fields,.aw-profile-grid,.aw-company-grid,.directory-filters){grid-template-columns:minmax(0,1fr)}
 body :is(.field,.period label){min-width:0}
 body .field :is(input,select,textarea),body .period input{font-size:16px;max-width:100%}
 body .aw-metrics,body #app .metrics,body #app:has(.workspace-heading) .metrics{grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}
 body :is(.aw-metric,.today-metric){min-width:0;padding:18px 14px}
 body :is(.aw-metric,.today-metric) :is(strong,span){overflow-wrap:anywhere}
 body .aw-metric strong{font-size:clamp(1.6rem,7vw,2rem)}
 body .aw-quick-grid{grid-template-columns:minmax(0,1fr)}
 body .aw-date-form{grid-template-columns:repeat(2,minmax(0,1fr))}
 body .aw-date-form label{width:100%}
 body .aw-presets{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));width:100%}
 body .aw-presets button{white-space:normal}
 body :is(.seg,.directory-tabs,.lead-tabs,.cc-section-tabs,.partner-tabs,.aw-tabs){max-width:100%;overflow-x:auto;overscroll-behavior-x:contain;flex-wrap:nowrap;-webkit-overflow-scrolling:touch;scroll-padding-inline:6px}
 body :is(.seg,.directory-tabs,.lead-tabs,.cc-section-tabs,.partner-tabs,.aw-tabs)>button{flex:0 0 auto;white-space:nowrap;min-height:44px}
 body .settingsrow{gap:12px;padding:16px 12px;font-size:.9375rem}
 body .settingsrow>span:has(small){line-height:1.5}
 body .settingsrow>span:has(small)>small{font-size:.875rem}
 body .settingsrow>span:has(small)>b{font-size:1rem}
 body .settingsrow .settings-row-label{flex:1;min-width:0;overflow-wrap:anywhere}
 body .ce-card-actions{gap:10px;flex-wrap:wrap}
 body .ce-card-actions>button{flex:1 1 125px;padding-inline:12px}
 body .ce-savebar>span,body .ce-savebar>button{flex-basis:100%;width:100%}
 body .ce-slot{grid-template-columns:repeat(2,minmax(0,1fr))}
 body .ce-slot>button{grid-column:1/-1}
 body .ce-blocked{flex-wrap:wrap;align-items:end}
 body .ce-blocked>.field{flex:1 1 160px}
 body .ce-choice-group label{max-width:100%;overflow-wrap:anywhere}
 body :is(.cc-metrics,.queue-counts,.cc-slot-grid){grid-template-columns:repeat(2,minmax(0,1fr))}
 body .cc-slot-grid>.ap-slot{min-width:0;margin:0;padding:12px 8px;overflow-wrap:anywhere}
 body :is(.cc-agent,.cc-handoff,.dispatch-line,.perf-session,.flowcheck,.review-banner,.summary){min-width:0;flex-wrap:wrap;gap:10px}
 body .cc-agent>*,body .perf-session>*{min-width:0;overflow-wrap:anywhere}
 body .onboardstep{flex-wrap:wrap;gap:12px}
 body .onboardstep>div{flex:1 1 160px;min-width:0}
 body .onboardstep>.secondary{min-height:44px;font-size:.875rem}
 body .permissionrow>span{min-width:0;overflow-wrap:anywhere}
 body .lead-period-toolbar{flex-wrap:wrap;gap:8px}
 body .lead-period-toolbar .lead-date-box{flex:1 1 145px;padding:12px;min-height:48px}
 body .period-step{flex:0 0 44px}
 body .lead-filter-icon{flex-basis:44px;min-height:48px}
 body .identity>div{min-width:0;overflow-wrap:anywhere}
 body .admin-mini-grid{grid-template-columns:repeat(2,minmax(0,1fr));row-gap:18px}
}
@media(max-width:380px){
 body:has(#nav:not(:empty))>#app{padding-inline:12px}
 body :is(.period,.partner-dates,.aw-date-form){grid-template-columns:minmax(0,1fr)}
 body :is(.leadrow,#rows .leadrow,#member-rows .leadrow){grid-template-columns:minmax(0,1fr);gap:10px}
 body :is(.leadrow,#rows .leadrow) .badge,body .member-state{justify-self:start;max-width:100%;text-align:left}
 body .today-support{grid-template-columns:minmax(0,1fr);gap:12px}
 body .today-support>div+div{border-left:0;padding-left:0}
 body .ce-slot{grid-template-columns:minmax(0,1fr)}
 body #modal .detailrow>b{text-align:left;flex-basis:100%}
}
@media(max-width:1049px) and (max-height:500px){
 body:has(#nav:not(:empty))>header.app-header{min-height:48px;padding-block:4px}
 body:has(#nav:not(:empty))>#nav{margin-block:4px;padding-block:4px}
 body #nav button,body[data-workspace=admin] #nav button{min-height:44px;flex-direction:row;gap:6px}
 body.map-page .housepanel{max-height:75%}
}

/* Agency and lead workspaces start directly with their page heading. */
body:has(#app .agency-tabs,#app .lead-heading)>header.app-header{display:none}
body:has(#app .agency-tabs,#app .lead-heading)>#app{padding-top:calc(16px + env(safe-area-inset-top,0px))}
