/* ==========================================================================
   FACTURACIÓN DE INGRESOS (DypCRM)
   ==========================================================================
   01. Filtros y Barra Superior (Años, Trimestres, Acciones)
   02. Resumen del Periodo (Totales, Estado)
   03. Listado de Facturas (Tabla de Ingresos y Gestoría)
   04. Detalle de Factura (Panel Lateral, Cabecera, Líneas, Totales)
   05. Cobros y Pagos (Tabla y Modales de Cobro)
   06. Modales de Edición y Líneas de Factura
   07. Importación y Avisos (XLS, Duplicadas, Bloqueo de Facturas)
   08. Adaptaciones Responsive (Móvil < 768px y Pantallas Reducidas)
   ========================================================================== */


/* ── 01. FILTROS Y BARRA SUPERIOR ────────────────────────────────────────── */
.facturas-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.facturas-left-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}

.facturas-toolbar .module-primary-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  flex: 0 1 auto;
}

/* Botón de estado e indicador rápido de Veri*Factu en la barra superior */
.facturas-verifactu-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs, 12px);
  padding: 0 var(--space-3, 10px);
  height: 36px;
  border-radius: var(--radius-md, 6px);
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  white-space: nowrap;
}

.facturas-verifactu-btn--bloqueado {
  background: color-mix(in srgb, var(--color-warning, #f59e0b) 12%, var(--color-surface, #ffffff));
  border-color: color-mix(in srgb, var(--color-warning, #f59e0b) 45%, var(--color-border, #e2e8f0));
  color: var(--color-warning, #d97706);
  font-weight: 600;
}

.facturas-verifactu-btn--bloqueado:hover {
  background: color-mix(in srgb, var(--color-warning, #f59e0b) 20%, var(--color-surface, #ffffff));
  border-color: var(--color-warning, #f59e0b);
}

.facturas-verifactu-btn--produccion {
  background: color-mix(in srgb, var(--color-success, #10b981) 10%, var(--color-surface, #ffffff));
  border-color: color-mix(in srgb, var(--color-success, #10b981) 40%, var(--color-border, #e2e8f0));
  color: var(--color-success, #059669);
  font-weight: 600;
}

.facturas-verifactu-btn--produccion:hover {
  background: color-mix(in srgb, var(--color-success, #10b981) 18%, var(--color-surface, #ffffff));
  border-color: var(--color-success, #10b981);
}

.facturas-verifactu-btn--pruebas {
  background: color-mix(in srgb, #3b82f6 10%, var(--color-surface, #ffffff));
  border-color: color-mix(in srgb, #3b82f6 40%, var(--color-border, #e2e8f0));
  color: #2563eb;
  font-weight: 600;
}

.facturas-verifactu-btn--pruebas:hover {
  background: color-mix(in srgb, #3b82f6 18%, var(--color-surface, #ffffff));
  border-color: #3b82f6;
}

/* Filtros y toolbar centralizados en css/estilos.css */

.facturas-top-actions .btn {
  height: 32px;
  min-height: 32px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

.facturas-delete-imported-btn {
  height: 32px;
  min-height: 32px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

.facturas-delete-imported-btn i {
  width: 15px;
  height: 15px;
}

.facturas-actions-bar {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin: calc(-1 * var(--space-2)) 0 var(--space-3);
  flex-wrap: wrap;
}

.facturas-actions-bar .btn {
  height: 32px;
  min-height: 32px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

.facturas-actions-bar .btn i {
  width: 15px;
  height: 15px;
  font-weight: 700;
}


/* ── 02. RESUMEN DEL PERIODO (franja horizontal compacta) ────────────────── */
.facturas-period-summary {
  margin: 0;
  padding: 2px 0;
}

.facturas-period-summary-inline {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  flex-wrap: wrap;
}

.facturas-summary-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.facturas-summary-item strong {
  color: var(--color-text);
  font-weight: 700;
}

.facturas-summary-item strong.facturas-summary-total {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--color-text);
}

.facturas-summary-item strong.facturas-period-partial {
  color: var(--color-success);
}

.facturas-summary-dot {
  color: var(--color-border);
  font-weight: bold;
  user-select: none;
}

.facturas-estado-filter-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: nowrap;
}


.factura-mobile-importes {
  display: none;
}


/* ── 03. LISTADO DE FACTURAS ─────────────────────────────────────────────── */
.factura-clickable-row {
  cursor: pointer;
}

.factura-numero-borrador {
  opacity: 0.22;
  font-weight: 500;
  transition: opacity 0.15s ease-in-out;
}

.factura-clickable-row:hover .factura-numero-borrador {
  opacity: 0.65;
}

.factura-empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-5);
}

.factura-action-mobile {
  display: none !important;
}

html[data-crm-role="gestoria"] [data-role-admin-only] {
  display: none !important;
}

html:not([data-crm-role="gestoria"]) [data-role-gestoria-only] {
  display: none !important;
}

#btnDescargarZipTrimestreGestoria i {
  width: 15px;
  height: 15px;
  margin-right: var(--space-1);
}


/* ── 04. DETALLE DE FACTURA (PANEL LATERAL) ──────────────────────────────── */
.detail-panel.detail-panel-factura {
  width: 600px;
}

.factura-detail-header {
  margin-bottom: var(--space-5);
  padding-right: 88px;
}

.factura-detail-header h2 {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
  flex-wrap: wrap;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

.factura-detail-header-date {
  font-size: var(--text-base);
  font-weight: 700;
}

.factura-detail-header-client {
  margin-bottom: 2px;
  font-weight: 700;
}

.factura-detail-header-address {
  margin-top: 0;
  overflow-wrap: anywhere;
}

.factura-detail-header-nif {
  font-weight: 600;
  white-space: nowrap;
}

/* Separación mínima (la misma que entre las líneas de datos) antes de los botones */
.factura-detail-actions-top {
  margin-top: var(--space-1);
}

.factura-detail-data-lines {
  display: block;
  margin: 0;
}

.factura-detail-data-lines p {
  margin: 0 0 var(--space-1);
  line-height: 1.45;
}

.factura-detail-data-lines p:last-child {
  margin-bottom: 0;
}

.factura-detail-data-lines strong {
  font-weight: 800;
}

.factura-detail-line-separator {
  margin: 0 var(--space-1);
}

.factura-detail-data-grid {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.factura-detail-data-item {
  min-width: 0;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-offset);
}

.factura-detail-data-item-full {
  grid-column: 1 / -1;
}

.factura-detail-data-item span {
  display: block;
  margin-bottom: 4px;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.factura-detail-data-item strong,
.factura-detail-data-item div {
  display: block;
  min-width: 0;
  color: var(--color-text);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.factura-detail-data-item .badge {
  display: inline-flex;
}

.factura-detail-data-item-pair,
.factura-detail-data-item-pair-force {
  grid-column: 1 / -1;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  align-items: start;
  column-gap: var(--space-4);
  row-gap: var(--space-2);
}

.factura-detail-data-item-pair-force>.factura-detail-data-field {
  display: block !important;
  min-width: 0;
}

.factura-detail-data-field {
  min-width: 0;
}

.factura-detail-data-field-right,
.factura-detail-data-item-pair-force>.factura-detail-data-field-right {
  text-align: right;
}

.factura-detail-data-field-right .badge,
.factura-detail-data-item-pair-force>.factura-detail-data-field-right .badge {
  justify-content: flex-end;
}

.factura-detail-data-item-pair .factura-detail-data-field span {
  margin-bottom: 4px;
}

.factura-detail-data-item-pair .factura-detail-data-field strong {
  display: block;
  min-width: 0;
  color: var(--color-text);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.factura-detalle-total {
  margin-top: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-offset);
  text-align: right;
  font-weight: 800;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.factura-detalle-total span,
.factura-detalle-total strong {
  white-space: nowrap;
}

.factura-lineas-detalle-table th:nth-child(2),
.factura-lineas-detalle-table td:nth-child(2) {
  width: 62px;
  white-space: nowrap;
}

.factura-lineas-detalle-table th:nth-child(3),
.factura-lineas-detalle-table td:nth-child(3) {
  width: 92px;
  white-space: nowrap;
}

.factura-lineas-detalle-table th:nth-child(4),
.factura-lineas-detalle-table td:nth-child(4) {
  width: 44px;
  white-space: nowrap;
}

.detail-panel-factura .factura-lineas-detalle-table tr.factura-linea-detalle-negrita td:first-child {
  font-weight: 700;
}

.factura-linea-detalle-cursiva td:first-child {
  font-style: italic;
  color: #595959;
}

.factura-linea-detalle-blanco td:first-child {
  height: 1.5em;
}

.factura-linea-estilo-label {
  display: none;
}


/* ── 05. COBROS Y PAGOS ──────────────────────────────────────────────────── */
.modal.modal-cobro,
.modal.modal-factura.modal-cobro {
  max-width: 620px;
}

.modal-cobro .modal-actions .btn {
  min-height: 44px;
}

.factura-label-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
}

.factura-label-action label {
  margin: 0;
}

.factura-contado-inline {
  white-space: nowrap;
}

.factura-cobro-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.modal.modal-entrega-correccion {
  max-width: 440px;
}


/* ── 06. MODALES DE EDICIÓN Y LÍNEAS DE FACTURA ─────────────────────────── */
.modal.modal-wide {
  max-width: 760px;
}

.modal.modal-factura,
.modal.modal-wide.modal-factura {
  max-width: 960px;
}

.factura-modal-intro {
  margin-top: calc(-1 * var(--space-2));
  margin-bottom: var(--space-4);
}

.factura-modal-actions-flat {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.factura-form-group-spaced {
  margin-top: var(--space-4);
}

.factura-form-group-notes {
  margin-top: var(--space-3);
}

.factura-technical-note {
  font-size: var(--text-xs);
  margin-top: 4px;
}

.factura-inline-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-1);
}

.factura-action-push-left {
  margin-right: auto;
}

.form-row.form-row-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.factura-row-cabecera-5 {
  display: grid;
  grid-template-columns: 115px 135px 115px minmax(180px, 1.6fr) 130px;
  gap: var(--space-2);
  align-items: flex-end;
  margin-bottom: var(--space-3);
}

.factura-row-cabecera-5 .form-group {
  margin-bottom: 0;
}

.factura-row-cliente-total .factura-cliente-crm {
  grid-column: span 2;
}

.factura-row-main .form-group,
.factura-row-localidad .form-group {
  margin-bottom: var(--space-3);
}

.factura-lineas-head,
.factura-linea-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 60px 85px 42px 84px 108px;
  gap: var(--space-2);
  align-items: center;
}

.factura-lineas-head {
  margin-bottom: var(--space-1);
  padding: 0 2px;
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.factura-lineas-box {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.factura-linea-row {
  margin-bottom: 0;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.factura-linea-row.factura-linea-dragging {
  opacity: 0.4;
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
}

.factura-linea-estilo {
  min-width: 0;
  padding-left: var(--space-1);
  padding-right: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.factura-lineas-head span:nth-child(n+2):nth-child(-n+5) {
  text-align: right;
}

.factura-linea-desc-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.factura-linea-ref-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  font-size: 10px;
  font-family: var(--font-mono, monospace);
  color: var(--color-primary);
  background: var(--color-primary-highlight);
  border: 1px solid var(--color-primary-border, rgba(59, 130, 246, 0.25));
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  width: fit-content;
  max-width: 100%;
}

.factura-linea-ref-badge .ref-badge-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.factura-linea-ref-badge .ref-badge-tag i {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
}

.factura-linea-ref-badge .ref-badge-clear {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0 2px;
  font-size: 12px;
  line-height: 1;
  border-radius: 2px;
}

.factura-linea-ref-badge .ref-badge-clear:hover {
  color: var(--color-error);
  background: var(--color-error-highlight);
}

.factura-linea-sn-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  font-size: 10px;
  font-family: var(--font-mono, monospace);
  color: #7c3aed;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.3);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  width: fit-content;
  max-width: 100%;
}

.factura-linea-sn-badge .sn-badge-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.factura-linea-sn-badge .sn-badge-tag i {
  width: 10px;
  height: 10px;
  flex-shrink: 0;
}

.factura-linea-sn-badge .sn-badge-clear {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0 2px;
  font-size: 12px;
  line-height: 1;
  border-radius: 2px;
}

.factura-linea-sn-badge .sn-badge-clear:hover {
  color: var(--color-error);
  background: var(--color-error-highlight);
}

/* Línea de rectificativa enlazada a la factura original */
.factura-linea-rect-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 3px;
  font-size: 10px;
  color: var(--color-warning);
  background: color-mix(in srgb, var(--color-warning) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-warning) 30%, transparent);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  width: fit-content;
}

.factura-linea-rect-badge i {
  width: 10px;
  height: 10px;
}

/* Cabecera de una rectificativa en el editor */
.factura-rectificativa-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  background: color-mix(in srgb, var(--color-warning) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-warning) 30%, transparent);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.factura-rectificativa-banner input {
  flex: 1 1 240px;
  min-width: 0;
}

/* Ventana para elegir qué se devuelve al crear una rectificativa */
.rectificativa-lineas {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 12px;
  font-size: var(--text-sm);
}

.rectificativa-lineas th,
.rectificativa-lineas td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--color-divider);
  text-align: left;
}

.rectificativa-lineas .num {
  text-align: right;
  white-space: nowrap;
}

.rectificativa-lineas input {
  width: 72px;
  text-align: right;
}

.factura-linea-descripcion,
.factura-linea-row input[data-field="descripcion"] {
  min-width: 0;
}

.factura-linea-uds,
.factura-linea-row input[data-field="unidades"] {
  text-align: right;
  padding-left: var(--space-2);
  padding-right: var(--space-2);
}

.factura-linea-dto,
.factura-linea-row input[data-field="descuento"] {
  text-align: right;
  padding-left: var(--space-1);
  padding-right: var(--space-1);
}

.factura-linea-precio,
.factura-linea-row input[data-field="precio"] {
  text-align: right;
  padding-left: var(--space-2);
  padding-right: var(--space-2);
}

.factura-linea-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  justify-content: flex-end;
}

.factura-linea-btn-ref {
  font-size: 11px;
  font-weight: 600;
  height: 32px;
  min-width: 32px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--color-border);
  transition: all 0.15s ease;
}

.factura-linea-btn-ref:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
  background: var(--color-primary-highlight);
}

.factura-linea-btn-ref.tiene-ref {
  background: rgba(16, 185, 129, 0.12);
  color: #059669;
  border: 1px solid rgba(16, 185, 129, 0.4);
  font-weight: 700;
}

.factura-linea-btn-ref.tiene-ref:hover {
  background: rgba(16, 185, 129, 0.2);
  border-color: #059669;
}

.factura-linea-btn-sn {
  height: 32px;
  font-size: 11px;
  font-weight: 600;
  min-width: 32px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--color-border);
  transition: all 0.15s ease;
}

.factura-linea-btn-sn:hover {
  color: #7c3aed;
  border-color: #7c3aed;
  background: rgba(139, 92, 246, 0.1);
}

.factura-linea-btn-sn.tiene-sn {
  background: rgba(139, 92, 246, 0.12);
  color: #7c3aed;
  border: 1px solid rgba(139, 92, 246, 0.4);
  font-weight: 700;
}

.factura-linea-btn-sn.tiene-sn:hover {
  background: rgba(139, 92, 246, 0.2);
  border-color: #7c3aed;
}

.factura-linea-btn-move {
  width: 22px;
  height: 32px;
  min-width: 22px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  opacity: 0.75;
}

.factura-linea-btn-move:hover {
  opacity: 1;
  color: var(--color-primary);
  background: var(--color-primary-highlight);
}

.factura-linea-remove {
  min-width: 24px;
  width: 24px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
}

.factura-linea-remove:hover {
  color: var(--color-error);
  background: var(--color-error-highlight);
}

.factura-lineas-add-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.factura-lineas-title {
  margin-top: var(--space-3);
  margin-bottom: var(--space-2);
  text-align: center;
}

.factura-linea-row[data-estilo="negrita"] input[data-field="descripcion"],
.factura-linea-row[data-estilo="negrita"] .factura-linea-descripcion {
  font-weight: 700;
}

.factura-linea-row[data-estilo="cursiva"] input[data-field="descripcion"],
.factura-linea-row[data-estilo="cursiva"] .factura-linea-descripcion {
  font-style: italic;
  color: #595959;
}

.factura-linea-row[data-estilo="referencia"] input[data-field="descripcion"],
.factura-linea-row[data-estilo="referencia"] .factura-linea-descripcion {
  font-style: italic;
  color: var(--color-text-faint);
  opacity: 0.55;
}

.factura-linea-row[data-estilo="blanco"] input[data-field="descripcion"],
.factura-linea-row[data-estilo="blanco"] .factura-linea-descripcion {
  font-style: italic;
  color: var(--color-text-muted);
}

.factura-lineas-detalle-table .factura-linea-detalle-negrita td {
  font-weight: 700;
}

.factura-lineas-detalle-table .factura-linea-detalle-cursiva td {
  font-style: italic;
  color: #595959;
}

.factura-lineas-detalle-table .factura-linea-detalle-referencia td {
  font-style: italic;
  color: var(--color-text-faint);
  opacity: 0.55;
  font-size: 0.9em;
}

.factura-lineas-detalle-table .factura-linea-detalle-blanco td {
  color: var(--color-text-muted);
  font-style: italic;
}


/* ── 07. IMPORTACIÓN Y AVISOS (XLS / DUPLICADAS / BLOQUEOS) ──────────────── */
.factura-import-preview {
  margin-top: var(--space-3);
  max-height: 50vh;
  overflow: auto;
}

.factura-import-table th,
.factura-import-table td {
  white-space: nowrap;
}

.factura-import-table td:nth-child(2),
.factura-import-table td:nth-child(5) {
  white-space: normal;
  min-width: 160px;
}

.import-row-warning {
  background: color-mix(in srgb, var(--color-warning) 8%, transparent);
}

.factura-import-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  white-space: nowrap;
  color: var(--color-text-muted);
}

.factura-import-numero {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.factura-import-numero strong,
.factura-import-numero span {
  overflow-wrap: anywhere;
}

.factura-import-meta {
  display: grid;
  grid-template-columns: 1fr 2fr .65fr .85fr;
  gap: var(--space-2);
  margin-top: var(--space-3);
  align-items: start;
}

.factura-import-meta div {
  min-width: 0;
}

.factura-import-meta span {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: 2px;
}

.factura-import-meta strong {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.factura-import-errors {
  margin-top: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-warning) 12%, transparent);
  color: var(--color-text);
  font-size: var(--text-sm);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.factura-import-errors ul {
  margin: var(--space-1) 0 0 var(--space-4);
  padding: 0;
}

.factura-import-errors li+li {
  margin-top: var(--space-1);
}

.factura-import-errors-general {
  margin-bottom: var(--space-3);
  margin-top: 0;
}

.modal-factura-rapida {
  max-width: 680px;
}

.factura-import-match {
  margin-top: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text);
  overflow-wrap: anywhere;
}

.factura-import-match .badge {
  margin-right: var(--space-2);
}

.factura-import-match-warning {
  color: var(--color-text-muted);
}

.factura-import-summary {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--color-primary) 6%, var(--color-surface));
  color: var(--color-text);
  font-size: var(--text-sm);
}

.factura-import-summary span {
  display: inline-flex;
  gap: 4px;
  align-items: baseline;
  white-space: nowrap;
}

.factura-import-summary-warning {
  color: var(--color-warning);
}

.factura-import-loading {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  color: var(--color-text);
}

.factura-import-loading p {
  margin: 2px 0 0 0;
}

.factura-import-working {
  margin-bottom: var(--space-3);
}

.facturas-duplicate-warning {
  position: relative;
  margin: var(--space-3) 0;
  padding: var(--space-3);
  border: 1px solid color-mix(in srgb, var(--color-warning) 45%, transparent);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-warning) 10%, transparent);
  color: var(--color-text);
  font-size: var(--text-sm);
  line-height: 1.35;
}

.facturas-duplicate-warning p {
  margin: .35rem 0 .5rem;
  color: var(--color-text-muted);
}

.facturas-duplicate-warning ul {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: .45rem;
}

.facturas-duplicate-warning li div {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: .1rem;
  overflow-wrap: anywhere;
}

.facturas-warning-close {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  width: 28px;
  height: 28px;
  border: 1px solid color-mix(in srgb, var(--color-warning) 26%, var(--color-border));
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--color-surface) 86%, var(--color-warning));
  color: var(--color-text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.facturas-warning-close:hover {
  color: var(--color-text);
  background: var(--color-surface);
}

.facturas-warning-section+.facturas-warning-section {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid color-mix(in srgb, var(--color-warning) 28%, transparent);
}

.invoice-client-candidates {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-4);
  max-height: min(62vh, 560px);
  overflow: auto;
  padding-right: 2px;
}

.invoice-client-candidate {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  padding: var(--space-3);
}

.invoice-client-candidate-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.invoice-client-candidate-actions {
  display: flex;
  justify-content: flex-end;
}

.invoice-client-section-title {
  margin: var(--space-4) 0 var(--space-2);
  font-size: var(--text-xs);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
}

.invoice-client-candidate-diff {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 3px;
}

.invoice-client-candidate-diff span {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: 1px 7px;
  font-size: 11px;
  color: var(--color-text-muted);
  background: var(--color-surface-offset);
}

/* Banner de protección y desbloqueo de factura emitida */
.factura-bloqueo-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.factura-bloqueo-info {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: #ef4444;
}

.factura-bloqueo-desbloqueado {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: #f59e0b;
}

.factura-campo-bloqueado {
  background-color: rgba(125, 125, 125, 0.08) !important;
  cursor: not-allowed !important;
  opacity: 0.85;
}

/* ── SELECTOR DE REFERENCIA DE COMPRA (MODAL FLOTANTE) ───────────────────── */
.factura-ref-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
  z-index: 10050;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  transition: opacity 0.15s ease;
}

.factura-ref-overlay.open {
  display: flex;
  opacity: 1;
}

.factura-ref-modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 620px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.25), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

.factura-ref-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-offset);
}

.factura-ref-header h3 {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.factura-ref-header h3 i {
  width: 16px;
  height: 16px;
  color: var(--color-primary);
}

.factura-ref-body {
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.factura-ref-articulo-info {
  font-size: var(--text-xs);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-offset);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--color-primary);
}

.factura-ref-lista {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 140px;
  max-height: 380px;
  padding-right: 2px;
}

.factura-ref-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  cursor: pointer;
  transition: all 0.15s ease;
  gap: var(--space-3);
}

.factura-ref-item:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-highlight);
}

.factura-ref-item.is-selected {
  border-color: var(--color-primary);
  background: var(--color-primary-highlight);
  box-shadow: 0 0 0 1px var(--color-primary);
}

.factura-ref-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
}

.factura-ref-item-prov {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.factura-ref-item-sub {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.factura-ref-item-articulos {
  font-size: 11px;
  color: var(--color-text-muted);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  margin-top: 3px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.factura-ref-item-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.factura-ref-item-code {
  font-family: var(--font-mono, monospace);
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-primary);
  background: var(--color-surface-2);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  white-space: nowrap;
}

.factura-ref-item-btn {
  height: 28px;
  min-height: 28px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
}

.factura-ref-alcance {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  margin-top: var(--space-2);
}

.factura-ref-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-offset);
}

/* ── 08. ADAPTACIONES RESPONSIVE (< 768px) ────────────────────────────────── */
@media (min-width: 768px) {
  .factura-estado-mobile {
    display: none !important;
  }
}

@media (max-width: 767px) {

  /* Estructura general de la vista */
  #view-facturacion.view.active {
    display: flex;
    flex-direction: column;
  }

  #view-facturacion .facturas-toolbar {
    order: 1;
  }

  #view-facturacion #facturasDuplicadasAviso {
    order: 2;
  }

  #view-facturacion #facturasResumenPeriodo {
    order: 3;
  }

  #view-facturacion .table-card {
    order: 4;
  }

  .facturas-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
  }

  .facturas-toolbar .module-primary-actions,
  .facturas-top-actions {
    display: flex;
    gap: var(--space-2);
    width: 100%;
    margin-left: 0;
    flex-wrap: nowrap;
  }

  .facturas-top-actions .btn {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
    text-align: center;
    margin: 0;
    height: 34px;
    font-size: var(--text-xs);
    padding: 0 var(--space-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .facturas-delete-imported-btn {
    flex: 1 1 0;
    width: auto;
    max-width: none;
    margin: 0;
    justify-content: center;
  }

  .facturas-combined-filter-bar {
    width: 100%;
    justify-content: center;
    margin-bottom: 0;
  }

  .facturas-periodo-group {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    max-width: 100%;
    flex-wrap: nowrap;
  }

  .facturas-btn-actual {
    display: none;
  }

  .facturas-year-bar {
    flex-wrap: nowrap;
    align-items: center;
    flex-shrink: 0;
  }

  .facturas-year-select {
    min-width: 76px;
    max-width: 88px;
    height: 32px;
    font-size: var(--text-xs);
    padding: 0 var(--space-2);
  }

  .facturas-quarter-options {
    width: auto;
    justify-content: center;
    gap: 3px;
    flex-shrink: 0;
  }

  .facturas-quarter-options .filter-btn {
    height: 32px;
    min-height: 32px;
    padding: 0 7px;
    font-size: var(--text-xs);
  }

  /* Resumen del periodo en móvil */
  .facturas-period-summary {
    padding: var(--space-3) var(--space-4);
  }

  .facturas-period-summary-title {
    text-align: center;
  }

  .facturas-period-summary-inline {
    justify-content: space-between;
    gap: 4px var(--space-2);
  }

  /* Tabla de facturas en tarjeta móvil (Admin) */
  .facturas-table tr {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .facturas-table td:nth-child(1) {
    grid-column: 1 / 2;
    grid-row: 1;
  }

  .facturas-table td:nth-child(2) {
    grid-column: 2 / 3;
    grid-row: 1;
    text-align: right !important;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    white-space: nowrap;
  }

  .facturas-table td:nth-child(3) {
    grid-column: 1 / 2;
    grid-row: 2;
    min-width: 0;
  }

  .facturas-table td:nth-child(5) {
    grid-column: 2 / 3;
    grid-row: 2;
    text-align: right !important;
    align-self: start;
  }

  .facturas-table td:nth-child(4) {
    grid-column: 1 / 2;
    grid-row: 3;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
  }

  .facturas-table td:nth-child(6) {
    grid-column: 2 / 3;
    grid-row: 3;
    text-align: right !important;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    white-space: nowrap;
  }

  .facturas-table td:nth-child(7) {
    grid-column: 2 / 3;
    grid-row: 4;
    text-align: right !important;
    font-weight: 800;
    white-space: nowrap;
  }

  .facturas-table.facturas-table-admin td.factura-base-cell,
  .facturas-table th.factura-th-vf,
  .facturas-table td.factura-vf-cell {
    display: none !important;
  }

  .facturas-table.facturas-table-admin td.factura-total-cell {
    grid-column: 2 / 3;
    grid-row: 3;
    text-align: right !important;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    white-space: nowrap;
  }

  .facturas-table.facturas-table-admin .factura-total-desktop {
    display: none;
  }

  .facturas-table.facturas-table-admin .factura-mobile-importes {
    display: inline;
  }

  /* Tabla de facturas en tarjeta móvil (Gestoría) */
  html[data-crm-role="gestoria"] .facturas-table tr,
  .facturas-table.facturas-table-gestoria tr {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  html[data-crm-role="gestoria"] .facturas-table td:nth-child(1),
  .facturas-table.facturas-table-gestoria td:nth-child(1) {
    grid-column: 1 / 2;
    grid-row: 1;
  }

  html[data-crm-role="gestoria"] .facturas-table td:nth-child(2),
  .facturas-table.facturas-table-gestoria td:nth-child(2) {
    grid-column: 2 / 3;
    grid-row: 1;
    text-align: right !important;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    white-space: nowrap;
  }

  html[data-crm-role="gestoria"] .facturas-table td:nth-child(3),
  .facturas-table.facturas-table-gestoria td:nth-child(3) {
    grid-column: 1 / 2;
    grid-row: 2;
    min-width: 0;
  }

  html[data-crm-role="gestoria"] .facturas-table td:nth-child(4),
  .facturas-table.facturas-table-gestoria td:nth-child(4) {
    grid-column: 1 / 2;
    grid-row: 3;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    text-align: left !important;
  }

  html[data-crm-role="gestoria"] .facturas-table td:nth-child(5),
  .facturas-table.facturas-table-gestoria td:nth-child(5) {
    grid-column: 2 / 3;
    grid-row: 2;
    text-align: right !important;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    white-space: nowrap;
  }

  html[data-crm-role="gestoria"] .facturas-table td:nth-child(6),
  .facturas-table.facturas-table-gestoria td:nth-child(6) {
    grid-column: 2 / 3;
    grid-row: 3;
    text-align: right !important;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    white-space: nowrap;
  }

  html[data-crm-role="gestoria"] .facturas-table td:nth-child(7),
  .facturas-table.facturas-table-gestoria td:nth-child(7) {
    grid-column: 2 / 3;
    grid-row: 4;
    text-align: right !important;
    font-weight: 800;
    white-space: nowrap;
  }

  html[data-crm-role="gestoria"] .facturas-table td:nth-child(8),
  .facturas-table.facturas-table-gestoria td:nth-child(8) {
    grid-column: 1 / 2;
    grid-row: 4;
    text-align: left !important;
    align-self: end;
  }

  /* Modales y Detalle en Móvil */
  .modal.modal-factura {
    max-width: 100%;
  }

  .factura-action-desktop {
    display: none !important;
  }

  .factura-action-mobile {
    display: inline-flex !important;
  }

  .detail-panel.detail-panel-factura {
    padding: var(--space-4) var(--space-3);
  }

  .detail-panel-factura .factura-detail-header h2 {
    margin-bottom: var(--space-1);
    line-height: 1.2;
  }

  .detail-panel-factura .factura-detail-header-date {
    font-size: var(--text-sm);
  }

  .detail-panel-factura .factura-detail-header-client,
  .detail-panel-factura .factura-detail-header-address {
    margin: 0;
    line-height: 1.3;
  }

  .detail-panel-factura .factura-detail-header-address {
    margin-top: 2px;
    font-size: var(--text-xs);
  }

  .detail-panel-factura .factura-detail-data-lines {
    display: none;
  }

  .detail-panel-factura .factura-detail-data-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .detail-panel-factura .factura-detail-data-item {
    padding: var(--space-3);
  }

  .detail-panel-factura .factura-detail-data-item-pair,
  .detail-panel-factura .factura-detail-data-item-pair-force {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
    column-gap: var(--space-3);
    row-gap: var(--space-2);
  }

  .detail-panel-factura .factura-detail-data-item-pair>.factura-detail-data-field,
  .detail-panel-factura .factura-detail-data-item-pair-force>.factura-detail-data-field {
    display: block !important;
    min-width: 0;
  }

  .detail-panel-factura .factura-detail-data-item-trio {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }

  .detail-panel-factura .factura-detail-data-field-center {
    text-align: center;
  }

  .detail-panel-factura .factura-detail-data-field-right {
    text-align: right !important;
  }

  .detail-panel-factura .factura-detail-data-field-right .badge {
    justify-content: flex-end !important;
  }

  .detail-panel-factura .factura-detail-actions-top {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .detail-panel-factura .factura-detail-actions-top .factura-action-mobile {
    order: -1;
    grid-column: 1 / -1;
  }

  .detail-panel-factura .factura-detail-actions .btn {
    min-height: 44px;
    font-size: 12px;
    white-space: nowrap;
    padding-left: var(--space-2);
    padding-right: var(--space-2);
    justify-content: center;
  }

  /* Líneas de detalle en el panel lateral móvil */
  .detail-panel-factura .factura-lineas-detalle-table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  .detail-panel-factura .factura-lineas-detalle-table thead {
    display: none;
  }

  .detail-panel-factura .factura-lineas-detalle-table,
  .detail-panel-factura .factura-lineas-detalle-table tbody,
  .detail-panel-factura .factura-lineas-detalle-table tr,
  .detail-panel-factura .factura-lineas-detalle-table td {
    display: block;
    width: 100%;
  }

  .detail-panel-factura .factura-lineas-detalle-table tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    margin-bottom: var(--space-3);
  }

  .detail-panel-factura .factura-lineas-detalle-table tr:last-child {
    margin-bottom: 0;
  }

  .detail-panel-factura .factura-lineas-detalle-table td {
    min-width: 0;
  }

  .detail-panel-factura .factura-lineas-detalle-table td:first-child {
    grid-column: 1 / -1;
    margin-bottom: 0;
    text-align: left !important;
    font-weight: 650;
    overflow-wrap: anywhere;
  }

  .detail-panel-factura .factura-lineas-detalle-table td:first-child::before {
    display: none;
  }

  .detail-panel-factura .factura-lineas-detalle-table td:not(:first-child) {
    display: block;
    margin-top: 0;
    padding: var(--space-1) var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface-offset);
    text-align: center !important;
    white-space: nowrap;
  }

  .detail-panel-factura .factura-lineas-detalle-table td:not(:first-child)::before {
    content: attr(data-label);
    display: inline;
    margin-right: 4px;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
  }

  .detail-panel-factura .factura-lineas-detalle-table td.factura-linea-detalle-empty-mobile {
    display: none !important;
  }

  .detail-panel-factura .factura-detalle-total {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-2);
    text-align: left;
    padding: var(--space-2) var(--space-3);
  }

  .detail-panel-factura .factura-detalle-total span,
  .detail-panel-factura .factura-detalle-total strong {
    min-width: 0;
    white-space: normal;
  }

  /* Cobros en panel lateral móvil */
  .detail-panel-factura .factura-cobros-table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  .detail-panel-factura .factura-cobros-table thead {
    display: none;
  }

  .detail-panel-factura .factura-cobros-table,
  .detail-panel-factura .factura-cobros-table tbody,
  .detail-panel-factura .factura-cobros-table tr,
  .detail-panel-factura .factura-cobros-table td {
    display: block;
    width: 100%;
  }

  .detail-panel-factura .factura-cobros-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: var(--space-2) var(--space-3);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-2);
    margin-bottom: var(--space-3);
  }

  .detail-panel-factura .factura-cobros-table tr:last-child {
    margin-bottom: 0;
  }

  .detail-panel-factura .factura-cobros-table td {
    min-width: 0;
  }

  .detail-panel-factura .factura-cobros-table td:nth-child(1) {
    grid-column: 1 / 2;
    grid-row: 1;
    align-self: baseline;
    text-align: left !important;
  }

  .detail-panel-factura .factura-cobro-importe {
    grid-column: 2 / 3;
    grid-row: 1;
    align-self: baseline;
    margin-top: 0 !important;
    text-align: right !important;
    white-space: nowrap;
    font-size: var(--text-base);
  }

  .detail-panel-factura .factura-cobros-table td:nth-child(2) {
    grid-column: 1 / -1;
    grid-row: 2;
    text-align: left !important;
  }

  .detail-panel-factura .factura-cobro-actions-cell {
    grid-column: 1 / -1;
    grid-row: 3;
    margin-top: var(--space-1) !important;
  }

  .detail-panel-factura .factura-cobro-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
    width: 100%;
  }

  .detail-panel-factura .factura-cobro-btn {
    min-height: 40px;
    justify-content: center;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
  }

  /* Formulario de factura y líneas en móvil */
  .factura-row-cabecera-5 {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  }

  .factura-row-cabecera-5 .factura-cliente-crm {
    grid-column: span 2;
  }

  .factura-row-main {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  }

  .factura-row-main .factura-estado-desktop {
    display: none !important;
  }

  .factura-row-localidad {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) !important;
  }

  .factura-row-localidad .form-group:nth-child(1) {
    grid-column: 1 / 2;
    grid-row: 1;
  }

  .factura-row-localidad .form-group:nth-child(2) {
    grid-column: 2 / 3;
    grid-row: 1;
  }

  .factura-row-localidad .form-group:nth-child(3) {
    grid-column: 1 / 2;
    grid-row: 2;
  }

  .factura-row-localidad .factura-estado-mobile {
    grid-column: 2 / 3;
    grid-row: 2;
    display: block !important;
  }

  .factura-lineas-head {
    display: none;
  }

  .factura-lineas-box {
    gap: var(--space-3);
  }

  .factura-linea-row {
    grid-template-columns: 62px minmax(0, 1fr) 54px 68px !important;
    gap: var(--space-2);
    padding: var(--space-3);
    align-items: center;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-surface-offset);
  }

  .factura-linea-desc-wrap,
  .factura-linea-descripcion,
  .factura-linea-row input[data-field="descripcion"] {
    grid-column: 1 / -1 !important;
    grid-row: 1 !important;
  }

  .factura-linea-uds,
  .factura-linea-row input[data-field="unidades"] {
    grid-column: 1 / 2 !important;
    grid-row: 2 !important;
    text-align: right;
  }

  .factura-linea-precio,
  .factura-linea-row input[data-field="precio"] {
    grid-column: 2 / 3 !important;
    grid-row: 2 !important;
    text-align: right;
  }

  .factura-linea-dto,
  .factura-linea-row input[data-field="descuento"] {
    grid-column: 3 / 4 !important;
    grid-row: 2 !important;
    text-align: right;
  }

  .factura-linea-estilo {
    grid-column: 4 / 5;
    grid-row: 2;
    align-self: center;
    min-height: 44px;
    padding: 0 var(--space-1);
  }

  .factura-linea-actions {
    grid-column: 1 / -1 !important;
    grid-row: 3 !important;
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px dashed var(--color-border);
  }

  .modal-cobro .form-row.form-row-3 {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .modal-cobro .form-row.form-row-3 .form-group:nth-child(3) {
    grid-column: 1 / -1;
  }

  .modal-cobro .modal-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--space-3);
  }

  .modal-cobro .modal-actions .btn {
    justify-content: center;
    min-width: 0;
  }
}

@media (max-width: 360px) {
  .detail-panel-factura .factura-detalle-total {
    grid-template-columns: 1fr;
  }

  .factura-linea-row {
    grid-template-columns: 54px minmax(0, 1fr) 50px 60px !important;
  }
}

@media (max-width: 320px) {

  .modal-cobro .form-row.form-row-3,
  .modal-cobro .modal-actions {
    grid-template-columns: 1fr;
  }

  .modal-cobro .modal-actions .btn-primary {
    order: -1;
  }
}

/* ── 09. COLUMNA E ICONO VERI*FACTU EN LISTADO ───────────────────────────── */
.facturas-table th.factura-th-estado,
.facturas-table td.factura-estado-cell {
  width: 1%;
  white-space: nowrap;
  text-align: center !important;
  padding-left: var(--space-2) !important;
  padding-right: 4px !important;
}

.factura-th-vf,
.facturas-table th.factura-th-vf,
.facturas-table td.factura-vf-cell {
  width: 1%;
  white-space: nowrap;
  text-align: center !important;
  padding-left: 2px !important;
  padding-right: var(--space-3) !important;
}

.badge-vf-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-size: 11px;
  font-weight: 700;
  border-radius: var(--radius-sm, 4px);
  cursor: pointer;
  line-height: 1;
  transition: transform var(--transition-interactive);
  vertical-align: middle;
}

.badge-vf-icon:hover {
  transform: scale(1.18);
}

/* Tema claro */
.badge-vf-ok {
  background: #d1fae5;
  color: #065f46;
}

.badge-vf-test {
  background: #dbeafe;
  color: #1e40af;
}

.badge-vf-pending {
  background: #fef3c7;
  color: #92400e;
}

.badge-vf-error {
  background: #fee2e2;
  color: #991b1b;
}

/* Tema oscuro (pastillas suaves sin borde) */
[data-theme="dark"] .badge-vf-ok {
  background: color-mix(in srgb, #10b981 14%, var(--color-surface-offset));
  color: #6ee7b7;
  border: none;
}

[data-theme="dark"] .badge-vf-test {
  background: color-mix(in srgb, #3b82f6 14%, var(--color-surface-offset));
  color: #93c5fd;
  border: none;
}

[data-theme="dark"] .badge-vf-pending {
  background: color-mix(in srgb, #f59e0b 14%, var(--color-surface-offset));
  color: #fcd34d;
  border: none;
}

[data-theme="dark"] .badge-vf-error {
  background: color-mix(in srgb, #ef4444 14%, var(--color-surface-offset));
  color: #fca5a5;
  border: none;
}