$spreadsheet-tab-font-size: 0.875rem !default;
$spreadsheet-cell-border: var(--rz-border-normal) !default;
$spreadsheet-header-background-color: var(--rz-base-200) !default;
$spreadsheet-header-active-background-color: var(--rz-secondary-lighter) !default;
$spreadsheet-splitter-background-color: var(--rz-base-200) !default;

.rz-spreadsheet {
    display: flex;
    flex-direction: column;
    border: var(--rz-spreadsheet-cell-border);
    outline: none;
    position: relative;

    .rz-tabview-nav {
        background-color: var(--rz-tabs-tab-background-color);
    }

    .rz-tabview {
        --rz-tabs-tab-padding-block: 0.25rem;
        --rz-tabs-tab-padding-inline: 0.5rem;
        --rz-tabs-tab-font-size: var(--rz-spreadsheet-tab-font-size);
    }

    .rz-tabview-panels {
        border: none;
    }

    .rz-tabview-panel {
        padding: 0.25rem;
    }
}

.rz-spreadsheet-table-design {
    overflow-y: hidden;

    .rz-label {
        font-size: var(--rz-input-font-size-sm);
    }
}

.rz-virtual-grid {
    position: relative;
    overflow: hidden;
}

.rz-virtual-grid-content {
    position: absolute;
    z-index: 1;
    overflow: hidden;
}

.rz-virtual-grid-scroller {
    overflow: scroll;;
    position: absolute;
    width: 100%;
    height: 100%;
}

.rz-spreadsheet-formula-editor {
    padding: 0 0.25rem 0.25rem;
    border-bottom: var(--rz-spreadsheet-cell-border);

    .rz-spreadsheet-editor {
        border-radius: var(--rz-input-border-radius);

        &::before {
            content: 'function';
            font-family: var(--rz-icon-font-family);
            font-size: 1rem;
            font-weight: 300;
            position: absolute;
            inset-inline-start: 0.25rem;
            top: 50%;
            transform: translateY(-50%);
            color: var(--rz-text-tertiary-color);
            pointer-events: none;
            z-index: 1;
        }
    }

    .rz-spreadsheet-editor-input,
    .rz-spreadsheet-editor-highlight {
        min-height: 1.425rem;
        padding: 0.125rem;
        padding-inline-start: 1.5rem;
    }
}

.rz-spreadsheet-cell {
    position: absolute;
    border-right: var(--rz-spreadsheet-cell-border);
    border-bottom: var(--rz-spreadsheet-cell-border);
    cursor: cell;
    font-size: 0.75rem;
    padding: 0.125rem;
    box-sizing: border-box;
    white-space: nowrap;
    overflow: hidden;
    background: var(--rz-base-background-color);
    user-select: none;
    -webkit-user-select: none;
}

.rz-spreadsheet-selection-cell {
    position: absolute;
    pointer-events: none;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.2);
}

.rz-spreadsheet-selection-cell-top {
    border-top: 2px solid var(--rz-primary);
}

.rz-spreadsheet-selection-cell-right {
    border-right: 2px solid var(--rz-primary);
}

.rz-spreadsheet-selection-cell-bottom {
    border-bottom: 2px solid var(--rz-primary);
}

.rz-spreadsheet-selection-cell-left {
    border-left: 2px solid var(--rz-primary);
}

.rz-spreadsheet-selection-range {
    position: absolute;
    pointer-events: none;
    box-sizing: border-box;
    background: var(--rz-primary-lighter);
    z-index: 2;
}

.rz-spreadsheet-selection-range-top {
    border-top: 2px solid var(--rz-primary);
}

.rz-spreadsheet-selection-range-right {
    border-right: 2px solid var(--rz-primary);
}

.rz-spreadsheet-selection-range-bottom {
    border-bottom: 2px solid var(--rz-primary);
}

.rz-spreadsheet-selection-range-left {
    border-left: 2px solid var(--rz-primary);
}

.rz-spreadsheet-selection-range-mask {
    mask-repeat: no-repeat;
    mask-image: linear-gradient(black, black),
                linear-gradient(white, white);
    mask-composite: exclude;
    mask-repeat: no-repeat;
}

.rz-spreadsheet-autofill-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--rz-primary);
    border: 1px solid var(--rz-base-background-color);
    box-sizing: border-box;
    cursor: crosshair;
    z-index: 1;
    pointer-events: auto;
}

.rz-spreadsheet-autofill-range {
    position: absolute;
    pointer-events: none;
    box-sizing: border-box;
    background: var(--rz-primary-lighter);
    z-index: 1;
}

.rz-spreadsheet-autofill-range-top {
    border-top: 2px dashed var(--rz-primary);
}

.rz-spreadsheet-autofill-range-right {
    border-right: 2px dashed var(--rz-primary);
}

.rz-spreadsheet-autofill-range-bottom {
    border-bottom: 2px dashed var(--rz-primary);
}

.rz-spreadsheet-autofill-range-left {
    border-left: 2px dashed var(--rz-primary);
}

.rz-spreadsheet-autofill-handle.rz-spreadsheet-frozen-row,
.rz-spreadsheet-autofill-handle.rz-spreadsheet-frozen-column {
    z-index: 3;
}

.rz-spreadsheet-autofill-handle.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column {
    z-index: 4;
}

.rz-spreadsheet-autofill-range.rz-spreadsheet-frozen-row,
.rz-spreadsheet-autofill-range.rz-spreadsheet-frozen-column {
    z-index: 3;
}

.rz-spreadsheet-autofill-range.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column {
    z-index: 4;
}

.rz-spreadsheet-column-header, .rz-spreadsheet-corner-header, .rz-spreadsheet-row-header {
    text-align: center;
    position: absolute;
    box-sizing: border-box;
    background: var(--rz-spreadsheet-header-background-color);
    border-right: var(--rz-spreadsheet-cell-border);
    border-bottom: var(--rz-spreadsheet-cell-border);
    font-weight: 500;
    font-size: 0.75rem;
    padding: 0.125rem;
    z-index: 1;
    user-select: none;
    -webkit-user-select: none;
}

.rz-spreadsheet-column-header {
    cursor: s-resize;
}

.rz-spreadsheet-row-header {
    cursor: e-resize;
}

.rz-spreadsheet-header-active {
    background: var(--rz-spreadsheet-header-active-background-color);
}

.rz-spreadsheet-header-selected {
    background: var(--rz-primary);
    color: var(--rz-on-primary);
}

.rz-spreadsheet-cell-editor {
    position: absolute;
    z-index: 1;
    background: var(--rz-base-background-color);
}

.rz-spreadsheet-cell-editor .rz-spreadsheet-editor {
    border: 2px solid var(--rz-primary);
}

.rz-spreadsheet-cell-editor .rz-spreadsheet-editor-input {
    outline: none;
}

.rz-spreadsheet-editor {
    position: relative;
    border: var(--rz-input-border);
    font-size: 0.8rem;
    min-width: fit-content;
    min-height: 100%;
    box-sizing: border-box;
    background-color: var(--rz-base-background-color);
    transition: var(--rz-input-transition);

    &:hover {
        border: var(--rz-input-hover-border);
        background-color: var(--rz-input-hover-background-color);
    }

    &:focus-within {
        border: var(--rz-input-focus-border);
        background-color: var(--rz-input-focus-background-color);
        outline: var(--rz-input-focus-outline);
        outline-offset: var(--rz-input-focus-outline-offset);
    }
}

.rz-spreadsheet-editor-input {
    color: transparent;
    caret-color: var(--rz-text-color);
    outline: none;
}

.rz-spreadsheet-editor-highlight {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    color: var(--rz-cell-color, inherit);
}

.rz-number-highlight {
    color: var(--rz-cell-color, #098658);
    font-weight: 500;
}

.rz-string-highlight {
    color: #a31515;
}

.rz-cell-highlight {
    font-weight: 500;
}

.rz-function-highlight {
    color: #795e26;
    font-weight: 500;
}

.rz-operator-highlight {
    color: var(--rz-cell-color, var(--rz-text-color));
    font-weight: 500;
}

.rz-default-highlight {
    color: var(--rz-cell-color, var(--rz-text-color));
}

.rz-spreadsheet-highlight-popup {
    display: none;
    position: absolute;
    @extend %dropdown-panel;
    width: 300px;
    overflow: auto;
    box-sizing: content-box;
    
    .rz-autocomplete-items {
        max-height: min(240px, 40vh);
        overflow-y: auto;
    }
}

.rz-spreadsheet-frozen-row {
    z-index: 2;
}

.rz-spreadsheet-frozen-column {
    z-index: 2;
}

.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column {
    z-index: 3;
}

.rz-spreadsheet-corner-header {
    z-index: 10;
}

.rz-spreadsheet-column-header.rz-spreadsheet-frozen-column,
.rz-spreadsheet-row-header.rz-spreadsheet-frozen-row {
    z-index: 4;
}

.rz-spreadsheet-selection-cell {
   z-index: 1;
}

.rz-spreadsheet-selection-range {
    z-index: 1;
}

.rz-spreadsheet-selection-cell.rz-spreadsheet-frozen-row,
.rz-spreadsheet-selection-cell.rz-spreadsheet-frozen-column {
    z-index: 3;
}

.rz-spreadsheet-selection-range.rz-spreadsheet-frozen-row,
.rz-spreadsheet-selection-range.rz-spreadsheet-frozen-column {
    z-index: 3;
}

.rz-spreadsheet-selection-cell.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column,
.rz-spreadsheet-selection-range.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column {
    z-index: 4;
    z-index: 4;
}

.rz-spreadsheet-cell-editor.rz-spreadsheet-frozen-row,
.rz-spreadsheet-cell-editor.rz-spreadsheet-frozen-column {
    z-index: 3;
}

.rz-spreadsheet-cell-editor.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column {
    z-index: 4;
}

.rz-spreadsheet-input-prompt {
    position: absolute;
    z-index: 1;
    background: var(--rz-warning-lighter);
    border: var(--rz-spreadsheet-cell-border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    padding: 0.5rem;
    max-width: 250px;
    font-size: 0.85rem;
    pointer-events: none;
    border-radius: var(--rz-border-radius);
}

.rz-spreadsheet-input-prompt-title {
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.rz-spreadsheet-input-prompt.rz-spreadsheet-frozen-row,
.rz-spreadsheet-input-prompt.rz-spreadsheet-frozen-column {
    z-index: 3;
}

.rz-spreadsheet-input-prompt.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column {
    z-index: 4;
}

.rz-spreadsheet-validation-error {
    position: absolute;
    z-index: 1;
    background: var(--rz-danger-lighter);
    border: 1px solid var(--rz-danger);
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    padding: 0.5rem;
    max-width: 300px;
    font-size: 0.85rem;
    pointer-events: none;
    border-radius: var(--rz-border-radius);
}

.rz-spreadsheet-validation-error-message {
    color: var(--rz-danger);
}

.rz-spreadsheet-validation-error.rz-spreadsheet-frozen-row,
.rz-spreadsheet-validation-error.rz-spreadsheet-frozen-column {
    z-index: 3;
}

.rz-spreadsheet-validation-error.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column {
    z-index: 4;
}

.rz-spreadsheet-horizontal-splitter,
.rz-spreadsheet-vertical-splitter {
    position: absolute;
    background-color: var(--rz-spreadsheet-splitter-background-color);
    z-index: 6;
}

.rz-spreadsheet-table-frame {
    position: absolute;
    z-index: 1;
    pointer-events: none;
}

.rz-spreadsheet-table-frame-top {
    border-top: 1px solid var(--rz-text-color);
}

.rz-spreadsheet-table-frame-left {
    border-left: 1px solid var(--rz-text-color);
}

.rz-spreadsheet-table-frame-right {
    border-right: 1px solid var(--rz-text-color);
}

.rz-spreadsheet-table-frame-bottom {
    border-bottom: 1px solid var(--rz-text-color);
}

.rz-spreadsheet-table-frame.rz-spreadsheet-frozen-row,
.rz-spreadsheet-table-frame.rz-spreadsheet-frozen-column {
    z-index: 3;
}

.rz-spreadsheet-selection-cell.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column,
.rz-spreadsheet-table-frame.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column {
    z-index: 4;
    z-index: 4;
}

.rz-spreadsheet-column-resize-handle,
.rz-spreadsheet-row-resize-handle {
    position: absolute;
    z-index: 5;
    &:hover {
        background-color: var(--rz-primary);
    }
}

.rz-spreadsheet-column-resize-handle {
    width: 5px;
    cursor: ew-resize;
    transform: translateX(-50%);
}

.rz-spreadsheet-row-resize-handle {
    height: 5px;
    cursor: ns-resize;
    transform: translateY(-50%);
}

.rz-spreadsheet-cell-chevron {
    position: absolute;
    top: 2px;
    right: 2px;
    border-radius: 0;
    padding: 0 !important;
}

.rz-spreadsheet-cell-popup {
    display: none;
    position: absolute;
    overflow: hidden;
    width: 300px;
    padding: 0 var(--rz-dropdown-horizontal-padding);
    background: var(--rz-base-background-color);
    border: var(--rz-border-normal);
    border-radius: var(--rz-border-radius);
    box-shadow: var(--rz-dropdown-panel-shadow);
}

.rz-menu.rz-spreadsheet-cell-menu {
    --rz-menu-item-padding-block: var(--rz-input-padding-block-sm);
    --rz-menu-item-padding-inline: var(--rz-input-padding-inline-sm);
    font-size: var(--rz-input-font-size-sm);
    margin-inline: calc(-1 * var(--rz-dropdown-horizontal-padding));
    border: none;
    border-radius: 0;
    box-shadow: none;

    .rz-navigation-item-icon {
        font-size: 1rem;
    }
}

.rz-spreadsheet-cell-menu-filter {
    max-height: min(200px, 40vh);
    overflow-y: auto;
    padding: calc(var(--rz-dialog-content-padding) - max(var(--rz-context-menu-padding-block), var(--rz-context-menu-padding-inline)));
    border-top: var(--rz-border-normal);
    margin-top: 0.5rem;
}

.rz-spreadsheet-cell-menu-filter .rz-navigation-item {
    padding-block: 0.25rem;
}

.rz-spreadsheet-cell-menu-filter .rz-chkbox {
    margin-inline-end: calc(1.5rem - var(--rz-checkbox-width));
}

.rz-spreadsheet-cell-menu-buttons {
    padding: calc(var(--rz-dialog-content-padding) - max(var(--rz-context-menu-padding-block), var(--rz-context-menu-padding-inline)));
    margin-bottom: calc(-1 * var(--rz-context-menu-padding-block));
    border-top: var(--rz-border-normal);

    .rz-button {
        flex: 1;
    }
}

.rz-spreadsheet-cell-hyperlink {
    color: var(--rz-link-color);
    text-decoration: var(--rz-link-text-decoration);
    cursor: pointer;

    &:hover {
        color: var(--rz-link-hover-color);
        text-decoration: var(--rz-link-hover-text-decoration);
    }

    &:visited {
        color: #954F72;
    }
}

.rz-spreadsheet-cell-invalid {
    &::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        width: 0;
        height: 0;
        border-style: solid;
        border-width: 0 6px 6px 0;
        border-color: transparent var(--rz-danger) transparent transparent;
    }
}

.rz-spreadsheet-cell-number {
    text-align: right;
}

.rz-spreadsheet-cell-error {
    color: var(--rz-danger);
}

.rz-spreadsheet-cell-editor-number {
    text-align: right;
}


.rz-function-hint-name-active {
    font-weight: bold;
}

.rz-function-hint-parameter-active {
    font-weight: bold;
}

.rz-spreadsheet-image {
    position: absolute;
    pointer-events: none;
    z-index: 1;
}

.rz-spreadsheet-image-clip {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.rz-spreadsheet-image.rz-spreadsheet-frozen-row,
.rz-spreadsheet-image.rz-spreadsheet-frozen-column {
    z-index: 3;
}

.rz-spreadsheet-image.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column {
    z-index: 4;
}

.rz-spreadsheet-image-container {
    position: absolute;
    overflow: hidden;

    img {
        width: 100%;
        height: 100%;
        object-fit: fill;
        display: block;
        pointer-events: auto;
        cursor: grab;
    }

    .rz-spreadsheet-selection-range {
        position: absolute;
        inset: 0;
    }
}

.rz-spreadsheet-resize-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--rz-primary);
    border: 1px solid var(--rz-base-background-color);
    pointer-events: auto;
    z-index: 5;
}

.rz-spreadsheet-resize-nw { cursor: nwse-resize; }
.rz-spreadsheet-resize-n { cursor: ns-resize; }
.rz-spreadsheet-resize-ne { cursor: nesw-resize; }
.rz-spreadsheet-resize-e { cursor: ew-resize; }
.rz-spreadsheet-resize-se { cursor: nwse-resize; }
.rz-spreadsheet-resize-s { cursor: ns-resize; }
.rz-spreadsheet-resize-sw { cursor: nesw-resize; }
.rz-spreadsheet-resize-w { cursor: ew-resize; }

.rz-spreadsheet-chart {
    position: absolute;
    pointer-events: none;
    z-index: 1;
}

.rz-spreadsheet-chart-clip {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.rz-spreadsheet-chart.rz-spreadsheet-frozen-row,
.rz-spreadsheet-chart.rz-spreadsheet-frozen-column {
    z-index: 3;
}

.rz-spreadsheet-chart.rz-spreadsheet-frozen-row.rz-spreadsheet-frozen-column {
    z-index: 4;
}

.rz-spreadsheet-chart-container {
    position: absolute;
    overflow: hidden;
    background: var(--rz-base-background-color);
    pointer-events: auto;
    cursor: grab;

    .rz-spreadsheet-selection-range {
        position: absolute;
        inset: 0;
    }
}

.rz-spreadsheet-chart-unsupported {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: var(--rz-base-200);
    color: var(--rz-text-disabled-color);
    font-size: 0.875rem;
}

.rz-spreadsheet-sheet-tabs {
    display: flex;
    flex-direction: row;
    align-items: center;
    border-top: var(--rz-spreadsheet-cell-border);
}

.rz-spreadsheet-sheet-tabs .rz-tabview {
    flex: 1;
    min-width: 0;
}

.rz-spreadsheet-sheet-tabs .rz-tabview-panels {
    display: none;
}

.rz-spreadsheet-sheet-tabs .rz-tabview-nav {
    border: none;
}

.rz-spreadsheet-add-sheet {
    margin-inline: 4px;
    flex-shrink: 0;
}

// Visual range picker — Excel-style RefEdit replacement
.rz-range-picker {
    position: relative;
    display: inline-flex;
    width: 100%;

    .rz-textbox {
        flex: 1;
    }
}

.rz-range-picker-collapse {
    position: absolute;
    inset-inline-end: 0;
    inset-block: 0;
    width: 1.75rem;
    background: transparent;
    border: 0;
    cursor: pointer;
    color: var(--rz-text-color);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;

    &:hover {
        color: var(--rz-primary);
    }

    .rzi {
        font-size: 0.875rem;
    }
}

.rz-range-picker-bar {
    position: absolute;
    top: 0.5rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 7;
    background: var(--rz-base-background-color);
    border: 1px solid var(--rz-primary);
    border-radius: var(--rz-border-radius);
    box-shadow: var(--rz-shadow-4);
    padding: 0.375rem 0.5rem;
    min-width: 280px;
    max-width: 480px;
    font-family: var(--rz-font-family);
    font-size: 0.875rem;

    .rz-range-picker-bar-value {
        flex: 1;
        color: var(--rz-text-color);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

.rz-spreadsheet-dialog-actions {
    margin-top: 0.5rem;

    .rz-button {
        min-width: 6rem;
    }
}
