html, body, #root {
  min-height: 100%;
}

/* The pipeline keeps its dedicated search control for mobile, where the
   global top search bar is hidden. On desktop, use the global search only. */
@media (min-width: 761px) {
  .crm-pipeline-toolbar > input[aria-label="Search deal pipeline"] {
    display: none !important;
  }
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .crm-shell {
    height: 100dvh !important;
    flex-direction: column !important;
  }

  .crm-sidebar {
    width: 100% !important;
    min-height: auto !important;
    flex-direction: row !important;
    position: relative;
    z-index: 30;
  }

  .crm-sidebar > div:first-child,
  .crm-sidebar > div:nth-last-child(-n+2) {
    display: none !important;
  }

  .crm-nav {
    display: flex !important;
    flex: 1 1 auto !important;
    padding: 7px 8px !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    gap: 4px;
    scrollbar-width: none;
  }

  .crm-nav::-webkit-scrollbar {
    display: none;
  }

  .crm-nav > button {
    width: auto !important;
    min-width: max-content;
    margin: 0 !important;
    padding: 8px 10px !important;
  }

  .crm-nav > button > span:nth-child(2) {
    flex: initial !important;
  }

  .crm-main {
    min-width: 0;
    overflow-x: hidden !important;
  }

  .crm-topbar {
    display: none !important;
  }

  .crm-content {
    padding: 16px 12px 28px !important;
  }

  .crm-content h1 {
    font-size: 21px !important;
  }

  .crm-content [style*="grid-template-columns"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .crm-content [style*="justify-content: space-between"] {
    flex-wrap: wrap;
    gap: 10px;
  }

  .crm-deal-toolbar,
  .crm-pipeline-toolbar {
    align-items: flex-start !important;
  }

  .crm-deal-toolbar > div:last-child,
  .crm-pipeline-toolbar > div:last-child {
    width: 100% !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .crm-deal-toolbar select,
  .crm-deal-toolbar input,
  .crm-pipeline-toolbar input {
    min-width: 0 !important;
    flex: 1 1 145px !important;
    width: auto !important;
  }

  .crm-deal-toolbar button,
  .crm-pipeline-toolbar button {
    flex: 0 0 auto !important;
  }

  .crm-content select,
  .crm-content input,
  .crm-content textarea {
    max-width: 100%;
  }

  .crm-content div:has(> table) {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .crm-content table {
    min-width: 680px;
  }

  .crm-content [style*="min-width: 240px"] {
    min-width: calc(100vw - 40px) !important;
    max-width: calc(100vw - 40px) !important;
  }

  /* Deal Pipeline: stages stack down the page; deals scroll across each stage. */
  .crm-content div:has(> div[style*="min-width: 240px"]) {
    flex-direction: column !important;
    align-items: stretch !important;
    overflow-x: visible !important;
    gap: 18px !important;
    padding-bottom: 8px !important;
  }

  .crm-content [style*="min-width: 240px"] {
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
  }

  .crm-content [style*="min-width: 240px"] > div:nth-child(2) {
    flex-direction: row !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    scroll-snap-type: x mandatory;
    scroll-padding-left: 2px;
    -webkit-overflow-scrolling: touch;
    gap: 10px !important;
    padding: 10px !important;
    min-height: 0 !important;
    scrollbar-width: none;
  }

  .crm-content [style*="min-width: 240px"] > div:nth-child(2)::-webkit-scrollbar {
    display: none;
  }

  .crm-content [style*="min-width: 240px"] > div:nth-child(2) > div {
    flex: 0 0 min(82vw, 320px) !important;
    scroll-snap-align: start;
  }

  .crm-content [style*="min-width: 240px"] > div:nth-child(2) > div > div:first-child {
    aspect-ratio: 4 / 3;
  }

  .crm-modal-backdrop {
    align-items: flex-start !important;
    padding: 8px !important;
  }

  .crm-modal {
    max-width: 100% !important;
    max-height: calc(100dvh - 16px) !important;
    border-radius: 10px !important;
  }

  .crm-modal > div {
    padding: 16px !important;
  }

  .crm-modal > div:has(> div > img) {
    padding-top: 16px !important;
  }

  .crm-modal [style*="grid-template-columns"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .crm-modal [style*="justify-content: space-between"] {
    flex-wrap: wrap;
    gap: 10px;
  }

  .crm-modal button,
  .crm-content button {
    min-height: 38px;
  }
}

@media (max-width: 420px) {
  .crm-nav > button {
    font-size: 12px !important;
  }

  .crm-nav > button > span:first-child {
    display: none;
  }

  .crm-content {
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
}
