/* ПростоСклад: общий мобильный слой для основного сервиса. */

@media (max-width: 640px) {
    html,
    body {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    body {
        background: #f3f6fa;
        font-size: 13.5px;
        font-weight: 700;
    }

    .main {
        width: 100%;
        max-width: 100%;
        margin: 10px 0;
        padding: 0 8px;
    }

    .primary-topbar {
        padding: 8px 10px;
        gap: 8px;
        border-bottom-color: rgba(255, 255, 255, 0.08);
        background: linear-gradient(180deg, #111c31, #0a1020);
    }

    .primary-brand {
        min-height: 36px;
        padding-right: 92px;
        font-size: 16px;
    }

    .brand-mark {
        width: 26px;
        height: 26px;
        border-radius: 7px;
    }

    .primary-right {
        right: 8px;
        top: 8px;
        gap: 4px;
    }

    .appbar-user,
    .appbar-tenant {
        display: none;
    }

    .primary-icon-link,
    .appbar-logout {
        width: 32px;
        height: 32px;
        padding: 0;
        align-items: center;
        justify-content: center;
    }

    .primary-nav {
        order: 3;
        width: 100%;
        flex-basis: 100%;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-auto-flow: row;
        gap: 6px;
        margin: 0 -2px;
        padding: 3px 2px 4px;
        overflow: visible;
        scroll-snap-type: none;
    }

    .primary-link {
        min-width: 0;
        min-height: 38px;
        justify-content: center;
        padding: 0 7px;
        border-radius: 10px;
        font-size: 11.5px;
        font-weight: 900;
        scroll-snap-align: start;
        background: rgba(255, 255, 255, 0.045);
        border-color: rgba(255, 255, 255, 0.075);
        overflow: hidden;
    }

    .primary-link span:last-child {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .primary-ico .icon,
    .primary-icon-link .icon {
        width: 16px;
        height: 16px;
    }

    .subtabs {
        top: 104px;
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: max-content;
        min-height: 40px;
        padding: 5px 10px;
        gap: 5px;
        overflow-x: auto;
        scroll-snap-type: x proximity;
    }

    .subtab {
        min-height: 30px;
        padding: 0 10px;
        border-radius: 9px;
        font-size: 12px;
        font-weight: 900;
        scroll-snap-align: start;
    }

    .toolbar,
    .doc-header,
    .doc-title,
    .doc-actions,
    .form-actions,
    .doc-footer-actions,
    .table-tools,
    .table-tools-left,
    .table-tools-actions,
    .bulk-bar,
    .price-preview-head,
    .li-toolbar,
    .lines-totals {
        width: 100%;
        max-width: 100%;
        gap: 7px;
    }

    .table-tools-standard {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 8px;
        padding: 8px;
        border-radius: 10px;
    }

    .table-tools-standard .table-tools-left {
        min-width: 0;
        width: 100%;
    }

    .table-tools-standard .table-filter {
        width: 100%;
    }

    .table-tools-standard .table-count {
        display: none;
    }

    .table-tools-standard .table-tools-actions {
        display: none;
    }

    .table-tools-standard .li-cols,
    .table-tools-standard .list-cols-wrap {
        width: auto;
        margin-left: 0;
    }

    .table-tools-standard .li-cols-btn,
    .table-tools-standard .lc-btn {
        width: 38px;
        min-width: 38px;
        max-width: 38px;
        padding: 0;
        overflow: hidden;
        color: transparent;
        position: relative;
    }

    .table-tools-standard .li-cols-btn::first-letter,
    .table-tools-standard .lc-btn::first-letter {
        color: #172033;
    }

    .toolbar,
    .doc-header,
    .price-preview-head {
        align-items: stretch;
    }

    .toolbar h1,
    .doc-title h1,
    .form-card h1 {
        font-size: 20px;
        line-height: 1.15;
    }

    .toolbar form,
    .doc-actions,
    .form-actions,
    .doc-footer-actions,
    .li-toolbar {
        display: flex;
        flex-wrap: wrap;
    }

    .toolbar form,
    .toolbar input[type="text"],
    .toolbar input[type="search"],
    .toolbar select,
    .field input,
    .field select,
    .field textarea,
    .table-filter,
    .li-price-type,
    .btn-primary,
    .btn-secondary,
    .btn-danger,
    .btn-primary-small,
    .table-tool-btn,
    .bulk-act,
    .bulk-clear {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    .btn-primary,
    .btn-secondary,
    .btn-danger,
    .btn-primary-small,
    .table-tool-btn,
    .bulk-act {
        min-height: 38px;
        border-radius: 10px;
        font-weight: 900;
    }

    .doc-actions .btn-primary,
    .doc-actions .btn-secondary,
    .doc-actions .btn-danger,
    .doc-actions .btn-primary-small,
    .form-actions .btn-primary,
    .form-actions .btn-secondary,
    .form-actions .btn-danger,
    .form-actions .btn-primary-small,
    .doc-footer-actions .btn-primary,
    .doc-footer-actions .btn-secondary,
    .doc-footer-actions .btn-danger,
    .doc-footer-actions .btn-primary-small {
        flex: 1 1 150px;
    }

    .form-card,
    .doc-section,
    .card,
    .plugin-card,
    .empty,
    .empty-state {
        max-width: 100%;
        padding: 12px;
        border-radius: 10px;
    }

    .doc-grid,
    .filter-grid,
    .price-config-head,
    .price-builder-grid,
    .feature-list,
    .cards {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    .split-layout,
    .plugin-hero,
    .plugin-card,
    .sys-row {
        flex-direction: column;
        align-items: stretch;
    }

    .subsidebar {
        width: 100%;
        padding-right: 0;
    }

    .doc-summary {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .ds-item {
        padding: 9px 10px;
    }

    .ds-value,
    .cell-stack,
    .cell-sub,
    .badge {
        min-width: 0;
        max-width: 100%;
        overflow-wrap: anywhere;
    }

    .badge {
        width: fit-content;
        white-space: normal;
        padding: 3px 8px;
        font-size: 10.5px;
    }

    .status-picker,
    .status-picker summary,
    .doc-status-group,
    .doc-status-actions {
        width: 100%;
    }

    .doc-status-panel {
        padding: 8px;
        gap: 8px;
    }

    .status-picker summary {
        justify-content: space-between;
    }

    .status-picker-value {
        max-width: calc(100vw - 128px);
    }

    .status-picker-menu,
    .li-cols-menu {
        left: 0;
        right: 0;
        min-width: 0;
        max-width: calc(100vw - 24px);
    }

    .table-wrap,
    .list-table-wrap,
    .table-scroll,
    .doc-section:has(> .table:not(.lines-table)),
    .form-card:has(> .table:not(.lines-table)) {
        overflow-x: visible;
    }

    .table.list-table,
    .report-table,
    .dash-table {
        display: block;
        width: 100%;
        min-width: 0;
        overflow: visible;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        background: transparent;
    }

    .table.list-table thead,
    .report-table thead,
    .dash-table thead {
        display: none;
    }

    .table.list-table tbody,
    .table.list-table tfoot,
    .report-table tbody,
    .report-table tfoot,
    .dash-table tbody {
        display: grid;
        min-width: 0;
        width: 100%;
        gap: 8px;
    }

    .table.list-table tr,
    .report-table tr,
    .dash-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 0;
        min-width: 0;
        width: 100%;
        padding: 10px 11px;
        background: #fff;
        border: 1px solid #d0d7e2;
        border-radius: 12px;
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    }

    .table.list-table tbody tr:hover td,
    .report-table tbody tr:hover td,
    .dash-table tbody tr:hover td {
        background: transparent;
    }

    .table.list-table th,
    .table.list-table td,
    .report-table th,
    .report-table td,
    .dash-table td {
        display: grid;
        grid-template-columns: minmax(92px, 38%) minmax(0, 1fr);
        align-items: start;
        gap: 8px;
        width: 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        height: auto;
        padding: 6px 0 !important;
        border: 0 !important;
        color: #172033;
        font-size: 13px;
        line-height: 1.25;
        text-align: left !important;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .table.list-table td::before,
    .report-table td::before,
    .dash-table td::before {
        content: attr(data-mobile-label);
        color: #667085;
        font-size: 11px;
        font-weight: 900;
        line-height: 1.25;
        text-transform: uppercase;
    }

    .table.list-table td:not([data-mobile-label])::before,
    .table.list-table td[data-mobile-label=""]::before,
    .report-table td:not([data-mobile-label])::before,
    .report-table td[data-mobile-label=""]::before,
    .dash-table td:not([data-mobile-label])::before,
    .dash-table td[data-mobile-label=""]::before {
        content: none;
    }

    .table.list-table td:not([data-mobile-label]),
    .table.list-table td[data-mobile-label=""],
    .report-table td:not([data-mobile-label]),
    .report-table td[data-mobile-label=""],
    .dash-table td:not([data-mobile-label]),
    .dash-table td[data-mobile-label=""] {
        display: block;
    }

    .table.list-table td:has(> input[type="checkbox"]),
    .report-table td:has(> input[type="checkbox"]) {
        display: flex;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        padding: 0 0 4px !important;
    }

    .table.list-table td:has(> input[type="checkbox"])::before,
    .report-table td:has(> input[type="checkbox"])::before {
        content: none;
    }

    .table.list-table input[type="checkbox"],
    .report-table input[type="checkbox"] {
        width: 18px;
        height: 18px;
    }

    .table.list-table .num,
    .report-table .num,
    .dash-table .num {
        text-align: left !important;
    }

    .table.list-table .actions,
    .report-table .actions {
        display: flex !important;
        grid-template-columns: none;
        flex-wrap: wrap;
        gap: 6px;
        padding-top: 8px !important;
        border-top: 1px solid #e5eaf1 !important;
    }

    .table.list-table .actions::before,
    .report-table .actions::before {
        content: none;
    }

    .table.list-table .actions a,
    .table-actions a {
        flex: 1 1 120px;
        margin: 0;
        justify-content: center;
    }

    .lines-wrap {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .lines-table {
        min-width: 760px;
    }

    .lines-table .col-select {
        width: 30px;
        min-width: 30px;
        max-width: 30px;
    }

    .lines-table .col-name {
        min-width: 220px;
    }

    .lines-table .col-qty,
    .lines-table .col-stock,
    .lines-table .col-reserved,
    .lines-table .col-available {
        width: 88px;
    }

    .lines-table .col-price,
    .lines-table .col-sum {
        width: 104px;
    }

    .li-toolbar {
        position: sticky;
        left: 0;
        justify-content: space-between;
        padding: 8px;
    }

    .li-toolbar .li-price-type-box,
    .li-toolbar .li-cols,
    .li-cols,
    .li-cols-btn {
        width: 100%;
        margin: 0;
    }

    .dash-hero,
    .dash-card-head,
    .price-preview-head {
        align-items: stretch;
    }

    .dash-hero-actions,
    .money-row,
    .attn-row,
    .dash-grid,
    .mini-stats,
    .quick-list {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    .dash-card,
    .attn-card {
        border-radius: 12px !important;
    }

    .attn-card {
        padding: 12px 13px !important;
        gap: 10px !important;
    }

    .attn-num,
    .money-val {
        font-size: 24px !important;
    }

    .dash-card-head {
        padding: 11px 12px !important;
    }

    .mini-stat,
    .quick-row {
        min-height: 42px;
    }

    /* Каталог товаров: в списке показываем только фото, код/артикул и название. */
    .table.list-table[data-list-key="products"] tbody {
        gap: 6px;
    }

    .table.list-table[data-list-key="products"] tr {
        grid-template-columns: 50px minmax(0, 1fr);
        grid-template-areas:
            "photo name"
            "photo sku"
            "photo code";
        column-gap: 9px;
        row-gap: 4px;
        min-height: 64px;
        padding: 8px 9px;
        align-items: center;
        border-color: #cfd8e3;
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    }

    .table.list-table[data-list-key="products"] td {
        display: none !important;
        padding: 0 !important;
    }

    .table.list-table[data-list-key="products"] td.lcol-photo,
    .table.list-table[data-list-key="products"] td:nth-child(3),
    .table.list-table[data-list-key="products"] td.lcol-sku,
    .table.list-table[data-list-key="products"] td.lcol-code {
        display: block !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: 100% !important;
        border: 0 !important;
    }

    .table.list-table[data-list-key="products"] td::before {
        content: none !important;
    }

    .table.list-table[data-list-key="products"] td.lcol-photo {
        grid-area: photo;
        align-self: center;
    }

    .table.list-table[data-list-key="products"] .thumb {
        width: 46px;
        height: 46px;
        border-radius: 8px;
        object-fit: cover;
        background: #eef2f6;
        border: 1px solid #d7dee8;
    }

    .table.list-table[data-list-key="products"] td:nth-child(3) {
        grid-area: name;
        align-self: end;
        min-height: 18px;
    }

    .table.list-table[data-list-key="products"] .product-link {
        display: block;
        color: #0b1220;
        text-decoration: none;
    }

    .table.list-table[data-list-key="products"] .product-link strong {
        display: -webkit-box;
        overflow: hidden;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        font-size: 13.5px;
        font-weight: 900;
        line-height: 1.18;
    }

    .table.list-table[data-list-key="products"] td.lcol-sku,
    .table.list-table[data-list-key="products"] td.lcol-code {
        justify-self: start;
        align-self: start;
        max-width: 100% !important;
        padding: 2px 7px !important;
        border-radius: 7px;
        background: #f1f5f9;
        color: #526174;
        font-size: 11px;
        font-weight: 900;
        line-height: 1.15;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .table.list-table[data-list-key="products"] td.lcol-sku {
        grid-area: sku;
    }

    .table.list-table[data-list-key="products"] td.lcol-code {
        grid-area: code;
        background: #ecfdf5;
        color: #166534;
    }
}
