/* ═══════════════════════════════════════════════════════════════════════════════
   ATLAS TABLE — Standardized Table Styles
   ═══════════════════════════════════════════════════════════════════════════════ */

/* ── WRAPPER ───────────────────────────────────────────────────────────────── */

.atlas-table-wrapper {
    background: var(--atlas-white);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    box-shadow: var(--atlas-shadow-1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Ancla de posicionamiento del overlay de carga (.atlas-table-overlay → inset:0). */
    position: relative;
}

/* ── HEADER ────────────────────────────────────────────────────────────────── */

.atlas-table-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.atlas-table-header .atlas-table-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--atlas-gray-900);
    margin: 0;
    margin-right: auto;
}

.atlas-table-header .atlas-table-title i {
    margin-right: 0.5rem;
    color: var(--kpi-primary, var(--atlas-blue-600));
}

.atlas-table-header .atlas-table-count {
    font-weight: 400;
    font-size: 0.8rem;
    color: var(--atlas-gray-500);
    margin-left: 0.5rem;
}

/* ── TOOLBAR (filters + column selector) ───────────────────────────────────── */

.atlas-table-toolbar {
    padding: 0.75rem 1.25rem;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

/* ── ADD FILTER MENU ───────────────────────────────────────────────────────── */

/* Scrollable like the Columns menu — the filter list can grow past the viewport. */
.atlas-filter-menu {
    min-width: 220px;
    max-height: 360px;
    overflow-y: auto;
}

/* ── COLUMN SELECTOR ───────────────────────────────────────────────────────── */

.atlas-column-selector .dropdown-menu {
    padding: 0.5rem 0;
}

.atlas-column-selector .form-check-label {
    font-size: 0.8125rem;
    color: var(--atlas-gray-700);
    user-select: none;
}

.atlas-column-selector .form-check-input {
    cursor: pointer;
}

/* ── FILTER CHIPS CONTAINER ────────────────────────────────────────────────── */

.atlas-filter-chips {
    display: none;
    padding: 0.625rem 1.25rem;
    background: linear-gradient(135deg, var(--atlas-slate-50) 0%, var(--atlas-slate-100) 100%);
    border-bottom: 1px solid var(--atlas-slate-200);
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.atlas-filter-chips-visible {
    display: flex;
}

/* ── FILTER CHIP ───────────────────────────────────────────────────────────── */

.atlas-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.3rem 0.5rem;
    background: var(--atlas-white);
    border: 1px solid var(--atlas-gray-200);
    border-radius: 9999px;
    font-size: 0.75rem;
    line-height: 1.2;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.atlas-chip:hover {
    border-color: #93c5fd;
    box-shadow: 0 1px 4px var(--atlas-color-primary-soft);
}

.atlas-chip-label {
    color: var(--atlas-gray-500);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.625rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.atlas-chip-select,
.atlas-chip-date,
.atlas-chip-text,
.atlas-chip-num {
    border: none;
    background: transparent;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--atlas-blue-800);
    padding: 0;
    outline: none;
    max-width: 160px;
    cursor: pointer;
}

/* Loading state del chip mientras resuelve un optionsProvider async (cardinalidad de un
   atributo EAV — utils/columnCatalog.js#buildAttributeFilters). */
.atlas-chip-loading {
    font-size: 0.75rem;
    white-space: nowrap;
}

/* Rango desde/hasta (daterange/numrange): separador visual entre los dos inputs. */
.atlas-chip-range-sep {
    color: var(--atlas-gray-400);
    font-size: 0.7rem;
    line-height: 1;
}

.atlas-chip-range-from,
.atlas-chip-range-to {
    max-width: 90px;
}

.atlas-chip-select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 0.75rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0 center;
    background-size: 8px;
}

.atlas-chip-date {
    max-width: 130px;
}

.atlas-chip-date::-webkit-calendar-picker-indicator {
    opacity: 0.5;
    cursor: pointer;
}

.atlas-chip-text {
    min-width: 80px;
}

.atlas-chip-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.125rem;
    height: 1.125rem;
    padding: 0;
    margin-left: 0.125rem;
    background: var(--atlas-gray-200);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    color: var(--atlas-gray-500);
    font-size: 0.625rem;
    transition: all 0.15s ease;
    line-height: 1;
}

.atlas-chip-remove:hover {
    background: var(--atlas-red-500);
    color: var(--atlas-white);
}

/* ── TABLE BASE STYLES ─────────────────────────────────────────────────────── */

.atlas-table-wrapper table.dataTable {
    width: 100% !important;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0 !important;
}

.atlas-table-wrapper table.dataTable thead th {
    background: var(--atlas-gray-50);
    font-weight: 600;
    color: var(--atlas-gray-500);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--atlas-gray-200);
    white-space: nowrap;
}

.atlas-table-wrapper table.dataTable tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--atlas-gray-100);
    color: var(--atlas-gray-900);
    font-size: 0.8125rem;
    vertical-align: middle;
}

.atlas-table-wrapper table.dataTable tbody tr:hover td {
    background: var(--atlas-gray-50);
}

/* Whole-row click affordance (set when config.onRowClick is provided). */
.atlas-table-wrapper table.dataTable tbody.atlas-rows-clickable tr {
    cursor: pointer;
}

.atlas-table-wrapper table.dataTable tbody tr:last-child td {
    border-bottom: none;
}

/* ── STICKY ACTIONS COLUMN ─────────────────────────────────────────────────── */

/* Class lives on .atlas-table-wrapper so it covers both the DataTables
   cloned header table and the original body table created by scrollX. */

.atlas-table-sticky-actions table.dataTable thead th:last-child,
.atlas-table-sticky-actions table.dataTable tbody td:last-child {
    position: sticky;
    right: 0;
    z-index: 2;
    background: var(--atlas-white);
    box-shadow: -4px 0 8px rgba(0, 0, 0, 0.04);
}

/* Actions cell: shrink to fit content */
.atlas-actions-cell {
    width: 1%;
    white-space: nowrap;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
}

.atlas-table-sticky-actions table.dataTable thead th:last-child {
    background: var(--atlas-gray-50);
    z-index: 3;
    text-align: left;
}

.atlas-table-sticky-actions table.dataTable tbody tr:hover td:last-child {
    background: var(--atlas-gray-50);
}

/* Ensure the scroll area shows the shadow correctly */
.atlas-table-wrapper .datatable-scroll-wrap,
.atlas-table-wrapper .dataTables_scrollBody {
    overflow-x: auto;
    overflow-y: visible;
    position: relative;
}

/* ── ACTIONS GROUP ─────────────────────────────────────────────────────────── */

.atlas-actions-group {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.3rem;
    white-space: nowrap;
}

.atlas-actions-group .btn {
    padding: 0.35rem 0.45rem;
    font-size: 0.875rem;
    line-height: 1;
    border-radius: 3px;
}

.atlas-actions-group .btn i {
    font-size: 1.15rem;
}

/* Dropdown-style actions */
.atlas-actions-group .dropdown-toggle::after {
    display: none;
}

.atlas-actions-group .dropdown-menu {
    font-size: 0.8125rem;
    min-width: 140px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--atlas-gray-200);
    border-radius: 8px;
}

/* ── SORT INDICATORS ───────────────────────────────────────────────────────── */

.atlas-table-wrapper table.dataTable thead th.sorting,
.atlas-table-wrapper table.dataTable thead th.sorting_asc,
.atlas-table-wrapper table.dataTable thead th.sorting_desc {
    cursor: pointer;
    position: relative;
    padding-right: 1.75rem !important;
    user-select: none;
}

.atlas-table-wrapper table.dataTable thead th.sorting::after,
.atlas-table-wrapper table.dataTable thead th.sorting_asc::after,
.atlas-table-wrapper table.dataTable thead th.sorting_desc::after {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    opacity: 0.3;
}

.atlas-table-wrapper table.dataTable thead th.sorting_asc::after {
    opacity: 0.8;
    color: var(--atlas-blue-600);
}

.atlas-table-wrapper table.dataTable thead th.sorting_desc::after {
    opacity: 0.8;
    color: var(--atlas-blue-600);
}

.atlas-table-wrapper table.dataTable thead th.sorting:hover {
    background: var(--atlas-slate-100);
}

/* ── DATATABLE HEADER / FOOTER OVERRIDES ───────────────────────────────────── */

.atlas-table-wrapper .datatable-header {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--atlas-gray-100);
}

.atlas-table-wrapper .datatable-footer {
    padding: 0.625rem 1.25rem;
    border-top: 1px solid var(--atlas-gray-100);
    font-size: 0.8125rem;
    color: var(--atlas-gray-500);
}

/* ── RESPONSIVE ────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .atlas-table-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .atlas-table-toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .atlas-chip-select,
    .atlas-chip-date,
    .atlas-chip-text,
    .atlas-chip-num {
        max-width: 120px;
    }

    .atlas-chip-range-from,
    .atlas-chip-range-to {
        max-width: 80px;
    }
}

/* ── EMPTY & LOADING STATES ────────────────────────────────────────────────── */

.atlas-table-wrapper .dataTables_empty {
    padding: 3rem 1rem !important;
    text-align: center;
    color: var(--atlas-gray-400);
    font-size: 0.875rem;
}

.atlas-table-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 3rem 1rem;
    color: var(--atlas-gray-500);
    font-size: 0.875rem;
}

/* ── SERVER-SIDE LOADING OVERLAY ──────────────────────────────────────────────
   Veil + tarjeta con spinner + mensaje contextual encima de la zona de datos.
   Solo se usa en modo server-side (lo monta AtlasTable._initLoadingOverlay). */

/* El overlay se posiciona respecto al wrapper. */
.atlas-table-wrapper {
    position: relative;
}

/* DataTables pinta su propio "Processing…" — lo ocultamos: usamos nuestro overlay. */
.atlas-table-wrapper .dataTables_processing {
    display: none !important;
}

.atlas-table-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    /* Veil translúcido con un punto de blur: deja entrever la tabla "viva" debajo. */
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(1.5px);
    -webkit-backdrop-filter: blur(1.5px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.18s ease, visibility 0.18s ease;
    pointer-events: none;
}

.atlas-table-overlay-visible {
    opacity: 1;
    visibility: visible;
    /* Bloquea interacción con la tabla mientras carga (evita doble-click/scroll raro). */
    pointer-events: auto;
}

.atlas-table-overlay-card {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 5.5rem;
    padding: 0.6rem 1.1rem;
    background: var(--atlas-white);
    border: 1px solid var(--atlas-gray-200);
    border-radius: 9999px;
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.12);
    color: #1e293b;
    font-size: 0.8125rem;
    font-weight: 600;
    /* Pequeño "pop" + respiración para reforzar el "estoy procesando". */
    animation: atlas-overlay-pop 0.22s ease, atlas-overlay-breathe 1.8s ease-in-out 0.22s infinite;
}

.atlas-table-spinner {
    width: 1.05rem;
    height: 1.05rem;
    border: 2.5px solid rgba(37, 99, 235, 0.18);
    border-top-color: var(--kpi-primary, var(--atlas-blue-600));
    border-radius: 50%;
    flex-shrink: 0;
    animation: atlas-spin 0.7s linear infinite;
}

.atlas-table-overlay-msg {
    white-space: nowrap;
    letter-spacing: 0.01em;
}

/* Puntos suspensivos animados (… secuencial) tras el mensaje. */
.atlas-table-dots::after {
    content: '';
    animation: atlas-dots 1.2s steps(1, end) infinite;
}

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

@keyframes atlas-dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
    100% { content: ''; }
}

@keyframes atlas-overlay-pop {
    from { transform: translateY(-6px) scale(0.96); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes atlas-overlay-breathe {
    0%, 100% { box-shadow: 0 6px 20px rgba(15, 23, 42, 0.12); }
    50%      { box-shadow: 0 6px 26px rgba(37, 99, 235, 0.22); }
}

/* Respeta usuarios con "reduce motion": sin giro/respiración, solo veil + texto. */
@media (prefers-reduced-motion: reduce) {
    .atlas-table-spinner { animation-duration: 1.4s; }
    .atlas-table-overlay-card { animation: none; }
    .atlas-table-dots::after { animation: none; content: '…'; }
}

/* ── ROW SELECTION ─────────────────────────────────────────────────────────── */

.atlas-select-cell {
    width: 36px !important;
    max-width: 36px;
    padding-left: 0.75rem !important;
    padding-right: 0.25rem !important;
}

.atlas-row-check {
    cursor: pointer;
    width: 1rem;
    height: 1rem;
}

.atlas-row-selected td {
    background: rgba(37, 99, 235, 0.04) !important;
}

.atlas-row-selected td:first-child {
    box-shadow: inset 3px 0 0 var(--atlas-blue-600);
}

.atlas-selection-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.625rem;
    background: rgba(37, 99, 235, 0.08);
    color: var(--atlas-blue-600);
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/* ── EXPORT BUTTON ─────────────────────────────────────────────────────────── */

.atlas-btn-export {
    background: linear-gradient(135deg, var(--atlas-slate-50) 0%, var(--atlas-slate-100) 100%);
    border: 1px solid var(--atlas-slate-200);
    color: #475569;
    font-weight: 500;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.atlas-btn-export:hover {
    background: linear-gradient(135deg, var(--atlas-slate-100) 0%, var(--atlas-slate-200) 100%);
    border-color: var(--atlas-slate-300);
    color: #1e293b;
}

.atlas-export-menu {
    min-width: 200px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    border: 1px solid var(--atlas-gray-200);
    border-radius: 10px;
    padding: 0.375rem 0;
}

.atlas-export-menu .dropdown-item {
    font-size: 0.8125rem;
    padding: 0.5rem 1rem;
    transition: background 0.1s ease;
}

.atlas-export-menu .dropdown-item:hover {
    background: var(--atlas-slate-100);
}

.atlas-export-menu .dropdown-divider {
    margin: 0.25rem 0;
    border-color: var(--atlas-slate-100);
}

/* ── EXPORT TOAST ──────────────────────────────────────────────────────────── */

.atlas-export-toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.75rem 1.25rem;
    background: var(--atlas-gray-900);
    color: var(--atlas-white);
    border-radius: 10px;
    font-size: 0.8125rem;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
}

.atlas-export-toast i {
    color: var(--atlas-emerald-500);
    font-size: 1rem;
}

.atlas-export-toast-visible {
    opacity: 1;
    transform: translateY(0);
}

/* ── UTILITY CLASSES FOR RENDERS ───────────────────────────────────────────── */

.atlas-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    line-height: 1.2;
}

.atlas-badge-success { background: rgba(16, 185, 129, 0.1); color: var(--atlas-emerald-600); }
.atlas-badge-danger  { background: rgba(239, 68, 68, 0.1);  color: var(--atlas-red-600); }
.atlas-badge-warning { background: rgba(245, 158, 11, 0.1); color: #d97706; }
.atlas-badge-info    { background: rgba(59, 130, 246, 0.1);  color: var(--atlas-blue-600); }
.atlas-badge-neutral { background: rgba(107, 114, 128, 0.1); color: var(--atlas-gray-600); }

.atlas-cell-stack {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.atlas-cell-stack .atlas-cell-main {
    font-weight: 500;
    color: var(--atlas-gray-900);
}

.atlas-cell-stack .atlas-cell-sub {
    font-size: 0.6875rem;
    color: var(--atlas-gray-400);
}

/* ── SEVERITY CHIP (reusable; see AtlasTable.severityChip) ──────────────────── */
/* Coloured pill + a CSS dot (currentColor) — no icon font, so it never renders a
   blank gap if a glyph fails to load. 1=Info, 2=Warning, 3=High, 4=Critical. */
.atlas-sev-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 2px 9px;
    border-radius: 9999px;
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    line-height: 1.4;
    white-space: nowrap;
}

.atlas-sev-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
    opacity: 0.9;
}

.atlas-sev-1 { background: var(--atlas-blue-100); color: var(--atlas-blue-700); }
.atlas-sev-2 { background: var(--atlas-amber-100); color: var(--atlas-amber-800); }
.atlas-sev-3 { background: var(--atlas-orange-100); color: var(--atlas-orange-800); }
.atlas-sev-4 { background: var(--atlas-red-100); color: var(--atlas-red-800); }
