@media (min-width: 1200px) {
  body[data-page="dashboard"] .main-content {
    padding-bottom: 28px;
  }
}

@media (min-width: 992px) {
  [data-recent-boqs-table],
  [data-recent-customer-pos-panel] .panel-body {
    min-height: 0;
    flex: 1;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  .dashboard-recent .table-dashboard th {
    position: sticky;
    z-index: 1;
    top: 0;
  }
}

@media (max-width: 1199px) {
  .topbar {
    gap: 10px;
  }

  .universal-search {
    width: clamp(220px, 28vw, 340px);
  }

  .topbar .user-menu-trigger .desktop-only,
  .universal-search-shortcut {
    display: none;
  }

  .universal-search-field input {
    padding-right: 32px;
  }

  .main-content {
    padding: 24px;
  }

  .editor-layout {
    grid-template-columns: minmax(0, 1fr) 250px;
  }

  .dashboard-grid {
    grid-template-columns: minmax(0, 1.5fr) minmax(260px, 0.7fr);
  }
}

@media (max-width: 991px) {
  :root {
    --header-height: 54px;
  }

  html,
  body {
    overflow-x: clip;
  }

  .responsive-table {
    overflow: hidden;
  }

  .sidebar {
    width: min(284px, calc(100vw - 52px));
    overscroll-behavior: contain;
    box-shadow: var(--shadow-modal);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  body.nav-open {
    overflow: hidden;
  }

  body.universal-search-open {
    overflow: hidden;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    z-index: 45;
    inset: 0;
    display: block;
    background: rgba(13, 19, 26, 0.46);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
  }

  body.nav-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .app-column {
    margin-left: 0;
  }

  .mobile-nav-trigger,
  .mobile-brand {
    display: inline-flex;
  }

  .mobile-brand {
    align-items: center;
    color: var(--color-text);
    font-size: 13px;
    font-weight: 680;
  }

  .breadcrumb {
    display: none;
  }

  .topbar {
    padding: 0 18px;
  }

  .topbar-left {
    min-width: 0;
  }

  .universal-search {
    position: fixed;
    z-index: 60;
    top: var(--header-height);
    right: 0;
    left: 0;
    display: none;
    width: auto;
    padding: 12px 18px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    box-shadow: var(--shadow-popover);
    transform: none;
  }

  body.universal-search-open .universal-search {
    display: block;
  }

  .universal-search-field {
    height: 40px;
  }

  .universal-search-field input {
    padding-right: 42px;
  }

  .universal-search-field input::-webkit-search-cancel-button {
    display: none;
    -webkit-appearance: none;
  }

  .universal-search-trigger,
  .universal-search-close {
    display: inline-grid;
  }

  .universal-search-close {
    position: absolute;
    right: 3px;
    width: 32px;
    height: 32px;
    place-items: center;
  }

  .universal-search-results {
    top: 100%;
    right: 18px;
    left: 18px;
    max-height: calc(100vh - var(--header-height) - 76px);
  }

  .dashboard-grid,
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .dashboard-primary,
  .dashboard-attention {
    display: contents;
  }

  .dashboard-metrics {
    order: 1;
  }

  .dashboard-attention > :first-child {
    order: 2;
  }

  .dashboard-recent {
    order: 3;
  }

  .dashboard-attention > [data-recent-customer-pos-panel] {
    order: 4;
  }

  .editor-page-header {
    flex-wrap: wrap;
  }

  .editor-page-header .page-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .editor-summary {
    position: static;
    grid-row: 1;
    max-height: none;
    overflow: visible;
  }

  .summary-card {
    display: grid;
    grid-template-columns: minmax(220px, 0.8fr) minmax(0, 1.2fr);
  }

  .summary-card-header,
  .summary-meta {
    display: none;
  }

  .summary-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-column: 2;
    grid-row: 1;
    padding: 10px 14px;
    border-left: 1px solid var(--color-border);
  }

  .summary-row {
    display: block;
    padding: 6px 10px;
    border-left: 0;
  }

  .summary-row:nth-child(even) {
    border-left: 1px solid var(--color-border);
  }

  .summary-row strong {
    display: block;
    margin-top: 3px;
  }

  .summary-total {
    grid-column: 1;
    grid-row: 1;
    margin: 0;
    border-top: 0;
  }

  .settings-layout {
    grid-template-columns: 1fr;
  }

  .settings-nav {
    position: static;
    display: flex;
    overflow-x: auto;
    padding-bottom: 4px;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }

  .settings-nav a {
    min-height: 38px;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .table-wrap {
    overscroll-behavior-inline: contain;
  }
}

@media (max-width: 767px) {
  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: initial;
  }

  .topbar {
    padding: 0 12px;
  }

  .universal-search {
    padding: 10px 12px;
  }

  .universal-search-results {
    right: 12px;
    left: 12px;
    max-height: calc(100vh - var(--header-height) - 68px);
  }

  .topbar-actions {
    gap: 3px;
  }

  .topbar-actions .button-secondary {
    width: 34px;
    min-width: 34px;
    padding: 0;
  }

  .topbar-actions .button-secondary span {
    display: none;
  }

  .main-content {
    padding: 20px 14px 40px;
  }

  body[data-page="boq-editor"] .main-content {
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
  }

  .page-header {
    display: block;
    margin-bottom: 18px;
  }

  .page-header-copy p {
    font-size: 12px;
  }

  .page-actions {
    width: 100%;
    flex-wrap: wrap;
    margin-top: 14px;
  }

  .page-actions .button-primary {
    flex: 1;
  }

  .editor-page-header .page-actions [data-save],
  .editor-page-header .page-actions [data-create-revision],
  .editor-page-header .page-actions [data-mark-won] {
    display: none;
  }

  body[data-page="boq-editor"].boq-won .main-content {
    padding-bottom: 40px;
  }

  .panel-header,
  .panel-body {
    padding-inline: 14px;
  }

  .panel-header > div,
  .modal-header > div {
    min-width: 0;
  }

  .record-metric {
    min-height: 88px;
    padding: 14px 16px;
  }

  .record-metric-value {
    margin-top: 7px;
    font-size: 25px;
  }

  .record-metric-detail {
    margin-top: 6px;
  }

  .record-metric-overview {
    grid-template-columns: 1fr;
  }

  .record-metric + .record-metric {
    border-top: 1px solid var(--color-border);
    border-left: 0;
  }

  .toolbar {
    align-items: stretch;
    padding: 11px;
  }

  .toolbar-group,
  .search-field {
    width: 100%;
  }

  .toolbar-group > label {
    min-width: 0;
    flex: 1 1 160px;
  }

  .toolbar > label:not(.search-field) {
    width: 100%;
  }

  .toolbar-group .select {
    min-width: 0;
    flex: 1;
  }

  .responsive-table .table-wrap {
    display: none;
  }

  .record-card-list {
    display: block;
  }

  .editor-desktop-table {
    display: none;
  }

  .editor-table-viewport {
    display: none;
  }

  .mobile-item-list {
    display: block;
  }

  .editor-toolbar .button span.optional-label {
    display: none;
  }

  .editor-toolbar .toolbar-group:first-child,
  .editor-view-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .editor-toolbar .toolbar-group:first-child .button,
  .editor-view-controls .button {
    width: 100%;
  }

  .editor-view-controls > label {
    grid-column: 1 / -1;
  }

  .editor-view-controls [data-toggle-reorder] {
    grid-column: 1 / -1;
  }

  .supporting-materials-panel .panel-header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .supporting-materials-panel [data-supporting-save-state] {
    max-width: 100%;
  }

  .supporting-materials-toolbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .supporting-materials-toolbar .toolbar-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
  }

  .supporting-materials-toolbar .button {
    min-width: 0;
    width: 100%;
  }

  .supporting-optional-label {
    display: none;
  }

  .supporting-materials-toolbar [data-save-supporting] {
    grid-column: 1 / -1;
  }

  .summary-card {
    display: block;
  }

  .summary-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 8px;
    border-left: 0;
  }

  .summary-row {
    padding: 5px 8px;
  }

  .summary-row:nth-child(odd) {
    border-left: 0;
  }

  .summary-row:nth-child(even) {
    border-left: 1px solid var(--color-border);
  }

  .summary-row strong {
    font-size: 12px;
  }

  .summary-total {
    padding: 13px 14px;
  }

  .summary-total strong {
    font-size: 22px;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px;
  }

  .col-3,
  .col-4,
  .col-5,
  .col-6,
  .col-8 {
    grid-column: span 1;
  }

  .col-12 {
    grid-column: 1 / -1;
  }

  .field-wide-mobile {
    grid-column: 1 / -1;
  }

  .modal-backdrop {
    align-items: end;
    padding: 0;
  }

  .modal {
    width: 100%;
    max-height: calc(100vh - 28px);
    max-height: calc(100dvh - env(safe-area-inset-top) - 12px);
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    animation-name: modal-mobile-in;
  }

  @keyframes modal-mobile-in {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
  }

  .modal-header {
    position: sticky;
    z-index: 2;
    top: 0;
    align-items: flex-start;
    background: var(--color-surface-raised);
  }

  .modal-header .icon-button {
    flex: 0 0 auto;
  }

  .modal-footer {
    position: sticky;
    z-index: 2;
    bottom: 0;
    flex-wrap: wrap;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    background: var(--color-surface-raised);
  }

  .modal-footer > .cluster {
    min-width: 0;
  }

  .settings-section .panel-body {
    padding: 15px;
  }

  .mobile-save-bar {
    position: fixed;
    z-index: 42;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    min-height: 68px;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--color-border);
    background: var(--color-surface-raised);
    box-shadow: 0 -8px 22px rgba(17, 25, 34, 0.08);
  }

  .mobile-save-bar strong,
  .mobile-save-bar span {
    display: block;
  }

  .mobile-save-bar strong {
    width: 140px;
    font-size: 15px;
    font-variant-numeric: tabular-nums;
  }

  .mobile-save-bar span {
    color: var(--color-text-muted);
    font-size: 10px;
  }

  .mobile-save-actions {
    min-width: 0;
    flex: 1 1 auto;
    justify-content: flex-end;
  }

  .mobile-save-actions .button {
    padding-inline: 10px;
  }

  .catalog-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .catalog-row > div {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .catalog-row > div:nth-child(2) {
    display: none;
  }

  .logo-upload {
    align-items: flex-start;
  }

  .data-management-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .record-card-header > :first-child {
    min-width: 0;
  }

  .record-card-header .status {
    flex: 0 0 auto;
  }

  .record-card-grid,
  .mobile-item-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-card-grid dd,
  .record-card-header .cell-primary {
    overflow-wrap: anywhere;
  }

  .detail-table-wrap {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }

  .product-usage-toolbar {
    align-items: stretch;
    flex-direction: column;
    padding: 11px 14px;
  }

  .product-usage-toolbar .search-field,
  .product-usage-toolbar > label {
    width: 100%;
  }

  .product-usage-toolbar .search-field {
    flex-basis: auto;
  }

  .product-usage-toolbar .select {
    width: 100%;
  }

  .product-usage-table-wrap {
    display: none;
  }

  .product-usage-cards {
    display: block;
  }

  .dashboard-recent .table-dashboard {
    min-width: 0;
    table-layout: fixed;
  }

  .dashboard-recent .dashboard-financial-column,
  .dashboard-recent .dashboard-updated-column {
    display: none;
  }

  .dashboard-recent th,
  .dashboard-recent td {
    padding-inline: 14px;
  }

  .dashboard-recent th:nth-child(1) {
    width: 31%;
  }

  .dashboard-recent th:nth-child(2) {
    width: 41%;
  }

  .dashboard-recent th:nth-child(3) {
    width: 28%;
  }

  .dashboard-recent td:nth-child(2) {
    overflow-wrap: anywhere;
  }

  body[data-page="boq-editor"] .toast-region {
    bottom: calc(82px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 767px),
  (max-width: 991px) and (max-height: 500px) {
  #pdf-modal .document-preview-fit-viewport {
    width: 100%;
    overflow: hidden;
  }

  #pdf-modal .document-preview-fit-stage {
    position: relative;
    width: 100%;
    min-height: 1px;
  }

  #pdf-modal .pdf-preview {
    position: absolute;
    top: 0;
    left: 0;
    width: 656px;
    min-width: 656px;
    padding: 18px;
    overflow: visible;
    transform-origin: top left;
  }

  #pdf-modal .pdf-preview-content {
    width: 620px;
    min-width: 620px;
  }
}

@media (max-width: 480px) {
  .mobile-save-bar > div:first-child {
    display: none;
  }

  .mobile-save-actions {
    width: 100%;
    flex: 1 1 100%;
  }

  .mobile-save-actions .button {
    flex: 1;
  }

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

  .col-3,
  .col-4,
  .col-5,
  .col-6,
  .col-8,
  .col-12 {
    grid-column: 1;
  }

  .supporting-materials-mobile-list .col-12 {
    grid-column: 1 / -1;
  }

  .record-card-grid {
    grid-template-columns: 1fr 1fr;
  }

  .toolbar-group > label {
    flex-basis: 100%;
  }

  .modal-footer {
    align-items: stretch;
  }

  .modal-footer > .button,
  .modal-footer > .cluster,
  .modal-footer > .cluster .button {
    width: 100%;
  }

  .modal-footer > .cluster {
    display: grid;
    grid-template-columns: 1fr;
  }

  .settings-logo-upload {
    align-items: flex-start;
    flex-direction: column;
  }

  .settings-logo-upload > .stack-xs {
    width: 100%;
    min-width: 0;
  }

  .data-management-row .toolbar-group .button {
    flex: 1 1 140px;
  }
}

@media (max-width: 360px) {
  .mobile-brand {
    max-width: 82px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .summary-list,
  .record-card-grid,
  .mobile-item-body {
    grid-template-columns: 1fr;
  }

  .summary-row,
  .summary-row:nth-child(even) {
    border-left: 0;
  }

  .summary-row + .summary-row {
    border-top: 1px solid var(--color-border);
  }
}

@supports (-webkit-touch-callout: none) {
  @media (hover: none) and (pointer: coarse) {
    input[type="search"] {
      font-size: 16px;
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
