/* NAVONAX CRM v19
 * - Active Leads, Lead Follow-up and Lost Leads are static and show all six
 *   operational fields requested by Admin.
 * - At desktop widths, Lead values use the first line and the always-visible
 *   horizontal action strip uses a second line in the same static record.
 * - Projects are deliberately excluded so the original CRM Project table and
 *   original two-column Project action layout remain untouched.
 */

/* Never revive the retired Lead expansion controls in upgraded browser tabs. */
.nvx-desktop-lead-toggle,
.nvx-lead-expanded-panel,
.nvx-lead-expanded-row,
.nvx-desktop-lead-filters {
  display: none !important;
}

/* Keep existing non-Project register actions horizontal without changing the
 * Project register. The Project module therefore falls back to its native CSS. */
.module-register-workspace:not([data-module="projects"])
  .register-table
  td[data-label="Action"] {
  max-width: none;
}

.module-register-workspace:not([data-module="projects"]) .row-actions {
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  display: flex !important;
  flex-flow: row nowrap !important;
  align-items: center;
  gap: 6px !important;
  padding: 1px 1px 4px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.module-register-workspace:not([data-module="projects"])
  .row-actions
  > .row-action {
  width: auto !important;
  min-width: max-content !important;
  flex: 0 0 auto !important;
  white-space: nowrap !important;
  margin: 0 !important;
}

/* Site Visits / Team Leads and Material / BOQ retain the horizontal controls
 * already approved before this scoped Project restoration. */
.nvx-leadops-table .nvx-leadops-row-actions,
.nvx-material-layer .nvx-row-actions {
  width: 100%;
  min-width: 0 !important;
  display: flex !important;
  flex-flow: row nowrap !important;
  align-items: center;
  gap: 6px !important;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
}

.nvx-leadops-table .nvx-leadops-row-actions > button,
.nvx-material-layer .nvx-row-actions > button {
  min-width: max-content;
  flex: 0 0 auto;
  margin: 0 !important;
  white-space: nowrap;
}

.nvx-material-layer .nvx-row-actions > button {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

@media (min-width: 1101px) {
  .module-register-workspace:not([data-module="projects"])
    .register-table-wrap {
    position: relative;
    isolation: isolate;
  }

  .module-register-workspace:not([data-module="projects"])
    .register-table {
    table-layout: auto !important;
    width: max-content !important;
    min-width: 100% !important;
  }

  .module-register-workspace:not([data-module="projects"])
    .register-table
    th:last-child,
  .module-register-workspace:not([data-module="projects"])
    .register-table
    td[data-label="Action"] {
    position: sticky !important;
    right: 0;
    left: auto;
    width: clamp(520px, 36vw, 660px) !important;
    min-width: clamp(520px, 36vw, 660px) !important;
    max-width: clamp(520px, 36vw, 660px) !important;
    box-shadow: -14px 0 22px -20px rgba(8, 42, 69, 0.7);
  }

  /* The six requested Lead values remain readable alongside compact actions. */
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    th:nth-child(2),
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    td:nth-child(2) {
    min-width: 110px;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    th:nth-child(3),
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    td:nth-child(3) {
    min-width: 155px;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    th:nth-child(4),
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    td:nth-child(4) {
    min-width: 130px;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    th:nth-child(5),
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    td:nth-child(5),
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    th:nth-child(6),
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    td:nth-child(6) {
    min-width: 135px;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    th:nth-child(7),
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"])
    .register-table
    td:nth-child(7) {
    min-width: 120px;
  }

  .module-register-workspace:not([data-module="projects"])
    .register-table
    th:last-child {
    z-index: 8;
    background: #f3f8fb;
  }

  .module-register-workspace:not([data-module="projects"])
    .register-table
    td[data-label="Action"] {
    z-index: 5;
    background: #fff;
  }

  .module-register-workspace:not([data-module="projects"])
    .register-table
    tbody
    tr:nth-child(even)
    td[data-label="Action"] {
    background: #f6fafd;
  }

  .module-register-workspace:not([data-module="projects"])
    .register-table
    tbody
    tr:hover
    td[data-label="Action"] {
    background: #eef8fe;
  }

  .module-register-workspace:not([data-module="projects"])
    .row-actions
    > .row-action {
    min-height: 30px;
    padding: 5px 6px !important;
    font-size: 8.5px !important;
    line-height: 1.1;
  }

  /*
   * The earlier pinned Action column covered Mobile, Project Nature, Assigned
   * To and Assigned Date whenever the persistent sidebar reduced the real
   * table width. Keep every Lead field in a fixed first line and place Actions
   * on a second, permanently visible line. This is CSS-only: no row listener,
   * expansion state, decorator or observer is introduced.
   */
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table-wrap {
    overflow-x: hidden !important;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table,
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table thead,
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table tbody {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table {
    table-layout: auto !important;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table thead tr,
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table tbody tr {
    display: grid !important;
    grid-template-columns:
      44px
      minmax(90px, 0.8fr)
      minmax(145px, 1.35fr)
      minmax(110px, 1fr)
      minmax(110px, 1fr)
      minmax(110px, 1fr)
      minmax(105px, 0.95fr);
    width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
  }

  /* Lost Leads has no bulk-selection checkbox, so its first line contains
   * exactly the six approved information fields. */
  .module-register-workspace[data-module="lost-leads"] .register-table thead tr,
  .module-register-workspace[data-module="lost-leads"] .register-table tbody tr {
    grid-template-columns:
      minmax(90px, 0.8fr)
      minmax(145px, 1.35fr)
      minmax(110px, 1fr)
      minmax(110px, 1fr)
      minmax(110px, 1fr)
      minmax(105px, 0.95fr);
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table thead tr {
    grid-template-rows: 58px;
    min-height: 58px;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table tbody tr {
    grid-template-rows: 56px auto;
    min-height: 0 !important;
    border-bottom: 1px solid #e1ebf2;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table th,
  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table td {
    position: static !important;
    left: auto !important;
    right: auto !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    box-shadow: none !important;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table th {
    display: flex !important;
    align-items: center;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table th:last-child {
    display: none !important;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table tbody td:not([data-label="Action"]) {
    display: flex !important;
    align-items: center;
    height: 56px !important;
    min-height: 56px !important;
    overflow: hidden;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table tbody td .cell-text {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table td[data-label="Action"] {
    grid-column: 1 / -1;
    display: flex !important;
    position: static !important;
    left: auto !important;
    right: auto !important;
    align-items: center;
    gap: 10px;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: 48px !important;
    height: auto !important;
    padding: 8px 10px 9px !important;
    border-top: 1px solid #e6eef4;
    background: #fbfdff !important;
    overflow: hidden;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .register-table td[data-label="Action"]::before {
    content: "Actions";
    flex: 0 0 58px;
    color: #5f7588;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 8px;
    font-weight: 850;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .row-actions {
    flex: 1 1 auto;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .module-register-workspace:is([data-module="leads"], [data-module="followups"], [data-module="lost-leads"]) .row-action {
    transition: none !important;
    box-shadow: none !important;
  }
}

@media (max-width: 1100px) {
  .module-register-workspace:not([data-module="projects"])
    .register-table
    td[data-label="Action"] {
    grid-template-columns: 1fr !important;
    overflow: hidden;
  }

  .module-register-workspace:not([data-module="projects"])
    .register-table
    td[data-label="Action"]::before {
    margin-bottom: 4px;
  }
}
