/* 410 Today R41.1 · Ledger layout stabilization
   Trigger: visual acceptance screenshots showed desktop/editor compression plus a mobile toolbar void and horizontal table overflow.
   Scope: layout/presentation only. Universal Item data, filters, editor behavior, R39 promotion and R41 view state remain unchanged.
*/

@media (min-width:901px){
  .ledger-admin-shell{
    grid-template-columns:238px minmax(0,1fr)!important;
  }
}

/* One obvious control rail. Count + view belong together; filters stay on the far right. */
.ledger-toolbar{
  display:flex!important;
  align-items:center!important;
  justify-content:space-between!important;
  gap:16px!important;
  min-width:0!important;
  min-height:0!important;
  height:auto!important;
  align-self:start!important;
}
.ledger-toolbar-primary{
  display:flex!important;
  align-items:center!important;
  gap:14px!important;
  min-width:0!important;
}
.ledger-toolbar-primary .ledger-bulk-meta{
  flex:0 0 auto!important;
  opacity:1!important;
}
.ledger-view-toggle{
  flex:0 0 auto!important;
}
.ledger-selects{
  margin-left:auto!important;
  flex:0 1 auto!important;
}

/* The closed editor should not permanently consume half the Ledger.
   Records get the full canvas. Selecting one opens a bounded right-side drawer. */
.ledger-workspace{
  position:relative!important;
  display:grid!important;
  grid-template-columns:minmax(0,1fr)!important;
  overflow:hidden!important;
}
.ledger-table-pane{
  width:100%!important;
  min-width:0!important;
  border-right:0!important;
}
.ledger-editor-pane{
  display:none!important;
}
.ledger-editor-pane.open{
  display:block!important;
  position:absolute!important;
  inset:0 0 0 auto!important;
  width:min(520px,46vw)!important;
  z-index:40!important;
  border-radius:24px 0 0 24px!important;
  border:1px solid var(--ledger-r40-line-strong,rgba(29,29,31,.18))!important;
  box-shadow:-18px 0 42px rgba(0,0,0,.14)!important;
  background:#fff!important;
}

/* Give the table enough room to read at normal desktop widths. */
.ledger-table{
  width:100%!important;
}
#ledgerTable[data-view="table"] .ledger-table-head,
#ledgerTable[data-view="table"] .ledger-record{
  grid-template-columns:88px minmax(260px,1.8fr) 94px 100px 94px 110px 118px!important;
}

/* Card view should breathe across the full record canvas. */
#ledgerTable[data-view="cards"]{
  grid-template-columns:repeat(auto-fill,minmax(290px,1fr))!important;
}

@media(max-width:1100px){
  .ledger-toolbar{
    align-items:flex-start!important;
    flex-direction:column!important;
    justify-content:flex-start!important;
  }
  .ledger-toolbar-primary{
    width:100%!important;
    justify-content:space-between!important;
  }
  .ledger-selects{
    width:100%!important;
    margin-left:0!important;
    flex-wrap:wrap!important;
  }
  .ledger-editor-pane.open{
    width:min(520px,62vw)!important;
  }
}

@media(max-width:900px){
  .ledger-admin-shell{
    grid-template-columns:82px minmax(0,1fr)!important;
  }
  .ledger-editor-pane.open{
    position:fixed!important;
    inset:0 0 0 82px!important;
    width:auto!important;
    border-radius:0!important;
  }
}

@media(max-width:620px){
  /* Mobile becomes document flow instead of a viewport-height application grid.
     This removes the giant empty control cavity seen in acceptance screenshots. */
  .ledger-admin-shell{
    display:block!important;
    min-height:100vh!important;
  }
  .ledger-admin-main{
    display:block!important;
    height:auto!important;
    min-height:100vh!important;
    overflow:visible!important;
  }
  .ledger-admin-header,
  .ledger-toolbar,
  .ledger-workspace{
    position:static!important;
  }
  .ledger-toolbar{
    display:flex!important;
    flex-direction:column!important;
    align-items:flex-start!important;
    justify-content:flex-start!important;
    gap:12px!important;
    min-height:0!important;
    height:auto!important;
    padding-top:12px!important;
    padding-bottom:12px!important;
  }
  .ledger-toolbar-primary{
    width:100%!important;
    display:flex!important;
    flex-direction:column!important;
    align-items:flex-start!important;
    justify-content:flex-start!important;
    gap:10px!important;
  }
  .ledger-selects{
    display:flex!important;
    width:100%!important;
    gap:8px!important;
    flex-wrap:wrap!important;
  }
  .ledger-selects select{
    flex:1 1 150px!important;
    min-width:0!important;
  }
  .ledger-view-toggle{
    width:max-content!important;
  }
  .ledger-workspace{
    display:block!important;
    min-height:0!important;
    overflow:visible!important;
  }
  .ledger-table-pane{
    overflow:visible!important;
    border-radius:20px!important;
  }
  .ledger-table{
    min-width:0!important;
    width:100%!important;
  }

  /* Table mode becomes a compact stacked record list on phones rather than
     forcing the seven-column 760px desktop table through a narrow viewport. */
  #ledgerTable[data-view="table"] .ledger-table-head{
    display:none!important;
  }
  #ledgerTable[data-view="table"] .ledger-record{
    display:grid!important;
    grid-template-columns:1fr 1fr!important;
    grid-template-rows:auto auto auto auto!important;
    gap:10px 14px!important;
    align-items:start!important;
    padding:16px!important;
    border-bottom:1px solid rgba(29,29,31,.08)!important;
  }
  #ledgerTable[data-view="table"] .ledger-record-id{
    grid-column:1!important;
    grid-row:1!important;
  }
  #ledgerTable[data-view="table"] .ledger-record-name{
    grid-column:1/-1!important;
    grid-row:2!important;
  }
  #ledgerTable[data-view="table"] .ledger-record-name strong,
  #ledgerTable[data-view="table"] .ledger-record-name small,
  #ledgerTable[data-view="table"] .ledger-cell{
    white-space:normal!important;
    overflow:visible!important;
    text-overflow:clip!important;
  }
  #ledgerTable[data-view="table"] .ledger-cell{
    position:relative!important;
    padding-top:14px!important;
  }
  #ledgerTable[data-view="table"] .ledger-cell::before{
    position:absolute!important;
    top:0!important;
    left:0!important;
    font-size:.58rem!important;
    font-weight:800!important;
    letter-spacing:.06em!important;
    text-transform:uppercase!important;
    color:#8e8e93!important;
  }
  #ledgerTable[data-view="table"] .ledger-cell:nth-child(3)::before{content:'Type'}
  #ledgerTable[data-view="table"] .ledger-cell:nth-child(4)::before{content:'Shape'}
  #ledgerTable[data-view="table"] .ledger-cell:nth-child(5)::before{content:'Cadence'}
  #ledgerTable[data-view="table"] .ledger-cell:nth-child(6)::before{content:'Horizon'}
  #ledgerTable[data-view="table"] .ledger-status{
    grid-column:2!important;
    grid-row:1!important;
    justify-self:end!important;
  }

  #ledgerTable[data-view="cards"]{
    grid-template-columns:1fr!important;
    padding:12px!important;
  }
  .ledger-editor-pane.open{
    position:fixed!important;
    inset:0!important;
    width:auto!important;
    border-radius:0!important;
  }
}
