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

/* Стили для больших экранов (десктоп) - по умолчанию */
.header-table {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.header-cell {
    display: block;
}

.header-title {
    flex: 1;
}

.header-buttons {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-buttons button {
    margin-left: 0;
    font-size: 0.875rem;
    padding: 0.375rem 0.75rem;
}

/* Общие стили для мобильных устройств */
@media (max-width: 991.98px) {
    /* Уменьшение размера текста и отступов */
    body {
        font-size: 14px;
    }
    
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }
    
    .card {
        margin-bottom: 1rem;
    }
    
    .card-header {
        padding: 0.75rem;
    }
    
    /* Адаптация шапки */
    header h1 {
        font-size: 1.5rem;
    }
    
    /* Адаптивные кнопки */
    .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
    
    /* Стиль для адаптивных таблиц */
    .table-responsive-adaptive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Убираем фиксированные ширины столбцов таблицы на мобильных */
    #orders-table th,
    #orders-table td {
        width: auto !important;
        min-width: unset !important;
        max-width: unset !important;
        white-space: nowrap;
    }
    
    /* Модификация карточек дашборда */
    #dashboard .card {
        margin-bottom: 0.5rem;
    }
    
    #dashboard .card-body {
        padding: 0.75rem;
    }
    
    #dashboard h5.card-title {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }
    
    #dashboard h2 {
        font-size: 1.5rem;
        margin-bottom: 0;
    }
    
    /* Улучшение панели фильтров */
    .card-body .d-flex.flex-wrap {
        gap: 0.5rem !important;
    }
    
    .date-filter {
        padding: 0.25rem 0.4rem;
        font-size: 0.7rem;
    }
    
    /* Стили для активного фильтра на мобильных */
    .date-filter.active {
        background-color: #007bff !important;
        border-color: #007bff !important;
        color: white !important;
    }
    
    /* Адаптация модальных окон */
    .modal-dialog {
        margin: 0.5rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    /* Альтернативное отображение карточек для малых экранов */
    .card-view-item {
        border: 1px solid #dee2e6;
        border-radius: 0.5rem;
        padding: 0.75rem;
        margin-bottom: 0.75rem;
        background-color: #fff;
        box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
    }
    
    .card-view-item .item-header {
        font-weight: bold;
        margin-bottom: 0.5rem;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .card-view-item .badge {
        margin-left: auto;
    }
    
    .card-view-item .item-body {
        font-size: 0.85rem;
    }
    
    .card-view-item .item-row {
        display: flex;
        margin-bottom: 0.25rem;
    }
    
    .card-view-item .item-label {
        width: 120px;
        color: #6f7d6c;
    }
    
    .card-view-item .item-actions {
        display: flex;
        justify-content: flex-end;
        gap: 0.5rem;
        margin-top: 0.75rem;
        border-top: 1px solid #eee;
        padding-top: 0.75rem;
    }
}

/* Улучшенные стили для карточного представления на мобильных */
@media (max-width: 767.98px) {
    /* Стилизация карточек для лучшего отображения на мобильных */
    .card-view-item {
        padding: 15px;
        border-radius: 8px;
        margin-bottom: 15px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        border: 1px solid #e0e0e0;
        background: white;
        text-align: left;
    }
    
    .card-view-item .item-header {
        padding-bottom: 10px;
        margin-bottom: 12px;
        border-bottom: 1px solid #eee;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
    }
    
    .card-view-item .item-header .customer-name {
        font-size: 1rem;
        font-weight: 600;
        color: #333;
        text-align: left;
        flex: 1;
        margin: 0;
        white-space: normal;
        overflow: hidden;
        text-overflow: ellipsis;
        min-width: 0;
        display: block !important;
        visibility: visible !important;
        line-height: 1.3;
        margin-right: 8px;
    }
    
    /* Скрываем номер строки на мобильных */
    .card-view-item .item-header .row-number {
        display: none;
    }
    
    .card-view-item .item-header .status-badge {
        margin-left: 8px;
        font-size: 0.9rem;
        padding: 0;
        border-radius: 50%;
        font-weight: 500;
        white-space: nowrap;
        flex: 0 0 auto;
        flex-shrink: 0;
        text-align: center;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 24px;
        height: 24px;
        line-height: 1;
        border: none;
        position: relative;
    }
    
    .card-view-item .item-header .status-badge {
        font-size: 0 !important;
        text-indent: -9999px !important;
        overflow: hidden !important;
        color: transparent !important;
    }
    
    .card-view-item .item-header .status-badge * {
        display: none !important;
    }
    
    .card-view-item .item-header .status-badge::before {
        display: block !important;
        position: absolute !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        font-size: 0.8rem !important;
        text-indent: 0 !important;
        color: inherit !important;
    }
    
    /* Цветовые схемы для статус-кружков в мобильных карточках */
    .card-view-item .status-badge.bg-success,
    .card-view-item .status-badge[data-status="Выполнен"] {
        background-color: #28a745 !important;
        color: white !important;
    }
    
    .card-view-item .status-badge.bg-success::before,
    .card-view-item .status-badge[data-status="Выполнен"]::before {
        content: "✓";
        font-size: 0.8rem;
        font-weight: bold;
        color: white !important;
    }
    
    .card-view-item .status-badge.bg-danger,
    .card-view-item .status-badge[data-status="Отменен"] {
        background-color: #dc3545 !important;
        color: white !important;
    }
    
    .card-view-item .status-badge.bg-danger::before,
    .card-view-item .status-badge[data-status="Отменен"]::before {
        content: "−";
        font-size: 1rem;
        font-weight: bold;
        color: white !important;
    }
    
    /* Все остальные статусы - часики */
    .card-view-item .status-badge.bg-primary,
    .card-view-item .status-badge.bg-warning,
    .card-view-item .status-badge.bg-info,
    .card-view-item .status-badge.bg-secondary,
    .card-view-item .status-badge[data-status="Новый"],
    .card-view-item .status-badge[data-status="В обработке"],
    .card-view-item .status-badge[data-status="Оплачен"],
    .card-view-item .status-badge[data-status="Доставляется"] {
        background-color: #ffc107 !important;
        color: #212529 !important;
    }
    
    .card-view-item .status-badge.bg-primary::before,
    .card-view-item .status-badge.bg-warning::before,
    .card-view-item .status-badge.bg-info::before,
    .card-view-item .status-badge.bg-secondary::before,
    .card-view-item .status-badge[data-status="Новый"]::before,
    .card-view-item .status-badge[data-status="В обработке"]::before,
    .card-view-item .status-badge[data-status="Оплачен"]::before,
    .card-view-item .status-badge[data-status="Доставляется"]::before {
        content: "🕐";
        font-size: 0.7rem;
        color: #212529 !important;
    }
    
    /* Принудительно показываем карточки на мобильных */
    #orders-table-container {
        display: none !important;
    }
    
    #card-view-container {
        display: block !important;
    }
    
    /* Стили для таблицы внутри карточки - обычная двухколоночная таблица */
    .card-view-item .order-details-table {
        font-size: 0.9rem;
        margin-bottom: 0;
        width: 100%;
        display: table;
    }
    
    .card-view-item .order-details-table tbody {
        display: table-row-group;
    }
    
    .card-view-item .order-details-table tr {
        display: table-row;
        border: none;
    }
    
    .card-view-item .order-details-table td {
        padding: 0.3rem 0.5rem;
        border: none;
        vertical-align: top;
        line-height: 1.3;
        display: table-cell;
    }
    
    .card-view-item .order-details-table .detail-label {
        font-weight: 600;
        color: #666;
        font-size: 0.85rem;
        text-align: left;
        white-space: nowrap;
        width: 110px;
    }
    
    .card-view-item .order-details-table .detail-label::after {
        content: "";
    }
    
    .card-view-item .order-details-table td:not(.detail-label) {
        font-size: 0.9rem;
        word-wrap: break-word;
        word-break: break-word;
        white-space: normal;
        text-align: left;
        overflow-wrap: break-word;
        line-height: 1.3;
        color: #333;
        font-weight: 500;
    }
    
    .card-view-item .total-price {
        color: #28a745 !important;
        font-weight: bold !important;
        font-size: 0.95rem !important;
    }
    
    /* Стили для строк таблицы в карточке */
    .card-view-item .order-details-table tr {
        border-bottom: 1px solid #f8f9fa;
    }
    
    .card-view-item .order-details-table tr:last-child {
        border-bottom: none;
    }
    
    .card-view-item .order-details-table tr:hover {
        background-color: #f8f9fa;
    }
    
    /* Особый стиль для комментария */
    .card-view-item .comment {
        font-style: italic;
        color: #6c757d !important;
        word-break: break-word;
        word-wrap: break-word;
        white-space: normal;
        overflow-wrap: break-word;
        line-height: 1.4;
        font-size: 0.85rem;
    }
    
    .card-view-item .comment:empty::before {
        content: "Нет комментария";
        color: #dee2e6;
    }
    
    /* Специальные стили для ячейки с комментарием */
    .card-view-item .order-details-table td.comment,
    .card-view-item .order-details-table td:has(.comment) {
        white-space: normal !important;
        word-break: break-word;
        overflow-wrap: break-word;
        max-width: 0;
        width: 100%;
    }
    
    /* Скрываем кнопки переключения вида на мобильных */
    .view-toggle {
        display: none !important;
    }
    
    /* Скрываем быстрые фильтры по дате на мобильных */
    .date-filters-container {
        display: none !important;
    }
    
    /* Отображение заголовка */
    header h1 {
        font-size: 1.2rem;
        margin-bottom: 0;
        line-height: 1.2;
    }
    
    /* Табличная структура для шапки на мобильных */
    .header-table {
        display: table;
        width: 100%;
        table-layout: fixed;
    }
    
    .header-cell {
        display: table-cell;
        vertical-align: middle;
    }
    
    .header-title {
        width: auto;
        text-align: left;
        padding-right: 10px;
    }
    
    .header-buttons {
        width: 40px;
        text-align: right;
        white-space: nowrap;
    }
    
    .header-title h1 {
        font-size: 1.3rem;
        white-space: nowrap;
        margin: 0;
    }
    
    #logout-btn {
        background-color: #6c757d !important;
        border-color: #6c757d !important;
        color: white !important;
        width: 32px !important;
        height: 24px !important;
        padding: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 2px !important;
        font-size: 0.8rem !important;
        margin-left: 4px !important;
    }
    
    #logout-btn:hover {
        background-color: #5a6268 !important;
        border-color: #545b62 !important;
    }
    
    #logout-btn span {
        display: none !important;
    }
    
    /* Уменьшаем пространство в карточке заказов */
    .card-header {
        padding: 10px 15px;
    }
    
    .card-body {
        padding: 10px 15px;
    }
}

/* Стили для iPad и планшетов (768px - 991px) */
@media (min-width: 768px) and (max-width: 991.98px) {
    /* Возвращаем нормальную структуру для планшетов */
    .header-table {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .header-cell {
        display: block;
    }
    
    .header-title {
        width: auto;
        flex: 1;
    }
    
    .header-buttons {
        width: auto;
        flex-shrink: 0;
    }
    
    #logout-btn {
        width: 32px !important;
        height: 32px !important;
        font-size: 0.9rem !important;
        margin-left: 8px !important;
        border-radius: 2px !important;
    }
    
    /* Специфичные адаптации для iPad */
    table {
        font-size: 0.85rem;
    }
    
    .table td, .table th {
        padding: 0.5rem;
    }
    
    /* Адаптация кнопок в заголовке */
    .card-header .d-flex {
        flex-wrap: wrap;
    }
    
    .card-header .btn-lg {
        padding: 0.5rem 1rem;
        font-size: 1rem;
    }
}

/* Стили для устройств с очень малым экраном */
@media (max-width: 575.98px) {
    /* Изменение размеров шрифтов */
    body {
        font-size: 13px;
    }
    
    h1, h2, h3, h4, h5, h6 {
        margin-bottom: 0.5rem;
    }
    
    /* Компактные стили для очень маленьких экранов */
    .header-title h1 {
        font-size: 1.1rem;
    }
    
    /* Еще меньше кнопки, но квадратная */
    #logout-btn {
        width: 28px !important;
        height: 20px !important;
        font-size: 0.7rem !important;
        border-radius: 1px !important;
    }
    
    .header-buttons {
        width: 36px;
    }
    
    /* Уменьшение отступов */
    .container-fluid {
        padding-left: 8px;
        padding-right: 8px;
    }
    
    /* Модификация карточек */
    .card {
        margin-bottom: 0.75rem;
    }
    
    .card-header {
        padding: 0.5rem 0.75rem;
    }
    
    .card-body {
        padding: 0.75rem;
    }
    
    /* Оптимизация кнопок */
    .btn-group-sm > .btn, .btn-sm {
        padding: 0.2rem 0.4rem;
        font-size: 0.7rem;
    }
}

/* Дополнительные стили для лучшего отображения статус-бейджей в карточках */
.card-view-item .item-header .status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px !important;
    height: 24px !important;
    border-radius: 50% !important;
    text-align: center;
    line-height: 1;
    padding: 0 !important;
    min-width: unset !important;
    max-width: unset !important;
}

/* Responsive adjustments для очень маленьких экранов */
@media (max-width: 480px) {
    .card-view-item .item-header .status-badge {
        width: 22px !important;
        height: 22px !important;
        border-radius: 50% !important;
        padding: 0 !important;
        min-width: unset !important;
    }
    
    .card-view-item .item-header .customer-name {
        font-size: 0.9rem;
    }
}

/* Стили для модального окна на мобильных устройствах */
@media (max-width: 767.98px) {
    /* Компактное расположение полей товара в модальном окне */
    #orderModal .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    #orderModal .modal-body {
        padding: 1rem 0.75rem;
    }
    
    /* Поля товара в одну строку на мобильных */
    #orderModal .row.g-2.align-items-end {
        gap: 0.25rem !important;
        align-items: flex-start !important;
        display: flex !important;
    }
    
    #orderModal .row.g-2.align-items-end .col-md-6 {
        flex: 1 1 50% !important;
        max-width: 50% !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
    }
    
    #orderModal .row.g-2.align-items-end .col-md-3 {
        flex: 1 1 25% !important;
        max-width: 25% !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
    }
    
    /* Уменьшение отступов между полями */
    #orderModal .form-label.mb-1 {
        margin-bottom: 0.25rem !important;
        font-size: 0.85rem;
        font-weight: 500;
        line-height: 1.2;
    }
    
    /* Выравнивание полей */
    #orderModal .row.g-2.align-items-end > div {
        display: flex;
        flex-direction: column;
        height: auto;
        justify-content: flex-start;
    }
    
    /* Одинаковая высота лейблов */
    #orderModal .row.g-2.align-items-end .form-label {
        margin-bottom: 0.25rem !important;
        height: 1.2em;
        flex-shrink: 0;
        display: flex;
        align-items: flex-end;
    }
    
    /* Поднимаем поля цены и количества */
    #orderModal .row.g-2.align-items-end .col-md-3 .form-label {
        margin-top: -0.1rem;
    }
    
    /* Компактные поля ввода */
    #orderModal .form-control {
        padding: 0.4rem 0.5rem;
        font-size: 0.9rem;
        margin-top: auto;
    }
    
    /* Специальное выравнивание для полей цены и количества */
    #orderModal .row.g-2.align-items-end .col-md-3 .form-control {
        margin-top: 0.1rem;
    }
    
    /* Адаптация кнопки добавления товара */
    #orderModal #add-product-btn {
        padding: 0.5rem;
        font-size: 0.85rem;
        margin-top: 0.5rem;
    }
    
    /* Стили для тегов товаров на мобильных */
    #orderModal .products-tags {
        margin-top: 0.75rem !important;
    }
    
    /* Компактные поля телефона и имени клиента */
    #orderModal .row:first-child .col-md-6 {
        margin-bottom: 0.75rem;
    }
    
    /* Уменьшение отступов в модальном окне */
    #orderModal .mb-3 {
        margin-bottom: 0.75rem !important;
    }
    
    /* Адаптация селекта статуса и менеджера */
    #orderModal .manager-selection {
        font-size: 0.9rem;
    }
    
    #orderModal .manager-item {
        padding: 0.4rem 0.6rem;
        font-size: 0.85rem;
    }
    
    /* Компактный комментарий */
    #orderModal textarea.form-control {
        padding: 0.5rem;
        font-size: 0.9rem;
    }
    
    /* Адаптация заголовка модального окна */
    #orderModal .modal-header {
        padding: 0.75rem;
    }
    
    #orderModal .modal-title {
        font-size: 1.1rem;
    }
    
    /* Адаптация футера модального окна */
    #orderModal .modal-footer {
        padding: 0.75rem;
        gap: 0.5rem;
    }
    
    #orderModal .modal-footer .btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
}

/* Дополнительные стили для очень маленьких экранов */
@media (max-width: 480px) {
    /* Еще более компактное расположение полей товара */
    #orderModal .row.g-2.align-items-end .col-md-6 {
        flex: 1 1 45% !important;
        max-width: 45% !important;
    }
    
    #orderModal .row.g-2.align-items-end .col-md-3:first-of-type {
        flex: 1 1 30% !important;
        max-width: 30% !important;
    }
    
    #orderModal .row.g-2.align-items-end .col-md-3:last-of-type {
        flex: 1 1 25% !important;
        max-width: 25% !important;
    }
    
    /* Еще меньшие поля и шрифты */
    #orderModal .form-control {
        padding: 0.35rem 0.4rem;
        font-size: 0.85rem;
    }
    
    #orderModal .form-label.mb-1 {
        font-size: 0.8rem;
    }
}

/* Улучшенные стили для карточного представления на мобильных */
@media (max-width: 767.98px) {
    /* Дашборд карточки в две колонки на мобильных */
    #dashboard {
        margin-bottom: 1rem;
    }
    
    #dashboard .row {
        margin: 0 -5px;
    }
    
    #dashboard .col-md-3 {
        padding: 0 5px;
        margin-bottom: 10px;
        flex: 0 0 50%;
        max-width: 50%;
        display: flex;
        flex-direction: column;
        height: 95px;
    }
    
    #dashboard .card {
        margin-bottom: 0;
        height: 100%;
        min-height: 95px;
        max-height: 95px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    #dashboard .card-body {
        padding: 0.6rem 0.4rem;
        text-align: center;
        display: flex;
        flex-direction: column;
        justify-content: center;
        flex: 1;
        align-items: center;
    }
    
    #dashboard .card-title {
        font-size: 0.85rem !important;
        margin-bottom: 0.3rem !important;
        line-height: 1.2;
        font-weight: 600;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    #dashboard h2 {
        font-size: 1.4rem !important;
        margin-bottom: 0 !important;
        font-weight: bold;
        line-height: 1.1;
    }
    
    #dashboard .card-title i {
        font-size: 0.75rem;
        margin-right: 0.3rem;
    }
    
    /* Стили для активного состояния карточек дашборда в мобильной версии */
    #dashboard .card.dashboard-active {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
        color: white !important;
        transform: translateY(-3px);
        box-shadow: 0 0.5rem 1rem rgba(102, 126, 234, 0.4) !important;
        border: 2px solid rgba(255, 255, 255, 0.3) !important;
    }
    
    #dashboard .card.dashboard-active .card-title,
    #dashboard .card.dashboard-active .card-title i,
    #dashboard .card.dashboard-active h2 {
        color: white !important;
    }
    
    #dashboard .card.dashboard-active .text-dark {
        color: rgba(255, 255, 255, 0.9) !important;
    }
    
    /* Добавляем pointer cursor для кликабельности */
    #dashboard .card {
        cursor: pointer;
        transition: all 0.3s ease;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    #dashboard .card:hover {
        transform: translateY(-2px);
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
    }
    
    #dashboard .card:active {
        transform: translateY(0);
        transition: transform 0.1s ease;
    }
}
