:root {
    --bg: #f3f6fb;
    --panel: #fff;
    --text: #172033;
    --muted: #6b7280;
    --line: #e5e7eb;
    --blue: #146ff8;
    --green: #0f9f6e;
    --orange: #d97706;
    --red: #dc2626;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, Arial, sans-serif;
}

.page {
    max-width: 1280px;
    margin: auto;
    padding: 30px;
}

.page.wide { max-width: 1600px; }

.top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 24px;
}

h1 {
    margin: 5px 0;
    font-size: 34px;
}

h2 { margin: 0 0 18px; }

p { color: var(--muted); }

.eyebrow {
    color: var(--blue);
    font-weight: 800;
    font-size: 12px;
    letter-spacing: .12em;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 22px;
    margin-bottom: 22px;
    box-shadow: 0 8px 30px rgba(17, 24, 39, .05);
}

.create-form, .actions, .section-title {
    display: flex;
    align-items: flex-end;
    gap: 12px;
}

.section-title {
    justify-content: space-between;
}

label {
    display: grid;
    gap: 7px;
    font-weight: 700;
}

select {
    min-width: 280px;
    padding: 12px;
    border: 1px solid #cfd5df;
    border-radius: 9px;
    background: white;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 9px;
    padding: 12px 16px;
    text-decoration: none;
    cursor: pointer;
    font-weight: 750;
    white-space: nowrap;
}

.primary { background: var(--blue); color: white; }
.secondary { background: #e8edf5; color: var(--text); }
.success { background: var(--green); color: white; }

.hint, .muted {
    color: var(--muted);
    font-size: 12px;
}

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.product {
    display: grid;
    gap: 3px;
    margin-bottom: 8px;
}

.quantity {
    min-height: 44px;
    font-size: 18px;
    font-weight: 800;
}

.index {
    font-size: 17px;
    font-weight: 800;
}

.badge, .status {
    display: inline-block;
    padding: 5px 9px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 750;
}

.badge.simple { background: #e8edf5; }
.badge.multi { background: #dcfce7; color: #067647; }
.badge.combined { background: #ffedd5; color: #9a3412; }

.combined-row { background: #fffaf1; }

.divider-row td {
    background: #172033;
    color: white;
    font-weight: 800;
}

.alert {
    padding: 13px 16px;
    border-radius: 10px;
    margin-bottom: 18px;
}

.alert.success { background: #dcfce7; color: #067647; }
.alert.error { background: #fee2e2; color: var(--red); }
.alert.warning { background: #fef3c7; color: #92400e; }

.link {
    color: var(--blue);
    font-weight: 750;
}

.empty {
    padding: 35px;
    text-align: center;
    color: var(--muted);
}

@media (max-width: 800px) {
    .page { padding: 15px; }

    .top, .actions, .create-form {
        flex-direction: column;
        align-items: stretch;
    }

    select { min-width: 100%; }
}

.product-image {
    width: 64px;
    height: 64px;
    object-fit: contain;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    float: left;
    margin-right: 10px;
}

.progress-card {
    display: none;
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: min(420px, calc(100vw - 30px));
    padding: 16px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 15px 45px rgba(17, 24, 39, .2);
    z-index: 1000;
}

.progress-head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
}

.progress-track {
    height: 12px;
    overflow: hidden;
    background: #e5e7eb;
    border-radius: 20px;
    margin-bottom: 9px;
}

.progress-bar {
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, #146ff8, #0f9f6e);
    transition: width .3s ease;
}

.product {
    display: grid;
    grid-template-columns: 72px minmax(240px, 1fr);
    column-gap: 10px;
    align-items: center;
}

.product-image {
    grid-row: 1 / span 2;
    width: 64px;
    height: 64px;
    object-fit: contain;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
}

.product {
    display: grid;
    grid-template-columns: 66px minmax(250px, 1fr);
    grid-template-rows: auto auto;
    column-gap: 10px;
    align-items: center;
    min-height: 66px;
}

.product-image {
    grid-column: 1;
    grid-row: 1 / 3;
    display: block;
    width: 58px;
    height: 58px;
    object-fit: contain;
    overflow: hidden;
    color: transparent;
}

.product > strong {
    grid-column: 2;
    grid-row: 1;
}

.product > span {
    grid-column: 2;
    grid-row: 2;
}

/* Статус этикеток сверху страницы */
.progress-card {
    display: none;
    position: static !important;
    width: 100% !important;
    margin: 0 0 22px;
    padding: 18px 20px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 8px 30px rgba(17, 24, 39, .08);
}

.progress-card.is-active {
    display: block;
}

.progress-head {
    font-size: 15px;
}

.progress-track {
    height: 15px;
}

/* Верхний статус получения этикеток */
.progress-card {
    display: none;
    position: static;
    width: 100%;
    margin: 0 0 22px;
    padding: 18px 20px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 8px 30px rgba(17, 24, 39, .08);
}

.progress-card.is-active {
    display: block;
}

.progress-head {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 11px;
}

.progress-track {
    width: 100%;
    height: 15px;
    overflow: hidden;
    margin-bottom: 9px;
    background: #e5e7eb;
    border-radius: 999px;
}

.progress-bar {
    width: 0;
    height: 100%;
    background: linear-gradient(90deg, #146ff8, #0f9f6e);
    border-radius: inherit;
    transition: width .35s ease;
}

.progress-card.is-ready .progress-bar {
    background: #0f9f6e;
}

.progress-card.has-error {
    border-color: #fca5a5;
}

.progress-card.has-error .progress-bar {
    background: #dc2626;
}

.labels-ready-notice {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin: 0 0 22px;
    padding: 18px 20px;
    background: #ecfdf3;
    border: 1px solid #86efac;
    border-radius: 14px;
}

.labels-ready-notice.is-visible {
    display: flex;
}

.labels-ready-notice strong {
    color: #067647;
    font-size: 17px;
}

.labels-ready-notice p {
    margin: 5px 0 0;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.row-actions form {
    margin: 0;
}

.delete-link {
    padding: 0;
    border: 0;
    background: transparent;
    color: #dc2626;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.delete-link:disabled {
    color: #9ca3af;
    cursor: not-allowed;
}

.labels-ready-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Компактный мобильный режим для FBS */
@media (max-width: 760px) {
    .page,
    .page.wide {
        max-width: none;
        padding: 10px;
    }

    .top {
        gap: 12px;
        margin-bottom: 12px;
    }

    .top h1,
    h1 {
        font-size: 23px;
        line-height: 1.15;
    }

    .top p {
        margin: 4px 0 0;
        font-size: 12px;
    }

    .actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        width: 100%;
        gap: 8px;
    }

    .actions .button,
    .actions button,
    .actions form {
        width: 100%;
    }

    .button {
        min-height: 42px;
        padding: 10px 11px;
        font-size: 13px;
        border-radius: 9px;
    }

    .panel {
        padding: 8px;
        border-radius: 12px;
        margin-bottom: 12px;
    }

    .table-wrap {
        overflow: visible;
    }

    .orders-table,
    .orders-table thead,
    .orders-table tbody,
    .orders-table tr,
    .orders-table th,
    .orders-table td {
        display: block;
        width: 100%;
    }

    .orders-table thead {
        display: none;
    }

    .orders-table tr {
        position: relative;
        margin: 0 0 10px;
        padding: 10px;
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 12px;
        box-shadow: 0 4px 14px rgba(17, 24, 39, .05);
    }

    .orders-table tr.combined-row {
        background: #fffaf1;
        border-color: #fed7aa;
    }

    .orders-table td {
        padding: 0;
        border: 0;
    }

    .orders-table td.index {
        position: absolute;
        top: 10px;
        left: 10px;
        width: 34px;
        height: 34px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #172033;
        color: #fff;
        border-radius: 9px;
        font-size: 14px;
    }

    .orders-table td.index + td {
        padding-left: 44px;
        min-height: 38px;
    }

    .orders-table td.index + td strong {
        display: block;
        font-size: 13px;
        line-height: 1.2;
        word-break: break-word;
    }

    .orders-table .muted {
        font-size: 11px;
        line-height: 1.25;
    }

    .orders-table td:nth-child(3) {
        margin-top: 9px;
        display: grid;
        gap: 8px;
    }

    .orders-table td:nth-child(4) {
        position: absolute;
        top: 10px;
        right: 10px;
        width: auto;
    }

    .orders-table td:nth-child(4) .quantity {
        min-height: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 42px;
        height: 34px;
        padding: 0 8px;
        background: #dcfce7;
        color: #067647;
        border-radius: 999px;
        font-size: 16px;
        font-weight: 900;
    }

    .orders-table td:nth-child(5) {
        display: none;
    }

    .orders-table td:nth-child(6) {
        margin-top: 8px;
    }

    .product {
        display: grid;
        grid-template-columns: 46px minmax(0, 1fr);
        grid-template-rows: auto auto;
        column-gap: 8px;
        min-height: 48px;
        margin: 0;
    }

    .product-image {
        width: 44px;
        height: 44px;
        border-radius: 7px;
    }

    .product > strong {
        font-size: 13px;
        line-height: 1.15;
        word-break: break-word;
    }

    .product > span {
        display: -webkit-box;
        overflow: hidden;
        color: #374151;
        font-size: 12px;
        line-height: 1.25;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    .badge,
    .status {
        padding: 4px 8px;
        font-size: 11px;
    }

    .divider-row {
        margin: 14px 0 10px !important;
        padding: 0 !important;
        border: 0 !important;
        box-shadow: none !important;
    }

    .divider-row td {
        display: block;
        padding: 9px 11px;
        border-radius: 10px;
        background: #172033;
        color: white;
        font-size: 13px;
    }

    .progress-card,
    .labels-ready-notice {
        padding: 12px;
        border-radius: 12px;
        margin-bottom: 12px;
    }

    .labels-ready-notice {
        align-items: stretch;
        flex-direction: column;
    }

    .labels-ready-actions {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .create-form {
        display: grid;
        gap: 10px;
    }

    select {
        min-width: 0;
        width: 100%;
    }
}

/* История партий с внутренним скроллом */
.batches-scroll {
    max-height: 520px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
}

.batches-scroll table {
    margin: 0;
}

.batches-scroll thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f8fafc;
}

.barcode-line {
    display: inline-block;
    margin-top: 3px;
    padding: 3px 7px;
    border-radius: 7px;
    background: #f3f4f6;
    color: #111827;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .02em;
}

/* ШК в строке товара — широкий аккуратный блок */
.barcode-line {
    display: inline-flex !important;
    align-items: center;
    width: fit-content;
    min-width: 150px;
    margin-top: 7px;
    padding: 5px 10px;
    border-radius: 8px;
    background: #f3f4f6;
    color: #111827;
    font-size: 13px;
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: .02em;
    white-space: nowrap;
}

/* Увеличение фото товара при наведении */
.product-image {
    position: relative;
    z-index: 1;
    cursor: zoom-in;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.product-image:hover {
    transform: scale(5);
    z-index: 100;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.28);
    background: white;
}


/* Панель действий новой партии */
.fbs-action-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 10px;
    margin-top: 12px;
}

.fbs-action-panel form {
    display: flex;
    margin: 0;
}

.fbs-action-panel .fbs-action-button {
    min-height: 46px;
    padding: 10px 16px;
    border: 0;
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.15;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
    transition:
        transform 0.15s ease,
        box-shadow 0.15s ease,
        opacity 0.15s ease;
}

.fbs-action-panel .fbs-action-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 9px 20px rgba(15, 23, 42, 0.17);
}

.fbs-action-button--containers {
    background: linear-gradient(135deg, #10b981, #059669);
}

.fbs-action-button--labels {
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.fbs-action-button--labels .pdf-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 28px;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.2);
    font-size: 12px;
    font-weight: 800;
}

.fbs-action-button--labels .button-text {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.fbs-action-button--labels small {
    margin-top: 3px;
    color: rgba(255, 255, 255, 0.78);
    font-size: 11px;
    font-weight: 500;
}

@media (max-width: 650px) {
    .fbs-action-panel,
    .fbs-action-panel form {
        width: 100%;
    }

    .fbs-action-panel .fbs-action-button {
        width: 100%;
    }
}

/* Красивые кнопки и история партий */
.button {
    min-height: 42px;
    gap: 8px;
    border-radius: 12px;
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease, opacity .15s ease;
    box-shadow: 0 8px 18px rgba(15, 23, 42, .08);
}

.button:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(15, 23, 42, .13);
}

.button:active {
    transform: translateY(0);
}

.button:disabled,
.button[disabled] {
    opacity: .55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.danger {
    background: var(--red);
    color: #fff;
}

.button.mini {
    min-height: 34px;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
}

.fbs-action-panel {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.fbs-action-panel form {
    margin: 0 !important;
}

.fbs-action-button,
.fbs-pdf-button {
    border-radius: 12px !important;
}

.history-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin: -4px 0 12px;
}

.history-table {
    min-width: 980px;
}

.history-table th,
.history-table td {
    vertical-align: middle;
}

.select-cell {
    width: 44px;
    text-align: center;
}

.select-cell input,
.batch-checkbox,
#selectAllBatches {
    width: 18px;
    height: 18px;
    accent-color: var(--blue);
    cursor: pointer;
}

.history-table tbody tr {
    transition: background .15s ease;
}

.history-table tbody tr:hover {
    background: #f8fafc;
}

.row-actions {
    gap: 8px;
    flex-wrap: wrap;
}

.status.labels_ready {
    background: #dcfce7;
    color: #067647;
}

.status.labels_processing {
    background: #fef3c7;
    color: #92400e;
}

.status.error {
    background: #fee2e2;
    color: #991b1b;
}

@media (max-width: 760px) {
    .section-title {
        align-items: center;
    }

    .history-toolbar {
        justify-content: stretch;
        margin: 0 0 10px;
    }

    .history-toolbar .button {
        width: 100%;
    }

    .history-table-wrap.batches-scroll {
        max-height: none;
        overflow: visible;
        border: 0;
        border-radius: 0;
    }

    .history-table {
        min-width: 0;
    }

    .history-table,
    .history-table thead,
    .history-table tbody,
    .history-table tr,
    .history-table th,
    .history-table td {
        display: block;
        width: 100%;
    }

    .history-table thead {
        display: none;
    }

    .history-table tr {
        position: relative;
        margin: 0 0 10px;
        padding: 12px;
        background: #fff;
        border: 1px solid var(--line);
        border-radius: 14px;
        box-shadow: 0 6px 18px rgba(17, 24, 39, .06);
    }

    .history-table td {
        display: flex;
        justify-content: space-between;
        gap: 14px;
        padding: 8px 0;
        border: 0;
        font-size: 13px;
    }

    .history-table td::before {
        content: attr(data-label);
        flex: 0 0 120px;
        color: var(--muted);
        font-size: 11px;
        font-weight: 800;
        text-transform: uppercase;
    }

    .history-table td.select-cell {
        justify-content: flex-start;
        padding: 0 0 8px;
    }

    .history-table td.select-cell::before {
        content: "Выбрать";
        flex: 0 0 auto;
        margin-right: 10px;
    }

    .history-table td[data-label="Действия"] {
        padding-top: 10px;
    }

    .history-table td[data-label="Действия"]::before {
        display: none;
    }

    .history-table .row-actions,
    .history-table .row-actions .button {
        width: 100%;
    }

    .fbs-action-panel {
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .fbs-action-panel form,
    .fbs-action-panel button,
    .fbs-pdf-button {
        width: 100%;
    }

    .fbs-pdf-button {
        justify-content: flex-start;
    }
}
