/* Grid container and structure */
.asgrid-container {
    background: var(--base-white);
    border-radius: var(--radius-16);
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--neutrals-200);
    display: flex;
    flex-direction: column;
    max-height: 75vh;
}

    .asgrid-container .grid-title {
        padding: 20px 24px;
        color: var(--gray-900-reg);
    }

.grid {
    overflow-y: auto;
    min-height: 100px;
    max-height: var(--max-height-100, calc(100svh - 260px));
    flex: 1;
}

.grid-header {
    display: flex;
    padding: 16px 24px;
    align-items: center;
    justify-content: space-between;
    min-height: 80px;
    color: var(--neutrals-600);
}

.asgrid-container .actions-container {
    padding: 0 var(--spacing-12);
    display: flex;
    gap: var(--spacing-12);
}

/* Grid table styles */
.grid table {
    min-width: 100%;
    border-collapse: collapse;
}

    .grid table thead {
        background-color: var(--neutrals-50);
        color: var(--neutrals-600);
        border-bottom: 1px solid var(--neutrals-200);
        position: sticky;
        top: 0;
        z-index: 2;
    }

        .grid table thead th {
            padding: 12px 20px;
            text-align: left !important;
            background-color: var(--neutrals-50);
        }

            /* Override QuickGrid's default centering for all header cells */
            .grid table thead th > *,
            .grid table thead th .col-title {
                display: flex;
                align-items: center;
                justify-content: flex-start;
                text-align: left;
            }

            /* Override QuickGrid alignment classes that might be applied */
            .grid table thead th.col-justify-center,
            .grid table thead th.col-justify-end,
            .grid table thead th[class*="col-justify"] {
                justify-content: flex-start !important;
            }

                .grid table thead th.col-justify-center > *,
                .grid table thead th.col-justify-end > *,
                .grid table thead th[class*="col-justify"] > * {
                    justify-content: flex-start !important;
                }

.grid .col-header-content {
    justify-content: flex-start;
}

.grid table tbody tr {
    border-bottom: 1px solid var(--neutrals-200);
}

.grid table tbody td {
    padding: 16px 20px !important;
    color: var(--neutrals-600);
    font-size: 14px;
    line-height: 20px;
    font-weight: 400;
}

.grid table tbody tr:not([aria-rowindex]) {
    display: none;
}

/* Grid header layout */
.grid-header-left {
    display: flex;
    align-items: center;
    gap: var(--spacing-4);
}

.grid-header-right {
    display: flex;
    align-items: center;
    gap: var(--spacing-8);
}

.grid-header-text {
    color: var(--neutrals-700);
}

/* Results per page selector */
.page-size-select {
    height: 36px;
    padding: 0 8px;
    border: 1px solid var(--neutrals-300);
    border-radius: var(--radius-8, 8px);
    color: var(--neutrals-700);
    background: var(--base-white);
    cursor: pointer;
}

    .page-size-select:focus {
        outline: none;
        border-color: var(--primary-500);
        box-shadow: 0 0 0 2px var(--primary-100);
    }

/* Sort icon overrides for QuickGrid */
.grid th[aria-sort] .col-options-button {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: inherit;
    text-align: left;
    width: 100%;
}

    .grid th[aria-sort] .col-options-button::after {
        content: "";
        flex-shrink: 0;
        display: inline-block;
        width: 16px;
        height: 16px;
        background-repeat: no-repeat;
        background-position: center;
        background-size: contain;
    }

.grid th.col-sort-none .col-options-button::after {
    background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5 10L8 13L11 10M11 6L8 3L5 6' stroke='%238B929C' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C%2Fsvg%3E");
}

.grid .sort-header-btn.col-sort-none {
    background-image: none;
}

.grid th.col-sort-asc .col-options-button::after {
    background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M8 13V3M8 3L3 8M8 3L13 8' stroke='%2319395D' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C%2Fsvg%3E");
}

.grid th.col-sort-desc .col-options-button::after {
    background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M8 3V13M8 13L3 8M8 13L13 8' stroke='%2319395D' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C%2Fsvg%3E");
}

/* Grid sticky column - first column sticky by default */
/* If there's a checkbox in the first header, make the second column sticky instead */

/* Default: Make first column sticky when there's NO checkbox in first header */
.grid table thead:not(:has(th:first-child input[type="checkbox"])) th:first-child,
.grid table tbody:not(:has(~ thead th:first-child input[type="checkbox"])) td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    box-shadow: 2px 0 6px -2px rgba(10, 13, 18, 0.1);
}

.grid table thead:not(:has(th:first-child input[type="checkbox"])) th:first-child {
    background-color: var(--neutrals-50);
    z-index: 3;
}

.grid table tbody:not(:has(~ thead th:first-child input[type="checkbox"])) td:first-child {
    background-color: var(--base-white);
}

/* When there's a checkbox in first header column, make the SECOND column sticky */
.grid table thead:has(th:first-child input[type="checkbox"]) th:nth-child(2),
.grid table tbody:has(~ thead th:first-child input[type="checkbox"]) td:nth-child(2) {
    position: sticky;
    left: 0;
    z-index: 1;
    box-shadow: 2px 0 6px -2px rgba(10, 13, 18, 0.1);
}

.grid table thead:has(th:first-child input[type="checkbox"]) th:nth-child(2) {
    background-color: var(--neutrals-50);
    z-index: 3;
}

.grid table tbody:has(~ thead th:first-child input[type="checkbox"]) td:nth-child(2) {
    background-color: var(--base-white);
}

/* Minimum column width (non-checkbox columns) */
/* First column (checkbox) stays narrow; apply min-width starting from second column */
.grid table th:nth-child(n+2),
.grid table td:nth-child(n+2) {
    min-width: 120px;
}

.grid.grid-is-empty table tbody {
    display: none;
}

.grid table tbody tr:has(input[type="checkbox"]:checked) {
    background-color: var(--primary-50);
}

/* For selected rows, update the sticky column background */
/* If checkbox is in first column, second column is sticky */
.grid table tbody:has(~ thead th:first-child input[type="checkbox"]) tr:has(input[type="checkbox"]:checked) td:nth-child(2) {
    background-color: var(--primary-50);
}

/* If no checkbox in first column, first column is sticky */
.grid table tbody:not(:has(~ thead th:first-child input[type="checkbox"])) tr:has(input[type="checkbox"]:checked) td:first-child {
    background-color: var(--primary-50);
}

/* Grid empty state */
.grid-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    border-top: 1px solid var(--neutrals-200);
}

.grid-empty-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: var(--neutrals-100);
    border-radius: 50%;
    margin-bottom: 16px;
    color: var(--neutrals-500);
}

.grid-empty-text {
    text-align: center;
}

.grid-empty-title {
    color: var(--neutrals-700);
    margin-bottom: 4px;
}

.grid-empty-subtitle {
    color: var(--neutrals-500);
}

.clear-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.15s ease-in-out;
    position: relative;
    flex-shrink: 0;
}

    .clear-icon:hover {
        border-radius: 8px;
        background: var(--neutrals-50);
    }

/* Sort header button styles */
.sort-header-btn {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 4px !important;
    background: none !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
    cursor: pointer !important;
    font-size: inherit !important;
    font-weight: 500 !important;
    color: inherit !important;
    font-family: inherit !important;
    line-height: inherit !important;
    text-align: left !important;
    width: 100% !important;
}

    .sort-header-btn:focus-visible {
        outline: 2px solid var(--primary-600) !important;
        outline-offset: 2px !important;
        border-radius: 2px !important;
    }

    .sort-header-btn::after {
        content: '' !important;
        display: inline-block !important;
        width: 16px !important;
        height: 16px !important;
        flex-shrink: 0 !important;
        background-repeat: no-repeat !important;
        background-position: center !important;
        background-size: 16px 16px !important;
    }

    .sort-header-btn.col-sort-none::after {
        background-image: none !important;
    }

    .sort-header-btn.col-sort-asc::after {
        background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M8 13V3M8 3L3 8M8 3L13 8' stroke='%2319395D' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C%2Fsvg%3E") !important;
    }

    .sort-header-btn.col-sort-desc::after {
        background-image: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M8 3V13M8 13L3 8M8 13L13 8' stroke='%2319395D' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C%2Fsvg%3E") !important;
    }

/* Grid link styles */
.grid-link-primary {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary-700);
    text-decoration: none;
}

    .grid-link-primary:hover,
    .grid-link-primary:focus-visible {
        text-decoration: underline;
        color: var(--primary-700);
    }

.grid-link-secondary {
    color: var(--primary-700);
    text-decoration: none;
}

    .grid-link-secondary:hover,
    .grid-link-secondary:focus-visible {
        text-decoration: underline;
        color: var(--primary-700);
    }

.col-numeric {
    text-align: right;
}

.col-justify-right {
    text-align: right;
}

/* Grid selection and checkbox styles */
.grid-selection-header {
    display: flex !important;
    align-items: center;
    gap: 20px;
    width: 100%;
    justify-content: flex-start !important;
}

.grid-selection-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.grid-row-cb {
    cursor: pointer;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.grid-info-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.grid-checkbox-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.grid-checkbox-label-container {
    display: flex;
    flex-direction: column;
}

    .grid-checkbox-label-container span {
        line-height: 20px;
        color: var(--neutrals-700);
    }
