.crm-profile-page {
    position: relative;
}

.crm-profile-hero {
    min-height: 220px;
    border: 1px solid var(--crm-border);
    border-radius: var(--crm-radius-xl);
    background:
        radial-gradient(circle at 16% 12%, rgba(56, 189, 248, .20), transparent 22rem),
        radial-gradient(circle at 92% 0%, rgba(124, 58, 237, .18), transparent 24rem),
        linear-gradient(135deg, var(--crm-panel), color-mix(in srgb, var(--crm-panel-solid) 84%, var(--crm-primary) 16%));
    box-shadow: var(--crm-shadow-soft);
    padding: 26px;
    margin-bottom: 18px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 22px;
    overflow: hidden;
}

.crm-profile-hero-user {
    display: flex;
    align-items: center;
    gap: 22px;
    min-width: 0;
}

.crm-profile-avatar-wrap {
    width: 124px;
    height: 124px;
    border-radius: 34px;
    position: relative;
    flex: 0 0 124px;
    border: 1px solid rgba(255, 255, 255, .18);
    background: linear-gradient(135deg, rgba(56, 189, 248, .24), rgba(37, 99, 235, .18));
    box-shadow: 0 18px 44px rgba(37, 99, 235, .22);
    overflow: hidden;
}

.crm-profile-avatar-img,
.crm-profile-avatar-fallback {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.crm-profile-avatar-fallback {
    display: none;
    place-items: center;
    color: #fff;
    font-size: 34px;
    font-weight: 900;
    letter-spacing: -.06em;
    background: linear-gradient(135deg, var(--crm-primary), var(--crm-cyan));
}

.crm-profile-avatar-edit {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 14px;
    display: grid;
    place-items: center;
    color: #fff;
    background: rgba(15, 23, 42, .72);
    backdrop-filter: blur(12px);
    cursor: pointer;
    transition: transform .16s ease, background-color .16s ease;
}

.crm-profile-avatar-edit:hover {
    transform: translateY(-1px);
    background: rgba(37, 99, 235, .86);
}

.crm-profile-avatar-edit svg,
.crm-profile-org-icon svg,
.crm-profile-hero svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.crm-profile-hero h1 {
    margin: 0;
    font-size: clamp(30px, 4vw, 48px);
    line-height: 1;
    letter-spacing: -.07em;
    font-weight: 900;
}

.crm-profile-hero p {
    margin: 12px 0 0;
    color: var(--crm-soft);
    font-size: 16px;
}

.crm-profile-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.crm-profile-tag {
    min-height: 30px;
    display: inline-flex;
    align-items: center;
    padding: 5px 11px;
    border-radius: 999px;
    color: var(--crm-soft);
    background: rgba(148, 163, 184, .13);
    font-size: 13px;
    font-weight: 850;
}

.crm-profile-tag.success {
    color: #86efac;
    background: rgba(34, 197, 94, .16);
}

html[data-theme="light"] .crm-profile-tag.success {
    color: #166534;
}

.crm-profile-hero-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.crm-profile-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
    gap: 18px;
    align-items: start;
}

.crm-profile-card {
    overflow: hidden;
}

.crm-profile-form {
    display: grid;
    gap: 18px;
}

.crm-profile-form .crm-field input[readonly] {
    opacity: .86;
}

.crm-profile-form.is-editing .crm-field input:not([readonly]) {
    background: var(--crm-panel-solid);
}

.crm-profile-form-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 2px;
}

.crm-profile-save-state {
    margin-right: auto;
    color: var(--crm-soft);
    font-size: 13px;
    font-weight: 800;
}

.crm-profile-counter {
    min-width: 36px;
    height: 36px;
    border-radius: 14px;
    display: inline-grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--crm-primary), var(--crm-cyan));
    font-weight: 900;
}

.crm-profile-org-list {
    display: grid;
    gap: 12px;
}

.crm-profile-org {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-height: 76px;
    padding: 14px;
    border: 1px solid var(--crm-border);
    border-radius: 18px;
    background: var(--crm-panel-2);
}

.crm-profile-org.active {
    border-color: rgba(56, 189, 248, .34);
    background: linear-gradient(135deg, rgba(37, 99, 235, .16), rgba(6, 182, 212, .08));
}

.crm-profile-org-icon {
    width: 46px;
    height: 46px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    color: #fff;
    background: linear-gradient(135deg, var(--crm-primary), var(--crm-cyan));
}

.crm-profile-org strong {
    display: block;
    color: var(--crm-text);
    font-weight: 900;
    line-height: 1.25;
}

.crm-profile-org span {
    display: block;
    margin-top: 4px;
    color: var(--crm-soft);
    font-size: 13px;
    font-weight: 700;
}

.crm-profile-org em {
    font-style: normal;
    color: var(--crm-primary-2);
    font-size: 12px;
    font-weight: 900;
}

.crm-profile-notify-card {
    margin-top: 18px;
}

.crm-profile-notify-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.crm-profile-toggle {
    position: relative;
    min-height: 84px;
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
    align-items: center;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--crm-border);
    border-radius: 20px;
    background: var(--crm-panel-2);
    cursor: pointer;
    transition: border-color .16s ease, transform .16s ease, background-color .16s ease;
}

.crm-profile-toggle:hover {
    border-color: rgba(56, 189, 248, .34);
    transform: translateY(-1px);
}

.crm-profile-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.crm-profile-toggle-ui {
    width: 54px;
    height: 32px;
    border-radius: 999px;
    background: rgba(148, 163, 184, .30);
    position: relative;
    transition: background-color .18s ease;
}

.crm-profile-toggle-ui:after {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .24);
    transition: transform .18s ease;
}

.crm-profile-toggle input:checked + .crm-profile-toggle-ui {
    background: linear-gradient(135deg, var(--crm-primary), var(--crm-cyan));
}

.crm-profile-toggle input:checked + .crm-profile-toggle-ui:after {
    transform: translateX(22px);
}

.crm-profile-toggle-text strong {
    display: block;
    color: var(--crm-text);
    font-weight: 900;
    line-height: 1.25;
}

.crm-profile-toggle-text small {
    display: block;
    margin-top: 5px;
    color: var(--crm-soft);
    font-size: 13px;
    line-height: 1.35;
}

.crm-avatar-modal[hidden] {
    display: none;
}

.crm-avatar-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 18px;
}

.crm-avatar-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, .72);
    backdrop-filter: blur(10px);
}

.crm-avatar-dialog {
    position: relative;
    width: min(560px, 100%);
    border: 1px solid var(--crm-border);
    border-radius: 28px;
    background: var(--crm-panel-solid);
    box-shadow: 0 30px 80px rgba(0, 0, 0, .36);
    padding: 18px;
}

.crm-avatar-dialog-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.crm-avatar-dialog-header h2 {
    margin: 0;
    color: var(--crm-text);
    font-size: 22px;
    font-weight: 900;
}

.crm-avatar-dialog-header p {
    margin: 5px 0 0;
    color: var(--crm-soft);
    font-size: 13px;
    font-weight: 700;
}

.crm-avatar-close {
    width: 38px;
    height: 38px;
    border: 1px solid var(--crm-border);
    border-radius: 14px;
    color: var(--crm-text);
    background: var(--crm-panel-2);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.crm-avatar-crop-wrap {
    position: relative;
    width: min(420px, 100%);
    aspect-ratio: 1;
    margin: 0 auto;
    border-radius: 24px;
    overflow: hidden;
    background: rgba(15, 23, 42, .50);
    touch-action: none;
    cursor: grab;
}

.crm-avatar-crop-wrap:active {
    cursor: grabbing;
}

.crm-avatar-crop-wrap canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.crm-avatar-crop-frame {
    position: absolute;
    inset: 34px;
    border: 2px solid rgba(255, 255, 255, .92);
    border-radius: 22px;
    box-shadow: 0 0 0 999px rgba(2, 6, 23, .38);
    pointer-events: none;
}

.crm-avatar-range {
    display: grid;
    gap: 8px;
    margin-top: 16px;
    color: var(--crm-soft);
    font-size: 13px;
    font-weight: 800;
}

.crm-avatar-range input {
    width: 100%;
}

.crm-avatar-dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

.crm-avatar-state {
    min-height: 18px;
    margin-top: 10px;
    color: var(--crm-soft);
    font-size: 13px;
    font-weight: 800;
}

.crm-avatar-state.is-error {
    color: #fb7185;
}

.crm-avatar-state.is-success {
    color: #86efac;
}

@media (max-width: 1180px) {
    .crm-profile-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 820px) {
    .crm-profile-hero {
        align-items: flex-start;
        flex-direction: column;
    }

    .crm-profile-hero-user {
        align-items: flex-start;
        flex-direction: column;
    }

    .crm-profile-hero-actions {
        width: 100%;
        justify-content: stretch;
    }

    .crm-profile-hero-actions .crm-btn {
        flex: 1;
    }

    .crm-profile-notify-grid,
    .crm-form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .crm-profile-hero,
    .crm-profile-card,
    .crm-avatar-dialog {
        padding: 16px;
    }

    .crm-profile-avatar-wrap {
        width: 104px;
        height: 104px;
        border-radius: 28px;
        flex-basis: 104px;
    }

    .crm-profile-org {
        grid-template-columns: 42px minmax(0, 1fr);
    }

    .crm-profile-org em {
        grid-column: 2;
    }

    .crm-profile-form-footer,
    .crm-avatar-dialog-footer {
        align-items: stretch;
        flex-direction: column;
    }

    .crm-profile-save-state {
        margin-right: 0;
    }

    .crm-avatar-crop-frame {
        inset: 24px;
    }
}
