/**
 * FileGallery Component Styles
 * Supporta tutti i tipi di file con icone appropriate
 * Richiede: FontAwesome 5+
 */

/* ==================== CAMPO FILE ==================== */

/* Righe affiancate: piu' campi galleria consecutivi stanno uno accanto
   all'altro e vanno a capo quando lo spazio finisce.
   La riga FLOTTA come una colonna Bootstrap, non e' inline-block: nella stessa
   pagina convivono con le `.col-md-*`, che sono float, e mescolare i due
   modelli fa uscire i campi dall'ordine in cui sono dichiarati.
   Il padding e' il gutter di 15px della griglia, senza il quale il campo
   resterebbe a filo del contenitore e non si allineerebbe con i campi testo. */
.file-gallery-row {
    float: left;
    padding-left: 15px;
    padding-right: 15px;
    max-width: 100%;
}

/* La prima riga galleria dopo un campo normale apre una riga nuova, cosi' il
   blocco delle immagini non si incastra nella riga precedente */
.mb-3:not(.file-gallery-row) + .file-gallery-row {
    clear: left;
}

.file-gallery-field {
    margin-bottom: 1rem;
}

/* Etichetta: testo breve; quella completa e' un suggerimento fluttuante che
   compare passando il mouse sul titolo. Deve stare in `position: absolute`,
   altrimenti aprirla allungherebbe solo la riga del thumbnail interessato e
   la fila di anteprime si disallineerebbe. */
.file-gallery-label {
    position: relative;
    display: block;
    max-width: 100%;
    cursor: help;
}

.file-gallery-label__text {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    border-bottom: 1px dotted #adb5bd;
}

/* Il suggerimento: fuori dal flusso, quindi non sposta nulla.
   Resta nel DOM (solo trasparente) per non sparire ai lettori di schermo. */
.file-gallery-label__hint {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 20;
    max-width: 280px;
    width: max-content;
    margin-top: 4px;
    padding: 6px 9px;
    border-radius: 4px;
    background: rgba(33, 37, 41, 0.95);
    color: #fff;
    font-size: 11px;
    font-weight: 400;
    line-height: 1.35;
    white-space: normal;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
}

/* Freccetta verso il titolo */
.file-gallery-label__hint::before {
    content: "";
    position: absolute;
    bottom: 100%;
    left: 12px;
    border: 5px solid transparent;
    border-bottom-color: rgba(33, 37, 41, 0.95);
}

.file-gallery-label:hover .file-gallery-label__hint,
.file-gallery-label:focus-within .file-gallery-label__hint {
    opacity: 1;
}

.file-gallery-field__container {
    display: inline-block;
    padding: 15px;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    background: #fafafa;
}

/* Cornice quadrata: ancora i comandi sovrapposti e delimita l'anteprima.
   La dimensione arriva inline dalle opzioni preview_width/preview_height. */
.file-gallery-field__frame {
    position: relative;
    max-width: 100%;
    border: 2px solid #dee2e6;
    border-radius: 6px;
    background: #fff;
    overflow: hidden;
}

.file-gallery-field__preview {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* L'immagine riempie il quadrato mantenendo le proporzioni (niente stretch) */
.file-gallery-field__img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Il cursore sta sull'immagine e non sulla cornice: e' esattamente
       l'area che apre l'ingrandimento, e sui file non-immagine (icona,
       segnaposto) non deve comparire. */
    cursor: zoom-in;
}

/* Icona per file non immagine */
.file-gallery-field__icon-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px;
    text-align: center;
    width: 100%;
    height: 100%;
}

.file-gallery-field__icon-preview i {
    font-size: 3rem;
    margin-bottom: 8px;
}

.file-gallery-field__filename {
    font-size: 11px;
    color: #666;
    word-break: break-all;
    max-width: 100%;
}

/* Placeholder */
.file-gallery-field__placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: #aaa;
}

.file-gallery-field__placeholder i {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

.file-gallery-field__placeholder span {
    font-size: 12px;
}

/* Azioni: sovrapposte all'anteprima, in basso a destra dentro la cornice */
.file-gallery-field__actions {
    position: absolute;
    right: 8px;
    bottom: 8px;
    z-index: 2;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    padding: 5px;
    border-radius: 20px;
    /* i comandi sono elementi diversi (button, label, a): senza azzerare le
       metriche ereditate dal tema si disallineano di qualche pixel */
    line-height: 1;
    /* velo scuro: i comandi restano leggibili su qualsiasi immagine */
    background: rgba(0, 0, 0, 0.45);
}

/* Pulsante icona: dimensione non negoziabile.
   Il selettore e' volutamente doppio (.file-gallery-field .file-gallery-field__btn):
   global.css ha `.mb-3 button { min-width: 160px }`, che e' piu' specifico
   di una singola classe e vince. Il campo sta dentro un .mb-3, quindi con
   una classe sola i pulsanti ereditavano 160px di larghezza minima: la
   flex-basis viene clampata dal min-width, l'elemento si allarga e il
   border-radius del 50% lo rende un'ellisse. */
.file-gallery-field .file-gallery-field__btn {
    flex: 0 0 32px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    min-width: 32px;
    max-width: 32px;
    height: 32px;
    min-height: 32px;
    max-height: 32px;
    align-self: center;
    padding: 0;
    margin: 0;
    border: 0;
    vertical-align: middle;
    border-radius: 50%;
    overflow: hidden;
    font-size: 13px;
    line-height: 1;
    color: #fff;
    cursor: pointer;
    text-decoration: none;
    transition: filter 0.15s ease, transform 0.15s ease;
}

.file-gallery-field .file-gallery-field__btn > i {
    margin: 0;
}

.file-gallery-field .file-gallery-field__btn:hover,
.file-gallery-field .file-gallery-field__btn:focus {
    color: #fff;
    text-decoration: none;
    filter: brightness(1.15);
    transform: translateY(-1px);
    outline: none;
}

/* Colori per azione */
.file-gallery-field__gallery-btn {
    background-color: #007bff;
}

.file-gallery-field__upload-btn {
    background-color: #6c757d;
}

.file-gallery-field__download-btn {
    background-color: #17a2b8;
}

.file-gallery-field__delete-btn {
    background-color: #dc3545;
}

/* La label dell'upload contiene l'input nascosto: le serve essere il
   contenitore di riferimento per il posizionamento assoluto */
.file-gallery-field .file-gallery-field__upload-btn {
    position: relative;
}

/* Il tema Bootstrap avvolge l'input file in .custom-file: qui l'input e'
   nascosto dietro la label, quindi non deve occupare spazio */
.file-gallery-field__upload-btn .custom-file,
.file-gallery-field__upload-btn .custom-file-label {
    position: absolute;
    width: 0;
    height: 0;
    padding: 0;
    margin: 0;
    border: 0;
    overflow: hidden;
    opacity: 0;
}

.file-gallery-field__file-input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
}

.file-gallery-field__info {
    margin-top: 10px;
    max-width: 100%;
}

/* ==================== MODAL GALLERIA ==================== */
.file-gallery-modal .modal-dialog {
    max-width: 900px;
    width: auto;
}

.file-gallery-modal .modal-content {
    position: relative;
}

.file-gallery-modal__header {
    position: relative;
}

/*
 * Pulsante di chiusura: dentro il popup, in alto a destra.
 * Il tema (minimal.css) posiziona `button.close` sopra al popup con
 * un'icona di sfondo: qui non usiamo la classe `close`, e in piu'
 * neutralizziamo esplicitamente eventuali regole ereditate.
 */
.file-gallery-modal .modal-content .modal-header .file-gallery-modal__close {
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 2;
    padding: 0;
    width: 30px;
    height: 30px;
    line-height: 28px;
    text-align: center;
    background: transparent none;
    border: 0;
    border-radius: 50%;
    font-size: 24px;
    font-weight: 400;
    color: #6c757d;
    opacity: 1;
    text-shadow: none;
    cursor: pointer;
}

.file-gallery-modal .modal-content .modal-header .file-gallery-modal__close:hover,
.file-gallery-modal .modal-content .modal-header .file-gallery-modal__close:focus {
    background: #f0f0f0 none;
    color: #212529;
    outline: none;
}

/* Nasconde un'eventuale X aggiuntiva iniettata dal tema */
.file-gallery-modal .modal-content .modal-header button.close {
    display: none !important;
}

.file-gallery-modal .modal-title {
    padding-right: 40px;
}

.file-gallery-modal .modal-body {
    max-height: 65vh;
    overflow-y: auto;
}

/* Layout a due colonne: albero categorie + contenuto */
.file-gallery-modal__body {
    display: flex;
    align-items: stretch;
    gap: 15px;
}

.file-gallery-modal__main {
    flex: 1 1 auto;
    min-width: 0;
}

/* ==================== ALBERO CATEGORIE ==================== */
.file-gallery-modal__sidebar {
    flex: 0 0 220px;
    max-width: 220px;
    border-right: 1px solid #e9ecef;
    padding-right: 12px;
}

.file-gallery-modal__sidebar-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    color: #6c757d;
    margin-bottom: 8px;
}

.file-gallery-modal__tree,
.file-gallery-modal__tree-children {
    list-style: none;
    margin: 0;
    padding: 0;
}

.file-gallery-modal__tree-children {
    padding-left: 16px;
}

.file-gallery-modal__tree-node.collapsed > .file-gallery-modal__tree-children {
    display: none;
}

.file-gallery-modal__tree-node.collapsed > .file-gallery-modal__tree-toggle i {
    transform: rotate(-90deg);
}

.file-gallery-modal__tree-toggle {
    display: inline-block;
    width: 14px;
    text-align: center;
    color: #adb5bd;
    cursor: pointer;
    font-size: 11px;
}

.file-gallery-modal__tree-toggle.is-empty {
    cursor: default;
}

.file-gallery-modal__tree-link {
    display: inline-block;
    max-width: calc(100% - 18px);
    padding: 3px 6px;
    border-radius: 4px;
    font-size: 13px;
    color: #343a40;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.file-gallery-modal__tree-link:hover {
    background: #f1f3f5;
    color: #007bff;
    text-decoration: none;
}

.file-gallery-modal__tree-link.active {
    background: #007bff;
    color: #fff;
}

/* Categoria fissa della pagina: navigabile ma non modificabile */
.file-gallery-modal__tree-link.is-readonly {
    font-weight: 600;
    text-transform: capitalize;
}

.file-gallery-modal__tree-link.is-readonly i {
    color: #adb5bd;
}

.file-gallery-modal__tree-link.is-readonly.active i {
    color: #fff;
}

.file-gallery-modal__tree-link i {
    margin-right: 5px;
}

.file-gallery-modal__tree-error {
    font-size: 12px;
    color: #dc3545;
}

.file-gallery-modal__new-folder-btn {
    display: block;
    width: 100%;
    margin-top: 12px;
    padding: 5px 8px;
    border: 1px dashed #ced4da;
    border-radius: 4px;
    background: #fff;
    color: #495057;
    font-size: 12px;
    text-align: left;
    cursor: pointer;
}

.file-gallery-modal__new-folder-btn:hover {
    border-color: #007bff;
    color: #007bff;
}

.file-gallery-modal__new-folder-btn i {
    margin-right: 5px;
}

/* Breadcrumb categoria corrente */
.file-gallery-modal__breadcrumb {
    font-size: 12px;
    color: #6c757d;
    margin-bottom: 10px;
}

/* Filtri */
.file-gallery-modal__filters {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.file-gallery-modal__filter-btn {
    padding: 5px 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.file-gallery-modal__filter-btn:hover {
    border-color: #007bff;
    color: #007bff;
}

.file-gallery-modal__filter-btn.active {
    background: #007bff;
    border-color: #007bff;
    color: #fff;
}

/* Esito del caricamento: mostra il nome del file che parte e di quello salvato */
.file-gallery-modal__upload-status {
    margin: -10px 0 15px;
    padding: 6px 10px;
    border-radius: 4px;
    background: #e7f1ff;
    color: #495057;
    font-size: 12px;
    word-break: break-all;
}

.file-gallery-modal__upload-status.is-error {
    background: #f8d7da;
    color: #842029;
}

/* Barra sposta/duplica (compare a file selezionato) */
.file-gallery-modal__transfer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 15px;
    padding: 8px 10px;
    border: 1px solid #b8daff;
    border-radius: 6px;
    background: #e7f1ff;
    font-size: 13px;
}

.file-gallery-modal__transfer-label {
    color: #495057;
    margin-right: 4px;
}

.file-gallery-modal__transfer-target {
    flex: 1 1 180px;
    min-width: 0;
    max-width: 100%;
    padding: 4px 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    background: #fff;
    color: #212529;
    font-size: 13px;
}

.file-gallery-modal__transfer-btn {
    padding: 4px 12px;
    border: 1px solid #007bff;
    border-radius: 4px;
    background: #007bff;
    color: #fff;
    font-size: 13px;
    cursor: pointer;
}

.file-gallery-modal__transfer-btn--danger {
    background: #dc3545;
    border-color: #dc3545;
}

.file-gallery-modal__transfer-btn:hover:not(:disabled) {
    filter: brightness(0.92);
}

.file-gallery-modal__transfer-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

/* Upload zone */
.file-gallery-modal__upload-zone {
    border: 2px dashed #ced4da;
    border-radius: 8px;
    padding: 25px;
    text-align: center;
    margin-bottom: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #f8f9fa;
}

.file-gallery-modal__upload-zone:hover {
    border-color: #007bff;
    background: #e7f1ff;
}

.file-gallery-modal__upload-zone.dragover {
    border-color: #28a745;
    background: #d4edda;
}

.file-gallery-modal__upload-zone i {
    display: block;
    font-size: 2rem;
    margin-bottom: 10px;
    color: #6c757d;
}

.file-gallery-modal__upload-zone p {
    margin: 0;
    color: #666;
}

.file-gallery-modal__upload-zone small {
    color: #999;
}

/* Griglia file */
.file-gallery-modal__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

/* Singolo item */
.file-gallery-modal__item {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 8px;
    padding: 10px;
    text-align: center;
    transition: all 0.2s ease;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.file-gallery-modal__item:hover {
    border-color: #007bff;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.file-gallery-modal__item.selected {
    border-color: #28a745;
    background: #f0fff4;
}

/* Preview immagine nel modal */
.file-gallery-modal__item-preview {
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    border-radius: 4px;
    overflow: hidden;
    background: #f5f5f5;
}

.file-gallery-modal__item-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Icona file nel modal */
.file-gallery-modal__item-preview i {
    font-size: 2.5rem;
}

/* Nome file */
.file-gallery-modal__item-name {
    font-size: 11px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 4px;
}

/* Info file */
.file-gallery-modal__item-info {
    font-size: 10px;
    color: #999;
}

/* Badge estensione */
.file-gallery-modal__item-ext {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: bold;
    text-transform: uppercase;
    margin-top: 5px;
}

/* Colori badge per tipo file */
.file-gallery-modal__item-ext.ext-image { background: #e8f5e9; color: #4CAF50; }
.file-gallery-modal__item-ext.ext-pdf { background: #ffebee; color: #F44336; }
.file-gallery-modal__item-ext.ext-word { background: #e3f2fd; color: #2196F3; }
.file-gallery-modal__item-ext.ext-excel { background: #e8f5e9; color: #4CAF50; }
.file-gallery-modal__item-ext.ext-powerpoint { background: #fff3e0; color: #FF9800; }
.file-gallery-modal__item-ext.ext-text { background: #eceff1; color: #607D8B; }
.file-gallery-modal__item-ext.ext-archive { background: #efebe9; color: #795548; }
.file-gallery-modal__item-ext.ext-audio { background: #f3e5f5; color: #9C27B0; }
.file-gallery-modal__item-ext.ext-video { background: #fce4ec; color: #E91E63; }
.file-gallery-modal__item-ext.ext-code { background: #e0f7fa; color: #00BCD4; }
.file-gallery-modal__item-ext.ext-default { background: #f5f5f5; color: #9E9E9E; }

/* Empty state */
.file-gallery-modal__empty {
    text-align: center;
    padding: 40px;
    color: #6c757d;
}

.file-gallery-modal__empty i {
    font-size: 3rem;
    margin-bottom: 15px;
    display: block;
}

/* Loading */
.file-gallery-modal__loading {
    text-align: center;
    padding: 40px;
}

.file-gallery-modal__loading i {
    font-size: 2rem;
    margin-bottom: 10px;
}

/* ==================== COLORI ICONE PER TIPO ==================== */
.file-icon-image { color: #4CAF50; }
.file-icon-pdf { color: #F44336; }
.file-icon-word { color: #2196F3; }
.file-icon-excel { color: #4CAF50; }
.file-icon-powerpoint { color: #FF9800; }
.file-icon-text { color: #607D8B; }
.file-icon-archive { color: #795548; }
.file-icon-audio { color: #9C27B0; }
.file-icon-video { color: #E91E63; }
.file-icon-code { color: #00BCD4; }
.file-icon-default { color: #9E9E9E; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .file-gallery-field__container {
        display: block;
        max-width: 100%;
    }

    /* La cornice si adatta alla larghezza disponibile restando quadrata */
    .file-gallery-field__frame {
        width: 100% !important;
        height: auto !important;
        aspect-ratio: 1 / 1;
    }

    .file-gallery-modal__body {
        flex-direction: column;
    }

    .file-gallery-modal__sidebar {
        flex: 0 0 auto;
        max-width: none;
        border-right: 0;
        border-bottom: 1px solid #e9ecef;
        padding-right: 0;
        padding-bottom: 10px;
    }

    .file-gallery-modal__grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }
    
    .file-gallery-modal__item-preview {
        height: 60px;
    }
    
    .file-gallery-modal__item-preview i {
        font-size: 2rem;
    }
}

/* ==================== ANIMAZIONI ==================== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.file-gallery-modal__item {
    animation: fadeIn 0.3s ease;
}

/* Progress bar per upload */
.file-gallery-modal__progress {
    margin-top: 10px;
    display: none;
}

.file-gallery-modal__progress.active {
    display: block;
}

.file-gallery-modal__progress-bar {
    height: 4px;
    background: #e0e0e0;
    border-radius: 2px;
    overflow: hidden;
}

.file-gallery-modal__progress-bar-inner {
    height: 100%;
    background: #007bff;
    width: 0%;
    transition: width 0.3s ease;
}

/* ==================== ZOOM DELL'ANTEPRIMA ==================== */

/*
 * Sovrapposto a tutta la finestra per vedere l'immagine del campo a
 * grandezza intera. Non e' un modal di Bootstrap: si apre anche sopra al
 * popup della galleria, e due modal sovrapposti lasciano il tema con lo
 * scroll bloccato alla chiusura del secondo.
 */
.file-gallery-zoom {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    /* sopra al popup della galleria, che sta sui 1050 di Bootstrap */
    z-index: 20000;
    padding: 40px 20px;
    background: rgba(0, 0, 0, 0.85);
    /* il clic sullo sfondo chiude: deve restare raggiungibile anche quando
       l'immagine e' piu' alta della finestra */
    overflow: auto;
    text-align: center;
}

.file-gallery-zoom.is-open {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Lo scroll della pagina sotto va fermato, altrimenti la rotellina sposta
   il documento invece dell'immagine ingrandita. */
body.file-gallery-zoom-open {
    overflow: hidden;
}

.file-gallery-zoom__figure {
    margin: 0;
    max-width: 100%;
    /* auto: un'immagine piccola resta piccola, non viene stirata */
    max-height: 100%;
}

.file-gallery-zoom__img {
    display: block;
    max-width: 90vw;
    /* spazio lasciato alla didascalia sotto */
    max-height: 82vh;
    margin: 0 auto;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    /* niente cursore di ingrandimento qui: il clic sull'immagine non chiude */
    cursor: default;
}

.file-gallery-zoom__caption {
    margin-top: 12px;
    color: #e9e9e9;
    font-size: 13px;
    word-break: break-all;
}

.file-gallery-zoom__close {
    position: fixed;
    top: 12px;
    right: 16px;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 28px;
    line-height: 38px;
    cursor: pointer;
}

.file-gallery-zoom__close:hover,
.file-gallery-zoom__close:focus {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
    outline: none;
}
