.management-shell.add-product-layout {
    --add-product-control-height: 34px;
    --add-product-mobile-control-height: 48px;
    --add-product-step-width: 32px;
    --add-product-quantity-input-width: 42px;
    display: grid;
    grid-template-columns: minmax(240px, 0.72fr) minmax(0, 1.78fr);
    gap: 14px;
    align-items: start
}

.add-product-layout input[type="text"],
.add-product-layout input[type="number"],
.add-product-layout input[type="date"],
.add-product-layout input[type="datetime-local"],
.add-product-layout input[type="file"],
.add-product-layout select,
.add-product-layout button:not(.table-sort-btn):not(.image-upload-btn) {
    height: var(--add-product-control-height)
}

.add-product-form {
    display: grid;
    gap: 12px
}

.add-product-form button {
    width: fit-content;
    min-width: 160px
}

.products-tools,
.category-tools {
    display: grid;
    gap: 8px;
    margin-bottom: 10px;
    align-items: end
}

.products-tools {
    grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(480px, 1.7fr)
}

.category-tools {
    grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(200px, 1fr)
}

.category-tools > div:last-child {
    display: flex;
    align-items: end
}

.products-tools button,
.category-tools button {
    width: 100%
}

@media (min-width:1201px) {
    .products-tools .product-bulk-actions {
        justify-content: flex-end
    }
}

@media (min-width:894px) and (max-width:1200px) {
    .products-tools {
        grid-template-columns: repeat(3, minmax(0, 1fr))
    }

    .products-tools .product-bulk-actions {
        grid-column: 1 / -1;
        justify-content: flex-end
    }
}

.table-wrap {
    border-radius: 8px;
    overflow: hidden;
    background: color-mix(in srgb, var(--mc-panel) 80%, transparent)
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    border-radius: inherit
}

.editable-table {
    width: 100%;
    min-width: 840px;
    margin-top: 0;
    border-collapse: separate;
    border-spacing: 0;
    border: 0;
    border-radius: 0
}

.editable-table input[type="text"],
.editable-table input[type="number"] {
    width: 100%;
    min-width: 90px;
    height: var(--add-product-control-height);
    padding: 0 8px
}

.editable-table td.actions-cell {
    white-space: nowrap
}

.editable-table .product-select {
    width: 17px;
    height: 17px;
    margin: 0;
    vertical-align: middle;
    cursor: pointer
}

.product-bulk-actions {
    display: flex;
    gap: 8px;
    align-items: stretch
}

.products-tools .product-bulk-actions button {
    width: auto;
    /*flex: 1 1 auto;*/
    white-space: nowrap
}

.products-panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px
}

.panel-title-row {
    display: flex;
    align-items: center;
    gap: 10px
}

.panel-title-row h2 {
    margin: 0
}

.panel-title-bordered {
    padding-bottom: 10px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--mc-primary)
}

.panel-title-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    color: var(--mc-primary)
}

.management-page button.reload-products-btn:not(.pos-icon-btn):not(.pos-mobile-actions-toggle):not(.pos-sidebar__link) {
    width: 38px;
    min-width: 38px;
    height: var(--add-product-control-height);
    padding: 0;
    background: var(--mc-panel-muted);
    color: var(--mc-text-soft);
    display: inline-flex;
    align-items: center;
    justify-content: center
}

.reload-products-btn svg {
    width: 18px;
    height: 18px
}

.management-page button.reload-products-btn:not(.pos-icon-btn):not(.pos-mobile-actions-toggle):not(.pos-sidebar__link):hover {
    background: var(--mc-hover-soft)
}

.editable-table thead tr {
    background: color-mix(in srgb, var(--mc-panel-muted) 88%, transparent)
}

.editable-table th,
.editable-table td {
    border: 0;
    border-bottom: 1px solid color-mix(in srgb, var(--mc-border) 70%, transparent);
    padding: 10px 8px;
    text-align: left;
    vertical-align: middle;
    border-radius: 0;
    color: var(--mc-text);
    white-space: nowrap;
    font-size: 14px
}

.editable-table th {
    height: 40px;
    max-width: 40px;
    padding-top: 0;
    padding-bottom: 0;
    font-size: 13px;
    color: var(--mc-text-soft);
    font-weight: 600
}

.table-sort-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    border: 0 !important;
    background: transparent !important;
    color: inherit !important;
    box-shadow: none !important;
    font: inherit;
    font-weight: inherit;
    cursor: pointer
}

.management-page .table-sort-btn:hover {
    background: transparent !important;
    color: inherit !important
}

.table-sort-btn:focus-visible {
    outline: 2px solid var(--mc-primary);
    outline-offset: 3px;
    border-radius: 2px
}

.table-sort-icon {
    width: 16px;
    height: 16px;
    opacity: .3
}

.table-sort-icon.is-active {
    opacity: 1
}

.editable-table tbody tr {
    transition: background-color .2s ease
}

.editable-table tbody tr:hover {
    background: color-mix(in srgb, var(--mc-panel-muted) 55%, transparent)
}

.editable-table tbody tr:last-child td {
    border-bottom: 0
}

.editable-table thead th:first-child {
    border-top-left-radius: 8px
}

.editable-table thead th:last-child {
    border-top-right-radius: 8px
}

.editable-table tbody tr:last-child td:first-child {
    border-bottom-left-radius: 8px
}

.editable-table tbody tr:last-child td:last-child {
    border-bottom-right-radius: 8px
}

.image-input-group {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 190px
}

.image-input-group .edit-image-path {
    min-width: 120px
}

.edit-image-thumb {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    object-fit: cover;
    border: 1px solid var(--mc-border);
    flex-shrink: 0
}

.edit-image-placeholder {
    display: none
}

.image-upload-btn,
.management-page button.quantity-edit-btn:not(.pos-icon-btn) {
    width: 34px;
    height: var(--add-product-control-height);
    padding: 0;
    line-height: 1;
    position: relative;
    border-radius: 9px;
    border: 1px solid var(--mc-border);
    background: color-mix(in srgb, var(--mc-panel-muted) 90%, transparent);
    color: var(--mc-text-soft);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color .2s ease, color .2s ease, border-color .2s ease
}

.image-upload-btn:hover,
.management-page button.quantity-edit-btn:not(.pos-icon-btn):hover {
    background: color-mix(in srgb, var(--mc-panel-muted) 72%, transparent);
    color: var(--mc-text)
}

.image-upload-btn svg,
.quantity-edit-btn svg {
    width: 17px;
    height: 17px;
    display: block;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%)
}

.quantity-control {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 92px
}

.edit-quantity {
    width: 52px !important;
    min-width: 0 !important;
    text-align: center
}

.price-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    min-width: 0;
    height: var(--add-product-control-height);
    background: var(--mc-card);
    overflow: hidden
}

.price-input-wrap .edit-price {
    width: 100%;
    min-width: 0;
    height: 100%;
    padding: 0 28px 0 10px;
    border: 0;
    background: transparent
}

.editable-table .edit-price {
    appearance: textfield;
    -moz-appearance: textfield
}

.editable-table .edit-price::-webkit-inner-spin-button,
.editable-table .edit-price::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none
}

.price-suffix {
    position: absolute;
    right: 18px;
    color: var(--mc-text-soft);
    pointer-events: none
}

.quantity-direct-control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 100%;
    min-width: 0;
    padding: 3px;
    border-radius: var(--ui-radius-sm);
    background: color-mix(in srgb, var(--mc-primary) 10%, transparent 100%)
}

.quantity-direct-control .edit-sort,
.quantity-direct-control .edit-quantity {
    display: block;
    width: var(--add-product-quantity-input-width) !important;
    min-width: var(--add-product-quantity-input-width) !important;
    height: var(--add-product-control-height) !important;
    padding: 0 4px !important;
    border: 0;
    border-radius: 8px !important;
    background: var(--mc-card) !important;
    color: var(--mc-text) !important;
    text-align: center;
    font-weight: 700;
    line-height: 1;
    outline: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .05)
}

.add-product-layout .quantity-direct-control input.edit-sort,
.add-product-layout .quantity-direct-control input.edit-quantity {
    border: 1.5px solid var(--mc-primary, #0b4a8b) !important
}

.quantity-direct-control .edit-sort:focus,
.quantity-direct-control .edit-quantity:focus {
    border-color: var(--mc-primary, #0b4a8b);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--mc-primary) 20%, transparent)
}

.quantity-direct-control .edit-sort,
.quantity-direct-control .edit-quantity {
    appearance: textfield;
    -moz-appearance: textfield
}

.quantity-direct-control .edit-sort::-webkit-inner-spin-button,
.quantity-direct-control .edit-sort::-webkit-outer-spin-button,
.quantity-direct-control .edit-quantity::-webkit-inner-spin-button,
.quantity-direct-control .edit-quantity::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none
}

.management-page button.quantity-step-btn:not(.pos-icon-btn):not(.pos-mobile-actions-toggle) {
    flex: 0 0 var(--add-product-step-width);
    width: var(--add-product-step-width) !important;
    min-width: var(--add-product-step-width) !important;
    height: var(--add-product-control-height) !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 8px !important;
    background: none !important;
    color: var(--mc-text) !important;
    font-size: 26px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: background-color .15s ease, opacity .15s ease
}

.management-page button.quantity-step-btn:not(.pos-icon-btn):not(.pos-mobile-actions-toggle):hover {
    background-color: color-mix(in srgb, var(--mc-primary) 8%, transparent) !important
}

.management-page button.quantity-step-btn:not(.pos-icon-btn):not(.pos-mobile-actions-toggle):active {
    background-color: color-mix(in srgb, var(--mc-primary) 16%, transparent) !important
}

.editable-table th:nth-child(6),
.editable-table td:nth-child(6) {
    width: 104px;
    min-width: 104px
}

.editable-table th:nth-child(6) {
    white-space: normal
}

.availability-column {
    width: 104px
}

.sort-order-column {
    width: 96px;
    min-width: 96px
}

.quantity-popover {
    position: absolute;
    z-index: 10;
    top: calc(100% + 6px);
    left: 0;
    width: 220px;
    padding: 10px;
    border: 1px solid var(--mc-border);
    border-radius: 9px;
    background: var(--mc-panel);
    box-shadow: 0 8px 22px rgba(0, 0, 0, .28)
}

.quantity-popover label {
    margin-bottom: 6px
}

.quantity-popover input {
    width: 100%;
    height: var(--add-product-control-height);
    box-sizing: border-box
}

.quantity-popover-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 8px
}

.visually-hidden-file {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0
}

.status-msg {
    min-height: 22px;
    margin-top: 8px;
    color: var(--mc-text-soft);
    font-size: 13px
}

#new-image-input {
    height: var(--add-product-control-height);
    padding: 4px 10px;
    display: flex;
    align-items: center
}

#new-image-input::file-selector-button {
    height: var(--add-product-control-height);
    margin-right: 10px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid var(--mc-border);
    background: var(--mc-panel-muted);
    color: var(--mc-text);
    cursor: pointer
}

#new-image-input::file-selector-button:hover {
    background: var(--mc-hover-soft)
}

.management-page label.inactive-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: var(--add-product-control-height);
    min-height: var(--add-product-control-height);
    padding: 0 12px;
    margin-bottom: 0;
    border: 1px solid var(--mc-border);
    border-radius: 8px;
    background: color-mix(in srgb, var(--mc-panel-muted) 70%, transparent);
    font-size: 13px;
    color: var(--mc-text);
    user-select: none;
    box-sizing: border-box
}

.management-page label.inactive-toggle input[type="checkbox"] {
    margin: 0;
    width: 16px;
    height: 16px
}

.product-row--inactive td {
    background: color-mix(in srgb, var(--mc-panel-muted) 65%, transparent);
    color: var(--mc-text-soft)
}

.toggle-active-row {
    margin-left: 6px
}

.management-page button.toggle-active-row.is-restore:not(.pos-icon-btn),
.management-page button.bulk-restore-btn:not(.pos-icon-btn) {
    background: #2c3e50;
    color: #ffff
}

.management-page button.toggle-active-row.is-restore:not(.pos-icon-btn):hover,
.management-page button.bulk-restore-btn:not(.pos-icon-btn):hover {
    background: var(--mc-hover-soft);
    color: #ffff
}

@media (orientation: portrait) and (max-width:1360px), (max-width:893px) {
    .management-shell.add-product-layout {
        grid-template-columns: 1fr
    }
}

@media (max-width:893px) {

    .add-product-layout {
        --add-product-control-height: var(--add-product-mobile-control-height);
        --add-product-step-width: 48px;
        --add-product-quantity-input-width: 42px
    }

    .quantity-direct-control .edit-sort,
    .quantity-direct-control .edit-quantity {
        flex: 1 1 auto;
        width: auto !important;
        min-width: 0 !important
    }

    .products-tools,
    .category-tools {
        grid-template-columns: 1fr
    }

    .product-bulk-actions {
        flex-direction: column
    }

    .products-tools .product-bulk-actions button {
        width: 100%
    }
}

/* Compact screens: turn the product table into stacked cards, one per row */
@media (max-width:893px) {
    .table-scroll {
        overflow-x: visible
    }

    .editable-table {
        min-width: 0;
        width: 100%;
        display: block
    }

    .editable-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap
    }

    .editable-table tbody {
        display: block
    }

    .editable-table tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
        grid-template-areas:
            "header header header"
            "prezzo prezzo image"
            "ordine ordine image"
            "quant quant image"
            "azioni azioni azioni";
        column-gap: 10px;
        row-gap: 8px;
        margin-bottom: 12px;
        padding: 12px 14px;
        border-radius: 14px;
        border: 1px solid var(--mc-border);
        background: color-mix(in srgb, var(--mc-panel) 94%, transparent);
        box-shadow: var(--ui-shadow-strong)
    }

    .editable-table tbody tr:last-child {
        margin-bottom: 0
    }

    .editable-table td {
        display: flex;
        align-items: center;
        gap: 8px;
        width: auto;
        max-width: none;
        min-width: 0;
        white-space: normal;
        border-bottom: 0;
        padding: 0
    }

    /* Header line: category + product name share the full-width header area, split 50/50 via justify-self so their combined width always spans the whole card regardless of the image column */
    .editable-table td:nth-child(1) {
        grid-area: header;
        align-self: start;
        justify-content: flex-end
    }

    .editable-table .product-select {
        display: none
    }

    .editable-table td:nth-child(2) {
        grid-area: header;
        align-self: start;
        justify-self: start;
        width: calc(50% - 5px);
        justify-content: center
    }

    .editable-table td:nth-child(3) {
        grid-area: header;
        align-self: start;
        justify-self: end;
        width: calc(50% - 5px);
        justify-content: center;
        min-width: 0
    }

    .editable-table td:nth-child(2) .edit-category,
    .editable-table td:nth-child(3) .edit-name {
        height: var(--add-product-control-height);
        padding: 0 8px;
        min-width: 0;
        font-size: 14px;
        font-weight: 700;
        text-align: center;
        border: 1px solid var(--mc-border);
        border-radius: 6px;
        background: var(--mc-card);
        color: var(--mc-text)
    }

    .editable-table td:nth-child(2) .edit-category:focus,
    .editable-table td:nth-child(3) .edit-name:focus {
        outline: none;
        border-color: var(--mc-primary)
    }

    .editable-table td:nth-child(2) .edit-category {
        width: 100%;
        max-width: none;
        background: color-mix(in srgb, var(--mc-primary) 10%, transparent 100%)
    }

    .editable-table td:nth-child(3) .edit-name {
        width: 100%
    }

    /* Label + value rows (prezzo/ordine/disponibilità) share one fixed value-column width */
    .editable-table td:nth-child(4),
    .editable-table td:nth-child(5),
    .editable-table td:nth-child(6) {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 150px;
        align-items: center;
        column-gap: 8px
    }

    .editable-table td:nth-child(4) {
        grid-area: prezzo
    }

    .editable-table td:nth-child(5) {
        grid-area: ordine
    }

    .editable-table td:nth-child(6) {
        grid-area: quant
    }

    .editable-table td:nth-child(4)::before,
    .editable-table td:nth-child(5)::before,
    .editable-table td:nth-child(6)::before {
        font-size: 14px;
        font-weight: 700;
        color: var(--mc-text)
    }

    .editable-table td:nth-child(4)::before {
        content: "Prezzo"
    }

    .editable-table td:nth-child(5)::before {
        content: "Ordine"
    }

    .editable-table td:nth-child(6)::before {
        content: "Disponibilità"
    }

    .editable-table td:nth-child(4) input[type="text"],
    .editable-table td:nth-child(4) input[type="number"] {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        text-align: center;
    }

    .editable-table td,
    .editable-table td.sort-order-column,
    .editable-table td.availability-column,
    .editable-table th:nth-child(6) {
        width: auto;
        min-width: 0;
        max-width: none
    }

    /* Thumbnail + upload, spanning the label rows on the right */
    .editable-table td:nth-child(7) {
        grid-area: image;
        align-self: start;
        justify-content: flex-end
    }

    .image-input-group {
        position: relative;
        width: 56px;
        height: 56px;
        min-width: 0
    }

    .edit-image-thumb,
    .edit-image-placeholder {
        width: 56px;
        height: 56px;
        border-radius: 10px
    }

    .edit-image-placeholder {
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1px dashed var(--mc-border);
        background: color-mix(in srgb, var(--mc-panel-muted) 72%, transparent);
        color: var(--mc-text-soft)
    }

    .edit-image-placeholder svg {
        width: 20px;
        height: 20px
    }

    .image-input-group .edit-image-path {
        display: none
    }

    .image-upload-btn {
        position: absolute;
        inset: 0;
        width: 56px;
        height: 56px;
        border: 0;
        background: transparent
    }

    .image-upload-btn svg {
        opacity: 0
    }

    .quantity-popover {
        left: auto;
        right: 0;
        max-width: calc(100vw - 64px)
    }

    /* Pill-style action row */
    .editable-table td.actions-cell {
        grid-area: azioni;
        justify-content: stretch;
        flex-wrap: wrap
    }

    .editable-table td.actions-cell button {
        flex: 1 1 auto;
        border-radius: 999px
    }
}