.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
}
.sortable:hover { color: #aaa; }
.sortable a {
    align-items: center;
    color: inherit;
    display: inline-flex;
    gap: 6px;
    text-decoration: none;
}
.sortable a::after       { content: '↕'; opacity: 0.35; font-size: 11px; line-height: 1; }
.sortable.asc a::after   { content: '↑'; opacity: 0.8; }
.sortable.desc a::after  { content: '↓'; opacity: 0.8; }

.data-card {
    overflow-x: auto;
}

#productsTable {
    table-layout: fixed;
    min-width: 1420px;
}

#productsTable th:nth-child(1),
#productsTable td:nth-child(1) { width: 160px; }
#productsTable th:nth-child(2),
#productsTable td:nth-child(2) { width: 300px; }
#productsTable th:nth-child(3),
#productsTable td:nth-child(3) { width: 155px; }
#productsTable th:nth-child(4),
#productsTable td:nth-child(4) { width: 145px; }
#productsTable th:nth-child(5),
#productsTable td:nth-child(5) { width: 110px; }
#productsTable th:nth-child(6),
#productsTable td:nth-child(6) { width: 110px; }
#productsTable th:nth-child(7),
#productsTable td:nth-child(7) { width: 130px; }
#productsTable th:nth-child(8),
#productsTable td:nth-child(8) { width: 150px; }
#productsTable th:nth-child(9),
#productsTable td:nth-child(9) { width: 150px; }

#productsTable th {
    white-space: nowrap;
}

#productsTable th a {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

#productsTable td {
    overflow: hidden;
    text-overflow: ellipsis;
}

#productsTable td:nth-child(3) {
    overflow: visible;
    text-overflow: clip;
}

#productsTable th:first-child,
#productsTable td:first-child {
    white-space: nowrap;
}

#productsTable tbody tr {
    --row-bg: var(--bg-card);
    --row-bg-hover: var(--bg-page);
    --row-bg-alt: #F4F6F8;
    --row-accent: var(--teal);
    --row-accent-soft: rgba(14,165,233,.45);
}

#productsTable tbody tr.row-status-in_stock_warehouse {
    --row-bg: var(--bg-card);
    --row-bg-hover: #FAFAFA;
    --row-bg-alt: #F6F7F8;
    --row-accent: var(--text-muted);
    --row-accent-soft: rgba(156,163,175,.38);
}

#productsTable tbody tr.row-status-in_stock_ozon {
    --row-bg: var(--bg-card);
    --row-bg-hover: #FAFAFA;
    --row-bg-alt: #F6F7F8;
    --row-accent: var(--text-muted);
    --row-accent-soft: rgba(156,163,175,.38);
}

#productsTable tbody tr.row-status-in_sale {
    --row-bg: #FFF8D8;
    --row-bg-hover: #FFF1B8;
    --row-bg-alt: #FFF3C8;
    --row-accent: #F59E0B;
    --row-accent-soft: rgba(245,158,11,.45);
}

#productsTable tbody tr.row-status-sold {
    --row-bg: var(--bg-card);
    --row-bg-hover: #FAFAFA;
    --row-bg-alt: #F6F7F8;
    --row-accent: var(--text-muted);
    --row-accent-soft: rgba(156,163,175,.38);
}

#productsTable tbody tr.row-status-sold.row-profit-positive {
    --row-bg: #ECFDF5;
    --row-bg-hover: #DDF8EC;
    --row-bg-alt: #E2FAEF;
    --row-accent: var(--green);
    --row-accent-soft: rgba(16,185,129,.45);
}

#productsTable tbody tr.row-status-sold.row-profit-negative {
    --row-bg: #FFF1F1;
    --row-bg-hover: #FFE3E3;
    --row-bg-alt: #FDE7E7;
    --row-accent: var(--accent);
    --row-accent-soft: rgba(252,68,69,.42);
}

.text-clip {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
    white-space: nowrap;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.table-toolbar {
    align-items: center;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin: 0 0 12px;
}

.article-search {
    align-items: center;
    display: flex;
    gap: 8px;
}

.article-search span {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
}

.article-search input {
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text-primary);
    font: inherit;
    min-height: 34px;
    padding: 7px 10px;
    width: 230px;
}

.article-search input:focus {
    border-color: rgba(14,165,233,.65);
    box-shadow: 0 0 0 3px rgba(14,165,233,.16);
    outline: none;
}

.filter-menu {
    position: relative;
}

.filter-menu summary {
    list-style: none;
}

.filter-menu summary::-webkit-details-marker {
    display: none;
}

.filter-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 20;
    min-width: 180px;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 14px 32px rgba(17,24,39,.14), 0 4px 10px rgba(17,24,39,.08);
}

.filter-panel label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 2px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.filter-panel input {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
}

.filter-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.filter-actions .btn-primary-saas,
.filter-actions .btn-secondary-saas {
    padding: 6px 10px;
    font-size: 12.5px;
}

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin: 14px 0;
}

.pagination-summary {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
}

.pagination-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.pagination-link {
    min-width: 34px;
    min-height: 32px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
}

.pagination-link:hover {
    background: var(--bg-page);
    color: var(--text-primary);
}

.pagination-link.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.pagination-link.disabled {
    opacity: .45;
    cursor: default;
}

/* ── EXPANDABLE ROWS ──────────────────────── */
.group-header {
    cursor: pointer;
    background-color: var(--row-bg) !important;
    font-weight: 500;
}

.group-header.no-expand {
    cursor: default;
}
.group-header td {
    background-color: var(--row-bg);
}
.group-header:hover {
    background-color: var(--row-bg-hover) !important;
}
.group-header:hover td {
    background-color: var(--row-bg-hover);
}
.group-header.expanded {
    background-color: var(--row-bg-hover) !important;
}
.group-header.expanded td {
    background-color: var(--row-bg-hover);
}
.group-header.expanded td:first-child {
    box-shadow: inset 3px 0 0 var(--row-accent);
}
.group-header:focus-visible {
    outline: 2px solid rgba(14,165,233,.45);
    outline-offset: -2px;
}

.expand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .18s ease, color .18s ease, transform .22s ease;
    margin-right: 8px;
    color: var(--text-muted);
    width: 22px;
    height: 22px;
    border-radius: 7px;
    background: #F3F4F6;
    vertical-align: middle;
}

.expand-icon::before {
    content: '';
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
    transition: transform .22s ease;
}

.group-header:hover .expand-icon,
.group-header.expanded .expand-icon {
    background: var(--teal-light);
    color: var(--teal);
}

.expanded .expand-icon::before {
    transform: rotate(45deg) translate(-1px, -1px);
}

.child-row {
    display: none;
    background-color: var(--row-bg) !important;
    font-size: 13.5px;
}

.child-row.show {
    display: table-row;
}

.child-row td {
    background: var(--row-bg);
    color: var(--text-primary);
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    border-bottom-color: transparent;
    transition: background .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.child-row.show td {
    border-bottom-color: var(--border);
}

.child-row.show td:first-child {
    box-shadow: inset 4px 0 0 var(--row-accent-soft);
}

.child-row-alt td {
    background: var(--row-bg);
}

.child-row.show:not(.closing).child-row-alt td {
    background: var(--row-bg-alt);
}

.child-cell-content {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding-top: 0;
    padding-bottom: 0;
    transform: translateY(-4px);
    transition:
        max-height .26s ease,
        opacity .2s ease,
        padding .26s ease,
        transform .26s ease;
}

.child-row.show:not(.closing) .child-cell-content {
    max-height: 56px;
    opacity: 1;
    padding-top: 14px;
    padding-bottom: 14px;
    transform: translateY(0);
}

.child-row.closing .child-cell-content {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    transform: translateY(-4px);
}

.child-row.closing td {
    background: var(--row-bg);
}

.child-row:hover {
    background: var(--row-bg-hover) !important;
}

.child-row:hover td {
    background: var(--row-bg-hover);
}

.child-row:hover .child-cell-content {
    background: transparent;
}

.load-more-row td {
    text-align: center;
}

.load-more-content {
    align-items: center;
    display: flex;
    justify-content: center;
}

.load-more-children {
    padding: 6px 12px;
}

.accrual-id-cell {
    align-items: center;
    display: flex;
    gap: 6px;
}

.accrual-info-button {
    align-items: center;
    background: #F3F4F6;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    flex: 0 0 auto;
    font-size: 12px;
    font-weight: 800;
    height: 22px;
    justify-content: center;
    line-height: 1;
    padding: 0;
    width: 22px;
}

.accrual-info-button:hover {
    background: var(--teal-light);
    border-color: rgba(14,165,233,.3);
    color: var(--teal);
}

.child-spacer {
    display: inline-block;
    width: 20px;
}

.group-header td:first-child .cell-article {
    width: calc(100% - 34px);
}

.child-row td:first-child .cell-article {
    width: calc(100% - 24px);
}

.group-name-layout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    width: 100%;
}

#productsTable td:nth-child(2) .cell-name {
    flex: 1 1 auto;
    min-width: 0;
    display: block;
}

.count-badge {
    background: var(--teal-light);
    color: var(--teal);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    margin-left: auto;
    white-space: nowrap;
    vertical-align: middle;
    flex: 0 0 auto;
    text-align: center;
}

.badge-mixed {
    background: var(--orange-light);
    color: #92400E;
}

.cost-edit-cell {
    align-items: center;
    display: flex;
    gap: 8px;
    justify-content: flex-start;
    min-width: 0;
}

.row-cost-value {
    display: inline-block;
    min-width: 0;
    text-align: right;
    width: 64px;
}

.cost-edit-button,
.cost-modal-close,
.cost-toast-undo {
    font: inherit;
}

.cost-edit-button {
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    flex: 0 0 auto;
    height: 26px;
    justify-content: center;
    line-height: 1;
    padding: 0;
    width: 26px;
}

.cost-edit-button:hover,
.cost-edit-button:focus-visible {
    background: var(--teal-light);
    border-color: rgba(14,165,233,.45);
    color: var(--teal);
    outline: none;
}

.cost-modal-backdrop {
    align-items: center;
    background: rgba(17,24,39,.36);
    display: none;
    inset: 0;
    justify-content: center;
    padding: 20px;
    position: fixed;
    z-index: 100;
}

.cost-modal-backdrop.show {
    display: flex;
}

.cost-modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(17,24,39,.2), 0 8px 20px rgba(17,24,39,.12);
    max-width: 360px;
    padding: 18px;
    width: 100%;
}

.cost-modal-header {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.cost-modal-header h2 {
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.25;
    margin: 0;
}

.cost-modal-close {
    align-items: center;
    background: transparent;
    border: 0;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    font-size: 24px;
    height: 30px;
    justify-content: center;
    line-height: 1;
    padding: 0;
    width: 30px;
}

.cost-modal-product {
    color: var(--text-secondary);
    font-size: 13px;
    margin: 8px 0 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.accrual-modal {
    max-width: 520px;
}

.accrual-summary {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 12px;
}

.accrual-summary div {
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
}

.accrual-summary span,
.accrual-section h3 {
    color: var(--text-secondary);
    display: block;
    font-size: 12px;
    font-weight: 700;
    margin: 0 0 5px;
}

.accrual-summary strong {
    color: var(--text-primary);
    font-size: 15px;
}

.accrual-section {
    margin-top: 16px;
}

.accrual-list {
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 240px;
    overflow: auto;
}

.accrual-list-row,
.accrual-empty {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 9px 10px;
}

.accrual-list-row + .accrual-list-row {
    border-top: 1px solid var(--border);
}

.accrual-list-row span,
.accrual-empty {
    color: var(--text-secondary);
    font-size: 13px;
}

.accrual-list-row strong {
    color: var(--text-primary);
    flex: 0 0 auto;
    font-size: 13px;
}

.accrual-list-row span:empty {
    display: none;
}

.accrual-list-row span:empty + strong {
    width: 100%;
}

.cost-field {
    display: grid;
    gap: 7px;
}

.cost-field span,
.cost-checkbox {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
}

.cost-field input {
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text-primary);
    font: inherit;
    padding: 9px 10px;
    width: 100%;
}

.cost-field input:focus {
    border-color: rgba(14,165,233,.65);
    box-shadow: 0 0 0 3px rgba(14,165,233,.16);
    outline: none;
}

.cost-checkbox {
    align-items: flex-start;
    display: flex;
    gap: 9px;
    line-height: 1.35;
    margin-top: 13px;
}

.cost-checkbox input {
    accent-color: var(--accent);
    flex: 0 0 auto;
    height: 16px;
    margin-top: 1px;
    width: 16px;
}

.cost-modal-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 16px;
}

.cost-toast {
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 18px 42px rgba(17,24,39,.18), 0 6px 16px rgba(17,24,39,.1);
    color: var(--text-primary);
    display: none;
    font-size: 14px;
    font-weight: 600;
    gap: 14px;
    left: 50%;
    min-width: 320px;
    overflow: hidden;
    padding: 13px 14px 12px;
    position: fixed;
    top: 18px;
    transform: translateX(-50%);
    z-index: 120;
}

.cost-toast.show {
    display: flex;
}

.cost-toast-progress {
    background: var(--accent);
    height: 3px;
    left: 0;
    position: absolute;
    top: 0;
    transform-origin: right center;
    width: 100%;
}

.cost-toast.show .cost-toast-progress {
    animation: cost-toast-countdown 5s linear forwards;
}

.cost-toast-undo {
    background: transparent;
    border: 0;
    color: var(--accent);
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    margin-left: auto;
    padding: 2px 0;
}

@keyframes cost-toast-countdown {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

@media (max-width: 768px) {
    #productsTable {
        min-width: 1420px;
    }

    .pagination-bar {
        align-items: flex-start;
        flex-direction: column;
    }

    .pagination-actions {
        justify-content: flex-start;
    }
}
