/* Кнопка профиля (иконка + текущая роль)
   #page-wraper в nd54-theme.css имеет z-index: 10000 — иначе кнопка и модалка под ним, на телефоне «не нажимаются» */
.profile-button {
    position: fixed;
    top: 10px;
    right: 20px;
    z-index: 10060;
    pointer-events: auto;
    touch-action: manipulation;
}

.profile-icon {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    border-radius: 20px;
    transition: background-color 0.2s;
}

.profile-icon:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.current-role {
    font-size: 14px;
    color: #333;
    text-transform: capitalize;
}

/* В кнопке ЛК — только иконка Font Awesome, без герба/картинки слева */
.profile-button .profile-icon img,
.profile-button .profile-icon .nd54-profile-emblem,
.profile-button .profile-emblem {
    display: none !important;
    width: 0 !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
}

.profile-icon::before,
.profile-icon::after {
    display: none !important;
    content: none !important;
    background: none !important;
}

.profile-icon i {
    flex-shrink: 0;
}

/* Legacy-модалки без Bootstrap (.fade). Bootstrap 5 — в nd54-layout-unified.css */
.modal:not(.fade) {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    overflow: auto;
}

/* Окно выбора роли: выше #page-wraper. Без класса .modal у Bootstrap — меньше гонок overflow при 2+ открытиях. */
#roleModal.role-modal {
    display: none; /* inline style при открытии = block, перекрывает */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    min-height: 100%;
    min-height: 100dvh;
    min-height: -webkit-fill-available;
    /* Без max-height блок растягивался по контенту: при body { overflow: hidden } скролла не было */
    max-height: 100vh;
    max-height: 100dvh;
    max-height: -webkit-fill-available;
    z-index: 10080 !important;
    box-sizing: border-box;
    margin: 0;
    padding: 12px 0;
    background-color: rgba(0, 0, 0, 0.5);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    pointer-events: auto;
    touch-action: pan-y;
}

.modal-content {
    background-color: #fff;
    margin: 15% auto;
    padding: 25px 20px;
    border: 1px solid #888;
    width: 300px;
    max-width: 90%;
    border-radius: 12px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    text-align: center;
    position: relative;
}

.close {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover,
.close:focus {
    color: black;
    text-decoration: none;
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1.5rem;
    color: #222;
}

.role-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    background-color: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    color: #333;
    transition: all 0.2s;
}

.role-btn:hover {
    background-color: #e9e9e9;
    border-color: #ccc;
}

.role-btn:active {
    transform: scale(0.98);
}

/* ========= Современное модальное окно выбора роли ========= */
/* Bootstrap 5: .modal-content — flex column; дочерняя кнопка растягивается → «×» по центру. Фикс: block + шапка */
.role-modal .modal-content.role-modal-content,
.role-modal .role-modal-content {
    display: block !important;
    flex-direction: unset !important;
    position: relative;
    background: white;
    border-radius: 24px;
    padding: 30px 20px;
    max-width: 700px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    animation: modalFadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.role-modal__header {
    position: relative;
    z-index: 1;
    width: 100%;
    margin: 0 0 0.5rem 0;
    padding: 0 3rem;
    box-sizing: border-box;
    text-align: center;
    direction: ltr;
    isolation: isolate;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.role-modal__header .role-close,
.role-modal__header button.close {
    position: absolute !important;
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
    z-index: 3;
    transform: none !important;
    float: none !important;
    width: 2.75rem;
    height: 2.75rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 300;
    line-height: 1;
    color: #666;
    background: transparent;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    -webkit-appearance: none;
    appearance: none;
}

.role-modal__header .role-close:hover,
.role-modal__header .role-close:focus-visible {
    color: var(--primary, #2279bd);
    outline: none;
}

.role-modal__header .role-modal-title {
    margin: 0 0 1.25rem 0;
    padding: 0.1rem 0 0;
}

/* Без transform на .modal-content — иначе при повторном открытии/фокусе плывёт position:absolute у крестика */
@keyframes modalFadeIn {
    0% { opacity: 0; }
    100% { opacity: 1; }
}

.role-modal-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin-bottom: 30px;
    position: relative;
}
.role-modal-title:after {
    content: '';
    display: block;
    width: 60px;
    height: 4px;
    background: var(--accent);
    margin: 10px auto 0;
    border-radius: 2px;
}

.role-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    padding: 10px;
}

.role-groups {
    display: flex;
    flex-direction: column;
    gap: 22px;
    padding: 8px 10px 10px;
    margin-top: 8px;
}

.role-group__header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 2px solid rgba(34, 121, 189, 0.12);
}

.role-group--citizens .role-group__header { border-bottom-color: rgba(23, 162, 184, 0.35); }
.role-group--druzhina .role-group__header { border-bottom-color: rgba(40, 167, 69, 0.35); }
.role-group--management .role-group__header { border-bottom-color: rgba(34, 121, 189, 0.35); }

.role-group__icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    background: rgba(34, 121, 189, 0.1);
    color: var(--primary);
}

.role-group--citizens .role-group__icon { background: rgba(23, 162, 184, 0.12); color: #17a2b8; }
.role-group--druzhina .role-group__icon { background: rgba(40, 167, 69, 0.12); color: #28a745; }
.role-group--management .role-group__icon { background: rgba(255, 193, 7, 0.18); color: #c99700; }

.role-group__title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 2px;
    line-height: 1.25;
}

.role-group__hint {
    font-size: 0.8rem;
    color: #64748b;
    margin: 0;
    line-height: 1.35;
}

.role-group__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.role-modal-subtitle {
    text-align: center;
    font-size: 0.9rem;
    color: #64748b;
    margin: 8px 0 0;
    line-height: 1.4;
}

.role-path-picker {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    padding: 12px 10px 4px;
}

.role-path-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 168px;
    padding: 22px 16px;
    border: 2px solid transparent;
    border-radius: 16px;
    background: #f8fafc;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    text-align: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

.role-path-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary);
    box-shadow: 0 16px 24px -8px rgba(34, 121, 189, 0.2);
}

.role-path-card__icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    background: rgba(34, 121, 189, 0.1);
    color: var(--primary);
}

.role-path-card--citizen .role-path-card__icon {
    background: rgba(23, 162, 184, 0.12);
    color: #17a2b8;
}

.role-path-card--druzhina .role-path-card__icon {
    background: rgba(40, 167, 69, 0.12);
    color: #28a745;
}

.role-path-card--citizen:hover .role-path-card__icon {
    background: #17a2b8;
    color: #fff;
}

.role-path-card--druzhina:hover .role-path-card__icon {
    background: #28a745;
    color: #fff;
}

.role-path-card__title {
    font-size: 1.35rem;
    font-weight: 700;
    color: #1e293b;
    line-height: 1.2;
}

.role-path-card__desc {
    font-size: 0.85rem;
    color: #64748b;
    line-height: 1.35;
    max-width: 220px;
}

.role-step-panel {
    padding: 4px 10px 8px;
}

.role-step-panel__title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 14px;
    text-align: center;
}

.role-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    padding: 6px 12px;
    border: 1px solid rgba(34, 121, 189, 0.25);
    border-radius: 999px;
    background: #fff;
    color: var(--primary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.role-back-btn:hover {
    background: rgba(34, 121, 189, 0.08);
    border-color: var(--primary);
}

.role-subgroup {
    margin-bottom: 18px;
}

.role-subgroup:last-child {
    margin-bottom: 0;
}

.role-subgroup__title {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #64748b;
    margin: 0 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.35);
}

@media (max-width: 767.98px) {
    .role-modal .role-modal-content,
    .role-modal .modal-content {
        max-height: min(92dvh, 920px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

.role-card {
    background: #f8fafc;
    border-radius: 16px;
    padding: 25px 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
}
.role-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
    border-color: var(--primary);
}
.role-card .role-icon {
    font-size: 48px;
    color: var(--primary);
    margin-bottom: 15px;
    transition: transform 0.3s ease;
}
.role-card:hover .role-icon {
    transform: scale(1.1) rotate(5deg);
}
.role-card h3 {
    font-size: 1.5rem;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 8px;
}
.role-card .role-desc {
    font-size: 0.9rem;
    color: #64748b;
    line-height: 1.4;
}

/* Акцентные цвета для карточек */
.role-card[data-role="druzhinnik"] .role-icon { color: #28a745; }
.role-card[data-role="rukovoditel"] .role-icon { color: #ffc107; }
.role-card[data-role="zayavitel"] .role-icon { color: #17a2b8; }
.role-card[data-role="guest"] .role-icon { color: #6c757d; }
.role-card[data-role="press"] .role-icon { color: #2279bd; }
.role-card[data-role="candidate"] .role-icon { color: #2279bd; }

/* Ripple-эффект на клик */
.role-card .ripple-effect {
    position: absolute;
    border-radius: 50%;
    background-color: rgba(34, 121, 189, 0.3);
    transform: scale(0);
    animation: ripple 0.6s linear;
    pointer-events: none;
}
@keyframes ripple {
    to { transform: scale(4); opacity: 0; }
}

/* Адаптивность для мобильных */
@media (max-width: 600px) {
    .profile-button {
        top: 5px;
        right: 10px;
    }
    .modal-content {
        margin: 30% auto;
        width: 80%;
    }
    .role-grid,
    .role-group__grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .role-groups {
        gap: 18px;
        padding: 4px 6px 8px;
    }
    .role-path-picker {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .role-path-card {
        min-height: 140px;
        padding: 18px 14px;
    }
    .role-card {
        padding: 20px;
    }
    .role-modal-title {
        font-size: 1.8rem;
    }
}

@media (hover: none) and (pointer: coarse) {
    .profile-button .profile-icon {
        min-height: 44px;
        min-width: 44px;
        padding: 8px 14px;
    }

    .role-modal__header .role-close,
    .role-modal__header button.close {
        min-width: 44px;
        min-height: 44px;
    }
}

/* Телефоны: длинная подпись тянет pill на центр экрана и наезжает на герой/линии — только иконка (подпись в aria-label у кнопки) */
@media (max-width: 640px) {
    .profile-button {
        top: max(6px, env(safe-area-inset-top, 0px)) !important;
        right: max(6px, env(safe-area-inset-right, 0px)) !important;
        left: auto !important;
        z-index: 10060;
    }

    .profile-button .profile-icon {
        position: relative;
        width: 46px !important;
        height: 46px !important;
        min-width: 46px !important;
        min-height: 46px !important;
        max-width: 46px !important;
        padding: 0 !important;
        margin: 0 !important;
        gap: 0 !important;
        border-radius: 50% !important;
        justify-content: center !important;
        align-items: center !important;
        box-sizing: border-box !important;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.22);
    }

    .profile-button .profile-icon .current-role {
        position: absolute !important;
        width: 1px !important;
        height: 1px !important;
        padding: 0 !important;
        margin: -1px !important;
        overflow: hidden !important;
        clip: rect(0, 0, 0, 0) !important;
        clip-path: inset(50%) !important;
        white-space: nowrap !important;
        border: 0 !important;
    }

    .profile-button .profile-icon i {
        font-size: 1.35rem !important;
        line-height: 1 !important;
    }
}