/**
 * ND54 — совместимость с браузерами: Chrome, Firefox, Safari (macOS/iOS),
 * Samsung Internet, Edge, Яндекс.Браузер, Opera.
 */

/* --- Базовые сбросы и стабильность раскладки --- */
*,
*::before,
*::after {
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

@supports (overflow: clip) {
    html,
    body {
        overflow-x: clip;
    }
}

body {
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

img,
svg,
video,
canvas,
iframe,
object {
    max-width: 100%;
    height: auto;
    vertical-align: middle;
}

/* Safari: flex-дети не раздувают контейнер */
.min-vw-0,
[style*="min-width: 0"],
.col,
[class*="col-"],
.card,
.modal-body,
.table-responsive,
.flex-grow-1 {
    min-width: 0;
}

/* --- Формы: единый вид WebKit / Gecko / Blink --- */
button,
input,
select,
textarea {
    font: inherit;
    color: inherit;
    margin: 0;
}

button,
[type="button"],
[type="submit"],
[type="reset"] {
    -webkit-appearance: button;
    appearance: button;
    cursor: pointer;
}

input[type="search"] {
    -webkit-appearance: none;
    appearance: none;
}

textarea {
    resize: vertical;
    overflow: auto;
}

::-webkit-input-placeholder {
    color: #94a3b8;
    opacity: 1;
}
::-moz-placeholder {
    color: #94a3b8;
    opacity: 1;
}
:-ms-input-placeholder {
    color: #94a3b8;
    opacity: 1;
}
::placeholder {
    color: #94a3b8;
    opacity: 1;
}

/* iOS: без зума при фокусе */
@media (max-width: 767.98px) {
    input:not([type="checkbox"]):not([type="radio"]),
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* --- Фокус: :focus-visible + fallback --- */
:focus {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--nd54-primary, #2279bd);
    outline-offset: 2px;
}

/* --- Flex / Grid: запас без gap --- */
@supports not (gap: 0.5rem) {
    .d-flex.flex-wrap > * {
        margin: 0.25rem;
    }
    .row > [class*="col-"] {
        margin-bottom: 0.75rem;
    }
}

/* --- Transform / fixed: GPU-слой для Safari --- */
.menu,
.profile-button,
.nd54-menu-toggle-btn,
.nd54-scroll-progress,
.nd54-audio-toggle,
.modal,
.role-modal,
#taskModalCustom.custom-modal--open {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* iOS: fixed background ломает скролл — отключаем на touch */
@supports (-webkit-touch-callout: none) {
    html.nd54-site-bg {
        background-attachment: scroll !important;
    }
}

/* --- Высота экрана: var(--nd54-vh) из nd54-compat.js --- */
.nd54-min-h-screen {
    min-height: 100vh;
    min-height: calc(var(--nd54-vh, 1vh) * 100);
}

.nd54-h-screen {
    height: 100vh;
    height: calc(var(--nd54-vh, 1vh) * 100);
}

.menu {
    height: 100vh;
    height: calc(var(--nd54-vh, 1vh) * 100);
    max-height: -webkit-fill-available;
    max-height: 100dvh;
}

/* --- Скролл: плавность WebKit --- */
.menu,
.modal-body,
.table-responsive,
.main-nav-tabs,
.sub-nav-tabs {
    -webkit-overflow-scrolling: touch;
}

/* Firefox: тонкий скролл */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(34, 121, 189, 0.45) transparent;
}

/* WebKit scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-thumb {
    background: rgba(34, 121, 189, 0.4);
    border-radius: 4px;
}

/* --- Bootstrap / модалки: backdrop и body lock --- */
.modal {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

body.modal-open {
    overflow: hidden;
    padding-right: 0 !important;
}

@supports (padding: max(0px)) {
    body.modal-open {
        padding-right: env(safe-area-inset-right, 0) !important;
    }
}

/* --- Видео / аудио --- */
video,
audio {
    max-width: 100%;
}

video {
    object-fit: cover;
}

/* --- Таблицы: не ломают вёрстку в старых движках --- */
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* --- Печать --- */
@media print {
    .nd54-ambient,
    .nd54-scroll-progress,
    .nd54-audio-toggle,
    .profile-button,
    .nd54-menu-toggle-btn,
    .menu,
    #nd54AmbientAudio {
        display: none !important;
    }

    body,
    #page-wraper {
        background: #fff !important;
        color: #000 !important;
    }
}

/* --- Снижение движения (доступность) --- */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        -webkit-animation-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        -webkit-animation-iteration-count: 1 !important;
        animation-iteration-count: 1 !important;
        -webkit-transition-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* --- Высокий контраст Windows --- */
@media (forced-colors: active) {
    .btn-primary {
        border: 2px solid ButtonText;
    }

    a:focus-visible,
    button:focus-visible {
        outline: 3px solid Highlight;
    }
}

html.nd54-no-intersection .nd54-reveal,
html.nd54-no-intersection .nd54-reveal.nd54-reveal--visible {
    opacity: 1 !important;
    visibility: visible !important;
    transform: none !important;
}

/* --- object-fit fallback (редкие старые WebView) --- */
@supports not (object-fit: cover) {
    .news-carousel .carousel-item img {
        width: 100%;
        height: auto;
    }
}

/* --- min()/max() fallback для критичных блоков --- */
@supports not (width: min(100%, 800px)) {
    #taskModalCustom .custom-modal-container {
        width: 90%;
        max-width: 800px;
    }

    .nd54-appeal-card {
        max-width: 100%;
    }
}

/* --- Яндекс / Opera: selection --- */
::selection {
    background: rgba(34, 121, 189, 0.25);
    color: inherit;
}

/* --- Ссылки и кнопки: без синего tap на iOS --- */
a,
button {
    -webkit-tap-highlight-color: rgba(34, 121, 189, 0.15);
}

/* --- fieldset legend в Firefox --- */
fieldset {
    min-width: 0;
    border: 0;
    margin: 0;
    padding: 0;
}

/* --- details/summary --- */
details > summary {
    cursor: pointer;
    list-style: none;
}

details > summary::-webkit-details-marker {
    display: none;
}

/* --- SVG в кнопках IE-mode не актуален; для WebKit --- */
svg {
    fill: currentColor;
    flex-shrink: 0;
}

/* --- Карта: object/embed --- */
object.svg-map {
    display: block;
    width: 100%;
    max-width: 100%;
}

/* --- Публичные формы (apply, application) --- */
.form-card,
.main-card {
    max-width: 100%;
}

/* --- safe-area для fixed UI --- */
@supports (padding: max(0px)) {
    .profile-button {
        top: max(12px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
    }

    .nd54-menu-toggle-btn {
        top: max(12px, env(safe-area-inset-top));
        left: max(12px, env(safe-area-inset-left));
    }
}
