/* ============================================
   SISTEMA DE ESPACIADO Y LAYOUT
   ============================================ */

.module {
  background: var(--bg-card);
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: var(--border-radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-card);
  transition: all var(--transition-base);
}

.module:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.module h2 {
  margin-top: 0;
  font-size: 1.15rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #eeeeee;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border-color-light);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ============================================
   CELDAS NUMÉRICAS
   ============================================ */

.numeric-header {
  text-align: right;
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

.numeric-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.numeric-cell input[type="number"],
.numeric-cell input[type="text"] {
  text-align: right;
}

/* ============================================
   TABLAS RESPONSIVE Y MEJORADAS
   ============================================ */

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: var(--spacing-lg);
  box-shadow: var(--shadow-sm);
  border-radius: var(--border-radius);
  background: var(--bg-card);
}

#budget-lines-table,
#result_list {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 800px;
  background: var(--bg-card);
}

#budget-lines-table thead,
#result_list thead {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--bg-secondary);
}

#budget-lines-table thead th,
#result_list thead th {
  background: #f8fafc;
  padding: 1rem 0.75rem;
  font-weight: var(--font-weight-semibold);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.75px;
  text-align: left;
  border-bottom: 2px solid #e2e8f0;
  color: #475569;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
}

#budget-lines-table tbody td,
#result_list tbody td {
  padding: 1rem 0.75rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
  color: #334155;
  font-size: 0.9rem;
}

/* Zebra striping sutil */
#budget-lines-table tbody tr:nth-child(even),
#result_list tbody tr.formset-row:nth-child(even) {
  background-color: var(--bg-secondary);
}

#budget-lines-table tbody tr:nth-child(odd),
#result_list tbody tr.formset-row:nth-child(odd) {
  background-color: var(--bg-card);
}

/* Row Hover Effect mejorado */
#budget-lines-table tbody tr:hover,
#result_list tbody tr:hover {
  background-color: rgba(17, 165, 201, 0.03) !important;
  transition: background-color 0.15s ease;
}

#budget-lines-table tbody tr.budget-line-row:hover,
#result_list tbody tr.formset-row:hover {
  cursor: pointer;
}

/* ============================================
   ESTADOS DE CARGA
   ============================================ */

.updating {
  position: relative;
  opacity: 0.7;
  pointer-events: none;
}

.updating::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 10;
}

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

/* ============================================
   DRAG HANDLE
   ============================================ */

.drag-handle {
  cursor: move;
  text-align: center;
  vertical-align: middle;
  color: var(--text-muted);
  width: 30px;
  transition: color var(--transition-base);
}

.drag-handle:hover {
  color: var(--primary);
}

.drag-handle i {
  font-size: var(--font-size-lg);
}

/* ============================================
   GRID DE CONFIGURACIÓN
   ============================================ */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--spacing-lg);
}

.settings-grid .form-row label {
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--spacing-sm);
}

.form-row {
  margin-bottom: var(--spacing-md);
}

.form-row label {
  display: block;
  margin-bottom: var(--spacing-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-primary);
}

.add-button-margin {
  margin-bottom: var(--spacing-lg);
}

/* ============================================
   INPUTS CON SUFIJOS
   ============================================ */

.input-with-percentage-suffix,
.input-with-currency-suffix {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.input-with-percentage-suffix .form-control,
.input-with-currency-suffix .form-control {
  flex-grow: 1;
  width: auto;
}

.percentage-suffix,
.currency-suffix {
  font-weight: var(--font-weight-semibold);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}

/* ============================================
   SECCIÓN DE TOTALES
   ============================================ */

.totals-row {
  background: linear-gradient(135deg, var(--bg-tertiary) 0%, #e0e4e7 100%);
  border-top: 3px solid var(--border-color);
  font-weight: var(--font-weight-bold);
  color: var(--text-primary);
}

.totals-cell {
  background: linear-gradient(135deg, var(--bg-tertiary) 0%, #e0e4e7 100%);
  padding: var(--spacing-md) var(--spacing-sm);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
}

.totals-breakdown-row {
  background-color: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: var(--font-weight-medium);
}

.separator {
  border: none;
  border-top: 2px solid var(--border-color-light);
  margin: var(--spacing-xl) 0;
}

/* ============================================
   COSTES DE ENSAMBLAJE
   ============================================ */

.assembly-cost-header,
.assembly-cost-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 0.5fr;
  gap: var(--spacing-md);
  align-items: center;
  margin-bottom: var(--spacing-sm);
  padding: var(--spacing-sm) 0;
}

.assembly-cost-header {
  font-weight: var(--font-weight-bold);
  padding-bottom: var(--spacing-md);
  border-bottom: 2px solid var(--border-color);
  color: var(--text-primary);
}

.assembly-cost-row {
  transition: background-color var(--transition-fast);
}

.assembly-cost-row:hover {
  background-color: var(--bg-hover);
  border-radius: var(--border-radius-sm);
}

.assembly-cost-row .delete-checkbox {
  text-align: center;
}

/* ============================================
   GRUPOS DE FORMULARIO
   ============================================ */

.budget-name-group {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  width: 100%;
}

.budget-info-row {
  margin-top: var(--spacing-md);
}

.budget-name-group label {
  flex-shrink: 0;
  font-weight: var(--font-weight-semibold);
}

.budget-name-group .form-control {
  flex-grow: 1;
}

/* ============================================
   FILA DE BOTONES
   ============================================ */

.submit-row {
  display: flex;
  gap: var(--spacing-md);
  justify-content: flex-start;
  padding: var(--spacing-lg) 0;
  margin-top: var(--spacing-lg);
  border-top: 2px solid var(--border-color-light);
  flex-wrap: wrap;
}

.submit-row form {
  display: inline-block;
  margin: 0;
  padding: 0;
  vertical-align: middle;
}

.submit-row form .button {
  width: auto;
  min-width: 140px;
  height: 42px;
  margin: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
}

.submit-row .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  white-space: nowrap;
  min-width: 140px;
  height: 42px;
}

/* ============================================
   SISTEMA DE BOTONES MEJORADO
   ============================================ */

.button {
  padding: 0.625rem 1.25rem;
  border-radius: var(--border-radius-sm);
  font-weight: 500;
  font-size: 0.875rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
  line-height: 1.5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.button:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.button:disabled,
.button.disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.button:disabled:hover,
.button.disabled:hover {
  transform: none;
  box-shadow: var(--shadow-sm);
}

/* Botones de acción pequeños */
.button.action-button {
  padding: var(--spacing-sm) var(--spacing-md);
  line-height: 1;
  min-width: 36px;
  min-height: 36px;
  text-align: center;
  justify-content: center;
  border-radius: var(--border-radius-sm);
}

.button-link {
  display: inline-block;
  padding: 2px 3px;
  margin: 2px 0;
  box-shadow: none;
}

.button-link:hover {
  transform: none;
  box-shadow: none;
}

/* Variantes de botones */
.button.action-button.danger {
  background: var(--color-danger);
  color: var(--text-light);
}

.button.action-button.danger:hover {
  background: var(--color-danger-hover);
}

.button.action-button.warning {
  background: var(--color-warning);
  color: var(--text-primary);
}

.button.action-button.warning:hover {
  background: var(--color-warning-hover);
}

.button.action-button.info {
  background: var(--color-info);
  color: var(--text-light);
}

.button.action-button.info:hover {
  background: var(--color-info-hover);
}

.button.action-button.default {
  background: var(--color-default);
  color: var(--text-light);
}

.button.action-button.default:hover {
  background: var(--color-default-hover);
}

.green-button {
  background: var(--color-success);
  color: var(--text-light);
}

.green-button:hover {
  background: var(--color-success-hover);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.yellow-button {
  background: var(--color-warning);
  color: var(--text-primary);
}

.yellow-button:hover {
  background: var(--color-warning-hover);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.red-button {
  background: var(--color-danger);
  color: var(--text-light);
}

.red-button:hover {
  background: var(--color-danger-hover);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.edit-button {
  background: var(--primary);
  color: var(--text-light);
}

.edit-button:hover {
  background: #0d8fa8;
  box-shadow: 0 4px 12px rgba(17, 165, 201, 0.3);
}

/* Botón primario por defecto */
.button.default {
  background: var(--color-default);
  color: var(--text-light);
}

.button.default:hover {
  background: var(--color-default-hover);
}

/* ============================================
   FORMULARIOS MEJORADOS
   ============================================ */

.form-control {
  padding: 0.5rem 0.75rem;
  border: 1px solid #cbd5e1;
  border-radius: var(--border-radius-sm);
  font-size: 0.9rem;
  height: 40px;
  transition: all 0.15s ease-in-out;
  background: #ffffff;
  color: #1e293b;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(17, 165, 201, 0.15);
}

.form-control:disabled {
  background: var(--bg-secondary);
  cursor: not-allowed;
  opacity: 0.6;
}

.form-control::placeholder {
  color: var(--text-muted);
}

/* Errores de formulario */
.text-danger,
.errornote {
  color: var(--color-danger);
  font-size: var(--font-size-sm);
  margin-top: var(--spacing-xs);
  display: block;
}

.alert {
  padding: var(--spacing-md);
  border-radius: var(--border-radius-sm);
  margin-bottom: var(--spacing-md);
  border-left: 4px solid;
}

.alert-danger {
  background-color: #f8d7da;
  border-color: var(--color-danger);
  color: #721c24;
}

.alert-success {
  background-color: #d4edda;
  border-color: var(--color-success);
  color: #155724;
}

.alert-info {
  background-color: #d1ecf1;
  border-color: var(--color-info);
  color: #0c5460;
}

.alert-warning {
  background-color: #fff3cd;
  border-color: var(--color-warning);
  color: #856404;
}

/* ============================================
   CHECKBOXES Y RADIOS
   ============================================ */

.form-row.with-inline-checkbox {
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-lg);
  flex-wrap: wrap;
}

.form-row.with-inline-checkbox .checkbox-group {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-top: 0;
}

.form-row.with-inline-checkbox .checkbox-group .help-text {
  font-style: italic;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  visibility: hidden;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.form-row.with-inline-checkbox .checkbox-group input[type="checkbox"]:hover+.help-text,
.form-row.with-inline-checkbox .checkbox-group input[type="checkbox"]:checked+.help-text {
  visibility: visible;
  opacity: 1;
}

/* ============================================
   BÚSQUEDA Y FILTROS
   ============================================ */

.search-module {
  background: var(--bg-secondary);
  padding: var(--spacing-md);
  border-radius: var(--border-radius);
  margin-bottom: var(--spacing-lg);
}

.search-form-container {
  display: flex;
  gap: var(--spacing-sm);
  align-items: center;
  flex-wrap: wrap;
}

.search-form-container {
  position: relative;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: var(--spacing-sm) var(--spacing-md);
  padding-left: 40px;
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  font-size: var(--font-size-base);
  transition: all var(--transition-base);
  background: var(--bg-card);
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(17, 165, 201, 0.1);
}

/* ============================================
   CARDS Y COMPONENTES MODERNOS
   ============================================ */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color-light);
  border-radius: var(--border-radius);
  padding: var(--spacing-lg);
  margin-bottom: var(--spacing-lg);
  box-shadow: var(--shadow-card);
  transition: all var(--transition-base);
}

.card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.card-header {
  padding-bottom: var(--spacing-md);
  margin-bottom: var(--spacing-md);
  border-bottom: 2px solid var(--border-color-light);
}

.card-body {
  padding: var(--spacing-md) 0;
}

.card-footer {
  padding-top: var(--spacing-md);
  margin-top: var(--spacing-md);
  border-top: 1px solid var(--border-color-light);
}

/* Badges */
.badge {
  display: inline-block;
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  vertical-align: baseline;
  border-radius: var(--border-radius-sm);
}

.badge-success {
  background-color: var(--color-success);
  color: var(--text-light);
}

.badge-warning {
  background-color: var(--color-warning);
  color: var(--text-primary);
}

.badge-danger {
  background-color: var(--color-danger);
  color: var(--text-light);
}

.badge-info {
  background-color: var(--color-info);
  color: var(--text-light);
}

.badge-default {
  background-color: var(--color-default);
  color: var(--text-light);
}

/* ============================================
   INFORMACIÓN DEL PRESUPUESTO
   ============================================ */

.budget-info-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-lg);
}

.budget-info-item {
  background: var(--bg-secondary);
  padding: var(--spacing-md);
  border-radius: var(--border-radius-sm);
  border-left: 4px solid var(--primary);
}

.budget-info-item strong {
  display: block;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-bottom: var(--spacing-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.budget-info-item span {
  display: block;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

.metric-card {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-secondary) 100%);
  border: 1px solid var(--border-color-light);
  border-radius: var(--border-radius);
  padding: var(--spacing-lg);
  text-align: center;
  box-shadow: var(--shadow-card);
}

.metric-value {
  font-size: var(--font-size-xxl);
  font-weight: var(--font-weight-bold);
  color: var(--primary);
  margin: var(--spacing-sm) 0;
  padding-top: var(--spacing-sm);
}

.metric-label {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ============================================
   DETALLES DE COSTES
   ============================================ */

.cost-details-content {
  padding: 1.25rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--border-radius-sm);
  margin: 0.75rem 1rem;
  box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.02);
}

.cost-details-table {
  width: 100%;
  margin: 0;
}

.cost-details-table th {
  background: var(--bg-tertiary);
  font-weight: var(--font-weight-semibold);
  padding: var(--spacing-sm) var(--spacing-md);
}

.cost-details-table td {
  padding: var(--spacing-sm) var(--spacing-md);
  border-bottom: 1px solid var(--border-color-light);
}

.additional-costs-sub-header {
  background: var(--bg-tertiary);
  font-weight: var(--font-weight-semibold);
}

/* ============================================
   DESGLOSE (BREAKDOWN)
   ============================================ */

.breakdown-content {
  padding: 1.25rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--border-radius-sm);
  margin: 0.75rem 1rem;
  box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.02);
}

/* Limpieza de padding en filas desplegables */
.cost-details-row td,
.breakdown-row td {
  padding: 0 !important;
}

/* ============================================
   RESULTADOS VACÍOS
   ============================================ */

.empty-state {
  text-align: center;
  padding: var(--spacing-xxl);
  color: var(--text-secondary);
}

.empty-state i {
  font-size: var(--font-size-xxxl);
  color: var(--text-muted);
  margin-bottom: var(--spacing-md);
  display: block;
}

.empty-state p {
  font-size: var(--font-size-lg);
  margin-bottom: var(--spacing-md);
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Tablets */
@media (max-width: 1024px) {
  .settings-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: var(--spacing-md);
  }

  .budget-info-card {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .submit-row {
    flex-direction: column;
  }

  .submit-row .button {
    width: 100%;
    justify-content: center;
  }
}

/* Móviles */
@media (max-width: 768px) {
  .module {
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
  }

  h1 {
    font-size: var(--font-size-xl);
  }

  h2 {
    font-size: var(--font-size-lg);
  }

  .settings-grid {
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
  }

  .search-form-container {
    flex-direction: column;
  }

  .search-input {
    width: 100%;
    min-width: unset;
  }

  .search-form-container .button {
    width: 100%;
  }

  /* Convertir tablas en cards en móviles */
  .table-responsive {
    overflow-x: visible;
  }

  #budget-lines-table,
  #result_list {
    display: block;
    min-width: unset;
  }

  #budget-lines-table thead,
  #result_list thead {
    display: none;
  }

  #budget-lines-table tbody,
  #result_list tbody {
    display: block;
  }

  #budget-lines-table tbody tr,
  #result_list tbody tr {
    display: block;
    margin-bottom: var(--spacing-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color-light);
    border-radius: var(--border-radius);
    padding: var(--spacing-md);
    box-shadow: var(--shadow-card);
  }

  #budget-lines-table tbody td,
  #result_list tbody td {
    display: flex;
    justify-content: space-between;
    padding: var(--spacing-sm) 0;
    border-bottom: 1px solid var(--border-color-light);
    text-align: right;
  }

  #budget-lines-table tbody td:before,
  #result_list tbody td:before {
    content: attr(data-label);
    font-weight: var(--font-weight-semibold);
    text-align: left;
    color: var(--text-secondary);
    flex: 1;
  }

  #budget-lines-table tbody td:last-child,
  #result_list tbody td:last-child {
    border-bottom: none;
  }

  #result_list tfoot {
    display: none;
  }

  .actions-cell {
    justify-content: flex-end !important;
    padding-top: var(--spacing-md);
  }

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

  .assembly-cost-header,
  .assembly-cost-row {
    grid-template-columns: 1fr;
    gap: var(--spacing-sm);
  }

  .assembly-cost-header {
    display: none;
  }

  .assembly-cost-row>div:before {
    content: attr(data-label);
    font-weight: var(--font-weight-semibold);
    display: block;
    margin-bottom: var(--spacing-xs);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
  }

  .submit-row {
    flex-direction: column;
  }

  .submit-row .button {
    width: 100%;
    justify-content: center;
  }

  .button.action-button {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Móviles pequeños */
@media (max-width: 480px) {
  .module {
    padding: var(--spacing-sm);
  }

  h1 {
    font-size: var(--font-size-xl);
  }

  h2 {
    font-size: var(--font-size-lg);
  }

  .button {
    padding: var(--spacing-sm);
    font-size: var(--font-size-sm);
  }
}

/* ============================================
   UTILIDADES
   ============================================ */

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

.text-right {
  text-align: right;
}

.text-left {
  text-align: left;
}

.mb-0 {
  margin-bottom: 0;
}

.mb-sm {
  margin-bottom: var(--spacing-sm);
}

.mb-md {
  margin-bottom: var(--spacing-md);
}

.mb-lg {
  margin-bottom: var(--spacing-lg);
}

.mt-0 {
  margin-top: 0;
}

.mt-sm {
  margin-top: var(--spacing-sm);
}

.mt-md {
  margin-top: var(--spacing-md);
}

.mt-lg {
  margin-top: var(--spacing-lg);
}

.p-0 {
  padding: 0;
}

.p-sm {
  padding: var(--spacing-sm);
}

.p-md {
  padding: var(--spacing-md);
}

.p-lg {
  padding: var(--spacing-lg);
}

/* ============================================
   SELECT2 INTEGRATION
   ============================================ */

.select2-container--default .select2-selection--single {
  height: 40px !important;
  border: 1px solid #cbd5e1 !important;
  border-radius: var(--border-radius-sm) !important;
  padding: 0.5rem 0.75rem !important;
  font-size: 0.9rem !important;
  background-color: #ffffff !important;
  transition: all 0.15s ease-in-out !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 24px !important;
  padding-left: 0 !important;
  color: #1e293b !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
  height: 38px !important;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 3px rgba(17, 165, 201, 0.15) !important;
  outline: none !important;
}

.select2-dropdown {
  border: 1px solid #cbd5e1 !important;
  border-radius: var(--border-radius-sm) !important;
  box-shadow: var(--shadow-md) !important;
}

.select2-results__option--highlighted {
  background-color: rgba(17, 165, 201, 0.1) !important;
  color: #1e293b !important;
}

.select2-results__option--selected {
  background-color: rgba(17, 165, 201, 0.08) !important;
  color: #1e293b !important;
}

/* ============================================
   INDICADOR DE SINCRONIZACIÓN
   ============================================ */

#sync-status-panel {
  background: #fafafb;
  border: 1px solid #e2e8f0;
  border-radius: var(--border-radius);
  padding: 1.25rem;
  box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.02);
  margin-bottom: 1rem;
}

#sync-status-panel p {
  margin: 0.35rem 0;
}

/* ============================================
   BOTONES ADICIONALES Y VARIANTES
   ============================================ */

.button.primary,
.button.edit-button {
  background: var(--primary);
  color: var(--text-light);
}

.button.primary:hover,
.button.edit-button:hover {
  background: #0d8fa8;
  box-shadow: 0 4px 12px rgba(17, 165, 201, 0.3);
}

.button.info {
  background: var(--color-info);
  color: var(--text-light);
}

.button.info:hover {
  background: var(--color-info-hover);
}

.button.action-button.success {
  background: var(--color-success);
  color: var(--text-light);
}

.button.action-button.success:hover {
  background: var(--color-success-hover);
}

/* ============================================
   TABLAS ANIDADAS (desglose / costes)
   ============================================ */

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
  background: var(--bg-card);
}

.table th,
.table td {
  padding: 0.5rem 0.75rem;
  vertical-align: middle;
}

.table-bordered th,
.table-bordered td {
  border: 1px solid var(--border-color);
}

.table-sm th,
.table-sm td {
  padding: 0.35rem 0.5rem;
}

.table thead th {
  background: var(--bg-secondary);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

/* ============================================
   VALORES MONETARIOS SEMÁNTICOS
   ============================================ */

.value-cost {
  color: var(--color-danger);
}

.value-sale {
  color: var(--color-success);
}

.value-margin {
  color: var(--primary);
}

.metric-value.value-cost {
  border-top: 3px solid var(--color-danger);
}

.metric-value.value-sale {
  border-top: 3px solid var(--color-success);
}

.metric-value.value-margin {
  border-top: 3px solid var(--primary);
}

.metric-value.value-profit {
  border-top: 3px solid var(--color-success);
  color: var(--color-success);
}

.budget-link {
  font-weight: var(--font-weight-semibold);
  color: var(--primary);
  text-decoration: none;
}

.budget-link:hover {
  text-decoration: underline;
}

/* ============================================
   LAYOUT Y UTILIDADES
   ============================================ */

.module-full-width {
  width: 100%;
  max-width: none;
}

.form-row-block {
  margin-top: var(--spacing-md);
}

.flex-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-md);
  align-items: center;
}

.flex-row-end {
  display: flex;
  justify-content: flex-end;
  gap: var(--spacing-sm);
  width: 100%;
}

.flex-row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
  width: 100%;
}

.actions-group {
  display: flex;
  gap: var(--spacing-xs);
  justify-content: flex-end;
}

.submit-row-actions {
  display: flex;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
  align-items: center;
}

.submit-row-export {
  display: flex;
  justify-content: flex-end;
  gap: var(--spacing-sm);
  margin-left: auto;
}

.submit-row {
  justify-content: space-between;
}

.small {
  font-size: var(--font-size-sm);
}

.mt-2 {
  margin-top: var(--spacing-sm);
}

.text-info {
  color: var(--color-info);
}

.text-right-bold {
  text-align: right;
  font-weight: var(--font-weight-bold);
}

.text-center-bold {
  text-align: center;
  font-weight: var(--font-weight-bold);
}

.totals-cell-lg {
  font-size: 1.2em;
}

.totals-cell-md {
  font-size: 1.1em;
}

.note-text {
  font-style: italic;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}

.load-defaults-form {
  margin-bottom: var(--spacing-lg);
}

.action-form,
.delete-form {
  display: inline-block;
  margin: 0;
}

.add-row-container {
  display: flex;
  justify-content: flex-end;
  gap: var(--spacing-sm);
  width: 100%;
  margin-bottom: var(--spacing-md);
}

.search-form-container .search-icon {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  z-index: 1;
  pointer-events: none;
}

.visually-hidden {
  display: none;
}

/* ============================================
   MENSAJES FLASH
   ============================================ */

.messages-container {
  margin-bottom: var(--spacing-lg);
}

.messages-container .alert {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

/* ============================================
   SYNC INDICATOR — ESTADOS
   ============================================ */

#top-sync-indicator {
  background: rgba(17, 165, 201, 0.06);
  color: #0e839f;
  padding: 0.75rem 1.25rem;
  border-radius: 9999px;
  border: 1px solid rgba(17, 165, 201, 0.15);
  font-weight: 500;
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

.sync-fresh,
#top-sync-icon.sync-fresh {
  color: var(--color-success);
}

.sync-stale,
#top-sync-icon.sync-stale {
  color: var(--color-warning);
}

.sync-old,
#top-sync-icon.sync-old {
  color: var(--color-danger);
}

.sync-never,
#top-sync-icon.sync-never {
  color: var(--color-default);
}

#last-sync-time.sync-fresh {
  color: var(--color-success);
}

#last-sync-time.sync-stale {
  color: var(--color-warning);
}

#last-sync-time.sync-old {
  color: var(--color-danger);
}

.sync-actions {
  display: flex;
  gap: var(--spacing-sm);
  margin-top: 1rem;
  flex-wrap: wrap;
}

/* ============================================
   GRID DE 3 COLUMNAS (descuentos)
   ============================================ */

.assembly-cost-grid-3,
.assembly-cost-grid-3.assembly-cost-header,
.assembly-cost-grid-3.assembly-cost-row {
  grid-template-columns: 1fr 1fr 100px;
}

/* ============================================
   TOAST DE NOTIFICACIÓN
   ============================================ */

.toast-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: var(--z-modal);
  min-width: 280px;
  box-shadow: var(--shadow-lg);
}

/* ============================================
   SUBMIT ROW DETALLE
   ============================================ */

@media (min-width: 769px) {
  .submit-row {
    flex-direction: row;
    align-items: center;
  }

  .submit-row-actions {
    flex: 1;
  }

  .submit-row-export {
    flex: 0 0 auto;
    width: auto;
  }
}