/* ============================================
	 Clientes Page
	 ============================================ */

.clientes-page {
	padding: var(--space-6);
	max-width: 1400px;
	margin: 0 auto;
}

@media (min-width: 1600px) {
	.clientes-page { max-width: 1600px; }
	.clientes-header h1 { font-size: 1.5rem; }
}

@media (min-width: 2200px) {
	.clientes-page { max-width: 2000px; }
}

.clientes-header {
	margin-bottom: var(--space-5);
}

.clientes-header h1 {
	font-size: 1.25rem;
	font-weight: 600;
}

.clientes-filters {
	display: flex;
	gap: var(--space-3);
	margin-bottom: var(--space-4);
	align-items: center;
}

.clientes-filters .search-input {
	flex: 1;
	max-width: 400px;
}

.clientes-filters .search-wrapper {
	flex: 1;
	max-width: 400px;
}

.client-avatar-col {
	width: 48px;
}

.client-avatar-cell {
	width: 48px;
}

.client-avatar {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	color: white;
	font-weight: 500;
	font-size: 12px;
}

.client-name-wrapper {
	display: flex;
	flex-direction: column;
	gap: 1px;
}

.client-company-name {
	font-weight: 500;
	color: var(--text-primary);
}

.client-code {
	font-size: 11px;
	color: var(--text-secondary);
	font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}

.contact-info {
	display: flex;
	flex-direction: column;
	gap: 1px;
}

.contact-name {
	color: var(--text-primary);
}

.contacts-count {
	font-size: 11px;
	color: var(--primary);
	background: var(--blue-50);
	padding: 1px var(--space-2);
	border-radius: var(--radius-sm);
	display: inline-block;
	width: fit-content;
	font-weight: 500;
}

.client-email .email-text {
	color: var(--text-secondary);
	max-width: 200px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	display: inline-block;
	font-size: 13px;
}

.client-phone {
	color: var(--text-primary);
	font-variant-numeric: tabular-nums;
	font-size: 13px;
}

.client-type {
	color: var(--text-primary);
	font-size: 13px;
}

.client-actions {
	text-align: center;
}

.clients-table .client-actions-col {
	width: 60px;
	text-align: center;
}

.clients-table td.client-actions {
	text-align: center;
	vertical-align: middle;
}

.clients-table td.client-actions .btn-view {
	margin: 0 auto;
	color: var(--primary);
	background: transparent;
	border: none;
}

.clients-table td.client-actions .btn-view:hover {
	color: var(--primary-hover);
	background: var(--primary-light);
}

.status-badge-client {
	display: inline-flex;
	align-items: center;
	padding: 2px var(--space-2);
	border-radius: var(--radius-sm);
	font-size: 12px;
	font-weight: 500;
	white-space: nowrap;
}

.status-badge-client.status-active {
	background: var(--green-50);
	color: var(--green-600);
}

.status-badge-client.status-inactive {
	background: var(--red-50);
	color: var(--red-600);
}

.status-badge-client.status-unknown {
	background: var(--gray-100);
	color: var(--gray-500);
}

.btn-contacts {
	position: relative;
	background: var(--blue-50);
	border: 1px solid rgba(59, 130, 246, 0.15);
	color: var(--primary);
	border-radius: var(--radius-sm);
	padding: 2px var(--space-2);
	cursor: pointer;
	transition: background-color var(--transition-fast);
	display: flex;
	align-items: center;
	gap: 2px;
	font-size: 12px;
}

.btn-contacts:hover {
	background: var(--blue-100);
}

.btn-contacts.active {
	background: var(--primary);
	color: white;
	border-color: var(--primary);
}

.contacts-badge {
	font-size: 11px;
	font-weight: 600;
	min-width: 14px;
	text-align: center;
}

.contacts-expand-row td {
	padding: 0 !important;
	background: var(--gray-50);
}

.contacts-expand-content {
	padding: var(--space-3) var(--space-4);
	border-top: 1px solid var(--border-color);
	border-bottom: 2px solid var(--primary);
}

.contacts-expand-header h4 {
	margin: 0 0 var(--space-3) 0;
	font-size: 12px;
	color: var(--text-secondary);
	text-transform: uppercase;
	letter-spacing: 0.04em;
	font-weight: 500;
}

.contacts-expand-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	gap: var(--space-2);
}

.contact-expand-card {
	background: white;
	border: 1px solid var(--border-color);
	border-radius: var(--radius-md);
	padding: var(--space-3);
}

.contact-expand-name {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	font-weight: 500;
	color: var(--text-primary);
	margin-bottom: var(--space-2);
	font-size: 14px;
}

.contact-expand-name svg {
	color: var(--primary);
	flex-shrink: 0;
}

.contact-expand-details {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 2px var(--space-3);
	font-size: 12px;
	color: var(--text-secondary);
}

.contact-expand-details span {
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

/* Client Modal */
.client-modal-overlay {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.4);
	display: flex;
	align-items: center;
	justify-content: center;
	z-index: 1000;
	padding: var(--space-4);
}

.client-modal {
	background: var(--card-bg);
	border-radius: var(--radius-lg);
	width: 100%;
	max-width: 560px;
	max-height: 80vh;
	overflow: hidden;
	display: flex;
	flex-direction: column;
	box-shadow: var(--shadow-lg);
}

.client-modal-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: var(--space-4) var(--space-5);
	border-bottom: 1px solid var(--border-color);
}

.client-modal-header h2 {
	margin: 0;
	font-size: 1.125rem;
	font-weight: 600;
}

.btn-close-modal {
	background: transparent;
	border: none;
	font-size: 18px;
	cursor: pointer;
	color: var(--text-secondary);
	padding: var(--space-1);
	border-radius: var(--radius-sm);
	transition: color var(--transition-fast), background-color var(--transition-fast);
	width: 28px;
	height: 28px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.btn-close-modal:hover {
	background: var(--gray-100);
	color: var(--text-primary);
}

.client-modal-body {
	padding: var(--space-5);
	overflow-y: auto;
}

.client-info-section,
.contacts-section {
	margin-bottom: var(--space-5);
}

.client-info-section:last-child,
.contacts-section:last-child {
	margin-bottom: 0;
}

.client-info-section h3,
.contacts-section h3 {
	margin: 0 0 var(--space-3) 0;
	font-size: 12px;
	color: var(--text-secondary);
	text-transform: uppercase;
	letter-spacing: 0.04em;
	font-weight: 500;
}

.info-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: var(--space-3);
}

.info-item {
	display: flex;
	flex-direction: column;
	gap: 1px;
}

.info-label {
	font-size: 11px;
	color: var(--text-secondary);
	text-transform: uppercase;
	letter-spacing: 0.04em;
	font-weight: 500;
}

.info-value {
	font-weight: 500;
	color: var(--text-primary);
	font-size: 14px;
}

.contacts-list {
	display: flex;
	flex-direction: column;
	gap: var(--space-3);
}

.contact-card {
	background: var(--card-bg);
	border-radius: var(--radius-md);
	padding: var(--space-4);
	border: 1px solid var(--border-color);
}

.contact-header {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	margin-bottom: var(--space-3);
	padding-bottom: var(--space-3);
	border-bottom: 1px solid var(--border-color);
}

.contact-avatar {
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: var(--gray-100);
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--text-secondary);
	flex-shrink: 0;
}

.contact-full-name {
	font-weight: 600;
	color: var(--text-primary);
	font-size: 13px;
}

.contact-details {
	display: flex;
	flex-direction: column;
	gap: var(--space-2);
}

.contact-row {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	font-size: 13px;
	color: var(--text-secondary);
}

.contact-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--gray-400);
	flex-shrink: 0;
	width: 16px;
}

.no-contacts {
	color: var(--text-secondary);
	text-align: center;
	padding: var(--space-5);
	background: var(--gray-50);
	border-radius: var(--radius-md);
	font-size: 13px;
}

@media (max-width: 768px) {
	.clientes-filters {
		flex-direction: column;
	}

	.clients-table thead {
		display: none;
	}

	.clients-table tbody tr.client-item {
		display: flex;
		flex-wrap: wrap;
		padding: var(--space-3);
		gap: var(--space-2);
		position: relative;
	}

	.clients-table tbody tr.contacts-expand-row {
		display: block;
	}

	.clients-table td {
		padding: 0;
	}

	.client-avatar-cell {
		width: auto;
		margin-right: var(--space-3);
	}

	.client-name {
		flex: 1;
	}

	.client-type-col,
	.client-type {
		display: none;
	}

	.client-actions {
		position: absolute;
		right: var(--space-3);
		top: 50%;
		transform: translateY(-50%);
	}

	.contacts-expand-grid {
		grid-template-columns: 1fr;
	}

	.info-grid {
		grid-template-columns: 1fr;
	}
}

@media (max-width: 1024px) {
	.clientes-page {
		padding: var(--space-4);
	}

	.clients-table th,
	.clients-table td {
		padding: var(--space-2) var(--space-3);
	}

	.client-email-col,
	.client-email,
	.client-type-col,
	.client-type {
		display: none;
	}
}

:root[data-theme='dark'] .contact-expand-card {
	background: #0f172a;
	border-color: #1e2f4d;
}

:root[data-theme='dark'] .contacts-expand-row td,
:root[data-theme='dark'] .no-contacts {
	background: rgba(15, 23, 42, 0.9);
}

/* ── Botón nuevo cliente ── */
.btn-new-client {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-new-client:hover {
  background: var(--primary-hover);
}

/* ── Modal crear cliente ── */
.create-client-modal {
  max-width: 620px;
  max-height: 90vh;
}

.create-client-section {
  margin-bottom: var(--space-5);
}

.create-client-section:last-child {
  margin-bottom: 0;
}

.create-client-section h3 {
  margin: 0 0 var(--space-3) 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.create-client-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-field--full {
  grid-column: 1 / -1;
}

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-required {
  color: var(--danger);
}

.form-input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

.form-textarea {
  resize: vertical;
  min-height: 60px;
}

.form-error {
  font-size: 11px;
  color: var(--danger);
  min-height: 14px;
}

.create-client-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-color);
  background: var(--bg-subtle);
}

.btn-cancel-create {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

.btn-cancel-create:hover {
  border-color: var(--gray-400);
  color: var(--text-primary);
  background: transparent;
}

.btn-submit-create {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-5);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  min-width: 120px;
  justify-content: center;
}

.btn-submit-create:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-submit-create:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* dark mode — create client modal */
:root[data-theme='dark'] .form-input {
  background: #0b1220;
  border-color: #1e2f4d;
  color: var(--text-primary);
}

:root[data-theme='dark'] .form-input:focus {
  border-color: var(--primary);
}

:root[data-theme='dark'] .create-client-footer {
  background: rgba(15, 23, 42, 0.8);
  border-color: #1e2f4d;
}

@media (max-width: 580px) {
  .create-client-grid {
    grid-template-columns: 1fr;
  }
  .form-field--full {
    grid-column: unset;
  }
}
