/* =====================================================================
   МОБИЛЬНЫЙ ВИД — только для телефонов (до 768px).
   Подключается последним на всех страницах: index.html, catalog.html, files.html.
   Десктопные стили здесь не переопределяются — всё внутри @media.
   ===================================================================== */

/* Нижнее меню по умолчанию скрыто (показывается только на телефоне) */
.mobile-nav {
    display: none;
}

/* Мобильное выпадающее меню (замена шестерёнки) */
.mobile-menu {
    display: none;
}

/* Кнопка «назад» в шапке чата — только для телефона */
.chat__back-btn {
    display: none;
}

@media (max-width: 768px) {
    /* ---------- Базовое: убираем зум при фокусе на iPhone ---------- */
    html {
        -webkit-text-size-adjust: 100%;
    }
    html,
    body {
        max-width: 100%;
    }
    body {
        overflow-x: hidden;
    }
    input,
    textarea,
    select {
        font-size: 16px !important;
    }

    /* Кнопки/ссылки — без задержки 300 мс на тап (iOS) */
    a,
    button {
        touch-action: manipulation;
    }

    /* Высота с учётом адресной строки Safari */
    #app {
        height: 100dvh;
        max-height: 100dvh;
    }

    /* Анимация width у сайдбара на iOS приводит к «залипанию» —
       на телефоне переключение делаем мгновенным */
    .sidebar,
    .sidebar--collapsed {
        transition: none !important;
    }

    /* ---------- Верхнюю шапку на телефоне убираем ---------- */
    .topbar {
        display: none !important;
    }

    /* ---------- Нижнее меню (как в мобильных приложениях) ---------- */
    .mobile-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        display: flex;
        align-items: stretch;
        background: #ffffff;
        border-top: 1px solid #eef0f4;
        box-shadow: 0 -2px 14px rgba(0, 0, 0, 0.06);
        padding-bottom: env(safe-area-inset-bottom, 0px);
        z-index: 950;
    }

    .mobile-nav__item {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-height: 54px;
        padding: 6px 2px;
        border: 0;
        background: transparent;
        font-family: inherit;
        font-size: 10px;
        line-height: 1.1;
        color: #8e929b;
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-nav__item:active {
        background: #f3f5f9;
    }

    .mobile-nav__item--active {
        color: #2e7d32;
    }

    .mobile-nav__icon {
        font-size: 21px;
        line-height: 1;
    }

    /* ================= index.html — чат ================= */
    #app {
        border-radius: 0;
        padding-bottom: calc(54px + env(safe-area-inset-bottom, 0px));
    }

    .app {
        position: relative;
    }

    /* Список запросов — на весь экран */
    .sidebar,
    .sidebar--collapsed {
        width: 100%;
        min-width: 0;
        opacity: 1;
        border-right: none;
    }

    /* Чат скрыт, пока не выбран запрос */
    .chat {
        display: none;
    }

    .app--chat-open .sidebar {
        display: none;
    }

    .app--chat-open .chat {
        display: flex;
        flex: 1;
        min-width: 0;
    }

    .chat__header {
        padding: 10px 12px;
        gap: 8px;
    }

    .chat__toggle-btn {
        display: none;
    }

    .chat__back-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 38px;
        height: 38px;
        border: none;
        border-radius: 10px;
        background: #f3f5f9;
        color: #1e1e2a;
        font-size: 20px;
        line-height: 1;
        cursor: pointer;
        flex-shrink: 0;
    }

    .chat__contact-title {
        font-size: 15px;
    }

    /* «Ссылка клиенту» — только иконка, чтобы не ломать шапку */
    .chat__link-btn {
        font-size: 0;
        padding: 8px 10px;
    }

    .chat__link-btn::before {
        content: '🔗';
        font-size: 17px;
    }

    /* «Прайс-лист» — тоже только иконка */
    .chat__pdf-btn {
        font-size: 0;
        padding: 8px 10px;
        background: transparent;
        margin-right: 4px;
    }

    .chat__pdf-btn::before {
        content: '📄';
        font-size: 17px;
    }

    .chat__pdf-btn:disabled::before {
        content: '⏳';
    }

    .chat__messages {
        padding: 12px;
    }

    .message {
        max-width: 92%;
    }

    /* Поле ввода — всё в одну строку: 📎 📦 [поле] ➤ */
    .chat__footer {
        flex-wrap: nowrap;
        align-items: flex-end;
        gap: 6px;
        padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)) 10px;
    }

    .footer-actions {
        flex: 0 0 auto;
        flex-direction: row;
        gap: 2px;
        padding-bottom: 0;
    }

    .footer-btn {
        width: 34px;
        height: 40px;
        font-size: 18px;
    }

    .input-wrapper {
        flex: 1 1 auto;
        min-width: 0;
        gap: 4px;
        padding: 2px 2px 2px 12px;
    }

    .chat__input {
        min-width: 0;
        overflow: hidden;   /* без внутренней полосы прокрутки */
    }

    .notifications-view {
        padding: 12px;
    }

    /* Шестерёнку заменяет нижнее меню: иконка в шапке скрыта,
       а список пунктов открывается над нижней панелью */
    .gear-wrapper {
        display: none;
    }

    .mobile-menu {
        display: block;
    }

    .mobile-menu__dropdown {
        position: fixed;
        right: 12px;
        bottom: calc(64px + env(safe-area-inset-bottom, 0px));
        z-index: 960;
        min-width: 210px;
        max-width: calc(100vw - 24px);
        padding: 6px;
        background: #ffffff;
        border-radius: 14px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
        border: 1px solid #eef0f4;
    }

    /* ---------- Модальные окна ---------- */
    .modal-card {
        width: calc(100% - 24px);
        max-width: 520px;
        padding: 18px;
        max-height: calc(100vh - 40px);
        overflow-y: auto;
    }

    .modal-footer {
        flex-wrap: wrap;
    }

    .modal-footer .btn-primary,
    .modal-footer .btn-secondary {
        flex: 1 1 auto;
        min-height: 42px;
    }

    /* ================= catalog.html ================= */
    body {
        padding: 0;
    }

    .page__header {
        padding: 12px 12px 0 12px;
        margin-bottom: 12px;
        gap: 8px;
    }

    .page__header h1 {
        font-size: 18px;
    }

    .total-badge {
        font-size: 11px;
        padding: 2px 8px;
    }

    /* «Назад в чат» не нужен — есть нижнее меню */
    .back-link {
        display: none;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 0 12px 12px 12px;
    }

    .search-box,
    .workplace-select,
    .price-filter {
        width: 100%;
        min-height: 42px;
    }

    .catalog {
        padding: 0 12px calc(70px + env(safe-area-inset-bottom, 0px)) 12px;
    }

    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 12px;
        width: 100%;
        max-width: 100%;
    }

    .catalog,
    #app {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .table-wrap table {
        font-size: 12px;
        min-width: 720px;
    }

    .table-wrap th,
    .table-wrap td {
        padding: 8px 6px;
        white-space: nowrap;
    }

    /* Пагинация: перенос строк, иначе она распирает страницу по ширине */
    .pagination,
    .files-pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
    }

    .page-btn {
        min-width: 34px;
        height: 34px;
        padding: 0 8px;
    }

    /* ================= files.html ================= */
    .files-page {
        padding: 12px 12px calc(72px + env(safe-area-inset-bottom, 0px)) 12px;
    }

    .files-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .files-select,
    .files-upload-btn {
        width: 100%;
        min-height: 44px;
    }

    .files-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .file-card__title {
        font-size: 14px;
        word-break: break-word;
    }

    .file-card__actions {
        flex-wrap: wrap;
    }

    .file-card__actions .file-card__download,
    .file-card__actions .file-card__share {
        min-height: 42px;
    }

    .files-pagination {
        padding-bottom: 8px;
    }

    /* ---------- Логин на телефоне ---------- */
    .login-card {
        width: calc(100% - 28px);
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .mobile-nav__item {
        font-size: 9px;
    }

    .mobile-nav__icon {
        font-size: 20px;
    }

    /* Меньше «воздуха» в списке запросов */
    .sidebar__header {
        padding: 12px 12px 8px 12px;
    }

    .thread-item {
        padding: 10px 12px;
    }

    .chat__link-btn {
        display: none;
    }

    .modal-footer {
        gap: 8px;
    }
}
