/* ═══════════════════════════════════════════════════════════════════════════════
   ATLAS EXPORT MODAL — ventana genérica "Personalize export" (js/utils/atlasExportModal.js)
   ═══════════════════════════════════════════════════════════════════════════════

   Plan 2026-09-17 F0 (§3.2). Sustituye al bloque `.pe-*` de css/pages/spools.css y al `<style>`
   inline de SpoolsManager.razor (residual del plan design-tokens F3, WARNINGS §38): mismo diseño,
   pero con tokens `--atlas-*` y sin un solo color a pelo, para que la ventana se vea igual en
   todas las páginas que la abran y siga los temas claro/oscuro del shell.

   Prefijo `.atlas-export-modal__*` (BEM plano) para no chocar con `.pe-*` mientras SMS migra.
*/

/* ── Contenedor ─────────────────────────────────────────────────────────────── */

.atlas-export-modal {
    /* Por encima de dropdowns/sticky de la tabla que la abre (--atlas-z-modal = 1080). */
    z-index: var(--atlas-z-modal, 1080);
}

/* Sin Bootstrap cargado se pinta abierta a mano: el fondo lo pone esta clase. */
.atlas-export-modal--standalone {
    background: rgba(0, 0, 0, 0.5);
}

.atlas-export-modal__dialog {
    max-width: min(1180px, 96vw);
}

.atlas-export-modal__content {
    border: 0;
    border-radius: var(--atlas-radius-2xl, 16px);
    box-shadow: var(--atlas-shadow-3);
    overflow: hidden;
    background: var(--atlas-surface, #fff);
    color: var(--atlas-text, #111827);
}

/* ── Cabecera ───────────────────────────────────────────────────────────────── */

.atlas-export-modal__header {
    background: linear-gradient(135deg, var(--atlas-gray-700, #374151) 0%, var(--atlas-gray-900, #111827) 100%);
    color: var(--atlas-white, #fff);
    border: 0;
    padding: var(--atlas-space-5, 20px) var(--atlas-space-6, 24px);
}

.atlas-export-modal__title {
    display: flex;
    align-items: center;
    gap: var(--atlas-space-2, 8px);
    font-weight: 700;
    color: inherit;
}

.atlas-export-modal__title i {
    font-size: 1.3rem;
}

/* Nombre del dataset / tabla: pastilla discreta junto al título. */
.atlas-export-modal__subject {
    margin-left: var(--atlas-space-1, 4px);
    padding: 0.1rem 0.55rem;
    border-radius: var(--atlas-radius-full, 999px);
    background: rgba(255, 255, 255, 0.14);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

/* ── Fila de ámbito (opcional: SMS "All positions / zona / sub-área") ───────── */

.atlas-export-modal__scope {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--atlas-space-2, 8px);
    padding: var(--atlas-space-3, 12px) var(--atlas-space-6, 24px);
    border-bottom: 1px solid var(--atlas-border, #e5e7eb);
    background: var(--atlas-surface-muted, #f9fafb);
}

.atlas-export-modal__scope-label {
    padding-right: var(--atlas-space-1, 4px);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--atlas-text-muted, #6b7280);
}

/* Mismo lenguaje visual que los chips de sub-área de Material Tracking: se leen como "lo mismo,
   pero para el Excel". */
.atlas-export-modal__scope-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    border: 1px solid var(--atlas-border, #e5e7eb);
    background: var(--atlas-surface, #fff);
    color: var(--atlas-text-muted, #6b7280);
    border-radius: var(--atlas-radius-full, 999px);
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    line-height: 1.4;
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.atlas-export-modal__scope-chip:hover:not(:disabled) {
    border-color: var(--atlas-border-strong, #d1d5db);
    color: var(--atlas-text, #111827);
}

.atlas-export-modal__scope-chip:disabled {
    opacity: 0.6;
    cursor: default;
}

.atlas-export-modal__scope-chip.is-active {
    background: var(--atlas-gray-900, #111827);
    border-color: var(--atlas-gray-900, #111827);
    color: var(--atlas-white, #fff);
    font-weight: 600;
}

/* Las sub-áreas cuelgan de su zona: mismo control, un punto más pequeño y con sangría, para que
   la jerarquía se vea sin dibujar un árbol. */
.atlas-export-modal__scope-chip--sub {
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    margin-left: var(--atlas-space-1, 4px);
}

/* ── Fila de estado (cargando / error) ──────────────────────────────────────── */

.atlas-export-modal__status {
    padding: var(--atlas-space-3, 12px) var(--atlas-space-6, 24px);
    border-bottom: 1px solid var(--atlas-border, #e5e7eb);
    background: var(--atlas-surface-muted, #f9fafb);
    font-size: 0.8rem;
    color: var(--atlas-text-muted, #6b7280);
}

.atlas-export-modal__status[hidden] {
    display: none;
}

.atlas-export-modal__loading i,
.atlas-export-modal__error i {
    margin-right: var(--atlas-space-1, 4px);
}

.atlas-export-modal__error {
    color: var(--atlas-red-600, #dc2626);
}

/* ── Columna izquierda: catálogo ────────────────────────────────────────────── */

.atlas-export-modal__catalog {
    border-right: 1px solid var(--atlas-border, #e5e7eb);
    display: flex;
    flex-direction: column;
}

.atlas-export-modal__catalog-tools {
    padding: var(--atlas-space-3, 12px) var(--atlas-space-3, 12px) var(--atlas-space-2, 8px);
    border-bottom: 1px solid var(--atlas-border, #e5e7eb);
    background: var(--atlas-surface, #fff);
    position: sticky;
    top: 0;
    z-index: 2;
}

/* Alto acotado con scroll propio. Sin esto, 40 casillas estiran la ventana hasta dejar la vista
   previa fuera de pantalla — que es justo lo que hay que poder ver. */
.atlas-export-modal__catalog-body {
    max-height: 46vh;
    overflow-y: auto;
    padding: var(--atlas-space-1, 4px) 0 var(--atlas-space-2, 8px);
}

.atlas-export-modal__group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--atlas-space-2, 8px) 0.9rem 0.35rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--atlas-text-muted, #6b7280);
    background: var(--atlas-surface-muted, #f9fafb);
    border-bottom: 1px solid var(--atlas-border, #e5e7eb);
    position: sticky;
    top: 0;
    z-index: 1;
}

.atlas-export-modal__group-toggle {
    border: 0;
    background: transparent;
    padding: 0;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    color: var(--atlas-color-primary, #2563eb);
}

.atlas-export-modal__group-toggle:hover {
    text-decoration: underline;
}

.atlas-export-modal__field {
    display: flex;
    align-items: center;
    gap: var(--atlas-space-2, 8px);
    padding: 0.3rem 0.9rem;
    margin: 0;
    font-size: 0.82rem;
    cursor: pointer;
    border-left: 3px solid transparent;
    color: var(--atlas-text-secondary, #374151);
}

.atlas-export-modal__field .form-check-input {
    margin: 0;
    flex: 0 0 auto;
}

.atlas-export-modal__field:hover {
    background: var(--atlas-surface-sunken, #f3f4f6);
}

.atlas-export-modal__field.is-on {
    border-left-color: var(--atlas-color-primary, #2563eb);
    background: var(--atlas-color-primary-soft, rgba(37, 99, 235, 0.08));
}

.atlas-export-modal__field.is-on .atlas-export-modal__field-label {
    font-weight: 600;
    color: var(--atlas-text, #111827);
}

.atlas-export-modal__field-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Icono de "hay tooltip" junto a los campos que traen `hint`. */
.atlas-export-modal__field-info {
    flex: 0 0 auto;
    color: var(--atlas-text-faint, #9ca3af);
    font-size: 0.85rem;
}

/* "empty": ninguna fila de la muestra trae valor para este campo. Aviso, no veto. */
.atlas-export-modal__empty-tag {
    flex: 0 0 auto;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--atlas-amber-700, #b45309);
    background: var(--atlas-amber-100, #fef3c7);
    border-radius: var(--atlas-radius-xs, 4px);
    padding: 0.05rem 0.3rem;
}

/* ── Columna derecha: orden + preview ───────────────────────────────────────── */

.atlas-export-modal__side {
    display: flex;
    flex-direction: column;
    min-width: 0; /* imprescindible: sin esto la preview ancha empuja el ancho del modal */
}

.atlas-export-modal__section {
    padding: var(--atlas-space-3, 12px);
    min-width: 0;
}

.atlas-export-modal__section + .atlas-export-modal__section {
    border-top: 1px solid var(--atlas-border, #e5e7eb);
}

.atlas-export-modal__section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--atlas-space-2, 8px);
    margin-bottom: var(--atlas-space-2, 8px);
}

.atlas-export-modal__label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--atlas-text-muted, #6b7280);
}

.atlas-export-modal__hint {
    font-size: 0.75rem;
    color: var(--atlas-text-muted, #6b7280);
}

/* Estado vacío compartido por catálogo, orden y preview. */
.atlas-export-modal__empty {
    padding: var(--atlas-space-5, 20px);
    text-align: center;
    font-size: 0.8rem;
    color: var(--atlas-text-muted, #6b7280);
}

.atlas-export-modal__empty i {
    margin-right: var(--atlas-space-1, 4px);
}

.atlas-export-modal__empty--dashed {
    background: var(--atlas-surface-muted, #f9fafb);
    border: 1px dashed var(--atlas-border, #e5e7eb);
    border-radius: var(--atlas-radius-md, 8px);
}

/* Columnas elegidas, en orden. Lista vertical con alto acotado: con las 40 marcadas esta lista sola
   llenaba la ventana. */
.atlas-export-modal__order {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-height: 9.5rem;
    overflow-y: auto;
}

.atlas-export-modal__chip {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--atlas-surface, #fff);
    border: 1px solid var(--atlas-border, #e5e7eb);
    border-radius: var(--atlas-radius-sm, 6px);
    padding: 0.15rem 0.3rem 0.15rem 0.35rem;
    font-size: 0.78rem;
    min-width: 0;
}

.atlas-export-modal__chip-pos {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.3rem;
    height: 1.15rem;
    padding: 0 0.2rem;
    background: var(--atlas-surface-sunken, #f3f4f6);
    color: var(--atlas-text-muted, #6b7280);
    border-radius: var(--atlas-radius-xs, 4px);
    font-size: 0.65rem;
    font-weight: 700;
    flex: 0 0 auto;
}

.atlas-export-modal__chip-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--atlas-text, #111827);
}

.atlas-export-modal__chip-btn {
    border: 0;
    background: transparent;
    color: var(--atlas-text-faint, #9ca3af);
    padding: 0 0.15rem;
    line-height: 1;
    font-size: 0.85rem;
    flex: 0 0 auto;
}

.atlas-export-modal__chip-btn:hover:not(:disabled) {
    color: var(--atlas-text, #111827);
}

.atlas-export-modal__chip-btn:disabled {
    opacity: 0.3;
}

.atlas-export-modal__chip-x:hover:not(:disabled) {
    color: var(--atlas-red-600, #dc2626);
}

/* Vista previa: el scroll horizontal es SUYO, no del modal ni de la página. Con 20 columnas la
   tabla mide más que la pantalla y sin esto arrastraba el diálogo entero de lado. */
.atlas-export-modal__preview-wrap {
    min-height: 6rem;
    min-width: 0;
}

.atlas-export-modal__preview {
    overflow: auto;
    max-width: 100%;
    max-height: 30vh;
    border: 1px solid var(--atlas-border, #e5e7eb);
    border-radius: var(--atlas-radius-md, 8px);
}

.atlas-export-modal__preview table {
    margin: 0;
    font-size: 0.74rem;
    white-space: nowrap;
    color: var(--atlas-text-secondary, #374151);
}

.atlas-export-modal__preview thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    /* La cabecera del .xlsx es este mismo azul: la vista previa se parece al fichero a propósito. */
    background: var(--atlas-blue-800, #1e40af);
    color: var(--atlas-white, #fff);
    font-weight: 600;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.35rem 0.5rem;
    border-color: var(--atlas-blue-700, #1d4ed8);
}

.atlas-export-modal__preview tbody td {
    padding: 0.3rem 0.5rem;
    border-color: var(--atlas-border, #e5e7eb);
}

.atlas-export-modal__cell-empty {
    color: var(--atlas-text-faint, #9ca3af);
}

/* ── Pie ────────────────────────────────────────────────────────────────────── */

.atlas-export-modal__footer {
    border-top: 1px solid var(--atlas-border, #e5e7eb);
    padding-top: var(--atlas-space-2, 8px);
    padding-bottom: var(--atlas-space-2, 8px);
    background: var(--atlas-surface, #fff);
}

.atlas-export-modal__footer-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.78rem;
    color: var(--atlas-text-muted, #6b7280);
    min-width: 0;
}

.atlas-export-modal__footer-info i {
    margin-right: var(--atlas-space-1, 4px);
}

.atlas-export-modal__footer-info strong {
    color: var(--atlas-text, #111827);
}

.atlas-export-modal__remember {
    font-size: 0.72rem;
    color: var(--atlas-text-faint, #9ca3af);
}

/* ── Móvil ──────────────────────────────────────────────────────────────────── */

@media (max-width: 991.98px) {
    /* Las dos columnas se apilan (col-lg-*): el borde lateral del catálogo pasa a ser inferior y
       el catálogo cede alto a la vista previa. */
    .atlas-export-modal__catalog {
        border-right: 0;
        border-bottom: 1px solid var(--atlas-border, #e5e7eb);
    }

    .atlas-export-modal__catalog-body {
        max-height: 32vh;
    }

    .atlas-export-modal__header {
        padding: var(--atlas-space-4, 16px);
    }

    .atlas-export-modal__footer {
        flex-wrap: wrap;
        gap: var(--atlas-space-2, 8px);
    }

    .atlas-export-modal__footer-info {
        flex-basis: 100%;
    }
}
