/* LitigationSpace — mobile compatibility fixes */

@media (max-width: 767px) {

  /* Clear hamburger button (fixed at top:12, 40px tall → 52px) + breathing room */
  main {
    padding: 64px 16px 24px !important;
  }

  /* 4-column stat grids → 2-column */
  [style*="repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* 3-column feature grids → 1-column */
  [style*="repeat(3, 1fr)"] {
    grid-template-columns: 1fr !important;
  }

  /* 5-column grids → 2-column */
  [style*="repeat(5, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* 6-column grids → 2-column */
  [style*="repeat(6, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* 5-column fixed-size grids → 2-column */
  [style*="repeat(5, minmax"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Prevent headings and text from overflowing */
  h1, h2, h3, h4, h5, h6, p, span, div {
    word-break: break-word;
    overflow-wrap: break-word;
  }

  /* Document editor: make the 816px paper scrollable on mobile */
  .ls-editor {
    width: 100% !important;
    min-width: unset !important;
    padding: 20px !important;
    box-sizing: border-box !important;
  }

  /* Wrap flex rows that might overflow (filter bars, action rows) */
  [style*="display: flex"][style*="gap"] {
    flex-wrap: wrap;
  }

  /* Case list / document list: action buttons area */
  [style*="flex-shrink: 0"][style*="display: flex"] {
    flex-shrink: 1 !important;
    flex-wrap: wrap !important;
  }

  /* Prevent fixed-pixel width boxes from overflowing viewport */
  [style*="width: 400px"],
  [style*="width: 500px"],
  [style*="width: 560px"],
  [style*="width: 700px"] {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Modals: ensure full-width on small screens */
  [style*="max-width: 580px"],
  [style*="max-width: 440px"],
  [style*="max-width: 520px"] {
    max-width: calc(100vw - 32px) !important;
  }

  /* Horizontal scroll for wide tables */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Progress bars container in case rows — shrink on mobile */
  [style*="width: 100px"],
  [style*="width: 110px"] {
    width: auto !important;
    min-width: 0 !important;
    display: none !important;
  }

  /* Reduce font-size on large headings */
  [style*="font-size: 1.75rem"] {
    font-size: 1.35rem !important;
  }
  [style*="font-size: 1.6rem"] {
    font-size: 1.25rem !important;
  }
  [style*="font-size: 1.5rem"] {
    font-size: 1.2rem !important;
  }
}

/* Extra small screens (< 480px) */
@media (max-width: 479px) {

  /* 2-column stat grids → 1-column on very small screens */
  [style*="repeat(4, 1fr)"] {
    grid-template-columns: 1fr 1fr !important;
  }

  /* Modals get full screen treatment */
  [style*="max-width: 580px"],
  [style*="max-width: 440px"],
  [style*="max-width: 520px"] {
    max-width: 100% !important;
    margin: 0 !important;
    border-radius: 0 !important;
  }
}
