/**
 * ND54 — единая тема: шрифт Inter, тени, скругления, плавные переходы.
 * Порядок: Bootstrap → (main.min.css на публичных страницах) → profile и пр. → этот файл → nd54-lively.css
 */

:root {
    --nd54-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --nd54-primary: #2279bd;
    --nd54-primary-rgb: 34, 121, 189;
    --nd54-primary-dark: #1a5a8c;
    --nd54-accent: #ffd700;
    --nd54-radius-sm: 8px;
    --nd54-radius: 12px;
    --nd54-radius-lg: 18px;
    --nd54-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --nd54-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --nd54-duration: 0.3s;
    --nd54-duration-fast: 0.18s;
    --nd54-shadow-xs: 0 1px 3px rgba(15, 23, 42, 0.06);
    --nd54-shadow-sm: 0 4px 14px rgba(15, 23, 42, 0.08);
    --nd54-shadow-md: 0 10px 30px rgba(15, 23, 42, 0.11);
    --nd54-shadow-lg: 0 22px 50px rgba(15, 23, 42, 0.14);
    --nd54-shadow-inset: inset 0 1px 0 rgba(255, 255, 255, 0.45);
    --nd54-focus-ring: 0 0 0 3px rgba(var(--nd54-primary-rgb), 0.35);
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

body {
    font-family: var(--nd54-font) !important;
    font-feature-settings: "kern" 1, "liga" 1;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
    font-family: var(--nd54-font);
    letter-spacing: -0.02em;
}

/* Ссылки: плавнее наведение, без резких скачков цвета */
a:not(.btn):not(.nav-link) {
    transition:
        color var(--nd54-duration) var(--nd54-ease),
        opacity var(--nd54-duration) var(--nd54-ease),
        text-decoration-color var(--nd54-duration) var(--nd54-ease),
        box-shadow var(--nd54-duration) var(--nd54-ease);
    text-underline-offset: 0.15em;
}

@media (prefers-reduced-motion: no-preference) {
    .btn,
    .btn-sm,
    .btn-lg,
    .btn-close,
    button:not(:disabled),
    input:not([type="hidden"]),
    select,
    textarea,
    .form-control,
    .form-select,
    .input-group-text,
    .card,
    .card-header,
    .list-group-item,
    .nav-link,
    .dropdown-menu,
    .dropdown-item,
    .modal-content,
    .accordion-button,
    .accordion-item,
    .pagination .page-link,
    .badge,
    img.img-fluid,
    .service-item,
    .service-item-link,
    .white-button a,
    .profile-button .profile-icon,
    #profileBtn,
    .accordion-toggle,
    .accordion-wrapper .accordion-item,
    .map-city-panel,
    .map-back-btn,
    .news-carousel .carousel-item img {
        transition:
            color var(--nd54-duration) var(--nd54-ease),
            background-color var(--nd54-duration) var(--nd54-ease),
            border-color var(--nd54-duration) var(--nd54-ease),
            box-shadow var(--nd54-duration) var(--nd54-ease),
            transform var(--nd54-duration) var(--nd54-ease),
            opacity var(--nd54-duration-fast) var(--nd54-ease),
            filter var(--nd54-duration) var(--nd54-ease);
    }

    .card {
        border-radius: var(--nd54-radius);
        box-shadow: var(--nd54-shadow-sm);
        border: 1px solid rgba(15, 23, 42, 0.06);
    }

    .card-header:first-child {
        border-radius: var(--nd54-radius) var(--nd54-radius) 0 0;
    }

    .btn {
        border-radius: var(--nd54-radius-sm);
        box-shadow: var(--nd54-shadow-xs);
    }

    .btn:hover:not(:disabled) {
        box-shadow: var(--nd54-shadow-sm);
        transform: translateY(-1px);
    }

    .btn:active:not(:disabled) {
        transform: translateY(0);
        box-shadow: var(--nd54-shadow-xs);
    }

    .btn-primary,
    .btn-primary:focus {
        background-color: var(--nd54-primary);
        border-color: var(--nd54-primary);
    }

    .btn-primary:hover:not(:disabled) {
        background-color: var(--nd54-primary-dark);
        border-color: var(--nd54-primary-dark);
    }

    .form-control,
    .form-select {
        border-radius: var(--nd54-radius-sm);
    }

    .form-control:focus,
    .form-select:focus {
        border-color: var(--nd54-primary);
        box-shadow: var(--nd54-focus-ring);
    }

    .modal-content {
        border-radius: var(--nd54-radius-lg);
        box-shadow: var(--nd54-shadow-lg);
        border: 1px solid rgba(15, 23, 42, 0.06);
    }

    .list-group-item {
        border-radius: var(--nd54-radius-sm) !important;
        margin-bottom: 4px;
    }

    .accordion-button {
        border-radius: var(--nd54-radius-sm) !important;
    }

    .accordion-button:not(.collapsed) {
        box-shadow: var(--nd54-shadow-xs);
    }

    .accordion-item {
        border-radius: var(--nd54-radius-sm);
        overflow: hidden;
        margin-bottom: 8px;
        box-shadow: var(--nd54-shadow-xs);
    }

    /* Боковое меню шаблона main.min */
    .menu .main-menu a,
    .menu .soial-icons a {
        transition:
            color var(--nd54-duration) var(--nd54-ease),
            background-color var(--nd54-duration) var(--nd54-ease),
            transform var(--nd54-duration) var(--nd54-ease);
    }

    .menu .main-menu a:hover {
        transform: translateX(4px);
    }

    .service-item,
    .service-item-link {
        border-radius: var(--nd54-radius);
    }

    .service-item:hover,
    .service-item-link:hover {
        box-shadow: var(--nd54-shadow-md);
    }

    .white-button a {
        border-radius: var(--nd54-radius-sm);
        box-shadow: var(--nd54-shadow-sm);
    }

    .white-button a:hover {
        box-shadow: var(--nd54-shadow-md);
    }

    .profile-button .profile-icon,
    #profileBtn.profile-icon {
        box-shadow: var(--nd54-shadow-sm);
    }

    .profile-button .profile-icon:hover,
    #profileBtn.profile-icon:hover {
        box-shadow: var(--nd54-shadow-md);
    }

    .dropdown-menu {
        border-radius: var(--nd54-radius);
        box-shadow: var(--nd54-shadow-md);
        border: 1px solid rgba(15, 23, 42, 0.08);
    }

    .pagination .page-link {
        border-radius: var(--nd54-radius-sm) !important;
        margin: 0 2px;
    }

    .table {
        border-radius: var(--nd54-radius-sm);
        overflow: hidden;
        box-shadow: var(--nd54-shadow-xs);
    }

    img.img-fluid.rounded,
    .rounded {
        transition: box-shadow var(--nd54-duration) var(--nd54-ease), transform var(--nd54-duration) var(--nd54-ease);
    }

    .carousel-control-prev,
    .carousel-control-next {
        transition: opacity var(--nd54-duration) var(--nd54-ease), transform var(--nd54-duration) var(--nd54-ease);
    }

    .carousel-control-prev:hover,
    .carousel-control-next:hover {
        transform: scale(1.05);
    }

    .accordion-toggle:hover {
        box-shadow: var(--nd54-shadow-sm);
        transform: translateY(-1px);
    }

    .accordion-toggle:active {
        transform: translateY(0);
    }
}

/* Боковое меню: соцкнопки (VK, Telegram) — всегда, в т.ч. при prefers-reduced-motion */
.menu .social-network ul.nd54-social-icons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.65rem;
}

.menu .social-network ul.nd54-social-icons > li {
    margin: 0;
}

.menu .social-network ul li a.nd54-social-link {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 48px !important;
    height: 48px !important;
    line-height: 1 !important;
    text-shadow: none !important;
    filter: none !important;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.28) !important;
    color: #fff !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.menu .social-network ul li a.nd54-social-link i {
    text-shadow: none !important;
    filter: none !important;
    font-size: 1.35rem;
    line-height: 1;
}

.menu .social-network ul li a.nd54-social-link:hover,
.menu .social-network ul li a.nd54-social-link:focus {
    text-shadow: none !important;
    filter: none !important;
}

.menu .social-network ul li a.nd54-social-link:hover {
    background: #fff !important;
    color: var(--nd54-primary, #2279bd) !important;
}

.menu .social-network ul li a.nd54-social-link:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 3px;
}

/* Лёгкое появление блоков (опционально: класс на секции) */
@keyframes nd54-fade-up {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (prefers-reduced-motion: no-preference) {
    .nd54-animate-in {
        animation: nd54-fade-up 0.55s var(--nd54-ease-out) both;
    }

    .nd54-animate-in-delay-1 {
        animation-delay: 0.08s;
    }

    .nd54-animate-in-delay-2 {
        animation-delay: 0.16s;
    }
}

@media (prefers-reduced-motion: reduce) {
    .btn:hover:not(:disabled),
    .carousel-control-prev:hover,
    .carousel-control-next:hover,
    .accordion-toggle:hover,
    .accordion-toggle:active {
        transform: none;
    }

    .nd54-animate-in,
    .nd54-animate-in-delay-1,
    .nd54-animate-in-delay-2 {
        animation: none !important;
    }
}

/* =============================================================================
   Адаптивность: телефоны, планшеты, safe-area, касания, без горизонтального скролла
   ============================================================================= */

img,
video,
canvas,
svg,
picture {
    max-width: 100%;
    height: auto;
}

iframe {
    max-width: 100%;
}

/* Таблицы и широкие блоки — прокрутка пальцем (iOS) */
.table-responsive {
    -webkit-overflow-scrolling: touch;
    overflow-x: auto;
}

/* Вырезы и индикатор «домой» на телефонах (z-index в profile.css — выше #page-wraper) */
.profile-button {
    top: max(10px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
}

body.nd54-role-modal-open {
    overflow: hidden;
}

#menu-toggle {
    top: env(safe-area-inset-top, 0px) !important;
    left: env(safe-area-inset-left, 0px) !important;
}

.menu .container {
    padding-top: max(8px, env(safe-area-inset-top, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

#taskModalCustom .custom-modal-container {
    margin-bottom: env(safe-area-inset-bottom, 0px);
}

.modal-dialog {
    margin-left: max(0.5rem, env(safe-area-inset-left, 0px));
    margin-right: max(0.5rem, env(safe-area-inset-right, 0px));
}

/* Сетка Bootstrap: колонки не раздувают страницу за счёт flex-min-width */
@media (max-width: 1199.98px) {
    .row > [class*="col"] {
        min-width: 0;
    }
}

/* iOS Safari: поля с font-size < 16px вызывают авто-зум при фокусе */
@media screen and (max-width: 767.98px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="url"],
    input[type="number"],
    textarea,
    select.form-select,
    select.form-control,
    .form-control {
        font-size: max(1rem, 16px);
    }
}

/* Крупнее зона нажатия на сенсорных экранах (ориентир ~44×44 pt) */
@media (hover: none) and (pointer: coarse) {
    .btn:not(.btn-sm) {
        min-height: 44px;
        padding-top: 0.55rem;
        padding-bottom: 0.55rem;
    }

    .accordion-toggle {
        min-height: 48px;
        padding-top: 14px;
        padding-bottom: 14px;
    }

    .nav-link {
        padding-top: 0.65rem;
        padding-bottom: 0.65rem;
    }
}

/* Ландшафт на маленьких телефонах */
@media (max-width: 896px) and (orientation: landscape) and (max-height: 500px) {
    .modal-dialog {
        margin-top: 0.5rem;
        margin-bottom: 0.5rem;
    }
}

/* Печать: убрать навигацию и фиксированные элементы */
@media print {
    .profile-button,
    .menu,
    .responsive-nav,
    #menu-toggle,
    #menu-close,
    .btn-pulse {
        display: none !important;
    }

    .section {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 12px !important;
        color: #000 !important;
        background: #fff !important;
    }

    body {
        background: #fff !important;
    }

    a[href]::after {
        content: none !important;
    }
}

/* Старые WebKit: запас, если backdrop-filter не поддерживается */
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .nd54-project-tasks-panel {
        background: rgba(248, 250, 252, 0.92);
    }
}

/* Кабинеты и Bootstrap-модалки: короткие предсказуемые переходы */
@media (prefers-reduced-motion: no-preference) {
    .modal.fade .modal-dialog {
        transition:
            transform 0.28s var(--nd54-ease-out),
            opacity 0.24s ease;
    }
}

@media (prefers-reduced-motion: reduce) {
    .modal.fade .modal-dialog {
        transition: none !important;
    }

    .tab-content-main {
        animation: none !important;
    }
}

/* =============================================================================
   Весь сайт: доверие, доступность, читаемость реквизитов и телефонов
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto !important;
    }

    .hero-fade-in,
    .btn-pulse,
    .security-animation {
        animation: none !important;
    }

    .parallax {
        transform: none !important;
        transition: none !important;
    }

    .carousel-item {
        transition: none !important;
    }
}

/* Клавиатура: явное кольцо фокуса */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[role="button"]:focus-visible,
summary:focus-visible {
    outline: none;
    box-shadow: var(--nd54-focus-ring);
}

.btn:focus-visible,
.nav-link:focus-visible,
.page-link:focus-visible {
    outline: none;
    box-shadow: var(--nd54-focus-ring);
}

/* Сенсор: крупнее зоны в боковом меню и соцкнопках */
@media (hover: none) and (pointer: coarse) {
    .menu .main-menu a {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .menu .soial-icons a {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    section.donation .btn-lg {
        min-height: 48px;
    }
}

/* Блок пожертвований (тёмный фон): контраст текста и ссылок без «мигания» */
section.donation.nd54-donation-section .donation-heading span,
section.donation.nd54-donation-section .donation-card,
section.donation.nd54-donation-section .donation-card p,
section.donation.nd54-donation-section .agreement-section,
section.donation.nd54-donation-section .agreement-section p {
    color: rgba(255, 255, 255, 0.95);
}

section.donation.nd54-donation-section .text-muted,
section.donation.nd54-donation-section small {
    color: rgba(255, 255, 255, 0.85) !important;
}

section.donation.nd54-donation-section a:not(.btn) {
    color: #bfdbfe;
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

section.donation.nd54-donation-section a:not(.btn):hover {
    color: #e0f2fe;
}

@media (prefers-reduced-motion: reduce) {
    section.donation.nd54-donation-section .btn-pulse {
        animation: none !important;
        box-shadow: none;
    }
}

/* Подвал: тот же тон, что у блока пожертвований, без «белого пятна» */
.nd54-site-footer {
    background: #1f1f1f;
    color: rgba(255, 255, 255, 0.9);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    width: 100%;
    box-sizing: border-box;
    position: relative;
    z-index: 10000;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* main.min.css задаёт всем .container padding 40px — для подвала это ломает вид */
.nd54-site-footer .nd54-site-footer__container {
    padding-top: 1.25rem !important;
    padding-bottom: 1.25rem !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
    max-width: 1140px;
    margin-left: auto;
    margin-right: auto;
}

.nd54-site-footer__link {
    color: #bfdbfe;
    text-decoration: underline;
    text-underline-offset: 0.2em;
    font-weight: 500;
}

.nd54-site-footer__link:hover {
    color: #e0f2fe;
}

.nd54-site-footer__link--main {
    font-size: 1.08rem;
    font-weight: 600;
    color: #f0f9ff !important;
    text-decoration: none !important;
    border-bottom: 1px solid rgba(191, 219, 254, 0.5);
    padding-bottom: 0.15rem;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.nd54-site-footer__link--main:hover {
    color: #fff !important;
    border-bottom-color: #fff;
}

/* reCAPTCHA v3: скрыть плавающий значок (нужна видимая подпись — см. .nd54-recaptcha-notice) */
.grecaptcha-badge {
    visibility: hidden !important;
}

.nd54-recaptcha-notice {
    font-size: 0.7rem;
    line-height: 1.45;
    color: rgba(255, 255, 255, 0.5);
    text-align: center;
    margin-top: 0.75rem;
    margin-bottom: 0;
}

.nd54-recaptcha-notice a {
    color: rgba(191, 219, 254, 0.9);
    text-decoration: underline;
    text-underline-offset: 0.15em;
}

.nd54-recaptcha-notice a:hover {
    color: #e0f2fe;
}

/* Та же подпись на светлом фоне (например, application.php) */
.nd54-recaptcha-notice.nd54-recaptcha-notice--light {
    color: #6c757d;
    margin-top: 1rem;
}

.nd54-recaptcha-notice.nd54-recaptcha-notice--light a {
    color: #2279bd;
}

.nd54-recaptcha-notice.nd54-recaptcha-notice--light a:hover {
    color: #1a5f94;
}

/* =============================================================================
   Меню: выезд слева + сдвиг страницы вправо (визуально «стык» с контентом)
   ============================================================================= */
:root {
    --nd54-drawer-w: min(380px, 94vw);
}

body.nd54-menu-open {
    overflow-x: hidden;
}

/* Только кнопка «гамбургер» — fixed. Крестик внутри .menu: absolute, иначе legacy right:0 наезжает на «Личный кабинет». */
#menu-toggle {
    display: inline-flex !important;
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.2);
    z-index: 10050 !important;
    pointer-events: auto !important;
    position: fixed !important;
    top: max(0px, env(safe-area-inset-top, 0px));
    left: max(0px, env(safe-area-inset-left, 0px));
    right: auto !important;
    width: 3rem;
    height: 3rem;
    min-width: 3rem;
    min-height: 3rem;
    border-radius: 0 0 12px 0;
}

#menu-close {
    position: absolute !important;
    top: max(0px, env(safe-area-inset-top, 0px)) !important;
    right: max(0px, env(safe-area-inset-right, 0px)) !important;
    left: auto !important;
    bottom: auto !important;
    z-index: 5 !important;
    display: inline-flex !important;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    pointer-events: auto !important;
    width: 2.75rem;
    height: 2.75rem;
    min-width: 2.75rem;
    min-height: 2.75rem;
    border-radius: 0 0 0 10px;
}

.nd54-menu-toggle-btn,
.nd54-menu-close-btn {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    margin: 0;
    padding: 0;
    cursor: pointer;
    font: inherit;
    color: inherit;
    background: #fff;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
}

.nd54-menu-toggle-btn:focus-visible,
.nd54-menu-close-btn:focus-visible {
    outline: none;
    box-shadow: var(--nd54-focus-ring, 0 0 0 3px rgba(34, 121, 189, 0.45));
}

/* Панель под основным слоем; страница уезжает вправо и открывает меню (fixed — контекст для #menu-close: absolute) */
.menu {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    height: 100vh !important;
    max-height: 100dvh !important;
    z-index: 9990 !important;
    width: var(--nd54-drawer-w) !important;
    max-width: 94vw !important;
    transform: translateX(-100%) !important;
    -webkit-transform: translateX(-100%) !important;
    transition:
        transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.28s ease !important;
    box-shadow: none !important;
}

.menu.open {
    transform: translateX(0) !important;
    -webkit-transform: translateX(0) !important;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12) !important;
}

/* Контент панели не под крестик */
.menu > .container {
    padding-top: 0.5rem;
}

#page-wraper {
    position: relative;
    z-index: 10000;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

body.nd54-menu-open #page-wraper {
    transform: translateX(var(--nd54-drawer-w));
}

body.nd54-menu-open .nd54-site-footer {
    transform: translateX(var(--nd54-drawer-w));
}

footer.nd54-shift-with-menu {
    position: relative;
    z-index: 10000;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

body.nd54-menu-open footer.nd54-shift-with-menu {
    transform: translateX(var(--nd54-drawer-w));
}

#page-wraper .section,
.section {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
}

/* Карта/hero: без отступов под старую боковую колонку */
.top-header img,
.top-header object {
    width: 100% !important;
    max-width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Кнопка гамбургера — не перекрывать герб/карту на узком экране */
@media (max-width: 767.98px) {
    #page-wraper > .section.about-me:first-of-type {
        padding-top: calc(0.5rem + 3.25rem + env(safe-area-inset-top, 0px));
    }
}

/* =============================================================================
   Любая ширина телефона (в т.ч. 320px, складные, вырезы): без гор. скролла
   ============================================================================= */
main,
#content,
#wrapper,
#content-wrapper,
.cabinet-wrap,
.cabinet-wrapper {
    min-width: 0;
}

/* Длинные URL и строки в таблицах/карточках */
p,
li,
dd,
td,
th,
.card-text,
.list-group-item,
.alert,
pre,
code {
    overflow-wrap: anywhere;
    word-wrap: break-word;
}

pre {
    white-space: pre-wrap;
    max-width: 100%;
}

@media (max-width: 575.98px) {
    .row {
        --bs-gutter-x: max(0.75rem, min(1.25rem, 4.5vw));
    }

    .container,
    .container-fluid,
    .container-sm,
    .container-md,
    .container-lg {
        padding-left: max(var(--bs-gutter-x, 0.75rem), env(safe-area-inset-left, 0px));
        padding-right: max(var(--bs-gutter-x, 0.75rem), env(safe-area-inset-right, 0px));
    }
}

/* Сверхузкие экраны: не раздувать отступы */
@media (max-width: 360px) {
    .card .card-header,
    .card .card-body,
    .card .card-footer {
        padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
    }
}

/* Узкий ландшафт: модалки не вылезают по высоте */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
    .modal-dialog {
        max-height: min(90vh, 100dvh);
        margin-top: 0.35rem;
    }

    .modal-content {
        max-height: min(88vh, 100dvh);
        overflow-y: auto;
    }
}

/* =============================================================================
   Универсально: телефоны/планшеты, кнопки не перекрывают друг друга
   Исключения: .nd54-keep-row — горизонтальная прокрутка вместо переноса
   ============================================================================= */
:root {
    --nd54-touch-min: 44px;
    --nd54-ui-gap: 0.5rem;
    --nd54-ui-gap-tight: 0.35rem;
}

/* Интерактив: касание, без 300ms задержки в старых WebKit, без «лишнего» outline при тапе */
button,
[role="button"],
input[type="submit"],
input[type="button"],
a.btn,
summary,
.nav-link,
.page-link,
.dropdown-item {
    touch-action: manipulation;
}

/* Ряды кнопок / действия в карточках и модалках — перенос и интервал (не слипание) */
@media (max-width: 991.98px) {
    .card-header .d-flex:not(.nd54-keep-row),
    .card-footer .d-flex:not(.nd54-keep-row),
    .modal-header .d-flex:not(.nd54-keep-row),
    .main-header .d-flex:not(.nd54-keep-row) {
        flex-wrap: wrap;
        row-gap: var(--nd54-ui-gap);
        column-gap: var(--nd54-ui-gap);
    }

    .d-flex.gap-1,
    .d-flex.gap-2,
    .d-flex.gap-3 {
        row-gap: var(--nd54-ui-gap);
    }
}

/* Bootstrap: группы кнопок на малых экранах — не в одну линию 10 кнопок */
@media (max-width: 767.98px) {
    .btn-group,
    .btn-group-vertical {
        display: flex;
        flex-wrap: wrap;
        max-width: 100%;
        gap: var(--nd54-ui-gap-tight);
    }

    .btn-group > .btn,
    .btn-group-vertical > .btn {
        position: relative;
        flex: 1 1 auto;
        min-width: min(100%, 8.5rem);
        margin: 0 !important;
        /* после переноса сегменты визуально отдельные, не слипшиеся */
        border-radius: var(--bs-border-radius, 0.375rem) !important;
    }

    .btn-toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: var(--nd54-ui-gap);
        max-width: 100%;
    }

    .btn-toolbar .btn-group {
        margin-bottom: 0;
    }
}

/* Модалки: футер с кнопками */
@media (max-width: 575.98px) {
    .modal-footer {
        display: flex;
        flex-wrap: wrap;
        gap: var(--nd54-ui-gap);
        align-items: stretch;
    }

    .modal-footer .btn,
    .modal-footer .btn-group {
        flex: 1 1 calc(50% - var(--nd54-ui-gap));
        min-width: min(100%, 9rem);
    }
}

/* Вкладки: не сжимать в кашу — прокрутка */
@media (max-width: 767.98px) {
    .nav.nav-tabs,
    .nav.nav-pills:not(.nd54-keep-row) {
        flex-wrap: nowrap;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        flex-shrink: 0;
        gap: 0.25rem;
    }

    .nav.nav-tabs .nav-item,
    .nav.nav-pills .nav-item {
        flex: 0 0 auto;
    }

    .nav.nav-tabs .nav-link,
    .nav.nav-pills .nav-link {
        white-space: nowrap;
    }
}

/* Пагинация */
@media (max-width: 575.98px) {
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.25rem;
    }
}

/* Поле + кнопка: не вылезать за экран */
@media (max-width: 575.98px) {
    .input-group {
        flex-wrap: wrap;
        max-width: 100%;
    }

    .input-group > :not(:first-child):not(.dropdown-menu) {
        margin-left: 0 !important;
    }

    .input-group .form-control,
    .input-group .form-select {
        min-width: 0;
        flex: 1 1 12rem;
    }

    .input-group .btn,
    .input-group .input-group-text {
        flex: 0 0 auto;
    }
}

/* Сенсор: мин. зона + отступы между соседними кнопками-ссылками */
@media (hover: none) and (pointer: coarse) {
    .btn:not(.btn-sm):not(.btn-xs),
    .page-link,
    .nav-pills .nav-link {
        min-height: var(--nd54-touch-min);
    }

    .d-flex .btn + .btn,
    .d-flex a.btn + a.btn,
    .card-footer .btn + .btn {
        margin-top: 0;
    }
}

/* Гориз. ряд без переноса: прокрутка (табы, тулбар с фильтрами) */
.nd54-keep-row,
.d-flex.nd54-keep-row {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: var(--nd54-ui-gap-tight);
    max-width: 100%;
    padding-bottom: 2px;
}

.nd54-keep-row > * {
    flex: 0 0 auto;
}

/* iOS/Chrome: минимальная высота вьюпорта (корректный dvh) */
@supports (min-height: 100dvh) {
    .min-vh-100 {
        min-height: 100dvh !important;
    }
}

/* Фиксированные панели — не под индикатор «домой» */
@media (max-width: 991.98px) {
    .position-fixed.end-0,
    .position-fixed.end-0.top-0 {
        right: max(0.5rem, env(safe-area-inset-right, 0px)) !important;
    }

    .position-fixed.bottom-0,
    [class~="bottom-0"].position-fixed {
        bottom: max(0, env(safe-area-inset-bottom, 0px)) !important;
    }
}

/* Публичная реклама (главная, кабинет заявителя): на всю ширину, по высоте — в окно */
.nd54-pub-ads-wrap,
.nd54-pub-ad-root {
    width: 100%;
    max-width: 100%;
}

.nd54-pub-ad-slides {
    position: relative;
    width: 100%;
    min-height: 8rem;
    background: #0f172a;
    overflow: hidden;
}

.nd54-pub-ad-slide {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/*
 * Картинки и видео: на всю ширину блока, высота — от окна.
 * object-fit: contain оставлял боковые/верхние «поля», если одна сторона упиралась
 * в max-height — с cover заполняем прямоугольник, лишнее обрезается по краям.
 */
.nd54-pub-ad-media,
.nd54-pub-ad-slide img,
.nd54-pub-ad-slide video {
    display: block;
    width: 100% !important;
    max-width: 100%;
    height: min(75dvh, 85vh, 1000px);
    min-height: 12rem;
    max-height: min(75dvh, 85vh, 1000px);
    object-fit: cover;
    object-position: center center;
    background: #0a0a0a;
    vertical-align: top;
}

@supports (height: 1svh) {
    .nd54-pub-ad-media,
    .nd54-pub-ad-slide img,
    .nd54-pub-ad-slide video {
        height: min(75svh, 1000px);
        max-height: min(75svh, 1000px);
    }
}

/* PDF / встроенные просмотры */
.nd54-pub-ad-frame {
    display: block;
    width: 100% !important;
    min-height: min(45vh, 28rem);
    max-height: min(82dvh, 85vh, 56rem);
    border: 0;
    background: #f1f5f9;
}
