/* forms-structure.css — approved scoped layer (2026-11-22).
   Founder: forms sprawl and pan sideways on phone. This layer only constrains:
   it never hides or removes a control. Loaded after each page's approved CSS. */
:root{--fs-gap:8px;--fs-ink:#272727;--fs-accent:#A86339}
/* Nothing may push the page wider than the viewport */
html,body{max-width:100%;overflow-x:clip}
:is(form,.card-body,.modal,.modal-body,dialog,[role=dialog],.drawer,.panel) :is(input:not([type=checkbox]):not([type=radio]):not([type=range]),select,textarea){max-width:100%;min-width:0;box-sizing:border-box}
:is(form,.card-body,.modal-body,dialog,[role=dialog]) > *{min-width:0}
/* Labels sit above their field on an 8px rhythm */
:is(form,.card-body) label:is(.ua-l,.gf-l,.form-label,.lbl){display:block;margin:0 0 4px}
/* Wide data tables: a contained scroller, never a page-wide overflow */
:is(.card-body,.table-wrap,.tbl-wrap):has(> table){overflow-x:auto;overscroll-behavior-x:contain;max-width:100%}

@media (max-width:760px){
  /* Any inline grid of fields collapses to ONE column; span-2 cells stop
     forcing a phantom second column (cause of "My email account" overflow). */
  :is(form,.card-body,.modal-body,dialog,[role=dialog],.form-grid,.fg,.grid2,.grid3)[style*="grid-template-columns"],
  :is(.form-grid,.form-row,.grid2,.grid3,.fields,.field-grid){grid-template-columns:minmax(0,1fr)!important;gap:var(--fs-gap)!important}
  :is(form,.card-body,.modal-body,dialog,[role=dialog]) [style*="grid-column"]{grid-column:1 / -1!important}
  :is(form,.card-body,.modal-body,dialog,[role=dialog]) :is(input:not([type=checkbox]):not([type=radio]):not([type=range]),select,textarea){width:100%}
  /* Button rows wrap instead of clipping ("Sav") */
  :is(form,.card-body,.modal-body,.modal-foot,.modal-footer,dialog,[role=dialog]) div:has(> .btn + .btn){flex-wrap:wrap;gap:var(--fs-gap)}
  :is(form,.card-body,.modal-body,.modal-foot,.modal-footer) .btn{max-width:100%;white-space:normal}
  /* Table toolbar (cp-select.js): one tidy wrapping row, compact controls */
  .cptbl-host{padding:8px 8px 0;position:sticky;left:0}
  /* Card header holding a toolbar: title + 44px icon buttons on row 1, toolbar full-width below */
  .card-head:has(> .cptbl-bar){display:flex!important;flex-wrap:wrap!important;align-items:center;gap:var(--fs-gap)!important}
  .card-head:has(> .cptbl-bar) > :is(h2,h3){flex:1 1 0;min-width:0}
  .card-head > .cptbl-bar{flex:1 0 100%!important;order:9}
  /* Toolbar: pickers row, then search + X on one row, then the count */
  .cptbl-bar{display:grid!important;grid-template-columns:minmax(0,1fr) 44px;gap:var(--fs-gap)!important;align-items:center;width:100%;margin:0!important}
  .cptbl-bar > *{min-width:0}
  .cptbl-bar > .cptbl-picks{grid-column:1 / -1;order:0;display:flex!important;flex-wrap:wrap;gap:var(--fs-gap);align-items:center}
  .cptbl-bar > input:not([type=checkbox]){order:1;grid-column:1;min-width:0!important;width:100%!important}
  .cptbl-bar > .cptbl-clear{order:2;grid-column:2}
  .cptbl-bar > .cnt{order:3;grid-column:1 / -1}
  .cptbl-bar .cptbl-picks > .cptbl-note{flex:1 0 100%}
  .cptbl-bar .cptbl-picks > .cptbl-lbl{flex:0 0 auto}
  .cptbl-bar .cptbl-picks > select{flex:1 1 140px;width:auto;min-width:0}
  .cptbl-bar button:not(.cptbl-chip){width:44px;min-width:44px;min-height:44px;padding:0!important;display:inline-flex;align-items:center;justify-content:center}
  /* console-approved.css (round 5) sets bare .np table wrappers to overflow:visible so the
     header can stick to the viewport; on phone that pushed wide tables past the card
     (Pickup board, Arrival clearance, Club add-ons, Ad Radar). Containment wins. */
  #admin-app #admin-content .np:not(.card-body):has(> .tbl){overflow-x:auto!important;overscroll-behavior-x:contain}
  /* Any .tbl: contained scroller, readable columns instead of crushed ones */
  :is(div,section):has(> table.tbl){overflow-x:auto;overscroll-behavior-x:contain;max-width:100%}
  table.tbl{width:max-content;min-width:100%}
  table.tbl th{white-space:nowrap}
  table.tbl td{min-width:88px;max-width:240px}
  table.tbl :is(th,td):first-child{position:sticky;left:0;z-index:1;background:var(--ca-panel,var(--surface,#272727))}
  /* Header icon buttons (refresh etc.) stay 44px squares, not empty slabs */
  .card-head .btn:has(> i.ti:only-child){width:44px;min-width:44px;padding:0!important;flex:0 0 44px;justify-content:center}
  /* Wide tables: sticky first column inside the contained scroller */
  :is(.card-body,.table-wrap,.tbl-wrap) > table th{white-space:nowrap}
  :is(.card-body,.table-wrap,.tbl-wrap) > table td{min-width:88px}
  :is(.card-body,.table-wrap,.tbl-wrap) > table :is(th,td):first-child{position:sticky;left:0;z-index:1;background:var(--ca-panel,var(--surface,#fff))}
  :is(.card-body,.table-wrap,.tbl-wrap) > table thead :is(th,td):first-child{z-index:2}
}
@media (min-width:761px){
  :is(.form-grid,.field-grid){display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,220px),1fr));gap:var(--fs-gap)}
}
