/* Reuse the canonical module menu on phones, including its role/plan controls. */
/* The workspace has no outer padding for the legacy header margins to cancel. */
body[data-td-ui="pro-max"] main > .topbar { margin-left: 0 !important; margin-right: 0 !important; }
body[data-td-ui="pro-max"] .tdMobileBottomNav [hidden],
body[data-td-ui="pro-max"] .tdMobileQuickFab[hidden] { display: none !important; }
body[data-td-ui="pro-max"] .sidebar nav .navGroupLabel[hidden] { display: none !important; }
@media (max-width: 820px) {
  html body[data-td-ui="pro-max"] { padding-bottom: calc(92px + env(safe-area-inset-bottom)) !important; }
  html body[data-td-ui="pro-max"] .topbar {
    margin: 0 0 12px !important; width: 100% !important; min-width: 0 !important;
    position: relative !important; top: auto !important; box-sizing: border-box;
  }
  html body[data-td-ui="pro-max"]:has(:is(#sales.active:not(.invoiceMode),#purchases.active:not(.purchaseMode),#items.active,#parties.active,#reports.active)) .topbar {
    display: block !important; height: auto !important; padding: 16px !important;
  }
  html body[data-td-ui="pro-max"]:has(:is(#sales.active:not(.invoiceMode),#purchases.active:not(.purchaseMode),#items.active,#parties.active,#reports.active)) .topbar > .actions {
    display: block !important; width: 100% !important; max-width: none !important;
    margin: 0 !important; overflow: visible !important; padding: 0 !important;
  }
  html body[data-td-ui="pro-max"]:has(#sales.active:not(.invoiceMode)) #salesRegisterTopContext,
  html body[data-td-ui="pro-max"]:has(#purchases.active:not(.purchaseMode)) #purchaseRegisterTopContext,
  html body[data-td-ui="pro-max"]:has(#items.active) #itemMasterTopContext,
  html body[data-td-ui="pro-max"]:has(#parties.active) #partyMasterTopContext,
  html body[data-td-ui="pro-max"]:has(#reports.active) #businessReportsTopContext {
    display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr)) !important;
    width: 100% !important; min-width: 0 !important; height: auto !important;
    gap: 8px !important; overflow: visible !important;
  }
  html body[data-td-ui="pro-max"] :is(#salesRegisterTopContext,#purchaseRegisterTopContext,#itemMasterTopContext,#partyMasterTopContext,#businessReportsTopContext) > * {
    min-width: 0 !important; max-width: 100% !important; width: auto !important; flex: initial !important;
  }
  html body[data-td-ui="pro-max"] :is(.salesRegisterTopTitle,.purchaseRegisterTopTitle,.itemMasterTopTitle,.partyMasterTopTitle,.businessReportsTopTitle,.businessReportsDates,.businessReportsTopActions) { grid-column: 1/-1 !important; }
  html body[data-td-ui="pro-max"] :is(#salesRegisterTopContext,#purchaseRegisterTopContext,#itemMasterTopContext,#partyMasterTopContext,#businessReportsTopContext) :is(article span,label > span) { font-size: 11px !important; line-height: 1.4 !important; }
  html body[data-td-ui="pro-max"] :is(#salesRegisterTopContext,#purchaseRegisterTopContext,#itemMasterTopContext,#partyMasterTopContext,#businessReportsTopContext) :is(button,a,input,select) {
    min-height: 44px !important; font-size: 13px !important; white-space: normal !important;
  }
  html body[data-td-ui="pro-max"] :is(#salesRegisterTopContext,#purchaseRegisterTopContext,#partyMasterTopContext) > button { grid-column: 1/-1 !important; }
  html body[data-td-ui="pro-max"] .topbar :is(#salesRegisterTopContext,#purchaseRegisterTopContext,#itemMasterTopContext,#partyMasterTopContext,#businessReportsTopContext) button:not([hidden]) { display: inline-flex !important; align-items: center; justify-content: center; }
  html body[data-td-ui="pro-max"] :is(#sales,#purchases,#items,#parties,#reports,#accounting,#users) table.tdMobileCardTable {
    min-width: 0 !important; width: 100% !important; max-width: 100% !important; font-family: inherit;
  }
  html body[data-td-ui="pro-max"] table.tdMobileCardTable :is(tbody,tr) { min-width: 0 !important; width: 100% !important; box-sizing: border-box; }
  /* Keep bill details together on phones without hiding columns or actions. */
  html body[data-td-ui="pro-max"] :is(.salesRegisterTable,.purchaseRegisterTable) table.tdMobileCardTable tr:has(.rowActions) {
    display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr)) !important;
    column-gap: 14px !important; align-items: stretch !important;
  }
  html body[data-td-ui="pro-max"] :is(.salesRegisterTable,.purchaseRegisterTable) table.tdMobileCardTable tr:has(.rowActions) td {
    display: flex !important; flex-direction: column; align-items: flex-start !important;
    justify-content: center; gap: 4px !important; width: auto !important;
    min-width: 0 !important; padding: 10px 0 !important; font-size: 13px !important;
    line-height: 1.4 !important; position: static !important; box-sizing: border-box;
  }
  html body[data-td-ui="pro-max"] .salesRegisterTable table.tdMobileCardTable tr:has(.rowActions) td:nth-child(4),
  html body[data-td-ui="pro-max"] .purchaseRegisterTable table.tdMobileCardTable tr:has(.rowActions) td:nth-child(5),
  html body[data-td-ui="pro-max"] :is(.salesRegisterTable,.purchaseRegisterTable) table.tdMobileCardTable tr:has(.rowActions) td:last-child {
    grid-column: 1/-1 !important;
  }
  html body[data-td-ui="pro-max"] :is(.salesRegisterTable,.purchaseRegisterTable) .rowActions {
    display: flex; flex-wrap: wrap; gap: 8px; width: 100%;
  }
  html body[data-td-ui="pro-max"] :is(.salesRegisterTable,.purchaseRegisterTable) .rowActions :is(a,button) {
    min-height: 44px !important; padding: 10px 12px !important;
  }
  html body[data-td-ui="pro-max"] #reports.active :is(.reportSnapshotCard,.reportLedgerCard) table.tdMobileCardTable { min-width: 0 !important; width: 100% !important; max-width: 100% !important; }
  html body[data-td-ui="pro-max"] :is(.itemTableWrap,.partyTable) table.tdMobileCardTable tbody tr:has(td:nth-child(2)) {
    display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr)) !important; column-gap: 14px !important;
  }
  html body[data-td-ui="pro-max"] :is(.itemTableWrap,.partyTable) table.tdMobileCardTable tbody td {
    display: flex !important; flex-direction: column; align-items: flex-start !important;
    gap: 5px !important; min-width: 0 !important; width: auto !important;
    padding: 10px 0 !important; position: static !important; font-size: 13px !important;
    overflow-wrap: anywhere;
  }
  html body[data-td-ui="pro-max"] .itemTableWrap table.tdMobileCardTable td:nth-child(3),
  html body[data-td-ui="pro-max"] .itemTableWrap table.tdMobileCardTable td:nth-child(4),
  html body[data-td-ui="pro-max"] .partyTable table.tdMobileCardTable td:first-child,
  html body[data-td-ui="pro-max"] .partyTable table.tdMobileCardTable td:nth-child(3),
  html body[data-td-ui="pro-max"] :is(.itemTableWrap,.partyTable) table.tdMobileCardTable td:last-child { grid-column: 1/-1 !important; }
  html body[data-td-ui="pro-max"] .itemTableWrap table.tdMobileCardTable td:last-child { flex-direction: row; flex-wrap: wrap; align-items: center !important; }
  html body[data-td-ui="pro-max"] .itemTableWrap table.tdMobileCardTable td:last-child::before { width: 100%; }
  html body[data-td-ui="pro-max"] #items input[type="checkbox"] { width: 22px !important; height: 22px !important; min-height: 22px !important; flex: 0 0 22px; }
  html body[data-td-ui="pro-max"] :is(.itemTableWrap,.partyTable) :is(button,.linkBtn) { min-height: 44px; }
  html body[data-td-ui="pro-max"] #dashboard .dashGridTwo > .panel { min-width: 0 !important; }
  html body[data-td-ui="pro-max"] #dashboard .barRow { grid-template-columns: 55px minmax(0,1fr) 82px !important; gap: 8px !important; }
  html body[data-td-ui="pro-max"] #dashboard .healthItem { flex-wrap: wrap; }
  html body[data-td-ui="pro-max"] #accounting .tableWrap { overflow-x: auto !important; }
  html body[data-td-ui="pro-max"] .sidebar.tdMobileMenuOpen { display: block !important; }
  html body[data-td-ui="pro-max"]:has(:is(#sales.active.invoiceMode,#purchases.active.purchaseMode)) .sidebar.tdMobileMenuOpen { display: block !important; }
  body[data-td-ui="pro-max"] .tdMobileBottomNav {
    position: fixed; inset: auto 8px max(8px, env(safe-area-inset-bottom)); z-index: 100;
    display: flex; gap: 5px; padding: 8px; border: 1px solid #dbe4ef;
    border-radius: 20px; background: #fff; box-shadow: 0 8px 28px #12372b24;
  }
  body[data-td-ui="pro-max"] .tdMobileBottomNav button {
    flex: 1 1 0; min-width: 0; min-height: 48px; padding: 6px 3px;
    display: grid; gap: 3px; place-items: center; border: 0; border-radius: 12px;
    background: #f1f5f9; color: #264b43; font-size: 11px; font-weight: 700;
  }
  body[data-td-ui="pro-max"] .tdMobileBottomNav button span { font-size: 18px; line-height: 1; }
  body[data-td-ui="pro-max"] .tdMobileBottomNav button.active,
  body[data-td-ui="pro-max"] #tdMobileMenu[aria-expanded="true"] { background: #0f766e; color: #fff; }
  body[data-td-ui="pro-max"] .sidebar { display: none !important; }
  body[data-td-ui="pro-max"] .sidebar.tdMobileMenuOpen {
    display: block !important; position: fixed !important;
    inset: auto 8px calc(82px + env(safe-area-inset-bottom)) !important;
    width: auto !important; height: auto !important; max-height: calc(100dvh - 170px) !important;
    overflow: auto !important; padding: 14px !important; border: 1px solid #cddfd9 !important;
    border-radius: 18px !important; background: #fff !important; z-index: 99 !important;
    box-shadow: 0 -8px 40px #12372b38 !important; overscroll-behavior: contain;
  }
  body[data-td-ui="pro-max"] .sidebar.tdMobileMenuOpen nav {
    display: grid !important; grid-template-columns: repeat(2,minmax(0,1fr)) !important;
    width: 100% !important; min-width: 0 !important; height: auto !important; gap: 7px !important;
  }
  body[data-td-ui="pro-max"] .sidebar.tdMobileMenuOpen .navGroupLabel {
    display: block !important; grid-column: 1/-1; color: #526c63 !important;
    font-size: 10px !important; padding: 12px 3px 3px !important;
  }
  body[data-td-ui="pro-max"] .sidebar.tdMobileMenuOpen nav button,
  body[data-td-ui="pro-max"] .sidebar.tdMobileMenuOpen nav .navLink {
    min-width: 0 !important; width: 100% !important; min-height: 44px !important;
    height: auto !important; font-size: 12px !important; padding: 10px !important;
    white-space: normal !important; text-align: left !important; justify-content: flex-start !important;
  }
  body[data-td-ui="pro-max"].loggedOut .sidebar,
  body[data-td-ui="pro-max"].loggedOut .tdMobileBottomNav { display: none !important; }
}
