/* Адаптивная верстка для мобильных устройств */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
    .metrics-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    }

    .charts-container {
        grid-template-columns: 1fr;
    }

    .header-left h1 {
        font-size: 2.5rem;
    }

    .stats-bar {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
    .container {
        padding: 20px 12px;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-md);
    }

    .header-left h1 {
        font-size: 2rem;
    }

    .header-right {
        width: 100%;
        align-items: stretch !important;
    }

    /* Nav links - horizontal scroll */
    .nav-links {
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        white-space: nowrap;
        padding-bottom: 8px;
        gap: 8px !important;
        margin-bottom: 12px;
    }

    .nav-links::-webkit-scrollbar {
        display: none;
    }

    .nav-links .nav-link {
        display: inline-block;
        padding: 8px 12px !important;
        font-size: 0.8rem !important;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .header-right > div:last-child {
        width: 100%;
        justify-content: space-between;
    }

    .api-status {
        flex: 1;
    }

    .theme-toggle {
        flex-shrink: 0;
    }

    .tabs-nav {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tab-button {
        white-space: nowrap;
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .tab-controls {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .control-group select,
    .control-group input {
        min-width: 100%;
        width: 100%;
    }

    /* Карточки в одну колонку */
    .metrics-grid {
        grid-template-columns: 1fr;
    }

    .metric-card {
        padding: var(--spacing-md);
    }

    /* Статистика */
    .stats-bar {
        grid-template-columns: 1fr;
        gap: var(--spacing-sm);
    }

    .stat-value {
        font-size: 1.5rem;
    }

    /* Графики */
    .charts-container {
        grid-template-columns: 1fr;
    }

    .chart-card {
        padding: var(--spacing-md);
    }

    .chart-wrapper {
        height: 250px;
    }

    .chart-options {
        flex-wrap: wrap;
    }

    /* Кнопки */
    .btn {
        width: 100%;
        justify-content: center;
    }

    /* Сообщения */
    .messages-container {
        left: 10px;
        right: 10px;
        max-width: none;
    }

    /* Формы */
    .plans-form {
        grid-template-columns: 1fr;
    }
}

/* Touch-friendly увеличенные области нажатия */
@media (max-width: 768px) {
    .btn,
    .tab-button,
    input,
    select {
        min-height: 44px;
        font-size: 16px; /* Предотвращает zoom на iOS */
    }

    /* Разрешаем нормальный скролл в контейнере вкладок */
    .tabs-container {
        touch-action: auto;
    }
}

/* Landscape ориентация на мобильных */
@media (max-width: 768px) and (orientation: landscape) {
    .header-left h1 {
        font-size: 1.5rem;
    }

    .chart-wrapper {
        height: 200px;
    }
}

/* Extra small screens (< 480px) */
@media (max-width: 480px) {
    .container {
        padding: 16px 8px;
    }

    .header-left h1 {
        font-size: 1.5rem;
    }

    .nav-links .nav-link {
        padding: 6px 10px !important;
        font-size: 0.75rem !important;
    }

    .metric-value {
        font-size: 1rem;
    }

    .stat-value {
        font-size: 1.25rem;
    }

    .tab-button {
        padding: 8px 12px;
        font-size: 0.8rem;
    }
}

/* Очень маленькие экраны (< 400px) */
@media (max-width: 400px) {
    .header-left h1 {
        font-size: 1.25rem;
    }

    .metric-value {
        font-size: 0.9rem;
    }

    .stat-value {
        font-size: 1.1rem;
    }
}

/* Прячем некоторые элементы на мобильных */
@media (max-width: 768px) {
    .desktop-only {
        display: none;
    }
}

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

/* Hamburger menu для мобильных */
@media (max-width: 768px) {
    .burger-menu {
        display: block;
        width: 30px;
        height: 24px;
        cursor: pointer;
        position: relative;
    }

    .burger-menu span {
        display: block;
        width: 100%;
        height: 3px;
        background: var(--text-primary);
        position: absolute;
        transition: all 0.3s ease;
    }

    .burger-menu span:nth-child(1) {
        top: 0;
    }

    .burger-menu span:nth-child(2) {
        top: 10px;
    }

    .burger-menu span:nth-child(3) {
        bottom: 0;
    }

    .burger-menu.active span:nth-child(1) {
        transform: rotate(45deg);
        top: 10px;
    }

    .burger-menu.active span:nth-child(2) {
        opacity: 0;
    }

    .burger-menu.active span:nth-child(3) {
        transform: rotate(-45deg);
        bottom: 11px;
    }
}
