/* ========================================
   MODERN FORMS - CSS GENÉRICO REUTILIZABLE
   ======================================== */

/* ========================================
   1. FORM CONTROLS UNIFICADOS
   ======================================== */

/* Base común para todos los form controls */
.form-control,
.form-control:focus,
select.form-control,
select.form-control:focus {
  background-color: #ffffff !important;
  border: 1px solid #e9ecef;
  border-radius: 6px;
  color: #495057;
  font-size: 0.875rem;
  line-height: 1.5;
  padding: 0.5rem 0.75rem;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
  box-shadow: none;
}

/* Estados focus unificados */
.form-control:focus,
select.form-control:focus {
  background-color: #ffffff !important;
  border-color: #007bff;
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.15);
}

/* Específico para selects - eliminar estilos del navegador */
select.form-control {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: 2.5rem;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* Input group para fechas */
.input-group .form-control {
  background-color: #ffffff !important;
  border-radius: 0 6px 6px 0;
  border-left: 0;
}

.input-group .form-control:focus {
  border-left: 1px solid #007bff;
}

.input-group-text {
  background-color: #f8f9fa;
  border: 1px solid #e9ecef;
  color: #6c757d;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border-radius: 6px 0 0 6px;
}

/* Labels con estilo consistente */
.info-label {
  color: #495057;
  font-weight: 500;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  display: block;
}

/* Placeholders con color consistente */
.form-control::placeholder,
select.form-control option:first-child {
  color: #9ca3af;
  opacity: 1;
}

/* Hover states para form controls */
.form-control:hover:not(:focus),
select.form-control:hover:not(:focus) {
  border-color: #d1d5db;
}

/* Disabled states */
.form-control:disabled,
select.form-control:disabled {
  background-color: #f8f9fa !important;
  border-color: #e9ecef;
  color: #6c757d;
  opacity: 1;
}

/* ========================================
   2. FILTERS CARD GENÉRICO
   ======================================== */

.filters-card {
  background: var(--modern-bg-white);
  border-radius: var(--modern-border-radius);
  box-shadow: var(--modern-shadow);
  border: 1px solid var(--modern-border-color);
  margin-bottom: 2rem;
}

.filters-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
}

.filters-title {
  font-size: 1rem;
  font-weight: 600;
  color: #495057;
  margin: 0;
}

/* Cuando los filtros están abiertos, agregar separador */
.filters-card:has(#filters-container:not([style*="display: none"])) .filters-header {
  border-bottom: 1px solid #f1f3f4;
}

#filters-container {
  padding: 1.5rem;
  padding-top: 1.25rem; /* Más espacio después de la línea separadora */
}

/* Acciones de filtros */
.filters-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 1.5rem;
  border-top: 1px solid #f1f3f4;
  margin-top: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.buttons-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ========================================
   3. BOTONES MINIMALISTAS GENÉRICOS
   ======================================== */

.btn-minimal {
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.875rem;
  transition: var(--modern-transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-minimal:hover {
  text-decoration: none;
}

.btn-minimal.btn-primary {
  background: #007bff;
  color: white;
}

.btn-minimal.btn-primary:hover {
  background: #0056b3;
  color: white;
  transform: translateY(-1px);
}

.btn-minimal.btn-success {
  background: #28a745;
  color: white;
}

.btn-minimal.btn-success:hover {
  background: #1e7e34;
  color: white;
  transform: translateY(-1px);
}

.btn-minimal.btn-outline {
  background: white;
  color: #6c757d;
  border: 1px solid #dee2e6;
}

.btn-minimal.btn-outline:hover {
  background: #f8f9fa;
  color: #495057;
  border-color: #adb5bd;
}

/* Botón collapse genérico */
.btn-collapse {
  border: none;
  background: none;
  color: var(--modern-text-muted);
  padding: 0.375rem;
  border-radius: 4px;
  transition: var(--modern-transition);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-collapse:hover {
  background-color: var(--modern-bg-light);
  color: var(--modern-primary-color);
}

.btn-collapse i {
  font-size: 0.75rem;
}

/* ========================================
   4. TABLE RESPONSIVE GENÉRICO
   ======================================== */

.table-card {
  background: var(--modern-bg-white);
  border-radius: var(--modern-border-radius);
  box-shadow: var(--modern-shadow);
  border: 1px solid var(--modern-border-color);
  overflow: hidden;
  width: 100%;
}

/* Contenedor responsive inteligente */
.table-responsive-smart {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

/* En pantallas grandes, asegurar que no haya scroll innecesario */
@media (min-width: 1200px) {
  .table-responsive-smart {
    overflow-x: visible;
  }
}

/* Tabla base que usa todo el ancho disponible */
.table-fixed {
  width: 100%;
  table-layout: fixed;
  margin: 0;
  min-width: 100%; /* Asegurar que use todo el ancho */
}

/* Para pantallas grandes, usar anchos más generosos */
@media (min-width: 1400px) {
  .table-fixed {
    min-width: 100%;
  }
}

/* Para pantallas medianas, usar min-width para scroll */
@media (min-width: 992px) and (max-width: 1399px) {
  .table-fixed {
    min-width: 1200px;
  }
}

/* Para pantallas pequeñas, usar min-width para scroll */
@media (max-width: 991px) {
  .table-fixed {
    min-width: 900px;
  }
}

/* Celdas que manejan overflow correctamente */
.table-fixed td {
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 0;
  padding: 0.75rem 0.5rem;
}

.table-fixed th {
  padding: 0.75rem 0.5rem;
}

/* Celda con texto truncado y tooltip */
.cell-truncate {
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  line-height: 1.3;
}

.cell-truncate span {
  display: inline-block;
  max-width: 100%;
  word-break: break-word;
}

.cell-truncate span[title] {
  cursor: help;
}

/* ========================================
   5. RESPONSIVE GENÉRICO
   ======================================== */

/* Mobile adjustments */
@media (max-width: 768px) {
  .filters-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .buttons-group {
    width: 100%;
    flex-direction: column;
  }

  .btn-minimal {
    width: 100%;
    justify-content: center;
  }

  .page-header .d-flex {
    flex-direction: column;
    align-items: stretch !important;
    gap: 1rem;
  }

  /* Evitar zoom en iOS */
  .form-control,
  select.form-control {
    font-size: 16px;
  }
}

@media (max-width: 576px) {
  .filters-header {
    padding: 1rem;
  }

  #filters-container {
    padding: 1rem;
    padding-top: 1rem;
  }

  .filters-actions {
    padding-top: 1rem;
    margin-top: 0.75rem;
  }
}

.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
  font-size: 0.875rem !important;
  font-weight: 400 !important;
  line-height: 1.5 !important;
  color: #495057 !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice {
  background-color: #007bff !important;
  border: 1px solid #007bff !important;
  color: #fff !important;
  font-size: 0.875rem !important;
}

.form-group .info-label {
  color: #495057 !important;
  font-weight: 500 !important;
  font-size: 0.875rem !important;
  margin-bottom: 0.5rem !important;
  display: block !important;
  line-height: 1.3 !important;
}

.info-label .text-danger {
  color: #dc3545 !important;
  font-weight: 700 !important;
}

/* ========================================
   6. BOTÓN EN HEADER DE TABLA
   ======================================== */

.tabla-header-boton {
  table-layout: fixed;
  width: 100%;
}

.tabla-header-boton .fila-header-accion {
  background: #f8fafc;
  border-bottom: 2px solid #e9ecef;
}

.tabla-header-boton .fila-header-accion th {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #64748b;
  padding: 1rem;
  border-top: none;
}

/* Botón fantasma/ghost */
.btn-header-ghost {
  background: transparent;
  color: #007bff;
  border: none;
  padding: 0.4375rem 0.625rem;
  border-radius: 6px;
  font-size: 0.8125rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  box-sizing: border-box;
  width: fit-content;
  max-width: 100%;
}

.btn-header-ghost:hover {
  background: #e7f3ff;
  color: #0056b3;
}

.btn-header-ghost i {
  font-size: 0.75rem;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.btn-header-ghost:hover i {
  transform: rotate(90deg);
}

.btn-header-ghost span {
  flex-shrink: 1;
  min-width: 0;
}

/* Tabla body limpia */
.tabla-header-boton tbody td {
  padding: 1rem;
  font-size: 0.875rem;
  color: #334155;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-top: 1px solid #f1f5f9;
}

.tabla-header-boton tbody tr:hover {
  background: #fafbfc;
}

/* Ajuste para evitar overflow del botón */
.tabla-header-boton .th-con-boton {
  padding-right: 1.5rem;
  padding-left: 0.5rem;
  white-space: nowrap;
  vertical-align: middle;
  overflow: visible;
  position: relative;
}

/* Contenedor del botón para controlar overflow */
.tabla-header-boton .th-con-boton > * {
  max-width: calc(100% - 0.5rem);
}

/* Responsive para botones en header */
@media (max-width: 1200px) {
  .tabla-header-boton .th-con-boton {
    padding-right: 0.875rem;
    padding-left: 0.5rem;
  }

  .btn-header-ghost {
    padding: 0.4375rem 0.625rem;
    font-size: 0.8125rem;
  }
}

@media (max-width: 992px) {
  .tabla-header-boton .th-con-boton {
    padding-right: 0.75rem;
    padding-left: 0.375rem;
  }

  .btn-header-ghost {
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
  }
}

/* Tablets - mantener texto */
@media (max-width: 768px) {
  .tabla-header-boton .fila-header-accion th {
    padding: 0.75rem 0.5rem;
    font-size: 0.75rem;
  }

  .tabla-header-boton .th-con-boton {
    padding-right: 0.625rem;
    padding-left: 0.375rem;
  }

  .btn-header-ghost {
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
  }
}

@media (max-width: 576px) {
  .tabla-header-boton .fila-header-accion th {
    padding: 0.625rem 0.375rem;
    font-size: 0.7rem;
  }

  .tabla-header-boton .th-con-boton {
    padding-right: 0.375rem;
    padding-left: 0.25rem;
  }

  .btn-header-ghost {
    padding: 0.3125rem 0.4375rem;
    font-size: 0.7rem;
  }

  .tabla-header-boton thead th:nth-child(3) {
    display: none;
  }

  .tabla-header-boton tbody td:nth-child(3) {
    display: none;
  }
}

/* Mobile muy pequeño - reducir tamaños pero MANTENER texto */
@media (max-width: 480px) {
  .tabla-header-boton .fila-header-accion th {
    padding: 0.5rem 0.25rem;
    font-size: 0.65rem;
  }

  .tabla-header-boton .th-con-boton {
    padding-right: 0.25rem;
    padding-left: 0.25rem;
  }

  .btn-header-ghost {
    padding: 0.3125rem 0.4375rem;
    font-size: 0.7rem;
    gap: 0.25rem;
  }

  .btn-header-ghost i {
    font-size: 0.65rem;
  }
}

/* Para pantallas extremadamente pequeñas */
@media (max-width: 400px) {
  .tabla-header-boton .fila-header-accion th {
    padding: 0.5rem 0.1875rem;
    font-size: 0.625rem;
  }

  .tabla-header-boton .th-con-boton {
    padding: 0.5rem 0.1875rem;
  }

  .btn-header-ghost {
    padding: 0.25rem 0.375rem;
    font-size: 0.65rem;
    gap: 0.1875rem;
  }

  .btn-header-ghost i {
    font-size: 0.625rem;
  }
}

