/*
 * Мобильная версия сайта (экраны до 768px).
 * Подключается в base.html ПОСЛЕ main.css, поэтому при равной специфичности выигрывает.
 * Десктопные стили не затрагиваются: всё внутри @media (max-width: 768px).
 */

@media (max-width: 768px) {

    /* ---------- Общее ---------- */

    /* html/body = 100% высоты мешают «прилипшей» шапке: она прилипает только в пределах body */
    html, body {
        height: auto;
    }

    img, video, iframe {
        max-width: 100%;
    }

    /* 16px в полях ввода — иначе iOS при фокусе приближает страницу */
    .form-control,
    .form-control-sm,
    select,
    textarea,
    input[type="text"],
    input[type="number"],
    input[type="search"],
    input[type="date"] {
        font-size: 16px;
    }

    .btn {
        min-height: 38px;
    }

    /* Таблицы раздела закупок (purchases-hub-table) пока не трогаем */
    .table:not(.purchases-hub-table) th,
    .table:not(.purchases-hub-table) td {
        padding: 6px 8px;
        font-size: 0.9rem;
    }

    /* ---------- Шапка ---------- */

    /* Шапка занимает место в потоке и «прилипает» сверху — контент больше не уезжает под неё */
    header.header-fix {
        position: sticky !important;
        top: 0;
        padding: 6px 0 !important;
    }

    header nav.mobile {
        position: relative;
        max-width: none;
        margin: 0;
        padding: 0 12px;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    header nav.mobile .mobile-logo {
        display: flex;
        align-items: center;
    }

    header nav.mobile .mobile-logo img {
        display: block;
        height: 40px;
        width: auto;
        max-width: 150px;
        border-radius: 5px;
    }

    header nav.mobile .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        font-size: 24px;
        border-radius: 8px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    header nav.mobile .menu-toggle:active {
        background-color: #e0e0e0;
    }

    header nav.mobile .menu-toggle i {
        margin-right: 0;
    }

    /* Выпадающее меню — на всю ширину, список в столбик */
    header nav ul.topmenu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        max-height: calc(100vh - 64px);
        margin: 0;
        padding: 0;
        flex-direction: column;
        align-items: stretch;
        overflow-y: auto;
        background-color: #fff;
        border-top: 1px solid #d3d3d3;
        box-shadow: 0 10px 16px rgba(0, 0, 0, 0.18);
    }

    header nav ul.topmenu.show {
        display: flex;
    }

    header nav ul.topmenu > li {
        width: 100%;
        margin: 0;
        border-bottom: 1px solid #eee;
    }

    /* Логотип показывается в самой шапке, в списке он не нужен */
    header nav ul.topmenu > li.mobile-menu-logo {
        display: none;
    }

    header nav ul.topmenu li a {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 14px 16px;
        font-size: 16px;
        border-radius: 0;
    }

    header nav ul.topmenu ul.submenu {
        display: none;
        position: static;
        margin: 0;
        padding: 0;
        list-style: none;
        border: none;
        box-shadow: none;
        background-color: #f8f9fa;
    }

    header nav ul.topmenu ul.submenu.show {
        display: block;
    }

    header nav ul.topmenu ul.submenu li {
        margin: 0;
        border-top: 1px solid #eee;
    }

    header nav ul.topmenu ul.submenu li a {
        padding: 12px 16px 12px 28px;
        font-size: 15px;
    }

    header nav ul.topmenu li > img#specialButton {
        display: block;
        margin: 10px 16px;
        height: 32px;
        width: auto;
    }

    /* Имя пользователя и выход */
    header nav ul.topmenu > li[style*="display: flex"] {
        padding: 12px 16px;
        justify-content: space-between;
    }

    header nav ul.topmenu > li[style*="display: flex"] a {
        padding: 0;
    }

    header nav ul.topmenu .logout-link {
        min-width: 44px;
        min-height: 40px;
    }

    header nav ul.topmenu .button-admin {
        display: block;
        width: 100%;
        padding: 10px !important;
        font-size: 16px;
    }

    header nav ul.topmenu > li > a:has(> .button-admin) {
        padding: 12px 16px;
    }

    /* Заголовки, которые раньше отступали «под фиксированную шапку» вручную (теперь шапка в потоке) */
    h3[style*="padding-top: 90px"] {
        padding-top: 12px !important;
    }

    /* ---------- Баннер под шапкой ---------- */

    .index-block {
        height: auto;
        min-height: 150px;
        padding: 18px 8px 12px;
        margin-bottom: 12px !important;
    }

    .index-text {
        padding: 8px;
    }

    .index-text h2 {
        font-size: 1.2rem;
        margin: 4px 0;
        line-height: 1.25;
    }

    .index-text h6 {
        font-size: 0.8rem;
        margin-top: 8px !important;
    }

    /* ---------- Заголовки-плашки и блоки контента ---------- */

    .news-plate,
    .anti-plate {
        height: auto;
        min-height: 35px;
        padding: 6px 12px;
    }

    .news-plate h2 {
        font-size: 1.25rem;
        line-height: 1.25;
    }

    .inplate-plate {
        width: 100%;
        max-width: 100%;
        height: auto;
        min-height: 40px;
        box-sizing: border-box;
        padding: 6px 12px;
    }

    .inplate-plate h2 {
        font-size: 1.2rem;
        margin: 0;
    }

    .news-container {
        gap: 12px;
        padding: 0 8px;
        box-sizing: border-box;
    }

    .about-block {
        width: 100% !important;
        padding: 12px;
        box-sizing: border-box;
    }

    .news-block {
        flex: 1 1 100%;
    }

    .news-block:hover {
        transform: none;
    }

    .news-image-solo {
        max-width: 100%;
    }

    .news-container-button {
        width: auto;
        height: auto;
    }

    /* Таблицы и видео из редактора не раздвигают страницу */
    .content-block table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
    }

    .video-item iframe {
        width: 100% !important;
        height: auto;
        aspect-ratio: 16 / 9;
    }

    .video-row {
        flex-wrap: wrap;
    }

    .video-row-2 {
        width: 100%;
    }

    /* ---------- Подвал ---------- */

    footer .footer-container {
        flex-direction: column;
        align-items: center !important;
        text-align: center;
        padding: 8px 12px !important;
    }

    footer .footer-section.logo {
        align-items: center !important;
    }

    footer .footer-section.contact {
        min-width: 0;
        text-align: center !important;
    }

    footer .footer-bottom {
        margin-top: 0 !important;
        padding: 6px 12px !important;
    }

    /* ---------- Модальные окна ---------- */

    /* Отступ сверху — под «прилипшую» шапку */
    .modal-dialog,
    .modal-dialog-word {
        width: auto;
        max-width: calc(100% - 16px);
        min-height: 0 !important;
        margin: 70px auto 16px !important;
    }

    .modal-content[style*="margin-top"] {
        margin-top: 0 !important;
    }

    .modal[style*="padding-top"] {
        padding-top: 0 !important;
    }

    #confirmPopup,
    #exportPopup {
        width: auto;
        max-width: calc(100vw - 24px);
        left: 12px;
        right: 12px;
        transform: none;
        top: 80px;
    }

    /* ---------- Карты отключений ---------- */

    .header-container {
        flex-direction: column;
        gap: 8px;
        width: 100% !important;
        padding: 8px 12px;
        box-sizing: border-box;
    }

    .header-container .back-button,
    .header-container .fullscreen-button {
        position: static !important;
        width: 100% !important;
        max-width: 320px;
        margin: 0 !important;
    }

    .header-container h3 {
        font-size: 1.15rem;
    }

    .header-container .legend,
    .legend-container .legend {
        margin: 0;
        gap: 6px 4px;
        justify-content: center;
    }

    .legend-item {
        margin-right: 6px;
        font-size: 13px;
    }

    .under-header,
    .legend-container {
        width: 100% !important;
        padding: 0 12px;
        box-sizing: border-box;
    }

    .toggle-container {
        margin-left: 0 !important;
        padding: 0 12px;
        text-align: center;
    }

    #map:not(.fullscreen-mode) {
        width: calc(100% - 16px) !important;
        max-width: none;
        height: 60vh !important;
        min-height: 320px;
    }

    .fullscreen-controls {
        top: 8px;
        right: 8px;
        left: 8px;
        max-width: none !important;
    }

    /* ---------- ServiceDesk ---------- */

    .service-requests-container {
        margin: 8px auto;
        padding: 8px 10px;
    }

    .service-requests-container h1 {
        font-size: 1.6rem;
    }

    .service-requests-container .form-section {
        padding: 14px;
        margin-bottom: 20px;
    }

    .service-requests-container .form-section h3,
    .service-requests-container .requests-list h3 {
        font-size: 1.25rem;
    }

    .service-requests-container .filter-section {
        padding: 12px;
    }

    .request-card {
        padding: 12px;
    }

    .request-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .request-header .ml-3 {
        margin-left: 0 !important;
        margin-right: 10px;
        display: inline-block;
    }

    .request-header .ml-2 {
        margin-left: 0 !important;
        margin-right: 6px;
    }

    .request-header .status-badge,
    .request-header .urgency-badge {
        margin-bottom: 4px;
    }

    .request-info-item {
        word-break: break-word;
    }

    .request-actions .d-inline-block,
    .request-actions select {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        margin: 0 0 8px 0 !important;
    }

    .request-actions .btn {
        width: 100%;
    }

    .service-requests-container .pagination {
        flex-wrap: wrap;
    }
}

/* Совсем узкие экраны */
@media (max-width: 400px) {
    header nav.mobile .mobile-logo img {
        height: 34px;
        max-width: 120px;
    }

    .index-text h2 {
        font-size: 1.05rem;
    }
}
