body.grid-mode {
    overflow: hidden;
}

.grid-card {
    position: fixed;
    inset: 0;
    background: #070d1a;
    display: none;
    flex-direction: column;
    z-index: 1000; /* Elevado por encima del header sticky (z-index: 100) */
}

.grid-card.active {
    display: flex;
}

/* ─── Sticky Top Action Bar ─── */
.grid-topbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: rgba(10, 15, 30, 0.95);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(99, 102, 241, 0.25);
    gap: 12px;
    flex-wrap: wrap;
}

.grid-topbar-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.grid-topbar h3 {
    font-size: 15px;
    font-weight: 700;
    color: white;
    margin: 0;
}

.grid-topbar p {
    font-size: 11px;
    color: #64748b;
    margin: 0;
}

.legend-row {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 4px;
}

.legend-dot {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: #94a3b8;
}

.legend-dot span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.grid-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

#gridIndexStats {
    font-size: 11px;
    color: #a78bfa;
    font-weight: 600;
    white-space: nowrap;
}

.topbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.topbar-btn:hover {
    filter: brightness(1.15);
    transform: translateY(-1px);
}

.btn-upload {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-approve {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    font-size: 14px;
    padding: 9px 22px;
    box-shadow: 0 4px 16px rgba(16, 185, 129, 0.35);
}

.btn-send-audit {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    font-size: 14px;
    padding: 9px 22px;
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.35);
}

.btn-send-audit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: none;
    transform: none;
}

/* ─── Body Area: Sidebar + Grid ─── */
.grid-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0; /* CRÍTICO: evita la Flexbox Height Trap */
    height: 0;    /* Fuerza al browser a calcular la altura interna correctamente */
}

/* ─── Master Checklist Sidebar ─── */
.master-checklist-panel {
    width: 240px;
    flex-shrink: 0;
    background: rgba(8, 12, 24, 0.95);
    border-right: 1px solid rgba(99, 102, 241, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0; /* CRÍTICO: evita la Flexbox Height Trap en sidebar */
}

.master-checklist-panel h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #6366f1;
    padding: 14px 16px 10px;
    border-bottom: 1px solid rgba(99, 102, 241, 0.12);
    margin: 0;
    flex-shrink: 0;
}

.checklist-scroll {
    overflow-y: auto;
    flex: 1;
    min-height: 0; /* CRÍTICO: habilita scroll interno en flexbox */
    padding: 8px;
}

.checklist-scroll::-webkit-scrollbar {
    width: 8px;
}

.checklist-scroll::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.6);
}

.checklist-scroll::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
}

.checklist-scroll::-webkit-scrollbar-thumb:hover {
    background: #6366f1;
}

.checklist-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 11px;
    color: #64748b;
    cursor: default;
    transition: all 0.2s;
    margin-bottom: 2px;
}

.checklist-item.fulfilled {
    background: rgba(16, 185, 129, 0.08);
    color: #10b981;
}

.checklist-item.na-exento {
    background: rgba(148, 163, 184, 0.08);
    color: #94a3b8;
    text-decoration: line-through;
}

.checklist-item .ci-icon {
    font-size: 12px;
    flex-shrink: 0;
}

.checklist-item .ci-label {
    font-size: 10.5px;
    line-height: 1.3;
}

/* ─── Pages Grid (Scrollable) ─── */
.pages-grid-wrap {
    flex: 1;
    min-height: 0;  /* CRÍTICO: sin esto el contenedor se expande infinitamente
                       y overflow-y: auto nunca activa la barra de scroll */
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch; /* Scroll suave en iOS/tablets */
}

.pages-grid-wrap::-webkit-scrollbar {
    width: 10px;
}

.pages-grid-wrap::-webkit-scrollbar-track {
    background: rgba(15, 23, 42, 0.6);
}

.pages-grid-wrap::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 6px;
    border: 2px solid rgba(15, 23, 42, 0.6);
}

.pages-grid-wrap::-webkit-scrollbar-thumb:hover {
    background: #6366f1;
}

.pages-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

/* ─── Page Cards ─── */
.page-card {
    background: #0d1526;
    border-radius: 12px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all 0.2s ease;
    border: 2px solid rgba(255, 255, 255, 0.04);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    position: relative;
}

.page-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
}

.page-num-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    color: #e2e8f0;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 20px;
    z-index: 2;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.conf-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 9.5px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 20px;
    z-index: 2;
}

.conf-ok {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.conf-warn {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.conf-neutral {
    background: rgba(148, 163, 184, 0.15);
    color: #94a3b8;
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.page-card img {
    width: 100%;
    height: 190px;
    object-fit: contain;
    background: white;
    border-radius: 6px;
    cursor: zoom-in;
    transition: opacity 0.2s;
}

.page-card img:hover {
    opacity: 0.9;
}

.page-card select {
    width: 100%;
    font-size: 10.5px;
    font-weight: 600;
    padding: 7px 10px;
    border-radius: 7px;
    background: rgba(15, 23, 42, 0.9);
    color: white;
    border: 1px solid rgba(99, 102, 241, 0.25);
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a78bfa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 12px;
    padding-right: 24px;
    cursor: pointer;
    transition: border-color 0.2s;
}

.page-card select:focus {
    border-color: #6366f1;
}

.page-card select option {
    background: #0f172a;
}

.drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    cursor: grab;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    transition: background 0.2s;
    flex-shrink: 0;
}

.drag-handle:hover {
    background: rgba(99, 102, 241, 0.2);
}

.drag-handle:active {
    cursor: grabbing;
}

.sortable-ghost {
    opacity: 0.35;
    transform: scale(0.95);
    border: 2px dashed #8b5cf6 !important;
}

.sortable-drag {
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7) !important;
    transform: scale(1.03);
    cursor: grabbing !important;
    z-index: 9999;
}

/* ─── Lightbox ─── */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.94);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: none;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
}

.lightbox-overlay.active {
    display: flex;
}

.lightbox-container {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-grow: 1;
    width: 100%;
    max-height: 75vh;
    overflow: hidden;
    position: relative;
}

.lightbox-overlay img {
    max-width: 90vw;
    max-height: 75vh;
    width: auto;
    height: auto;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

.close-lightbox {
    position: absolute;
    top: 20px;
    right: 28px;
    font-size: 36px;
    color: white;
    cursor: pointer;
    background: none;
    border: none;
    transition: 0.2s;
    line-height: 1;
    z-index: 1010;
}

.close-lightbox:hover {
    color: #ef4444;
    transform: scale(1.15);
}

/* ─── Footer (compact) ─── */
footer {
    margin-top: auto;
    padding: 24px;
    font-size: 11px;
    color: #334155;
    text-align: center;
    width: 100%;
}
/* ── TOAST NOTIFICATIONS ── */
#toastContainer {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    pointer-events: none;
}
.toast-message {
    background: white;
    color: #1e293b;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transform: translateY(-20px) scale(0.9);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 450px;
    text-align: left;
    line-height: 1.4;
}
.toast-message.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}
.toast-error { border: 1px solid #fca5a5; background: #fef2f2; color: #991b1b; }
.toast-success { border: 1px solid #6ee7b7; background: #f0fdf4; color: #166534; }

/* ─── Lightbox Controls ─── */
.lightbox-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: auto;
    padding: 20px;
}

.lightbox-overlay img {
    max-width: 90% !important;
    max-height: 90% !important;
    width: auto !important;
    height: auto !important;
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
    image-rendering: -webkit-optimize-contrast;
    transition: transform 0.2s cubic-bezier(0.1, 0.8, 0.2, 1);
    transform-origin: center center;
}

.lightbox-controls {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 12px;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 30px;
    padding: 8px 18px;
    z-index: 10000;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.lightbox-btn {
    background: transparent;
    border: none;
    color: #cbd5e1;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.lightbox-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
}

.lightbox-btn:active {
    transform: translateY(0);
}

/* ─── Custom Search Dropdown ─── */
.custom-dropdown-container {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.custom-dropdown-trigger {
    width: 100%;
    font-size: 10.5px;
    font-weight: 600;
    padding: 7px 10px;
    border-radius: 7px;
    background: rgba(15, 23, 42, 0.9);
    color: white;
    border: 1px solid rgba(99, 102, 241, 0.25);
    outline: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 24px;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a78bfa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 8px center;
    background-size: 12px;
}

.custom-dropdown-trigger:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.custom-dropdown-menu {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    width: 100%;
    min-width: 200px;
    background: rgba(10, 18, 36, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(99, 102, 241, 0.45);
    border-radius: 8px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.7);
    z-index: 100;
    display: none;
    flex-direction: column;
    padding: 6px;
    gap: 6px;
}

.custom-dropdown-menu.show {
    display: flex;
}

.custom-dropdown-search {
    width: 100%;
    font-size: 11px;
    background: rgba(15, 23, 42, 0.8);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    padding: 6px 8px;
    outline: none;
    box-sizing: border-box;
}

.custom-dropdown-search:focus {
    border-color: #a78bfa;
    background: rgba(15, 23, 42, 0.95);
}

.custom-dropdown-options {
    max-height: 180px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-right: 2px;
}

.custom-dropdown-options::-webkit-scrollbar {
    width: 4px;
}
.custom-dropdown-options::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 2px;
}
.custom-dropdown-options::-webkit-scrollbar-thumb {
    background: rgba(167, 139, 250, 0.3);
    border-radius: 2px;
}
.custom-dropdown-options::-webkit-scrollbar-thumb:hover {
    background: rgba(167, 139, 250, 0.5);
}

.custom-dropdown-group-header {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
    padding: 6px 6px 2px 6px;
    font-weight: 700;
    pointer-events: none;
    user-select: none;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    margin-top: 4px;
}
.custom-dropdown-group-header:first-of-type {
    border-top: none;
    margin-top: 0;
}

.custom-dropdown-option {
    font-size: 10.5px;
    padding: 6px 8px;
    border-radius: 4px;
    color: #cbd5e1;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.custom-dropdown-option:hover {
    background: rgba(99, 102, 241, 0.2);
    color: white;
}

.custom-dropdown-option.selected {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    font-weight: 600;
}

.custom-dropdown-option.option-ignored {
    color: #fca5a5;
}

.custom-dropdown-option.option-ignored:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #fee2e2;
}
