/* =========================
   АДАПТИВНЫЙ
========================= */

/* Сетка карточек объявлений: держим максимум окошек в ряду.
   База — 5 колонок (в cards.css), они доезжают до 1001px включительно
   (Nest Hub Max и весь диапазон 1001–1200px = 5 объявлений в строке).
   Дальше ужимаем по одной колонке, но даже на маленьких телефонах
   остаётся 2 в ряд, а не 1 — чтобы влезало больше. */
@media (max-width: 1000px) {
    .items-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 980px) {
    .items-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 760px) {
    .items-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Вкладки «Мои объявления / Новости» — заглушки на будущее. Показываем только
   на широких экранах, где для них есть место рядом с поиском; ниже 1300px
   прячем, чтобы поиск не схлопывался и шапка оставалась компактной. */
@media (max-width: 1300px) {
    .header-tabs {
        display: none;
    }
}

/* ── Шапка ниже десктопа — единая бургер-раскладка в ОДНУ строку: поиск +
   кнопка «бургер». Десктопная шапка помещается в один ряд только от 1024px;
   ниже раньше была «странная» многострочная раскладка (особенно заметная на
   складных устройствах вроде ASUS Zenbook Fold, ~700–1000px). Теперь на всём
   диапазоне до 1023px — компактный бургер, а всё содержимое обычной шапки
   (логотип, Барнаул, каталог, избранное, сообщения, мои объявления,
   вход/профиль, тема, разместить) уходит в выезжающее меню. */
@media (max-width: 1023px) {
    .site-header {
        position: static;
        margin-bottom: 16px;
    }

    .header-inner {
        flex-wrap: nowrap;
        align-items: center;
        gap: 10px;
        padding: 9px 0;
        min-height: 0;
    }

    /* В верхней строке на телефоне остаётся только поиск —
       навигация уехала в нижнюю панель (.bottom-nav). */
    .logo,
    .catalog-picker,
    .publish-btn,
    .header-tabs,
    .header-actions,
    .city-picker {
        display: none;
    }

    .search-box {
        flex: 1 1 auto;
        min-width: 0;
    }

    .search-box input,
    .search-btn {
        font-size: 16px; /* >=16px — отключает авто-зум в iOS */
    }

    /* Контент не должен прятаться под фиксированной нижней панелью. */
    body {
        padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    }

    /* ---------- Нижняя панель навигации ---------- */
    .bottom-nav {
        display: flex;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1500;
        align-items: stretch;
        justify-content: space-around;
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--panel);
        border-top: 1px solid rgba(24, 193, 210, 0.18);
        box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.18);
    }

    .bnav-item {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 8px 2px 7px;
        border: none;
        background: none;
        cursor: pointer;
        text-decoration: none;
        color: var(--muted);
        font-size: 11px;
        font-weight: 600;
        line-height: 1.1;
    }

    .bnav-icon {
        width: 24px;
        height: 24px;
        fill: none;
        stroke: currentColor;
        stroke-width: 2;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

    /* Активный раздел — акцентным цветом. */
    .bnav-item.is-active {
        color: var(--accent);
    }

    /* Центральная кнопка «Разместить» — приподнятый акцентный круг. */
    .bnav-publish {
        color: var(--accent);
    }

    .bnav-plus {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 46px;
        height: 46px;
        margin-top: -18px;
        border-radius: 50%;
        background: var(--accent);
        color: #fff;
        font-size: 30px;
        font-weight: 300;
        line-height: 1;
        box-shadow: 0 4px 12px rgba(24, 193, 210, 0.45);
    }

    /* Иконка сообщений + бейдж непрочитанных. */
    .bnav-icon-wrap {
        position: relative;
        display: inline-flex;
    }

    .bnav-badge {
        position: absolute;
        top: -6px;
        right: -9px;
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        border-radius: 999px;
        background: #e5484d;
        color: #fff;
        font-size: 10px;
        font-weight: 700;
        line-height: 16px;
        text-align: center;
        box-shadow: 0 0 0 2px var(--panel);
    }

    /* Затемнение позади меню */
    .drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1999;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease;
    }

    .drawer-backdrop.is-open {
        opacity: 1;
        visibility: visible;
    }

    /* Сама панель меню — выезжает справа */
    .mobile-drawer {
        display: flex;
        flex-direction: column;
        gap: 4px;
        position: fixed;
        top: 0;
        right: 0;
        z-index: 2000;
        width: min(82%, 340px);
        height: 100%;
        padding: 14px 16px calc(env(safe-area-inset-bottom, 0px) + 20px);
        background: var(--panel);
        box-shadow: -8px 0 28px rgba(0, 0, 0, 0.4);
        transform: translateX(100%);
        transition: transform 0.25s ease;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .mobile-drawer.is-open {
        transform: translateX(0);
    }

    .mobile-drawer-head {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 10px;
    }

    .drawer-logo {
        display: inline-flex;
        align-items: center;
    }

    .drawer-logo-img {
        width: 116px;
        height: auto;
        display: block;
    }

    /* Выбор города в мобильном меню — раскрывающийся список (<details>) */
    .drawer-city-picker {
        width: 100%;
    }

    /* Кнопка-«ручка» (это <summary>) — со стрелкой-кареткой справа */
    .drawer-city {
        justify-content: space-between;
        list-style: none;
    }

    .drawer-city::-webkit-details-marker {
        display: none;
    }

    .drawer-city::after {
        content: '';
        width: 0;
        height: 0;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-top: 6px solid currentColor;
        transition: transform 0.2s ease;
    }

    .drawer-city-picker[open] .drawer-city::after {
        transform: rotate(180deg);
    }

    .drawer-city-menu {
        display: flex;
        flex-direction: column;
        margin: 2px 0 4px;
    }

    .drawer-city-menu .city-search {
        height: 46px;
        margin-bottom: 6px;
        font-size: 16px; /* >=16px — отключает авто-зум в iOS */
    }

    .drawer-city-menu .city-results {
        display: flex;
        flex-direction: column;
        gap: 2px;
        max-height: 42vh;
        overflow-y: auto;
    }

    .drawer-city-item {
        display: flex;
        align-items: center;
        min-height: 44px;
        padding: 0 14px 0 28px;
        border-radius: 10px;
        color: var(--muted);
        font-size: 15px;
        font-weight: 600;
        text-decoration: none;
    }

    .drawer-city-item:hover,
    .drawer-city-item:active {
        background: rgba(24, 193, 210, 0.12);
        color: var(--accent);
    }

    .drawer-city-item.is-active {
        color: var(--accent);
    }

    /* Каталог в мобильном меню — раскрывающийся список категорий (<details>) */
    .drawer-catalog-picker {
        width: 100%;
    }

    .drawer-catalog {
        justify-content: space-between;
        list-style: none;
    }

    .drawer-catalog::-webkit-details-marker {
        display: none;
    }

    .drawer-catalog::after {
        content: '';
        width: 0;
        height: 0;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-top: 6px solid currentColor;
        transition: transform 0.2s ease;
    }

    .drawer-catalog-picker[open] .drawer-catalog::after {
        transform: rotate(180deg);
    }

    .drawer-catalog-menu {
        display: flex;
        flex-direction: column;
        gap: 2px;
        margin: 2px 0 4px;
    }

    .drawer-catalog-item {
        display: flex;
        align-items: center;
        gap: 10px;
        min-height: 44px;
        padding: 0 14px 0 20px;
        border-radius: 10px;
        color: var(--muted);
        font-size: 15px;
        font-weight: 600;
        text-decoration: none;
    }

    .drawer-catalog-item:hover,
    .drawer-catalog-item:active {
        background: rgba(24, 193, 210, 0.12);
        color: var(--accent);
    }

    .drawer-catalog-item.is-active {
        color: var(--accent);
    }

    .drawer-close {
        width: 40px;
        height: 40px;
        border: none;
        background: transparent;
        color: var(--text);
        font-size: 26px;
        line-height: 1;
        cursor: pointer;
        border-radius: 10px;
    }

    .drawer-link {
        display: flex;
        align-items: center;
        width: 100%;
        min-height: 52px;
        padding: 0 14px;
        border: none;
        border-radius: 12px;
        background: transparent;
        color: var(--text);
        font-size: 16px;
        font-weight: 700;
        text-align: left;
        text-decoration: none;
        font-family: inherit;
        cursor: pointer;
    }

    .drawer-link:hover,
    .drawer-link:active {
        background: rgba(24, 193, 210, 0.12);
        color: var(--accent);
    }

    .drawer-link-accent {
        margin: 6px 0;
        background: var(--accent);
        color: #ffffff;
        justify-content: center;
    }

    .drawer-link-accent:hover,
    .drawer-link-accent:active {
        background: var(--accent-hover);
        color: #ffffff;
    }

    .drawer-logout {
        margin: 0;
        padding: 0;
        display: block;
    }
}

@media (max-width: 640px) {
    .shell {
        width: min(100%, calc(100% - 20px));
    }

    .item .desc,
    .item .author,
    #footer {
        font-size: 14px;
    }

    #footer {
        text-align: left;
    }

    .footer-content {
        flex-direction: column;
        gap: 16px;
    }
}

/* Ландшафтные телефоны (низкие экраны) — ещё компактнее */
@media (max-width: 980px) and (max-height: 480px) {
    .header-inner {
        gap: 8px;
        padding: 8px 0;
    }

    .logo-img {
        width: 112px;
    }

    .catalog-btn,
    .search-box,
    .publish-btn {
        height: 42px;
    }
}
