/* ============================================================================
   BASE GENÉRICA (otros modales del sitio)
   ============================================================================ */
.modal {
  display: none;                 /* oculto por defecto */
  position: fixed;
  left: 0; top: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(0,0,0,0.8);
  align-items: center;           /* no afecta mientras esté oculto */
  justify-content: center;
  z-index: 999999;               /* alto, pero no al máximo */
  padding-top: 80px;
}
.modal.is-open { display: flex; }

.modal-content {
  position: relative;
  background-color: #fff;
  border-radius: 10px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
  padding: 0;
}

.close-btn {
  position: absolute;
  top: 10px; right: 15px;
  font-size: 24px;
  cursor: pointer;
  font-weight: bold;
  color: #ff0000;
  background: none;
  border: none;
  z-index: 10000;
}

/* ============================================================================
   SECCIÓN DE SUBIDA (estilo original, ahora en CSS)
   ============================================================================ */
#importar-csv-section {
  display: none;                 /* oculto por defecto */
  margin-top: 5px;
  padding: 15px;
  border: 2px solid #ccc;
  background-color: #1a1a1a;
  text-align: center;
  border-radius: 8px;
  max-width: 350px;
  margin-left: auto;
  margin-right: auto;
}
#importar-csv-section.is-open { display: block !important; }

#importar-csv-section h3 {
  color: #ffffff;
  font-size: 14px;
  margin-bottom: 10px;
}

.file-input-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#file-input-csv {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.custom-file-button {
  background-color: #ffffff;
  color: #000000;
  border: none;
  padding: 8px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  display: inline-block;
}
.custom-file-button:hover { background-color: #dddddd; }

.file-name {
  font-size: 14px;
  color: #bbbbbb;
  margin-top: 5px;
  text-align: center;
}

#importar-csv-section button {
  background-color: #007bff;
  color: #ffffff;
  border: none;
  padding: 10px 15px;
  font-size: 14px;
  border-radius: 5px;
  cursor: pointer;
  margin-top: 5px;
  width: auto;
  font-weight: bold;
}
#importar-csv-section button:hover { background-color: #0069d9; }

/* ============================================================================
   MODAL DE IMPORTACIÓN CSV (específico, sin tocar otros)
   ============================================================================ */
#importar-csv-modal {
  position: fixed;
  inset: 0;
  display: none;                 /* oculto por defecto */
  align-items: flex-start;       /* ancla el contenido arriba */
  justify-content: center;
  background: rgba(0,0,0,.80);
  z-index: 2147483646;
  -webkit-overflow-scrolling: touch;
  padding-top: 20px;
}
#importar-csv-modal.is-open { display: flex; }

/* Panel del modal: shrink-wrap al contenido */
#importar-csv-modal .modal-content {
  position: relative;
  z-index: 2147483647;

  display: inline-flex;          /* columna pero sin estirar hijos */
  flex-direction: column;
  align-items: flex-start;       /* evita stretch horizontal */

  /* 👇 clave para quitar el “espacio blanco” */
  width: max-content !important; /* ancho = contenido real */
  max-width: calc(96vw - 24px);  /* límite por pantalla */
  max-height: 90vh;

  overflow: auto;
  background: #fff;
  color: #000;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,.5);
  padding: 20px 16px 28px;
}

/* Fallback (navegadores viejos) */
@supports not (width: max-content) {
  #importar-csv-modal .modal-content { width: auto !important; }
}

/* Cierre: SOLO .close-btn-csv */
#importar-csv-modal .close-btn-csv {
  position: sticky;
  top: 0;
  align-self: flex-end;
  margin-left: auto;
  display: inline-block;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  margin: 8px 8px 12px 8px;
  padding: 6px 10px;
  color: #c1121f !important;
  cursor: pointer;
  background: transparent !important;
  border: 0 !important;
  outline: none;
  box-shadow: none !important;
  text-shadow: none !important;
  appearance: none;
}

/* Botón Confirmar: centrado sin depender de flex */
#confirm-import-csv {
  margin: 24px auto 22px;        /* centra con auto */
  background-color: #28a745 !important;
  color: #ffffff !important;
  border: 0 !important;
  border-radius: 8px !important;
  padding: 12px 18px !important;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: none;                  /* el JS lo muestra */
  box-shadow: none !important;
  text-shadow: none !important;
  text-transform: none !important;
}
#confirm-import-csv:hover { filter: brightness(0.95); }

/* --------------------------------------------------------------------------
   PREVIEW: el bloque y tablas se miden por su contenido y se centran
   -------------------------------------------------------------------------- */
#csv-preview {
  align-self: flex-start;
  display: inline-block;         /* deja de ocupar 100% */
  width: max-content;            /* ancho = tablas reales */
  max-width: calc(96vw - 32px);  /* tope por pantalla */
  padding: 0 16px;
  overflow-x: auto;              /* respaldo si se pasa del ancho */
}

/* título principal del preview (si existe fuera/antes de las tablas) */
#importar-csv-modal #csv-preview > h2,
#importar-csv-modal .modal-content > h2:first-of-type {
  display: inline-block;         /* que NO haga 100% */
  width: auto;
  margin: 0 auto 8px;
  text-align: center;
}

/* wrappers de cada tabla: ancho según contenido y centrados */
#importar-csv-modal .tabla-operaciones,
#importar-csv-modal .tabla-transferencias {
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 0 auto 18px;
}

/* la tabla se ajusta al contenido (no llena el modal) */
#importar-csv-modal #csv-preview table {
  width: max-content !important;
  max-width: none !important;
  border-collapse: collapse;
  table-layout: auto !important;
  margin: 0;
}

/* celdas sin mínimos para poder encoger */
#importar-csv-modal #csv-preview th,
#importar-csv-modal #csv-preview td {
  min-width: 0 !important;
  max-width: none !important;
}

/* estilos base de celdas */
#csv-preview th,
#csv-preview td {
  text-align: left;
  vertical-align: top;
  white-space: normal;
  padding: 8px 10px;
  border: 1px solid #ddd;
}

/* encabezado: color y sticky */
#csv-preview thead th {
  background-color: #222;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 1;
}

/* -------- Operaciones (10 columnas) -------- */
.tabla-operaciones thead th { white-space: normal; } /* th pueden envolver */
.tabla-operaciones tbody td:nth-child(1),
.tabla-operaciones tbody td:nth-child(2),
.tabla-operaciones tbody td:nth-child(4),
.tabla-operaciones tbody td:nth-child(5),
.tabla-operaciones tbody td:nth-child(6),
.tabla-operaciones tbody td:nth-child(7),
.tabla-operaciones tbody td:nth-child(8),
.tabla-operaciones tbody td:nth-child(9),
.tabla-operaciones tbody td:nth-child(10) { white-space: nowrap; }
.tabla-operaciones tbody td:nth-child(5),
.tabla-operaciones tbody td:nth-child(6),
.tabla-operaciones tbody td:nth-child(7),
.tabla-operaciones tbody td:nth-child(8),
.tabla-operaciones tbody td:nth-child(9) { text-align: right; }
.tabla-operaciones th:nth-child(3),
.tabla-operaciones td:nth-child(3) {
  white-space: normal;
  word-break: break-word;
}

/* -------- Transferencias (4 columnas) -------- */
.tabla-transferencias thead th { white-space: normal; }
.tabla-transferencias tbody td:nth-child(1),
.tabla-transferencias tbody td:nth-child(3),
.tabla-transferencias tbody td:nth-child(4) { white-space: nowrap; }
.tabla-transferencias tbody td:nth-child(3) { text-align: right; }
.tabla-transferencias th:nth-child(2),
.tabla-transferencias td:nth-child(2) {
  white-space: normal;
  word-break: break-word;
}

/* Responsivo */
@media (max-width: 768px) {
  #importar-csv-modal .modal-content {
    max-width: 95vw;             /* sigue respetando el tope en móvil */
  }
  #csv-preview table { font-size: 12px; }
  #csv-preview th, #csv-preview td { padding: 6px; min-width: 0; }
}

/* Bloqueo de scroll del body cuando el modal está abierto */
body.fe-modal-open { overflow: hidden; }