﻿.drag-handle {
    background-color: #f8f9fa !important;
    border-right: 2px solid #dee2e6 !important;
    position: relative;
    transition: all 0.2s ease;
    text-align: center;
    vertical-align: middle;
    cursor: move;
    padding: 5px;
    width: 30px;
    min-width: 30px;
    max-width: 30px;
}

    .drag-handle:hover {
        background-color: #e9ecef !important;
        cursor: move !important;
        transform: scale(1.05);
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }

    .drag-handle:active {
        transform: scale(0.98);
    }

    /* Icona grip nell'handle */
    .drag-handle .fas {
        pointer-events: none;
        transition: color 0.2s ease;
        font-size: 14px;
        color: #666;
    }

    .drag-handle:hover .fas {
        color: #007bff !important;
    }

/* Stati della riga durante il drag */
.drag-over {
    background-color: #e3f2fd !important;
    border-top: 3px solid #2196f3 !important;
    border-bottom: 3px solid #2196f3 !important;
    box-shadow: 0 0 10px rgba(33, 150, 243, 0.3);
    position: relative;
    z-index: 10;
}

.dragging {
    background-color: #e3f2fd !important;
    border: 2px solid #2196f3 !important;
    opacity: 0.8 !important;
    z-index: 1000;
    position: relative;
}

/* Stati del body durante il drag */
body.dragging-active {
    cursor: move !important;
    user-select: none;
}

    body.dragging-active * {
        pointer-events: none;
    }

    body.dragging-active .drag-handle {
        pointer-events: auto;
    }

    body.dragging-active tr {
        pointer-events: auto;
    }

    body.dragging-active table {
        pointer-events: auto;
    }

    /* NASCONDI OVERFLOW DURANTE IL DRAG */
    body.dragging-active table,
    body.dragging-active .table {
        overflow: hidden !important;
        table-layout: fixed !important;
    }

    body.dragging-active .table-responsive {
        overflow: hidden !important;
    }

    /* Forza le celle a rimanere nelle loro dimensioni durante il drag */
    body.dragging-active td,
    body.dragging-active th {
        overflow: hidden !important;
        white-space: nowrap !important;
        text-overflow: ellipsis !important;
    }

    /* Evita che i bordi degli indicatori escano dalla tabella */
    body.dragging-active .drag-over-top,
    body.dragging-active .drag-over-bottom,
    body.dragging-active tbody.drop-zone-first,
    body.dragging-active tbody.drop-zone-last {
        overflow: hidden !important;
    }

    /* Mantieni la larghezza fissa durante il drag per evitare ricalcoli */
    body.dragging-active table {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
    }

/* Transizioni per le righe */
tr {
    transition: all 0.2s ease;
}

   

/* Miglioramenti per la tabella durante il drag */
table.table-bordered tr.dragging td {
    border-color: #ffc107 !important;
}

table.table-bordered tr.drag-over td {
    border-color: #2196f3 !important;
}

/* Indicatore di drop position */
.drop-indicator {
    height: 3px;
    background: linear-gradient(90deg, #007bff, #0056b3);
    margin: 0;
    border-radius: 2px;
    opacity: 0.8;
    animation: pulse 1.5s infinite;
    position: absolute;
    left: 0;
    right: 0;
    z-index: 100;
}

/* NUOVI INDICATORI VISIVI - Linea superiore/inferiore per il drop */

/* Indicatore per drop nella metà superiore della riga (inserirà SOPRA) */
.drag-over-top {
    position: relative;
}

    .drag-over-top::before {
        /*content: '';*/
        position: absolute;
        top: -2px;
        left: 0;
        right: 0;
        height: 4px;
        background: linear-gradient(90deg, #007bff, #00d4aa, #007bff);
        border-radius: 2px;
        z-index: 1000;
        pointer-events: none;
        animation: glow-top 1.2s infinite ease-in-out;
        box-shadow: 0 0 8px rgba(0, 123, 255, 0.6);
    }

/* Indicatore per drop nella metà inferiore della riga (inserirà SOTTO) */
.drag-over-bottom {
    position: relative;
}

    /*.drag-over-bottom::after {*/
      /*  content: '';*/
        /*position: absolute;
        bottom: -2px;
        left: 0;
        right: 0;
        height: 4px;
        background: linear-gradient(90deg, #007bff, #00d4aa, #007bff);
        border-radius: 2px;
        z-index: 1000;
        pointer-events: none;
        animation: glow-bottom 1.2s infinite ease-in-out;
        box-shadow: 0 0 8px rgba(0, 123, 255, 0.6);
    }*/

/* Indicatore per la prima posizione (sopra la prima riga) */
tbody.drop-zone-first {
    position: relative;
}

    tbody.drop-zone-first::before {
        content: '';
        position: absolute;
        top: -2px;
        left: 0;
        right: 0;
        height: 3px;
        background: linear-gradient(90deg, #007bff, #2196f3, #f8f9fa);
        border-radius: 2px;
        z-index: 1000;
        pointer-events: none;
        animation: glow-first 1s infinite ease-in-out;
        box-shadow: 0 0 10px rgb(255, 254, 253);
    }

/* Indicatore per l'ultima posizione (sotto l'ultima riga) */
tbody.drop-zone-last {
    position: relative;
}

   /* tbody.drop-zone-last::after {
        content: '';
        position: absolute;
        bottom: -2px;
        left: 0;
        right: 0;
        height: 4px;
        background: linear-gradient(90deg, #dc3545, #fd7e14, #dc3545);
        border-radius: 2px;
        z-index: 1000;
        pointer-events: none;
        animation: glow-last 1s infinite ease-in-out;
        box-shadow: 0 0 10px rgba(220, 53, 69, 0.7);
    }*/

/* Rimuovi gli indicatori standard quando usi quelli specifici */
.drag-over-top.drag-over,
.drag-over-bottom.drag-over {
    background-color: transparent !important;
    border-top: none !important;
    border-bottom: none !important;
    box-shadow: none !important;
}

/* Animazioni personalizzate per i diversi indicatori */
@keyframes glow-top {
    0% {
        opacity: 0.6;
        transform: scaleY(1) translateY(0px);
        box-shadow: 0 0 5px rgba(0, 123, 255, 0.4);
    }

    50% {
        opacity: 1;
        transform: scaleY(1.3) translateY(-1px);
        box-shadow: 0 0 15px rgba(0, 123, 255, 0.8);
    }

    100% {
        opacity: 0.6;
        transform: scaleY(1) translateY(0px);
        box-shadow: 0 0 5px rgba(0, 123, 255, 0.4);
    }
}

@keyframes glow-bottom {
    0% {
        opacity: 0.6;
        transform: scaleY(1) translateY(0px);
        box-shadow: 0 0 5px rgba(0, 123, 255, 0.4);
    }

    50% {
        opacity: 1;
        transform: scaleY(1.3) translateY(1px);
        box-shadow: 0 0 15px rgba(0, 123, 255, 0.8);
    }

    100% {
        opacity: 0.6;
        transform: scaleY(1) translateY(0px);
        box-shadow: 0 0 5px rgba(0, 123, 255, 0.4);
    }
}

@keyframes glow-first {
    0% {
        opacity: 0.7;
        transform: scaleY(1);
        box-shadow: 0 0 5px rgba(40, 167, 69, 0.5);
    }

    50% {
        opacity: 1;
        transform: scaleY(1.4);
        box-shadow: 0 0 20px rgba(40, 167, 69, 0.9);
    }

    100% {
        opacity: 0.7;
        transform: scaleY(1);
        box-shadow: 0 0 5px rgba(40, 167, 69, 0.5);
    }
}

@keyframes glow-last {
    0% {
        opacity: 0.7;
        transform: scaleY(1);
        box-shadow: 0 0 5px rgba(220, 53, 69, 0.5);
    }

    50% {
        opacity: 1;
        transform: scaleY(1.4);
        box-shadow: 0 0 20px rgba(220, 53, 69, 0.9);
    }

    100% {
        opacity: 0.7;
        transform: scaleY(1);
        box-shadow: 0 0 5px rgba(220, 53, 69, 0.5);
    }
}

/* Animazioni */
@keyframes pulse {
    0% {
        opacity: 0.4;
        transform: scaleY(1);
    }

    50% {
        opacity: 1;
        transform: scaleY(1.2);
    }

    100% {
        opacity: 0.4;
        transform: scaleY(1);
    }
}

@keyframes shake {
    0%, 100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-2px);
    }

    75% {
        transform: translateX(2px);
    }
}

/* Feedback per drop non valido */
.invalid-drop {
    animation: shake 0.3s ease-in-out;
    background-color: #f8d7da !important;
    border-color: #dc3545 !important;
}

/* Stili responsivi */
@media (max-width: 768px) {
    .drag-handle {
        width: 25px;
        min-width: 25px;
        max-width: 25px;
        padding: 3px;
    }

        .drag-handle .fas {
            font-size: 12px;
        }
}

/* Miglioramenti per l'accessibilità */
.drag-handle:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Tooltip per l'handle */
.drag-handle[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #333;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    z-index: 1001;
    margin-bottom: 5px;
}

.drag-handle[title]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #333;
    z-index: 1001;
}

/* Fix per conflitti con altri stili */
.drag-handle * {
    pointer-events: none !important;
}

/* Stili per prevenire interferenze con altri componenti */
.multiselect__tags,
.multiselect__content {
    pointer-events: auto !important;
}

body.dragging-active .multiselect__tags,
body.dragging-active .multiselect__content,
body.dragging-active .btn,
body.dragging-active input,
body.dragging-active select,
body.dragging-active textarea {
    pointer-events: none !important;
}

/* Così si vede meglio dove sposto la riga */
.drag-over td {
    position: relative;
}

    .drag-over td::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(33, 150, 243, 0.1);
        pointer-events: none;
        z-index: 1;
    }


/* INDICATORI VISIVI PER POSIZIONE DROP - VERSIONE SENZA PSEUDO-ELEMENTI */

/* Reset completo per evitare conflitti */
.drag-over-top,
.drag-over-bottom {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    animation: none !important;
    position: relative;
}

/* Indicatore per drop nella metà superiore della riga (inserirà SOPRA) */
.drag-over-top {
    border-top: 3px solid #007bff !important;
    background: linear-gradient(180deg, rgba(0, 123, 255, 0.1) 0%, transparent 30%) !important;
    opacity: 0.7 !important;
    animation: pulse-top-simple 1.5s infinite ease-in-out;
}

/* Indicatore per drop nella metà inferiore della riga (inserirà SOTTO) */
.drag-over-bottom {
    border-bottom: 3px solid #007bff !important;
    background: linear-gradient(0deg, rgba(0, 123, 255, 0.1) 0%, transparent 30%) !important;
    opacity: 0.7 !important;
    animation: pulse-bottom-simple 1.5s infinite ease-in-out;
}

/* Priorità assoluta: una riga può avere SOLO uno stato alla volta */
.drag-over-top.drag-over-bottom {
    border-bottom: none !important;
    border-top: 3px solid #007bff !important;
    animation: pulse-top-simple 1.5s infinite ease-in-out;
}

/* Override completo della classe drag-over standard */
.drag-over-top.drag-over,
.drag-over-bottom.drag-over,
tr.drag-over.drag-over-top,
tr.drag-over.drag-over-bottom {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    transform: none !important;
    opacity: 0.6 !important;
}

/* Riapplica gli stili specifici dopo l'override */
tr.drag-over.drag-over-top {
    border-top: 3px solid #007bff !important;
    background: linear-gradient(180deg, rgba(0, 123, 255, 0.1) 0%, transparent 30%) !important;
    opacity: 0.7 !important;
}

tr.drag-over.drag-over-bottom {
    border-bottom: 3px solid #007bff !important;
    background: linear-gradient(0deg, rgba(0, 123, 255, 0.1) 0%, transparent 30%) !important;
    opacity: 0.7 !important;
}

/* Forza table-layout fisso durante il drag per evitare ricalcoli */
body.dragging-active table,
body.dragging-active .table {
    table-layout: fixed !important;
    width: 100% !important;
}

/* Forza le celle a mantenere le loro dimensioni */
body.dragging-active td,
body.dragging-active th {
    box-sizing: border-box !important;
    overflow: hidden !important;
}

/* Indicatori per prima/ultima posizione - VERSION SEMPLIFICATA */
tbody.drop-zone-first {
    position: relative;
    /*background: linear-gradient(180deg, rgba(40, 167, 69, 0.15) 0%, transparent 0%) !important;*/
    border-top: 3px solid #007bff !important;
}

tbody.drop-zone-last {
    position: relative;
   /* background: linear-gradient(0deg, rgba(220, 53, 69, 0.15) 0%, transparent 0%) !important;*/
    border-bottom: 3px solid #007bff !important;
}

/* Reset quando il drag finisce */
tbody:not(.drop-zone-first):not(.drop-zone-last) {
    background: none !important;
    border: none !important;
}

/* Animazioni semplificate - solo opacity per evitare layout shift */
@keyframes pulse-top-simple {
    0% {
        opacity: 0.5;
        border-top-color: rgba(0, 123, 255, 0.6);
    }

    50% {
        opacity: 0.8;
        border-top-color: rgba(0, 123, 255, 1);
    }

    100% {
        opacity: 0.5;
        border-top-color: rgba(0, 123, 255, 0.6);
    }
}

@keyframes pulse-bottom-simple {
    0% {
        opacity: 0.5;
        border-bottom-color: rgba(0, 123, 255, 0.6);
    }

    50% {
        opacity: 0.8;
        border-bottom-color: rgba(0, 123, 255, 1);
    }

    100% {
        opacity: 0.5;
        border-bottom-color: rgba(0, 123, 255, 0.6);
    }
}

/* Performance optimization */
.dragging,
.drag-over,
.drag-over-top,
.drag-over-bottom {
    will-change: transform, opacity;
}

.table td:nth-child(2) {
    min-width: 150px !important;
    width: 150px !important;
}

    .table td:nth-child(2) select {
        width: 100% !important;
        min-width: 140px !important;
    }

.multiselect__clear {
    display: none !important;
}


.cpa-dnd-container.drop-zone-first::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background-color: #007bff;
    z-index: 1000;
}

.cpa-dnd-container.drop-zone-last::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background-color: #007bff;
    z-index: 1000;
}

.cpa-dnd-container tr.drag-over-top {
    border-top: 3px solid #007bff;
}

.cpa-dnd-container tr.drag-over-bottom {
    border-bottom: 3px solid #007bff;
}

.cpa-dnd-container tr.dragging {
    opacity: 0.5;
    transform: scale(0.95);
    transition: all 0.2s ease;
}

.dragging-active .cpa-dnd-container tr:not(.dragging) {
    transition: all 0.2s ease;
}

.drag-handle {
    cursor: move !important;
}

    .drag-handle:hover {
        background-color: #e9ecef !important;
    }