/* ========================================
   FELIX HUB - MOBILE RESPONSIVE STYLES
   Адаптивные стили для всех страниц
   ======================================== */

/* 
   БАЗОВЫЕ НАСТРОЙКИ
   Применяются ко всем страницам
*/

/* Убираем горизонтальный скролл */
html, body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100%;
}

/* Улучшаем отображение текста на мобильных */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Увеличиваем кликабельные зоны кнопок */
button, .btn, a.btn {
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* Улучшаем отображение input на iOS */
input, select, textarea {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 8px;
}

/* Отключаем масштабирование input на iOS */
input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="number"],
select,
textarea {
    font-size: 16px !important;
}

/* ========================================
   HEADER & NAVIGATION
   ======================================== */

@media (max-width: 768px) {
    /* Header */
    .header, .page-header {
        padding: 15px 20px !important;
    }
    
    .header-content, .page-header-content {
        flex-direction: row !important;
        gap: 15px;
        align-items: center !important;
        justify-content: space-between !important;
    }
    
    .header h1, .page-header h1 {
        font-size: 1.1em !important;
        flex-wrap: wrap;
        font-weight: 600 !important;
    }
    
    .header-actions {
        width: auto !important;
        justify-content: flex-end;
        gap: 8px !important;
    }
    
    /* Navigation - компактная версия */
    .nav {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        margin-bottom: 20px !important;
    }
    
    .nav a {
        padding: 10px 12px !important;
        font-size: 0.85em !important;
        font-weight: 500 !important;
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Burger Menu для больших навигаций */
    .nav-large {
        position: relative;
        margin-bottom: 20px;
    }
    
    .nav-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        background: white;
        border: 2px solid #e0e0e0;
        padding: 12px 15px;
        border-radius: 10px;
        font-weight: 600;
        font-size: 0.95em;
        color: #333;
        cursor: pointer;
        transition: all 0.3s ease;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }
    
    .nav-toggle:hover {
        border-color: #667eea;
        background: #f8f9ff;
    }
    
    .nav-toggle:active {
        transform: scale(0.98);
    }
    
    /* Красивая иконка гамбургера */
    .nav-toggle::after {
        content: '';
        width: 20px;
        height: 14px;
        background-image: 
            linear-gradient(to bottom, 
                #667eea 0%, #667eea 2px, 
                transparent 2px, transparent 6px,
                #667eea 6px, #667eea 8px,
                transparent 8px, transparent 12px,
                #667eea 12px, #667eea 14px
            );
        background-size: 100% 14px;
        background-repeat: no-repeat;
        transition: all 0.3s ease;
    }
    
    .nav-toggle.active::after {
        background-image: none;
        width: 18px;
        height: 18px;
        position: relative;
    }
    
    .nav-toggle.active::after {
        content: '✕';
        background: none;
        font-size: 24px;
        line-height: 18px;
        color: #667eea;
        font-weight: 300;
        width: auto;
        height: auto;
    }
    
    .nav-items {
        display: none;
        flex-direction: column;
        gap: 6px;
        margin-top: 10px;
        animation: slideDown 0.3s ease;
    }
    
    @keyframes slideDown {
        from {
            opacity: 0;
            transform: translateY(-10px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
    
    .nav-items.active {
        display: flex;
    }
    
    .nav-items a {
        padding: 12px 15px !important;
        background: white;
        border-radius: 8px;
        font-size: 0.9em !important;
        font-weight: 500 !important;
        border: 1px solid #e0e0e0;
        transition: all 0.2s ease;
    }
    
    .nav-items a:hover {
        background: #f8f9ff;
        border-color: #667eea;
        transform: translateX(3px);
    }
    
    .nav-items a.active {
        background: #667eea;
        color: white;
        border-color: #667eea;
    }
}

@media (max-width: 480px) {
    /* На маленьких экранах - вертикальное меню */
    .nav {
        grid-template-columns: 1fr !important;
    }
    
    .header h1, .page-header h1 {
        font-size: 1em !important;
    }
}

/* ========================================
   BUTTONS & ACTIONS
   ======================================== */

@media (max-width: 768px) {
    .btn {
        padding: 10px 14px !important;
        font-size: 0.85em !important;
        white-space: nowrap;
        font-weight: 500 !important;
    }
    
    .btn-sm, .btn-small {
        padding: 7px 10px !important;
        font-size: 0.8em !important;
    }
    
    .action-buttons {
        flex-wrap: wrap;
        gap: 6px !important;
    }
    
    .action-buttons .btn {
        flex: 1 1 calc(50% - 6px);
        min-width: calc(50% - 6px);
    }
    
    /* Улучшенный стиль для кнопок в header */
    .header-actions .btn,
    .page-header-content .btn {
        padding: 8px 12px !important;
        font-size: 0.8em !important;
        border-radius: 6px !important;
    }
}

@media (max-width: 480px) {
    /* Кнопки занимают всю ширину на маленьких экранах */
    .action-buttons .btn {
        flex: 1 1 100%;
        width: 100%;
    }
    
    .header-actions {
        flex-direction: row !important;
        width: auto !important;
        flex-wrap: nowrap;
    }
    
    .header-actions .btn {
        white-space: nowrap;
        padding: 7px 10px !important;
        font-size: 0.75em !important;
    }
}

/* ========================================
   CONTAINERS & LAYOUTS
   ======================================== */

@media (max-width: 768px) {
    .container {
        padding: 20px 15px !important;
    }
    
    .card, .stat-card, .order-card {
        padding: 20px 15px !important;
        margin-bottom: 15px !important;
    }
    
    .main-content {
        padding: 15px !important;
        min-height: auto !important;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 15px 10px !important;
    }
}

/* ========================================
   GRIDS & STATS
   ======================================== */

@media (max-width: 768px) {
    /* Компактная статистика в виде строк */
    .stats-grid, .stats-bar, .stats {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
        margin-bottom: 20px !important;
    }
    
    .stat-card, .stat-item {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 8px 15px !important;
        border-radius: 8px !important;
        background: white !important;
        border-left: 3px solid currentColor !important;
        min-height: auto !important;
    }
    
    .stat-card h3, .stat-label {
        font-size: 0.85em !important;
        font-weight: 500 !important;
        margin: 0 !important;
        opacity: 0.8 !important;
    }
    
    .stat-value, .stat-number, .stat-card .number {
        font-size: 1.2em !important;
        font-weight: 700 !important;
        margin: 0 !important;
    }
    
    /* Цветные акценты для разных типов */
    .stat-card.new, .stat-item:nth-child(1) {
        border-left-color: #667eea !important;
    }
    
    .stat-card.processing, .stat-item:nth-child(2) {
        border-left-color: #f59e0b !important;
    }
    
    .stat-card.ready, .stat-item:nth-child(3) {
        border-left-color: #10b981 !important;
    }
    
    .stat-card.completed, .stat-item:nth-child(4) {
        border-left-color: #6b7280 !important;
    }
    
    /* Filters Grid */
    .filters-grid, .filters {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
        padding: 15px !important;
    }
}

/* ========================================
   TABLES
   ======================================== */

@media (max-width: 768px) {
    /* Горизонтальный скролл для таблиц */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px;
        padding: 0 15px;
    }
    
    table {
        font-size: 0.85em !important;
        min-width: 600px;
    }
    
    th, td {
        padding: 10px 8px !important;
        white-space: nowrap;
    }
    
    /* Скрываем некоторые колонки на мобильных */
    .hide-mobile {
        display: none !important;
    }
    
    /* Компактные таблицы */
    .table-header {
        padding: 15px !important;
    }
    
    .table-header h2 {
        font-size: 1.2em !important;
    }
}

/* Карточный вид таблиц для мобильных */
@media (max-width: 640px) {
    .table-cards {
        display: block !important;
    }
    
    .table-cards thead {
        display: none;
    }
    
    .table-cards tbody {
        display: block;
    }
    
    .table-cards tr {
        display: block;
        margin-bottom: 15px;
        background: white;
        border-radius: 10px;
        padding: 15px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    }
    
    .table-cards td {
        display: block;
        text-align: left !important;
        padding: 8px 0 !important;
        border: none !important;
        white-space: normal !important;
        min-width: auto !important;
    }
    
    .table-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        display: block;
        margin-bottom: 5px;
        color: #667eea;
    }
}

/* ========================================
   FORMS
   ======================================== */

@media (max-width: 768px) {
    .form-group {
        margin-bottom: 15px !important;
    }
    
    .form-group label {
        font-size: 0.95em !important;
        margin-bottom: 6px !important;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 12px !important;
        font-size: 16px !important;
    }
    
    /* Исправление прокрутки для select на мобильных */
    .form-group select {
        -webkit-appearance: menulist-button;
        appearance: menulist-button;
        max-height: none !important; /* Не ограничиваем на мобильных - iOS использует нативное меню */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Специально для iOS - улучшаем прокрутку select */
    @supports (-webkit-touch-callout: none) {
        .form-group select {
            -webkit-overflow-scrolling: touch !important;
            overflow-y: visible !important; /* На iOS select использует нативное меню */
            max-height: none !important;
        }
    }
    
    .form-group select option {
        font-size: 16px !important;
        padding: 12px 10px !important;
        min-height: 44px; /* Минимальная высота для удобного тапа */
        line-height: 1.5;
    }
    
    /* Checkbox и Radio увеличенные для сенсорных экранов */
    .checkbox-item, .radio-item {
        padding: 15px 12px !important;
        margin-bottom: 8px;
    }
    
    .checkbox-item input[type="checkbox"],
    .radio-item input[type="radio"] {
        width: 22px !important;
        height: 22px !important;
        margin-right: 12px !important;
    }
    
    /* Custom parts input */
    .custom-parts-input {
        flex-direction: column !important;
        gap: 10px !important;
    }
    
    .custom-parts-input input {
        width: 100% !important;
    }
    
    .custom-parts-input .add-btn {
        width: 100% !important;
    }
}

/* ========================================
   MODALS
   ======================================== */

@media (max-width: 768px) {
    .modal-content {
        width: 95% !important;
        max-width: 95% !important;
        max-height: 85vh !important;
        margin: 20px;
        padding: 0 !important;
    }
    
    .modal-header {
        padding: 15px 20px !important;
    }
    
    .modal-body {
        padding: 15px 20px !important;
        max-height: calc(85vh - 140px) !important;
    }
    
    .modal-footer {
        padding: 15px 20px !important;
    }
    
    .modal-header h2 {
        font-size: 1.2em !important;
    }
    
    .close-modal {
        font-size: 26px !important;
    }
}

@media (max-width: 480px) {
    .modal-content {
        width: 100% !important;
        height: 100% !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0;
    }
}

/* ========================================
   LANGUAGE SWITCHER
   ======================================== */

@media (max-width: 768px) {
    /* Переключатель языка в шапке */
    .language-switcher {
        order: -1; /* Первым в header-actions */
        margin-right: 5px;
    }
    
    .lang-buttons {
        gap: 5px !important;
    }
    
    .lang-btn {
        width: 30px !important;
        height: 30px !important;
        font-size: 15px !important;
        padding: 0 !important;
        border-width: 1.5px !important;
    }
    
    /* Скрываем title на мобильных */
    .lang-btn[title]::after {
        display: none !important;
    }
    
    /* Адаптируем расположение в header-actions */
    .header-actions {
        align-items: center !important;
        flex-wrap: nowrap !important;
    }
    
    /* Для старого стиля (на всякий случай) */
    .language-switcher.old-style {
        top: 8px !important;
        right: 8px !important;
        z-index: 1001;
    }
    
    .lang-selector {
        background: white;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        padding: 4px;
    }
    
    .lang-select {
        padding: 6px 26px 6px 8px !important;
        font-size: 0.8em !important;
        border: 1px solid #e0e0e0;
        border-radius: 6px;
        background-color: white;
        font-weight: 500;
    }
    
    .lang-icon {
        font-size: 0.9em !important;
        margin-right: 4px;
    }
}

@media (max-width: 480px) {
    .lang-buttons {
        gap: 4px !important;
    }
    
    .lang-btn {
        width: 26px !important;
        height: 26px !important;
        font-size: 13px !important;
    }
    
    /* На очень маленьких экранах уменьшаем отступы в header */
    .page-header-content,
    .header-content {
        gap: 10px !important;
    }
}

/* ========================================
   CARDS & BLOCKS
   ======================================== */

@media (max-width: 768px) {
    .order-card {
        padding: 15px !important;
    }
    
    .order-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px;
    }
    
    .order-id {
        font-size: 1.1em !important;
    }
    
    .order-details {
        font-size: 0.9em !important;
    }
    
    .parts-list {
        font-size: 0.85em !important;
    }
    
    .custom-part-tag {
        font-size: 0.85em !important;
        padding: 6px 10px !important;
    }
}

/* ========================================
   BADGES & STATUS
   ======================================== */

@media (max-width: 768px) {
    .status-badge {
        font-size: 0.75em !important;
        padding: 4px 8px !important;
    }
}

/* ========================================
   EMPTY STATES
   ======================================== */

@media (max-width: 768px) {
    .empty-state {
        padding: 40px 15px !important;
    }
    
    .empty-state h3 {
        font-size: 1.1em !important;
    }
    
    .empty-state p {
        font-size: 0.9em !important;
    }
}

/* ========================================
   TYPOGRAPHY
   ======================================== */

@media (max-width: 768px) {
    h1 {
        font-size: 1.5em !important;
    }
    
    h2 {
        font-size: 1.3em !important;
    }
    
    h3 {
        font-size: 1.1em !important;
    }
    
    .subtitle {
        font-size: 0.95em !important;
    }
}

/* ========================================
   LOADING & ALERTS
   ======================================== */

@media (max-width: 768px) {
    .loading {
        padding: 30px 15px !important;
        font-size: 1em !important;
    }
    
    .alert, .success-message, .error-message {
        padding: 12px 15px !important;
        font-size: 0.9em !important;
        margin: 10px !important;
    }
}

/* ========================================
   SPECIFIC PAGES FIXES
   ======================================== */

/* Index Page - Language Buttons */
@media (max-width: 768px) {
    .lang-btn {
        padding: 15px 20px !important;
        font-size: 1em !important;
    }
    
    .flag {
        font-size: 1.3em !important;
    }
}

@media (max-width: 480px) {
    .lang-btn {
        padding: 12px 15px !important;
        font-size: 0.95em !important;
    }
    
    .logo {
        font-size: 2.5em !important;
    }
}

/* Admin Panel - Filters */
@media (max-width: 768px) {
    .filters .filter-group {
        margin-bottom: 0;
    }
    
    .filters .filter-group:last-child {
        grid-column: 1;
    }
}

/* Parts Manager */
@media (max-width: 768px) {
    .tabs {
        padding: 8px !important;
        gap: 5px !important;
    }
    
    .tab {
        padding: 10px 15px !important;
        font-size: 0.9em !important;
        flex: 1;
        text-align: center;
    }
}

/* ========================================
   LANDSCAPE ORIENTATION
   ======================================== */

@media (max-width: 768px) and (orientation: landscape) {
    .main-content {
        min-height: auto !important;
        padding: 20px !important;
    }
    
    .container {
        max-width: 100% !important;
    }
    
    .stats-grid, .stats-bar {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .header-actions,
    .language-switcher,
    .nav,
    .btn,
    button {
        display: none !important;
    }
    
    .container {
        max-width: 100% !important;
    }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Responsive utilities */
.mobile-only {
    display: none !important;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }
    
    .desktop-only {
        display: none !important;
    }
    
    .mobile-hidden {
        display: none !important;
    }
}

/* Spacing helpers */
@media (max-width: 768px) {
    .mt-mobile {
        margin-top: 15px !important;
    }
    
    .mb-mobile {
        margin-bottom: 15px !important;
    }
    
    .p-mobile {
        padding: 15px !important;
    }
}

/* Text alignment */
@media (max-width: 768px) {
    .text-center-mobile {
        text-align: center !important;
    }
    
    .text-left-mobile {
        text-align: left !important;
    }
}

/* Scrollable container */
.scroll-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Safe area для устройств с "notch" */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .page-header, .header {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

/* Увеличиваем контраст фокуса для клавиатурной навигации */
@media (max-width: 768px) {
    *:focus {
        outline: 3px solid #667eea;
        outline-offset: 2px;
    }
    
    button:focus,
    a:focus,
    input:focus,
    select:focus,
    textarea:focus {
        outline: 3px solid #667eea;
        outline-offset: 2px;
    }
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   ======================================== */

/* Оптимизация анимаций на мобильных */
@media (max-width: 768px) {
    * {
        transition-duration: 0.2s !important;
    }
    
    /* Используем transform вместо margin/padding для анимаций */
    .btn:active {
        transform: scale(0.98) !important;
    }
}

/* Smooth scrolling */
html {
    scroll-behavior: smooth;
}

/* ========================================
   DARK MODE SUPPORT (опционально)
   ======================================== */

@media (prefers-color-scheme: dark) and (max-width: 768px) {
    /* Можно добавить темную тему если потребуется */
}
