/* Global UI Components */
.mention-link {
    -webkit-touch-callout: none !important; /* Disabilita il menù a comparsa su iOS/Android */
    -webkit-user-select: none !important; /* Evita la selezione del testo */
    user-select: none !important;
}

/* Main Header Controls Layout */
#controls {
    display: flex;
    gap: 1rem;
    align-items: center;
    position: relative;
    transition: opacity 0.3s ease;
    order: 5; /* Between branding and install button */
    min-width: 0;
    justify-self: end;
}

/* Header Navigation Overhaul (Toggle States) */
.header-back-btn {
    margin-left: 12px;
    width: 34px !important;
    height: 34px !important;
    border-radius: 50% !important;
    background: #f1f5f9 !important;
    border: 1px solid #e2e8f0 !important;
    color: #475569 !important;
    display: none; /* Hidden by default */
}

.header-back-btn:hover {
    background: #e2e8f0 !important;
    color: #0f172a !important;
    transform: scale(1.1);
}

/* Smooth fade-out of controls when navigating into a section */
body.in-section #controls {
    opacity: 0;
    pointer-events: none;
}

body.in-section .header-back-btn {
    display: flex !important;
}

/* Global Button Reset & Base Icons */
button {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    font-family: inherit;
    color: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--primary-color, #3b82f6);
    outline-offset: 2px;
}

.text-muted {
    color: #94a3b8 !important;
}

#tree-selector-container {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 4px;
    background: var(--glass-bg);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 9999px;
    box-shadow: var(--shadow-sm);
}

.tree-crest-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: transparent;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.tree-crest-btn img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    transition: transform 0.3s ease;
    filter: grayscale(0.8) opacity(0.6);
}

.tree-crest-btn:hover img {
    filter: grayscale(0.3) opacity(0.9);
    transform: scale(1.1);
}

.tree-crest-btn.active {
    background: white;
    border-color: #d97706;
    box-shadow: 0 0 12px rgba(217, 119, 6, 0.2), inset 0 2px 4px rgba(0, 0, 0, 0.05);
}

.tree-crest-btn.active img {
    filter: none;
    opacity: 1;
    transform: scale(1.1);
}

/* Header Action Buttons */
#reset-view-btn,
#admin-upload-btn,
#name-edit-btn,
#delete-profile-btn,
#info-edit-btn,
#bio-edit-btn,
#stemma-edit-btn,
#add-photo-btn,
.mr-btn,
.history-btn,
.open-users-btn,
.back-btn,
.btn-icon-alt,
.action-icon-btn,
.admin-upload-btn,
.fm-attach-btn,
.fm-detach-btn,
.btn-add-relative {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    color: #1e293b;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

#stemma-edit-btn {
    width: auto;
    min-width: 36px;
    padding: 0 16px;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 500;
}

#stemma-edit-btn.btn-stemma-edit {
    display: inline-flex;
    width: auto;
    max-width: 100%;
    margin: 20px auto 0;
    align-self: center;
    justify-content: center;
}

#contrib-submit-btn.runtime-submit-btn-full {
    display: inline-flex;
    width: 100%;
    min-height: 44px;
    height: 44px;
    padding: 0 16px;
    gap: 8px;
    justify-content: center;
    white-space: normal;
    text-align: center;
}

#contrib-submit-btn.runtime-submit-btn-full .material-symbols-outlined,
#contrib-submit-btn.runtime-submit-btn-full .runtime-send-icon {
    flex-shrink: 0;
    margin-right: 0;
}

/* Forziamo il comportamento da fratelli su desktop (dissolviamo il wrapper) */
.main-controls-row {
    display: contents;
}


#reset-view-btn:hover,
#admin-upload-btn:hover,
#name-edit-btn:hover,
#delete-profile-btn:hover,
#info-edit-btn:hover,
#bio-edit-btn:hover,
#stemma-edit-btn:hover,
#add-photo-btn:hover,
.mr-btn:hover,
.history-btn:hover,
.open-users-btn:hover,
.back-btn:hover,
.btn-icon-alt:hover,
.action-icon-btn:hover,
.admin-upload-btn:hover,
.fm-attach-btn:hover,
.btn-add-relative:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: var(--primary-color, #3b82f6);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

#reset-view-btn:active,
#admin-upload-btn:active,
#name-edit-btn:active,
#delete-profile-btn:active,
#info-edit-btn:active,
#bio-edit-btn:active,
#stemma-edit-btn:active,
#add-photo-btn:active,
.mr-btn:active,
.history-btn:active,
.open-users-btn:active,
.back-btn:active,
.btn-icon-alt:active,
.action-icon-btn:active,
.admin-upload-btn:active,
.fm-attach-btn:active,
.btn-add-relative:active {
    transform: translateY(0);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
}

.mr-btn i, 
.history-btn i,
#reset-view-btn .material-symbols-outlined {
    font-size: 20px;
}

#action-buttons-container {
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-session-btn {
    width: auto;
    min-width: 36px;
    height: 36px;
    padding: 0 12px;
    gap: 6px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    color: #475569;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.header-session-btn .material-symbols-outlined {
    font-size: 18px;
}

.header-session-label {
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.header-session-btn:hover {
    background: #fff7ed;
    border-color: rgba(217, 119, 6, 0.25);
    color: #b45309;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(217, 119, 6, 0.12);
}

.header-session-btn:active {
    transform: translateY(0);
    box-shadow: inset 0 2px 4px rgba(15, 23, 42, 0.08);
}

/* Specific button overrides if needed */
#ai-proposals-btn {
    border-color: rgba(139, 92, 246, 0.2);
}

#ai-proposals-btn:hover {
    border-color: #8b5cf6;
    color: #8b5cf6;
}

#open-users-btn {
    border-color: rgba(168, 85, 247, 0.2);
}

#open-users-btn:hover {
    border-color: #a855f7;
    color: #a855f7;
}

@media (max-width: 480px) {
    .header-session-btn {
        width: 34px;
        min-width: 34px;
        height: 34px;
        padding: 0;
        border-radius: 10px;
    }

    .header-session-label {
        display: none;
    }
}

@keyframes pulse-green {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 5px;
    border: 2px solid #f1f5f9;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Base Inputs & Selects */
select,
input[type="text"],
input[type="password"] {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.875rem;
    color: var(--text-primary);
    background-color: var(--surface-color);
    transition: all 0.2s;
    outline: none;
}

select:focus,
input[type="text"]:focus,
input[type="password"]:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

#search-input {
    border-radius: 9999px;
    padding-left: 1.25rem;
    width: 280px;
    background: var(--glass-bg);
    border-color: var(--glass-border);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
}

#generation-selector {
    border-radius: 9999px;
    background: var(--glass-bg);
    border-color: var(--glass-border);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    cursor: pointer;
}

/* Material Symbols Helper */
.material-symbols-outlined {
    font-family: 'Material Symbols Outlined' !important;
    font-size: 20px;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    display: inline-block;
    line-height: 1;
    text-transform: none;
    letter-spacing: normal;
    word-wrap: normal;
    white-space: nowrap;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Modals (Global Structure) */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.4);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-content {
    background: white;
    padding: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    animation: modalSlide 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Popover Cards (Facebook-style) */
.popover-card {
    position: fixed;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15), 0 0 1px rgba(0,0,0,0.1);
    z-index: 10005;
    display: flex;
    flex-direction: column;
    animation: popoverFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid #e2e8f0;
    overflow: visible; /* To see the arrow */
}

.popover-arrow {
    position: absolute;
    top: -8px;
    right: 14px; /* Default for right-aligned header buttons */
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-bottom: 8px solid white;
    filter: drop-shadow(0 -1px 0 rgba(0,0,0,0.05));
    z-index: 1;
}

@keyframes popoverFadeIn {
    from { opacity: 0; transform: translateY(-10px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: white;
    z-index: 10;
}

.modal-body {
    padding: 1.5rem;
}

.close-modal {
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.close-modal:hover {
    color: var(--primary-color);
}

/* Avatar Components */
.p-avatar {
    box-sizing: border-box;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    border: 1px solid rgba(0, 0, 0, 0.05);
    background-color: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    background-size: cover;
    background-position: center;
}

.p-avatar img {
    display: block;
    position: absolute;
    max-width: none;
    left: 50%;
    top: 50%;
}

.p-avatar-crop {
    display: block;
    width: 100%;
    height: 100%;
    background-color: #f8fafc;
    background-repeat: no-repeat;
    position: relative;
    overflow: hidden;
}

.p-avatar-crop-media {
    display: block;
    position: absolute;
    max-width: none !important;
    max-height: none !important;
    transform: none !important;
}

.p-avatar.placeholder {
    color: rgba(255, 255, 255, 0.95);
    font-weight: 600;
}

.p-avatar-wrapper {
    box-sizing: border-box;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.avatar-badge {
    position: absolute;
    bottom: -1px;
    right: -1px;
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    z-index: 2;
    overflow: hidden;
    border-radius: 50%;
}

.avatar-badge img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Spinners */
.spinner {
    width: 48px;
    height: 48px;
    border: 5px solid var(--border-color);
    border-bottom-color: var(--primary-color);
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
}

.btn-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    margin-right: 10px;
    vertical-align: middle;
}

/* Helpers */
.hidden {
    display: none !important;
}

.rotating {
    animation: spin 1s linear infinite;
    display: inline-block;
}

/* ══════════════════════════════════════════
   Modern Action Buttons 
   ══════════════════════════════════════════ */

.btn-primary,
.btn-outline,
.btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 20px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    border: 1.5px solid transparent;
    line-height: 1.4;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(59, 130, 246, 0.2);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    transform: translateY(-1px);
}

.btn-outline {
    background: transparent;
    color: #64748b;
    border-color: #e2e8f0;
}

.btn-outline:hover {
    background: #f8fafc;
    color: #1e293b;
    border-color: #cbd5e1;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.08);
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
    background: #ef4444;
    color: white;
    border-color: #ef4444;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 0.8rem;
    border-radius: 6px;
}

/* Scroll to Top Button */
.scroll-top-btn {
    position: fixed;
    bottom: 150px; /* Stacked above AI Bot (80 bottom + 60 height + 10 gap) */
    right: 36px;   /* Centered vertically with the AI Bot */
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--primary-color, #3b82f6);
    color: white;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 5000;
}

@media (max-width: 768px) {
    .scroll-top-btn {
        bottom: 130px; /* Stacked above mobile AI Bot (70 bottom + 50 height + 10 gap) */
        width: 44px;
        height: 44px;
        right: 18px; /* Centered visually with mobile AI Bot */
    }
}

.scroll-top-btn:hover {
    background: var(--primary-hover, #2563eb);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.scroll-top-btn.show-btn {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

/* MR Scene */
.mr-scene {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: transparent;
}

/* Mobile Component Adjustment */
@media (max-width: 768px) {
    #tree-selector-container {
        order: 1;
        margin: 0;
        padding: 2px;
    }

    .tree-crest-btn {
        width: 32px;
        height: 32px;
    }

    .tree-crest-btn img {
        width: 22px;
        height: 22px;
    }
}
/* ══════════════════════════════════════════
   Toasts & Notifications
   ══════════════════════════════════════════ */

#toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 20000;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    min-width: 300px;
    max-width: 450px;
    background: white;
    border-radius: 14px;
    padding: 16px 20px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 14px;
    border: 1px solid #e2e8f0;
    transform: translateX(120%);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s;
    opacity: 0;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast-message {
    font-size: 0.9rem;
    font-weight: 500;
    color: #334155;
    flex: 1;
    line-height: 1.5;
}

.toast .material-symbols-outlined {
    font-size: 24px;
}

.toast-success .material-symbols-outlined { color: #10b981; }
.toast-error .material-symbols-outlined { color: #ef4444; }
.toast-warning .material-symbols-outlined { color: #f59e0b; }
.toast-info .material-symbols-outlined { color: #3b82f6; }

/* ══════════════════════════════════════════
   Confirm Dialog (Premium replacement for native confirm)
   ══════════════════════════════════════════ */

.confirm-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    z-index: 20001;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.confirm-dialog-card {
    background: white;
    width: 90%;
    max-width: 400px;
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    transform: scale(0.9);
    animation: scaleUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.confirm-dialog-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 16px;
    margin-bottom: 24px;
}

.confirm-dialog-icon {
    font-size: 48px;
    color: var(--primary-color);
    background: rgba(59, 130, 246, 0.1);
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.confirm-dialog-body p {
    font-size: 1.05rem;
    font-weight: 600;
    color: #1e293b;
    margin: 0;
    line-height: 1.6;
}

.confirm-dialog-actions {
    display: flex;
    gap: 12px;
}

.confirm-dialog-actions button {
    flex: 1;
    height: 48px;
}

@keyframes scaleUp {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* =========================================
   FIX MOBILE - OVERRIDE GLOBALI RESPONSIVI
   ========================================= */
@media (max-width: 768px) {
    
    /* 1. Fix Header "Centro Revisione AI" */
    .proposals-header {
        flex-direction: row !important;
        align-items: center !important;
        gap: 12px !important;
        height: auto !important;
        padding-bottom: 16px !important;
    }
    
    .proposals-header h2 {
        font-size: 1.5rem !important;
        margin: 0 !important;
    }
    
    #ai-scan-coherence-btn {
        margin-left: 0 !important;
        width: 100% !important;
        justify-content: center !important;
        box-sizing: border-box !important;
    }

    /* 2. Fix Top Bar & Main Header row consolidation */
    #controls:not(.hidden) {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 8px !important;
        padding: 4px 0 2px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        max-height: none !important;
        overflow: visible !important;
    }

    /* Controls stack: crests first, quick actions second, search row last */
    #tree-selector-container {
        order: 1 !important;
        display: flex !important;
        justify-content: center !important;
        width: fit-content !important;
        margin: 0 auto !important;
    }

    #action-buttons-container {
        order: 2 !important;
    }

    /* Main Row: Search + compact controls, always last */
    .main-controls-row {
        order: 3 !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        gap: 8px !important;
        width: min(100%, 380px) !important;
        justify-content: center !important;
        align-items: center !important;
    }

    #generation-selector {
        order: 2 !important;
        width: 42px !important;
        min-width: 42px !important;
        height: 36px !important;
        padding: 0 6px !important;
        border-radius: 8px !important;
        text-align: center !important;
        font-size: 0.9rem !important;
        font-weight: 700 !important;
        background-position: right 6px center !important;
        background-size: 14px !important;
    }

    #search-wrapper {
        order: 1 !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
        max-width: none !important;
    }

    #search-input {
        width: 100% !important;
        box-sizing: border-box !important;
        padding: 8px 12px !important;
        font-size: 0.92rem !important;
    }

    #reset-view-btn {
        order: 3 !important;
        flex-shrink: 0 !important;
    }

    #action-buttons-container {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        justify-content: flex-start !important;
        padding: 2px 12px 8px !important;
        width: 100% !important;
        max-width: 100% !important;
        gap: 10px !important;
        box-sizing: border-box !important;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        scroll-padding-inline: 12px;
    }
    
    #action-buttons-container > * {
        flex-shrink: 0 !important;
    }

    /* Center sparse icon rows while still allowing horizontal scroll when needed */
    #action-buttons-container::before,
    #action-buttons-container::after {
        content: '' !important;
        margin: auto !important;
        display: block !important;
        flex: 0 0 0 !important;
    }
    
    .header-session-btn {
        flex-shrink: 0 !important;
    }

    #action-buttons-container::-webkit-scrollbar {
        display: none !important;
    }

    /* 3. Fix Modale Gestione Utenti */
    #users-list-container .user-row {
        flex-wrap: wrap !important;
        gap: 8px !important;
        padding: 12px !important;
    }
    
    #users-list-container .user-role-badge {
        margin-left: 0 !important;
        font-size: 0.75rem !important;
    }

    /* Collapse controls row on mobile when in a section */
    body.in-section #controls:not(.hidden) {
        max-height: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        gap: 0 !important;
        overflow: hidden !important;
    }
}
/* PWA iOS Instructions */
.pwa-ios-modal {
    padding: 24px;
    text-align: center;
}

.pwa-ios-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.pwa-ios-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: #1e293b;
}

.pwa-ios-body {
    text-align: left;
    margin-bottom: 24px;
    color: #475569;
}

.pwa-ios-body ol {
    padding-left: 20px;
    margin: 16px 0;
}

.pwa-ios-body li {
    margin-bottom: 12px;
    line-height: 1.5;
}

.ios-share-icon {
    display: inline-block;
    width: 20px;
    height: 20px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="%233b82f6" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><polyline points="16 6 12 2 8 6"/><line x1="12" y1="2" x2="12" y2="15"/></svg>') no-repeat center;
    vertical-align: middle;
    margin: 0 2px;
}

.pwa-ios-close {
    width: 100%;
}

/* Gallery Category Filter Bar */
.gallery-filter-bar {
    display: flex;
    gap: 8px;
    padding: 0 20px 16px 20px;
    overflow-x: auto;
}

.gallery-filter-bar::-webkit-scrollbar {
    display: none;
}

.filter-chip {
    padding: 6px 16px;
    border-radius: 20px;
    background: #f1f5f9;
    color: #64748b;
    border: 1.5px solid #e2e8f0;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.filter-chip:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.filter-chip.active {
    background: #4f46e5;
    color: white;
    border-color: #4f46e5;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

/* Lightbox Badge Animation */
@keyframes badge-pop {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.desc-section span[style*="background"] {
    display: inline-block;
    animation: badge-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Admin Action Section improvements */
.admin-action-buttons-row {
    display: flex;
    gap: 8px;
}

.admin-delete-tag-btn, .admin-delete-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.admin-delete-tag-btn {
    background: #f1f5f9;
    color: #475569;
}

.admin-delete-tag-btn:hover {
    background: #e2e8f0;
}

.admin-delete-btn {
    background: #fef2f2;
    color: #dc2626;
}

.admin-delete-btn:hover {
    background: #fee2e2;
}
