/* 
 * Мобильная адаптация для всех страниц
 * Подключать после основных стилей
 */

/* ═══════════════════════════════════════════════════════════════
   БАЗОВЫЕ НАСТРОЙКИ
   ═══════════════════════════════════════════════════════════════ */

/* Улучшение читаемости на мобильных */
@media (max-width: 768px) {
    * {
        -webkit-tap-highlight-color: rgba(251, 191, 36, 0.2);
    }
    
    html {
        font-size: 14px; /* Уменьшаем базовый размер шрифта */
    }
    
    body {
        overflow-x: hidden;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* ═══════════════════════════════════════════════════════════════
   МОБИЛЬНОЕ МЕНЮ (БУРГЕР)
   ═══════════════════════════════════════════════════════════════ */

.mobile-menu-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
}

.mobile-logo {
    font-size: 1.25rem;
    font-weight: 800;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.mobile-burger {
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    position: relative;
    z-index: 1001;
}

.burger-line {
    display: block;
    width: 100%;
    height: 3px;
    background: #fbbf24;
    margin: 6px 0;
    transition: all 0.3s ease;
    border-radius: 2px;
}

.mobile-burger.active .burger-line:nth-child(1) {
    transform: rotate(45deg) translate(8px, 8px);
}

.mobile-burger.active .burger-line:nth-child(2) {
    opacity: 0;
}

.mobile-burger.active .burger-line:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

.mobile-menu {
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    padding: 1.5rem;
    z-index: 999;
}

.mobile-menu.active {
    transform: translateX(0);
}

.mobile-menu-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    margin-bottom: 0.5rem;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 1rem;
    text-decoration: none;
    color: #e2e8f0;
    font-weight: 600;
    transition: all 0.3s ease;
}

.mobile-menu-item:hover,
.mobile-menu-item:active {
    background: rgba(251, 191, 36, 0.15);
    border-color: rgba(251, 191, 36, 0.4);
    transform: translateX(5px);
}

.mobile-menu-icon {
    font-size: 1.5rem;
    width: 40px;
    text-align: center;
}

/* Overlay для закрытия меню */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* ═══════════════════════════════════════════════════════════════
   АДАПТАЦИЯ КОНТЕЙНЕРОВ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .container {
        max-width: 100%;
        padding: 0 1rem;
        margin: 0 auto;
    }
    
    .page-container {
        padding: 1rem;
        margin-top: 64px; /* Отступ под fixed header */
    }
}

/* ═══════════════════════════════════════════════════════════════
   КАРТОЧКИ И БЛОКИ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .card {
        padding: 1.25rem;
        margin-bottom: 1rem;
        border-radius: 1.25rem;
    }
    
    .card-title {
        font-size: 1.15rem;
    }
    
    /* Сетки становятся одноколоночными */
    .grid,
    .content-grid,
    .stats-grid,
    .features-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }
}

/* ═══════════════════════════════════════════════════════════════
   ПРОФИЛЬ УЧЕНИКА
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .profile-header {
        padding: 1.5rem 1rem;
    }
    
    .header-content {
        flex-direction: column;
        gap: 1.5rem;
    }
    
    .header-left {
        flex-direction: column;
        align-items: center;
        text-align: center;
        width: 100%;
    }
    
    .avatar {
        width: 100px !important;
        height: 100px !important;
        font-size: 2.5rem !important;
    }
    
    .profile-info h1 {
        font-size: 1.5rem;
    }
    
    .profile-stats {
        justify-content: center;
        gap: 0.75rem;
        flex-wrap: wrap;
    }
    
    .stat-item {
        min-width: 100px;
        padding: 0.75rem;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
    
    /* Значки и медали */
    .badges-grid,
    .medals-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem;
    }
    
    .badge-item,
    .medal-item {
        padding: 0.75rem;
    }
    
    .badge-icon {
        width: 48px !important;
        height: 48px !important;
        font-size: 2rem !important;
    }
    
    /* Таблица рейтингов */
    .ratings-table {
        font-size: 0.9rem;
    }
    
    .rating-row {
        padding: 0.85rem 1rem;
    }
    
    .rating-score {
        font-size: 1.15rem;
    }
}

/* Очень маленькие экраны (iPhone SE) */
@media (max-width: 375px) {
    .badges-grid,
    .medals-grid {
        grid-template-columns: 1fr !important;
    }
    
    .profile-stats {
        grid-template-columns: 1fr 1fr;
    }
}

/* ═══════════════════════════════════════════════════════════════
   РЕЙТИНГИ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .rating-filters {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .filter-group {
        width: 100%;
    }
    
    .filter-group select {
        width: 100%;
    }
    
    /* Таблица становится карточками на мобильном */
    .rating-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .rating-table {
        min-width: 500px;
    }
    
    .rating-table th,
    .rating-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
    }
}

/* ═══════════════════════════════════════════════════════════════
   ГЛАВНАЯ СТРАНИЦА
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .hero-header {
        padding: 2rem 1rem !important;
    }
    
    .hero-title {
        font-size: 1.75rem !important;
    }
    
    .hero-subtitle {
        font-size: 1rem !important;
    }
    
    /* Статистика */
    .live-stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
    }
    
    .stat-card {
        padding: 1rem !important;
    }
    
    .stat-number {
        font-size: 1.75rem !important;
    }
    
    /* Топ лидеры */
    .leaders-grid {
        grid-template-columns: 1fr !important;
    }
    
    .leader-card {
        padding: 1.25rem !important;
    }
    
    /* Классы */
    .class-buttons {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.75rem !important;
    }
    
    .class-btn {
        padding: 1rem !important;
        font-size: 0.95rem !important;
    }
    
    /* Новости */
    .news-grid {
        grid-template-columns: 1fr !important;
    }
    
    .news-card {
        flex-direction: column !important;
    }
    
    .news-image {
        width: 100% !important;
        height: 200px !important;
        border-radius: 1rem 1rem 0 0 !important;
    }
    
    .news-content {
        padding: 1.25rem !important;
    }
    
    /* Таймер обратного отсчета */
    .countdown-timer {
        padding: 1.5rem 1rem !important;
    }
    
    .timer-title {
        font-size: 1.35rem !important;
    }
    
    .timer-display {
        gap: 0.5rem !important;
    }
    
    .timer-unit {
        min-width: 60px !important;
        padding: 0.75rem 0.5rem !important;
    }
    
    .timer-value {
        font-size: 1.75rem !important;
    }
    
    .timer-label {
        font-size: 0.75rem !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   АДМИН-ПАНЕЛЬ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .admin-header {
        padding: 1.5rem 1rem;
    }
    
    .admin-sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 280px;
        height: 100vh;
        transition: left 0.3s ease;
        z-index: 1100;
    }
    
    .admin-sidebar.active {
        left: 0;
    }
    
    .admin-content {
        margin-left: 0 !important;
        padding: 1rem;
    }
    
    .quick-actions {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 1rem;
    }
    
    .quick-action-btn {
        padding: 1.25rem 1rem !important;
    }
    
    .settings-card {
        padding: 1.25rem !important;
    }
    
    .form-row,
    .row {
        flex-direction: column !important;
    }
    
    .col-md-6,
    .col-md-4,
    .col-md-3 {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   КНОПКИ И ИНТЕРАКТИВНЫЕ ЭЛЕМЕНТЫ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Увеличиваем размер кнопок для удобного нажатия */
    button,
    .btn,
    a.button {
        min-height: 44px; /* Рекомендация Apple для touch */
        padding: 0.85rem 1.25rem;
        font-size: 1rem;
    }
    
    /* Touch feedback */
    button:active,
    .btn:active {
        transform: scale(0.97);
    }
    
    /* Увеличиваем чекбоксы и радио */
    input[type="checkbox"],
    input[type="radio"] {
        width: 24px;
        height: 24px;
        min-width: 24px;
        min-height: 24px;
    }
    
    /* Увеличиваем поля ввода */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        min-height: 44px;
        font-size: 16px; /* Предотвращает zoom в Safari */
        padding: 0.75rem 1rem;
    }
}

/* ═══════════════════════════════════════════════════════════════
   МОДАЛЬНЫЕ ОКНА
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .modal-content {
        width: 95vw !important;
        max-width: 95vw !important;
        max-height: 90vh !important;
        margin: 5vh auto;
        border-radius: 1.25rem;
    }
    
    .modal-header {
        font-size: 1.25rem;
        padding: 1.25rem;
    }
    
    .modal-body {
        padding: 1.25rem;
    }
}

/* ═══════════════════════════════════════════════════════════════
   ТАБЛИЦЫ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Горизонтальный скролл для больших таблиц */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 1rem;
        margin-bottom: 1rem;
    }
    
    table {
        min-width: 500px;
    }
    
    th, td {
        padding: 0.75rem 0.5rem !important;
        font-size: 0.85rem !important;
    }
    
    /* Или превращаем таблицу в карточки */
    .mobile-card-table tr {
        display: block;
        margin-bottom: 1rem;
        background: rgba(30, 41, 59, 0.6);
        border-radius: 1rem;
        padding: 1rem;
    }
    
    .mobile-card-table td {
        display: block;
        text-align: left !important;
        border: none !important;
        padding: 0.5rem 0 !important;
    }
    
    .mobile-card-table td:before {
        content: attr(data-label);
        font-weight: 700;
        color: #94a3b8;
        display: inline-block;
        width: 120px;
    }
}

/* ═══════════════════════════════════════════════════════════════
   ФОРМЫ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .form-group {
        margin-bottom: 1.25rem;
    }
    
    label {
        font-size: 0.95rem;
        margin-bottom: 0.5rem;
    }
    
    /* Стэкаем элементы формы */
    .form-row {
        flex-direction: column;
        gap: 1rem;
    }
    
    /* Кнопки занимают всю ширину */
    .btn-group {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .btn-group .btn {
        width: 100%;
    }
}

/* ═══════════════════════════════════════════════════════════════
   НАВИГАЦИЯ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Скрываем desktop навигацию */
    .desktop-nav,
    .navbar-desktop {
        display: none !important;
    }
    
    /* Показываем мобильную навигацию */
    .mobile-menu-wrapper {
        display: block;
    }
}

@media (min-width: 769px) {
    /* Скрываем мобильное меню на desktop */
    .mobile-menu-wrapper,
    .mobile-burger,
    .mobile-overlay {
        display: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   УТИЛИТЫ
   ═══════════════════════════════════════════════════════════════ */

/* Скрыть на мобильных */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Показать только на мобильных */
@media (min-width: 769px) {
    .show-mobile {
        display: none !important;
    }
}

/* Текст по центру на мобильных */
@media (max-width: 768px) {
    .text-center-mobile {
        text-align: center !important;
    }
}

/* Уменьшенные отступы на мобильных */
@media (max-width: 768px) {
    .p-mobile-sm {
        padding: 0.75rem !important;
    }
    
    .m-mobile-sm {
        margin: 0.75rem !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   LANDSCAPE ОРИЕНТАЦИЯ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) and (orientation: landscape) {
    .mobile-menu {
        top: 56px;
    }
    
    .mobile-header {
        padding: 0.75rem 1rem;
    }
    
    .avatar {
        width: 80px !important;
        height: 80px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   ПЛАНШЕТЫ
   ═══════════════════════════════════════════════════════════════ */

@media (min-width: 768px) and (max-width: 1024px) {
    .container {
        max-width: 720px;
    }
    
    .grid,
    .content-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .leaders-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr) minmax(0, 1fr) !important;
        align-items: end !important;
        gap: 0.75rem !important;
    }

    .leader-card {
        min-width: 0;
    }

    .leader-card.first {
        transform: scale(1.03) !important;
    }

    .leader-card.first:hover {
        transform: scale(1.04) translateY(-3px) !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   АНИМАЦИИ (уменьшаем на мобильных для производительности)
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Отключаем тяжелые анимации */
    .flip-animation,
    .parallax-bg,
    .particle-effect {
        animation: none !important;
    }
    
    /* Упрощаем transitions */
    * {
        transition-duration: 0.2s !important;
    }
}

/* Режим энергосбережения */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   ФИКСИРОВАННЫЕ ЭЛЕМЕНТЫ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Sticky elements занимают меньше места */
    .sticky-header {
        position: sticky;
        top: 64px; /* Под mobile header */
        z-index: 100;
    }
    
    /* Floating кнопки */
    .floating-btn {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
        z-index: 900;
    }
}

/* ═══════════════════════════════════════════════════════════════
   ОПТИМИЗАЦИЯ ИЗОБРАЖЕНИЙ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    img {
        max-width: 100%;
        height: auto;
    }
    
    /* Аватары оптимального размера */
    .avatar img,
    .profile-photo img {
        object-fit: cover;
    }
    
    /* Lazy loading hint */
    img[loading="lazy"] {
        background: rgba(148, 163, 184, 0.1);
    }
}

/* ═══════════════════════════════════════════════════════════════
   SAFE AREA (для iPhone с вырезом)
   ═══════════════════════════════════════════════════════════════ */

@supports (padding: env(safe-area-inset-top)) {
    .mobile-header {
        padding-top: calc(1rem + env(safe-area-inset-top));
    }
    
    .mobile-menu {
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    }
}

/* ═══════════════════════════════════════════════════════════════
   ПРОИЗВОДИТЕЛЬНОСТЬ
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* Hardware acceleration для smooth scrolling */
    .mobile-menu,
    .mobile-overlay {
        transform: translateZ(0);
        will-change: transform;
    }
    
    /* Оптимизация рендеринга */
    .card,
    .profile-header,
    .leader-card {
        will-change: auto;
        contain: layout style paint;
    }
}
