/* SPDX-License-Identifier: LicenseRef-Highcharts */

/**
 * @license Highcharts Grid Lite v3.1.0
 *
 * (c) 2009-2025 Highsoft AS
 *
 * A commercial license may be required depending on use.
 * See www.highcharts.com/license
 */

@import url("./grid-base-variables.css");
@import url("./grid-popup-variables.css");
@import url("./grid-menu-variables.css");
@import url("./grid-link-variables.css");
@import url("./grid-input-variables.css");
@import url("./grid-button-variables.css");
@import url("./grid-icon-variables.css");
@import url("./grid-caption-variables.css");
@import url("./grid-description-variables.css");
@import url("./grid-pagination-variables.css");
@import url("./grid-table-variables.css");
@import url("./grid-theme-default.css");

/* Grid container */
.hcg-container {
    container-type: inline-size;
    container-name: hcg;
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    box-sizing: border-box;
    color-scheme: light dark;
    max-height: inherit;
}

.highcharts-light .hcg-container {
    color-scheme: light;
}

.highcharts-dark .hcg-container {
    color-scheme: dark;
}

.hcg-container * {
    box-sizing: border-box;
}

.hcg-container:has(.hcg-no-data) {
    justify-content: center;
    align-items: center;
}

/* ----------------------------------------------------------
  INPUT ELEMENTS
------------------------------------------------------------ */

.hcg-container .hcg-input {
    width: 100%;

    &:disabled {
        opacity: 0.4;
        cursor: not-allowed;
    }

    &::placeholder {
        color: #767676;
    }

    &:focus-visible {
        outline: none;
    }

    &[type="checkbox"] {
        --ig-input-checkbox-size: 1.333em;

        appearance: none;
        width: var(--ig-input-checkbox-size);
        height: var(--ig-input-checkbox-size);
        cursor: pointer;
        position: relative;

        &:checked::before {
            content: "";
            position: absolute;
            inset: 0;
            margin: 0.05em;
            mask: center/contain no-repeat;
            mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 13l4 4L19 7'/%3E%3C/svg%3E");
        }
    }

    select& {
        appearance: none;
        background-image: url("data:image/svg+xml,%3csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M3.5 7.5L6 10L8.5 7.5M3.5 4.5L6 2L8.5 4.5' stroke='%23767676' stroke-linecap='round' stroke-linejoin='round'/%3e%3c/svg%3e");
        background-repeat: no-repeat;
        background-position: right 5px center;

        /* Reserve space for the chevron (functional shell, not theme). */
        padding-inline-end: 1.25rem;
        white-space: nowrap;
        text-overflow: ellipsis;
    }
}

/* ----------------------------------------------------------
  BUTTON ELEMENT
------------------------------------------------------------ */

.hcg-container :is(.hcg-button, .hcg-icon) {
    position: relative;
    display: inline-flex;
    vertical-align: middle;
    align-items: center;
    justify-content: center;
    flex-direction: row;
    line-height: 1;
    gap: 2px;
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, border 0.2s ease;

    svg {
        width: 0.9em;
        height: 0.9em;
        display: block;
    }

    span {
        display: inline-block;
        line-height: 1;
    }

    span:empty {
        display: none;
    }

    &.reverse {
        flex-direction: row-reverse;
    }

    &:focus-visible {
        outline: none;
    }

    &:disabled {
        opacity: 0.4;
        cursor: not-allowed;
    }
}

/* ----------------------------------------------------------
  TABLE ELEMENTS
------------------------------------------------------------ */

/* <table> */
.hcg-container .hcg-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    table-layout: fixed;
    flex: 1;

    &.hcg-scrollable-content {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    /* <thead> */
    &.hcg-virtualization thead {
        display: block;
    }

    &.hcg-column-virtualization thead tr {
        display: block;
        overflow: visible;
    }

    &.hcg-column-virtualization thead th .hcg-header-cell-container {
        height: 100%;
    }

    thead th {
        position: relative;
    }

    /* <tbody> */
    &.hcg-scrollable-content > tbody {
        height: 100%;
        overflow: auto;
        min-height: 0;
        flex: 1;
    }

    &.hcg-virtualization > tbody {
        display: block;
        position: relative;
    }

    > tbody > tr {
        overflow: hidden;
        width: 100%;
    }

    > tbody > tr > :where(.hcg-cell) {
        position: relative;
        line-height: 1em;
        overflow: hidden;
    }

    > tbody > tr.hcg-mocked-row > :where(.hcg-cell) {
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    .hcg-last-header-cell-in-row,
    tbody tr > :where(.hcg-cell):last-child {
        border-right: none;
    }

    tbody tr:last-of-type > :where(.hcg-cell) {
        border-bottom: none;
    }

    &.hcg-scrollable-content > tbody > tr {
        display: block;
    }

    &.hcg-column-virtualization :is(thead tr, tbody tr) > :where(.hcg-cell, .hcg-header-cell) {
        display: inline-block;
        vertical-align: top;
    }

    &.hcg-virtualization > tbody > tr {
        position: absolute;
    }

    > tbody.hcg-rows-content-nowrap > tr > :where(.hcg-cell) {
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    > tbody > tr > :where(.hcg-cell):focus {
        outline: none;
    }
}

/* ----------------------------------------------------------
  HEADER ELEMENTS
------------------------------------------------------------ */
.hcg-container thead th {
    .hcg-header-cell-container {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .hcg-header-cell-content {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .hcg-header-cell-container.hcg-no-width .hcg-header-cell-content {
        visibility: hidden;
        transition: none;
    }

    .hcg-header-cell-icons {
        display: flex;
        overflow: hidden;
        align-items: center;
        max-width: 0;
        opacity: 0;
        z-index: 11;
        cursor: pointer;
        transition: max-width 0.3s ease, opacity 0.3s ease;
    }

    .hcg-header-cell-icons .hcg-icon.hcg-icon-selected::after {
        content: "";
        position: absolute;
        top: 2px;
        right: 2px;
        width: 0.3em;
        height: 0.3em;
        border-radius: 50%;
        background: currentColor;
    }

    :is(:hover, :focus-visible) .hcg-header-cell-icons,
    .hcg-header-cell-icons:has(.hcg-button:focus-visible, .hcg-icon:focus-visible, .hcg-button.hcg-button-selected, .hcg-icon.hcg-icon-highlighted, .hcg-icon.hcg-icon-selected),
    .hcg-header-cell-container.hcg-no-width .hcg-header-cell-icons {
        max-width: 100px;
        opacity: 1;
    }

    .hcg-header-cell-container.hcg-no-width .hcg-header-cell-menu-icon {
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        margin-left: 0;
    }

    .hcg-header-cell-icons .hcg-header-cell-menu-icon .hcg-icon {
        padding-inline: 3px;
    }

    .hcg-header-cell-icons > :first-child {
        margin-left: 5px;
    }

    .hcg-column-resizer {
        position: absolute;
        display: flex;
        align-items: center;
        justify-content: center;
        top: 0;
        width: 9px;
        right: -5px;
        height: 100%;
        user-select: none;
        touch-action: none;
        z-index: 10;
        cursor: col-resize;
    }

    .hcg-column-resizer.hovered::after {
        content: "";
        height: 100%;
        width: max(3px, calc(var(--hcg-header-column-border-width, var(--hcg-border-width, 1px)) + 2px));
        background: var(--hcg-header-color, var(--hcg-color, currentColor));
    }
}

/* ----------------------------------------------------------
  PAGINATION ELEMENTS
------------------------------------------------------------ */

.hcg-container .hcg-pagination {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;

    > * {
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        align-items: center;
    }

    .hcg-pagination-info {
        justify-content: flex-start;
    }

    .hcg-pagination-controls {
        justify-content: center;

        .hcg-pagination-pages {
            display: flex;
            flex-wrap: nowrap;

            .hcg-button {
                display: inline-flex;
                align-items: center;
                justify-content: center;
            }

            span {
                display: inline-flex;
                align-items: center;
                justify-content: center;
            }
        }
    }

    .hcg-pagination-page-size {
        justify-content: flex-end;

        /* Override global `.hcg-input { width: 100% }` — themed sets explicit width. */
        select.hcg-input {
            width: auto;
        }
    }

    /* .hcg-pagination-nav-dropdown {
        display: none;
        min-width: 200px;
    } */

    &.hcg-pagination-left,
    &.hcg-pagination-center,
    &.hcg-pagination-right {
        > * {
            flex: 0 0 auto;
            min-width: auto;
        }
    }

    &.hcg-pagination-left { justify-content: flex-start; }
    &.hcg-pagination-center { justify-content: center; }
    &.hcg-pagination-right { justify-content: flex-end; }

    &:not(:has(.hcg-pagination-info)) .hcg-pagination-controls {
        justify-content: flex-start;
    }

    &:not(:has(.hcg-pagination-page-size)) .hcg-pagination-controls {
        justify-content: flex-end;
    }
}

@container hcg (max-width: 800px) {
    .hcg-container .hcg-pagination {
        flex-direction: column;
        align-items: stretch;

        /* Row gap when stacked — honor theme token when set. */
        gap: var(--hcg-pagination-gap, 0.5rem);
        --ig-pagination-stacked-align: center;

        &.hcg-pagination-left { --ig-pagination-stacked-align: flex-start; }
        &.hcg-pagination-right { --ig-pagination-stacked-align: flex-end; }

        > * {
            flex: 0 0 auto;
            justify-content: var(--ig-pagination-stacked-align);
        }

        .hcg-pagination-info,
        .hcg-pagination-controls,
        .hcg-pagination-page-size {
            justify-content: var(--ig-pagination-stacked-align);
        }

        .hcg-pagination-controls {
            /* Keep one row; scroll if controls still overflow. */
            flex-wrap: nowrap;
            max-width: 100%;
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
        }

        .hcg-pagination-pages {
            flex-wrap: nowrap;
        }

        .hcg-pagination-page-size {
            text-align: center;
            flex-wrap: wrap;
            gap: 0.5rem;
        }
        &.hcg-pagination-left .hcg-pagination-page-size { text-align: left; }
        &.hcg-pagination-right .hcg-pagination-page-size { text-align: right; }

        &:not(:has(.hcg-pagination-page-size)) .hcg-pagination-controls,
        &:not(:has(.hcg-pagination-info)) .hcg-pagination-controls {
            justify-content: var(--ig-pagination-stacked-align);
        }
    }
}

/* ----------------------------------------------------------
  CREDITS ELEMENT
------------------------------------------------------------ */

.hcg-credits,
.highcharts-light .hcg-credits {
    display: block;
    width: 114px;
    height: 20px;
    background-size: contain;
    background-repeat: no-repeat;
    background-image:
        image-set(
            /* stylelint-disable-next-line function-comma-newline-after */
            url("https://assets.highcharts.com/grid/logo_light.png") 1x,
            url("https://assets.highcharts.com/grid/logo_lightx2.png") 2x
        );
}

@media (prefers-color-scheme: dark) {
    .hcg-credits {
        background-image:
            image-set(
                /* stylelint-disable-next-line function-comma-newline-after */
                url("https://assets.highcharts.com/grid/logo_dark.png") 1x,
                url("https://assets.highcharts.com/grid/logo_darkx2.png") 2x
            );
    }
}

.highcharts-dark .hcg-credits {
    background-image:
        image-set(
            /* stylelint-disable-next-line function-comma-newline-after */
            url("https://assets.highcharts.com/grid/logo_dark.png") 1x,
            url("https://assets.highcharts.com/grid/logo_darkx2.png") 2x
        );
}

/* ----------------------------------------------------------
  POPUP ELEMENTS
------------------------------------------------------------ */
.hcg-container .hcg-popup {
    position: absolute;
    z-index: 1000;
    min-width: 200px;
    overflow: auto;
    border-width: 1px;
    border-style: solid;

    .hcg-menu-header {
        margin-bottom: 5px;
    }

    .hcg-menu-header-category {
        opacity: 0.5;
        user-select: none;
    }
}

/* ----------------------------------------------------------
  MENU ELEMENTS
------------------------------------------------------------ */

.hcg-container .hcg-menu-container {
    margin: 0;
    display: flex;
    flex-direction: column;
    list-style: none;
    padding: 0;

    .hcg-menu-item {
        display: flex;
        align-items: center;
        gap: 2px;
        width: 100%;
        min-width: 185px;
        background-color: transparent;
        border: 1px solid transparent;
    }

    .hcg-menu-item:not(:disabled) {
        cursor: pointer;
    }

    .hcg-menu-item:focus-visible {
        outline: none;
    }

    .hcg-menu-item-icon {
        --icon-size: 16px;

        flex: 0 0 var(--icon-size);
        width: var(--icon-size);
        height: var(--icon-size);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        opacity: 0.6;
    }

    .hcg-menu-item.active .hcg-menu-item-icon,
    .hcg-menu-item.highlighted .hcg-menu-item-icon,
    .hcg-menu-item:not(:disabled):hover .hcg-menu-item-icon {
        opacity: 1;
    }

    .hcg-menu-item-label {
        flex: 1 1 auto;
        min-width: 0;
        text-align: left;
        padding-left: 0.75rem;
    }

    .hcg-menu-divider {
        border-top-width: 1px;
        border-top-style: solid;
        height: 0;
    }
}

/* ----------------------------------------------------------
  FILTERING ELEMENTS
------------------------------------------------------------ */

.hcg-header-cell:has(.hcg-column-filter-wrapper) {
    overflow: hidden;
}

.hcg-column-filter-wrapper {
    width: 100%;
    display: flex;
    flex-flow: column;
    row-gap: 5px;
    min-width: 50px;
}

.hcg-column-filter-operator-spacer {
    visibility: hidden;
    pointer-events: none;
    user-select: none;
}

.hcg-clear-filter-button {
    appearance: none;
    background: none;
    border: 0;
    padding: 0;
    margin: 0;
    display: inline;
    vertical-align: baseline;
    font: inherit;
    font-size: 0.625rem;
    white-space: nowrap;
    font-weight: normal;
    align-self: end;
}

.hcg-clear-filter-button:hover {
    text-decoration: underline;
    cursor: pointer;
}

.hcg-clear-filter-button:disabled,
.hcg-clear-filter-button:disabled:hover {
    opacity: 0.5;
    text-decoration: none;
    cursor: default;
}

/* ----------------------------------------------------------
  OTHER ELEMENTS
------------------------------------------------------------ */

/* Sorting */
.hcg-table thead th.hcg-column-sortable {
    cursor: pointer;
}

/* Accessibility */
.hcg-visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    white-space: nowrap;
    clip: rect(1px, 1px, 1px, 1px);
    margin-top: -3px;
    opacity: 0.01;
}

.hcg-container.hcg-caption * {
    font: inherit;
    margin: 0;
}

/* Loader */
.hcg-loading-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    width: 100%;
    height: 100%;
    gap: 10px;
    color: var(--ig-loader-color);
}

.hcg-loading-wrapper .hcg-spinner {
    border-top-width: 5px;
    border-top-style: solid;
    border-top-color: var(--ig-loader-color);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Start Grid CSS Helpers Classes */

.hcg-table thead tr th.hcg-right .hcg-header-cell-content,
.hcg-table tbody tr > :where(.hcg-cell).hcg-right {
    text-align: right;
}

.hcg-table thead tr th.hcg-center .hcg-header-cell-content,
.hcg-table tbody tr > :where(.hcg-cell).hcg-center {
    text-align: center;
}

.hcg-table thead tr th.hcg-left .hcg-header-cell-content,
.hcg-table tbody tr > :where(.hcg-cell).hcg-left {
    text-align: left;
}

/* End Grid CSS Helpers Classes */
