/**
 * User Profile - Account Settings
 *
 * Account layout, sidebar, settings forms, toggles, avatar upload, form elements
 * Mobile-first with collapsible sidebar accordion and touch-friendly controls
 *
 * @package PC Kompas User API
 */

/* Account Layout (2-column with sidebar on desktop) */
.account-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(1.5rem, 4vw, 2rem);
    align-items: start;
}

/* Desktop: 2-column layout */
@media (min-width: 769px) {
    .account-layout {
        grid-template-columns: 260px 1fr;
    }
}

/* Account Sidebar */
.account-sidebar {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    position: relative;
}

/* Desktop: sticky sidebar */
@media (min-width: 769px) {
    .account-sidebar {
        position: sticky;
        top: 140px;
    }
}

.account-sidebar__nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.account-sidebar__item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: clamp(0.875rem, 1.5vw + 0.25rem, 0.9375rem);
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.account-sidebar__item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.account-sidebar__item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.account-sidebar__item--active {
    background: var(--accent-light);
    color: var(--accent);
}

.account-sidebar__item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Mobile Sidebar Accordion */
.account-sidebar__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-primary);
    font-size: clamp(0.9375rem, 1.5vw + 0.25rem, 1rem);
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
}

.account-sidebar__toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.account-sidebar__toggle-icon {
    width: 20px;
    height: 20px;
    transition: transform 0.2s ease;
    color: var(--text-secondary);
}

.account-sidebar--open .account-sidebar__toggle-icon {
    transform: rotate(180deg);
}

/* Mobile: hide toggle on desktop, show nav always */
@media (min-width: 769px) {
    .account-sidebar__toggle {
        display: none;
    }

    .account-sidebar__nav {
        display: flex !important;
    }
}

/* Mobile: collapsible nav */
@media (max-width: 768px) {
    .account-sidebar__nav {
        display: none;
        padding-top: 8px;
        border-top: 1px solid var(--border);
        margin-top: 8px;
    }

    .account-sidebar__nav--open {
        display: flex !important;
    }
}

/* Account Content Area */
.account-content {
    min-width: 0;
}

/* Settings Groups */
.settings-group {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: clamp(1rem, 3vw, 1.5rem);
    margin-bottom: clamp(1rem, 3vw, 1.5rem);
}

.settings-group__title {
    font-size: clamp(1.125rem, 3vw + 0.75rem, 1.5rem);
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 clamp(6px, 1vw, 8px) 0;
}

.settings-group__description {
    font-size: clamp(0.8125rem, 1.25vw + 0.25rem, 0.875rem);
    color: var(--text-secondary);
    margin: 0 0 clamp(1rem, 2.5vw, 1.25rem) 0;
    line-height: 1.5;
}

.settings-group--danger {
    border-color: var(--error);
    background: var(--error-bg);
}

.settings-group--danger .settings-group__title {
    color: var(--error);
}

.settings-group__hint {
    font-size: clamp(0.8125rem, 1.25vw + 0.25rem, 0.875rem);
    color: var(--text-muted);
    margin-top: 8px;
}

/* Toggle Switches - Touch friendly with adequate spacing */
.notification-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: clamp(1rem, 3vw, 2rem);
    padding: clamp(1rem, 3vw, 1.5rem) 0;
    border-bottom: 1px solid var(--border);
    min-height: 64px;
}

.notification-toggle:last-child {
    border-bottom: none;
}

.notification-toggle__info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 0;
}

.notification-toggle__label {
    font-size: clamp(0.875rem, 1.5vw + 0.25rem, 0.9375rem);
    font-weight: 600;
    color: var(--text-primary);
}

.notification-toggle__description {
    font-size: clamp(0.75rem, 1vw + 0.25rem, 0.8125rem);
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Toggle Switch Component - WCAG 2.2 touch target (48x48 hit area) */
.toggle-switch {
    position: relative;
    width: 52px;
    height: 28px;
    flex-shrink: 0;
    min-width: 52px;
    /* Expand touch target to 48x48 via padding */
    padding: 10px 0;
    margin: -10px 0;
    box-sizing: content-box;
}

.toggle-switch input {
    opacity: 0;
    position: absolute;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 1;
}

.toggle-switch__slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 28px;
    transition: all 0.2s ease;
}

.toggle-switch__slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 2px;
    top: 2px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all 0.2s ease;
}

.toggle-switch input:checked + .toggle-switch__slider {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-switch__slider:before {
    transform: translateX(24px);
    background: var(--bg-primary);
}

/* Focus state for accessibility */
.toggle-switch input:focus + .toggle-switch__slider {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Active state */
.toggle-switch input:active + .toggle-switch__slider {
    box-shadow: 0 0 0 3px var(--accent-light);
}

/* Avatar Upload */
.avatar-upload {
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 2vw, 1.25rem);
}

.avatar-upload__preview {
    width: clamp(96px, 15vw, 128px);
    height: clamp(96px, 15vw, 128px);
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid var(--border);
}

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

.avatar-upload__actions {
    display: flex;
    align-items: center;
    gap: clamp(0.75rem, 1.5vw, 1rem);
    flex-wrap: wrap;
}

.avatar-upload__actions .btn {
    min-height: 48px;
}

.avatar-upload__input {
    display: none;
}

/* Form Elements */
.form-group {
    margin-bottom: clamp(1rem, 2.5vw, 1.25rem);
}

.form-label {
    display: block;
    font-size: clamp(0.875rem, 1.5vw + 0.25rem, 0.9375rem);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: clamp(0.75rem, 2vw, 1rem) clamp(1rem, 2.5vw, 1.25rem);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 16px; /* Prevent iOS zoom */
    font-family: inherit;
    transition: all 0.2s ease;
    min-height: 48px;
    -webkit-appearance: none;
    appearance: none;
}

.form-input {
    line-height: 1.5;
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-input:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-secondary);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-input:disabled,
.form-textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.form-textarea {
    resize: vertical;
    min-height: 120px;
    padding-top: 14px;
    padding-bottom: 14px;
}

.form-error {
    display: block;
    font-size: clamp(0.8125rem, 1.25vw + 0.25rem, 0.875rem);
    color: var(--error);
    margin-top: 6px;
}

.form-input--error {
    border-color: var(--error);
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    cursor: pointer;
    min-height: 48px;
    padding: 8px 0;
    -webkit-user-select: none;
    user-select: none;
}

.form-checkbox input[type="checkbox"] {
    position: relative;
    appearance: none;
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    border: 2px solid var(--border);
    border-radius: 6px;
    background: var(--bg-tertiary);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.form-checkbox input[type="checkbox"]:hover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.form-checkbox input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.form-checkbox input[type="checkbox"]:checked::after {
    content: "";
    display: block;
    width: 6px;
    height: 10px;
    border: solid var(--bg-primary);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-bottom: 2px;
}

.form-checkbox input[type="checkbox"]:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.form-checkbox__label {
    font-size: clamp(0.875rem, 1.5vw + 0.25rem, 0.9375rem);
    color: var(--text-primary);
    cursor: pointer;
    flex: 1;
}

/* Alert Messages */
.alert {
    padding: clamp(0.75rem, 2vw, 1rem) clamp(1rem, 2.5vw, 1.25rem);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: clamp(0.875rem, 1.5vw + 0.25rem, 0.9375rem);
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert--error {
    background: var(--error-bg);
    border: 1px solid var(--error);
    color: var(--error);
}

.alert--success {
    background: var(--success-bg);
    border: 1px solid var(--success);
    color: var(--success);
}

.alert--info {
    background: var(--accent-light);
    border: 1px solid var(--accent);
    color: var(--text-primary);
}

/* Settings Form */
.settings-form {
    display: flex;
    flex-direction: column;
    gap: clamp(1rem, 2.5vw, 1.25rem);
}

.settings-form .btn {
    min-height: 48px;
}

/* Theme Selector */
.theme-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(0.75rem, 2vw, 1rem);
    margin-bottom: 16px;
}

/* Mobile: 3 columns still work but are smaller */
@media (max-width: 400px) {
    .theme-selector {
        grid-template-columns: repeat(2, 1fr);
    }
}

.theme-selector__option {
    position: relative;
    cursor: pointer;
}

.theme-selector__option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-selector__card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(0.75rem, 1.5vw, 1rem);
    padding: clamp(1rem, 3vw, 1.25rem);
    background: var(--bg-tertiary);
    border: 2px solid var(--border);
    border-radius: 10px;
    transition: all 0.2s ease;
    min-height: clamp(100px, 15vw, 120px);
    cursor: pointer;
    touch-action: manipulation;
}

.theme-selector__option:hover .theme-selector__card {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.theme-selector__option input[type="radio"]:checked + .theme-selector__card {
    border-color: var(--accent);
    border-width: 3px;
    background: var(--accent-light);
    box-shadow: 0 0 0 4px var(--accent-light);
}

.theme-selector__option input[type="radio"]:focus + .theme-selector__card {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.theme-selector__label {
    font-size: clamp(0.8125rem, 1.25vw + 0.25rem, 0.9375rem);
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

.theme-selector__card svg {
    width: clamp(24px, 4vw, 32px);
    height: clamp(24px, 4vw, 32px);
    color: var(--text-secondary);
}

.theme-selector__option input[type="radio"]:checked + .theme-selector__card svg {
    color: var(--accent);
}

/* Form hints */
.form-hint {
    font-size: clamp(0.6875rem, 1vw + 0.125rem, 0.75rem);
    color: var(--text-muted);
    margin-top: 4px;
}

/* Notification Toggle Loading State */
.toggle-switch__loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-top-color: transparent;
    border-radius: 50%;
    animation: toggle-spin 0.6s linear infinite;
}

@keyframes toggle-spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Disabled notification toggles */
.notification-toggle--disabled {
    opacity: 0.6;
    pointer-events: none;
}

.notification-toggles--disabled {
    opacity: 0.8;
}

/* Settings group note */
.settings-group__note {
    font-size: clamp(0.75rem, 1vw + 0.25rem, 0.8125rem);
    color: var(--text-muted);
    font-style: italic;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* Notification Loading State */
.notification-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: clamp(2rem, 5vw, 2.5rem) clamp(1rem, 3vw, 1.25rem);
    color: var(--text-secondary);
}

.notification-loading__spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: toggle-spin 0.8s linear infinite;
}

/* Mobile: full-width buttons in settings forms */
@media (max-width: 480px) {
    .settings-form .btn {
        width: 100%;
        justify-content: center;
    }

    .avatar-upload__actions {
        flex-direction: column;
    }

    .avatar-upload__actions .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Delete Request Modal */
.modal--delete-request {
    width: 100%;
    max-width: 480px;
    background: var(--bg-modal);
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.delete-request-info {
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 3vw, 16px);
    margin-bottom: clamp(16px, 4vw, 24px);
}

.delete-request-info__item {
    display: flex;
    align-items: flex-start;
    gap: clamp(10px, 2vw, 12px);
    padding: clamp(12px, 3vw, 16px);
    background: var(--bg-tertiary);
    border-radius: 8px;
    font-size: clamp(0.875rem, 1.5vw + 0.25rem, 0.9375rem);
    color: var(--text-primary);
    line-height: 1.4;
}

.delete-request-info__icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    color: var(--accent);
    margin-top: 1px;
}

.delete-request-warning {
    font-size: clamp(0.8125rem, 1.25vw + 0.25rem, 0.875rem);
    color: var(--text-secondary);
    line-height: 1.5;
    padding: clamp(12px, 3vw, 16px);
    background: var(--error-bg);
    border: 1px solid var(--error);
    border-radius: 8px;
    margin: 0;
}

/* Modal transitions */
.modal-enter {
    transition: opacity 0.2s ease;
}

.modal-enter-start {
    opacity: 0;
}

.modal-enter-end {
    opacity: 1;
}

.modal-leave {
    transition: opacity 0.15s ease;
}

.modal-leave-start {
    opacity: 1;
}

.modal-leave-end {
    opacity: 0;
}
