:root {
    --filtered-text: #53dcd7;
    --filtered-background: #122f31;
    --filtered-border: #122f31;
}

.sheet {
    position: fixed;
    width: 100%;
    height: 100%;
    overflow: auto;
    background: var(--bg-primary);
}

.sheet-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 3;
    display: flex;
    height: 32px;
    width: 100%;
    background: var(--bg-primary-alt);
    line-height: 32px;
    gap: .4rem;
    padding: 0 .4rem;
}

.sheet-toolbar-primary,
.sheet-toolbar-secondary {
    display: flex;
    gap: .4rem;
}

.sheet-toolbar-primary {
    flex-shrink: 0;
}

.sheet-toolbar-primary:empty {
    display: none;
}

.sheet-toolbar-secondary {
    overflow: auto;
    flex-shrink: 1;
}

.sheet-toolbar-secondary * {
    white-space: nowrap;
}

.sheet-toolbar-buttons > button,
.sheet-toolbar-buttons > .button {
    display: block;
    padding: 0;
    width: 1.5rem;
    height: 1.5rem;
    line-height: 1.5rem;
    text-align: center;
}

.sheet-toolbar .label {
    position: relative;
    line-height: normal;
    height: fit-content;
    top: .3rem;
}

.sheet-head {
    position: sticky;
    top: 32px;
    z-index: 2;
    background: var(--bg-secondary);
    height: fit-content;
    border-top: 1px solid var(--border-secondary);
    border-bottom: 1px solid var(--border-secondary);
}

.sheet-body {
    display: flex;
    flex-direction: column;
    padding-top: 30px;
    width: fit-content;
    height: fit-content;
}

.sheet-row {
    display: flex;
}

.sheet-row:nth-child(even) .sheet-cell:not(.sheet-cell-head) {
    background: var(--bg-primary-alt);
}

.sheet-row.hidden {
    display: none;
}

.sheet-row.hidden + .sheet-row:not(.hidden) {
    border-top: 3px solid var(--filtered-border);
}

.sheet-cell {
    position: relative;
    padding: 0;
    outline: 1px solid var(--border-secondary);
    cursor: cell;
    white-space: nowrap;
    overflow: hidden;
    font-size: 14px;
    background: var(--bg-primary);
    flex-grow: 0;
    flex-shrink: 0;
    /*user-select: none;*/ /* Removed as it blocked pasting events before first click (maybe a focus issue?) */
}

.sheet-cell-content {
    position: absolute;
    top: 50%;
    left: 0;
    display: inline-block;
    padding: 8px;
    transform: translateY(-50%);
    line-height: 1;
    user-select: none;
    overflow: hidden;
}

.sheet-cell-head {
    width: 42px;
    position: sticky;
    left: 0;
    z-index: 1;
    border-left: 1px solid var(--border-secondary);
}

.sheet-row-head .sheet-cell,
.sheet-cell-head {
    text-align: center;
    background-color: var(--bg-secondary);
    cursor: default;
}

.selected {
    background: var(--bg-selection) !important;
}

.selected ::selection {
    --bg-selection-alt: #2781be;
    background-color: var(--bg-selection-alt);
}

.sheet-cell-input {
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
    width: 100%;
    height: 100%;
    background: inherit;
    border: none;
    font: inherit;
    padding: 8px;
    resize: none;
    line-height: 1;
    color: inherit;
    border-radius: 0;
}

.sheet-cell-input:focus {
    outline: none;
    border: none;
}

.handle {
    position: absolute;
}

.handle.hidden {
    display: none;
}

.handle-column {
    height: 100%;
    top: 0;
    width: 5px;
    cursor: col-resize;
}

.handle-row {
    width: 42px;
    left: 0;
    height: 5px;
    cursor: row-resize;
    z-index: 2;
}

.sheet-cell-top-left {
    cursor: cell !important;
}

.sheet-cell-shelf {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.sheet-column-name {
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
}

.sheet-cell.filtered .sheet-column-name {
    color: var(--filtered-text);
}

.sheet-cell.filtered {
    background-color: var(--filtered-background);
}

.sheet-column-name-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    border: none;
    background: inherit;
    outline: none;
    font: inherit;
    text-align: inherit;
    color: inherit;
    margin: .4rem 0;
    padding: 0;
    line-height: 1;
}

.aleft,
.aleft .sheet-cell-input {
    text-align: left;
}

.acenter,
.acenter .sheet-cell-input {
    text-align: center;
}

.acenter .sheet-cell-content {
    left: 50%;
    transform: translate(-50%, -50%);
}

.aright,
.aright .sheet-cell-input {
    text-align: right;
}

.aright input[type=number].sheet-cell-input {
    text-align: center;
}

.aright .sheet-cell-content {
    float: right;
    left: unset;
    right: 0;
}

.highlight {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

.sheet-cell.selected .highlight {
    opacity: 0.8;
}

.highlight-accent {
    background: var(--mark);
}

.highlight-success {
    background: var(--success);
}

.highlight-error {
    background: var(--warning);
}

.highlight+.sheet-cell-content {
    color: var(--text-dark);
}

.script-textarea {
    font-family: "Fira Code", monospace;
    resize: vertical;
}

.sheet-shrink .sheet-cell {
    font-size: 12px;
}

.sheet-shrink .sheet-cell-content {
    padding: 2px;
}

.sheet-shrink .sheet-cell-input {
    padding: 5px 2px 2px 2px;
}

@media print {

    .sheet-toolbar {
        position: relative;
        background: none;
    }

    .sheet-toolbar-primary {
        display: none;
    }

    .sheet {
        position: relative;
        overflow: visible;
    }

    .sheet-head {
        background: none;
        border-top: none;
        border-bottom: none;
    }

    .sheet-body {
        padding-top: 0;
    }

    .sheet-row {
        break-inside: avoid;
    }

}