/* ============================================
	 Facturas + Tablas + Paginacion
	 ============================================ */

/* ── Checkbox column ── */
.invoice-select-col {
	width: 36px;
	padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4) !important;
	text-align: center;
}

.invoice-check,
.invoice-check-all {
	width: 15px;
	height: 15px;
	cursor: pointer;
	accent-color: var(--primary);
}

/* ── Bulk action bar ── */
.bulk-action-bar {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	padding: var(--space-2) var(--space-4);
	background: var(--blue-600);
	color: white;
	border-radius: var(--radius-lg);
	margin-bottom: var(--space-3);
	animation: slideDown 0.15s ease;
}

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

.bulk-count {
	font-size: 13px;
	font-weight: 600;
	white-space: nowrap;
}

.bulk-actions {
	display: flex;
	gap: var(--space-2);
	margin-left: auto;
	align-items: center;
}

.btn-bulk {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 12px;
	border-radius: var(--radius-md);
	border: 1px solid rgba(255,255,255,0.3);
	background: rgba(255,255,255,0.12);
	color: white;
	font-size: 13px;
	font-weight: 500;
	font-family: inherit;
	cursor: pointer;
	transition: background 0.15s;
}

.btn-bulk:hover { background: rgba(255,255,255,0.22); }

.btn-bulk-delete { border-color: rgba(248,113,113,0.5); }
.btn-bulk-delete:hover { background: rgba(239,68,68,0.25); }

.btn-bulk-cancel {
	background: transparent;
	border-color: rgba(255,255,255,0.2);
	font-size: 12px;
}
.btn-bulk-cancel:hover { background: rgba(255,255,255,0.1); }

:root[data-theme='dark'] .bulk-action-bar {
	background: #1d4ed8;
}

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

.facturas-header { margin-bottom: var(--space-5); }
.facturas-header h1 { font-size: 1.25rem; font-weight: 600; }

/* ── Quarterly toggle button ── */
.btn-quarterly {
	display: inline-flex;
	align-items: center;
	gap: var(--space-1);
	padding: var(--space-2) var(--space-3);
	background: var(--card-bg) !important;
	color: var(--text-secondary) !important;
	border: 1px solid var(--border-color) !important;
	border-radius: var(--radius-md);
	cursor: pointer;
	font-size: 13px;
	font-weight: 500;
	font-family: inherit;
	height: 36px;
	transition: all 0.2s ease;
	white-space: nowrap;
}

.btn-quarterly:hover {
	background: var(--gray-50) !important;
	color: var(--text-primary) !important;
	border-color: var(--gray-300) !important;
}

.btn-quarterly--active {
	background: var(--blue-600) !important;
	color: white !important;
	border-color: var(--blue-600) !important;
}

.btn-quarterly--active:hover {
	background: var(--blue-700) !important;
	border-color: var(--blue-700) !important;
}

:root[data-theme='dark'] .btn-quarterly {
	background: #081226 !important;
	border-color: #1e2f4d !important;
	color: var(--text-secondary) !important;
}

:root[data-theme='dark'] .btn-quarterly:hover {
	background: rgba(30,58,110,0.3) !important;
	color: var(--text-primary) !important;
}

/* ── Quarterly summary view ── */
.quarterly-view {
	margin-bottom: var(--space-4);
}

.quarterly-year-block {
	background: var(--card-bg);
	border: 1px solid var(--border-color);
	border-radius: var(--radius-lg);
	overflow: hidden;
	margin-bottom: var(--space-4);
	box-shadow: var(--shadow-xs);
}

.quarterly-year-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: var(--space-3) var(--space-5);
	background: var(--gray-50);
	border-bottom: 1px solid var(--border-color);
}

.quarterly-year-label {
	font-size: 14px;
	font-weight: 700;
	color: var(--text-primary);
}

.quarterly-year-total {
	font-size: 12px;
	color: var(--text-secondary);
	font-variant-numeric: tabular-nums;
}

.quarterly-table {
	width: 100%;
	border-collapse: collapse;
}

.quarterly-table th {
	padding: var(--space-2) var(--space-4);
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	color: var(--text-secondary);
	text-align: right;
	background: var(--gray-50);
	border-bottom: 1px solid var(--border-color);
}

.quarterly-table th:first-child { text-align: left; }

.quarterly-table td {
	padding: var(--space-3) var(--space-4);
	font-size: 13px;
	border-bottom: 1px solid var(--border-color);
	text-align: right;
	font-variant-numeric: tabular-nums;
}

.quarterly-table tbody tr:last-child td { border-bottom: none; }
.quarterly-table tbody tr:hover { background: var(--gray-50); }

.quarterly-q-label {
	text-align: left !important;
	font-weight: 600;
	color: var(--text-primary);
}

.quarterly-q-label span {
	font-weight: 400;
	color: var(--text-secondary);
	font-size: 12px;
}

.quarterly-count      { color: var(--text-secondary); }
.quarterly-num        { color: var(--text-primary); }
.quarterly-tax        { color: var(--text-secondary); }
.quarterly-total--pos { color: var(--primary);  font-weight: 600; }
.quarterly-paid       { color: var(--success);  font-weight: 500; }
.quarterly-pending    { color: var(--danger);   font-weight: 500; }
.quarterly-zero       { color: var(--text-secondary); }

.quarterly-footer-row td {
	font-weight: 700;
	background: var(--gray-50);
	border-top: 2px solid var(--border-color);
	border-bottom: none;
	color: var(--text-primary);
}

.quarterly-footer-row td.quarterly-paid    { color: var(--success); }
.quarterly-footer-row td.quarterly-pending { color: var(--danger); }
.quarterly-footer-row td.quarterly-zero    { color: var(--text-secondary); }

.quarterly-loading, .quarterly-empty {
	padding: var(--space-8);
	text-align: center;
	color: var(--text-secondary);
	font-size: 14px;
}

:root[data-theme='dark'] .quarterly-year-block {
	background: #081226;
	border-color: #1e2f4d;
}

:root[data-theme='dark'] .quarterly-year-header,
:root[data-theme='dark'] .quarterly-table th,
:root[data-theme='dark'] .quarterly-footer-row td {
	background: rgba(15,23,42,0.95);
	border-color: #1e2f4d;
}

:root[data-theme='dark'] .quarterly-table td { border-color: #1e2f4d; }
:root[data-theme='dark'] .quarterly-table tbody tr:hover { background: rgba(30,58,110,0.2); }

.btn-new-invoice {
	background: linear-gradient(135deg, var(--blue-600), var(--blue-700));
	color: white;
	padding: var(--space-2) var(--space-4);
	border: none;
	border-radius: var(--radius-md);
	cursor: pointer;
	font-weight: 500;
	font-size: 14px;
	font-family: inherit;
	transition: all 0.2s ease;
	height: 36px;
	display: inline-flex;
	align-items: center;
	gap: var(--space-1);
	letter-spacing: 0.01em;
}

.btn-new-invoice:hover {
	background: linear-gradient(135deg, var(--blue-700), #1e3a8a);
	transform: translateY(-1px);
	box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-new-invoice:active {
	transform: translateY(0);
	box-shadow: none;
}

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

.search-input,
.filter-status {
	padding: var(--space-2) var(--space-3);
	border: 1px solid var(--border-color);
	border-radius: var(--radius-md);
	font-size: 14px;
	font-family: inherit;
	background: var(--card-bg);
	color: var(--text-primary);
	height: 36px;
	transition: border-color var(--transition-fast);
}

.search-input:focus,
.filter-status:focus {
	outline: none;
	border-color: var(--primary);
	box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.12);
}

.search-input { flex: 1; max-width: 320px; }
.filter-status { min-width: 180px; cursor: pointer; }

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 340px;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-tertiary, var(--gray-400));
  display: flex;
  align-items: center;
  pointer-events: none;
}

.search-input--with-icon {
  padding-left: 34px !important;
  max-width: 100%;
  flex: none;
  width: 100%;
}

.invoices-table-container,
.clients-table-container {
	background: var(--card-bg);
	border-radius: var(--radius-lg);
	border: 1px solid var(--border-color);
	overflow: hidden;
	box-shadow: var(--shadow-xs);
}

.invoices-table,
.clients-table {
	width: 100%;
	border-collapse: collapse;
}

.invoices-table thead,
.clients-table thead {
	background: var(--gray-50);
	border-bottom: 1px solid var(--border-color);
}

.invoices-table th,
.clients-table th {
	font-weight: 500;
	color: var(--text-secondary);
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	padding: var(--space-3) var(--space-4);
	text-align: left;
}

.invoices-table tbody tr,
.clients-table tbody tr {
	border-bottom: 1px solid var(--border-color);
	transition: background-color var(--transition-fast);
}

.invoices-table tbody tr:hover,
.clients-table tbody tr:hover { background-color: var(--gray-50); }

.invoices-table tbody tr:last-child,
.clients-table tbody tr:last-child { border-bottom: none; }

.invoices-table td,
.clients-table td { padding: var(--space-3) var(--space-4); font-size: 14px; }

/* Sortable column headers */
.invoices-table th.sortable {
	user-select: none;
	white-space: nowrap;
}

.invoices-table th.sortable:hover {
	color: var(--text-primary);
	background-color: var(--gray-100);
}

:root[data-theme='dark'] .invoices-table th.sortable:hover {
	background-color: rgba(30, 58, 110, 0.3);
}

.invoices-table th.sort-active {
	color: var(--primary);
}

.sort-icon {
	font-size: 11px;
	opacity: 0.7;
}

/* Totals summary bar */
.invoices-summary {
	display: flex;
	align-items: center;
	gap: var(--space-5);
	padding: var(--space-3) var(--space-4);
	background: var(--card-bg);
	border: 1px solid var(--border-color);
	border-radius: var(--radius-lg);
	margin-top: var(--space-3);
	box-shadow: var(--shadow-xs);
	flex-wrap: wrap;
}

.summary-divider {
	width: 1px;
	height: 24px;
	background: var(--border-color);
	flex-shrink: 0;
}

.summary-item {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

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

.summary-value {
	font-size: 14px;
	font-weight: 600;
	color: var(--text-primary);
	font-variant-numeric: tabular-nums;
}

.summary-item--paid .summary-value    { color: var(--success); }
.summary-item--pending .summary-value { color: var(--danger); }

:root[data-theme='dark'] .invoices-summary {
	background: #081226;
	border-color: #1e2f4d;
}

/* Clickable invoice number */
.btn-invoice-num {
	appearance: none;
	-webkit-appearance: none;
	background: none !important;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
	cursor: pointer;
	font-weight: 500;
	font-size: 13px;
	color: var(--text-primary);
	padding: 0;
	margin: 0;
	font-family: inherit;
	line-height: inherit;
	transition: color var(--transition-fast);
}

.btn-invoice-num:hover,
.btn-invoice-num:focus,
.btn-invoice-num:focus-visible,
.btn-invoice-num:active {
	background: none !important;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
	color: var(--text-primary);
}

.btn-invoice-num:hover {
	color: var(--primary) !important;
	text-decoration: underline;
	text-decoration-color: var(--primary);
	text-underline-offset: 3px;
}

.invoice-number { font-weight: 500; color: var(--text-primary); }

.invoice-client {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	color: var(--text-secondary);
}

.client-icon { display: flex; align-items: center; color: var(--gray-400); }
.invoice-date { color: var(--text-primary); }

.invoice-total,
.invoice-remain {
	font-weight: 600;
	font-variant-numeric: tabular-nums;
}

/* ── Amount colours (used everywhere: table, summary, quarterly) ── */
.amount-positive { color: var(--primary); }
.amount-paid     { color: var(--success); }
.amount-pending  { color: var(--danger);  }
.amount-muted    { color: var(--text-secondary); }

.invoice-actions {
	display: flex;
	gap: var(--space-1);
	justify-content: center;
}

.btn-view,
.btn-action {
	background: transparent;
	border: none;
	padding: var(--space-1);
	border-radius: var(--radius-sm);
	cursor: pointer;
	color: var(--gray-400);
	transition: color var(--transition-fast), background-color var(--transition-fast);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
}

.btn-view:hover { color: var(--primary); background-color: var(--blue-50); }
.btn-action:hover { background-color: var(--gray-100); color: var(--text-primary); }
.btn-delete:hover { background-color: var(--red-50); color: var(--danger); }

.loading,
.error,
.no-invoices,
.no-clients {
	padding: var(--space-10);
	text-align: center;
	color: var(--text-secondary);
	font-size: 14px;
}

.error { color: var(--danger); }

.pagination {
	display: flex;
	justify-content: center;
	align-items: center;
	gap: var(--space-4);
	margin-top: var(--space-4);
	padding: var(--space-3) var(--space-4);
	background: var(--card-bg);
	border-radius: var(--radius-lg);
	border: 1px solid var(--border-color);
}

.pagination-info {
	font-weight: 500;
	color: var(--text-secondary);
	font-size: 13px;
	display: flex;
	gap: var(--space-1);
	align-items: center;
	font-variant-numeric: tabular-nums;
}

.pagination-info .current-page,
.pagination-info .total-pages {
	font-weight: 600;
	color: var(--text-primary);
	min-width: 20px;
	text-align: center;
}

.btn-pagination {
	padding: var(--space-2) var(--space-3);
	background-color: var(--card-bg);
	color: var(--text-primary);
	border: 1px solid var(--border-color);
	border-radius: var(--radius-md);
	cursor: pointer;
	font-weight: 500;
	font-size: 13px;
	transition: background-color var(--transition-fast), border-color var(--transition-fast);
	display: flex;
	align-items: center;
	gap: var(--space-1);
}

.btn-pagination:hover:not(:disabled) {
	background-color: var(--gray-50);
	border-color: var(--gray-300);
}

.btn-pagination:disabled {
	background-color: var(--gray-50);
	color: var(--gray-300);
	cursor: not-allowed;
	border-color: var(--gray-200);
}

/* Dark tune */
:root[data-theme='dark'] .invoices-table-container,
:root[data-theme='dark'] .clients-table-container,
:root[data-theme='dark'] .pagination {
	background: #081226;
	border-color: #1e2f4d;
}

:root[data-theme='dark'] .invoices-table thead,
:root[data-theme='dark'] .clients-table thead {
	background: rgba(15, 23, 42, 0.95);
}

:root[data-theme='dark'] .invoices-table tbody tr:hover,
:root[data-theme='dark'] .clients-table tbody tr:hover,
:root[data-theme='dark'] .btn-pagination:hover:not(:disabled) {
	background-color: rgba(30, 58, 110, 0.24);
}

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

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

	.search-input {
		max-width: 100% !important;
	}

	.pagination {
		flex-wrap: wrap;
		gap: var(--space-3);
	}

	.btn-pagination {
		flex: 1;
		min-width: 100px;
		justify-content: center;
	}

	.pagination-info {
		order: 3;
		width: 100%;
		justify-content: center;
	}
}

@media (max-width: 640px) {
	.facturas-page {
		padding: var(--space-3);
	}

	/* Scroll horizontal suave en la tabla */
	.invoices-table-container {
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
	}

	.invoices-table {
		min-width: 560px;
	}

	/* Ocultar columnas menos importantes en pantallas pequeñas */
	.invoices-table th.invoice-date,
	.invoices-table td.invoice-date,
	.invoices-table th.invoice-remain,
	.invoices-table td.invoice-remain {
		display: none;
	}
}

@media (min-width: 1600px) {
	.facturas-page { max-width: 1600px; }
	.invoices-table th,
	.invoices-table td { font-size: 14px; padding: var(--space-3) var(--space-5); }
	.facturas-header h1 { font-size: 1.5rem; }
	.filter-status { min-width: 220px; }
}

@media (min-width: 2200px) {
	.facturas-page { max-width: 2000px; }
	.invoices-table th,
	.invoices-table td { padding: var(--space-4) var(--space-6); }
}
