/*
 * Matching Fields and the product category warning. The shared pieces (table, card, window,
 * notices, buttons) come from ktmp-ui.css; this file holds only what these screens draw alone.
 */

/* Tables: coverage under each marketplace name, and term rows shown by their Expand button. */
.ktmp-match-table.fixed {
    min-width: 900px;
}

.ktmp-match-coverage {
    font-weight: 400;
    color: var(--ktmp-text-muted);
    font-variant-numeric: tabular-nums;
}

.ktmp-match-coverage__bar {
    min-width: 80px;
    margin-top: var(--ktmp-space-1);
}

.ktmp-match-table tr.ktmp-sub-row:not(.visible) {
    display: none;
}

/*
 * Terms table: however many marketplaces there are, the taxonomy name stays on the left and
 * the Match column on the right while the frame scrolls sideways. The table keeps its full
 * height and the page scrolls it, so the shared sticky frame's height limit is lifted here.
 */
.ktmp-table-scroll--sticky.ktmp-match-scroll {
    max-height: none;
}

.ktmp-match-table--sticky-last tr > :last-child:not(:first-child) {
    position: sticky;
    inset-inline-end: 0;
    z-index: 1;
    background: inherit;
    box-shadow: inset 1px 0 0 var(--ktmp-border-light);
}

.ktmp-match-table--sticky-last tr.ktmp-row-child > :last-child {
    background: var(--ktmp-surface);
}

.ktmp-match-table--sticky-last thead tr > :last-child:not(:first-child) {
    z-index: 3;
    background: var(--ktmp-surface);
}

/* Edit card above the table; its one row of fields scrolls in a short frame. */
.ktmp-match-edit {
    margin: var(--ktmp-space-5) 0;
}

.ktmp-match-edit .ktmp-table-scroll {
    max-height: 240px;
    overflow: auto;
}

.ktmp-match-edit__table td {
    min-width: 160px;
    vertical-align: top;
}

.ktmp-match-current {
    margin: 0 0 var(--ktmp-space-2);
}

.ktmp-match-current__label {
    color: var(--ktmp-text-secondary);
}

.ktmp-match-current .current-value {
    font-weight: var(--ktmp-weight-strong);
}

.ktmp-match-warning .notice.inline {
    max-width: 560px;
    margin: 0;
    text-align: start;
}

/* Window: the form fills the space between header and footer, so its body scrolls on its own. */
.ktmp-match-window__form {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
}

.ktmp-match-window .ktmp-label {
    display: block;
    margin: 0 0 6px;
    font-weight: var(--ktmp-weight-strong);
}

.ktmp-flat-category-container > .select-wrapper + .select-wrapper,
.ktmp-flat-category-container > .notice.inline + .select-wrapper {
    margin-top: var(--ktmp-space-4);
}

/*
 * Category levels, one per line. Every level after the first starts with a tree mark that
 * joins it to the level above; the second level is indented a little, deeper levels more.
 * The first select takes a whole line; each later mark shares a line with its select.
 *
 * The column gap is a whole line wide, so nothing fits after a select and every mark starts
 * a new line, however deep its indent. A select after a mark takes that gap back with its
 * start margin and grows into what the mark leaves of the line.
 */
.ktmp-subcategory-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--ktmp-space-3) 0;
}

.ktmp-window .ktmp-subcategory-container {
    column-gap: 100%;
}

.ktmp-window .ktmp-subcategory-container .ktmp-subcategory-select {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    margin-inline-start: -100%;
}

.ktmp-window .ktmp-subcategory-container .ktmp-subcategory-select:first-child {
    flex-basis: 100%;
    margin-inline-start: 0;
}

.ktmp-subcategory-container > .ktmp-tree {
    flex: none;
    width: 12px;
    height: 22px;
    margin: -22px var(--ktmp-space-2) 0 var(--ktmp-space-3);
    border-end-start-radius: 0;
}

.ktmp-subcategory-container > .ktmp-tree ~ .ktmp-tree {
    margin-inline-start: var(--ktmp-space-8);
}

/* From the third mark on, each level steps in by one mark and its gap; the script sets the depth. */
.ktmp-subcategory-container > .ktmp-tree ~ .ktmp-tree ~ .ktmp-tree {
    margin-inline-start: calc(var(--ktmp-space-3) + (var(--ktmp-tree-depth) - 1) * (12px + var(--ktmp-space-2)));
}

/* Attribute and term rules: option label, value and Remove on one line, categories below. */
#rule-container {
    display: flex;
    flex-direction: column;
    gap: var(--ktmp-space-3);
    margin-bottom: var(--ktmp-space-4);
}

.ktmp-match-rule {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr) max-content;
    align-items: center;
    gap: var(--ktmp-space-2) var(--ktmp-space-3);
}

/* Rule cards. The first term option applies to every category and uses the accent inset instead. */
.ktmp-match-rule:not(.ktmp-inset) {
    padding: var(--ktmp-space-4);
    border: 1px solid var(--ktmp-border-light);
    border-radius: var(--ktmp-radius-lg);
    background: var(--ktmp-surface-card);
}

.ktmp-match-window .ktmp-match-rule > .ktmp-label {
    margin: 0;
}

.ktmp-match-rule > select,
.ktmp-match-rule > .select2-container {
    grid-column: 2;
    min-width: 0;
}

.ktmp-match-rule > .remove-select {
    grid-column: 3;
}

.ktmp-match-rule > .ktmp-field-error,
.ktmp-match-rule > .ktmp-select-all-wrapper,
.ktmp-match-rule > .ktmp-category-checkboxes {
    grid-column: 1 / -1;
}

.ktmp-select-all-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: var(--ktmp-space-1) var(--ktmp-space-4);
}

/* Category checkboxes in two columns; a category another rule holds is greyed out. */
.ktmp-category-checkboxes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--ktmp-space-1) var(--ktmp-space-4);
    max-height: 240px;
    overflow-y: auto;
}

.ktmp-category-checkboxes:empty {
    display: none;
}

.ktmp-category-checkboxes .ktmp-check {
    align-items: flex-start;
}

.ktmp-category-checkboxes .ktmp-check > input {
    margin-top: 2px;
}

.ktmp-category-checkboxes .ktmp-check:has(> input:disabled:not(:checked)) {
    color: var(--ktmp-text-muted);
    cursor: not-allowed;
}

#add-rule {
    margin-bottom: var(--ktmp-space-4);
}

.ktmp-match-unmatched p {
    margin: var(--ktmp-space-1) 0 0;
}

/* Product category screen: the warning under the Parent category picker, as wide as core's fields. */
.ktmp-parent-warning-slot .notice.inline {
    box-sizing: border-box;
    max-width: 95%;
    margin: var(--ktmp-space-2) 0 0;
}

@media screen and (max-width: 782px) {
    .ktmp-match-rule {
        grid-template-columns: minmax(0, 1fr);
    }

    .ktmp-match-rule > select,
    .ktmp-match-rule > .select2-container,
    .ktmp-match-rule > .remove-select {
        grid-column: 1;
    }

    .ktmp-category-checkboxes {
        grid-template-columns: minmax(0, 1fr);
    }
}
