@media (max-width: 1024px) {
  .app-shell {
    display: block;
    padding: 8px;
    min-height: auto;
    gap: 0;
  }

  .app-main.page {
    width: 100%;
    max-width: 100%;
    padding: 10px;
    min-height: calc(100vh - 66px);
    min-height: calc(100dvh - 66px);
    border-radius: 10px;
    overflow: visible;
  }

  .gmail-toolbar,
  .ui-toolbar,
  .main-tracker-search-row.ui-search-row,
  .domain-toolbar,
  .email-toolbar,
  .feeder-toolbar,
  .cj-crawler-toolbar,
  .ipqr-toolbar,
  .migration-config-toolbar,
  .invoices-toolbar,
  .pf-toolbar,
  .product-viewer-toolbar {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  .table-wrap,
  .ui-table-wrap {
    max-width: 100%;
    overflow-x: auto !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .data-table,
  .ui-table {
    min-width: max-content;
  }
}

@media (max-width: 820px) {
  html,
  body {
    overflow-x: hidden;
  }

  .topbar-inner {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "drawer appname"
      "user user";
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
  }

  .topbar-left {
    display: contents;
  }

  .brand { display: none; }

  .topbar-menu-btn {
    grid-area: drawer;
    justify-self: start;
  }

  .topbar-title {
    grid-area: appname;
    position: static;
    transform: none;
    pointer-events: auto;
    max-width: 100%;
    width: 100%;
    text-align: center;
    justify-self: stretch;
    font-size: 1rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-title-link {
    color: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
  }

  .topbar-title.has-app .topbar-title-brand,
  .topbar-title.has-app .topbar-title-sep {
    display: none;
  }

  .topbar-user-area {
    grid-area: user;
    display: grid;
    grid-template-columns: minmax(120px, max-content) minmax(90px, max-content) minmax(88px, max-content);
    justify-content: center;
    align-items: center;
    justify-items: stretch;
    width: 100%;
    margin-left: 0;
    gap: 8px;
  }

  .topbar-user-area .active-users-box,
  .topbar-user-area .table-status,
  .topbar-user-area form {
    margin: 0;
    width: 100%;
  }

  .topbar-user-area .active-users-box {
    justify-content: center;
  }

  .topbar-user-area .table-status {
    margin-top: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 34px;
    line-height: 1;
    padding: 0 8px;
    border: 1px solid rgba(29, 42, 52, 0.12);
    border-radius: 999px;
    background: rgba(240, 245, 252, 0.95);
  }

  .topbar-user-area form .toolbar-btn {
    width: 100%;
  }

  body.gmails-body,
  body.cjcrawler-body,
  body.product-viewer-body,
  body.wallet-body {
    overflow: auto !important;
  }

  body.gmails-body .page,
  body.cjcrawler-body .page,
  body.product-viewer-body .page,
  body.wallet-body .page {
    height: auto !important;
    min-height: calc(100vh - 62px);
    overflow: visible !important;
    padding: 8px !important;
  }

  .flash-stack,
  .ui-flash-stack {
    left: 8px;
    right: 8px;
    top: 58px;
    width: auto;
  }

  .modal-dialog,
  .ui-modal-dialog {
    width: calc(100vw - 16px) !important;
    max-width: calc(100vw - 16px) !important;
    max-height: calc(100dvh - 16px);
    margin: 8px auto !important;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .modal-dialog > form,
  .ui-modal-dialog > form,
  .modal-dialog > .new-entry-form,
  .ui-modal-dialog > .new-entry-form,
  .modal-dialog > .files-ledger-reference-layout,
  .ui-modal-dialog > .files-ledger-reference-layout {
    overflow: auto;
    min-height: 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .modal-actions,
  .ui-modal-actions {
    position: sticky;
    bottom: 0;
    background: rgba(245, 250, 255, 0.98);
    z-index: 3;
  }

  .new-entry-form,
  .device-modal-form,
  .domain-entry-form,
  .email-entry-form,
  .feeder-entry-form,
  .ipqr-entry-form,
  .accounting-entry-form,
  .migration-add-store-form,
  .files-upload-form {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 768px) {
  .topbar {
    position: sticky;
    top: 0;
    z-index: 90;
  }

  body.drawer-open .app-drawer {
    top: 58px;
    height: calc(100vh - 58px);
    height: calc(100dvh - 58px);
  }

  .table-wrap,
  .ui-table-wrap {
    max-height: calc(100dvh - 260px);
  }

  .data-table th,
  .data-table td,
  .ui-table th,
  .ui-table td {
    font-size: 1rem;
    padding: 6px 8px !important;
  }

  .table-status {
    font-size: 1rem;
  }

  .auth-login-panel .modal-actions,
  .auth-login-panel .ui-modal-actions {
    justify-content: stretch;
  }

  .auth-login-panel .modal-actions .toolbar-btn,
  .auth-login-panel .ui-modal-actions .ui-btn,
  .auth-login-panel .ui-modal-actions .toolbar-btn {
    width: 100%;
    min-width: 100%;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 6px;
  }

  .app-main.page {
    padding: 8px;
  }

  .topbar-inner {
    padding: 7px 8px;
  }

  .toolbar-btn,
  .ui-btn,
  .row-action-btn,
  .icon-btn {
    min-height: 36px;
  }

  .table-status {
    gap: 6px;
  }

  .topbar-user-area {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .topbar-user-area .active-users-box,
  .topbar-user-area .table-status,
  .topbar-user-area form {
    max-width: 280px;
  }
}
