/* ============================================
   WAY MOBILE-FIRST DESIGN SYSTEM
   Философия: Mobile-First — сначала мобильные
   Requirements: 1.1, 1.2, 8.1, 8.2, 8.3, 8.4
   ============================================ */

/* ============================================
   БАЗОВЫЕ МОБИЛЬНЫЕ СТИЛИ (Mobile-First)
   ============================================ */

/* Контейнеры */
.container-fluid {
    padding: 12px;
}

/* Навигация */
.navbar {
    padding: 10px 0;
}

.navbar-brand {
    font-size: 1rem;
}

.navbar-nav {
    margin-top: 10px;
}

.nav-link {
    padding: 8px 12px !important;
}

/* ============================================
   БОЛЬШИЕ КНОПКИ ДЛЯ ПАЛЬЦЕВ
   Requirements: 1.1 (min 48px touch targets)
   ============================================ */

.btn,
.btn-modern,
.way-btn {
    min-height: 48px;
    min-width: 48px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-touch {
    min-height: 48px;
    min-width: 48px;
    font-size: 16px;
    padding: 12px 16px;
}

/* Формы — предотвращаем зум на iOS */
input,
select,
textarea,
.form-control,
.form-select,
.form-modern-input,
.form-modern-select {
    min-height: 48px;
    font-size: 16px !important; /* Предотвращает зум на iOS */
    touch-action: manipulation;
}

/* ============================================
   ПЛАВАЮЩАЯ КНОПКА ЧАТА (FAB)
   Requirements: 3.4
   ============================================ */

.chat-fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--way-accent, #3498db);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    border: none;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.chat-fab:active {
    transform: scale(0.95);
}

.chat-fab i {
    font-size: 1.5rem;
}

/* FAB кнопка общая */
.fab-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.fab-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

.fab-button:active {
    transform: scale(0.95);
}

/* ============================================
   АДАПТИВНЫЕ ТАБЛИЦЫ С ГОРИЗОНТАЛЬНЫМ СКРОЛЛОМ
   Requirements: 8.1, 8.2, 8.3, 8.4
   ============================================ */

.table-responsive-way {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 0 12px;
}

/* Индикатор скролла */
.table-responsive-way::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 20px;
    background: linear-gradient(to right, transparent, rgba(0, 0, 0, 0.1));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.table-responsive-way.has-scroll::after {
    opacity: 1;
}

/* Таблица на мобильных */
.table-to-cards {
    display: table;
    width: 100%;
}

/* ============================================
   КАРТОЧКИ ВМЕСТО ТАБЛИЦ НА МОБИЛЬНЫХ
   Requirements: 1.2
   ============================================ */

.cards-view {
    display: none;
}

/* Карточка лида */
.lead-card {
    background: var(--way-bg-primary, #ffffff);
    border: 1px solid var(--way-border, #dfe6e9);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.lead-card:active {
    transform: scale(0.98);
}

.lead-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.lead-card-name {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--way-text-primary, #2c3e50);
    margin: 0;
}

.lead-card-status {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.lead-card-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--way-text-secondary, #7f8c8d);
}

.lead-card-info-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.lead-card-info-item i {
    width: 16px;
    color: var(--way-muted, #95a5a6);
}

.lead-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--way-border, #dfe6e9);
}

.lead-card-actions .btn {
    flex: 1;
    min-height: 44px;
}

/* Карточка этапа */
.stage-card {
    background: var(--way-bg-primary, #ffffff);
    border: 1px solid var(--way-border, #dfe6e9);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stage-card:active {
    transform: scale(0.98);
}

.stage-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.stage-card-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--way-text-primary, #2c3e50);
    margin: 0;
}

.stage-card-type {
    font-size: 1.2rem;
}

.stage-card-progress {
    margin-bottom: 12px;
}

.stage-card-progress-bar {
    height: 6px;
    background: var(--way-bg-tertiary, #ecf0f1);
    border-radius: 3px;
    overflow: hidden;
}

.stage-card-progress-fill {
    height: 100%;
    background: var(--way-accent, #3498db);
    transition: width 0.3s ease;
}

.stage-card-dates {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--way-text-secondary, #7f8c8d);
}

/* Карточка рабочего */
.worker-card {
    background: var(--way-bg-primary, #ffffff);
    border: 1px solid var(--way-border, #dfe6e9);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: transform 0.2s ease;
}

.worker-card:active {
    transform: scale(0.98);
}

.worker-card-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--way-accent, #3498db);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
    flex-shrink: 0;
}

.worker-card-info {
    flex: 1;
    min-width: 0;
}

.worker-card-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--way-text-primary, #2c3e50);
    margin: 0 0 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.worker-card-role {
    font-size: 0.85rem;
    color: var(--way-text-secondary, #7f8c8d);
}

.worker-card-status {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* ============================================
   СВАЙП-ЖЕСТЫ
   Requirements: 1.3, 1.4
   ============================================ */

.swipeable {
    touch-action: pan-y;
    user-select: none;
    position: relative;
    overflow: hidden;
}

.swipeable-content {
    transition: transform 0.3s ease;
}

.swipeable-actions {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
}

.swipeable-actions-left {
    left: 0;
    transform: translateX(-100%);
}

.swipeable-actions-right {
    right: 0;
    transform: translateX(100%);
}

.swipeable-action {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 20px;
    color: white;
    font-weight: 600;
}

.swipeable-action-success {
    background: var(--way-success, #27ae60);
}

.swipeable-action-danger {
    background: var(--way-danger, #e74c3c);
}

.swipeable-action-warning {
    background: var(--way-warning, #f39c12);
}

/* Индикатор долгого нажатия */
.long-press-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(52, 152, 219, 0.2);
    pointer-events: none;
    transition: transform 0.3s ease;
}

.long-press-active .long-press-indicator {
    transform: translate(-50%, -50%) scale(1);
}

/* ============================================
   МОБИЛЬНЫЕ МЕДИА-ЗАПРОСЫ
   ============================================ */

@media (max-width: 767px) {
    /* Общие стили */
    .container-fluid {
        padding: 10px;
    }
    
    /* Дашборд */
    .dashboard-header h1 {
        font-size: 1.5rem;
    }
    
    .stat-card {
        margin-bottom: 15px;
    }
    
    .stat-value {
        font-size: 1.8rem;
    }
    
    /* Карточки */
    .card,
    .modern-card {
        margin-bottom: 15px;
    }
    
    .card-header,
    .modern-card-header {
        padding: 15px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .card-body,
    .modern-card-body {
        padding: 15px;
    }
    
    /* Кнопки */
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
    
    .btn-sm {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
        min-height: 40px;
    }
    
    /* Таблицы → Карточки */
    .table-to-cards {
        display: none !important;
    }
    
    .cards-view {
        display: block !important;
    }
    
    /* Адаптивные таблицы */
    .table-responsive {
        font-size: 0.85rem;
        margin: 0 -15px;
        padding: 0 15px;
    }
    
    /* Скрываем второстепенные колонки */
    .table .d-none-mobile,
    .table .hide-mobile {
        display: none !important;
    }
    
    /* Модальные окна */
    .modal-dialog {
        margin: 10px;
    }
    
    .modal-content {
        border-radius: 12px;
    }
    
    /* Прогресс-бары */
    .progress {
        height: 8px;
    }
    
    /* Скрываем боковую панель */
    .sidebar,
    .object-sidebar {
        display: none;
    }
    
    /* Мобильное меню */
    .mobile-menu {
        display: flex;
    }
    
    /* Сетка объекта */
    .object-detail-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* CRM фильтры */
    .crm-filters-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Рабочие */
    .workers-main-grid {
        display: block !important;
    }
    
    .workers-filters {
        display: none;
    }
    
    .workers-stats-grid {
        display: block !important;
    }
    
    .workers-stats-grid > div {
        margin-bottom: 1rem;
    }
    
    /* Скрываем текст в кнопках */
    #addWorkerBtn span,
    #refreshWorkersBtn span {
        display: none;
    }
    
    /* Компактные аватары */
    .avatar {
        width: 32px;
        height: 32px;
        font-size: 0.75rem;
    }
    
    /* Пагинация */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .page-link {
        padding: 8px 12px;
        font-size: 0.85rem;
    }
    
    /* Навигация */
    .navbar-collapse {
        background: var(--bg-secondary, #1a1a1a);
        border-top: 1px solid var(--border-color, #333);
        margin-top: 10px;
        padding: 10px;
        border-radius: 8px;
    }
    
    .navbar-nav {
        flex-direction: column;
    }
    
    .nav-item {
        width: 100%;
    }
    
    .nav-link {
        width: 100%;
        padding: 12px !important;
        border-radius: 4px;
    }
}

/* ============================================
   ПЛАНШЕТЫ (768px - 1024px)
   ============================================ */

@media (min-width: 768px) and (max-width: 1024px) {
    /* Показываем таблицы */
    .table-to-cards {
        display: table !important;
    }
    
    .cards-view {
        display: none !important;
    }
    
    /* Адаптивные таблицы */
    .table-responsive-way {
        overflow-x: auto;
    }
    
    /* Скрываем некоторые колонки */
    .table .d-none-tablet {
        display: none !important;
    }
    
    /* Сетка рабочих */
    .workers-main-grid {
        grid-template-columns: 1fr !important;
    }
    
    .workers-filters {
        display: none;
    }
    
    /* Чат сайдбар */
    .chat-sidebar {
        width: 300px;
    }
    
    .stat-value {
        font-size: 2rem;
    }
}

/* ============================================
   ДЕСКТОП (1024px+)
   ============================================ */

@media (min-width: 1025px) {
    /* Показываем таблицы */
    .table-to-cards {
        display: table !important;
    }
    
    .cards-view {
        display: none !important;
    }
    
    /* Скрываем FAB */
    .fab-button,
    .chat-fab {
        display: none !important;
    }
    
    /* Сетка рабочих */
    .workers-main-grid {
        display: grid;
        grid-template-columns: 280px 1fr;
    }
    
    /* Показываем фильтры */
    .workers-filters {
        display: block;
    }
}

/* ============================================
   ИНТЕРФЕЙС РАБОЧЕГО (МОБИЛЬНЫЙ ПРИОРИТЕТ)
   ============================================ */

.mobile-dashboard {
    padding: 15px;
}

.today-tasks {
    margin-bottom: 20px;
}

.today-tasks h3 {
    font-size: 1.3rem;
    margin-bottom: 15px;
    color: var(--text-primary, #fff);
}

.task-card {
    background: var(--bg-card, #1a1a1a);
    border: 1px solid var(--border-color, #333);
    border-radius: 12px;
    padding: 15px;
    margin-bottom: 15px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.task-card:active {
    transform: scale(0.98);
}

.task-card h4 {
    font-size: 1.1rem;
    margin: 10px 0;
    color: var(--text-primary, #fff);
}

.task-card p {
    font-size: 0.9rem;
    color: var(--text-secondary, #888);
    margin: 5px 0;
}

.task-status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.task-status.in-progress {
    background: rgba(0, 212, 255, 0.2);
    color: var(--accent-blue, #00d4ff);
    border: 1px solid var(--accent-blue, #00d4ff);
}

.task-status.completed {
    background: rgba(0, 255, 136, 0.2);
    color: var(--accent-green, #00ff88);
    border: 1px solid var(--accent-green, #00ff88);
}

.task-status.pending {
    background: rgba(136, 136, 136, 0.2);
    color: var(--text-muted, #888);
    border: 1px solid var(--text-muted, #888);
}

/* Кнопка отчёта */
.btn-report {
    width: 100%;
    margin-top: 15px;
    padding: 12px;
    background: var(--accent-blue, #00d4ff);
    color: var(--bg-primary, #0a0a0a);
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    min-height: 48px;
}

.btn-report:hover {
    background: #00b8e6;
    transform: translateY(-1px);
}

.btn-report:active {
    transform: translateY(0);
}

/* Форма отчета */
.report-form {
    background: var(--bg-card, #1a1a1a);
    border: 1px solid var(--border-color, #333);
    border-radius: 12px;
    padding: 20px;
    margin-top: 20px;
}

.report-form.hidden {
    display: none;
}

.report-form textarea {
    width: 100%;
    min-height: 120px;
    padding: 12px;
    background: var(--bg-tertiary, #2a2a2a);
    border: 1px solid var(--border-color, #333);
    border-radius: 8px;
    color: var(--text-primary, #fff);
    font-size: 16px;
    font-family: inherit;
    resize: vertical;
    margin-bottom: 15px;
}

.report-form textarea:focus {
    outline: none;
    border-color: var(--accent-blue, #00d4ff);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.2);
}

.report-form input[type="file"] {
    width: 100%;
    padding: 10px;
    background: var(--bg-tertiary, #2a2a2a);
    border: 1px solid var(--border-color, #333);
    border-radius: 8px;
    color: var(--text-primary, #fff);
    margin-bottom: 15px;
}

.btn-submit {
    width: 100%;
    padding: 12px;
    background: var(--accent-green, #00ff88);
    color: var(--bg-primary, #0a0a0a);
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
    min-height: 48px;
}

.btn-submit:hover {
    background: #00e677;
    transform: translateY(-1px);
}

.btn-submit:active {
    transform: translateY(0);
}

/* ============================================
   МОБИЛЬНОЕ МЕНЮ (НИЖНЯЯ НАВИГАЦИЯ)
   ============================================ */

.mobile-menu {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary, #1a1a1a);
    border-top: 1px solid var(--border-color, #333);
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 1000;
}

.mobile-menu-items {
    display: flex;
    justify-content: space-around;
}

.mobile-menu-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    color: var(--text-secondary, #888);
    text-decoration: none;
    font-size: 0.7rem;
    transition: color 0.2s ease;
}

.mobile-menu-item.active {
    color: var(--accent-blue, #00d4ff);
}

.mobile-menu-item i {
    font-size: 1.3rem;
}

/* ============================================
   МОДАЛЬНЫЕ ОКНА НА МОБИЛЬНЫХ
   ============================================ */

@media (max-width: 575px) {
    .modal-fullscreen-sm-down {
        width: 100vw;
        max-width: none;
        height: 100%;
        margin: 0;
    }
    
    .modal-fullscreen-sm-down .modal-content {
        height: 100%;
        border: 0;
        border-radius: 0;
    }
    
    .modal-fullscreen-sm-down .modal-body {
        overflow-y: auto;
    }
    
    /* Улучшенные формы */
    .modal-body .form-control,
    .modal-body .form-select {
        font-size: 16px;
        padding: 0.75rem;
    }
    
    .modal-footer .btn {
        flex: 1;
        padding: 0.75rem;
    }
}

/* ============================================
   АВАТАРЫ
   ============================================ */

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.avatar-sm {
    width: 32px;
    height: 32px;
    font-size: 0.7rem;
}

.avatar-lg {
    width: 48px;
    height: 48px;
    font-size: 1rem;
}

/* ============================================
   УТИЛИТЫ ДЛЯ АДАПТИВНОСТИ
   ============================================ */

/* Скрытие на разных размерах */
@media (max-width: 767px) {
    .hide-mobile { display: none !important; }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .hide-tablet { display: none !important; }
}

@media (min-width: 1025px) {
    .hide-desktop { display: none !important; }
}

/* Показ только на определённых размерах */
.show-mobile { display: none !important; }
.show-tablet { display: none !important; }
.show-desktop { display: none !important; }

@media (max-width: 767px) {
    .show-mobile { display: block !important; }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .show-tablet { display: block !important; }
}

@media (min-width: 1025px) {
    .show-desktop { display: block !important; }
}

/* ============================================
   ЛЕНИВАЯ ЗАГРУЗКА ИЗОБРАЖЕНИЙ
   Requirements: 1.5
   ============================================ */

.lazy-image {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.lazy-image.loaded {
    opacity: 1;
}

.lazy-image-placeholder {
    background: var(--way-bg-tertiary, #ecf0f1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--way-text-muted, #bdc3c7);
}

/* ============================================
   КЭШИРОВАННЫЕ ДАННЫЕ (OFFLINE)
   Requirements: 1.6
   ============================================ */

.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--way-warning, #f39c12);
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 0.85rem;
    z-index: 9999;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.offline-indicator.visible {
    transform: translateY(0);
}

.cached-data-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(243, 156, 18, 0.2);
    color: var(--way-warning, #f39c12);
    border-radius: 4px;
    font-size: 0.75rem;
}

/* ============================================
   МОБИЛЬНАЯ ОПТИМИЗАЦИЯ - ДАШБОРД
   ============================================ */

@media (max-width: 767px) {
    /* Сетка 4 колонки → 2 колонки на мобильных */
    .grid-modern-4 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: var(--space-3, 12px) !important;
    }
    
    /* Сетка 2 колонки → 1 колонка на мобильных */
    .grid-modern[style*="grid-template-columns: 1fr 1fr"],
    .grid-modern[style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Компактные карточки статистики */
    .modern-card {
        padding: var(--space-3, 12px);
    }
    
    /* Меньшие иконки в карточках */
    .modern-card [style*="width: 48px"][style*="height: 48px"] {
        width: 40px !important;
        height: 40px !important;
    }
    
    .modern-card [style*="width: 56px"][style*="height: 56px"] {
        width: 44px !important;
        height: 44px !important;
    }
    
    /* Меньший размер шрифта для значений */
    .modern-card [style*="font-size: var(--font-size-2xl)"] {
        font-size: var(--font-size-xl, 1.25rem) !important;
    }
    
    .modern-card [style*="font-size: var(--font-size-3xl)"] {
        font-size: var(--font-size-2xl, 1.5rem) !important;
    }
    
    /* Заголовки страниц */
    h1[style*="font-size: var(--font-size-3xl)"],
    h1[style*="font-size: var(--font-size-4xl)"] {
        font-size: var(--font-size-2xl, 1.5rem) !important;
    }
    
    /* Быстрые действия — 2x2 сетка */
    .quick-action-btn {
        padding: var(--space-3, 12px) !important;
    }
    
    .quick-action-btn i {
        font-size: 1.25rem !important;
    }
    
    /* Прогресс-бар бонуса */
    #bonusProgressCard .modern-card-body > div:first-child {
        flex-direction: column;
        gap: var(--space-3);
        text-align: center;
    }
    
    #bonusProgressCard [style*="text-align: right"] {
        text-align: center !important;
    }
}

/* Очень маленькие экраны (< 375px) */
@media (max-width: 374px) {
    .grid-modern-4 {
        grid-template-columns: 1fr !important;
    }
    
    .modern-card [style*="font-size: var(--font-size-2xl)"] {
        font-size: var(--font-size-lg, 1.125rem) !important;
    }
}

/* ============================================
   МОБИЛЬНАЯ НАВИГАЦИЯ - НИЖНЕЕ МЕНЮ
   ============================================ */

.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary, #141414);
    border-top: 1px solid var(--border-color, #2a2a2a);
    padding: 8px 0;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 1050;
}

.mobile-bottom-nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
    max-width: 500px;
    margin: 0 auto;
}

.mobile-bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    color: var(--text-secondary, #b0b0b0);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    transition: color 0.2s ease;
    min-width: 60px;
}

.mobile-bottom-nav-item i {
    font-size: 1.25rem;
}

.mobile-bottom-nav-item.active {
    color: var(--accent-blue, #00d4ff);
}

.mobile-bottom-nav-item:active {
    transform: scale(0.95);
}

@media (max-width: 767px) {
    /* Нижнее меню убрано — используем только верхний бургер */
    .mobile-bottom-nav {
        display: none !important;
    }
    
    /* Убираем лишние отступы снизу */
    body {
        padding-bottom: 0;
    }
    
    main.page-container {
        padding-bottom: var(--space-8, 32px) !important;
    }
}

/* ============================================
   МОБИЛЬНЫЕ МОДАЛЬНЫЕ ОКНА
   ============================================ */

@media (max-width: 575px) {
    .modal-dialog {
        margin: 0;
        max-width: 100%;
        min-height: 100vh;
    }
    
    .modal-content {
        border-radius: 0 !important;
        min-height: 100vh;
        border: none !important;
    }
    
    .modal-header {
        position: sticky;
        top: 0;
        z-index: 10;
        background: var(--color-bg-elevated, #1e1e1e);
    }
    
    .modal-footer {
        position: sticky;
        bottom: 0;
        z-index: 10;
        background: var(--color-bg-elevated, #1e1e1e);
        padding-bottom: calc(var(--space-6, 24px) + env(safe-area-inset-bottom)) !important;
    }
    
    .modal-footer .btn-modern {
        flex: 1;
        min-height: 48px;
    }
}

/* ============================================
   МОБИЛЬНЫЕ ТАБЛИЦЫ И СПИСКИ
   ============================================ */

@media (max-width: 767px) {
    /* Горизонтальный скролл для таблиц */
    .table-responsive {
        margin: 0 -12px;
        padding: 0 12px;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Компактные ячейки */
    .table td, .table th {
        padding: 10px 8px;
        font-size: 0.85rem;
    }
    
    /* Скрываем второстепенные колонки */
    .table .hide-mobile,
    .table .d-none-mobile {
        display: none !important;
    }
}

/* ============================================
   МОБИЛЬНЫЕ ФОРМЫ
   ============================================ */

@media (max-width: 767px) {
    .form-modern-group {
        margin-bottom: var(--space-4, 16px);
    }
    
    .form-modern-input,
    .form-modern-select,
    .form-modern-textarea {
        font-size: 16px !important; /* Предотвращает зум на iOS */
        padding: 14px 16px;
        min-height: 50px;
    }
    
    .form-modern-label {
        font-size: 0.9rem;
        margin-bottom: 6px;
    }
    
    /* Сетка форм в 1 колонку */
    .form-modern .grid-modern,
    .modal-body .grid-modern {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================
   МОБИЛЬНЫЕ КНОПКИ
   ============================================ */

@media (max-width: 767px) {
    .btn-modern {
        min-height: 48px;
        padding: 12px 20px;
        font-size: 0.95rem;
    }
    
    .btn-modern-sm {
        min-height: 40px;
        padding: 8px 16px;
    }
    
    /* Кнопки в ряд — полная ширина */
    .btn-group-mobile {
        display: flex;
        flex-direction: column;
        gap: var(--space-2, 8px);
    }
    
    .btn-group-mobile .btn-modern {
        width: 100%;
    }
}

/* ============================================
   МОБИЛЬНЫЕ КАРТОЧКИ CRM
   ============================================ */

@media (max-width: 767px) {
    /* Сетка лидов — 1 колонка */
    #leadsList {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }
    
    /* Компактные карточки лидов */
    .crm-task-card {
        padding: 12px;
    }
    
    .crm-task-card-title {
        font-size: 0.9rem;
    }
    
    /* Фильтры CRM */
    .crm-filters-grid {
        grid-template-columns: 1fr !important;
        gap: var(--space-3, 12px) !important;
    }
    
    /* Вкладки CRM */
    #leads-tab, #crm-tasks-tab {
        font-size: 0.9rem;
        padding: var(--space-2, 8px) var(--space-3, 12px) !important;
    }
}

/* ============================================
   МОБИЛЬНЫЕ ФИНАНСЫ
   ============================================ */

@media (max-width: 767px) {
    /* Статистика финансов */
    #financeStats {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* График и детали — вертикально */
    .modern-card-body > div[style*="display: flex"][style*="gap"] {
        flex-direction: column !important;
        align-items: center !important;
    }
    
    /* Размер графика */
    #financeCategoriesChart {
        max-width: 160px !important;
        max-height: 160px !important;
    }
}

/* ============================================
   PULL-TO-REFRESH ИНДИКАТОР
   ============================================ */

.pull-to-refresh {
    position: fixed;
    top: 56px;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background: var(--bg-secondary, #141414);
    border: 1px solid var(--border-color, #2a2a2a);
    border-radius: 20px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary, #b0b0b0);
    z-index: 1000;
    transition: transform 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.pull-to-refresh.visible {
    transform: translateX(-50%) translateY(10px);
}

.pull-to-refresh i {
    animation: spin 1s linear infinite;
}

/* ============================================
   SAFE AREA ДЛЯ NOTCH (iPhone X+)
   ============================================ */

@supports (padding-top: env(safe-area-inset-top)) {
    .navbar,
    .navbar-modern {
        padding-top: calc(10px + env(safe-area-inset-top));
    }
    
    body {
        padding-top: calc(70px + env(safe-area-inset-top));
    }
    
    .mobile-bottom-nav {
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }
}

/* ============================================
   LANDSCAPE РЕЖИМ
   ============================================ */

@media (max-width: 767px) and (orientation: landscape) {
    /* Компактнее в ландшафте */
    .grid-modern-4 {
        grid-template-columns: repeat(4, 1fr) !important;
    }
    
    .mobile-bottom-nav {
        padding: 4px 0;
        padding-bottom: calc(4px + env(safe-area-inset-bottom));
    }
    
    .mobile-bottom-nav-item {
        padding: 4px 8px;
        font-size: 9px;
    }
    
    .mobile-bottom-nav-item i {
        font-size: 1rem;
    }
}

/* ============================================
   ТЕМНАЯ ТЕМА - УЛУЧШЕНИЯ ДЛЯ МОБИЛЬНЫХ
   ============================================ */

@media (max-width: 767px) {
    /* Более контрастные границы */
    .modern-card {
        border-color: var(--border-color, #333);
    }
    
    /* Улучшенная читаемость */
    .text-muted {
        color: var(--text-secondary, #999) !important;
    }
}


/* ============================================
   COMPANY PAGES - МОБИЛЬНАЯ АДАПТАЦИЯ
   ============================================ */

@media (max-width: 767px) {
    /* Дашборд компании */
    .co-page { padding: 0; }
    .co-title { font-size: 1.3rem; }
    .co-stats { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
    .co-stat { padding: 14px 10px; }
    .co-stat-value { font-size: 1.2rem; }
    .co-stat-icon { font-size: 1.3rem; }
    .co-actions { grid-template-columns: 1fr !important; gap: 10px !important; }
    .co-action { padding: 14px 12px; }
    .co-company-card { padding: 20px 16px; border-radius: 16px; }
    .co-company-name { font-size: 1.1rem; }
    .co-company-meta { gap: 10px; font-size: 0.8rem; }
    
    /* Команда */
    .team-page { padding: 0; }
    .team-header { flex-direction: column; align-items: flex-start; }
    .team-title { font-size: 1.3rem; }
    .team-filters { gap: 6px; }
    .team-filter { padding: 6px 12px; font-size: 0.8rem; }
    .team-card { padding: 14px; gap: 12px; flex-wrap: wrap; }
    .team-avatar { width: 44px; height: 44px; }
    .team-card-name { font-size: 0.9rem; }
    .team-card-meta { font-size: 0.78rem; gap: 8px; }
    .team-card-actions { width: 100%; justify-content: flex-end; margin-top: 6px; }
    
    /* Профиль */
    .prof-page { padding: 0; }
    .prof-title { font-size: 1.3rem; }
    .prof-card { padding: 20px 16px; }
    .prof-row { grid-template-columns: 1fr !important; }
    
    /* Подписка */
    .sub-page { padding: 0; }
    .sub-title { font-size: 1.3rem; }
    .sub-current { padding: 20px 16px; border-radius: 16px; }
    .sub-current-plan { font-size: 1.3rem; }
    .sub-current-meta { flex-direction: column; gap: 8px; }
    .sub-limits { grid-template-columns: 1fr !important; gap: 10px !important; }
    .tiers-grid { grid-template-columns: 1fr !important; }
    .tier-card { padding: 24px 18px; }
    .tier-price { font-size: 1.6rem; }
}

@media (max-width: 480px) {
    .co-stats { grid-template-columns: 1fr !important; }
    .co-stat { flex-direction: row; gap: 12px; text-align: left; }
}
