/* ============================================
   МОБИЛЬНАЯ АДАПТАЦИЯ ДЛЯ WEB-CRM
   Версия: 1.2 (ИСПРАВЛЕННАЯ)
   ============================================ */

@media screen and (max-width: 768px) {
    /* Глобальные стили */
    * {
        box-sizing: border-box;
    }

    body {
        font-size: 14px;
        overflow-x: hidden;
    }

    html, body {
        max-width: 100%;
        overflow-x: hidden;
    }

    /* ============================================
       КНОПКА БУРГЕР
       ============================================ */
    .mobile-menu-toggle {
        display: flex !important;
        position: fixed;
        top: 15px;
        left: 15px;
        z-index: 1001;
        width: 44px;
        height: 44px;
        background: rgba(255, 255, 255, 0.95);
        border-radius: 50%;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .mobile-menu-toggle:active {
        transform: scale(0.95);
    }

    .mobile-menu-toggle span {
        display: block;
        width: 24px;
        height: 2px;
        background: #333;
        position: relative;
        transition: all 0.3s ease;
    }

    .mobile-menu-toggle span::before,
    .mobile-menu-toggle span::after {
        content: '';
        position: absolute;
        width: 24px;
        height: 2px;
        background: #333;
        transition: all 0.3s ease;
    }

    .mobile-menu-toggle span::before {
        top: -8px;
    }

    .mobile-menu-toggle span::after {
        bottom: -8px;
    }

    .mobile-menu-toggle.active span {
        background: transparent;
    }

    .mobile-menu-toggle.active span::before {
        top: 0;
        transform: rotate(45deg);
    }

    .mobile-menu-toggle.active span::after {
        bottom: 0;
        transform: rotate(-45deg);
    }

    /* ============================================
       ОВЕРЛЕЙ
       ============================================ */
    .mobile-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .mobile-overlay.active {
        display: block;
        opacity: 1;
    }

    /* ============================================
       САЙДБАР (ASIDE)
       ============================================ */
    aside.mobile-sidebar {
        position: fixed !important;
        top: 0 !important;
        left: -100% !important;
        width: 280px !important;
        height: 100vh !important;
        z-index: 1000 !important;
        transition: left 0.3s ease !important;
        overflow-y: auto !important;
        background: #f9f9f9 !important;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1) !important;
    }

    aside.mobile-sidebar.active {
        left: 0 !important;
    }

    /* Отступ для логотипа */
    aside.mobile-sidebar > div:first-child {
        padding-top: 70px !important;
    }

    /* Увеличиваем пункты меню для тапа */
    aside.mobile-sidebar .menu-item {
        min-height: 44px !important;
        padding: 12px 16px !important;
        font-size: 15px !important;
    }

    /* ============================================
       ОСНОВНОЙ КОНТЕНТ
       ============================================ */
    main, .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding: 70px 12px 20px !important;
    }

    /* Заголовки страниц */
    .page-header, h1, h2 {
        font-size: 20px !important;
        margin-bottom: 16px !important;
    }

    /* ============================================
       КАЛЕНДАРЬ — МЕСЯЧНЫЙ ВИД
       ============================================ */
    .calendar-container {
        padding: 0 !important;
    }

    .month-navigation {
        flex-wrap: wrap !important;
        gap: 8px !important;
        justify-content: center !important;
        margin-bottom: 12px !important;
    }

    .month-tabs {
        display: flex !important;
        overflow-x: auto !important;
        gap: 6px !important;
        padding: 8px 0 !important;
        scrollbar-width: none !important;
    }

    .month-tabs::-webkit-scrollbar {
        display: none !important;
    }

    .month-tab {
        flex-shrink: 0 !important;
        padding: 8px 14px !important;
        font-size: 13px !important;
    }

    .view-switcher {
        width: 100% !important;
        justify-content: center !important;
        margin-bottom: 12px !important;
    }

    .view-btn {
        flex: 1 !important;
        padding: 10px !important;
        font-size: 13px !important;
    }

    /* ============================================
       ✅ КАЛЕНДАРЬ — ДНЕВНОЙ/НЕДЕЛЬНЫЙ ВИД
       БЕЗОПАСНАЯ АДАПТАЦИЯ (не ломает раскладку)
       ============================================ */

    /* Горизонтальный скролл для контейнера календаря */
    .calendar-scroll-area {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Уменьшаем шрифты и отступы — НЕ трогаем width/grid */
    .date-text,
    .day-header {
        font-size: 11px !important;
        line-height: 1.2 !important;
    }

    .calendar-event,
    .task-block,
    .event-block {
        font-size: 10px !important;
        padding: 2px 4px !important;
        margin-bottom: 1px !important;
        border-radius: 3px !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        min-height: 20px !important;
        line-height: 1.2 !important;
    }

    .task-block .task-time,
    .event-block .event-time {
        font-size: 9px !important;
    }

    .task-block .task-title,
    .event-block .event-title {
        font-size: 10px !important;
    }

    /* Скрываем аватары событий — экономят место */
    .task-block .task-avatar,
    .event-block .event-avatar {
        display: none !important;
    }

    /* Скрываем иконку редактирования — слишком мелко */
    .task-edit-icon {
        display: none !important;
    }

    /* Resize-ручка чуть больше для удобства */
    .resize-handle {
        height: 10px !important;
    }

    /* ============================================
       КАРТОЧКИ
       ============================================ */
    .clients-grid, .projects-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .client-card, .project-card, .task-card {
        padding: 16px !important;
        border-radius: 12px !important;
    }

    /* ============================================
       МОДАЛЬНЫЕ ОКНА
       ============================================ */
    .modal {
        padding: 0 !important;
        align-items: flex-end !important;
    }

    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 90vh !important;
        border-radius: 12px 12px 0 0 !important;
        margin: 0 !important;
        overflow-y: auto !important;
    }

    .modal-header {
        padding: 16px !important;
        position: sticky !important;
        top: 0 !important;
        background: #fff !important;
        z-index: 10 !important;
        border-bottom: 1px solid #e5e7eb !important;
    }

    .modal-body {
        padding: 16px !important;
    }

    .modal-footer {
        padding: 16px !important;
        position: sticky !important;
        bottom: 0 !important;
        background: #fff !important;
        border-top: 1px solid #e5e7eb !important;
        flex-direction: column !important;
        gap: 8px !important;
    }

    .modal-footer button {
        width: 100% !important;
        min-height: 44px !important;
    }

    /* ============================================
       ФОРМЫ
       ============================================ */
    .form-group {
        margin-bottom: 16px !important;
    }

    .form-label {
        font-size: 13px !important;
        margin-bottom: 6px !important;
    }

    .form-input, .form-select, .form-textarea, input, select, textarea {
        width: 100% !important;
        padding: 12px !important;
        font-size: 15px !important;
        border-radius: 8px !important;
        min-height: 44px !important;
    }

    /* ============================================
       КНОПКИ
       ============================================ */
    button, .btn {
        min-height: 44px !important;
        padding: 12px 20px !important;
        font-size: 14px !important;
        border-radius: 8px !important;
    }

    /* ============================================
       СКРОЛЛБАРЫ
       ============================================ */
    ::-webkit-scrollbar {
        width: 6px;
        height: 6px;
    }

    ::-webkit-scrollbar-track {
        background: transparent;
    }

    ::-webkit-scrollbar-thumb {
        background: rgba(0, 0, 0, 0.2);
        border-radius: 3px;
    }
}

/* Очень маленькие экраны */
@media screen and (max-width: 360px) {
    .calendar-event,
    .task-block,
    .event-block {
        font-size: 9px !important;
        padding: 1px 3px !important;
        min-height: 18px !important;
    }

    button, .btn {
        font-size: 13px !important;
        padding: 10px 16px !important;
    }
}