/* CRM Grid (estructura transversal) */
/* Nota: NO se cambia la paleta. Solo layout/spacing y se reutilizan variables existentes. */

.crm-grid {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow, 0 2px 8px rgba(0,0,0,0.15));
}

/* Layout: header + grid llenan el alto disponible; scroll solo en tableWrap */
.customers-page {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-width: 100%;
  overflow: hidden;
}

.customers-page .crm-pageHeader,
.customers-page .crm-grid {
  margin-left: 8px;
  margin-right: 8px;
}

.customers-page .crm-pageHeader {
  flex: 0 0 auto;
  margin-top: 8px;
  /* Sin scroll de pagina: sticky no aporta; el header queda fijo por flex */
  position: relative;
  top: auto;
  z-index: 30;
}

.customers-page .crm-grid {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  margin-bottom: 8px;
  overflow: hidden; /* scroll interno en .crm-grid__tableWrap */
}

.customers-page .crm-grid__tableWrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto; /* unico scroll vertical/horizontal del listado */
}

.customers-page .crm-pager {
  flex: 0 0 auto;
  position: relative;
  z-index: 3;
  background: var(--color-bg-secondary, #2d3e4f);
}

.crm-pageHeader {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: var(--shadow, 0 2px 8px rgba(0,0,0,0.15));
  margin-bottom: 12px;
}

.crm-pageHeader__toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 18px; /* más espacio entre fila 1 (título) y fila 2 (controles) */
  padding: 14px;
}

.crm-pageHeader__titleRow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.crm-pageHeader__controlsRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.crm-pageHeader__left,
.crm-pageHeader__right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Popover de filtros / paneles en header (compartido Deals, Companies, Contacts) */
.crm-headerPopover {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.crm-headerPopover .crm-headerIconBtn.active {
  border-color: var(--color-accent);
  background: rgba(26,188,156,0.10);
}

.crm-pageHeader__left .btn-outline-primary.crm-headerIconBtn,
.crm-pageHeader__left .btn-outline-secondary.crm-headerIconBtn,
.crm-pageHeader__left .btn-outline-danger.crm-headerIconBtn {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}

.crm-pageHeader__left .btn-outline-primary.crm-headerIconBtn:hover,
.crm-pageHeader__left .btn-outline-secondary.crm-headerIconBtn:hover,
.crm-pageHeader__left .btn-outline-danger.crm-headerIconBtn:hover {
  background: rgba(255,255,255,0.02);
}

.crm-pageHeader__left .crm-headerIconBtn:focus,
.crm-pageHeader__left .crm-headerIconBtn:focus-visible {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(26,188,156,0.18);
}

.crm-pageHeader__left .crm-headerIconBtn:active {
  border-color: var(--color-accent);
  background: rgba(26,188,156,0.10);
}

.crm-pageHeader__right {
  justify-content: flex-end;
}

.crm-pageHeader__toolbar .btn,
.crm-pageHeader__toolbar .form-select,
.crm-pageHeader__toolbar input {
  min-height: 44px;
}

/* Importante: no forzar color global en .btn del header,
   porque en algunos temas/overrides los outline tienen fondo claro. */

.crm-pageHeader__right .crm-headerIconBtn i {
  color: currentColor;
}

.crm-pageHeader__right .btn-outline-secondary.crm-headerIconBtn,
.crm-pageHeader__right .btn-outline-primary.crm-headerIconBtn,
.crm-pageHeader__right .btn-outline-danger.crm-headerIconBtn {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}

.crm-pageHeader__right .btn-outline-secondary.crm-headerIconBtn:hover,
.crm-pageHeader__right .btn-outline-primary.crm-headerIconBtn:hover,
.crm-pageHeader__right .btn-outline-danger.crm-headerIconBtn:hover {
  background: rgba(255,255,255,0.02);
}

.crm-pageHeader__right .btn-outline-primary.crm-headerIconBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Verde SOLO como focus (no permanente) */
.crm-pageHeader__right .crm-headerIconBtn:focus,
.crm-pageHeader__right .crm-headerIconBtn:focus-visible {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(26,188,156,0.18);
}

.crm-pageHeader__right .crm-headerIconBtn:active {
  border-color: var(--color-accent);
  background: rgba(26,188,156,0.10);
}

.crm-pageHeader__toolbar .form-select {
  padding-top: 8px;
  padding-bottom: 8px;
}

.crm-pageHeader__toolbar .crm-grid__search input {
  min-height: 44px;
}

.crm-headerBtn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 10px;
  line-height: 1;
}

.crm-headerIconBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border-radius: 10px;
  line-height: 1;
}

.crm-pageHeader__right .crm-headerIconBtn {
  width: 44px;     /* todos iguales */
  padding: 0;      /* sin variación por padding */
  flex: 0 0 44px;  /* evita que el + se estire */
  box-sizing: border-box;
}

.crm-pageHeader__right .btn.btn-primary.crm-headerIconBtn {
  width: 44px;
  flex: 0 0 44px;
  padding: 0;
}

.crm-headerIconBtn i,
.crm-actionsButton i {
  font-size: 14px;
}

.crm-grid__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
}

.crm-grid__toolbarLeft,
.crm-grid__toolbarRight {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.crm-grid__titleRow {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 220px;
}

.crm-grid__title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
  white-space: nowrap;
}

.crm-grid__subtitleSelect {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-secondary);
  font-weight: 600;
}

.crm-grid__search {
  position: relative;
  min-width: 260px;
  flex: 1 1 260px;
}

.crm-grid__search input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-bg-secondary);
  color: var(--color-text);
  min-height: 40px;
}

.crm-grid__search.no-icon input {
  padding-left: 12px; /* sin lupa */
}

.crm-grid__searchIcon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-secondary);
}

.crm-grid__tableWrap {
  overflow-x: auto;
  overflow-y: visible; /* para que el menú de acciones no quede recortado */
  -webkit-overflow-scrolling: touch;
}

.crm-grid__emptyState {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  padding: 32px 20px;
  text-align: center;
  color: var(--color-text);
}

.crm-grid__emptyState p {
  margin: 0;
  color: #ffffff;
  background: rgba(45,62,79,0.96);
  border: 1px solid rgba(26,188,156,0.45);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.24);
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}

.crm-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px; /* desktop/tablet; en <=768 se anula */
}

.crm-table thead th {
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  padding: 10px 10px;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

/* Header de tabla fijo: el scroll debe ocurrir en el contenedor (ej. .crm-grid__tableWrap con overflow) */
.crm-grid__tableWrap .crm-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--color-bg-secondary);
}

.crm-table tbody td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  vertical-align: middle;
}

.crm-table tbody tr:hover {
  background: rgba(255,255,255,0.02);
}

.crm-cellPrimary {
  font-weight: 700;
  line-height: 1.2;
}

/* Name clickable: underline como ayuda visual (alineado a Prospectos) */
.customers-page .crm-name-link {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  color: var(--color-text, #fff);
  font: inherit;
  font-weight: 700;
  text-align: left;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.customers-page .crm-name-link:hover,
.customers-page .crm-name-link:focus-visible {
  color: var(--color-accent, #1abc9c);
  outline: none;
}

.crm-cellSecondary {
  margin-top: 2px;
  font-size: 12px;
  color: var(--color-text-secondary);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.crm-statusDot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(26,188,156,0.12);
  flex: 0 0 auto;
}

.crm-actionsCell {
  width: 72px;
  text-align: right;
}

.crm-actionsButton {
  min-height: 36px;
  min-width: 36px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text);
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.crm-actionsEllipsis {
  font-weight: 900;
  letter-spacing: 2px;
  transform: translateY(-1px);
  user-select: none;
}

.crm-actionsButton:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(26,188,156,0.15);
}

/* Row actions menu */
.crm-actionsMenu-backdrop {
  display: none;
}

.crm-actionsMenuWrap {
  position: relative;
  display: inline-flex;
  justify-content: flex-end;
}

.crm-actionsMenu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: var(--shadow, 0 10px 30px rgba(0,0,0,0.25));
  padding: 6px;
  z-index: 20;
}

.crm-actionsMenu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-text);
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
}

.crm-actionsMenu button:hover {
  background: rgba(26,188,156,0.12);
  border-color: rgba(26,188,156,0.25);
}

.crm-actionsMenu button:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(26,188,156,0.15);
}

/* Responsive (canon: 768) */
@media (max-width: 768px) {
  .customers-page .crm-pageHeader,
  .customers-page .crm-grid {
    margin-left: 6px;
    margin-right: 6px;
  }

  .crm-pageHeader__toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .crm-pageHeader__right {
    justify-content: flex-start;
  }

  .crm-pageHeader__controlsRow {
    flex-direction: column;
    align-items: stretch;
  }

  .crm-grid__toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .crm-grid__titleRow {
    min-width: 0;
  }

  .crm-grid__search {
    min-width: 0;
    width: 100%;
  }

  .crm-table {
    min-width: 0;
    width: 100%;
  }

  .crm-table .crm-col--secondary {
    display: none !important;
  }

  /* Evita que la unica fila llene todo el alto del tableWrap (bloque oscuro vacio) */
  .crm-table.crm-table--stacked {
    display: block;
    width: 100%;
    height: auto !important;
    min-height: 0 !important;
  }

  .crm-table--stacked thead {
    display: none;
  }

  .crm-table--stacked tbody {
    display: block;
    width: 100%;
    height: auto !important;
  }

  .crm-table--stacked tbody tr {
    display: block;
    width: 100%;
    height: auto !important;
    margin: 0 0 12px;
    padding: 10px 12px;
    border: 1px solid var(--color-border, #34495e);
    border-radius: 8px;
    background: #243445;
  }

  .crm-table--stacked tbody tr:hover {
    background: rgba(26, 188, 156, 0.08);
  }

  .crm-table--stacked tbody td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(52, 73, 94, 0.5);
    white-space: normal;
    height: auto !important;
  }

  .crm-table--stacked tbody td:last-child {
    border-bottom: none;
  }

  .crm-table--stacked tbody td.crm-actionsCell {
    display: block;
  }

  .crm-table--stacked tbody td[data-col]::before {
    content: attr(data-col-label);
    flex: 0 0 40%;
    max-width: 40%;
    color: var(--color-text-secondary, #95a5a6);
    font-size: 0.75rem;
    font-weight: 600;
  }

  .crm-table--stacked .crm-actionsMenuWrap {
    display: flex;
    justify-content: flex-end;
    width: 100%;
  }

  .crm-table--stacked .crm-actionsButton {
    min-width: 44px;
    min-height: 44px;
  }

  /* Backdrop + hoja fija (escapa overflow del grid/pager) */
  .crm-actionsMenu-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1190;
    margin: 0;
    padding: 0;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
  }

  .crm-table--stacked .crm-actionsMenu {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    top: auto;
    width: auto;
    min-width: 0;
    max-width: none;
    max-height: 50vh;
    overflow-y: auto;
    margin: 0;
    z-index: 1200;
    background: #2d3e4f;
    border: 1px solid var(--color-border, #34495e);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
    color: #ffffff;
    padding: 8px;
  }

  .crm-table--stacked .crm-actionsMenu button {
    display: flex;
    width: 100%;
    color: #ffffff;
    min-height: 44px;
    opacity: 1;
  }

  .customers-page .crm-pager {
    z-index: 3;
    background: #2d3e4f;
  }
}

@media (min-width: 769px) {
  .crm-actionsMenu-backdrop {
    display: none !important;
  }
}

/* Pager (estructura tipo screenshot) */
.crm-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-top: 1px solid var(--color-border);
  background: rgba(255,255,255,0.02);
}

.crm-pager__left {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.crm-pager__right {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.crm-pager__size,
.crm-pager__page,
.crm-pager__nav {
  min-height: 40px;
  min-width: 40px;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text);
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}

.crm-pager__nav {
  border-radius: 10px;
  min-width: 44px;
}

.crm-pager__size.is-active,
.crm-pager__page.is-active {
  background: rgba(26,188,156,0.12);
  border-color: var(--color-accent);
}

.crm-pager__ellipsis {
  color: var(--color-text-secondary);
  padding: 0 6px;
  font-weight: 700;
}

.crm-pager__size:focus,
.crm-pager__page:focus,
.crm-pager__nav:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(26,188,156,0.15);
}

.crm-pager__nav:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Toolbar Exportador / Personalizar columnas (paridad Reportes) */
.crm-grid__tableActions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 12px 0;
}

.crm-grid__toolbarButton {
  min-height: 32px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--color-border, #34495e);
  background: transparent;
  color: var(--color-text, #ffffff);
  font-size: 0.9rem;
  cursor: pointer;
}

.crm-grid__toolbarButton:hover,
.crm-grid__toolbarButton:focus-visible {
  border-color: var(--color-accent, #1abc9c);
  color: var(--color-accent, #1abc9c);
  outline: none;
}

.crm-grid__iconOnlyTable {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--color-border, #34495e);
  background: transparent;
  color: var(--color-text, #ffffff);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.crm-grid__iconOnlyTable:hover,
.crm-grid__iconOnlyTable:focus-visible {
  border-color: var(--color-accent, #1abc9c);
  color: var(--color-accent, #1abc9c);
  outline: none;
}

.crm-grid__iconOnlyTable .crm-actionsEllipsis {
  line-height: 1;
  font-weight: 700;
  letter-spacing: 0.05em;
}

@media (max-width: 768px) {
  .crm-pager {
    flex-direction: column;
    align-items: stretch;
  }

  .crm-pager__left {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }

  .crm-pager__right {
    justify-content: flex-start;
  }
}

