:root {
  --font-inter: 'Inter', sans-serif;
}

body {
  font-family: var(--font-inter);
  background-color: #f1f5f9;
  /* Slate 100 */
  color: #334155;
  /* Slate 700 */
}

/* Scrollbar personalizada */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Estilos de Inputs y Selects */
.filter-input,
.filter-select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  background-color: #fff;
  color: #475569;
  transition: all 0.2s;
  outline: none;
}

.filter-input:focus,
.filter-select:focus {
  border-color: #6366f1;
  /* Indigo 500 */
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Botones de Filtro */
.filter-button {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.25rem;
  width: 100%;
  padding: 0.5rem;
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  color: #64748b;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-button:hover {
  background-color: #e2e8f0;
  color: #334155;
}

/* Icon Button */
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 0.375rem;
  border: 1px solid #e2e8f0;
  background-color: white;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s;
}

.icon-button:hover {
  background-color: #f1f5f9;
  color: #3b82f6;
  border-color: #cbd5e1;
}

/* Botón Guardar (Recurrentes) */
.save-button {
  background-color: #6366f1;
  /* Indigo 500 */
  color: white;
  border: 1px solid #4f46e5;
}

.save-button:hover {
  background-color: #4f46e5;
  /* Indigo 600 */
  color: white;
}

/* Filas con estados */
.row-overdue {
  background-color: #fef2f2 !important;
  /* Red 50 */
  color: #991b1b !important;
  /* Red 800 */
}

.row-overdue td:first-child {
  border-left: 4px solid #ef4444 !important;
  /* Red 500 */
}

.row-due-today {
  background-color: #fff7ed !important;
  /* Orange 50 */
  color: #9a3412 !important;
  /* Orange 800 */
}

.row-due-today td:first-child {
  border-left: 4px solid #f97316 !important;
  /* Orange 500 */
}

.row-due-tomorrow {
  background-color: #fefce8 !important;
  /* Yellow 50 */
  color: #854d0e !important;
  /* Yellow 800 */
}

.row-due-tomorrow td:first-child {
  border-left: 4px solid #eab308 !important;
  /* Yellow 500 */
}

.row-consolidated {
  background-color: #f8fafc;
  /* Slate 50 */
  color: #94a3b8;
  /* Slate 400 */
  font-style: italic;
}

/* Celdas Editables */
.editable-cell[contenteditable="true"] {
  background-color: #fff;
  box-shadow: inset 0 0 0 2px #6366f1;
  border-radius: 4px;
  padding: 4px 8px;
}

/* Sticky Headers para la tabla */
thead tr th {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: #f8fafc;
  /* Slate 50 */
}

/* La segunda fila del header (filtros) debe estar justo debajo de la primera */
thead tr:nth-child(2) th {
  top: 48px;
  /* Ajuste preciso: altura fila 1 con py-4 es ~48px */
  z-index: 9;
}

/* =========================================
   ESTILOS PARA MÓVILES (Card View)
   ========================================= */
@media (max-width: 768px) {

  /* Ocultar encabezados de tabla normal */
  thead {
    display: none;
  }

  /* MOSTRAR FILTROS CUANDO ESTÁ ACTIVO */
  thead.show-mobile-filters {
    display: block !important;
    background-color: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 1rem;
    border-radius: 0.75rem;
    padding: 1rem;
  }

  /* Ocultar títulos de columnas (Primera Fila) siempre en móvil */
  thead.show-mobile-filters tr:first-child {
    display: none;
  }

  /* Mostrar segunda fila (Filtros) como Grid */
  thead.show-mobile-filters tr:nth-child(2) {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  /* Resetear estilos de TH para que parezcan inputs */
  thead.show-mobile-filters tr:nth-child(2) th {
    display: block;
    padding: 0;
    top: auto;
    position: static;
    width: auto !important;
    background: transparent;
  }

  /* Ocultar columna de acciones en filtros */
  thead.show-mobile-filters tr:nth-child(2) th:first-child {
    display: none;
  }

  /* Labels para los filtros (Pseudo-elementos) */
  thead.show-mobile-filters tr:nth-child(2) th::before {
    content: attr(data-filter-label);
    /* Necesitaremos añadir esto al HTML */
    display: block;
    text-align: left;
    font-size: 0.7rem;
    color: #64748b;
    margin-bottom: 0.25rem;
    font-weight: 600;
    text-transform: uppercase;
  }

  /* Resetear comportamiento de tabla para que ocupe todo el ancho */
  table,
  tbody,
  tfoot,
  tr,
  td {
    display: block;
    width: 100%;
  }

  /* Convertir filas en tarjetas (Body y Footer) */
  tbody tr,
  tfoot tr {
    margin-bottom: 1rem;
    background-color: white;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    padding: 0.75rem;
  }

  /* Estilos específicos para el FOOTER en móvil */
  tfoot tr {
    margin-top: 1rem;
    background-color: #f8fafc;
    /* Diferenciar ligeramente */
  }

  tfoot td {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0.75rem 0;
    border: none;
    text-align: left;
  }

  /* Ocultar celdas vacías en footer móvil */
  tfoot td:empty {
    display: none !important;
  }

  /* Ajustar la celda del Label para que use Flex */
  tfoot td:first-child {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  tfoot td:first-child .flex {
    width: 100%;
    justify-content: space-between;
  }

  /* Aumentar tamaño del Total */
  tfoot #totalMontoVisible {
    justify-content: flex-end;
    font-size: 1.5rem;
    color: #4f46e5;
    padding-top: 0;
  }

  /* =============== LOGICA COLAPSABLE =============== */

  /* Por defecto en móvil, ocultar columnas secundarias */
  tbody td[data-col="tipo"],
  tbody td[data-col="categoria"],
  tbody td[data-col="subcategoria"],
  tbody td[data-col="periodicidad"],
  tbody td[data-col="metodo"],
  tbody td[data-col="observaciones"] {
    display: none !important;
  }

  /* Mostrar cuando la fila tiene clase expanded */
  tbody tr.expanded td[data-col="tipo"],
  tbody tr.expanded td[data-col="categoria"],
  tbody tr.expanded td[data-col="subcategoria"],
  tbody tr.expanded td[data-col="periodicidad"],
  tbody tr.expanded td[data-col="metodo"],
  tbody tr.expanded td[data-col="observaciones"] {
    display: flex !important;
    animation: fadeIn 0.3s ease;
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateY(-5px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Indicador visual de expansión (Chevron) */
  tbody tr {
    position: relative;
    cursor: pointer;
    transition: transform 0.1s;
  }

  tbody tr:active {
    transform: scale(0.99);
  }

  tbody tr::after {
    content: '';
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 0.6rem;
    height: 0.6rem;
    border-right: 2px solid #cbd5e1;
    border-bottom: 2px solid #cbd5e1;
    transform: rotate(45deg);
    transition: all 0.3s;
  }

  tbody tr.expanded::after {
    transform: rotate(-135deg);
    top: 1.2rem;
    border-color: #6366f1;
  }

  /* Celdas como filas flexibles */
  tbody td {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid #f1f5f9;
    text-align: right;
    min-height: 2rem;
  }

  tbody td:last-child {
    border-bottom: none;
  }

  /* Inyectar etiquetas de columna */
  tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #64748b;
    font-size: 0.75rem;
    text-transform: uppercase;
    margin-right: 1rem;
    text-align: left;
    flex-shrink: 0;
  }

  /* Ajustes específicos para celdas */
  .icon-button {
    padding: 4px;
    width: 28px;
    height: 28px;
  }

  /* Asegurar que la primera celda tenga estilo HEADER UNIFICADO (BLANCO) */
  tbody td:first-child {
    /* background-color: #ffffff !important; */
    /* Blanco */
    margin: -0.75rem -0.75rem 0 -0.75rem;
    /* Pegado arriba y lados */
    padding: 0.75rem 1rem 0 1rem;
    /* Padding interno */
    border-radius: 0.75rem 0.75rem 0 0;
    /* Bordes redondeados superiores */
    border-bottom: none;
    border-left: none !important;
    display: flex;
    justify-content: flex-start;
  }

  /* IMPORTANTE: Ocultar el label "ACCIONES" generado por JS/CSS */
  tbody td:first-child::before {
    content: none !important;
    display: none !important;
  }

  /* Estilo para la celda de FECHA (Parte inferior del Header - BLANCO) */
  tbody td[data-col="fecha"] {
    /* background-color: #ffffff !important; */
    /* Blanco */
    color: #334155;
    /* Slate 700 (Texto normal oscuro) */
    margin: 0 -0.75rem 0.5rem -0.75rem;
    /* Pegado lados y margen abajo */
    padding: 0.25rem 1rem 0.75rem 1rem;
    /* Padding interno */
    border-bottom: 1px solid #e2e8f0;
    /* Borde gris suave */
    width: calc(100% + 1.5rem);
    border-radius: 0 0 0 0;
    /* Recto */
  }

  /* =========================================
     MEJORAS VISUALES MÓVIL (BORDES DE ESTADO)
     ========================================= */

  /* 1. SELECCIONADO / EXPANDIDO (Indigo) */
  tbody tr.expanded {
    border: 2px solid #6366f1 !important;
    /* Indigo 500 */
  }

  /* 2. VENCIDO (Rojo) */
  tbody tr.row-overdue {
    border: 2px solid #ef4444 !important;
    /* Red 500 */
    background-color: white !important;
  }

  tbody tr.row-overdue td:first-child {
    border-left: none !important;
  }

  /* 3. HOY (Naranja) */
  tbody tr.row-due-today {
    border: 2px solid #f97316 !important;
    /* Orange 500 */
    background-color: white !important;
  }

  tbody tr.row-due-today td:first-child {
    border-left: none !important;
  }

  /* 4. MAÑANA (Amarillo) */
  tbody tr.row-due-tomorrow {
    border: 2px solid #eab308 !important;
    /* Yellow 500 */
    background-color: white !important;
  }

  tbody tr.row-due-tomorrow td:first-child {
    border-left: none !important;
  }

}
