/**
 * Preferences form (legacy module CSS + settings-scoped normalization).
 *
 * Obiettivo: eliminare la dipendenza stilistica da classi legacy quando
 * la pagina vive dentro User Settings shell, senza toccare logica.
 */

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper.hcgpt-settings-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 0;
    width: 100%;
    background: transparent;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper.hcgpt-settings-page .hcgpt-preferences-form {
    margin: 0;
    max-width: 100%;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper.hcgpt-settings-page .hcgpt-preferences-form-wrapper,
#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper.hcgpt-settings-page .hcgpt-preferences-header,
#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper.hcgpt-settings-page .hcgpt-preferences-grid {
    max-width: 100%;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-preferences-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    padding: 0;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-preference-card {
    padding: 0;
    border: 0;
    background: transparent;
    margin: 0;
    display: block;
    border-radius: 0;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-preference-card.hcgpt-field {
    background: var(--hcgpt-color-surface) !important;
    border: 0 !important;
    border-radius: 14px !important;
    padding: 22px 24px !important;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-preference-card.hcgpt-field:hover {
    border-color: transparent !important;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-preference-card h3,
#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-preference-card p {
    margin: 0;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-preference-card .hcgpt-pref-label {
    display: flex;
    align-items: center;
    gap: 8px;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-select,
#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-preference-input,
#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-textarea {
    background: var(--hcgpt-color-surface-2) !important;
    border: 1px solid var(--hcgpt-color-border-strong) !important;
    border-radius: 10px !important;
    color: var(--hcgpt-color-text) !important;
    font-family: var(--hcgpt-font-sans);
    font-size: var(--hcgpt-font-size-14, 14px);
    min-height: 44px;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-select:focus,
#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-preference-input:focus,
#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-textarea:focus {
    outline: 0;
    border-color: var(--hcgpt-brand-1, #6e3aff) !important;
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--hcgpt-brand-1, #6e3aff) 14%, transparent) !important;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-textarea,
#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper textarea.hcgpt-preference-input {
    min-height: 118px;
    resize: vertical;
    line-height: 1.45;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-preferences-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    text-align: right;
    padding: 8px 0 0;
    background: transparent;
    border-top: 0;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-save-preferences-btn {
    background: var(--hcgpt-brand-gradient) !important;
    border: 1px solid transparent !important;
    color: #fff !important;
    border-radius: 999px !important;
    box-shadow: 0 4px 14px -2px rgba(110, 58, 255, 0.32) !important;
    transition: filter 0.15s ease, transform 0.15s ease !important;
    text-transform: none !important;
    width: auto;
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-save-preferences-btn:hover {
    background: var(--hcgpt-brand-gradient) !important;
    transform: translateY(-1px);
}

#hcgpt-app-view-settings .hcgpt-preferences-form-wrapper .hcgpt-preferences-message {
    margin: 0;
    width: 100%;
    text-align: left;
}

.hcgpt-preferences-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

.hcgpt-preferences-form-wrapper {
    background: var(--hcgpt-app-bg);
    color: var(--hcgpt-color-text);
}

.hcgpt-preferences-form-wrapper :is(h1, h2, h3) {
    font-family: var(--hcgpt-font-heading);
}

/* App shell (/app -> Settings -> Personalization):
   keep this view aligned with Shared/Archive rhythm (centered, 2 columns, tighter top spacing). */
#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper {
    margin: 0 auto;
    max-width: min(800px, 100%);
    padding-top: clamp(18px, 2.2vw, 30px);
    padding-bottom: clamp(8px, 1.2vw, 14px);
    width: 100%;
}

#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preferences-header,
#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preferences-form {
    margin-left: auto;
    margin-right: auto;
    max-width: 100%;
}

#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preferences-header {
    margin-bottom: 18px;
    text-align: left;
}

#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preferences-grid {
    gap: 16px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 0;
}

#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preference-card {
    padding: 22px 24px;
    border-radius: 14px;
}

#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preferences-form.hcgpt-card {
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
}

#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preferences-actions {
    align-items: center;
    background: transparent;
    border-top: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 18px 0 0;
}

#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preferences-actions .hcgpt-preferences-message,
#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preferences-actions .preferences-status {
    margin: 0;
    max-width: 560px;
    width: 100%;
}

/* 2.20.20: brand v2 alignment.
 * Was a transparent outline button with `!important` everywhere
 * which vinceva su `.hcgpt-btn-primary` in ui-components.css. Now
 * matches the brand gradient pill (same as LOG IN / Save Client /
 * any other primary CTA in the app). Kept the `!important` flags
 * because the high-specificity descendant selector below them
 * already justified them — switching to non-!important could
 * unmask another lower-specificity override. */
#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-save-preferences-btn {
    background: var(--hcgpt-brand-gradient) !important;
    border: none !important;
    border-radius: 999px !important;
    color: #fff !important;
    font-weight: var(--hcgpt-font-weight-semibold);
    min-width: 220px;
    box-shadow: var(--hcgpt-brand-shadow) !important;
}

#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-save-preferences-btn:hover {
    background: var(--hcgpt-brand-gradient) !important;
    transform: translateY(-1px);
    box-shadow: var(--hcgpt-brand-shadow-lg) !important;
}

#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-select,
#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preference-input {
    background: var(--hcgpt-color-surface) !important;
    border: 1px solid var(--hcgpt-color-border) !important;
    color: var(--hcgpt-color-text) !important;
}

#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-select:focus,
#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preference-input:focus {
    border-color: var(--hcgpt-color-border-strong) !important;
    box-shadow: none !important;
    outline: none;
}

#hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-select option {
    background: var(--hcgpt-color-surface) !important;
    color: var(--hcgpt-color-text) !important;
}

#hcgpt-preferences-form select[multiple].hcgpt-preference-input {
    height: auto;
    padding: 0;
    line-height: 1.45;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--hcgpt-color-border-strong) var(--hcgpt-color-surface-2);
}

#hcgpt-preferences-form select[multiple].hcgpt-preference-input option {
    background: var(--hcgpt-color-surface) !important;
    color: var(--hcgpt-color-text) !important;
    line-height: 1.4;
    min-height: 1.9em;
    padding: 8px 12px;
    white-space: normal;
    word-break: break-word;
}

#hcgpt-preferences-form select[multiple].hcgpt-preference-input option:checked {
    background: var(--hcgpt-color-surface-2) !important;
    color: var(--hcgpt-color-text) !important;
    box-shadow: inset 3px 0 0 var(--hcgpt-color-border-strong);
    font-weight: 600;
}

#hcgpt-preferences-form select[multiple].hcgpt-preference-input::-webkit-scrollbar {
    width: 10px;
}

#hcgpt-preferences-form select[multiple].hcgpt-preference-input::-webkit-scrollbar-track {
    background: var(--hcgpt-color-surface-2);
    border-radius: 8px;
}

#hcgpt-preferences-form select[multiple].hcgpt-preference-input::-webkit-scrollbar-thumb {
    background: var(--hcgpt-color-border-strong);
    border-radius: 8px;
    border: 2px solid var(--hcgpt-color-surface-2);
}

/* Keep preferences canvas stable and neutral in dark/system-dark mode */
.hcgpt-preferences-form-wrapper.hcgpt-scope:is([data-hcgpt-theme="dark"], [data-hcgpt-resolved-theme="dark"]) {
    --hcgpt-color-bg: #000;
    --hcgpt-app-bg: #000;
    background: #000;
}

@media (prefers-color-scheme: dark) {
    .hcgpt-preferences-form-wrapper.hcgpt-scope[data-hcgpt-theme="system"] {
        --hcgpt-color-bg: #000;
        --hcgpt-app-bg: #000;
        background: #000;
    }
}

.hcgpt-preferences-header {
    text-align: center;
    margin-bottom: 24px;
    padding: 0;
    background: transparent;
    color: var(--hcgpt-color-text);
    border-radius: 0;
    box-shadow: none;
}

/* Phase 4V-2: inside the Settings shell the Preferences header carries both
   `.hcgpt-preferences-header` and the V4 `.hcgpt-settings-page__header`, and the
   title/subtitle already use the V4 `.hcgpt-settings-page__title/__subtitle`
   classes. The legacy `text-align: center` above made the title wrap centered
   while every other Settings tab is left-axis. Force the shared left axis so the
   header reads as one family. (Standalone Preferences keeps the centered legacy
   header.) */
#hcgpt-app-view-settings .hcgpt-preferences-header {
    text-align: left;
}

#hcgpt-app-view-settings .hcgpt-preferences-form {
    display: grid;
    gap: 18px;
    margin: 0;
    width: 100%;
}

#hcgpt-app-view-settings .hcgpt-preferences-card {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

#hcgpt-app-view-settings .hcgpt-preferences-card__header {
    align-items: center;
    min-height: 96px;
}

#hcgpt-app-view-settings .hcgpt-preferences-card__body {
    background: var(--hcgpt-settings-surface-1);
}

#hcgpt-app-view-settings .hcgpt-preferences-card .hcgpt-settings-field-grid {
    gap: 18px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

#hcgpt-app-view-settings .hcgpt-preferences-card .hcgpt-settings-field-card {
    display: flex;
    flex-direction: column;
    min-height: 164px;
    background: var(--hcgpt-settings-surface-2);
}

#hcgpt-app-view-settings .hcgpt-preferences-card .hcgpt-settings-field-card__header {
    flex: 0 0 auto;
}

#hcgpt-app-view-settings .hcgpt-preferences-card .hcgpt-settings-field-card__control {
    align-content: start;
    flex: 1 1 auto;
}

#hcgpt-app-view-settings .hcgpt-preferences-card .hcgpt-settings-field-card__title,
#hcgpt-app-view-settings .hcgpt-preferences-card .hcgpt-settings-field-card__hint,
#hcgpt-app-view-settings .hcgpt-preferences-card__footer-note {
    overflow-wrap: anywhere;
}

#hcgpt-app-view-settings .hcgpt-preferences-card .hcgpt-preference-card--wide {
    grid-column: 1 / -1;
    min-height: 220px;
}

#hcgpt-app-view-settings .hcgpt-preferences-card :is(.hcgpt-preference-input, .hcgpt-settings-select, .hcgpt-settings-textarea) {
    background: var(--hcgpt-settings-surface-1) !important;
}

#hcgpt-app-view-settings .hcgpt-preferences-card :is(.hcgpt-preference-input, .hcgpt-settings-select, .hcgpt-settings-textarea):hover,
#hcgpt-app-view-settings .hcgpt-preferences-card :is(.hcgpt-preference-input, .hcgpt-settings-select, .hcgpt-settings-textarea):focus {
    background: var(--hcgpt-settings-surface-1) !important;
}

#hcgpt-app-view-settings .hcgpt-preferences-card__footer {
    min-height: 54px;
    background: var(--hcgpt-settings-surface-3);
}

#hcgpt-app-view-settings .hcgpt-preferences-card__footer-note {
    margin: 0;
    color: var(--hcgpt-color-text-muted);
    font-family: var(--hcgpt-font-sans, "Open Sans", system-ui, sans-serif);
    font-size: 13px;
    line-height: 1.45;
}

#hcgpt-app-view-settings .hcgpt-preferences-card__footer .hcgpt-preferences-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 0;
    margin: 0;
    background: transparent;
    border: 0;
    text-align: right;
}

#hcgpt-app-view-settings .hcgpt-preferences-card__footer .preferences-status {
    margin: 0;
    max-width: 360px;
    text-align: left;
}

.hcgpt-preferences-header h2 {
    margin: 0 0 8px 0;
    font-size: clamp(1.8rem, 2.5vw, 2.2rem);
    font-weight: 600;
    color: var(--hcgpt-color-text);
}

.hcgpt-preferences-header p {
    margin: 0;
    font-size: 1.1em;
    opacity: 1;
    color: var(--hcgpt-color-text-muted);
}

.hcgpt-preferences-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
    padding: 30px;
}

.hcgpt-preference-card {
    background: var(--hcgpt-color-surface);
    border-radius: var(--hcgpt-radius-md);
    padding: 25px;
    border: 1px solid var(--hcgpt-color-border);
    transition: border-color var(--hcgpt-transition-fast);
}

.hcgpt-preference-card.hcgpt-field {
    margin-bottom: 0;
}

.hcgpt-preference-card--wide {
    grid-column: 1 / -1;
}

.hcgpt-preference-card textarea.hcgpt-preference-input {
    min-height: 118px;
    resize: vertical;
    line-height: 1.45;
}

.hcgpt-preference-card:hover {
    border-color: var(--hcgpt-color-border-strong);
}

.hcgpt-preference-card h3,
.hcgpt-preference-card p {
    margin: 0;
}

.hcgpt-preference-card h3 {
    font-weight: 600;
}

.hcgpt-preference-card .hcgpt-pref-label {
    align-items: center;
    display: flex;
    gap: 8px;
}

.hcgpt-preference-card .hcgpt-pref-label-icon {
    color: var(--hcgpt-color-text-muted);
    flex: 0 0 18px;
    font-size: 18px;
    height: 18px;
    line-height: 18px;
    width: 18px;
}

.hcgpt-preference-card p {
    line-height: 1.4;
}

/* Phase 3D-2: the surface/border "footer bar" was removed so the migrated
   `.hcgpt-form-actions` (V4) renders as a transparent right-aligned action row.
   The `.hcgpt-preferences-actions` class is retained only as a JS hook
   (ump-preferences.js status fallback). */
.hcgpt-preferences-actions {
    text-align: center;
}

.hcgpt-save-preferences-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.hcgpt-preferences-message,
.preferences-status {
    margin-top: var(--hcgpt-space-3);
    text-align: center;
}

.hcgpt-preferences-message {
    animation: slideIn 0.3s ease;
}

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

/* Responsive Design */
@media (max-width: 767.98px) {
    .hcgpt-preferences-container {
        padding: 15px;
    }
    
    .hcgpt-preferences-header {
        padding: 0;
    }
    
    .hcgpt-preferences-header h2 {
        font-size: 1.8em;
    }
    
    .hcgpt-preferences-grid {
        grid-template-columns: 1fr;
        gap: 20px;
        padding: 20px;
    }
    
    .hcgpt-preference-card {
        padding: 20px;
    }
    
    .hcgpt-preferences-actions {
        padding: 20px;
    }
    
    .hcgpt-save-preferences-btn {
        width: 100%;
    }

    #hcgpt-app-view-settings .hcgpt-preferences-card__header,
    #hcgpt-app-view-settings .hcgpt-preferences-card__body,
    #hcgpt-app-view-settings .hcgpt-preferences-card__footer {
        padding-inline: 18px;
    }

    #hcgpt-app-view-settings .hcgpt-preferences-card .hcgpt-settings-field-grid {
        grid-template-columns: 1fr;
    }

    #hcgpt-app-view-settings .hcgpt-preferences-card__footer {
        align-items: stretch;
        flex-direction: column;
    }

    #hcgpt-app-view-settings .hcgpt-preferences-card__footer .hcgpt-preferences-actions {
        align-items: stretch;
        flex-direction: column;
        padding: 0;
        text-align: left;
    }

    #hcgpt-app-view-settings .hcgpt-preferences-card__footer .hcgpt-save-preferences-btn {
        width: 100%;
    }
}

@media (max-width: 900px) {
    #hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper {
        max-width: 100%;
    }

    #hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preferences-grid {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    #hcgpt-app-view-settings .hcgpt-us-panel-body .hcgpt-preferences-form-wrapper .hcgpt-preferences-header h2 {
        font-size: 2rem;
    }
}

@media (max-width: 480px) {
    .hcgpt-preferences-header h2 {
        font-size: 1.5em;
    }
    
    .hcgpt-preferences-header p {
        font-size: 1em;
    }
    
}

/* Loading States */
.hcgpt-preferences-form.submitting {
    opacity: 0.7;
    pointer-events: none;
}

.hcgpt-preferences-form.submitting .hcgpt-save-preferences-btn {
    cursor: not-allowed;
    opacity: 0.7;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .hcgpt-preference-card {
        border: 2px solid #000;
    }
    
    .hcgpt-select {
        border: 2px solid #000;
    }
    
    .hcgpt-save-preferences-btn {
        border: 2px solid #000;
    }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
    .hcgpt-preference-card,
    .hcgpt-save-preferences-btn,
    .hcgpt-preferences-message {
        transition: none;
    }
    
    .hcgpt-preference-card:hover {
        transform: none;
    }
    
    .hcgpt-save-preferences-btn:hover {
        transform: none;
    }
} 
