/* ========================================
   TABLE PERMISSIONS - EXTENDS TABLE MANAGER V2 STYLES
   ========================================
   
   FILE: tablepermissions.css
   PAGINA: TablePermissions.razor (/admin/permissions)
   CARICATO DA: _Host.cshtml (dopo tablemanagerv2.css)
   
   STRUTTURA SEZIONI:
   1. ROLE DROPDOWN POPUP      -> Stile popup Syncfusion SfDropDownList (selezione ruolo)
   2. ROLE DROPDOWN INPUT      -> Stile input del dropdown (bordo, altezza, freccia)
   3. BADGE PERSONALIZZATI     -> badge-lg, badge-xl, badge-warning con animazione pulse
   4. USERS LIST (Per Ruolo)   -> Lista utenti con checkbox (user-item, user-info)
   5. USERS GRID (Per Utente)  -> Griglia utenti cliccabili (user-card, selected state)
   6. USER EDIT HEADER         -> Header scheda modifica utente (border-left blu, gradient)
   7. CATEGORIES CONTAINER     -> Wrapper card espandibili
   8. TABLE PERMISSION ROW     -> Righe tabella con 3 stati:
      - row-enabled:  border-left blu (#2c5aa0), sfondo bianco
      - row-disabled: border-left grigio (#94a3b8), sfondo #f9fafb, opacity 0.75
      - row-modified: border-left arancione (#f59e0b), sfondo #fffbeb
   9. perm-table-info          -> Info tabella (icona + nome + descrizione)
      NOTA: rinominata da 'table-info' per evitare conflitto con Bootstrap
            .table-info { background-color: #c1f0e2 } in modern.css
  10. TOGGLE BUTTON            -> Bottone circolare ON/OFF con 3 varianti:
      - btn-success:   verde (#22c55e) = abilitato
      - btn-secondary: grigio (#e2e8f0) = disabilitato
      - btn-warning:   arancione gradient + glow animation = modificato
  11. SWITCH LABEL             -> Checkbox "Abilita Tutto" stilizzata
  12. PENDING CHANGES          -> Card modifiche pendenti con slideIn animation
  13. CHANGES LIST             -> Lista modifiche (border-left verde/rosso)
  14. RESPONSIVE               -> Breakpoint 991px, 768px, 576px
  15. LOADING/EMPTY STATE      -> Spinner e stato vuoto
  16. SCROLLBAR CUSTOM         -> Scrollbar blu per users-list e changes-list
  17. ACCESSIBILITY            -> Focus outline per tastiera
  18. PRINT STYLES             -> Nasconde bottoni e toggle in stampa
   
   COLORI PRINCIPALI:
   - Blu primario:    #2c5aa0 (bordi, hover, scrollbar, focus)
   - Verde successo:  #22c55e (toggle ON, badge-success)
   - Arancione:       #f59e0b / #ff9800 (modifiche, warning)
   - Grigio disab.:   #94a3b8 (row-disabled, toggle OFF)
   - Sfondo chiaro:   #f8fafc / #f9fafb (righe alternate/disabilitate)
*/

/* ========== ROLE DROPDOWN POPUP ========== */

/* Popup container - deve flottare sopra il contenuto */
/* SCOPED: Si applica SOLO alla pagina con classe .permissions-page */
.permissions-page .e-ddl.e-popup {
    z-index: 10000 !important;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2) !important;
    border: 1px solid #ced4da !important;
    border-radius: 6px !important;
    background-color: #fff !important;
    overflow: hidden !important;
    max-width: 350px !important;
    min-width: 200px !important;
}

/* Wrapper lista dentro il popup */
.permissions-page .e-ddl.e-popup .e-content,
.permissions-page .e-ddl.e-popup .e-ul {
    max-height: 250px !important;
    overflow-y: auto !important;
}

/* Lista Items nel Popup */
.permissions-page .e-ddl.e-popup .e-list-item {
    padding: 10px 16px !important;
    line-height: 1.5 !important;
    font-size: 0.95rem !important;
    min-height: 42px !important;
    color: #333 !important;
    cursor: pointer !important;
    transition: background-color 0.15s ease !important;
    border-bottom: 1px solid #f0f0f0 !important;
    background-color: #fff !important;
}

.permissions-page .e-ddl.e-popup .e-list-item:last-child {
    border-bottom: none !important;
}

/* Hover State */
.permissions-page .e-ddl.e-popup .e-list-item:hover,
.permissions-page .e-ddl.e-popup .e-list-item.e-hover {
    background-color: #e8f0fe !important;
    color: #2c5aa0 !important;
}

/* Active/Selected State */
.permissions-page .e-ddl.e-popup .e-list-item.e-active {
    background-color: #2c5aa0 !important;
    color: #fff !important;
    font-weight: 600 !important;
}

/* Scrollbar Popup */
.permissions-page .e-ddl.e-popup .e-content::-webkit-scrollbar {
    width: 6px;
}

.permissions-page .e-ddl.e-popup .e-content::-webkit-scrollbar-track {
    background: #f8f9fa;
}

.permissions-page .e-ddl.e-popup .e-content::-webkit-scrollbar-thumb {
    background: #adb5bd;
    border-radius: 3px;
}

.permissions-page .e-ddl.e-popup .e-content::-webkit-scrollbar-thumb:hover {
    background: #2c5aa0;
}

/* Role Selection Section */
.per-ruolo-section .card {
    position: relative;
    z-index: 1;
}

.role-stats-wrapper {
    display: flex;
    align-items: center;
    min-height: 60px;
    padding-top: 0.5rem;
}

.role-stats-wrapper .d-flex {
    width: 100%;
}

.role-stats-wrapper .gap-2 > * {
    margin-right: 0.5rem;
    margin-bottom: 0.5rem;
}

.role-stats-wrapper .gap-2 > *:last-child {
    margin-right: 0;
}

.role-stats-wrapper button {
    white-space: nowrap;
}

/* Badge Personalizzati */
.badge-lg {
    font-size: 1rem;
    padding: 0.5rem 1rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-xl {
    font-size: 1.2rem;
    padding: 0.6rem 1.2rem;
    font-weight: 600;
}

.badge-warning {
    background-color: #ff9800 !important;
    color: white !important;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Stats Inline */
.stats-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Users List (Per Ruolo) */
.users-list {
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
    position: relative;
    z-index: 1;
}

.user-item {
    padding: 1rem;
    margin-bottom: 0.75rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 2px solid #e9ecef;
    transition: all 0.3s ease;
    position: relative;
}

.user-item:hover {
    border-color: #2c5aa0;
    box-shadow: 0 2px 8px rgba(44, 90, 160, 0.2);
    transform: translateX(5px);
}

.user-item .custom-control {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 50px;
}

.user-item .custom-control-input {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    z-index: 1;
}

.user-item .custom-control-label {
    flex: 1;
    cursor: pointer;
    padding-left: 2rem;
    margin-bottom: 0;
    display: flex;
    align-items: center;
}

.user-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    min-width: 0;
}

.user-info strong {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-info small {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-item .badge {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    white-space: nowrap;
}

/* Users Grid (Per Utente) */
.users-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.user-card {
    padding: 1rem;
    background: white;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.user-card:hover {
    border-color: #2c5aa0;
    box-shadow: 0 4px 12px rgba(44, 90, 160, 0.3);
    transform: translateY(-2px);
}

.user-card.selected {
    background: #e3f2fd;
    border-color: #2196f3;
    border-width: 3px;
}

.user-card .user-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.user-card .user-details {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* User Edit Header (Modifica) */
.user-edit-header {
    border-left: 5px solid #2c5aa0;
    background: linear-gradient(to right, #f8f9fa, white);
}

.user-edit-info h4 {
    color: #2c5aa0;
    font-weight: 700;
}

.user-edit-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

/* Categories Container */
.categories-container {
    margin-top: 1rem;
}

/* Table Permission Row */
.table-permission-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    margin-bottom: 4px;
    background: #fff !important;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    border-left: 4px solid #cbd5e1;
    transition: all 0.2s ease;
}

.table-permission-row:nth-child(even) {
    background: #f8fafc !important;
}

.table-permission-row:hover {
    background: #eef2ff !important;
    border-left-color: #2c5aa0;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

/* Stato abilitata */
.table-permission-row.row-enabled {
    border-left-color: #2c5aa0;
    background: #fff !important;
}

.table-permission-row.row-enabled:nth-child(even) {
    background: #f8fafc !important;
}

.table-permission-row.row-enabled:hover {
    background: #eef2ff !important;
    border-left-color: #1e40af;
}

/* Stato disabilitata */
.table-permission-row.row-disabled {
    border-left-color: #94a3b8;
    background: #f9fafb !important;
    opacity: 0.75;
}

.table-permission-row.row-disabled:hover {
    opacity: 1;
    background: #f1f5f9 !important;
    border-left-color: #64748b;
}

/* Stato modificata */
.table-permission-row.row-modified {
    border-left-color: #f59e0b;
    background: #fffbeb !important;
}

.table-permission-row.row-modified:hover {
    background: #fef3c7 !important;
    border-left-color: #d97706;
}

.table-permission-row .perm-table-info {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1;
    min-width: 0;
}

.table-permission-row .perm-table-info i {
    font-size: 1.1rem;
    color: #475569;
    flex-shrink: 0;
}

.table-permission-row.row-enabled .perm-table-info i {
    color: #2c5aa0;
}

.table-permission-row .perm-table-info strong {
    font-size: 0.9rem;
    color: #1e293b;
}

.table-permission-row .perm-table-info .text-muted {
    font-size: 0.78rem;
    color: #94a3b8;
}

/* Toggle Button */
.toggle-btn {
    min-width: 38px;
    width: 38px;
    height: 38px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    border: 2px solid currentColor;
    border-radius: 50%;
}

.toggle-btn.btn-success {
    background: #22c55e;
    border-color: #22c55e;
    color: white;
}

.toggle-btn.btn-success:hover {
    background: #16a34a;
    border-color: #16a34a;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.4);
}

.toggle-btn.btn-secondary {
    background: #e2e8f0;
    border-color: #cbd5e1;
    color: #94a3b8;
}

.toggle-btn.btn-secondary:hover {
    background: #cbd5e1;
    border-color: #94a3b8;
    color: #64748b;
}

.toggle-btn.btn-warning {
    background: linear-gradient(135deg, #ff9800 0%, #ff6f00 100%);
    border-color: #ff9800;
    color: white;
    animation: glow 2s ease-in-out infinite;
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 5px rgba(255, 152, 0, 0.5); }
    50% { box-shadow: 0 0 20px rgba(255, 152, 0, 0.8); }
}

/* Switch Label (Abilita Tutto) */
.switch-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    padding: 0.5rem 1rem;
    background: white;
    border: 2px solid #2c5aa0;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.3s ease;
}

.switch-label:hover {
    background: #e7f3ff;
    transform: scale(1.05);
}

.switch-label input[type="checkbox"] {
    display: none;
}

.switch-label i {
    font-size: 1.5rem;
    color: #6c757d;
    transition: all 0.3s ease;
}

.switch-label input[type="checkbox"]:checked + i {
    color: #28a745;
}

/* Pending Changes Card */
.pending-changes {
    animation: slideIn 0.5s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.changes-list {
    list-style: none;
    padding: 0;
    max-height: 300px;
    overflow-y: auto;
}

.changes-list li {
    padding: 0.5rem 1rem;
    margin-bottom: 0.5rem;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid currentColor;
    transition: all 0.3s ease;
}

.changes-list li:hover {
    background: white;
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.text-success .changes-list li {
    border-left-color: #28a745;
}

.text-danger .changes-list li {
    border-left-color: #dc3545;
}

/* Category Header con Toggle */
.category-header .d-flex {
    width: 100%;
}

.category-header h5 {
    flex: 1;
}

/* Responsive */
@media (max-width: 991px) {
    .role-stats-wrapper {
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 2px solid #e9ecef;
    }

    .role-stats-wrapper .d-flex {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.75rem;
    }

    .role-stats-wrapper .gap-2 > * {
        margin-right: 0;
        margin-bottom: 0.5rem;
    }

    .role-stats-wrapper button {
        width: 100%;
        margin-left: 0 !important;
    }

    .role-stats-wrapper .badge {
        display: block;
        text-align: center;
    }
}

@media (max-width: 768px) {
    .users-grid {
        grid-template-columns: 1fr;
    }

    .user-edit-header .d-flex {
        flex-direction: column;
        align-items: stretch !important;
    }

    .user-edit-stats {
        align-items: stretch;
        margin-top: 1rem;
    }

    .stats-inline {
        flex-direction: column;
        align-items: stretch;
    }

    .table-permission-row {
        flex-direction: row;
        gap: 0.5rem;
        padding: 0.5rem 0.75rem;
    }

    .toggle-btn {
        min-width: 34px;
        width: 34px;
        height: 34px;
    }
}

@media (max-width: 576px) {
    .badge-lg {
        font-size: 0.875rem;
        padding: 0.4rem 0.8rem;
    }

    .badge-xl {
        font-size: 1rem;
        padding: 0.5rem 1rem;
    }

    .pending-changes .row {
        flex-direction: column;
    }

    .pending-changes .col-md-6 {
        margin-bottom: 1rem;
    }
}

/* Loading State */
.permissions-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
}

.permissions-loading .spinner-border {
    width: 3rem;
    height: 3rem;
    border-width: 0.3rem;
    color: #2c5aa0;
}

/* Empty State Override */
.permissions-manager .empty-state {
    padding: 3rem 1rem;
}

/* Custom Scrollbar */
.users-list::-webkit-scrollbar,
.changes-list::-webkit-scrollbar {
    width: 8px;
}

.users-list::-webkit-scrollbar-track,
.changes-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.users-list::-webkit-scrollbar-thumb,
.changes-list::-webkit-scrollbar-thumb {
    background: #2c5aa0;
    border-radius: 10px;
}

.users-list::-webkit-scrollbar-thumb:hover,
.changes-list::-webkit-scrollbar-thumb:hover {
    background: #1e4070;
}

/* Accessibility */
.user-item:focus-within,
.user-card:focus-within,
.table-permission-row:focus-within {
    outline: 2px solid #2c5aa0;
    outline-offset: 2px;
}

/* ========== ROLE DROPDOWN INPUT (.role-dropdown) ========== */

/* Componente wrapper - limita larghezza */
.role-dropdown {
    width: 100% !important;
    max-width: 350px !important;
}

/* Input group - bordo, altezza, forma */
.role-dropdown.e-ddl.e-input-group,
.role-dropdown.e-control-wrapper.e-ddl {
    height: 46px !important;
    min-height: 46px !important;
    max-height: 46px !important;
    border: 2px solid #ced4da !important;
    border-radius: 8px !important;
    background-color: #fff !important;
    display: flex !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    overflow: hidden !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
}

.role-dropdown.e-ddl.e-input-group:hover,
.role-dropdown.e-control-wrapper.e-ddl:hover {
    border-color: #2c5aa0 !important;
    box-shadow: 0 2px 8px rgba(44, 90, 160, 0.12) !important;
}

.role-dropdown.e-ddl.e-input-group.e-input-focus,
.role-dropdown.e-control-wrapper.e-ddl.e-input-focus {
    border-color: #2c5aa0 !important;
    box-shadow: 0 0 0 3px rgba(44, 90, 160, 0.2) !important;
}

/* Input text */
.role-dropdown input.e-input {
    font-size: 0.95rem !important;
    font-weight: 500 !important;
    color: #212529 !important;
    padding: 0 12px !important;
    height: 42px !important;
    line-height: 42px !important;
    background-color: transparent !important;
    flex: 1 !important;
    min-width: 0 !important;
}

/* Placeholder */
.role-dropdown input.e-input::placeholder {
    color: #6c757d !important;
    font-weight: 400 !important;
    font-size: 0.9rem !important;
}

/* Freccia dropdown */
.role-dropdown .e-input-group-icon.e-ddl-icon {
    font-size: 12px !important;
    height: 42px !important;
    width: 36px !important;
    min-width: 36px !important;
    color: #495057 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex-shrink: 0 !important;
    transition: color 0.2s ease !important;
}

.role-dropdown:hover .e-input-group-icon.e-ddl-icon {
    color: #2c5aa0 !important;
}

/* Nasconde underline Syncfusion */
.role-dropdown.e-ddl.e-input-group::before,
.role-dropdown.e-ddl.e-input-group::after,
.role-dropdown.e-control-wrapper::before,
.role-dropdown.e-control-wrapper::after {
    display: none !important;
    height: 0 !important;
}

/* Print Styles */
@media print {
    .navigation-tabs,
    .search-section,
    .user-edit-header button,
    .toggle-btn,
    .pending-changes button {
        display: none !important;
    }

    .category-header {
        page-break-after: avoid;
    }

    .table-permission-row {
        break-inside: avoid;
        border: 1px solid #dee2e6;
    }
}
