@media (max-width: 1100px) {
  .grid-sidebar,
  .grid-2,
  .grid-3,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .brand {
    min-width: 160px;
  }
}

@media (max-width: 820px) {
  html,
  body,
  .app-shell {
    max-width: 100%;
    overflow-x: hidden;
  }

  body {
    padding-bottom: calc(64px + var(--safe-bottom));
  }

  .topbar,
  .nav {
    display: none;
  }

  .mobile-topbar {
    min-height: var(--oz-height-mobile-header);
    height: auto;
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    align-items: center;
    gap: var(--oz-spacing-sm);
    position: sticky;
    top: 0;
    z-index: var(--oz-z-mobile);
    background: var(--oz-color-surface);
    border-bottom: 1px solid var(--oz-color-border);
    box-shadow: var(--oz-shadow-header);
    padding: var(--oz-spacing-sm) var(--oz-spacing-md);
  }

  .mobile-title {
    min-width: 0;
    flex: 1;
  }

  .mobile-topbar .logo,
  .mobile-topbar > .btn {
    flex: 0 0 auto;
  }

  .mobile-topbar-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--oz-spacing-xs);
    justify-content: stretch;
  }

  .mobile-topbar-actions .btn,
  .mobile-topbar-actions .oz-btn {
    min-width: 0;
    width: 100%;
    padding-left: 8px;
    padding-right: 8px;
  }

  .mobile-title strong,
  .mobile-title span {
    display: block;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .mobile-title span {
    color: var(--oz-color-text-weak);
    font-size: var(--oz-font-size-caption);
  }

  .mobile-bottom {
    display: grid;
    grid-template-columns: repeat(5, minmax(48px, 1fr));
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(58px + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--oz-color-surface);
    border-top: 1px solid var(--oz-color-border);
    z-index: var(--oz-z-mobile);
  }

  .mobile-bottom button {
    border: 0;
    background: transparent;
    color: var(--oz-color-text-weak);
    display: grid;
    place-items: center;
    align-content: center;
    gap: 1px;
    font-size: var(--oz-font-size-caption);
    font-weight: 700;
    min-width: 0;
    overflow: hidden;
  }

  .mobile-bottom button span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-bottom button.active {
    color: var(--oz-color-brand);
  }

  .mobile-bottom .ico {
    font-size: 19px;
  }

  .mobile-drawer-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(var(--oz-color-scrim-rgb), 0.42);
    z-index: var(--oz-z-popover);
    overflow: hidden;
  }

  .mobile-drawer {
    width: min(88vw, 340px);
    max-width: 100vw;
    height: 100%;
    background: var(--oz-color-surface);
    overflow: auto;
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.28);
    padding-bottom: calc(72px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
  }

  .mobile-drawer-head {
    background: linear-gradient(135deg, var(--oz-color-brand), var(--oz-color-brand-active));
    color: #fff;
    padding: var(--oz-spacing-lg);
  }

  .mobile-drawer button {
    width: 100%;
    text-align: left;
    border: 0;
    border-left: 3px solid transparent;
    background: transparent;
    color: var(--oz-color-text-body);
    padding: var(--oz-spacing-md) var(--oz-spacing-lg);
    font-size: var(--oz-font-size-small);
    font-weight: 700;
    min-height: 44px;
  }

  .mobile-drawer button.active {
    background: rgba(var(--oz-color-brand-rgb), 0.08);
    border-left-color: var(--oz-color-brand);
  }

  .drawer-section {
    color: var(--oz-color-text-weak);
    font-size: var(--oz-font-size-caption);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: var(--oz-spacing-md) var(--oz-spacing-lg) 5px;
  }

  .container {
    padding: var(--oz-spacing-md);
    overflow-x: hidden;
  }

  .card,
  .oz-card,
  .card-header,
  .card-body,
  .oz-card-body,
  .oz-page-header,
  .hero,
  .empty-state,
  .global-result-card,
  .app-tile,
  .app-tile-main,
  .quick-create-card,
  .mobile-record-card,
  .oz-record-workspace,
  .oz-record-tabpanel,
  .oz-related-list,
  .oz-object-content,
  .oz-workspace-card {
    min-width: 0;
  }

  .grid-sidebar,
  .record-main,
  .oz-record-main-grid,
  .oz-home-work-grid,
  .oz-home-top-grid,
  .oz-home-quick-actions,
  .oz-object-manager-shell,
  .oz-object-detail-grid,
  .oz-setup-header-top,
  .duplicate-record-grid,
  .duplicate-merge-choice-grid {
    grid-template-columns: 1fr;
  }

  .oz-object-sidebar,
  .sidebar,
  .oz-filter-panel,
  .oz-record-right-panel {
    position: static;
    top: auto;
  }

  .oz-record-right-panel,
  .oz-object-workspace,
  .oz-object-sidebar,
  .oz-object-content,
  .record-main,
  .oz-record-main-grid {
    min-width: 0;
  }

  .hero,
  .oz-page-header,
  .card-header,
  .oz-record-headerbar,
  .oz-record-header,
  .oz-object-page-header,
  .oz-setup-nav,
  .oz-path-bar,
  .oz-path-steps,
  .oz-filter-panel-head,
  .oz-filter-links,
  .oz-filter-footer,
  .oz-modal-footer,
  .oz-modal-footer-actions,
  .oz-record-actions,
  .oz-home-quick-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .oz-record-headerbar,
  .oz-record-header,
  .oz-highlights-panel,
  .record-highlight-panel,
  .oz-record-highlights,
  .oz-record-summary-grid,
  .oz-workspace-health-grid,
  .oz-storage-health-grid,
  .oz-snapshot-grid,
  .oz-package-grid,
  .oz-import-grid,
  .oz-field-wizard-grid,
  .oz-layout-builder-grid,
  .oz-list-builder-grid,
  .oz-security-health-grid {
    grid-template-columns: 1fr;
  }

  .oz-record-meta-strip {
    align-items: stretch;
  }

  .oz-record-meta-item {
    width: 100%;
    justify-content: space-between;
  }

  .oz-record-title-block h1,
  .oz-record-title-block .sub,
  .oz-list-title-area h1,
  .oz-list-title-area .sub,
  .mobile-record-card,
  .global-result-card,
  .app-tile-main,
  .oz-backup-reminder-banner,
  .oz-workspace-warning,
  .oz-storage-warning {
    overflow-wrap: anywhere;
  }

  .empty-state {
    flex-direction: column;
    align-items: stretch;
  }

  h1 {
    font-size: 21px;
  }

  table {
    min-width: 720px;
  }

  .table-wrap,
  .oz-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .oz-related-table {
    min-width: 560px;
  }

  .oz-inline-search,
  .oz-inline-search input,
  .global-search,
  .global-search input,
  .oz-setup-search,
  .oz-setup-search input,
  .oz-setup-select-field,
  .oz-admin-toolbar .oz-inline-search input,
  .field input,
  .field select,
  .field textarea {
    width: 100%;
    min-width: 0;
  }

  .table-wrap::before {
    content: "Swipe horizontally to view more";
    display: block;
    padding: var(--oz-spacing-sm) var(--oz-spacing-md);
    color: var(--oz-color-text-weak);
    background: var(--oz-color-background);
    font-size: var(--oz-font-size-caption);
    border-bottom: 1px solid var(--oz-color-border-soft);
  }

  .record-card-list {
    display: grid;
    gap: var(--oz-spacing-md);
  }

  .record-table-on-mobile {
    display: none;
  }

  .mobile-record-card {
    background: var(--oz-color-surface);
    border: 1px solid var(--oz-color-border-soft);
    border-radius: var(--oz-radius-md);
    box-shadow: var(--oz-shadow-card);
    padding: var(--oz-spacing-md);
  }

  .oz-mobile-record-head,
  .oz-mobile-record-actions {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--oz-spacing-sm);
  }

  .oz-mobile-record-fields {
    display: grid;
    gap: var(--oz-spacing-sm);
    margin: var(--oz-spacing-sm) 0;
  }

  .oz-mobile-record-fields .kv {
    padding: 0;
  }

  .oz-mobile-record-actions {
    flex-wrap: wrap;
    align-items: center;
  }

  .oz-mobile-checkbox {
    margin-bottom: 0;
    min-width: 110px;
  }

  .oz-mobile-checkbox span {
    margin-bottom: 4px;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-wrap: wrap;
  }

  .oz-record-tabs,
  .oz-admin-tabs,
  .oz-setup-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 2px;
  }

  .oz-record-tabs button,
  .oz-admin-tabs button,
  .oz-setup-nav button,
  .mobile-bottom button span {
    white-space: nowrap;
    flex: 0 0 auto;
  }

  .oz-record-tabs button {
    min-height: 44px;
    max-width: 48vw;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .oz-modal-backdrop,
  .modal-backdrop,
  .command-backdrop {
    align-items: stretch;
    justify-content: center;
    padding: var(--oz-spacing-sm);
    overflow: auto;
  }

  .oz-modal {
    width: 100%;
    max-width: 720px;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    margin: 0;
  }

  .modal {
    width: 100%;
    max-width: 720px;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }

  .oz-modal-body {
    max-height: calc(100vh - 170px);
    max-height: calc(100dvh - 170px);
    overflow: auto;
    padding: var(--oz-spacing-md);
  }

  .oz-modal-header,
  .oz-modal-footer {
    padding-left: var(--oz-spacing-md);
    padding-right: var(--oz-spacing-md);
  }

  .oz-modal-header {
    padding-right: 48px;
  }

  .oz-modal-footer {
    grid-template-columns: 1fr;
  }

  .oz-modal-footer-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
    width: 100%;
  }

  .oz-column-sort-modal,
  .command-palette,
  .quick-create-modal,
  .quick-capture-modal,
  .oz-edit-modal,
  .modal {
    width: 100%;
    max-width: 720px;
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }

  .command-palette {
    margin: 0;
  }

  .command-list,
  .quick-create-body,
  .oz-import-body,
  .oz-field-wizard-body {
    max-height: calc(100vh - 170px);
    max-height: calc(100dvh - 170px);
    overflow: auto;
  }

  .quick-create-list,
  .oz-edit-grid,
  .oz-sort-row,
  .oz-filter-card,
  .oz-admin-toolbar,
  .oz-list-toolbar,
  .oz-list-toolbar-actions,
  .oz-record-actions,
  .oz-setup-header-actions,
  .oz-workspace-actions,
  .oz-snapshot-actions,
  .oz-import-actions {
    grid-template-columns: 1fr;
    flex-wrap: wrap;
  }

  .modal-actions,
  .oz-backup-reminder-banner .actions,
  .oz-persistence-banner .actions,
  .oz-workspace-actions,
  .oz-list-toolbar-actions,
  .oz-record-actions {
    width: 100%;
  }

  .oz-filter-panel {
    width: 100%;
    max-width: 100%;
    max-height: none;
  }

  .oz-filter-panel-body,
  .oz-object-meta-nav,
  .oz-setup-sidebar {
    max-height: 260px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .oz-persistence-banner,
  .oz-workspace-warning,
  .oz-storage-warning,
  .oz-backup-reminder {
    flex-direction: column;
    align-items: stretch;
  }

  .oz-filter-panel,
  .oz-object-content,
  .card-body {
    padding-left: var(--oz-spacing-md);
    padding-right: var(--oz-spacing-md);
  }

  .btn,
  .oz-btn {
    min-height: var(--oz-height-button-touch);
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.2;
  }

  .mobile-topbar-actions .btn,
  .mobile-topbar-actions .oz-btn,
  .mobile-bottom button {
    min-height: 42px;
  }

  .oz-row-action-button,
  .inline-edit {
    min-width: 42px;
    min-height: 42px;
  }
}

@media (max-width: 520px) {
  .hero-title,
  .oz-page-header-title {
    align-items: flex-start;
  }

  .mobile-topbar {
    align-items: flex-start;
  }

  .mobile-topbar .logo {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
  }

  .mobile-topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .mobile-topbar-actions .btn,
  .mobile-topbar-actions .oz-btn {
    flex: 1 1 0;
    min-width: 0;
  }

  .hero-icon,
  .oz-page-header-icon {
    width: 40px;
    height: 40px;
  }

  .btn,
  .oz-btn {
    width: 100%;
  }

  .mobile-topbar > .btn,
  .mobile-bottom button,
  .oz-row-action-button,
  .inline-edit {
    width: auto;
  }

  .mobile-bottom button {
    font-size: 11px;
  }

  .mobile-bottom .ico {
    font-size: 16px;
  }

  .mobile-record-card,
  .oz-object-content,
  .oz-object-title-card {
    padding: var(--oz-spacing-sm);
  }

  .oz-mobile-record-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}
