/**
 * AG FILE UPLOADER - CSS Styles
 * 
 * Stili unificati per il componente file uploader
 * Utilizzato da partial: functions/views/partials/_file-uploader.php
 * 
 * @version 2.0.0
 * @author AG Framework
 */

/* ========================================================================
   DRAG & DROP ZONE
   ======================================================================== */

.drag-drop-zone {
    position: relative;
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    background-color: #f9fafb;
    transition: all 0.3s ease;
    cursor: pointer;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.drag-drop-zone:hover {
    border-color: #206bc4;
    background-color: #f0f7ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(32, 107, 196, 0.1);
}

.drag-drop-zone.drag-over {
    border-color: #206bc4;
    background-color: #e6f2ff;
    border-style: solid;
    box-shadow: 0 0 20px rgba(32, 107, 196, 0.2);
}

/* Variante Compact */
.drag-drop-zone-compact {
    padding: 24px 16px;
    min-height: 140px;
}

.drag-drop-zone-compact .drag-drop-icon i {
    font-size: 2rem;
}

.drag-drop-zone-compact .drag-drop-text {
    font-size: 0.9rem;
}

/* Icona */
.drag-drop-icon {
    margin-bottom: 16px;
}

.drag-drop-icon i {
    font-size: 3rem;
    color: #206bc4;
    opacity: 0.7;
    transition: all 0.3s ease;
}

.drag-drop-zone:hover .drag-drop-icon i {
    opacity: 1;
    transform: scale(1.1);
}

/* Contenuto */
.drag-drop-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.drag-drop-text {
    color: #374151;
    font-size: 1rem;
    margin: 0;
}

.drag-drop-button {
    font-weight: 500;
    padding: 8px 24px;
    border-width: 2px;
    transition: all 0.2s ease;
}

.drag-drop-button:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(32, 107, 196, 0.2);
}

.drag-drop-description {
    color: #6b7280;
    font-size: 0.875rem;
    margin-top: 12px;
}

/* Input nascosto */
.file-input-hidden {
    display: none !important;
}

/* ========================================================================
   PROGRESS BAR
   ======================================================================== */

.upload-progress {
    animation: fadeInDown 0.3s ease;
}

.upload-progress .progress {
    height: 24px;
    border-radius: 8px;
    background-color: #e5e7eb;
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.upload-progress .progress-bar {
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 24px;
    transition: width 0.3s ease;
    background: linear-gradient(90deg, #206bc4 0%, #4299e1 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.upload-progress .progress-text {
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* ========================================================================
   FILES LIST CONTAINER
   ======================================================================== */

.files-list-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.files-list-container:empty {
    display: none;
}

/* File Item Card */
.file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    transition: all 0.2s ease;
    animation: fadeInUp 0.3s ease;
}

.file-item:hover {
    border-color: #206bc4;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

/* File Icon */
.file-item-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: linear-gradient(135deg, #f0f7ff 0%, #e6f2ff 100%);
    color: #206bc4;
    font-size: 1.2rem;
}

.file-item-icon.file-pdf {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #dc2626;
}

.file-item-icon.file-word {
    background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
    color: #2563eb;
}

.file-item-icon.file-excel {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    color: #059669;
}

.file-item-icon.file-image {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #d97706;
}

.file-item-icon.file-zip {
    background: linear-gradient(135deg, #e9d5ff 0%, #d8b4fe 100%);
    color: #7c3aed;
}

/* File Info */
.file-item-info {
    flex: 1;
    min-width: 0; /* Previene overflow */
}

.file-item-name {
    font-weight: 600;
    color: #1f2937;
    font-size: 0.9rem;
    margin-bottom: 2px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    line-height: 1.2;
    color: #6b7280;
}

.file-item-size,
.file-item-date,
.file-item-uploader {
    display: flex;
    align-items: center;
    gap: 3px;
}

.file-item-meta i {
    font-size: 1rem;
    opacity: 0.7;
}

/* File Actions */
.file-item-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.file-item-actions .btn {
    padding: 6px 10px;
    font-size: 0.8rem;
    font-weight: 500;
    border-width: 1px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.file-item-actions .btn i {
    font-size: 0.95rem;
}

/* ⚠️ DIMENSIONI BOTTONI PIÙ COMPATTI */
.file-item-actions .btn-sm {
    padding: 4px 8px;
    font-size: 0.75rem;
}

.file-item-actions .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Download Button */
.file-item-actions .btn-primary {
    background-color: #206bc4;
    border-color: #206bc4;
    color: #fff;
}

.file-item-actions .btn-primary:hover {
    background-color: #1a5ba8;
    border-color: #1a5ba8;
    box-shadow: 0 2px 8px rgba(32, 107, 196, 0.3);
}

/* Delete Button */
.file-item-actions .btn-danger {
    background-color: #dc2626;
    border-color: #dc2626;
    color: #fff;
}

.file-item-actions .btn-danger:hover {
    background-color: #b91c1c;
    border-color: #b91c1c;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.3);
}

/* View Button */
.file-item-actions .btn-info {
    background-color: #0891b2;
    border-color: #0891b2;
    color: #fff;
}

.file-item-actions .btn-info:hover {
    background-color: #0e7490;
    border-color: #0e7490;
    box-shadow: 0 2px 8px rgba(8, 145, 178, 0.3);
}

/* ========================================================================
   PREVIEW AREA (durante upload)
   ======================================================================== */

.upload-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
}

.upload-preview:empty {
    display: none;
}

/* Nascondi progress bar generale quando è seguita da preview non vuota */
.upload-progress:has(~ .upload-preview:not(:empty)) {
    display: none !important;
}

/* Fallback per browser senza :has() - usa invece classe JS */
.upload-progress.hide-when-preview {
    display: none !important;
}

.file-preview-card {
    position: relative;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
    background: #ffffff;
    text-align: center;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    animation: fadeInScale 0.3s ease;
}

.file-preview-card:hover {
    border-color: #206bc4;
    box-shadow: 0 4px 12px rgba(32, 107, 196, 0.15);
    transform: translateY(-2px);
}

/* File completato con successo - stile discreto e professionale */
.file-preview-card.upload-complete {
    /* Mantieni gli stili base senza bordo verde invasivo */
    background: #ffffff;
    border-color: #e5e7eb;
}

.file-preview-card.upload-complete:hover {
    border-color: #206bc4;
    box-shadow: 0 4px 12px rgba(32, 107, 196, 0.15);
    transform: translateY(-2px);
}

/* Errore upload - indica visivamente solo in caso di errore */
.file-preview-card.upload-error {
    border-color: #fca5a5;
    background: #fef2f2;
}

.file-preview-image {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 12px;
    border: 1px solid #e5e7eb;
}

.file-preview-icon {
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: #206bc4;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border-radius: 8px;
    border: 1px solid rgba(32, 107, 196, 0.1);
}

.file-preview-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 6px;
    line-height: 1.3;
}

.file-preview-size {
    font-size: 0.75rem;
    color: #6b7280;
    margin-bottom: 10px;
    font-weight: 500;
}

.file-preview-progress {
    width: 100%;
}

.file-preview-progress .progress {
    height: 8px;
    border-radius: 4px;
    background-color: #f3f4f6;
    overflow: hidden;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

.file-preview-progress .progress-bar {
    background: linear-gradient(90deg, #206bc4 0%, #4299e1 100%);
    transition: width 0.3s ease;
    box-shadow: 0 0 8px rgba(32, 107, 196, 0.4);
}

.file-preview-remove {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid #e5e7eb;
    color: #dc2626;
    font-size: 0.9rem;
    opacity: 0.8;
    transition: all 0.2s ease;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.file-preview-remove:hover {
    opacity: 1;
    background: #fee2e2;
    border-color: #dc2626;
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(220, 38, 38, 0.2);
}

.file-preview-remove:active {
    transform: scale(0.95);
}

/* ========================================================================
   RESPONSIVE
   ======================================================================== */

@media (max-width: 768px) {
    .drag-drop-zone {
        padding: 24px 16px;
        min-height: 160px;
    }
    
    .drag-drop-icon i {
        font-size: 2rem;
    }
    
    .file-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .file-item-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .file-item-actions .btn {
        flex: 1;
        justify-content: center;
        font-size: 0.85rem;
        padding: 8px 12px;
    }
    
    .file-item-meta {
        flex-wrap: wrap;
    }
}

/* ========================================================================
   ANIMATIONS
   ======================================================================== */

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* ========================================================================
   EMPTY STATE
   ======================================================================== */

.files-list-empty {
    text-align: center;
    padding: 40px 20px;
    color: #9ca3af;
}

.files-list-empty i {
    font-size: 3rem;
    margin-bottom: 12px;
    opacity: 0.5;
}

.files-list-empty p {
    margin: 0;
    font-size: 0.95rem;
}

/* ========================================================================
   LOADING ANIMATIONS
   ======================================================================== */

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.rotating {
    animation: rotate 1s linear infinite;
    display: inline-block;
}

/* Button loading state */
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
/* ========================================================================
   FUNZIONALITÀ ENHANCED
   ======================================================================== */

/* Search Box */
.ag-file-search-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 1rem;
}

.ag-file-search-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
}

.ag-file-search-input {
    padding-left: 2.5rem;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    width: 100%;
}

.ag-file-search-input:focus {
    border-color: #206bc4;
    box-shadow: 0 0 0 0.2rem rgba(32, 107, 196, 0.25);
}

.ag-file-search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    pointer-events: none;
}

/* Select2 categoria filtro */
.ag-file-cat-select + .select2-container {
    flex-shrink: 0;
}

.ag-file-search-container .select2-container--default .select2-selection--single {
    height: 38px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    display: flex;
    align-items: center;
}

.ag-file-search-container .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 36px;
    color: #495057;
}

.ag-file-search-container .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
}

/* Enhanced File Item */
.ag-file-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem; /* RIDOTTO da 1rem a 0.5rem */
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 0.5rem; /* RIDOTTO da 0.75rem */
    transition: all 0.2s ease;
    position: relative;
    min-height: auto; /* RIMOSSO min-height fisso */
}

.ag-file-item:hover {
    border-color: #206bc4;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

/* Drag Handle */
.ag-file-drag-handle {
    cursor: grab;
    padding: 0.5rem;
    margin-right: 0.75rem;
    color: #9ca3af;
    font-size: 1.25rem;
}

.ag-file-drag-handle:hover {
    color: #206bc4;
}

.ag-file-drag-handle:active {
    cursor: grabbing;
}

/* Drag & Drop States */
.ag-file-ghost {
    opacity: 0.4;
    background: #f3f4f6;
}

.ag-file-chosen {
    background: #e6f2ff;
    border-color: #206bc4;
    box-shadow: 0 4px 12px rgba(32, 107, 196, 0.2);
}

.ag-file-drag {
    transform: rotate(2deg);
    cursor: grabbing;
}

/* File Info Section */
.ag-file-info {
    flex: 1;
    min-width: 0;
    margin-right: 1rem;
}

.ag-file-title {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.25rem;
}

.ag-file-name {
    font-size: 0.75rem;
    color: #6c757d;
    margin-bottom: 0.15rem;
    line-height: 1.2;
}

.ag-file-description-preview {
    font-size: 0.75rem;
    color: #9ca3af;
    font-style: italic;
    line-height: 1.2;
    margin-top: 0.1rem;
}

.ag-file-meta {
    display: flex;
    gap: 0.6rem;
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 0.3rem;
    line-height: 1.2;
}

/* Meta Info in alto a destra */
.ag-file-meta-top {
    position: absolute;
    top: 6px;
    right: 8px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 1.5em;
    font-size: 0.8rem;
    color: #525252;
    line-height: 1;
    pointer-events: none; /* Non interferisce con i click sui bottoni */
}

.ag-file-meta-top .file-item-size,
.ag-file-meta-top .file-item-date,
.ag-file-meta-top .file-item-expiry {
    display: flex;
    align-items: center;
    gap: 2px;
}

.ag-file-meta-top i {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* File Scaduto - Sfondo rosso chiaro */
.ag-file-expired {
    background-color: #fdf6f6 !important;
    border-left: 3px solid #d63939;
}

.ag-file-expired:hover {
    background-color: #fce8e8 !important;
}

/* Label scadenza */
.file-item-expiry {
    font-weight: 500;
}

.file-item-expiry.text-danger {
    color: #d63939 !important;
}

.file-item-expiry.text-warning {
    color: #f76707 !important;
}

/* Spazio per file-item-actions per non sovrapporsi */
.file-item-actions {
    margin-top: 18px; /* Lascia spazio alle meta-info sopra */
}

/* Rendi il file-item relative per posizionare meta-top */
.file-item {
    position: relative;
}

/* Description Icon con Tooltip */
.ag-file-description-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-right: 0.3rem;
    color: #206bc4;
    cursor: help;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.ag-file-description-icon:hover {
    color: #1862ab;
    transform: scale(1.1);
}

/* Actions Buttons Enhanced */
.ag-file-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.ag-file-actions .btn {
    white-space: nowrap;
}

.ag-file-actions .btn-sm {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

/* Sortable List */
.ag-files-sortable {
    min-height: 50px;
}

/* Tooltip Custom Styles */
.tooltip {
    font-size: 0.875rem;
}

.tooltip-inner {
    max-width: 300px;
    text-align: left;
    padding: 0.75rem;
}

/* Modal TinyMCE Fix */
.tox-tinymce-aux {
    z-index: 1060 !important;
}

.modal-body .tox-toolbar {
    background: #f8f9fa !important;
}

/* Empty State Enhanced */
.files-list-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: #6c757d;
}

.files-list-empty i {
    font-size: 3rem;
    color: #d1d5db;
    margin-bottom: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .ag-file-item {
        flex-wrap: wrap;
    }
    
    .ag-file-actions {
        width: 100%;
        margin-top: 0.75rem;
        justify-content: flex-end;
    }
    
    .ag-file-drag-handle {
        order: -1;
    }
    
    .ag-file-description-icon {
        display: none;
    }
}

/* Print Styles */
@media print {
    .ag-file-search-container,
    .ag-file-drag-handle,
    .ag-file-actions {
        display: none !important;
    }
    
    .ag-file-item {
        break-inside: avoid;
        border: 1px solid #000;
        margin-bottom: 0.5rem;
    }
}

/* ============================================================================
   CATEGORY BADGE
   ============================================================================ */
.ag-file-category-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.72rem;
    font-weight: 600;
    color: #1a5fb4;
    background-color: rgba(59, 125, 216, 0.13);
    border: 1px solid rgba(59, 125, 216, 0.40);
    border-radius: 5px;
    padding: 2px 9px;
    margin-bottom: 3px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    white-space: nowrap;
    box-shadow: 0 1px 2px rgba(59, 125, 216, 0.08);
}

.ag-file-category-badge .ti {
    font-size: 0.75rem;
    margin-right: 2px;
}

.ag-file-badge-group {
    font-weight: 500;
    color: #495057;
    text-transform: none;
    letter-spacing: 0;
}

.ag-file-badge-sep {
    color: #adb5bd;
    font-weight: 400;
    font-size: 0.80rem;
    text-transform: none;
    letter-spacing: 0;
    margin: 0 2px;
}

.ag-file-category-badge--deleted {
    color: #c47d0e;
    background-color: rgba(255, 171, 0, 0.12);
    border-color: rgba(196, 125, 14, 0.40);
}

.ag-file-category-badge--deleted .ag-file-badge-group {
    color: #c47d0e;
}