/* Compact Sales and Customers layouts on phones. All actions use the existing controls. */
@media (max-width: 760px) {
  :is([data-page-route="followups"], [data-page-route="calls"], [data-page-route="outreach"],
      [data-page-route="campaigns"], [data-page-route="social"], [data-page-route="contacts"])
    #page-content .page-head {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) fit-content(54%);
    align-items: center !important;
    gap: 8px !important;
    margin: 0 0 12px !important;
  }
  :is([data-page-route="followups"], [data-page-route="calls"], [data-page-route="outreach"],
      [data-page-route="campaigns"], [data-page-route="social"], [data-page-route="contacts"])
    #page-content .page-head > * {
    min-width: 0;
    margin: 0 !important;
  }
  :is([data-page-route="followups"], [data-page-route="calls"], [data-page-route="outreach"],
      [data-page-route="campaigns"], [data-page-route="social"], [data-page-route="contacts"])
    #page-content .page-head .page-actions {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center;
    width: auto !important;
  }
  :is([data-page-route="followups"], [data-page-route="calls"], [data-page-route="outreach"],
      [data-page-route="campaigns"], [data-page-route="social"], [data-page-route="contacts"])
    #page-content .page-head :is(.btn, h1) {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  :is([data-page-route="followups"], [data-page-route="calls"], [data-page-route="outreach"],
      [data-page-route="campaigns"], [data-page-route="social"], [data-page-route="contacts"])
    #page-content .page-head .page-actions > .btn {
    min-height: 44px !important;
    min-width: 0;
    width: auto !important;
    padding: 7px 11px !important;
    font-size: .8125rem !important;
    line-height: 1.2;
    gap: 5px;
    text-align: center;
  }

  /* Keep the two original permission-checked actions inside the banner. */
  #page-content .customer-companies-screen .customer-page-head {
    position: relative;
    isolation: isolate;
    overflow: hidden;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) fit-content(48%);
    align-items: center;
    gap: 6px 10px !important;
    padding: 10px 12px !important;
    margin: 0 0 10px !important;
    border-radius: 14px;
    background: linear-gradient(110deg, #56152c, #8a173a 70%, #a31d43);
    color: #fff;
  }
  #page-content .customer-companies-screen .customer-page-head > :first-child {
    min-width: 0;
    min-height: 0;
    margin: 0;
    padding: 0 !important;
    background: transparent !important;
    position: static;
  }
  #page-content .customer-companies-screen .customer-page-head > :first-child::after {
    z-index: -1;
    opacity: .23;
  }
  #page-content .customer-companies-screen .customer-page-head .eyebrow { display: none; }
  #page-content .customer-companies-screen .customer-page-head h1 {
    margin: 0;
    color: #fff !important;
    font-size: clamp(1.25rem, 5vw, 1.55rem) !important;
    line-height: 1.14 !important;
    overflow-wrap: anywhere;
  }
  #page-content .customer-companies-screen .customer-page-head p {
    margin: 4px 0 0;
    color: #ffecf2 !important;
    line-height: 1.25;
  }
  #page-content .customer-companies-screen .customer-page-head .page-actions {
    display: grid !important;
    gap: 4px !important;
    width: auto !important;
    margin: 0 !important;
    align-self: center;
  }
  #page-content .customer-companies-screen .customer-page-head .page-actions:empty { display: none !important; }
  #page-content .customer-companies-screen .customer-page-head:has(.page-actions:empty) { grid-template-columns: 1fr; }
  #page-content .customer-companies-screen .page-actions button {
    width: 100% !important;
    min-width: 0;
    min-height: 40px !important;
    border: 1px solid #f7bdcf !important;
    border-radius: 8px !important;
    padding: 6px 10px !important;
    font-size: .8125rem !important;
    line-height: 1.2;
    gap: 5px;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  #page-content .customer-companies-screen .page-actions [data-action="customer-company-new"] {
    order: -1;
    color: #7b1335 !important;
    background: #fff !important;
  }
  #page-content .customer-companies-screen .page-actions [data-action="location-review"] {
    background: #681530 !important;
    color: #fff !important;
  }

  /* Directory records share a stable identity/status row and an action footer. */
  #page-content .customer-table.mobile-record-table tbody > tr {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto fit-content(32%) !important;
    grid-template-areas: "identity identity status" "next open open" !important;
    padding: 11px !important;
    gap: 8px 10px !important;
  }
  #page-content .customer-table.mobile-record-table tbody > tr > td {
    min-width: 0;
    padding: 0 !important;
    margin: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  #page-content .customer-table.mobile-record-table .entity-cell,
  #page-content .people-mobile-table .entity-cell {
    display: flex;
    align-items: center !important;
    gap: 8px;
    min-width: 0;
  }
  #page-content .customer-table .entity-cell > div,
  #page-content .people-mobile-table .entity-cell > div { min-width: 0; }
  #page-content .customer-table .entity-title,
  #page-content .people-mobile-table .entity-title {
    display: block;
    white-space: normal !important;
    overflow-wrap: anywhere;
    text-align: start;
    line-height: 1.3;
  }
  #page-content .customer-table .entity-cell { align-items: flex-start !important; }
  #page-content .customer-table .customer-open-link svg { flex: none; width: 14px; height: 14px; }
  #page-content .customer-table .mobile-record-identity { grid-area: identity !important; }
  #page-content .customer-table .mobile-record-identity::before,
  #page-content .customer-table .mobile-record-action::before,
  #page-content .customer-table .mobile-record-status::before { display: none !important; }
  #page-content .customer-table .mobile-record-status {
    grid-area: status !important;
    align-self: start;
    justify-self: end;
  }
  #page-content .customer-table .mobile-record-next {
    grid-area: next !important;
    align-self: center;
    background: transparent;
  }
  #page-content .customer-table .mobile-record-action {
    grid-area: open !important;
    align-self: end;
    justify-self: end;
  }
  /* Some versions expose additional columns in the mobile directory. */
  body:not(.sections) #page-content .customer-table.mobile-record-table tbody > tr {
    grid-template-areas: "identity identity status" "people people pipeline" "owner owner owner" "next open open" !important;
  }
  #page-content .customer-table tr > td:nth-child(3) { grid-area: people; }
  #page-content .customer-table tr > td:nth-child(4) { grid-area: pipeline; }
  #page-content .customer-table tr > td:nth-child(6) { grid-area: owner; }
  #page-content .customer-table .customer-open-link,
  #page-content .people-mobile-table .mobile-record-action .btn {
    min-width: 44px !important;
    min-height: 40px !important;
    padding: 5px 9px !important;
    white-space: normal;
    line-height: 1.25;
  }

  #page-content .people-mobile-table tbody > tr {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    grid-template-areas: "identity identity" "company role" "contact contact" "relationship edit";
    gap: 8px 10px;
    padding: 11px;
  }
  #page-content .people-mobile-table .mobile-record-identity {
    grid-area: identity;
    border-block-end: 1px solid #e8dfe3;
    padding-bottom: 7px !important;
  }
  #page-content .people-mobile-table tr > td:nth-child(2) { grid-area: company; }
  #page-content .people-mobile-table tr > td:nth-child(3) { grid-area: role; }
  #page-content .people-mobile-table .mobile-record-next {
    grid-area: contact;
    padding: 0 !important;
    border-radius: 0;
    background: transparent;
  }
  #page-content .people-mobile-table td .text-link {
    display: inline-block;
    text-align: start;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  #page-content .people-mobile-table tr > td:nth-child(5) { grid-area: relationship; align-self: center; }
  #page-content .people-mobile-table .mobile-record-action {
    grid-area: edit;
    align-self: end;
    justify-self: end;
    padding: 0 !important;
  }

  /* Keep the customer details and discussion readable with long freeform text. */
  #page-content .followup-table table[data-mobile-card] tbody > tr {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    grid-template-areas: "when when" "customer customer" "notes notes" "deal owner" "actions actions";
    align-items: start;
    padding: 12px;
    gap: 9px 12px;
  }
  #page-content .followup-table table[data-mobile-card] td { overflow-wrap: anywhere; }
  #page-content .followup-table table[data-mobile-card] td:nth-child(1) {
    grid-area: when;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 7px;
  }
  #page-content .followup-table .followup-status-date::before,
  #page-content .followup-table td:last-child::before { display: none; }
  #page-content .followup-table .followup-status-date small { display: inline; margin: 0; }
  #page-content .followup-table td:nth-child(2) { grid-area: customer; }
  #page-content .followup-table .followup-customer { min-width: 0; max-width: none; gap: 8px; }
  #page-content .followup-table .followup-customer > .avatar { flex: 0 0 28px; width: 28px; height: 28px; }
  #page-content .followup-table .followup-context { display: block; margin: 2px 0 0; padding-inline-start: 36px; }
  #page-content .followup-table td.followup-discussion {
    grid-area: notes;
    max-width: none;
    min-width: 0;
    line-height: 1.4;
  }
  #page-content .followup-table .followup-discussion p {
    display: block;
    margin: 3px 0 0;
    line-height: 1.4;
    -webkit-line-clamp: unset;
    overflow: visible;
    color: #574750;
  }
  #page-content .followup-table td:nth-child(4) { grid-area: deal; }
  #page-content .followup-table td:nth-child(5) { grid-area: owner; }
  #page-content .followup-table td:nth-child(6) { grid-area: actions; }
  #page-content .followup-table .followup-actions {
    display: flex;
    max-width: none;
    gap: 7px;
    justify-content: flex-end;
    border-top: 1px solid #e8dfe3;
    padding-top: 8px;
  }
  #page-content .followup-table .followup-actions > .btn {
    min-height: 40px;
    flex: 0 1 auto;
    white-space: normal;
    text-align: center;
  }
}

@media (min-width:761px) and (max-width:1023px) {
  :is([data-page-route="followups"], [data-page-route="calls"], [data-page-route="outreach"],
      [data-page-route="campaigns"], [data-page-route="social"], [data-page-route="contacts"])
    #page-content .page-head {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) fit-content(54%);
    align-items: center !important;
    gap: 8px !important;
    margin: 0 0 12px !important;
  }
  :is([data-page-route="followups"], [data-page-route="calls"], [data-page-route="outreach"],
      [data-page-route="campaigns"], [data-page-route="social"], [data-page-route="contacts"])
    #page-content .page-head > * {
    min-width: 0;
    margin: 0 !important;
  }
  :is([data-page-route="followups"], [data-page-route="calls"], [data-page-route="outreach"],
      [data-page-route="campaigns"], [data-page-route="social"], [data-page-route="contacts"])
    #page-content .page-head .page-actions {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center;
    width: auto !important;
  }
  :is([data-page-route="followups"], [data-page-route="calls"], [data-page-route="outreach"],
      [data-page-route="campaigns"], [data-page-route="social"], [data-page-route="contacts"])
    #page-content .page-head :is(.btn, h1) {
    white-space: normal;
    overflow-wrap: anywhere;
  }
  :is([data-page-route="followups"], [data-page-route="calls"], [data-page-route="outreach"],
      [data-page-route="campaigns"], [data-page-route="social"], [data-page-route="contacts"])
    #page-content .page-head .page-actions > .btn {
    min-height: 44px !important;
    min-width: 0;
    width: auto !important;
    padding: 7px 11px !important;
    font-size: .8125rem !important;
    line-height: 1.2;
    gap: 5px;
    text-align: center;
  }
}

/* Align search and filter controls to the width of their results panel. */
.followup-list-panel {
  container: followup-list / inline-size;
}
#page-content .followup-list-panel .followup-toolbar {
  --control-height: 2.625rem;
  display: grid !important;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, var(--filter-columns, 2.65fr)) auto;
  align-items: end;
  gap: .75rem;
  padding: 1rem;
}
#page-content #followup-call-filters {
  --filter-columns: 1.8fr;
}
#page-content .followup-toolbar .field {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: .35rem;
  min-width: 0;
  max-width: none;
  margin: 0;
}
#page-content .followup-toolbar .field > span:first-child {
  color: #495463;
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.35;
}
#page-content .followup-toolbar > .followup-search {
  grid-area: auto;
}
#page-content .followup-toolbar .search-field {
  position: relative;
  display: flex;
  min-width: 0;
  width: 100%;
  margin: 0;
  padding: 0;
}
#page-content .followup-toolbar .search-field svg {
  position: absolute;
  inset-inline-start: .7rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}
#page-content .followup-toolbar .search-field input {
  padding-inline: 2.15rem .65rem !important;
}
#page-content .followup-toolbar :is(input, select, .btn) {
  box-sizing: border-box;
  min-width: 0;
  min-height: var(--control-height);
  height: var(--control-height);
}
#page-content .followup-toolbar :is(input, select) {
  width: 100%;
  max-width: 100%;
  font-size: .875rem;
  line-height: 1.3;
}
#page-content .followup-filter-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: end;
  gap: .75rem;
}
#page-content #followup-call-filters .followup-filter-options {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
#page-content .followup-filter-actions {
  display: flex;
  align-items: end;
  gap: .4rem;
}
#page-content .followup-filter-toggle {
  display: none;
}
@container followup-list (max-width: 54rem) {
  #page-content .followup-list-panel .followup-toolbar {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  #page-content .followup-filter-actions {
    grid-area: 1 / 2;
  }
  #page-content .followup-filter-options {
    grid-row: 2;
    grid-column: 1 / -1;
  }
  #page-content .followup-toolbar:not(.filters-open) .followup-filter-options {
    display: none;
  }
  #page-content .followup-filter-toggle {
    display: inline-flex;
  }
}
@container followup-list (max-width: 34rem) {
  #page-content .followup-list-panel .followup-toolbar {
    --control-height: 44px;
    grid-template-columns: minmax(0, 1fr);
    gap: .65rem;
    padding: .75rem;
  }
  #page-content .followup-toolbar :is(input, select) {
    font-size: 1rem;
  }
  #page-content .followup-filter-actions {
    grid-area: auto;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  #page-content .followup-filter-actions .btn {
    width: 100%;
    margin: 0;
    white-space: normal;
  }
  #page-content .followup-filter-options {
    grid-row: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .6rem;
  }
  #page-content #followup-filters .followup-filter-options > :first-child {
    grid-column: 1 / -1;
  }
}

/* Keep the relevant date sort in reach at every follow-up list width. */
#page-content #followup-filters.followup-queue-toolbar {
  grid-template-columns: minmax(0, 1fr);
}
#followup-filters .queue-primary-row,
#followup-filters .queue-extra-row {
  display: grid;
  align-items: end;
  gap: .65rem;
  grid-template-columns: minmax(10rem, 1.5fr) minmax(9rem, 1fr) minmax(10rem, 1fr) minmax(6rem, .8fr) minmax(6rem, .8fr) auto;
}
#followup-filters .queue-extra-row {
  border-block-start: 1px solid var(--line, #e4e1e3);
  padding-block-start: .75rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
#followup-filters .queue-extra-row[hidden] { display: none; }
#followup-filters .queue-actions {
  display: flex;
  gap: .4rem;
}
#followup-filters .queue-next-seven {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  min-height: var(--control-height);
  cursor: pointer;
}
#page-content #followup-filters input[type=checkbox] {
  width: 1rem;
  min-height: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--brand, #9a123e);
}
@container followup-list (max-width: 68rem) {
  #followup-filters .queue-primary-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  #followup-filters .queue-actions .btn { flex: 1; }
}
@container followup-list (max-width: 48rem) {
  #followup-filters .queue-primary-row,
  #followup-filters .queue-extra-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #page-content #followup-filters .followup-search,
  #followup-filters .queue-actions { grid-column: 1 / -1; }
  #page-content #followup-filters:not(.filters-open) .queue-scope { display: none; }
  #followup-filters .queue-actions .btn { min-width: 0; padding-inline: .45rem; }
}
