/* ========================================
   MAIN MOBILE RESPONSIVE STYLES
   Объединенный файл мобильных стилей для Kaspi Bot

   Включает:
   - Базовые мобильные стили (mobile.css)
   - Комплексную адаптацию (mobile-comprehensive.css)
   - Исправления и фиксы (mobile-fixes.css)
   ======================================== */

/* ========================================
   ЧАСТЬ 1: БАЗОВЫЕ МОБИЛЬНЫЕ СТИЛИ
   ======================================== */

/* Viewport and Base Mobile Improvements */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Enhanced Mobile Styles (max-width: 768px) */
@media (max-width: 768px) {
    /* Body and Container */
    body {
        padding: 8px;
        min-width: 320px;
    }

    /* Login Container - Mobile Optimized */
    .login-container {
        padding: 24px 16px;
        margin: 20px auto;
        width: calc(100% - 16px);
        max-width: 100%;
        border-radius: 8px;
    }

    .login-container h1 {
        font-size: 20px;
        line-height: 1.3;
    }

    .login-container .subtitle {
        font-size: 13px;
    }

    /* Header - Mobile Optimized */
    .header {
        padding: 12px;
        border-radius: 8px;
        flex-direction: column;
        gap: 10px;
    }

    .header-left {
        width: 100%;
        justify-content: flex-start;
        padding: 0;
    }

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

    .header-title {
        font-size: 16px;
        line-height: 1.2;
    }

    .header-subtitle {
        font-size: 10px;
        margin-top: 2px;
    }

    .header-right {
        width: 100%;
        justify-content: space-between;
        gap: 8px;
    }

    .user-info {
        flex: 1;
        min-width: 0;
        padding: 6px 12px;
    }

    .user-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 120px;
    }

    .logout-btn {
        padding: 6px 12px;
        font-size: 12px;
        white-space: nowrap;
    }

    /* Main Container - Mobile Optimized */
    .main-container {
        gap: 10px;
    }

    /* Cards - Mobile Optimized */
    .card {
        border-radius: 10px;
        overflow: hidden;
    }

    .card-header {
        padding: 14px;
        gap: 8px;
    }

    .card-title {
        font-size: 16px;
        line-height: 1.3;
    }

    .card-body {
        padding: 14px;
    }

    /* Status Card - Mobile Optimized */
    .status-card {
        padding: 10px;
        margin-bottom: 12px;
    }

    .status-item {
        font-size: 12px;
        margin-bottom: 10px;
        align-items: flex-start;
    }

    .status-item:last-child {
        margin-bottom: 0;
    }

    .status-icon {
        margin-top: 2px;
    }

    .status-text {
        flex: 1;
        min-width: 0;
        word-wrap: break-word;
    }

    .status-value {
        font-size: 14px;
        font-weight: 700;
    }

    /* Buttons - Mobile Optimized */
    .action-buttons,
    .download-buttons {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .action-btn,
    .download-btn {
        padding: 14px 10px;
        min-height: 85px;
        touch-action: manipulation;
    }

    /* Одиночные кнопки на полную ширину */
    .action-buttons:has(.action-btn:only-child) {
        grid-template-columns: 1fr;
    }

    .btn-icon {
        font-size: 26px;
    }

    .btn-label {
        font-size: 13px;
        line-height: 1.2;
        text-align: center;
    }

    .btn-sublabel {
        font-size: 9px;
        margin-top: 2px;
        text-align: center;
        line-height: 1.2;
    }

    /* Info Box - Mobile Optimized */
    .info-box {
        padding: 10px;
        margin-top: 12px;
    }

    .info-box-title {
        font-size: 12px;
        margin-bottom: 8px;
    }

    .info-item {
        font-size: 11px;
        margin-bottom: 6px;
        line-height: 1.4;
    }

    .info-item:last-child {
        margin-bottom: 0;
    }

    .info-item code {
        font-size: 10px;
        padding: 2px 5px;
        display: inline-block;
        word-break: break-all;
    }

    /* Log Container - Mobile Optimized */
    .log-container {
        height: auto;
        min-height: 350px;
    }

    .log-header {
        padding: 12px;
    }

    .log-box {
        padding: 10px;
        font-size: 10px;
        line-height: 1.5;
        min-height: 250px;
        max-height: 400px;
    }

    /* Forms - Mobile Optimized */
    input[type="text"],
    input[type="password"],
    input[type="number"] {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 10px;
    }

    button[type="submit"] {
        padding: 12px;
        font-size: 15px;
        touch-action: manipulation;
    }

    /* Flash Messages - Mobile Optimized */
    .flash-messages {
        position: fixed;
        top: 8px;
        right: 8px;
        left: 8px;
        max-width: none;
        z-index: 9999;
    }

    .alert {
        font-size: 12px;
        padding: 10px 14px;
        margin-bottom: 8px;
    }
}

/* Extra Small Devices (max-width: 480px) */
@media (max-width: 480px) {
    body {
        padding: 5px;
    }

    .header {
        padding: 10px;
    }

    .header-title {
        font-size: 14px;
    }

    .header-subtitle {
        font-size: 9px;
    }

    .logo {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .user-info {
        padding: 5px 10px;
    }

    .user-avatar {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .user-name {
        font-size: 12px;
        max-width: 100px;
    }

    .logout-btn {
        padding: 5px 10px;
        font-size: 11px;
    }

    .card-header {
        padding: 12px;
    }

    .card-title {
        font-size: 15px;
    }

    .card-body {
        padding: 12px;
    }

    .status-item {
        font-size: 11px;
    }

    .status-icon {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }

    .status-value {
        font-size: 13px;
    }

    .btn-icon {
        font-size: 22px;
    }

    .btn-label {
        font-size: 12px;
    }

    .btn-sublabel {
        font-size: 8px;
    }

    .action-btn,
    .download-btn {
        padding: 12px 8px;
        min-height: 80px;
    }

    .log-box {
        font-size: 9px;
        min-height: 200px;
    }
}

/* Very Small Devices (max-width: 360px) */
@media (max-width: 360px) {
    .header-title {
        font-size: 13px;
    }

    .card-title {
        font-size: 14px;
    }

    .user-name {
        max-width: 80px;
    }

    .status-text,
    .status-value {
        font-size: 11px;
    }

    .action-btn,
    .download-btn {
        padding: 10px 6px;
        min-height: 75px;
    }

    .btn-label {
        font-size: 11px;
    }

    .btn-icon {
        font-size: 20px;
    }

    .btn-sublabel {
        font-size: 7px;
    }
}

/* Landscape Orientation - Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .header {
        padding: 8px 15px;
        flex-direction: row;
    }

    .header-left,
    .header-right {
        width: auto;
    }

    .header-left {
        flex: 1;
    }

    .header-right {
        justify-content: flex-end;
    }

    .log-container {
        min-height: 250px;
    }

    .log-box {
        min-height: 150px;
        max-height: 300px;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .download-btn:hover::before,
    .action-btn:hover::before {
        opacity: 0;
    }

    .download-btn:hover,
    .action-btn:hover,
    .logout-btn:hover,
    .admin-button:hover {
        transform: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    /* Larger touch targets */
    .download-btn,
    .action-btn,
    .logout-btn,
    .admin-button,
    button[type="submit"],
    input[type="submit"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* Better button spacing */
    .action-buttons,
    .download-buttons {
        gap: 12px;
    }

    /* Prevent text selection on buttons */
    button,
    .download-btn,
    .action-btn,
    .logout-btn {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
}

/* Tablet Portrait (768px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
    .main-container {
        grid-template-columns: 1fr;
        max-width: 700px;
        margin: 0 auto;
    }

    .header {
        padding: 18px 30px;
    }

    .card-body {
        padding: 25px;
    }

    .log-container {
        min-height: 450px;
    }
}

/* Tablet Landscape */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: landscape) {
    .main-container {
        grid-template-columns: 1fr 1fr;
        gap: 18px;
    }

    .log-container {
        grid-column: span 2;
        min-height: 400px;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .card,
    .header,
    .login-container {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    }
}

/* Reduce Motion for Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        padding: 0;
    }

    .header,
    .logout-btn,
    .admin-button,
    .toolbar,
    .flash-messages {
        display: none;
    }

    .card {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ddd;
    }

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

/* ========================================
   ЧАСТЬ 2: КОМПЛЕКСНАЯ МОБИЛЬНАЯ АДАПТАЦИЯ
   ======================================== */

/* Общие настройки */
html {
    scroll-behavior: smooth;
}

body {
    touch-action: pan-y;
}

/* Отключение выделения текста для кнопок */
button,
.tool-btn,
.action-btn,
.download-btn {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Планшеты (до 1024px) */
@media (max-width: 1024px) {
    body {
        padding: 12px;
    }

    /* Основной контейнер в одну колонку */
    .main-container {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }

    /* Таблица редактора */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-height: calc(100vh - 400px);
    }

    /* Toolbar на планшетах */
    .toolbar {
        padding: 15px 20px;
        gap: 12px;
    }

    .toolbar-left,
    .toolbar-right {
        width: 100%;
        justify-content: space-between;
    }

    .search-input {
        width: 100%;
        max-width: 100%;
    }
}

/* Мобильные устройства (до 768px) */
@media (max-width: 768px) {

    /* LOGIN СТРАНИЦА */
    .login-container .logo-icon {
        font-size: 40px;
    }

    .login-container .logo h1 {
        font-size: 24px;
    }

    /* HEADER */
    .header {
        flex-direction: row;
        margin-bottom: 12px;
        align-items: center;
    }

    .header-left {
        flex: 1;
        min-width: 0;
    }

    .logo {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .header-right {
        width: auto;
        justify-content: flex-end;
        margin-left: auto;
    }

    .user-info {
        flex: 0 0 auto;
        padding: 8px 14px;
    }

    .user-avatar {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .user-name {
        font-size: 14px;
    }

    .logout-btn {
        padding: 8px 14px;
    }

    .back-btn {
        padding: 8px 14px;
        font-size: 12px;
    }

    /* CARDS */
    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .card-title {
        width: 100%;
    }

    /* STATUS CARD */
    .status-card {
        padding: 12px;
    }

    .status-item {
        align-items: center;
        flex-wrap: nowrap;
        gap: 10px;
    }

    .status-icon {
        width: 28px;
        height: 28px;
        font-size: 14px;
        flex-shrink: 0;
    }

    .status-value {
        flex-shrink: 0;
        white-space: nowrap;
        margin-left: auto;
    }

    /* КНОПКИ */
    .action-btn,
    .download-btn {
        min-height: 90px;
        width: 100%;
    }

    .action-btn:only-child {
        max-width: 100%;
    }

    .btn-icon {
        font-size: 28px;
    }

    .btn-sublabel {
        font-size: 10px;
        margin-top: 3px;
    }

    .tool-btn {
        padding: 10px 14px;
        font-size: 13px;
        width: 100%;
        justify-content: center;
    }

    .admin-button {
        padding: 14px;
        font-size: 14px;
        width: 100%;
    }

    /* INFO BOX */
    .info-box {
        padding: 12px;
        margin-bottom: 12px;
    }

    .info-item {
        line-height: 1.5;
    }

    .info-item code {
        padding: 2px 6px;
    }

    /* LOG CONTAINER */
    .log-container {
        min-height: 300px;
    }

    .log-header {
        font-size: 14px;
    }

    .log-box {
        line-height: 1.6;
        min-height: 200px;
        max-height: 350px;
    }

    /* FORMS */
    input[type="text"],
    input[type="password"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }

    button[type="submit"],
    input[type="submit"] {
        padding: 12px;
        font-size: 15px;
    }

    /* TOOLBAR (EDITOR) */
    .toolbar {
        flex-direction: column;
    }

    .toolbar-left,
    .toolbar-right {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .search-box {
        width: 100%;
    }

    .search-input {
        font-size: 14px;
        padding: 10px 40px 10px 14px;
    }

    .search-filter {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
    }

    .search-filter-select {
        width: 100%;
        font-size: 14px;
        padding: 10px;
    }

    .search-info {
        font-size: 12px;
        padding: 8px 12px;
        text-align: center;
    }

    /* TABLE (EDITOR) */
    .table-wrapper {
        -webkit-overflow-scrolling: touch;
        max-height: calc(100vh - 450px);
        border-radius: 8px;
    }

    .data-table {
        font-size: 11px;
        min-width: 100%;
    }

    .data-table th {
        padding: 10px 6px;
        font-size: 11px;
        white-space: nowrap;
    }

    .data-table td {
        padding: 8px 6px;
        min-width: 80px;
    }

    .select-col {
        width: 35px;
        min-width: 35px !important;
    }

    .row-num-col {
        width: 40px;
        min-width: 40px !important;
        font-size: 10px;
    }

    /* Фиксированные колонки на мобильных */
    .select-col,
    .row-num-col {
        position: sticky;
        left: 0;
        background: inherit;
        z-index: 5;
    }

    .row-num-col {
        left: 35px;
    }

    /* Поля ввода в таблице */
    .data-table input[type="text"],
    .data-table input[type="number"],
    .data-table select {
        font-size: 12px;
        padding: 6px;
        width: 100%;
        min-width: 70px;
    }

    .data-table textarea {
        font-size: 12px;
        padding: 6px;
        min-height: 60px;
    }

    /* Кнопки в таблице */
    .action-cell {
        display: flex;
        gap: 4px;
        flex-wrap: wrap;
    }

    .action-cell .tool-btn {
        padding: 6px 10px;
        font-size: 11px;
        min-width: auto;
    }

    /* MODAL */
    .modal {
        padding: 10px;
    }

    .modal-content {
        width: calc(100% - 20px);
        max-width: 100%;
        max-height: calc(100vh - 40px);
        margin: 20px auto;
        border-radius: 12px;
    }

    .modal-header {
        padding: 16px;
    }

    .modal-title {
        font-size: 18px;
    }

    .modal-body {
        padding: 16px;
        max-height: calc(100vh - 200px);
        overflow-y: auto;
    }

    .modal-footer {
        padding: 16px;
        flex-direction: column-reverse;
        gap: 10px;
    }

    .modal-footer .tool-btn,
    .modal-footer button {
        width: 100%;
    }

    /* FORM GROUPS в модальном окне */
    .form-group {
        margin-bottom: 16px;
    }

    .form-group label {
        font-size: 13px;
        margin-bottom: 6px;
    }

    /* WAREHOUSE PAGE */
    .warehouse-filters {
        flex-direction: column;
        gap: 10px;
    }

    .filter-group {
        width: 100%;
    }

    .warehouse-stats {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 14px;
    }

    .stat-value {
        font-size: 24px;
    }

    .stat-label {
        font-size: 12px;
    }

    /* REPRICE PAGE */
    .reprice-form {
        padding: 14px;
    }

    .reprice-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .reprice-card {
        padding: 14px;
    }

    /* ORDERS PAGE */
    .orders-filters {
        flex-direction: column;
        gap: 10px;
    }

    .order-card {
        padding: 14px;
    }

    .order-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .order-products {
        padding: 10px;
    }

    /* SETTINGS PAGE */
    .settings-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .setting-card {
        padding: 16px;
    }

    .setting-input {
        font-size: 14px;
        padding: 10px;
    }

    /* KASPI UPLOAD PAGE */
    .upload-area {
        padding: 30px 16px;
    }

    .upload-icon {
        font-size: 48px;
    }

    .upload-text {
        font-size: 14px;
    }

    .file-info {
        padding: 12px;
        font-size: 12px;
    }

    /* GLOBAL MINIMIZED WINDOWS */
    .global-minimized-container {
        bottom: 10px;
        left: 10px;
        right: 10px;
        max-width: calc(100% - 20px);
    }

    .global-minimized-window {
        min-width: auto;
        width: 100%;
        padding: 10px 14px;
    }

    .global-minimized-title {
        font-size: 13px;
    }

    .global-minimized-subtitle {
        font-size: 11px;
    }

    /* GLOBAL FULL MODAL */
    .global-full-modal-content {
        width: calc(100% - 20px);
        max-width: 100%;
        margin: 10px;
    }

    .global-full-modal-header {
        padding: 16px 20px;
    }

    .global-modal-title {
        font-size: 18px;
    }

    .global-full-modal-body {
        padding: 20px;
    }

    .global-modal-info {
        padding: 14px;
        flex-direction: column;
        text-align: center;
    }

    .global-modal-actions {
        gap: 10px;
    }

    .btn-global-continue,
    .btn-global-cancel {
        font-size: 14px;
        padding: 12px 20px;
    }

    /* КАТЕГОРИИ В МОДАЛЬНОМ ОКНЕ */
    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .category-card {
        padding: 16px;
        min-height: 100px;
    }

    .category-icon {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .category-name {
        font-size: 12px;
    }

    .category-count {
        font-size: 10px;
    }

    /* TABS */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }

    .tab-btn {
        padding: 10px 16px;
        font-size: 13px;
        white-space: nowrap;
    }

    /* PAGINATION */
    .pagination {
        flex-wrap: wrap;
        gap: 6px;
        justify-content: center;
    }

    .pagination button {
        padding: 8px 12px;
        font-size: 12px;
        min-width: 36px;
    }
}

/* Маленькие мобильные (до 480px) */
@media (max-width: 480px) {
    body {
        padding: 6px;
    }

    /* HEADER */
    .header {
        padding: 10px;
    }

    .logo {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }

    .header-title {
        font-size: 14px;
    }

    .header-subtitle {
        font-size: 9px;
    }

    .user-info {
        padding: 6px 10px;
    }

    .user-avatar {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    .user-name {
        font-size: 12px;
        max-width: 100px;
    }

    .logout-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    /* CARDS */
    .card-header {
        padding: 12px;
    }

    .card-title {
        font-size: 15px;
    }

    .card-body {
        padding: 12px;
    }

    /* STATUS */
    .status-item {
        font-size: 11px;
    }

    .status-icon {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }

    .status-value {
        font-size: 13px;
    }

    /* BUTTONS */
    .action-btn,
    .download-btn {
        padding: 12px 8px;
        min-height: 85px;
    }

    .btn-icon {
        font-size: 24px;
    }

    .btn-label {
        font-size: 12px;
    }

    .btn-sublabel {
        font-size: 9px;
    }

    .tool-btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    /* LOG */
    .log-box {
        font-size: 9px;
        min-height: 180px;
    }

    /* TABLE */
    .data-table {
        font-size: 10px;
    }

    .data-table th,
    .data-table td {
        padding: 6px 4px;
    }

    /* MODAL */
    .modal-title {
        font-size: 16px;
    }

    .modal-body {
        padding: 14px;
    }

    /* CATEGORIES */
    .categories-grid {
        grid-template-columns: 1fr;
    }

    .category-card {
        padding: 14px;
    }
}

/* Очень маленькие устройства (до 360px) */
@media (max-width: 360px) {
    .header-title {
        font-size: 13px;
    }

    .card-title {
        font-size: 14px;
    }

    .user-name {
        max-width: 80px;
    }

    .status-text,
    .status-value {
        font-size: 11px;
    }

    .action-btn,
    .download-btn {
        padding: 10px 6px;
        min-height: 80px;
    }

    .btn-label {
        font-size: 11px;
    }

    .btn-icon {
        font-size: 22px;
    }

    .btn-sublabel {
        font-size: 8px;
    }
}

/* Горизонтальная ориентация */
@media (max-width: 768px) and (orientation: landscape) {
    .header {
        padding: 10px 16px;
        flex-direction: row;
    }

    .header-left,
    .header-right {
        width: auto;
    }

    .header-left {
        flex: 1;
    }

    .header-right {
        justify-content: flex-end;
        flex-direction: row;
    }

    .log-container {
        min-height: 250px;
    }

    .log-box {
        min-height: 150px;
        max-height: 300px;
    }

    .modal-content {
        max-height: calc(100vh - 30px);
    }

    .modal-body {
        max-height: calc(100vh - 180px);
    }
}

/* Сенсорные устройства */
@media (hover: none) and (pointer: coarse) {
    /* Убираем hover эффекты на сенсорных устройствах */
    .download-btn:hover::before,
    .action-btn:hover::before,
    .tool-btn:hover::before {
        opacity: 0;
    }

    .download-btn:hover,
    .action-btn:hover,
    .logout-btn:hover,
    .admin-button:hover,
    .tool-btn:hover,
    button:hover {
        transform: none;
        box-shadow: inherit;
    }

    /* Увеличенные области нажатия */
    .download-btn,
    .action-btn,
    .logout-btn,
    .admin-button,
    .tool-btn,
    button[type="submit"],
    input[type="submit"],
    a.tool-btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Лучшие отступы между кнопками */
    .action-buttons,
    .download-buttons,
    .toolbar-left,
    .toolbar-right {
        gap: 12px;
    }

    /* Отключение выделения текста */
    button,
    .download-btn,
    .action-btn,
    .logout-btn,
    .tool-btn {
        -webkit-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }

    /* Улучшенная прокрутка */
    .table-wrapper,
    .modal-body,
    .log-box {
        -webkit-overflow-scrolling: touch;
    }
}

/* Планшеты портрет (768px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: portrait) {
    .main-container {
        grid-template-columns: 1fr;
        max-width: 700px;
        margin: 0 auto;
    }

    .header {
        padding: 18px 30px;
    }

    .card-body {
        padding: 25px;
    }

    .log-container {
        min-height: 450px;
    }

    .toolbar {
        padding: 16px 24px;
    }

    .data-table {
        font-size: 12px;
    }
}

/* Планшеты ландшафт */
@media (min-width: 769px) and (max-width: 1024px) and (orientation: landscape) {
    .main-container {
        grid-template-columns: 1fr 1fr;
        gap: 18px;
    }

    .log-container {
        grid-column: span 2;
        min-height: 400px;
    }

    .editor-container {
        grid-column: span 2;
    }
}

/* HIGH DPI дисплеи */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .card,
    .header,
    .login-container,
    .modal-content {
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    }

    /* Более четкие границы */
    .data-table th,
    .data-table td {
        border-width: 0.5px;
    }
}

/* Уменьшенная анимация */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Печать */
@media print {
    .header,
    .logout-btn,
    .admin-button,
    .toolbar,
    .flash-messages,
    .global-minimized-container,
    .action-buttons,
    .tool-btn {
        display: none !important;
    }

    .table-wrapper {
        overflow: visible;
        max-height: none;
    }

    .data-table {
        font-size: 10pt;
    }
}

/* Дополнительные улучшения */

/* Скрытие скроллбара в мобильной версии */
@media (max-width: 768px) {
    .table-wrapper::-webkit-scrollbar {
        height: 6px;
    }

    .table-wrapper::-webkit-scrollbar-track {
        background: #f1f5f9;
        border-radius: 3px;
    }

    .table-wrapper::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 3px;
    }

    .table-wrapper::-webkit-scrollbar-thumb:hover {
        background: #94a3b8;
    }
}

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

/* Безопасные области для устройств с вырезом (notch) */
@supports (padding: max(0px)) {
    body {
        padding-left: max(8px, env(safe-area-inset-left));
        padding-right: max(8px, env(safe-area-inset-right));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    .header {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    .global-minimized-container {
        left: max(10px, env(safe-area-inset-left));
        right: max(10px, env(safe-area-inset-right));
        bottom: max(10px, env(safe-area-inset-bottom));
    }
}

/* ========================================
   ЧАСТЬ 3: ИСПРАВЛЕНИЯ И ФИКСЫ
   ======================================== */

/* Фикс межбуквенного интервала для всего сайта */
* {
    letter-spacing: normal !important;
    word-spacing: normal !important;
}

/* Улучшенный рендеринг текста */
body {
    text-rendering: optimizeLegibility;
    font-feature-settings: 'kern' 1;
}

/* Зеленая рамка у status-card как в десктопной версии */
.status-card {
    border: 2px solid #86efac !important;
}

/* Исправление растянутого имени пользователя */
@media (max-width: 768px) {
    .header {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
    }

    .header-left {
        flex: 1 !important;
        width: auto !important;
    }

    .header-right {
        width: auto !important;
        justify-content: flex-end !important;
        margin-left: auto !important;
        flex: 0 0 auto !important;
    }

    .user-info {
        flex: 0 0 auto !important;
        width: auto !important;
    }

    /* ИСПРАВЛЕНИЕ STATUS CARD */
    .status-card {
        padding: 14px;
        margin-bottom: 14px;
        border-radius: 12px;
    }

    .status-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 10px;
        margin-bottom: 12px;
        font-size: 13px;
        flex-wrap: nowrap;
    }

    .status-item:last-child {
        margin-bottom: 0;
    }

    .status-icon {
        width: 30px;
        height: 30px;
        font-size: 14px;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .status-text {
        flex: 1;
        min-width: 0;
        word-wrap: break-word;
        word-break: break-word;
        color: #166534;
        font-weight: 500;
        line-height: 1.4;
        white-space: normal;
    }

    .status-value {
        font-size: 14px;
        font-weight: 700;
        color: #15803d;
        white-space: nowrap;
        flex-shrink: 0;
        margin-left: auto;
        text-align: right;
    }

    /* Особый случай для длинных значений */
    .status-item.wrap-value .status-value {
        white-space: normal;
        word-break: break-all;
    }

    /* CARD HEADER */
    .card-header {
        gap: 8px;
    }

    .card-title {
        line-height: 1.3;
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .card-title span {
        line-height: 1.3;
    }

    /* CARD BODY */
    .card-body {
        line-height: 1.5;
    }

    /* INFO BOX */
    .info-box {
        line-height: 1.5;
    }

    .info-box-title {
        font-size: 13px;
        line-height: 1.4;
    }

    .info-item {
        font-size: 12px;
        line-height: 1.5;
    }

    /* HEADER */
    .header-title {
        letter-spacing: normal;
    }

    .header-subtitle {
        font-size: 11px;
        line-height: 1.3;
    }

    .user-name {
        line-height: 1.3;
    }

    /* BUTTONS */
    .tool-btn,
    .action-btn,
    .download-btn,
    .logout-btn,
    .back-btn {
        line-height: 1.3;
        text-align: center;
    }

    .btn-label {
        font-size: 14px;
        line-height: 1.3;
    }

    .btn-sublabel {
        font-size: 11px;
        line-height: 1.3;
    }

    /* FORMS */
    input[type="text"],
    input[type="password"],
    input[type="number"],
    textarea,
    select {
        line-height: 1.5;
        letter-spacing: normal;
    }

    /* TABLE */
    .data-table {
        line-height: 1.4;
    }

    .data-table th,
    .data-table td {
        line-height: 1.4;
    }

    /* MODAL */
    .modal-title {
        line-height: 1.3;
    }

    .modal-body {
        line-height: 1.5;
    }

    /* LOG BOX */
    .log-box {
        line-height: 1.6;
        font-family: 'Courier New', 'Monaco', monospace;
    }

    /* PAGINATION */
    .pagination button {
        line-height: 1.3;
    }
}

/* Маленькие мобильные (до 480px) - фиксы */
@media (max-width: 480px) {
    .status-item {
        font-size: 12px;
        gap: 8px;
    }

    .status-icon {
        width: 26px;
        height: 26px;
        font-size: 13px;
    }

    .status-text {
        font-size: 12px;
    }

    .status-value {
        font-size: 13px;
    }

    .card-title {
        font-size: 15px;
    }

    .header-title {
        font-size: 15px;
    }
}

/* Очень маленькие устройства (до 360px) - фиксы */
@media (max-width: 360px) {
    .status-item {
        font-size: 11px;
    }

    .status-icon {
        width: 24px;
        height: 24px;
        font-size: 12px;
    }

    .status-text {
        font-size: 11px;
    }

    .status-value {
        font-size: 12px;
    }

    .card-title {
        font-size: 14px;
    }

    .header-title {
        font-size: 14px;
    }
}

/* Исправление переносов в русском тексте */
@media (max-width: 768px) {
    body {
        hyphens: none;
        -webkit-hyphens: none;
        -ms-hyphens: none;
    }

    /* Предотвращение странного переноса */
    .status-text,
    .card-title,
    .header-title,
    .btn-label {
        hyphens: none;
        -webkit-hyphens: none;
        overflow-wrap: break-word;
        word-wrap: break-word;
    }
}

/* Исправление конкретных проблемных элементов */
@media (max-width: 768px) {
    /* Dashboard статистика */
    .main-container .card .status-card .status-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 10px;
        flex-wrap: nowrap;
    }

    .main-container .card .status-card .status-item .status-icon {
        order: 0;
        flex: 0 0 30px;
    }

    .main-container .card .status-card .status-item .status-text {
        order: 1;
        flex: 1 1 auto;
        min-width: 0;
    }

    .main-container .card .status-card .status-item .status-value {
        order: 2;
        flex: 0 0 auto;
        margin-left: 0;
        width: auto;
    }

    /* Для длинных дат - разрешаем перенос */
    .status-item:has(.status-value:contains("2026-01-02")) .status-value,
    .status-item .status-value:not(:empty) {
        max-width: 45%;
        word-break: break-word;
        white-space: normal;
        text-align: right;
    }

    /* Но для чисел - оставляем nowrap */
    .status-item:has(.status-text:contains("товаров")) .status-value,
    .status-item:has(.status-text:contains("наличии")) .status-value,
    .status-item:has(.status-text:contains("предзаказом")) .status-value,
    .status-item:has(.status-text:contains("файла")) .status-value {
        white-space: nowrap;
        word-break: normal;
    }
}

/* Специальные фиксы для iOS */
@supports (-webkit-touch-callout: none) {
    /* iOS specific fixes */
    @media (max-width: 768px) {
        body {
            -webkit-text-size-adjust: 100%;
        }

        .status-item,
        .card-title,
        .header-title {
            -webkit-font-smoothing: antialiased;
        }
    }
}

/* Улучшение читаемости */
@media (max-width: 768px) {
    /* Оптимальные интервалы для мобильных */
    p, div, span {
        letter-spacing: 0;
        word-spacing: 0;
    }

    /* Улучшенная типографика */
    .status-text,
    .info-item,
    .card-body {
        text-align: left;
        line-height: 1.5;
    }

    /* Предотвращение растягивания текста */
    .status-item {
        text-align: left;
        justify-content: flex-start;
    }
}

/* ========================================
   CARD COLLAPSE - мобильное сворачивание карточек
   ======================================== */
@media (max-width: 768px) {
    /* Кнопка видна только на мобиле */
    .card-collapse-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 30px;
        height: 30px;
        flex-shrink: 0;
        border: none;
        background: #f1f5f9;
        border-radius: 8px;
        cursor: pointer;
        color: #64748b;
        transition: background 0.15s;
        margin-left: auto;
    }
    .card-collapse-btn:hover {
        background: #e2e8f0;
    }

    /* Шапка сворачиваемой карточки - строка с переносом */
    .card.collapsible .card-header {
        flex-direction: row !important;
        flex-wrap: wrap;
        align-items: center;
    }
    .card.collapsible .card-title {
        flex: 1;
        min-width: 0;
    }
    /* Кнопки действий (лог, экспорт) переносятся на следующую строку */
    .card.collapsible .log-buttons {
        width: 100%;
        order: 3;
    }

    /* Тело карточки - плавный collapse */
    .card.collapsible .card-body {
        overflow: hidden;
        max-height: 4000px;
        opacity: 1;
        transition: max-height 0.35s ease, opacity 0.25s ease, padding 0.2s ease;
    }
    .card.collapsible.collapsed .card-body {
        max-height: 0 !important;
        opacity: 0;
        padding-top: 0;
        padding-bottom: 0;
    }
    /* Кнопки логов скрываются при сворачивании */
    .card.collapsible.collapsed .log-buttons {
        display: none !important;
    }

    /* Шеврон поворачивается при сворачивании */
    .card.collapsed .card-collapse-chevron {
        transform: rotate(-90deg);
    }
}
