/* Desktop Công nợ uses the same left-workspace geometry as Chi tiết đơn. */
.pc-mode #customerDebtModalWrapper,
body[data-force-pc="1"] #customerDebtModalWrapper{
  left:0 !important;
  right:480px !important;
  top:0 !important;
  bottom:0 !important;
  width:auto !important;
  height:auto !important;
  justify-content:stretch !important;
  background:#fff !important;
}
.pc-mode #customerDebtBackdrop,
body[data-force-pc="1"] #customerDebtBackdrop{
  display:none !important;
}
.pc-mode #customerDebtBottomSheet,
body[data-force-pc="1"] #customerDebtBottomSheet{
  position:relative !important;
  width:100% !important;
  height:100% !important;
  max-height:none !important;
  border-radius:0 !important;
  transform:none !important;
  box-shadow:none !important;
  background:#fff !important;
}
.pc-mode #customerDebtBottomSheet > .cart-handle,
body[data-force-pc="1"] #customerDebtBottomSheet > .cart-handle{
  display:none !important;
}
.pc-mode #customerDebtContentToShare,
body[data-force-pc="1"] #customerDebtContentToShare{
  min-height:0 !important;
}


/* Debt P2/P3/P4 mobile: keep balances, customer identity and actions legible.
   No new scroll, network, click handlers, or debt mutation owners. */
/* UI-126: panel-scoped controls; no viewport breakpoint for a fixed 428px workspace. */
  #tab-cong-no #quickDebtCustomerButton,
  #tab-cong-no #quickDebtAmount,
  #tab-cong-no button[onclick^="submitQuickDebt("]{
    min-height:44px;
  }
  #tab-cong-no #quickDebtAmount,
  #customerDebtBottomSheet #popupDebtAmount{
    min-height:44px;
    font-size:16px !important;
  }
  #tab-cong-no #btnFilterNo,
  #tab-cong-no #btnFilterDu,
  #tab-cong-no #btnFilterHet{
    min-width:0;
    min-height:44px;
    padding:6px 4px;
    font-size:12px;
    line-height:1.25;
    white-space:normal;
  }
  #tab-cong-no #sortContainer{
    gap:8px;
    min-width:0;
  }
  #tab-cong-no #debtGroupTitle{
    flex:1 1 auto;
    min-width:0;
  }
  #customerDebtBottomSheet #cDebtModalName{
    min-width:0;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
  }
  #customerDebtBottomSheet button[onclick="shareCustomerDebtImage()"],
  #customerDebtBottomSheet button[onclick="closeCustomerDebtModal()"]{
    min-width:40px;
    min-height:40px;
  }
  #customerDebtBottomSheet button[onclick^="submitPopupDebt("]{
    min-height:44px;
  }

/* UI-125 — The app is a centered 428px mobile panel even when desktop
   browser windows are different sizes. Never select a compact debt layout
   from OUTER viewport width (e.g. 500 vs 730px). Only use the actual
   in-panel summary grid width. */
#tab-cong-no > header > .grid{
  container-type:inline-size;
}
#tab-cong-no > header > .grid > div{
  min-width:0;
  flex-direction:row;
  align-items:center;
  justify-content:space-between;
  gap:4px;
}
#tab-cong-no #totalDebtDisplay,
#tab-cong-no #totalSurplusDisplay{
  flex:0 0 auto;
  max-width:100%;
  align-self:center;
  font-variant-numeric:tabular-nums;
  white-space:nowrap;
}
@container (max-width:330px){
  #tab-cong-no > header > .grid > div{
    flex-direction:column;
    align-items:stretch;
    justify-content:flex-start;
    gap:6px;
  }
  #tab-cong-no #totalDebtDisplay,
  #tab-cong-no #totalSurplusDisplay{
    align-self:flex-start;
  }
}
/* Select size is also independent of Chrome's outer window.
   Only coarse-touch input uses >=16px to prevent iOS native focus zoom. */
#tab-cong-no #debtSortSelect{
  flex:0 0 auto;
  width:142px;
  min-width:0;
  max-width:142px;
  height:36px;
  min-height:36px;
  font-size:12px !important;
}
@media (hover:none) and (pointer:coarse){
  #tab-cong-no #debtSortSelect{font-size:16px !important;}
}

/* DEBT-223: pagination footer belongs to the existing ledger scroll owner.
   It is appended after the oldest loaded row; modal header/buttons stay pinned. */
#cDebtModalHistoryList .debt-history-more{
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap:8px;
  padding:14px 8px 18px;
  font-size:11px;
  line-height:1.4;
  color:#64748b;
  text-align:center;
}
#cDebtModalHistoryList .debt-history-more[hidden],
#cDebtModalHistoryList .debt-history-more-button[hidden]{display:none!important}
#cDebtModalHistoryList .debt-history-more-button{
  min-height:40px;
  border:1px solid #bbd4c2;
  border-radius:999px;
  color:#166534;
  background:#f0fdf4;
  font-size:12px;
  font-weight:600;
  padding:9px 18px;
  cursor:pointer;
  touch-action:manipulation;
}
#cDebtModalHistoryList .debt-history-more-button:disabled{opacity:.6;cursor:wait}

/* SPEC-DEBT-WORKSPACE-DENSITY-20261101 — Admin/User debt screen.
   Reduce stacked decoration, not legible text, tappable targets or ledger rows.
   Scoped to the debt workspace (never the general sales/order UI). */
#tab-cong-no > header{
  padding-top:10px;
  padding-bottom:12px;
}
#tab-cong-no > header > .grid{
  margin-top:8px;
  gap:8px;
}
#tab-cong-no > header > .grid > div{
  min-height:56px;
  padding:9px 10px;
}
#tab-cong-no > header > .grid > div > div:first-child{min-width:0}
/* Amount badges must fit beside the two-line labels on narrow panels. */
#tab-cong-no #totalDebtDisplay,
#tab-cong-no #totalSurplusDisplay{
  padding:5px 8px;
  font-size:clamp(12px,3vw,14px);
  line-height:1.25;
}
#tab-cong-no > main{
  /* Keep the original 80px scroll-end clearance for the last customer. */
  padding:12px 14px 80px;
}
#tab-cong-no > main > :not([hidden]) ~ :not([hidden]){
  margin-top:10px;
}
/* Role=user hides the quick receipt form with .hidden, not [hidden].
   Its Tailwind space-y margin must not remain above the first filter card. */
#tab-cong-no > main > [data-permission="canMutateDebt"].hidden + div{
  margin-top:0 !important;
}
#tab-cong-no > main > [data-permission="canMutateDebt"]{
  padding:12px;
}
#tab-cong-no > main > [data-permission="canMutateDebt"] > :not([hidden]) ~ :not([hidden]){
  margin-top:7px;
}
#tab-cong-no #quickDebtCustomerButton,
#tab-cong-no #quickDebtAmount,
#tab-cong-no button[onclick^="submitQuickDebt("]{
  min-height:44px;
}
#tab-cong-no #quickDebtAmount{margin-top:4px}
#tab-cong-no label[for="quickDebtAmount"]{
  margin-top:5px;
  margin-bottom:0;
}
#tab-cong-no .debt-customer-card{
  min-height:72px;
  padding:11px 12px;
}
#tab-cong-no .debt-customer-detail{margin-top:2px}
#tab-cong-no #debtCustomerListContainer > :not([hidden]) ~ :not([hidden]){
  margin-top:8px;
}
/* Keep the modal header/actions pinned and its existing ledger as scroll owner.
   Reduce chrome before ledger rows rather than cutting off transaction text. */
#customerDebtBottomSheet > .cart-handle{
  padding-top:8px;
  padding-bottom:2px;
}
#customerDebtBottomSheet > .cart-handle + div{
  padding:8px 14px;
}
#customerDebtContentToShare > div:first-child{
  padding:9px 16px;
}
#customerDebtBottomSheet #cDebtModalHistoryList{
  padding:9px 14px;
  min-height:0;
}
#customerDebtBottomSheet #cDebtModalHistoryList > div:not(#debtHistoryPageFooter){
  min-height:44px;
  padding-top:8px;
  padding-bottom:8px;
}
#customerDebtBottomSheet > [data-permission="canMutateDebt"]{
  padding:12px 16px;
}
/* Payment controls remain comfortably usable on iPhone, including iOS zoom. */
#customerDebtBottomSheet #popupDebtAmount,
#customerDebtBottomSheet button[onclick^="submitPopupDebt("]{
  min-height:44px;
}

/* SPEC-DEBT-SUMMARY-HIERARCHY-20261101: keep compact filters visually
   subordinate to customer balances; no change to permissions or sorting. */
#tab-cong-no > main > [data-permission="canMutateDebt"].hidden{
  display:none !important;
}
#tab-cong-no > main > div:nth-child(2){
  padding:8px 10px;
  gap:4px;
}
#tab-cong-no #sortContainer{min-height:36px}
#tab-cong-no #debtGroupTitle{line-height:1.3}
#tab-cong-no .debt-customer-detail{
  color:#64748b;
  font-size:11px;
  line-height:1.35;
  margin-top:2px;
}
#customerDebtBottomSheet #cDebtModalHistoryList > div:not(#debtHistoryPageFooter){
  padding-top:7px;
  padding-bottom:7px;
}
#customerDebtBottomSheet #cDebtModalHistoryList > div:not(#debtHistoryPageFooter) > div:first-child{
  min-width:0;
}


/* SPEC-PWA-DEBT-TYPE-20261101:
   Align debtor names, amounts and supporting dates with sales typography.
   Do not shrink money input/selects below iOS's 16px zoom-safe threshold. */
@media (max-width:767px){
  #tab-cong-no .debt-customer-name{
    font-size:14px !important;
    line-height:1.3 !important;
    font-weight:700 !important;
  }
  #tab-cong-no .debt-customer-money{
    font-size:14px !important;
    line-height:1.3 !important;
  }
  #tab-cong-no .debt-customer-detail{
    font-size:11.5px !important;
    line-height:1.4 !important;
  }
}


/* SPEC-DEBT-CARD-THIRD-ROW-20261101
   Given a narrow debt customer card with a long cycle warning, keep the
   amount right-aligned alongside name + last delivery (rows 1 and 2), then
   let the cycle summary occupy the entire text+amount width on row 3.
   Use the existing DOM; no data, role, or amount changes. */
#tab-cong-no .debt-customer-card{
  /* Row 3 is implicit, so readonly user cards without a cycle badge
     do not reserve a blank third row. */
  grid-template-rows:auto auto;
  row-gap:2px;
  min-height:64px;
}
#tab-cong-no .debt-customer-body{
  display:contents;
}
#tab-cong-no .debt-customer-avatar{
  grid-column:1;
  grid-row:1 / 3;
  align-self:center;
}
#tab-cong-no .debt-customer-name{
  grid-column:2;
  grid-row:1;
  align-self:end;
}
#tab-cong-no .debt-customer-detail{
  grid-column:2;
  grid-row:2;
  align-self:start;
}
#tab-cong-no .debt-customer-money{
  grid-column:3;
  grid-row:1 / 3;
  align-self:center;
}
#tab-cong-no .debt-cycle-card-meta{
  grid-column:2 / 4;
  grid-row:3;
  min-width:0;
  margin-top:1px;
}


/* SPEC-DEBT-SORT-MOBILE-TYPE-20261101:
   Visual label remains 13px, matching other compact filters. The fully
   interactive native select overlays the visual text at 16px (iOS zoom-safe).
   No duplicate click/sort owner; one existing onchange still calls renderCongNo.
   Keyboard focus is visibly inset, without a colored bleed on the PWA edge. */
#tab-cong-no .debt-sort-field{
  position:relative;
  box-sizing:border-box;
  width:142px;
  min-width:0;
  height:44px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:4px;
  padding:0 10px 0 12px;
  border:1px solid #e2e8f0;
  border-radius:10px;
  background-color:#f8fafc;
  color:#334155;
}
#tab-cong-no .debt-sort-visible-value{
  display:block;
  flex:1 1 auto;
  min-width:0;
  overflow:hidden;
  white-space:nowrap;
  text-overflow:ellipsis;
  pointer-events:none;
  font-size:13px;
  font-weight:650;
  line-height:1.3;
}
#tab-cong-no .debt-sort-caret{
  pointer-events:none;
  flex:none;
  color:#475569;
  font-size:14px;
}
#tab-cong-no .debt-sort-field #debtSortSelect{
  appearance:none;
  -webkit-appearance:none;
  position:absolute;
  inset:0;
  z-index:1;
  display:block;
  width:100% !important;
  max-width:100% !important;
  height:100% !important;
  min-height:44px !important;
  margin:0;
  padding:0;
  border:0;
  opacity:0;
  cursor:pointer;
  font-size:16px !important;
  touch-action:manipulation;
}
#tab-cong-no .debt-sort-field:focus-within{
  box-shadow:inset 0 0 0 2px #16a34a;
}
/* SPEC-DEBT-SORT-ACTIVE-GROUP-20261101: an inert sort must not
   occupy space in non-debt groups. The semantic-columns CSS declares
   display:inline-flex, so [hidden] needs an explicit stronger rule. */
#tab-cong-no .debt-sort-control[hidden]{
  display:none !important;
}
/* SPEC-DEBT-FILTER-HEADING-DENSITY-20261101:
   Without a sort control the list heading is still shown, but it no
   longer reserves an empty 36px input-height row. iOS PWA supports :has.
   Owing group retains the 44px native select touch target. */
#tab-cong-no .debt-sort-row:has(.debt-sort-control[hidden]){
  min-height:24px;
}
@media(max-width:350px){
  #tab-cong-no .debt-sort-field{
    width:130px;
    padding-left:8px;
    padding-right:8px;
  }
}


/* SPEC-DEBT-DETAIL-SHEET-DENSITY-20261101
   Given the iPhone debt detail sheet, give transaction history more vertical
   room without removing ledger evidence, the cycle disclosure or actions.
   The native money input stays 16px (no iOS zoom), and buttons >=44px.
   PC/forced-PC and printed/shared debt ledger keep their existing layout. */
@media (max-width:767px){
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtBottomSheet{
    height:90% !important;
    max-height:calc(100% - 12px);
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtBottomSheet > .cart-handle{
    padding-top:6px;
    padding-bottom:0;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtBottomSheet > .cart-handle + div{
    padding:7px 14px;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtContentToShare > div:first-child{
    padding:8px 14px;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtContentToShare > div:first-child > div{
    width:100%;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
    min-width:0;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtContentToShare #cDebtModalBalanceLabel{
    font-size:11px;
    line-height:1.3;
    min-width:0;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtContentToShare #cDebtModalTotal{
    margin:0;
    font-size:19px;
    line-height:1.2;
    white-space:nowrap;
    font-variant-numeric:tabular-nums;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #cDebtModalHistoryList{
    padding:7px 12px !important;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #cDebtModalHistoryList > div:not(#debtHistoryPageFooter){
    padding:8px 9px !important;
    gap:8px;
    align-items:center;
    border-radius:12px;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #cDebtModalHistoryList > div + div{
    margin-top:6px !important;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #cDebtModalHistoryList > div:not(#debtHistoryPageFooter) > div:first-child{
    min-width:0;
    flex:1 1 auto;
    overflow-wrap:anywhere;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #cDebtModalHistoryList > div:not(#debtHistoryPageFooter) > div:last-child{
    min-width:66px;
    max-width:42%;
    flex:0 0 auto;
    text-align:right;
    font-variant-numeric:tabular-nums;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #cDebtModalHistoryList > div:not(#debtHistoryPageFooter) > div:first-child > p:first-child{
    font-size:13px;
    line-height:1.3;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #cDebtModalHistoryList > div:not(#debtHistoryPageFooter) > div:first-child > p:not(:first-child),
  body:not(.pc-mode):not([data-force-pc="1"]) #cDebtModalHistoryList > div:not(#debtHistoryPageFooter) > div:last-child > p:not(:first-child){
    font-size:11px;
    line-height:1.3;
    margin-top:2px;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #cDebtModalHistoryList > div:not(#debtHistoryPageFooter) > div:last-child > p:first-child{
    font-size:14px;
    line-height:1.25;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtBottomSheet > [data-permission="canMutateDebt"]{
    padding:9px 14px 10px;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtBottomSheet .debt-popup-amount-wrap{
    position:relative;
    min-width:0;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtBottomSheet .debt-popup-amount-label{
    position:absolute;
    z-index:1;
    top:5px;
    left:12px;
    color:#64748b;
    font-size:11px;
    font-weight:600;
    line-height:1.2;
    pointer-events:none;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtBottomSheet #popupDebtAmount{
    width:100%;
    min-height:48px;
    padding:17px 12px 4px !important;
    font-size:16px !important;
    line-height:1.25;
    box-sizing:border-box;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtBottomSheet .debt-popup-amount-wrap + .flex{
    margin-top:8px !important;
    gap:8px;
  }
  body:not(.pc-mode):not([data-force-pc="1"]) #customerDebtBottomSheet button[onclick^="submitPopupDebt("]{
    min-height:44px;
    padding-top:9px;
    padding-bottom:9px;
    font-size:14px;
  }
}

/* SPEC-DEBT-LEDGER-TWO-LINE-20261104 — One transaction title plus one
   combined book/time line. Both money figures sit vertically centered at
   the right; ledger amounts and scroll/click behavior stay unchanged. */
#customerDebtBottomSheet #cDebtModalHistoryList .debt-ledger-row{
  display:grid;
  grid-template-columns:minmax(0,1fr) auto;
  align-items:center;
  column-gap:10px;
}
#customerDebtBottomSheet #cDebtModalHistoryList .debt-ledger-info{
  min-width:0;
}
#customerDebtBottomSheet #cDebtModalHistoryList .debt-ledger-title{
  min-width:0;
  line-height:1.3;
}
#customerDebtBottomSheet #cDebtModalHistoryList .debt-ledger-title > i{
  flex-shrink:0;
}
#customerDebtBottomSheet #cDebtModalHistoryList .debt-ledger-label{
  min-width:0;
  overflow-wrap:anywhere;
}
#customerDebtBottomSheet #cDebtModalHistoryList .debt-ledger-meta{
  line-height:1.3;
  overflow-wrap:anywhere;
}
#customerDebtBottomSheet #cDebtModalHistoryList .debt-ledger-side{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  justify-content:center;
  align-self:center;
  min-width:66px;
  gap:2px;
  white-space:nowrap;
  font-variant-numeric:tabular-nums;
}
#customerDebtBottomSheet #cDebtModalHistoryList .debt-ledger-side > p{
  margin:0;
  line-height:1.3;
}
