/* Keep desktop layouts unchanged; phones scroll wide tables within their panels. */
.mobile-sidebar-backdrop,
.mobile-sidebar-close {
  display: none;
}

@media (max-width: 920px) {
  body.mobile-nav-open { overflow: hidden; }

  .sidebar {
    width: min(300px, calc(100vw - 48px));
    min-width: 0;
    height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .mobile-sidebar-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 19;
    background: rgba(17, 25, 43, .48);
    border-radius: 0;
  }

  .mobile-sidebar-close {
    display: grid;
    place-items: center;
    flex: 0 0 44px;
    height: 44px;
    background: transparent;
    color: #fff;
    font-size: 20px;
  }

  .sidebar .brand { padding: 0 12px; }
  .nav-item { min-height: 48px; }
  .main, .content, .page-view { min-width: 0; }
}

@media (max-width: 920px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  }

  .topbar-left { min-width: 0; gap: 10px; }
  .topbar-left > div { min-width: 0; }
  .topbar h1 { font-size: 18px; overflow-wrap: anywhere; }
  .topbar p { display: none; }
  .topbar-actions { min-width: 0; width: 100%; gap: 8px; justify-content: space-between; }
  .topbar .profile { gap: 6px; }
  .topbar .icon-btn, .profile-logout, .customer-context-button { width: 44px; height: 44px; flex-shrink: 0; }
  .language-switcher { height: 44px; }
  .language-switcher button { height: 36px; min-width: 40px; }
  .content { padding: 14px 12px calc(24px + env(safe-area-inset-bottom)); }
  .content h2 { font-size: 20px; }
  .content h3 { font-size: 15px; }
  .content h2, .content h3, .customer-picker-brand, .login-brand { overflow-wrap: anywhere; }
  .page-view > *, .panel, .table-header > *, .inbound-toolbar > *, .section-title-row > * { min-width: 0; }

  .inventory-summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .inventory-stat-card, .inventory-ratio-card { padding: 12px; gap: 8px; min-height: 84px; border-radius: 8px; }
  .inventory-stat-card .stat-icon { width: 28px; height: 28px; flex: 0 0 28px; }
  .stat-info { min-width: 0; }
  .stat-info strong { font-size: 22px; overflow-wrap: anywhere; letter-spacing: 0; }
  .stat-info small { display: none; }
  .inventory-ratio-card { flex-wrap: wrap; }
  .usage-donut { width: 52px; height: 52px; flex: 0 0 52px; }
  .usage-donut-inner { width: 36px; height: 36px; }
  .usage-donut-inner strong { font-size: 12px; }
  .ratio-info > strong { font-size: 16px; margin: 4px 0; }
  .ratio-legend { gap: 4px 8px; }

  .toolbar-actions, .table-actions, .recent-toolbar-actions,
  .receipt-footer-actions, .inventory-actions, .modal-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
  }
  .toolbar-actions > *, .table-actions > *, .receipt-footer-actions > * { max-width: 100%; }
  .inventory-search-box, .admin-user-search, .table-search { width: 100%; min-width: 0; }
  .form-panel { padding: 14px; }

  :is(.content, .modal-backdrop, .login-view, .customer-picker-view) :is(input, select, textarea) {
    /* Override compact table editors too, avoiding automatic phone input zoom. */
    font-size: 16px !important;
    min-height: 44px;
    max-width: 100%;
  }
  :is(.content, .modal-backdrop, .login-view, .customer-picker-view) :is(input[type="checkbox"], input[type="radio"]) {
    min-height: 20px;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
  }
  :where(.content, .modal-backdrop, .login-view, .customer-picker-view) :is(button, .primary-btn, .secondary-btn) {
    min-height: 44px;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .account-edit-button, .row-delete-btn, .table-filter-btn { min-width: 44px; }
  .account-edit-button { width: 44px; height: 44px; }
  .account-actions { min-width: 96px; }
  .table-filter-btn { position: static; margin-left: 4px; vertical-align: middle; }
  .content table th { white-space: nowrap; }
  .table-th-shell { min-width: 92px; }
  .table-th-label { overflow-wrap: normal; }
  .column-resizer { display: none; }
  .table-filter-menu { max-width: calc(100vw - 16px); max-height: calc(100dvh - 24px); }
  .table-filter-menu input:not([type="checkbox"]) { font-size: 16px; min-height: 44px; }
  .table-filter-menu button, .table-filter-menu .filter-value-row { min-height: 44px; }
  .table-filter-menu input[type="checkbox"] { width: 20px; height: 20px; }
  .inventory-table { --inventory-freeze-col-1: 170px; margin-right: 0; }
  .inventory-table th:nth-child(n+3):nth-child(-n+4),
  .inventory-table td:nth-child(n+3):nth-child(-n+4) { position: static; box-shadow: none; }
  .inventory-table th:nth-child(2), .inventory-table td:nth-child(2) { max-width: 170px; overflow-wrap: anywhere; }
  .inventory-table td:nth-child(2) .cell-main { white-space: normal; }

  .table-scroll, .edit-history-scroll, .production-history-table-wrap {
    max-width: 100%;
    overflow: auto;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }
  .table-scroll::-webkit-scrollbar { height: 8px; }
  .floating-table-scrollbar { display: none; }
  .inventory-table-panel .table-scroll { max-height: 65dvh; min-height: 200px; }
  .edit-history-scroll { max-height: 65dvh; min-height: 200px; }

  .login-view { min-height: 100dvh; align-content: center; gap: 20px; padding: 24px 14px; }
  .login-brand { gap: 12px; }
  .login-brand img { width: 56px; height: 56px; flex-shrink: 0; }
  .login-brand strong { font-size: 22px; }
  .login-panel { padding: 22px 18px; }
  .login-panel .language-switcher { position: static; margin-bottom: 16px; }
  .login-panel h1 { font-size: 24px; }
  .login-field input { min-width: 0; }

  .customer-picker-header { flex-wrap: wrap; gap: 12px; }
  .customer-picker-header-actions { flex-wrap: wrap; }
  .customer-picker-brand { min-width: 0; }
  .customer-picker-brand span { max-width: 100%; }

  .modal-backdrop { padding: 8px; }
  .modal-backdrop .norm-modal { width: 100%; max-width: 100%; max-height: calc(100dvh - 16px); }
  .norm-edit-head { padding: 14px; gap: 10px; flex-direction: row; align-items: flex-start; }
  .norm-edit-head > div { min-width: 0; flex: 1; overflow-wrap: anywhere; }
  .norm-edit-head .icon-btn { flex: 0 0 44px; }
  .user-account-form { padding: 14px 14px 4px; }
  .modal-actions { position: sticky; bottom: 0; background: #fff; padding: 12px 14px; border-top: 1px solid var(--line); z-index: 2; }
  .modal-actions > button { flex: 1; min-width: 100px; }
  .toast { max-width: calc(100vw - 24px); width: max-content; white-space: normal; overflow-wrap: anywhere; bottom: calc(16px + env(safe-area-inset-bottom)); }
}

@media (max-width: 359px) {
  .inventory-summary-grid { grid-template-columns: minmax(0, 1fr); }
  .topbar .avatar { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
