/* Reusable grouped analytical table. The component deliberately composes the
 * ERP detail-table scroll, column, typed-cell and row-activation foundations;
 * this file owns only pivot grouping, summaries and the persistent scroll
 * treatment. */

.erp-pivot-table {
    container-name: erp-pivot-table;
    container-type: inline-size;
}

.erp-pivot-table__shell {
    position: relative;
    min-width: 0;
    overflow: clip;
    border: 1px solid var(--divider);
    border-radius: var(--radius-md);
    background: var(--surface);
}

.erp-pivot-table__toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.35rem;
    margin-bottom: 0.65rem;
}

.erp-pivot-table__toolbar-button,
.erp-pivot-table__sort-control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.38rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.erp-pivot-table__toolbar-button {
    min-height: 2rem;
    padding: 0 0.6rem;
    color: var(--text-secondary);
    font-size: 0.74rem;
    font-weight: 700;
}

.erp-pivot-table__toolbar-button:hover:not(:disabled),
.erp-pivot-table__toolbar-button:focus-visible,
.erp-pivot-table__sort-control:hover,
.erp-pivot-table__sort-control:focus-visible {
    background: var(--primary-50);
    color: var(--primary);
    outline: none;
}

.erp-pivot-table__toolbar-button:focus-visible,
.erp-pivot-table__sort-control:focus-visible {
    box-shadow: var(--shadow-focus);
}

.erp-pivot-table__toolbar-button:disabled {
    cursor: default;
    opacity: 0.42;
}

.erp-pivot-table__sort-control {
    width: 100%;
    min-height: 2rem;
    justify-content: flex-start;
    padding: 0.2rem 0.35rem;
    margin: -0.2rem -0.35rem;
    letter-spacing: inherit;
    text-align: inherit;
    text-transform: inherit;
}

.erp-pivot-table__sort-control svg {
    flex: 0 0 auto;
    opacity: 0.42;
}

.erp-pivot-table__sort-control.is-active {
    color: var(--primary);
}

.erp-pivot-table__sort-control.is-active svg {
    opacity: 1;
}

.erp-detail-table__heading.is-align-end .erp-pivot-table__sort-control {
    justify-content: flex-end;
}

.erp-detail-table__heading.is-align-center .erp-pivot-table__sort-control {
    justify-content: center;
}

.erp-pivot-table__scroll {
    border: 0;
    border-radius: 0;
}

.erp-pivot-table__table {
    border-collapse: separate;
    border-spacing: 0;
}

.erp-pivot-table__table thead th {
    position: sticky;
    z-index: 3;
    top: 0;
}

.erp-pivot-table__divider-before {
    border-inline-start: 2px solid var(--divider) !important;
}

.erp-pivot-table__group-row:hover,
.erp-pivot-table__summary-row:hover {
    background: transparent !important;
}

.erp-pivot-table__group-heading {
    padding: 0 !important;
    border-bottom-color: color-mix(in srgb, var(--divider) 82%, var(--primary));
    background: color-mix(in srgb, var(--surface-sunken) 88%, var(--primary-50));
    color: var(--color-kview);
    font-size: 0.84rem;
    font-weight: 700;
    letter-spacing: normal;
    text-align: left;
    text-transform: none;
}

.erp-pivot-table__group-control,
.erp-pivot-table__group-label {
    display: flex;
    width: 100%;
    min-height: 44px;
    align-items: center;
    gap: 0.55rem;
    box-sizing: border-box;
    padding: 0.55rem 0.85rem;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
}

.erp-pivot-table__group-control {
    cursor: pointer;
}

.erp-pivot-table__group-control:hover {
    background: color-mix(in srgb, var(--primary-50) 72%, transparent);
}

.erp-pivot-table__group-control:focus-visible {
    border-radius: calc(var(--radius-sm) - 1px);
    box-shadow: inset 0 0 0 2px var(--primary);
    outline: none;
}

.erp-pivot-table__group-chevron {
    flex: 0 0 auto;
    color: var(--primary);
    transition: transform var(--transition-fast);
}

.erp-pivot-table__group-chevron.is-expanded {
    transform: rotate(90deg);
}

.erp-pivot-table__group-copy {
    display: flex;
    min-width: 0;
    align-items: baseline;
    gap: 0.55rem;
}

.erp-pivot-table__group-copy > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.erp-pivot-table__group-copy small {
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 550;
}

.erp-pivot-table__group-heading--summary,
.erp-pivot-table__group-heading--summary ~ .erp-pivot-table__summary-cell {
    border-top: 1px solid color-mix(in srgb, var(--divider) 70%, var(--primary));
    background: color-mix(in srgb, var(--primary-50) 55%, var(--surface));
}

/* The adaptive collapsed state is deliberately one visual row: the group
 * identity and its measures share the same surface and column alignment. */
.erp-pivot-table__group-row--adaptive-summary > .erp-pivot-table__group-heading,
.erp-pivot-table__group-row--adaptive-summary > .erp-pivot-table__summary-cell {
    border-bottom-color: color-mix(in srgb, var(--divider) 82%, var(--primary));
    background: color-mix(in srgb, var(--surface-sunken) 88%, var(--primary-50));
}

.erp-pivot-table__group-row--adaptive-summary > .erp-pivot-table__summary-cell {
    padding-block: 0.55rem;
}

.erp-pivot-table__data-row[hidden],
.erp-pivot-table__group-rows[hidden] {
    display: none;
}

.erp-pivot-table__summary-label,
.erp-pivot-table__summary-cell {
    background: color-mix(in srgb, var(--surface-sunken) 76%, var(--surface));
    color: var(--color-kview);
    font-weight: 700;
}

.erp-pivot-table__summary-label {
    padding: 0.72rem 1rem;
    border-bottom: 1px solid var(--divider);
    text-align: left;
}

.erp-pivot-table__summary-cell .erp-cell-number {
    font-weight: 750;
}

.erp-pivot-table__persistent-scroll {
    margin-top: -1px;
}

@media (hover: hover) {
    .erp-pivot-table__scroll.is-horizontally-scrollable {
        scrollbar-width: none;
    }

    .erp-pivot-table__scroll.is-horizontally-scrollable::-webkit-scrollbar {
        width: 0;
        height: 0;
    }
}

@media (hover: none) and (pointer: coarse) {
    .erp-pivot-table__persistent-scroll {
        display: none;
    }
}

@container erp-pivot-table (max-width: 560px) {
    .erp-pivot-table__group-copy {
        display: grid;
        gap: 0.08rem;
    }
}
