/**
 * CSS per le ottimizzazioni implementate
 * Include stili per gestione errori, auto-save, validazione avanzata e compressione immagini
 */

/* === SISTEMA GESTIONE ERRORI === */
.area-notifiche {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    max-width: 400px;
    pointer-events: none;
}

.notifica {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    margin-bottom: 10px;
    padding: 0;
    opacity: 0;
    transform: translateX(100%);
    animation: slideIn 0.3s ease-out forwards;
    pointer-events: auto;
    border-left: 4px solid #007bff;
}

.notifica.errore {
    border-left-color: #dc3545;
}

.notifica.successo {
    border-left-color: #28a745;
}

.notifica.avviso {
    border-left-color: #ffc107;
}

.notifica-contenuto {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    font-size: 14px;
    line-height: 1.4;
}

.notifica-chiudi {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: #666;
    margin-left: 10px;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notifica-chiudi:hover {
    color: #333;
}

@keyframes slideIn {
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* === SISTEMA AUTO-SAVE === */
.autosave-indicatore {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 8px 15px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: all 0.3s ease;
}

.autosave-indicatore.modificato {
    border-color: #ffc107;
    background: #fff8e1;
}

.autosave-indicatore.salvato {
    border-color: #28a745;
    background: #f8fff9;
}

.autosave-indicatore.recuperato {
    border-color: #007bff;
    background: #f0f8ff;
}

.stato-icona {
    font-size: 14px;
}

.stato-testo {
    font-weight: 500;
    color: #333;
}

.ultimo-salvataggio {
    color: #666;
    font-size: 11px;
}

/* Dialogo di recupero dati */
.dialogo-recupero {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
}

.dialogo-contenuto {
    background: #fff;
    border-radius: 12px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.dialogo-contenuto h3 {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 18px;
}

.dialogo-contenuto p {
    margin: 10px 0;
    color: #666;
    line-height: 1.5;
}

.dialogo-azioni {
    display: flex;
    gap: 10px;
    margin-top: 25px;
    justify-content: flex-end;
}

.dialogo-azioni .btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-primary {
    background: #007bff;
    color: white;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

/* === SISTEMA VALIDAZIONE AVANZATA === */
.validation-error {
    color: #dc3545;
    font-size: 12px;
    margin-top: 5px;
    display: block;
    animation: fadeIn 0.2s ease-in;
}

.validation-error-field {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
}

.validation-success-field {
    border-color: #28a745 !important;
    box-shadow: 0 0 0 0.2rem rgba(40, 167, 69, 0.25) !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Indicatori di validazione */
.campo-validazione {
    position: relative;
}

.campo-validazione::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background-size: contain;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.campo-validazione.validation-success-field::after {
    content: '✓';
    color: #28a745;
    font-weight: bold;
    opacity: 1;
    background: none;
    width: auto;
    height: auto;
}

.campo-validazione.validation-error-field::after {
    content: '✗';
    color: #dc3545;
    font-weight: bold;
    opacity: 1;
    background: none;
    width: auto;
    height: auto;
}

/* === SISTEMA COMPRESSIONE IMMAGINI === */
.compression-progress {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
    margin: 15px 0;
}

.compression-progress h4 {
    margin: 0 0 15px 0;
    color: #333;
    font-size: 16px;
}

.progress-bar {
    width: 100%;
    height: 20px;
    background: #e9ecef;
    border-radius: 10px;
    overflow: hidden;
    margin: 10px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #007bff, #0056b3);
    border-radius: 10px;
    transition: width 0.3s ease;
    position: relative;
}

.progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 12px;
    font-weight: 500;
}

.compression-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-top: 15px;
}

.stat-item {
    text-align: center;
    padding: 10px;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
}

.stat-value {
    font-size: 18px;
    font-weight: bold;
    color: #007bff;
    display: block;
}

.stat-label {
    font-size: 12px;
    color: #666;
    margin-top: 5px;
}

/* Drag & Drop per immagini */
.drag-drop-area {
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    padding: 40px 20px;
    text-align: center;
    background: #f8f9fa;
    transition: all 0.3s ease;
    cursor: pointer;
}

.drag-drop-area:hover {
    border-color: #007bff;
    background: #f0f8ff;
}

.drag-drop-area.drag-over {
    border-color: #007bff;
    background: #e3f2fd;
    transform: scale(1.02);
}

.drag-drop-icon {
    font-size: 48px;
    color: #dee2e6;
    margin-bottom: 15px;
}

.drag-drop-text {
    color: #666;
    font-size: 16px;
    margin-bottom: 10px;
}

.drag-drop-hint {
    color: #999;
    font-size: 14px;
}

/* Anteprima immagini compresse */
.image-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.preview-item {
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.preview-image {
    width: 100%;
    height: 150px;
    object-fit: cover;
    display: block;
}

.preview-info {
    padding: 10px;
    font-size: 12px;
    color: #666;
}

.preview-filename {
    font-weight: 500;
    color: #333;
    margin-bottom: 5px;
    word-break: break-word;
}

.preview-size {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.preview-compression {
    color: #28a745;
    font-weight: 500;
}

/* === TEMA SCURO/CHIARO === */
:root {
    --primary-color: #007bff;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --background-color: #ffffff;
    --text-color: #333333;
    --border-color: #dee2e6;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
    --border-radius: 8px;
}

[data-theme="dark"] {
    --primary-color: #0d6efd;
    --secondary-color: #6c757d;
    --success-color: #198754;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #0dcaf0;
    --light-color: #495057;
    --dark-color: #212529;
    --background-color: #212529;
    --text-color: #ffffff;
    --border-color: #495057;
    --shadow: 0 2px 10px rgba(0,0,0,0.3);
}

/* Applicazione del tema */
body {
    background-color: var(--background-color);
    color: var(--text-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

.form-container {
    background-color: var(--background-color);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

input, textarea, select {
    background-color: var(--background-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

input:focus, textarea:focus, select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(var(--primary-color), 0.25);
}

/* === ANIMAZIONI FLUIDE === */
.form-section {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(0);
    opacity: 1;
}

.form-section.entering {
    transform: translateY(-10px);
    opacity: 0;
}

.form-section.exiting {
    transform: translateY(10px);
    opacity: 0;
}

/* Animazioni per i pulsanti */
.btn {
    transition: all 0.2s ease;
    transform: translateY(0);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Animazioni per le card */
.card {
    transition: all 0.3s ease;
    transform: translateY(0);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* === RESPONSIVE MIGLIORATO === */
@media (max-width: 768px) {
    .area-notifiche {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .autosave-indicatore {
        bottom: 10px;
        left: 10px;
        right: 10px;
        justify-content: center;
    }
    
    .dialogo-contenuto {
        margin: 20px;
        padding: 20px;
    }
    
    .dialogo-azioni {
        flex-direction: column;
    }
    
    .dialogo-azioni .btn {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .compression-stats {
        grid-template-columns: 1fr;
    }
    
    .image-preview {
        grid-template-columns: 1fr;
    }
    
    .signature-pad {
        height: 120px;
    }
    
    .form-container {
        padding: 15px;
        margin: 10px;
    }
}

@media (max-width: 480px) {
    .notifica-contenuto {
        padding: 12px 15px;
        font-size: 13px;
    }
    
    .autosave-indicatore {
        font-size: 11px;
        padding: 6px 12px;
    }
    
    .drag-drop-area {
        padding: 20px 15px;
    }
    
    .drag-drop-icon {
        font-size: 36px;
    }
    
    .drag-drop-text {
        font-size: 14px;
    }
}

/* === ACCESSIBILITÀ === */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus migliorato per accessibilità */
button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Riduzione movimento per utenti sensibili */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Contrasto elevato */
@media (prefers-contrast: high) {
    .notifica {
        border: 2px solid currentColor;
    }
    
    .btn {
        border: 2px solid currentColor;
    }
    
    input, textarea, select {
        border: 2px solid currentColor;
    }
}

/* === UTILITÀ === */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

.fade-out {
    animation: fadeOut 0.3s ease-out;
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

.slide-up {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

/* Classi di utilità per spacing */
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.mt-5 { margin-top: 3rem; }

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mb-5 { margin-bottom: 3rem; }

.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 1rem; }
.p-4 { padding: 1.5rem; }
.p-5 { padding: 3rem; }

/* Classi di utilità per testo */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-primary { color: var(--primary-color); }
.text-secondary { color: var(--secondary-color); }
.text-success { color: var(--success-color); }
.text-danger { color: var(--danger-color); }
.text-warning { color: var(--warning-color); }
.text-info { color: var(--info-color); }

.font-weight-bold { font-weight: bold; }
.font-weight-normal { font-weight: normal; }
.font-weight-light { font-weight: 300; }

/* Classi di utilità per display */
.d-none { display: none; }
.d-block { display: block; }
.d-inline { display: inline; }
.d-inline-block { display: inline-block; }
.d-flex { display: flex; }
.d-grid { display: grid; }

.justify-content-center { justify-content: center; }
.justify-content-between { justify-content: space-between; }
.justify-content-around { justify-content: space-around; }
.justify-content-start { justify-content: flex-start; }
.justify-content-end { justify-content: flex-end; }

.align-items-center { align-items: center; }
.align-items-start { align-items: flex-start; }
.align-items-end { align-items: flex-end; }
.align-items-stretch { align-items: stretch; }