/**
 * Dashboard Container Module CSS - Versione corretta
 */

/* Nascondi elementi in modalità non-modifica */
.edit-mode-only.hidden {
    display: none !important;
}

/* Stile per la dashboard in modalità modifica */
.dashboard-container.edit-mode {
    border: 2px dashed #007bff;
    background-color: rgba(0, 123, 255, 0.05);
    padding: 10px;
    position: relative;
    transition: all 0.3s ease;
}

.dashboard-container.edit-mode:before {
    content: "Modalità modifica";
    position: absolute;
    top: -10px;
    left: 10px;
    background: #007bff;
    color: white;
    padding: 2px 8px;
    font-size: 12px;
    border-radius: 3px;
    z-index: 100;
}

/* Evidenzia celle e righe in modalità modifica */
.dashboard-container.edit-mode .dashboard-cell {
    border: 1px dashed rgba(0, 123, 255, 0.5);
    background-color: rgba(255, 255, 255, 0.8);
    min-height: 80px; /* Altezza minima per celle vuote */
    transition: all 0.3s ease;
}

.dashboard-container.edit-mode .dashboard-row {
    margin-bottom: 10px;
    border-bottom: 1px solid rgba(0, 123, 255, 0.2);
    padding-bottom: 10px;
}

/* Stile widget in modalità modifica */
.dashboard-container.edit-mode .dashboard-widget {
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.dashboard-container.edit-mode .dashboard-widget:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transform: translateY(-2px);
}

/* Dashboard Container */
.dashboard-container {
    margin-bottom: 2rem;
    font-family: var(--body-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
    transition: margin-right 0.3s ease; /* Aggiungi transizione per il margine */
}

/* Sposta il container quando il pannello è aperto */
body.panel-open .dashboard-container {
    margin-right: 320px; /* Imposta un margine pari alla larghezza del pannello */
}

/* Su schermi piccoli, non spostare il container */
@media (max-width: 992px) {
    body.panel-open .dashboard-container {
        margin-right: 0;
    }
}

/* Dashboard Header */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.dashboard-title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--body-color, #212529);
}

.dashboard-customize-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.25rem;
    background-color: var(--primary, #0088cc);
    color: #fff;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.dashboard-customize-btn:hover {
    background-color: var(--primary-hover, #0077b3);
}

.dashboard-customize-btn:active {
    transform: translateY(1px);
}

/* Dashboard Grid - Sistema flessibile con supporto per righe */
.dashboard-grid {
    display: grid;
    grid-template-rows: auto;
    gap: 1rem;
}

/* Sistema a colonne */
.dashboard-columns-1 {
    grid-template-columns: 1fr;
}

.dashboard-columns-2 {
    grid-template-columns: repeat(2, 1fr);
}

.dashboard-columns-3 {
    grid-template-columns: repeat(3, 1fr);
}

.dashboard-columns-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* Sistema a righe */
.dashboard-rows-1 .dashboard-row {
    height: auto;
}

.dashboard-rows-2 .dashboard-row {
    height: calc(50vh - 2rem);
}

.dashboard-rows-3 .dashboard-row {
    height: calc(33vh - 2rem);
}

.dashboard-row {
    display: contents; /* Per mantenere il layout della griglia */
    min-height: 50px;
}

.dashboard-cell {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 50px; /* Altezza minima per poter trascinare */
    padding: 0.5rem;
    border: 1px dashed transparent; /* Bordo per quando si attiva il drag and drop */
    transition: border-color 0.2s;
}

.dashboard-cell.cell-highlight {
    border-color: rgba(0, 136, 204, 0.5);
    background-color: rgba(0, 136, 204, 0.05);
}

/* Widgets */
.dashboard-widget {
    background-color: #fff;
    border-radius: 0.25rem;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.dashboard-widget:hover {
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
}

.widget-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--primary, #0088cc);
    color: #fff;
}

.widget-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 500;
}

.widget-title i {
    margin-right: 0.5rem;
}

.widget-actions {
    display: flex;
    gap: 0.5rem;
}

.widget-actions button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.widget-actions button:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

.widget-content {
    padding: 1rem;
}

/* Widget states */
.widget-content.loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100px;
}

.widget-ghost {
    opacity: 0.5;
    background: #c8ebfb;
}

.widget-chosen {
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.2);
}

.widget-drag {
    opacity: 0.8;
    transform: rotate(4deg);
}

/* PANNELLO DI PERSONALIZZAZIONE - VERSIONE UNIFICATA */
.dashboard-customize-panel {
    position: fixed;
    top: 0;
    right: -320px;
    width: 320px;
    height: 100vh;
    padding: 1.5rem;
    background-color: #fff;
    box-shadow: -0.25rem 0 1rem rgba(0, 0, 0, 0.1);
    z-index: 1050;
    overflow-y: auto;
    transition: right 0.3s ease;
    display: block;
}

.dashboard-customize-panel.open {
    right: 0;
}

.dashboard-customize-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 10;
}

.panel-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 500;
}

.panel-close-btn {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--body-color, #212529);
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
}

.panel-close-btn:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.dashboard-customize-panel .panel-content {
    padding: 0 0 1rem 0;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--body-color, #212529);
    background-color: #fff;
    background-clip: padding-box;
    border: 1px solid #ced4da;
    border-radius: 0.25rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus {
    color: var(--body-color, #212529);
    background-color: #fff;
    border-color: var(--primary, #0088cc);
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(0, 136, 204, 0.25);
}

/* Stile per la lista widget */
.available-widgets {
    margin: 10px 0;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #eee;
    padding: 5px;
    border-radius: 4px;
}

.available-widget {
    padding: 8px;
    margin-bottom: 5px;
    background: #f8f9fa;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.available-widget:hover {
    background-color: #e9ecef;
}

.available-widget.widget-hidden {
    background: #f1f1f1;
    color: #888;
}

.available-widget i {
    margin-right: 0.75rem;
    color: var(--primary, #0088cc);
}

.widget-toggle-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #007bff;
    margin-left: auto;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.05);
    color: var(--body-color, #212529);
    font-size: 0.75rem;
    transition: background-color 0.2s;
}

.widget-toggle-btn:hover {
    background-color: rgba(0, 0, 0, 0.1);
}

.panel-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.btn {
    display: inline-block;
    font-weight: 400;
    line-height: 1.5;
    text-align: center;
    text-decoration: none;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    border-radius: 0.25rem;
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.btn-primary {
    color: #fff;
    background-color: var(--primary, #0088cc);
    border: 1px solid var(--primary, #0088cc);
}

.btn-primary:hover {
    color: #fff;
    background-color: var(--primary-hover, #0077b3);
    border-color: var(--primary-hover, #0077b3);
}

.btn-danger {
    color: #fff;
    background-color: #dc3545;
    border: 1px solid #dc3545;
}

.btn-danger:hover {
    color: #fff;
    background-color: #bb2d3b;
    border-color: #b02a37;
}

/* Alert Messages */
.dashboard-message {
    position: fixed;
    top: 1rem;
    right: 1rem;
    padding: 0.75rem 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: 0.25rem;
    z-index: 1060;
    animation: fadeOut 3s forwards;
    animation-delay: 2s;
}

.alert-success {
    color: #0f5132;
    background-color: #d1e7dd;
    border-color: #badbcc;
}

.alert-danger {
    color: #842029;
    background-color: #f8d7da;
    border-color: #f5c2c7;
}

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

/* Stile mobile */
@media (max-width: 768px) {
    .dashboard-customize-panel {
        width: 100%;
        right: -100%;
    }
    
    /* Overlay scuro quando il pannello è aperto su mobile */
    body.panel-open::before {
        content: "";
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1049;
    }
    
    /* Stile predefinito minimizzato per mobile */
    .dashboard-customize-panel.open {
        height: auto;
        max-height: 30%;
        bottom: 0;
        top: auto;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.2);
    }
    
    /* Quando viene espanso */
    .dashboard-customize-panel.open:not(.minimized) {
        max-height: 100%;
        top: 0;
        bottom: auto;
    }
    
    /* Stile minimizzato */
    .dashboard-customize-panel.minimized {
        height: auto;
        max-height: 30%;
        bottom: 0;
        top: auto;
    }
    
    /* Indicazione visiva per trascino */
    .dashboard-customize-panel.open.minimized .panel-header:after {
        content: "";
        height: 4px;
        width: 40px;
        background: #ddd;
        border-radius: 2px;
        position: absolute;
        top: 4px;
        left: 50%;
        transform: translateX(-50%);
    }
    
    /* Messaggio informativo per minimizzato */
    .dashboard-customize-panel.open.minimized:after {
        content: "↑ Trascina verso l'alto per più opzioni";
        display: block;
        text-align: center;
        padding: 5px;
        font-size: 12px;
        color: #666;
        background: #f8f9fa;
        border-top: 1px solid #eee;
    }
    
    .dashboard-customize-panel .panel-header {
        padding: 15px;
    }
    
    .dashboard-customize-panel .minimize-btn {
        background: none;
        border: none;
        color: #666;
        font-size: 16px;
        cursor: pointer;
        margin-right: 10px;
    }
    
    /* Pulsante per chiudere in modalità mobile */
    .dashboard-customize-panel .mobile-close {
        display: block;
        width: 100%;
        text-align: center;
        padding: 12px;
        background: #f8f9fa;
        border-top: 1px solid #eee;
        color: #666;
        font-weight: bold;
        margin-top: 15px;
    }
    
    /* Migliora accessibilità touch */
    .dashboard-customize-panel .form-group {
        margin-bottom: 20px;
    }
    
    .dashboard-customize-panel .panel-actions {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    
    .dashboard-customize-panel .panel-actions button {
        padding: 12px;
        width: 100%;
    }
    
    .dashboard-columns-3,
    .dashboard-columns-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Personalizza il selettore per rendere più facile interagire su mobile */
.dashboard-customize-panel select {
    height: 40px;
    font-size: 16px; /* Dimensione minima per evitare lo zoom su iOS */
}

.dashboard-customize-panel button {
    padding: 8px 12px;
    min-height: 40px; /* Dimensione minima per il touch */
}

/* Responsive Adjustments */
@media (max-width: 992px) {
    .dashboard-columns-4 {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Layout desktop - sposta la dashboard quando il pannello è aperto */
@media (min-width: 769px) {

    /* Sposta la dashboard a sinistra quando il pannello è aperto */
    .dashboard-container.edit-mode {
        transition: margin-right 0.3s ease;
        margin-right: 320px;  /* Larghezza del pannello + spazio */
        max-width: calc(100% - 320px);
    }
} 


@media (max-width: 576px) {
    .dashboard-columns-2,
    .dashboard-columns-3,
    .dashboard-columns-4 {
        grid-template-columns: 1fr;
    }
}
