/**
 * public/assets/css/components.css
 * Componenti riutilizzabili modernizzati: tabelle, modali, paginazione, upload foto, ecc.
 */

/* ============================================================
   TABELLA DATI
   ============================================================ */
.data-table-wrapper {
    overflow-x: auto;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
}

.data-table {
    width          : 100%;
    border-collapse: separate;
    border-spacing : 0;
    font-size      : var(--font-size-sm);
}

.data-table thead th {
    background    : var(--color-gray-50);
    padding       : 0.875rem 1rem;
    text-align    : left;
    font-weight   : 600;
    color         : var(--text-secondary);
    border-bottom : 2px solid var(--border-color);
    white-space   : nowrap;
    letter-spacing: 0.01em;
}

/* Intestazione ordinabile */
.data-table thead th.sortable {
    cursor    : pointer;
    user-select: none;
    transition: background var(--transition);
}
.data-table thead th.sortable:hover { background: var(--color-gray-100); }

.sort-icon {
    display     : inline-flex;
    flex-direction: column;
    margin-left : 4px;
    opacity     : 0.4;
    vertical-align: middle;
}
th.sort-asc  .sort-icon,
th.sort-desc .sort-icon { opacity: 1; }

.data-table tbody td {
    padding      : 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    color        : var(--text-primary);
    vertical-align: middle;
    transition   : background var(--transition);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr {
    transition: background var(--transition);
}
.data-table tbody tr:hover {
    background: var(--color-gray-50);
}

/* Riga evidenziata (soft delete) */
.data-table tbody tr.deleted { opacity: 0.6; font-style: italic; }

/* Link inline nelle celle della tabella */
.table-link {
    color          : var(--color-primary);
    text-decoration: none;
    font-weight    : 600;
    transition     : color var(--transition), text-shadow var(--transition);
}
.table-link:hover {
    color: var(--color-primary-dark);
    text-decoration: none;
    text-shadow: 0 0 8px rgba(37, 99, 235, 0.25);
}

/* Avatar nella tabella */
.table-avatar {
    width        : 38px;
    height       : 38px;
    border-radius: 50%;
    object-fit   : cover;
    background   : var(--color-gray-200);
    display      : flex;
    align-items  : center;
    justify-content: center;
    font-weight  : 600;
    color        : var(--color-gray-500);
    font-size    : var(--font-size-xs);
    overflow     : hidden;
    transition   : box-shadow var(--transition), transform var(--transition);
    box-shadow   : 0 2px 6px rgba(0,0,0,0.08);
}
.table-avatar:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.table-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ============================================================
   PAGINAZIONE
   ============================================================ */
.pagination {
    display        : flex;
    align-items    : center;
    justify-content: space-between;
    padding        : 0.875rem 1.25rem;
    border-top     : 1px solid var(--border-color);
    gap            : 1rem;
    flex-wrap      : wrap;
    font-size      : var(--font-size-sm);
    background     : var(--color-gray-50);
}

.pagination-info { color: var(--text-muted); }

.pagination-controls {
    display    : flex;
    align-items: center;
    gap        : 0.35rem;
}

.page-btn {
    min-width    : 36px;
    height       : 36px;
    padding      : 0 0.5rem;
    border       : 1px solid var(--border-color);
    background   : var(--color-white);
    border-radius: var(--border-radius);
    cursor       : pointer;
    font-size    : var(--font-size-sm);
    font-weight  : 500;
    display      : flex;
    align-items  : center;
    justify-content: center;
    transition   : all var(--transition);
    color        : var(--text-primary);
    box-shadow   : 0 1px 2px rgba(0,0,0,0.03);
}
.page-btn:hover:not(:disabled) {
    background: var(--color-gray-100);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.06);
    border-color: var(--color-gray-300);
}
.page-btn.active {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color     : white;
    border-color: transparent;
    box-shadow: 0 4px 12px -4px rgba(37, 99, 235, 0.35);
    font-weight: 600;
}
.page-btn.active:hover:not(:disabled) {
    background  : linear-gradient(135deg, #1d4ed8, #1e40af);
    color       : white;
    border-color: transparent;
}
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* ============================================================
   BARRA FILTRI / RICERCA
   ============================================================ */
.filters-bar {
    display    : flex;
    align-items: center;
    gap        : 0.75rem;
    flex-wrap  : wrap;
    padding    : 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background : var(--color-gray-50);
}

/* Card filtri con label sopra ogni campo */
.filters-card {
    margin-bottom: 1.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow var(--transition);
}
.filters-card:hover {
    box-shadow: var(--shadow-md);
}

.filters-card .filters-bar {
    display    : flex;
    align-items: flex-end;
    gap        : 0.875rem;
    flex-wrap  : wrap;
    padding    : 1.25rem;
    border-bottom: none;
    background : transparent;
}

.filters-group {
    display       : flex;
    flex-direction: column;
    flex          : 1;
    min-width     : 130px;
}
.filters-group-search { flex: 2; min-width: 200px; }

.filters-group-reset {
    flex      : none;
    align-self: flex-end;
    padding-bottom: 0;
}

.filters-group .form-label {
    margin-bottom: 0.4rem;
    font-weight: 600;
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.filters-card .search-input-wrapper {
    max-width: none;
    flex     : none;
    width    : 100%;
}

.search-input-wrapper {
    position  : relative;
    flex      : 1;
    min-width : 200px;
    max-width : 400px;
}
.search-input-wrapper svg {
    position : absolute;
    left     : 0.875rem;
    top      : 50%;
    transform: translateY(-50%);
    width    : 18px;
    height   : 18px;
    color    : var(--text-muted);
    pointer-events: none;
}
.search-input-wrapper input {
    padding-left: 2.5rem;
}

.filter-select {
    min-width: 140px;
}

/* ============================================================
   MODALE
   ============================================================ */
.modal-backdrop,
.modal-overlay {
    position  : fixed;
    inset     : 0;
    background: rgba(0, 0, 0, 0.45);
    z-index   : 200;
    display   : flex;
    align-items: center;
    justify-content: center;
    padding   : 1rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* Variante "movibile" (applicata a TUTTI i modali via modalEnhancer.js):
   nessun blur né oscuramento dello sfondo (i dati sottostanti restano leggibili),
   header trascinabile. Il click sullo sfondo non chiude (gestito in JS). */
.modal-backdrop.is-movable,
.modal-overlay.is-movable {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}
.modal-backdrop.is-movable .modal,
.modal-overlay.is-movable .modal {
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.45), 0 0 0 1px var(--border-color);
}
.modal-backdrop.is-movable .modal-header,
.modal-overlay.is-movable .modal-header {
    cursor: move;
    user-select: none;
    touch-action: none;
}

.modal {
    background   : var(--bg-surface);
    border       : 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow   : 0 25px 50px -12px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255,255,255,0.15) inset;
    max-width    : 540px;
    width        : 100%;
    max-height   : 90vh;
    display      : flex;
    flex-direction: column;
    animation    : modalIn 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    overflow     : hidden;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.94) translateY(12px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-xl { max-width: 1100px; }
.modal-lg { max-width: 720px; }
.modal-sm { max-width: 400px; }

.modal-header {
    display        : flex;
    align-items    : center;
    justify-content: space-between;
    padding        : 1.25rem 1.5rem;
    border-bottom  : 1px solid var(--border-color);
    background     : linear-gradient(180deg, var(--color-gray-50) 0%, var(--bg-surface) 100%);
}
.modal-header h3 { font-size: var(--font-size-lg); font-weight: 700; }

.modal-close-btn {
    background   : transparent;
    border       : none;
    color        : var(--text-muted);
    cursor       : pointer;
    padding      : 0.375rem;
    border-radius: var(--border-radius);
    display      : flex;
    align-items  : center;
    transition   : all var(--transition);
    width        : 32px;
    height       : 32px;
    justify-content: center;
}
.modal-close-btn:hover { background: var(--color-gray-100); color: var(--text-primary); }
.modal-close-btn svg   { width: 20px; height: 20px; }

.modal-body {
    padding  : 1.5rem;
    overflow-y: auto;
    flex     : 1;
}

.modal-footer {
    padding        : 1rem 1.5rem;
    border-top     : 1px solid var(--border-color);
    display        : flex;
    justify-content: flex-end;
    gap            : 0.75rem;
    background     : var(--color-gray-50);
    border-radius  : 0 0 var(--border-radius-lg) var(--border-radius-lg);
}

/* ============================================================
   UPLOAD FOTO
   ============================================================ */
.photo-upload-area {
    display       : flex;
    flex-direction: column;
    align-items   : center;
    gap           : 0.875rem;
}

.photo-preview {
    width        : 130px;
    height       : 130px;
    border-radius: 50%;
    background   : var(--color-gray-100);
    border       : 3px solid var(--border-color);
    overflow     : hidden;
    position     : relative;
    display      : flex;
    align-items  : center;
    justify-content: center;
    cursor       : pointer;
    transition   : all var(--transition);
    box-shadow   : 0 4px 12px rgba(0,0,0,0.08);
}
.photo-preview:hover {
    border-color: var(--color-primary);
    transform: scale(1.04);
    box-shadow: 0 8px 24px -4px rgba(37, 99, 235, 0.2);
}
.photo-preview img   { width: 100%; height: 100%; object-fit: cover; }
.photo-preview .photo-placeholder {
    color    : var(--text-muted);
    font-size: var(--font-size-3xl);
    font-weight: 700;
    user-select: none;
}
.photo-preview .photo-overlay {
    position  : absolute;
    inset     : 0;
    background: linear-gradient(180deg, rgba(0,0,0,0.3) 0%, rgba(0,0,0,0.6) 100%);
    display   : flex;
    align-items: center;
    justify-content: center;
    opacity   : 0;
    transition: opacity var(--transition);
    color     : white;
    font-size : var(--font-size-xs);
    font-weight: 600;
    flex-direction: column;
    gap: 0.25rem;
}
.photo-preview:hover .photo-overlay { opacity: 1; }

/* Barra di progresso upload */
.upload-progress {
    width     : 100%;
    height    : 4px;
    background: var(--color-gray-200);
    border-radius: 9999px;
    overflow  : hidden;
    display   : none;
}
.upload-progress.visible { display: block; }
.upload-progress-bar {
    height    : 100%;
    background: linear-gradient(90deg, var(--color-primary), #7c3aed);
    transition: width 0.2s ease;
}

/* ============================================================
   SEZIONE SCHEDA DIPENDENTE
   ============================================================ */
.detail-grid {
    display              : grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap                  : 1rem;
}

.detail-field {
    display       : flex;
    flex-direction: column;
    gap           : 0.35rem;
    padding       : 0.5rem 0;
}
.detail-field label {
    font-size  : var(--font-size-xs);
    font-weight: 600;
    color      : var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.detail-field .field-value {
    font-size: var(--font-size-sm);
    color    : var(--text-primary);
    font-weight: 500;
    padding: 0.25rem 0;
    background: var(--color-gray-50);
    border-radius: var(--border-radius-sm);
    padding: 0.375rem 0.625rem;
    border: 1px solid var(--border-color);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.detail-field .field-value:hover {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.06);
}

/* ============================================================
   TABS
   ============================================================ */
.tabs {
    display      : flex;
    border-bottom: 2px solid var(--border-color);
    gap          : 0;
    margin-bottom: 1.5rem;
}
.tab-btn {
    padding     : 0.75rem 1.25rem;
    border      : none;
    background  : transparent;
    cursor      : pointer;
    font-size   : var(--font-size-sm);
    font-weight : 600;
    color       : var(--text-muted);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition  : all var(--transition);
    position    : relative;
    letter-spacing: 0.01em;
}
.tab-btn:hover  {
    color: var(--text-primary);
    background: linear-gradient(180deg, transparent 60%, rgba(37, 99, 235, 0.04) 100%);
}
.tab-btn.active {
    color       : var(--color-primary);
    border-bottom-color: var(--color-primary);
    background: linear-gradient(180deg, transparent 60%, rgba(37, 99, 235, 0.06) 100%);
}
.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 20%;
    width: 60%;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
    border-radius: 9999px;
    filter: blur(2px);
    opacity: 0.5;
}

/* ============================================================
   DRAG & DROP (riordinamento campi personalizzati)
   ============================================================ */
.drag-item {
    cursor: grab;
    transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
    border-radius: var(--border-radius);
    padding: 0.625rem 1rem;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
}
.drag-item:hover {
    box-shadow: var(--shadow-sm);
    transform: translateX(2px);
}
.drag-item:active { cursor: grabbing; }
.drag-item.dragging {
    opacity   : 0.6;
    box-shadow: var(--shadow-md);
    transform: scale(1.01);
    border-color: var(--color-primary);
}
.drag-item.drag-over {
    background: var(--color-primary-light);
    border-style: dashed;
}

/* ============================================================
   STORICO MODIFICHE (audit log nel dettaglio dipendente)
   ============================================================ */
.history-item {
    display    : flex;
    gap        : 0.75rem;
    padding    : 0.875rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size  : var(--font-size-sm);
    transition : background var(--transition);
}
.history-item:hover {
    background: var(--color-gray-50);
    border-radius: var(--border-radius-sm);
    margin: 0 -0.5rem;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}
.history-item:last-child { border-bottom: none; }

.history-dot {
    width        : 10px;
    height       : 10px;
    border-radius: 50%;
    background   : linear-gradient(135deg, var(--color-primary), #7c3aed);
    margin-top   : 5px;
    flex-shrink  : 0;
    box-shadow   : 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.history-action { font-weight: 600; }
.history-meta   { color: var(--text-muted); font-size: var(--font-size-xs); }

.history-toggle-btn {
    background  : none;
    border      : none;
    cursor      : pointer;
    color       : var(--color-primary);
    font-size   : var(--font-size-xs);
    padding     : 0.25rem 0 0;
    display     : inline-flex;
    align-items : center;
    gap         : 0.25rem;
    font-weight : 600;
    transition  : color var(--transition);
}
.history-toggle-btn:hover { color: var(--color-primary-dark); }
.history-toggle-btn:hover span { text-decoration: underline; }

.history-toggle-icon {
    font-style  : normal;
    line-height : 1;
    transition  : transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
    display     : inline-block;
}
.history-toggle-btn.expanded .history-toggle-icon {
    transform: rotate(90deg);
}

.history-details {
    margin-top    : 0.5rem;
    display       : none;
    flex-direction: column;
    gap           : 0.35rem;
}
.history-details.expanded {
    display: flex;
}

.history-detail-row {
    display    : flex;
    align-items: baseline;
    gap        : 0.5rem;
    font-size  : var(--font-size-xs);
    padding    : 0.25rem 0;
}

.history-detail-key {
    font-weight   : 600;
    color         : var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink   : 0;
    min-width     : 120px;
}

.history-detail-val {
    color      : var(--text-primary);
    font-family: monospace;
    font-weight: 500;
}

.history-detail-arrow {
    color      : var(--text-muted);
    flex-shrink: 0;
}

/* ============================================================
   Selettore società (multi-tenant) nella sidebar
   ============================================================ */
.sidebar-company {
    padding: 0.25rem 0.75rem 0.75rem;
    margin-bottom: 0.35rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.sidebar-company-name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-white);
    padding: 0.5rem 0.6rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--border-radius-sm);
}
.sidebar-company-select {
    width: 100%;
    padding: 0.55rem 2rem 0.55rem 0.65rem;
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-white);
    background-color: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.10);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    /* chevron chiaro coerente con la sidebar scura */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M19 9l-7 7-7-7'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.55rem center;
    background-size: 1.05rem;
    transition: background-color var(--transition), border-color var(--transition);
}
.sidebar-company-select:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: rgba(96, 165, 250, 0.45);
}
.sidebar-company-select:focus {
    outline: none;
    border-color: #60a5fa;
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.25);
}
/* La tendina aperta è renderizzata dal SO: testo scuro su bianco per leggibilità */
.sidebar-company-select option { color: #0b1021; background: #ffffff; }
/* Quando la sidebar è minimizzata, nascondi il selettore (resta lo switch al re-espandere) */
#sidebar.collapsed .sidebar-company { display: none; }

/* ============================================================
   Overlay selezione società al primo accesso
   ============================================================ */
.company-picker-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4000;
    padding: 1rem;
}
.company-picker {
    background: var(--color-white);
    border-radius: var(--border-radius);
    padding: 1.75rem;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.company-picker-title {
    margin: 0 0 0.5rem;
    font-size: var(--font-size-xl);
    color: var(--text-primary);
}
.company-picker-sub {
    margin: 0 0 1.25rem;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}
.company-picker-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}
.company-picker-item {
    padding: 0.85rem 1rem;
    font-size: var(--font-size-base);
    font-weight: 600;
    text-align: left;
    color: var(--text-primary);
    background: var(--color-gray-100);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: var(--transition);
}
.company-picker-item:hover:not(:disabled) {
    border-color: var(--color-primary);
    color: var(--color-primary);
}
.company-picker-item.active {
    border-color: var(--color-primary);
    color: var(--color-primary);
}
.company-picker-item.active::after {
    content: ' (attuale)';
    font-weight: 400;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}
.company-picker-item:disabled { opacity: 0.6; cursor: default; }
