/* CRM / customers pages — mobile card list */

.customer-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  background: var(--neutral-0);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: background 0.15s ease, border-color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.customer-card:active {
  background: var(--color-surface-3);
  border-color: var(--brand-green);
}

.customer-card-select {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

.customer-card-select .crm-select-customer {
  width: 1.15rem;
  height: 1.15rem;
  margin: 0;
  cursor: pointer;
}

.customer-card-body {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}

.customer-card.crm-row-selected {
  background: rgba(var(--brand-green-rgb), 0.07);
  border-color: var(--brand-green);
}

.customer-card-name {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-ink);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.customer-card-detail {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.customer-card-detail i {
  width: 18px;
  text-align: center;
  margin-right: 6px;
  color: var(--color-text-faint);
}

.customer-card-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}


.customer-card-action-label {
  display: none;
}

@media (max-width: 768px) {
  .customer-card {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "select body actions"
      ".      revenue actions"
      "history history history";
    align-items: start;
    gap: 8px 10px;
  }

  .customer-card-select {
    grid-area: select;
    align-self: start;
    padding-top: 2px;
  }

  .customer-card-body {
    grid-area: body;
    flex: none;
    min-width: 0;
  }

  .customer-card .crm-cliente-revenue {
    grid-area: revenue;
    align-self: center;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .customer-card-actions {
    grid-area: actions;
    flex-direction: column;
    gap: 6px;
    align-self: start;
  }

  .customer-card .crm-sales-history-panel {
    grid-area: history;
    flex: none;
    order: unset;
    width: 100%;
    margin: 0;
  }

  .customer-card-name {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
  }

  .customer-card-body .customer-card-detail {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .customer-card-actions .btn {
    min-width: 40px;
    min-height: 40px;
    width: 40px;
    height: 40px;
    padding: 0;
    font-size: var(--font-size-sm);
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    border-width: 0;
    box-shadow: var(--shadow-xs);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: transparent;
  }

  .customer-card-actions .btn:active {
    transform: scale(0.96);
    box-shadow: var(--shadow-xs);
  }

  .customer-card-actions .crm-record-sale {
    background: rgba(var(--rgb-info), 0.12);
    color: var(--color-info);
  }

  .customer-card-actions .crm-record-sale:active {
    background: rgba(var(--rgb-info), 0.2);
  }

  .customer-card-actions .crm-edit-customer {
    background: var(--neutral-100);
    color: var(--neutral-600);
  }

  .customer-card-actions .crm-edit-customer:active {
    background: var(--neutral-200);
  }

  .customer-card-actions .crm-delete-customer {
    background: rgba(var(--rgb-danger), 0.1);
    color: var(--color-danger-bright);
  }

  .customer-card-actions .crm-delete-customer:active {
    background: rgba(var(--rgb-danger), 0.18);
  }

  .customer-card-actions .crm-record-sale .bi,
  .customer-card-actions .crm-edit-customer .bi,
  .customer-card-actions .crm-delete-customer .bi {
    font-size: var(--font-size-base);
    line-height: 1;
  }

  .customer-card-action-label {
    display: none;
  }
}

/* Search */
.customers-search-group {
  max-width: 400px;
}

/* Add-customer modal */
#addCustomerModal .modal-content {
  border-radius: var(--radius-lg);
  border: none;
  box-shadow: var(--shadow-modal);
  animation: modalFadeIn 0.3s ease-out;
}

#addCustomerModal .modal-header {
  background: linear-gradient(135deg, rgba(var(--brand-green-rgb), 0.08), rgba(var(--brand-green-rgb), 0.02));
  border-bottom: 2px solid rgba(var(--brand-green-rgb), 0.15);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.5rem 2rem;
}

#addCustomerModal .modal-title {
  font-weight: 700;
  color: var(--color-ink);
  font-size: var(--font-size-2xl);
}

#addCustomerModal .modal-title .bi {
  color: var(--brand-green);
}

#addCustomerModal .btn-close {
  font-size: var(--font-size-xl);
}

#addCustomerModal .modal-body {
  padding: 2rem;
}

#addCustomerModal .form-label {
  font-weight: 600;
  color: var(--color-ink);
  margin-bottom: 0.5rem;
}

#addCustomerModal .customer-modal-field,
#addCustomerModal .form-control,
#addCustomerModal .form-select {
  border: 1.5px solid var(--color-border);
  transition: all 0.2s ease;
}

#addCustomerModal textarea.form-control {
  resize: vertical;
}

#addCustomerModal .form-select.customer-modal-prefix {
  max-width: 140px;
}


#addCustomerModal .form-control:focus,
#addCustomerModal .form-select:focus {
  border-color: var(--brand-green);
  box-shadow: var(--focus-ring);
  outline: none;
}

#addCustomerModal .modal-footer {
  border-top: 1px solid var(--color-border);
  padding: 1.5rem 2rem;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

#addCustomerModal .modal-footer .btn {
  font-weight: 600;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Sales history (J4) */
.crm-cliente-revenue {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.crm-cliente-revenue .crm-revenue-chevron {
  font-size: var(--font-size-xs);
  opacity: 0.55;
  margin-left: 0.2rem;
  transition: transform 0.15s ease;
}

.crm-cliente-revenue.is-expanded .crm-revenue-chevron {
  transform: rotate(180deg);
}

.crm-sales-history-row > td {
  background: var(--neutral-50);
  border-bottom: 1px solid var(--neutral-200);
}

.crm-sales-history-panel {
  width: 100%;
}

.crm-sales-history-scroll {
  max-height: 12.5rem; /* ~5 rows */
  overflow-y: auto;
}

.crm-sales-history-table {
  font-size: var(--font-size-caption);
}

.crm-sales-history-table th {
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--neutral-500);
  border-bottom-width: 1px;
  position: sticky;
  top: 0;
  background: var(--neutral-50);
  z-index: 1;
}

.crm-sales-history-table--compact td {
  white-space: nowrap;
}

.crm-sales-history-table--compact .crm-sale-delete-btn {
  flex-shrink: 0;
}

.crm-sale-history-item {
  cursor: pointer;
}

.crm-sale-history-item:hover {
  background: rgba(var(--brand-green-rgb), 0.06);
}

.customer-card .crm-sales-history-panel {
  flex: 1 1 100%;
  order: 10;
  width: 100%;
  margin: 0.15rem 0 0;
  padding: 0.5rem 0.65rem;
  background: var(--neutral-50);
  border-radius: var(--radius-sm);
  border: 1px solid var(--neutral-200);
}

.customer-card .crm-sales-history-panel[hidden],
.customer-card .crm-sales-history-panel.d-none {
  display: none !important;
}

/* Bulk-selection action bar (CRM Clienti multi-select) */
.crm-bulk-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.55rem 0.9rem;
  margin-bottom: 0.85rem;
  background: rgba(var(--brand-green-rgb), 0.08);
  border: 1px solid var(--brand-green);
  border-radius: var(--radius-sm);
  animation: crmBulkBarIn 0.15s ease-out;
}

@keyframes crmBulkBarIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.crm-bulk-actions-bar__count {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: var(--color-ink);
}

.crm-bulk-actions-bar__count i {
  color: var(--brand-green);
}

.crm-bulk-actions-bar__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.crm-bulk-actions-bar .crm-bulk-clear {
  color: var(--color-text-muted);
  text-decoration: none;
  padding: 0.25rem 0.4rem;
}

.crm-bulk-actions-bar .crm-bulk-clear:hover {
  color: var(--color-ink);
}

@media (max-width: 768px) {
  .crm-bulk-actions-bar {
    position: sticky;
    top: 0;
    z-index: 5;
  }
}

/* Sale modal — match add-customer / calendar modal polish */
#recordSaleModal .modal-content {
  border-radius: var(--radius-lg);
  border: none;
  box-shadow: var(--shadow-modal);
}

#recordSaleModal .modal-header {
  background: linear-gradient(135deg, rgba(var(--brand-green-rgb), 0.08), rgba(var(--brand-green-rgb), 0.02));
  border-bottom: 2px solid rgba(var(--brand-green-rgb), 0.15);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 1.25rem 1.5rem;
}

#recordSaleModal .modal-title {
  font-weight: 700;
  color: var(--color-ink);
  font-size: var(--font-size-lg);
}

#recordSaleModal .modal-title .bi {
  color: var(--brand-green);
}

#recordSaleModal .modal-footer {
  border-top: 1px solid var(--color-border);
  padding: 1rem 1.25rem;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  gap: 0.5rem;
}

#recordSaleModal .modal-footer .btn {
  font-weight: 600;
}

#recordSaleModal .modal-footer .btn-outline-secondary {
  background: var(--neutral-100);
  border: 1.5px solid var(--neutral-200);
  color: var(--neutral-600);
}

#recordSaleModal .modal-footer .btn-outline-secondary:hover,
#recordSaleModal .modal-footer .btn-outline-secondary:active {
  background: var(--neutral-200);
  border-color: var(--neutral-300);
  color: var(--neutral-700);
}

#recordSaleModal .modal-footer .btn-outline-danger {
  background: rgba(var(--rgb-danger), 0.08);
  border: 1.5px solid rgba(var(--rgb-danger), 0.25);
  color: var(--color-danger-bright);
}

#recordSaleModal .modal-footer .btn-outline-danger:hover,
#recordSaleModal .modal-footer .btn-outline-danger:active {
  background: rgba(var(--rgb-danger), 0.15);
  border-color: rgba(var(--rgb-danger), 0.35);
  color: var(--color-danger-ink-deep);
}

#recordSaleModal .modal-footer .btn-success {
  background: linear-gradient(135deg, var(--brand-action), var(--brand-action-hover));
  border: none;
  color: var(--neutral-0);
  box-shadow: var(--shadow-brand);
}

#recordSaleModal .modal-footer .btn-success:hover,
#recordSaleModal .modal-footer .btn-success:active {
  background: linear-gradient(135deg, var(--brand-action-hover), var(--brand-green-strong));
  color: var(--neutral-0);
  box-shadow: var(--shadow-brand);
}

@media (max-width: 768px) {
  #recordSaleModal .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--color-surface);
    z-index: 10;
    padding: 0.75rem 1rem calc(env(safe-area-inset-bottom, 0px) + 0.75rem);
    box-shadow: var(--shadow-card);
  }
}


/* ── Clienti: one-line client cell, service chips, actions menu, empty state ── */

.crm-cliente-cell {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.crm-avatar {
  flex: 0 0 2rem;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-round);
  font-size: var(--font-size-xs);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--brand-green-ink);
  background: rgba(var(--brand-green-rgb), 0.12);
}

.crm-cliente-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.crm-cliente-name {
  display: block;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  text-align: left;
  color: var(--color-ink);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-cliente-name:hover {
  color: var(--brand-green-strong);
}

.crm-cliente-name:focus-visible {
  outline: 2px solid var(--brand-green);
  outline-offset: 2px;
  border-radius: var(--radius-2xs);
}

.crm-cliente-sub {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-visit-date {
  display: block;
  color: var(--color-ink);
}

.crm-visit-rel {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.crm-cell-empty {
  color: var(--color-text-faint);
}

.crm-revenue-amount--has {
  color: var(--brand-green-strong);
  font-weight: 600;
}

.crm-td-money {
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.crm-td-money .crm-revenue-chevron {
  margin-left: 0.3rem;
  opacity: 0.45;
}

.crm-svc-chips {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
}

.crm-svc-chip {
  display: inline-block;
  max-width: 9rem;
  padding: 0.1rem 0.55rem;
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-pill);
  background: var(--neutral-100);
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--neutral-700);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-svc-chip--more {
  flex: 0 0 auto;
  background: transparent;
  color: var(--neutral-500);
}

.crm-action-sale,
.crm-action-more {
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

.crm-action-sale {
  color: var(--brand-green-ink);
  background: rgba(var(--brand-green-rgb), 0.1);
  border: 1px solid rgba(var(--brand-green-rgb), 0.25);
}

.crm-action-sale:hover,
.crm-action-sale:focus-visible {
  color: var(--neutral-0);
  background: var(--brand-green);
  border-color: var(--brand-green);
}

.crm-action-more {
  color: var(--neutral-500);
  background: transparent;
  border: 1px solid transparent;
}

.crm-action-more:hover,
.crm-action-more:focus-visible,
.crm-action-more.show {
  color: var(--color-ink);
  background: var(--neutral-100);
  border-color: var(--color-border);
}

.crm-action-menu {
  min-width: 10rem;
  padding: 0.35rem;
  border-radius: var(--radius-md);
}

.crm-action-menu .dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
}

.crm-action-menu .dropdown-item i {
  width: 1rem;
  text-align: center;
  color: var(--color-text-faint);
}

.crm-action-menu .crm-action-danger,
.crm-action-menu .crm-action-danger i {
  color: var(--color-danger-bootstrap);
}

.crm-clienti-table-card .admin-stats-table tbody td.crm-empty-cell {
  padding: 0;
}

.crm-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2rem 1rem;
  text-align: center;
  white-space: normal;
  color: var(--color-text-muted);
}

.crm-empty i {
  font-size: var(--font-size-2xl);
  color: var(--color-text-faint);
}

.crm-empty p {
  margin: 0;
}

/* Mobile cards: same content as the desktop row. */
.customer-card-tools {
  flex-shrink: 0;
}

.customer-card-services {
  margin-top: 6px;
}

.customer-card .crm-svc-chips {
  flex-wrap: wrap;
}

.customer-card .crm-visit-rel {
  display: inline;
}

@media (max-width: 768px) {
  .customer-card-tools {
    grid-area: actions;
    align-self: start;
  }

  .customer-card-tools .crm-clienti-actions {
    flex-direction: column;
    gap: 6px;
  }

  .customer-card-tools .crm-action-sale,
  .customer-card-tools .crm-action-more {
    width: 40px;
    height: 40px;
  }

  .customer-card-tools .crm-action-more {
    border-color: var(--color-border);
  }

  .customer-card-tools .crm-action-menu .dropdown-item {
    min-height: 40px;
  }
}
