/* Modale preferenze utente — CSS esplicito (non dipende da rebuild Tailwind). */

html.prefs-modal-open,
html.prefs-modal-open body {
    overflow: hidden;
    touch-action: none;
}

#user-prefs-modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}

#user-prefs-modal.hidden {
    display: none !important;
}

#user-prefs-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.user-prefs-sheet {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 42rem;
    min-height: min(78vh, 100%);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-bottom: none;
    border-radius: 1.25rem 1.25rem 0 0;
    box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.18);
    overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.user-prefs-handle {
    flex-shrink: 0;
    width: 2.75rem;
    height: 0.3rem;
    margin: 0.625rem auto 0;
    border-radius: 9999px;
    background: #d1d5db;
}

.user-prefs-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem 1rem;
    border-bottom: 1px solid #f3f4f6;
}

.user-prefs-title {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    color: #111827;
}

.user-prefs-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border: none;
    border-radius: 0.5rem;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
}

.user-prefs-close:hover {
    background: #f3f4f6;
    color: #374151;
}

.user-prefs-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 1rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
}

.user-prefs-section + .user-prefs-section {
    margin-top: 1.5rem;
}

.user-prefs-section-title {
    margin: 0 0 0.75rem;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #6b7280;
}

.user-prefs-section-head .user-prefs-section-title {
    margin-bottom: 0;
}

.user-prefs-section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.user-prefs-hint {
    margin: 0;
    font-size: 0.6875rem;
    line-height: 1.35;
    color: #9ca3af;
}

.user-prefs-theme-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.user-prefs-theme-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 3rem;
    padding: 0.75rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.75rem;
    background: #fff;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
}

.user-prefs-theme-btn.is-active {
    border-color: #3b82f6;
    background: #eff6ff;
    color: #1d4ed8;
}

.user-prefs-locale-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

.user-prefs-locale-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: 3.25rem;
    padding: 0.875rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.75rem;
    background: #fff;
    text-align: left;
    color: #1f2937;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.user-prefs-locale-btn:hover {
    border-color: #93c5fd;
    background: #f9fafb;
}

.user-prefs-locale-btn.is-active {
    border-color: #3b82f6;
    background: #eff6ff;
    color: #1e3a8a;
}

.user-prefs-locale-flag {
    font-size: 1.5rem;
    line-height: 1;
    flex-shrink: 0;
}

.user-prefs-locale-flag-img {
    width: 28px;
    height: 21px;
    object-fit: cover;
    border-radius: 3px;
    flex-shrink: 0;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.12);
}

.user-prefs-locale-code {
    flex-shrink: 0;
    min-width: 1.75rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #64748b;
    font-variant-numeric: tabular-nums;
}

.user-prefs-locale-btn.is-active .user-prefs-locale-code {
    color: #1d4ed8;
}

.user-prefs-locale-text {
    min-width: 0;
    flex: 1;
}

.user-prefs-locale-name {
    display: block;
    font-size: 0.9375rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-prefs-locale-meta {
    display: block;
    margin-top: 0.125rem;
    font-size: 0.6875rem;
    font-weight: 500;
    color: #2563eb;
}

.user-prefs-locale-check {
    flex-shrink: 0;
    color: #2563eb;
}

@media (min-width: 640px) {
    #user-prefs-modal {
        align-items: center;
        padding: 1rem;
    }

    .user-prefs-sheet {
        min-height: auto;
        max-height: 85vh;
        border-radius: 1rem;
        border-bottom: 1px solid #e5e7eb;
        box-shadow: 0 24px 48px rgba(15, 23, 42, 0.18);
    }

    .user-prefs-handle {
        display: none;
    }

    .user-prefs-locale-grid {
        grid-template-columns: 1fr 1fr;
    }

    .user-prefs-hint {
        max-width: 55%;
        text-align: right;
    }
}

/* Dark mode */
html.dark .user-prefs-sheet {
    background: #111827;
    border-color: #374151;
}

html.dark .user-prefs-header {
    border-bottom-color: #1f2937;
}

html.dark .user-prefs-title {
    color: #f9fafb;
}

html.dark .user-prefs-close {
    color: #94a3b8;
}

html.dark .user-prefs-close:hover {
    background: #1f2937;
    color: #f8fafc;
}

html.dark .user-prefs-section-title {
    color: #94a3b8;
}

html.dark .user-prefs-hint {
    color: #64748b;
}

html.dark .user-prefs-theme-btn,
html.dark .user-prefs-locale-btn {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

html.dark .user-prefs-theme-btn.is-active,
html.dark .user-prefs-locale-btn.is-active {
    background: rgba(30, 58, 138, 0.35);
    border-color: #3b82f6;
    color: #bfdbfe;
}

html.dark .user-prefs-locale-btn:hover {
    background: #1e293b;
    border-color: #60a5fa;
}

html.dark .user-prefs-locale-code {
    color: #94a3b8;
}

html.dark .user-prefs-locale-btn.is-active .user-prefs-locale-code {
    color: #93c5fd;
}

html.dark .user-prefs-handle {
    background: #475569;
}
