/* ============================================================
   mobile.css — универсальная адаптация всех страниц под смартфоны
   Подключается на каждой странице ПОСЛЕ основных стилей.
   ============================================================ */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

@media (max-width: 820px) {
    html, body {
        overflow-x: hidden !important;
    }

    /* Отключаем задержку тапа и двойной зум на интерактивных элементах */
    a, button, .menu-trigger, .tab-btn, .l-tab, .day, .slot, .master-opt,
    .chat-item, .ticket-item, .request-item, .service-card, .file-btn,
    .file-label, .btn-act, .btn-logout, .send-btn, .close-x, .close-modal,
    .complete-btn, .review-btn, .load-more-btn {
        touch-action: manipulation;
    }

    /* Поля ввода: 16px, чтобы iOS не зумил страницу при фокусе */
    input, select, textarea {
        font-size: 16px !important;
        padding: 10px !important;
    }
    input[type="checkbox"], input[type="radio"] {
        width: auto;
        min-width: 20px;
        min-height: 20px;
    }

    /* --- Основные контейнеры-«карточки» --- */
    .admin-card, .messenger-card, .chat-card, .chat-container, .ticket-card,
    .d-card, .profile-card, .block-card, .order-card, .workshop-card,
    .c-card, .l-card, .box, .form-l {
        width: 94vw !important;
        max-width: 94vw !important;
        border-width: 5px !important;
        border-radius: 22px !important;
        padding: 14px !important;
        box-sizing: border-box !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }

    /* Кабинеты и чаты — высота по экрану */
    .admin-card, .messenger-card, .chat-card, .chat-container,
    .ticket-card, .d-card, .l-card, .c-card {
        height: 86vh !important;
        min-height: 86vh;
    }

    /* Простые карточки — по содержимому */
    .profile-card, .order-card, .workshop-card, .box, .form-l, .block-card {
        height: auto !important;
        min-height: 0 !important;
        margin-top: 14px !important;
        margin-bottom: 14px !important;
    }

    /* Страницы авторизации: высокую форму нельзя обрезать сверху — скролл */
    body:has(.form-l), body:has(.box) {
        align-items: flex-start !important;
        overflow-y: auto;
        padding: 24px 0;
    }
    .general { padding: 8px 0; }
    .form-l, .box { padding: 24px 18px !important; }
    .form-title { font-size: 20px !important; }
    .checkbox-group { font-size: 12px; align-items: flex-start; }
    .checkbox-group input { margin-top: 2px; }

    /* Прокручиваемые области внутри карточек */
    .scroll-area, .l-scroll, .c-scroll, .msg-area, .content-wrap, .messages-area {
        padding: 12px !important;
        -webkit-overflow-scrolling: touch;
    }
    .scroll-area, .l-scroll, .c-scroll, .msg-area, .messages-area {
        flex: 1 1 auto;
        min-height: 0;
    }

    /* --- Заголовки --- */
    h1 { font-size: 24px !important; }
    h2 { font-size: 15px !important; letter-spacing: 0.5px !important; margin-bottom: 10px !important; }
    h3 { font-size: 16px !important; }

    /* --- Кнопки: удобный размер под палец --- */
    .btn, .btn-main, .btn-outline, .btn-red, .btn-green {
        min-height: 42px;
        padding: 10px 12px !important;
        font-size: 12px !important;
    }

    /* --- Вкладки (админка, директор, обучение) --- */
    .admin-tabs, .tabs, .l-tabs {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        flex-wrap: nowrap !important;
    }
    .admin-tabs::-webkit-scrollbar, .tabs::-webkit-scrollbar, .l-tabs::-webkit-scrollbar { display: none; }
    .tab-btn, .l-tab {
        flex: 0 0 auto !important;
        min-width: 76px !important;
        padding: 12px 10px !important;
        font-size: 10px !important;
        white-space: nowrap;
    }

    /* --- Списки и строки --- */
    .admin-item, .ticket-item, .chat-item, .order-item, .course-item,
    .l-item, .card-row, .user-row, .request-item {
        padding: 10px 12px !important;
    }
    .admin-item, .request-header, .header-stats, .chat-top {
        flex-wrap: wrap;
        gap: 6px;
    }
    .admin-item span { font-size: 12px !important; }

    /* --- Заявки мастера (orders.php) --- */
    .request-item { padding: 14px !important; border-radius: 16px; }
    .request-info { font-size: 12px; }
    .request-text { font-size: 13px; }

    /* --- Статистика --- */
    .stats-grid { gap: 8px !important; }
    .stat-box { flex: 1 1 42% !important; min-width: 42% !important; padding: 12px !important; }
    .stat-val { font-size: 17px !important; }

    /* --- Модалки --- */
    .modal-overlay { padding: 12px 6px !important; align-items: flex-start !important; }
    .modal-card {
        max-width: 96vw !important;
        padding: 16px !important;
        border-width: 4px !important;
        border-radius: 18px !important;
        max-height: 92vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .modal-actions { flex-wrap: wrap; }
    .close-x { top: 6px; right: 10px; }

    /* --- Сообщения и медиа --- */
    .msg { max-width: 90% !important; font-size: 14px !important; padding: 10px 12px !important; }
    .msg-media, .msg img, .msg video { max-width: 100% !important; height: auto !important; }
    video { max-width: 100% !important; height: auto; }
    .msg-time { font-size: 10px !important; }

    /* --- Шапка чата --- */
    .chat-header, .chat-head, .c-head { padding: 10px 12px !important; flex-wrap: wrap; }
    .header-name { font-size: 14px !important; }
    .header-avatar { width: 42px !important; height: 42px !important; }
    .order-bar { padding: 8px 12px; font-size: 11px; }

    /* --- Панель ввода в чатах --- */
    .input-panel, .input-bar { padding: 10px 10px; gap: 6px; }
    .input-panel input[type="text"], .input-bar input { min-width: 0; }
    .send-btn { width: 42px; height: 42px; font-size: 16px; }
    .file-btn { font-size: 20px; }
    .complete-btn, .review-btn, .load-more-btn { min-height: 42px; }

    /* --- Профиль --- */
    .avatar-box { width: 84px; height: 84px; }
    .cards-list { padding: 8px; }
    .card-row { font-size: 12px; padding: 8px; }

    /* --- Мастера --- */
    .master-avatar { width: 54px; height: 54px; }
    .chat-item { gap: 10px; }
    .price-tag { font-size: 11px; padding: 3px 8px; }
    .reviews-card { padding: 14px; max-width: 96vw; }
    .card-actions { gap: 6px; }
    .reviews-overlay { padding: 12px; }

    /* --- Выбор мастера: горизонтальная лента без скроллбара --- */
    .master-picker {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .master-picker::-webkit-scrollbar { display: none; }

    /* --- Заказ / бесплатный ответ --- */
    .time-slots { grid-template-columns: repeat(3, 1fr); }
    .custom-calendar { padding: 8px; }
    .master-opt .mo-price { font-size: 11px; padding: 3px 7px; }

    /* --- Мастерская --- */
    .workshop-container { padding: 12px; }
    .list-box { padding: 8px; }

    /* --- Доступ заблокирован --- */
    .block-card { padding: 28px 20px; }
    .lock-icon { font-size: 56px; }
    .btn-logout { min-height: 44px; padding: 12px 28px; }

    /* --- Длинный контент: переносы --- */
    .lesson-content, .page-content, .request-text, .order-question, .q-display,
    .course-desc, .ticket-item .meta, .rev-full .rev-text, .lesson-title {
        word-break: break-word;
        overflow-wrap: anywhere;
    }
    pre, code { white-space: pre-wrap; word-break: break-word; }

    /* --- Меню-триггер: не под вырез экрана --- */
    .menu-trigger {
        top: calc(10px + env(safe-area-inset-top, 0px));
        left: env(safe-area-inset-left, 0px);
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    /* --- Поле поиска --- */
    .search-box { font-size: 16px !important; }

    /* --- Лендинг (index.php) --- */
    .header .container { flex-wrap: wrap; gap: 8px; flex-direction: column; align-items: center; }
    .nav { flex-wrap: wrap; gap: 6px !important; justify-content: center; }
    .nav a { margin-left: 0 !important; margin: 4px 8px; }
    .hero { padding: 2.2rem 0 !important; margin: 12px 8px !important; }
    .hero h2 { font-size: 22px !important; }
    .hero p { font-size: 0.92rem; }
    .services h3 { font-size: 1.25rem; letter-spacing: 3px; }
    .service-card { padding: 1.2rem; }
    .carts { flex-direction: column; align-items: center; float: none; width: 100%; }
    .img { width: min(58vw, 260px); height: min(58vw, 260px); object-fit: cover; margin: 8px auto; }
    .cart_ad { margin-top: 0 !important; }
    .footer { padding: 1.2rem 0; }
}

@media (max-width: 380px) {
    .tab-btn, .l-tab { min-width: 62px !important; font-size: 9px !important; padding: 10px 6px !important; }
    .msg { max-width: 94% !important; }
    .chat-avatar { width: 44px !important; height: 44px !important; }
    .stat-box { flex: 1 1 100% !important; min-width: 100% !important; }
    .file-section, .file-upload-group { flex-direction: column; }
    .form-title { font-size: 18px !important; }
    .service-card { padding: 1rem; }
}
