/* ===== SISTEMA MODALI UNIFORME ===== */

/* Modal Base */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    overscroll-behavior: contain;
    overflow-y: auto;
}

body:has(.modal.active[style*="flex"]) {
    overflow: hidden;
    touch-action: none;
}


.modal.active {
    opacity: 1;
}

/* Modal Content Container */
.modal-content {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 95%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    touch-action: pan-y;
    animation: modalSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-wide {
    max-width: 900px !important;
    width: 90% !important;
}

.grafico-container {
    position: relative;
}

.grafico-container canvas {
    width: 100% !important;
    height: 100% !important;
}

.legenda-colori {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.legenda-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    color: #555;
}

.colore-box {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.1);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Modal Header - SEMPRE VISIBILE */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid #e9ecef;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 16px 16px 0 0;
    position: sticky;
    top: 0;
    z-index: 1;
}

.modal-header h3 {
    margin: 0;
    color: #2c3e50;
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal-header .close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #6c757d;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
}

.modal-header .close-modal:hover {
    background: rgba(108, 117, 125, 0.1);
    color: #e74c3c;
    transform: scale(1.1);
}

/* Modal Body - SCROLLABILE */
.modal-body {
    padding: 2rem;
    overflow-y: auto;
    overflow-x: hidden;
    touch-action: pan-y;
    flex: 1;
    min-height: 0;
}

/* Modal Footer - SEMPRE VISIBILE */
.modal-footer {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    padding: 1.5rem 2rem;
    border-top: 1px solid #e9ecef;
    background: #f8f9fa;
    border-radius: 0 0 16px 16px;
    position: sticky;
    bottom: 0;
    z-index: 1;
}

/* ===== SISTEMA PULSANTI MODERNO UNIFORME ===== */

/* Pulsante Base */
.btn:not(.btn-storico):not(.btn-outline):not(.btn-modern) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    user-select: none;
    min-height: 44px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn:not(.btn-storico):not(.btn-outline):not(.btn-modern):disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn:not(.btn-storico):not(.btn-outline):not(.btn-modern)::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.btn:not(.btn-storico):not(.btn-outline):not(.btn-modern):hover::before {
    left: 100%;
}

/* Varianti Colore */
.btn-primary {
    background: linear-gradient(135deg, var(--brand-purple) 0%, var(--brand-purple-light) 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(13, 13, 13, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(13, 13, 13, 0.4);
    background: linear-gradient(135deg, var(--brand-purple-light) 0%, #8b5fbf 100%);
}

/* Pulsanti specifici che devono essere arancio */
.btn-primary.btn-confirm,
button[onclick*="confermaObiettivo"],
button[onclick*="confermaPagamento"] {
    background: linear-gradient(135deg, var(--brand-orange) 0%, var(--brand-orange-light) 100%) !important;
    box-shadow: 0 4px 15px rgba(255, 122, 0, 0.3) !important;
}

.btn-primary.btn-confirm:hover,
button[onclick*="confermaObiettivo"]:hover,
button[onclick*="confermaPagamento"]:hover {
    box-shadow: 0 8px 25px rgba(255, 122, 0, 0.4) !important;
    background: linear-gradient(135deg, var(--brand-orange-light) 0%, #FFA488 100%) !important;
}

.btn-secondary {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    color: #495057;
    border: 2px solid #dee2e6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.btn-secondary:hover:not(:disabled) {
    transform: translateY(-2px);
    background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
    border-color: #adb5bd;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.btn-success {
    background: linear-gradient(135deg, #ff7a00 0%, #ff9f40 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 122, 0, 0.3);
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 122, 0, 0.4);
    background: linear-gradient(135deg, #e66900 0%, #ff7a00 100%);
}

.btn-danger {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

.btn-danger:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(231, 76, 60, 0.4);
    background: linear-gradient(135deg, #c0392b 0%, #a93226 100%);
}

.btn-warning {
    background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
    color: #212529;
    box-shadow: 0 4px 15px rgba(255, 193, 7, 0.3);
}

.btn-warning:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 193, 7, 0.4);
    background: linear-gradient(135deg, #e0a800 0%, #ea6100 100%);
}

/* Dimensioni */
.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    min-height: 36px;
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1.1rem;
    min-height: 52px;
}

/* Pulsanti Icon */
.btn-icon {
    padding: 0.5rem;
    min-width: 40px;
    min-height: 40px;
    border-radius: 8px;
}

.btn-icon i {
    font-size: 1rem;
}

/* Pulsanti Full Width */
.btn-block {
    width: 100%;
    justify-content: center;
}

/* Gruppi di Pulsanti */
.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.btn-group .btn {
    flex: 1;
    min-width: auto;
}

/* Stati Speciali */
.btn-loading {
    position: relative;
    color: transparent !important;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .modal-content {
        width: 98%;
        max-height: 95vh;
        margin: 1rem;
    }
    
    .modal-header {
        padding: 1rem 1.5rem;
    }
    
    .modal-header h3 {
        font-size: 1.25rem;
    }
    
    .modal-body {
        padding: 1.5rem;
    }
    
    .modal-footer {
        padding: 1rem 1.5rem;
        flex-direction: column-reverse;
    }
    
    .btn-group {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .modal-header {
        padding: 0.75rem 1rem;
    }
    
    .modal-header h3 {
        font-size: 1.1rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 0.75rem 1rem;
    }
}