/* Screen layout only: paper dimensions and print CSS remain independent. */
@media screen {
  .main,.view,.view-head>div,.sale-toolbar>*,.notes-block,.filterbar>* { min-width:0; }
  .grid-wrap { max-width:100%; overscroll-behavior-x:contain; -webkit-overflow-scrolling:touch; }
  .data-table td:last-child { white-space:nowrap; }
  .table-status { display:flex; flex-wrap:wrap; align-items:center; gap:8px; }
  .table-status>span { margin-right:auto; }
  .table-status>button { padding:7px 12px; }
  .suggestion,.product-option { cursor:pointer; touch-action:pan-y; }
  .suggestion>div,.product-option>div { min-width:0; overflow-wrap:anywhere; }
  .suggestion:focus-visible,.product-option:focus-visible { outline:2px solid var(--teal-dark); outline-offset:-3px; }
  .suggestions,.product-popover { overscroll-behavior:contain; }
  .product-popover { z-index:45; }
  .order-grid input[type=number] { touch-action:manipulation; }
  button:disabled { opacity:.55; cursor:wait; }
  .sidebar-backdrop { position:fixed; inset:114px 0 0; z-index:14; border:0; background:rgba(4,15,24,.5); }
  .password-required .sidebar,.password-required .workspace-tabs,.password-required .topnav,
  .password-required .global-search,.password-required .mobile-menu,.password-required #sync-status { display:none!important; }
  .password-required .main { margin-left:0; padding-top:96px; }
  .password-required .account-layout { margin:auto; max-width:890px; }
  .dialog-head { gap:12px; }
  .dialog-head h3 { overflow-wrap:anywhere; }
  .dialog-head .ghost,.dialog-head .primary { font-size:15px; }
  .dialog-head .primary { background:var(--teal); color:#fff; }
  .mobile-table-hint { display:none; }
  .detail-dialog { max-height:calc(100dvh - 24px); overflow:auto; overscroll-behavior:contain; }
  #detail-content { max-width:100%; overflow:auto; }
  .edit-form label { min-width:0; }
  .edit-form input,.edit-form textarea,.edit-form select { width:100%; min-width:0; }
  .edit-form .check-label input { width:auto; }
  .operation-busy { padding:20px; }
  .operation-busy-card { max-width:100%; }
}
@media screen and (max-width:1250px) {
  .topnav { display:none; }
  .global-search { flex:1; min-width:100px; }
}
@media screen and (max-width:980px) {
  .workspace-tabs { left:0; padding-inline:12px; }
  .sidebar { width:min(280px,85vw); }
  .bill-meta { flex-wrap:wrap; }
  .supplier-picker input,.customer-picker input { min-width:0; width:100%; }
  .account-layout { grid-template-columns:1fr; }
  .filterbar { flex-wrap:wrap; }
  .filterbar input:first-child { min-width:0; }
}
@media screen and (max-width:640px) {
  html { -webkit-text-size-adjust:100%; scroll-padding-top:126px; }
  body { overflow-wrap:break-word; }
  input,textarea,select { font-size:16px; min-height:42px; }
  select { max-width:100%; }
  input[type=checkbox] { min-height:20px; width:20px; height:20px; flex:none; }
  button { touch-action:manipulation; }
  .topbar { height:64px; gap:7px; padding:0 9px; }
  .mobile-menu { width:38px; padding:4px; flex:none; }
  .identity { flex:0 0 auto; min-width:0; }
  .identity-logo { width:35px; height:35px; border-radius:9px; }
  .topbar .account-button { margin-left:auto; max-width:86px; padding:8px 3px; font-size:13px; }
  .topbar .theme-toggle { padding:8px 6px; font-size:12px; }
  #logout { padding:8px 3px; font-size:13px; }
  .sync-status { width:8px; min-width:8px; flex:none; }
  .sync-status span { display:none; }
  .workspace-tabs { top:64px; height:46px; gap:5px; padding:5px 8px 0; }
  .workspace-tab { flex:none; height:41px; min-width:115px; max-width:225px; font-size:13px; gap:6px; }
  .workspace-tab span { overflow:hidden; text-overflow:ellipsis; }
  .workspace-tab button { min-height:36px; min-width:30px; font-size:20px; }
  .sidebar { top:110px; padding:10px; }
  .sidebar-backdrop { top:110px; }
  .main { padding:126px 10px 22px; width:100%; }
  .view-head { gap:12px; flex-wrap:wrap; margin-bottom:12px; }
  .view-head h2 { font-size:23px; }
  .view-head>.primary { padding:9px 12px; font-size:14px; }
  .bill-meta { display:flex; width:100%; justify-content:space-between; font-size:12px; gap:5px; }
  .bill-meta label { margin:0; }
  .bill-meta input { max-width:156px; padding:8px; }
  .sale-toolbar,.filterbar { padding:11px; gap:10px; }
  .customer-picker,.supplier-picker { display:grid; grid-template-columns:1fr; width:100%; gap:6px; }
  .customer-picker input,.supplier-picker input { max-width:none; }
  .sales-customer-filter { flex:auto; min-width:0; width:100%; }
  .suggestions,.sales-customer-filter .suggestions { left:0; top:100%; width:100%; }
  .suggestion { padding:12px; gap:6px; flex-wrap:wrap; min-height:46px; }
  .product-option { min-height:60px; padding:10px; font-size:14px; grid-template-columns:minmax(0,1fr) auto; }
  .product-option strong { overflow-wrap:anywhere; }
  .product-option small { font-size:12px; }
  .product-option>div:last-child { max-width:98px; }
  .frequency-badge { margin:3px 0 0; }
  .segmented { width:100%; }
  .segmented button { flex:1; padding:9px 6px; }
  .frequency-legend { line-height:1.9; }
  .customer-chip { font-size:14px; line-height:1.65; overflow-wrap:anywhere; }
  .order-grid input { font-size:16px; min-height:44px; }
  .order-grid td { padding:4px; }
  .order-grid th { font-size:13px; }
  .order-grid .remove-row { width:34px; min-height:44px; }
  .order-grid td:first-child,.order-grid th:first-child { position:sticky; left:0; z-index:1; background:var(--paper); }
  .grid-wrap { border-radius:7px; }
  .mobile-table-hint { display:block; color:var(--muted); font-size:12px; margin:12px 2px -7px; }
  .sale-footer { gap:10px; }
  .notes-block,.total-card { padding:12px; }
  .notes-block>label { grid-template-columns:1fr; }
  .inline-fields label { display:grid; grid-template-columns:85px minmax(0,1fr); }
  .actionbar { flex-wrap:wrap; gap:7px; bottom:0; padding-bottom:max(9px,env(safe-area-inset-bottom)); z-index:4; }
  .actionbar>button { flex:1 1 calc(50% - 7px); min-height:44px; padding:9px; font-size:14px; }
  .filterbar label { width:100%; justify-content:space-between; }
  .filterbar input,.filterbar select { max-width:100%; }
  .filterbar label input,.filterbar label select { min-width:0; flex:1; }
  .filterbar label input[type=date] { max-width:250px; }
  .date-presets { display:flex; flex-wrap:wrap; justify-content:space-between; gap:3px; }
  .date-presets button { min-height:40px; flex:1; padding:7px 6px; font-size:13px; }
  .summary-row,.report-cards { grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
  .summary-card,.report-card { padding:12px; }
  .summary-card strong,.report-card strong { font-size:19px; overflow-wrap:anywhere; }
  .report-controls { padding:10px; gap:10px; }
  .report-range { flex:1 1 100%; }
  .report-panel .data-table { min-width:480px; }
  .report-panel:last-child .data-table { min-width:580px; }
  .report-bar-row { grid-template-columns:35px minmax(0,1fr) 104px; gap:5px; }
  .product-filterbar select { min-width:0; width:100%; }
  .category-visual { max-width:100%; padding-bottom:7px; }
  .category-card { min-width:110px; max-width:210px; text-align:left; white-space:normal; }
  .template-editor-layout { min-width:0; }
  .template-actions { display:flex; flex-direction:row; flex-wrap:wrap; width:100%; gap:7px; }
  .template-actions button { flex:1; padding:10px 7px; font-size:14px; }
  .template-group { padding:12px; min-width:0; }
  .template-preview-head { flex-wrap:wrap; gap:5px; }
  .template-preview { max-height:60dvh; padding:10px; }
  .account-profile,.settings-card { padding:16px; }
  .account-profile>div { min-width:0; overflow-wrap:anywhere; }
  .account-layout,.admin-layout { grid-template-columns:minmax(0,1fr); }
  .settings-card .check-label { align-items:flex-start; line-height:1.6; }
  .login-layer { padding:16px; }
  .login-card { padding:20px; }
  .login-brand img { width:110px; height:110px; }
  .login-brand h1 { font-size:30px; margin-bottom:8px; }
  .login-brand span { border-radius:12px; line-height:1.6; }
  .detail-dialog,.print-dialog { max-width:calc(100vw - 16px); width:calc(100vw - 16px); padding:14px; max-height:calc(100dvh - 16px); }
  .detail-dialog .dialog-head { position:sticky; top:-14px; background:var(--paper); z-index:3; padding-top:10px; }
  .dialog-head h3 { font-size:19px; }
  .dialog-head button { min-width:38px; min-height:42px; }
  .dialog-head .primary { font-size:15px; padding:7px 12px; }
  .print-dialog .dialog-head { flex-wrap:wrap; }
  .print-sheet { min-width:0!important; max-width:100%; padding:8px; }
  .drawer { width:100%; padding:16px; }
  .history-item { font-size:14px; }
  .history-item>div { min-width:0; overflow-wrap:anywhere; }
  .category-manager { grid-template-columns:minmax(0,1fr); }
  .category-list { max-height:34dvh; }
  .category-list-item>div { min-width:0; overflow-wrap:anywhere; }
  .category-list-item button { flex:none; }
  .toast { left:12px; right:12px; bottom:max(14px,env(safe-area-inset-bottom)); font-size:14px; z-index:220; }
  .password-required .main { padding-top:80px; }
}
@media screen and (prefers-reduced-motion:reduce) {
  *,*::before,*::after { scroll-behavior:auto!important; transition:none!important; }
}
@media print { .sidebar-backdrop { display:none!important; } }
