/* Module: 19-profile.css */
/* Scope: Standalone profile page layout and billing presentation. */

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: 'Manrope', sans-serif;
    background: var(--theme-bg-app);
    color: var(--theme-text-primary);
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font: inherit;
}

body {
    min-height: 100vh;
    padding: 32px 20px;
}

/* Hide reCAPTCHA badge on profile page only. */
.grecaptcha-badge {
    display: none !important;
}

.profile-page {
    max-width: 1200px;
    margin: 0 auto;
    min-height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
}

.profile-topbar {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    margin-bottom: 28px;
}

.profile-brand-banner {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.8rem;
    width: fit-content;
    padding: 0.55rem 0.65rem 0.45rem;
    border-radius: 14px 14px 0 0;
    background: linear-gradient(180deg, var(--theme-bg-surface-soft), var(--theme-bg-app));
}

.profile-brand-banner-logo {
    width: 3.15rem;
    height: 3.15rem;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255, 255, 255, 0.35);
    box-shadow: inset 0 0 0 1px rgba(128, 146, 170, 0.18), 0 4px 12px rgba(21, 38, 58, 0.12);
    flex-shrink: 0;
}

.profile-brand-banner-copy {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    min-width: 0;
}

.profile-brand-banner-name {
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--theme-text-default);
}

.profile-brand-banner-tagline {
    margin-top: 0.18rem;
    font-size: 0.58rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--theme-text-secondary);
}

.profile-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.profile-mobile-menu-toggle {
    display: none;
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 12px;
    border: 1px solid var(--theme-border-default);
    background: var(--theme-bg-surface-soft);
    color: var(--theme-text-primary);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.profile-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0.7rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--theme-border-default);
    background: var(--theme-bg-surface-soft);
    color: var(--theme-text-primary);
    cursor: pointer;
    font-weight: 700;
    transition: all 0.2s ease;
}

.profile-btn.primary {
    background: var(--theme-primary);
    color: var(--theme-text-inverse);
    border-color: var(--theme-primary);
}

.profile-btn.primary:hover {
    background: var(--theme-primary-active);
    border-color: var(--theme-primary-active);
}

.profile-btn.profile-btn-danger {
    background: var(--theme-surface-danger-muted);
    border-color: var(--theme-accent-danger-border);
    color: var(--theme-danger);
}

.profile-btn.profile-btn-danger:hover {
    background: var(--theme-danger-soft);
    border-color: var(--theme-danger);
    color: var(--theme-text-inverse);
}

.profile-btn.profile-btn-danger:focus-visible {
    outline: 2px solid var(--theme-danger);
    outline-offset: 2px;
}

#profile-manage-billing-btn {
    background: transparent;
    border-color: var(--theme-accent-primary-border-strong);
    color: var(--theme-primary-active);
}

#profile-manage-billing-btn:hover {
    background: var(--theme-primary-soft);
    border-color: var(--theme-primary-active);
    color: var(--theme-primary-active);
}

#profile-manage-billing-btn:focus-visible {
    outline: 2px solid var(--theme-primary-active);
    outline-offset: 2px;
}

#profile-cancel-subscription-btn {
    background: var(--theme-surface-danger-muted);
    border-color: var(--theme-accent-danger-border);
    color: var(--theme-danger);
}

#profile-cancel-subscription-btn:hover {
    background: var(--theme-danger-soft);
    border-color: var(--theme-danger);
    color: var(--theme-text-inverse);
}

#profile-cancel-subscription-btn:focus-visible {
    outline: 2px solid var(--theme-danger);
    outline-offset: 2px;
}

.profile-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#profile-back-link[aria-disabled="true"],
#profile-back-link[data-return-state="billing-required"] {
    cursor: not-allowed;
}

#profile-back-link[aria-disabled="true"]:hover,
#profile-back-link[data-return-state="billing-required"]:hover {
    cursor: not-allowed;
}

.profile-shell {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    gap: 22px;
    flex: 1;
    align-items: stretch;
}

.profile-sidebar,
.profile-card {
    background: var(--theme-bg-surface-soft);
    border: 1px solid var(--theme-border-default);
    border-radius: 18px;
    box-shadow: 0 10px 22px var(--theme-shadow-neutral-soft);
}

.profile-sidebar {
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
}

.profile-avatar-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 18px;
}

.profile-avatar {
    width: 92px;
    height: 92px;
    margin: 12px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--theme-primary-soft), var(--theme-highlight-soft));
    border: 1px solid var(--theme-border-default);
    font-size: 2rem;
    font-weight: 800;
    color: var(--theme-primary-active);
    cursor: pointer;
    overflow: hidden;
    padding: 0;
    position: relative;
}

.profile-avatar.avatar-loading::after,
.profile-avatar-editor-preview.avatar-loading::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 3px solid var(--theme-border-default);
    border-top-color: var(--theme-primary-active);
    animation: profile-avatar-spin 0.8s linear infinite;
    z-index: 3;
}

.profile-avatar.avatar-loading > .profile-avatar-image,
.profile-avatar.avatar-loading > .profile-avatar-initial,
.profile-avatar-editor-preview.avatar-loading > .profile-avatar-editor-image,
.profile-avatar-editor-preview.avatar-loading > .profile-avatar-editor-initial {
    opacity: 0;
}

.profile-avatar-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.profile-avatar-image[hidden],
.profile-avatar-editor-image[hidden] {
    display: none !important;
}

.profile-avatar-initial {
    line-height: 1;
}

.profile-avatar-initial i {
    font-size: 2rem;
}

.profile-identity {
    text-align: center;
    margin-bottom: 18px;
}

.profile-name {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 800;
}

.profile-email {
    margin: 6px 0 0;
    color: var(--theme-text-muted);
    font-size: 0.84rem;
}

.profile-side-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.profile-side-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 0.75rem 0.8rem;
    border-radius: 12px;
    color: var(--theme-text-default);
    font-weight: 700;
    border: 1px solid transparent;
    background: transparent;
}

.profile-side-link.active {
    background: var(--theme-primary-soft);
    color: var(--theme-primary-active);
    border-color: var(--theme-accent-primary-border);
}

.profile-side-link:hover {
    background: var(--theme-surface-primary-muted);
}

.profile-return-link {
    margin-top: 12px;
    color: var(--palette-ema-text-invert);
    background: var(--palette-ema-primary);
    border: 1px solid var(--theme-primary-24);
    box-shadow: 0 4px 12px var(--theme-primary-12);
    justify-content: center;
    text-align: center;
}

.profile-return-link:hover {
    background: linear-gradient(135deg, var(--theme-white-94), var(--theme-primary-soft));
    border-color: color-mix(in srgb, var(--theme-primary-light) 64%, transparent);
    color: var(--theme-primary-active);
}


.profile-logout-link {
    margin-top: 12px;
    border-color: var(--theme-border-default);
    color: var(--theme-text-default);
    display:none;
}

.profile-logout-link:hover {
    background: var(--theme-error-soft, var(--theme-danger-soft));
    border-color: var(--theme-error-soft, var(--theme-danger-soft));
    color: var(--theme-error-text, var(--theme-text-default));
}

.profile-main {
    display: flex;
    flex-direction: column;
    gap: 22px;
    min-height: 100%;
}

.profile-card {
    padding: 22px;
}

.profile-main > .profile-card {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.profile-card-highlighted {
    border-color: var(--theme-accent-primary-border);
    box-shadow: 0 12px 26px var(--theme-shadow-primary-soft);
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.profile-card.is-hidden {
    display: none;
}

.profile-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.profile-section-header h2,
.profile-section-header h3 {
    margin: 0;
    font-size: 1.1rem;
}


.profile-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0.34rem 0.7rem;
    border-radius: 999px;
    background: var(--theme-primary-soft);
    color: var(--theme-primary-active);
    font-size: 0.74rem;
    font-weight: 800;
}

.profile-overview {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.profile-overview-summary {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--theme-border-default);
}

.profile-overview-summary-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--theme-border-default);
    background: var(--theme-surface-card);
}

.profile-overview-summary-label {
    color: var(--theme-text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
}

.profile-overview-summary-item strong {
    font-size: 1rem;
    font-weight: 700;
    color: var(--theme-text-default);
}

.profile-metric {
    padding: 18px;
    border-radius: 14px;
    border: 1px solid var(--theme-border-default);
    background: var(--theme-surface-card);
}

.profile-metric-label {
    margin: 0 0 6px;
    color: var(--theme-text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.profile-metric-value {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 800;
}

.profile-metric-value-split {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.98rem;
    font-weight: 700;
}

.profile-metric-value-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.profile-metric-value-label {
    color: var(--theme-text-muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.profile-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.profile-avatar-editor {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-bottom: 1rem;
}

.profile-avatar-editor-preview {
    width: 56px;
    height: 56px;
    min-width: 56px;
    min-height: 56px;
    max-width: 56px;
    max-height: 56px;
    flex: 0 0 56px;
    aspect-ratio: 1 / 1;
    margin: 4px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--theme-primary-soft), var(--theme-highlight-soft));
    border: 1px solid var(--theme-border-default);
    color: var(--theme-primary-active);
    font-weight: 800;
    overflow: hidden;
    position: relative;
}

.profile-avatar-editor-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.profile-avatar-editor-initial {
    line-height: 1;
}

.profile-avatar-editor-initial i {
    font-size: 1.35rem;
}

@keyframes profile-avatar-spin {
    to {
        transform: rotate(360deg);
    }
}

.profile-avatar-edit-btn:disabled,
.profile-avatar-clear-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.profile-avatar-edit-btn.is-hidden,
.profile-avatar-clear-btn.is-hidden {
    display: none !important;
}

.profile-account-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
}

.profile-account-action-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.profile-account-actions.is-hidden {
    display: none;
}

.profile-account-message {
    margin: 0;
    min-height: 1.2rem;
    color: var(--theme-danger);
    font-size: 0.88rem;
    line-height: 1.2;
    flex: 1;
}

.profile-account-message.success {
    color: var(--theme-success);
}

.profile-save-btn {
    min-width: 142px;
    min-height: 36px;
    padding: 0.5rem 0.8rem;
    font-size: 0.92rem;
}

.profile-save-btn.is-loading {
    position: relative;
    color: transparent;
}

.profile-save-btn.is-loading i,
.profile-save-btn.is-loading span {
    opacity: 0;
}

.profile-save-btn.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    margin-left: -7px;
    border-radius: 50%;
    border: 2px solid var(--theme-white-50);
    border-top-color: var(--theme-text-inverse);
    animation: profile-avatar-spin 0.75s linear infinite;
}

.profile-save-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.profile-password-section {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--theme-border-default);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.profile-password-section.is-hidden {
    display: none;
}

.profile-password-section h4 {
    margin: 0;
    font-size: 1rem;
}

.profile-password-help {
    margin: 0;
    color: var(--theme-text-muted);
    font-size: 0.9rem;
}

.profile-security-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.profile-security-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    align-items: start;
}

.profile-security-email-field {
    margin-bottom: 0;
}

.profile-security-email-field input[readonly] {
    background: var(--theme-surface-muted);
    color: var(--theme-text-primary);
}

.profile-security-help {
    margin: 0;
    color: var(--theme-text-muted);
    font-size: 0.88rem;
}

.profile-security-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid var(--theme-border-default);
    background: var(--theme-surface-muted);
}

.profile-security-actions.is-disabled {
    opacity: 0.58;
}

.profile-security-actions.is-disabled .profile-btn {
    pointer-events: none;
}

.profile-security-danger-actions {
    border-color: var(--theme-accent-danger-border);
    background: var(--theme-surface-danger-muted);
}

.profile-security-status {
    margin: 0;
    min-height: 1.2rem;
    font-size: 0.88rem;
    line-height: 1.4;
    color: var(--theme-text-muted);
}

.profile-security-status.success {
    color: var(--theme-success);
}

.profile-security-status.error {
    color: var(--theme-danger);
}

.profile-security-action-copy h4 {
    margin: 0;
    font-size: 0.98rem;
}

.profile-security-action-copy .profile-password-help {
    margin-top: 6px;
}

@media (max-width: 780px) {
    .profile-security-grid {
        grid-template-columns: 1fr;
    }
}

#profile-change-password.is-hidden {
    display: none;
}

.profile-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.profile-field.full {
    grid-column: 1 / -1;
}

.profile-field label {
    font-size: 0.78rem;
    color: var(--theme-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
}

.profile-field input,
.profile-field select {
    width: 100%;
    min-height: 46px;
    border-radius: 12px;
    border: 1px solid var(--theme-border-default);
    background: var(--theme-bg-surface);
    padding: 0.72rem 0.8rem;
    color: var(--theme-text-primary);
    font: inherit;
}

.billing-stack {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.billing-card-section {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.billing-card-section-header h4 {
    margin: 0;
    font-size: 1rem;
}

.billing-card-section-header p,
.plan-description {
    margin: 0;
    color: var(--theme-text-muted);
    font-size: 0.9rem;
}

.billing-plan-options {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    align-items: stretch;
}

.billing-plan-card {
    border: 1px solid var(--theme-border-default);
    border-radius: 16px;
    padding: 18px;
    background: var(--theme-surface-card);
    cursor: default;
    user-select: none;
    height: 100%;
    display: flex;
    flex-direction: column;
    transition: none;
}

.billing-plan-card.is-current,
.billing-plan-card.is-selected {
    border-color: var(--theme-border-default);
    background: var(--theme-surface-card);
    box-shadow: none;
    transform: none;
}

.billing-plan-card:focus-visible {
    outline: none;
}

.billing-plan-options .billing-plan-card {
    border-color: var(--theme-border-default);
    box-shadow: none;
    transform: none;
}

.plan-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.plan-name {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 800;
}

.plan-price {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin: 14px 0 10px;
}

.plan-price strong {
    font-size: 1.5rem;
    line-height: 1;
}

.plan-list {
    list-style: none;
    padding: 0;
    margin: 14px 0 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    color: var(--theme-text-default);
}

.plan-list li {
    display: flex;
    align-items: center;
    gap: 8px;
}

.plan-list li i {
    color: var(--theme-success);
}

.plan-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: auto;
    padding-top: 14px;
}

.plan-actions .profile-btn {
    width: 100%;
}

#profile-pro-upgrade-btn.is-loading {
    position: relative;
    color: transparent;
}

#profile-pro-upgrade-btn.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    margin-left: -7px;
    border-radius: 50%;
    border: 2px solid var(--theme-white-50);
    border-top-color: var(--theme-text-inverse);
    animation: profile-avatar-spin 0.75s linear infinite;
}

#profile-cancel-subscription-btn.is-loading {
    position: relative;
    color: transparent;
}

#profile-cancel-subscription-btn.is-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    margin-left: -7px;
    border-radius: 50%;
    border: 2px solid var(--theme-accent-danger-border);
    border-top-color: var(--theme-danger);
    animation: profile-avatar-spin 0.75s linear infinite;
}

.billing-plan-card-enterprise .plan-header {
    align-items: center;
}

.payment-card {
    border: 1px solid var(--theme-border-default);
    border-radius: 16px;
    padding: 18px;
    background: var(--theme-surface-primary-muted);
}

.payment-card h4 {
    margin: 0 0 12px;
}

.payment-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--theme-border-default);
    color: var(--theme-text-default);
}

.payment-row:last-child {
    border-bottom: 0;
}

.muted {
    color: var(--theme-text-muted);
}

@media (max-width: 900px) {
    .profile-mobile-menu-toggle {
        display: inline-flex;
    }

    .profile-topbar {
        justify-content: flex-start;
        position: sticky;
        top: 0;
        z-index: 15;
        background: var(--theme-bg-app);
        padding: 8px 0;
    }

    #profile-brand-link {
        margin-left: auto;
    }

    #profile-back-link {
        width: 100%;
        min-width: 0;
        padding: 0.75rem 0.8rem;
    }

    #profile-back-link span {
        display: inline;
    }

    .profile-shell {
        grid-template-columns: 1fr;
    }

    .profile-sidebar {
        position: fixed;
        top: 92px;
        left: 20px;
        right: 20px;
        z-index: 20;
        max-height: 0;
        overflow: hidden;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-10px);
        pointer-events: none;
        transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s ease, max-height 0.2s ease;
    }

    .profile-sidebar.is-open {
        max-height: 560px;
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        pointer-events: auto;
    }

    .profile-overview,
    .profile-overview-billing-grid,
    .profile-form {
        grid-template-columns: 1fr;
    }

    .billing-plan-options {
        grid-template-columns: 1fr;
    }
}
