/*
 * A spreadsheet's preview (resources/js/sheet-preview.js): the icon of an
 * xlsx, xls, ods, csv, … file in a file list is a button, and opens a dialog
 * with the file's sheets as tables, laid out like a spreadsheet (column
 * letters on top, row numbers on the left, both kept in view while
 * scrolling). Registered with FilamentAsset, so it ships on the apex site and
 * inside the panel.
 */

/* The icon: a button that looks like the icon box it replaces. */
.sheet-preview-trigger {
    cursor: zoom-in;
    border: 0;
    padding: 0;
    transition: background-color 0.15s;
}

.sheet-preview-trigger:hover {
    background-color: rgb(229 231 235);
}

.dark .sheet-preview-trigger:hover {
    background-color: rgb(55 65 81);
}

.sheet-preview-trigger:focus-visible {
    outline: 2px solid rgb(79 70 229);
    outline-offset: -2px;
}

.sheet-preview {
    width: min(72rem, calc(100vw - 2rem));
    max-width: none;
    height: min(48rem, calc(100dvh - 2rem));
    max-height: none;
    margin: auto;
    padding: 0;
    border: 0;
    border-radius: 0.75rem;
    background: #fff;
    color: rgb(17 24 39);
    box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.35);
}

.sheet-preview::backdrop {
    background: rgb(17 24 39 / 0.6);
}

.sheet-preview-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sheet-preview-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgb(229 231 235);
}

.sheet-preview-title {
    flex: 1;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    font-size: 1rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sheet-preview-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: 0.5rem;
    background: transparent;
    color: rgb(107 114 128);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

.sheet-preview-close:hover {
    background: rgb(243 244 246);
    color: rgb(17 24 39);
}

/* One button per sheet, when there is more than one. */
.sheet-preview-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    padding: 0.5rem 1rem 0;
}

.sheet-preview-tabs[hidden] {
    display: none;
}

.sheet-preview-tabs button {
    padding: 0.25rem 0.75rem;
    border: 1px solid rgb(209 213 219);
    border-radius: 0.375rem;
    background: #fff;
    color: inherit;
    font-size: 0.875rem;
    cursor: pointer;
}

.sheet-preview-tabs button[aria-pressed='true'] {
    border-color: rgb(79 70 229);
    background: rgb(238 242 255);
    color: rgb(67 56 202);
    font-weight: 600;
}

.sheet-preview-status {
    margin: 0;
    padding: 0.5rem 1rem 0;
    color: rgb(75 85 99);
    font-size: 0.875rem;
}

.sheet-preview-status:empty {
    display: none;
}

.sheet-preview-body {
    flex: 1;
    min-height: 0;
    margin: 0.75rem 1rem 1rem;
    overflow: auto;
    border: 1px solid rgb(229 231 235);
    border-radius: 0.375rem;
}

.sheet-preview-body table {
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
}

.sheet-preview-body caption {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.sheet-preview-body th,
.sheet-preview-body td {
    max-width: 24rem;
    padding: 0.25rem 0.5rem;
    border-right: 1px solid rgb(229 231 235);
    border-bottom: 1px solid rgb(229 231 235);
    overflow: hidden;
    text-align: left;
    text-overflow: ellipsis;
    vertical-align: top;
    white-space: pre;
}

/* Column letters and row numbers stay in view. */
.sheet-preview-body thead th,
.sheet-preview-body thead td,
.sheet-preview-body tbody th {
    position: sticky;
    background: rgb(243 244 246);
    color: rgb(107 114 128);
    font-weight: 500;
}

.sheet-preview-body thead th,
.sheet-preview-body thead td {
    top: 0;
    z-index: 1;
    text-align: center;
}

.sheet-preview-body tbody th {
    left: 0;
    text-align: right;
}

.sheet-preview-body thead td {
    left: 0;
    z-index: 2;
}

.dark .sheet-preview {
    background: rgb(17 24 39);
    color: rgb(243 244 246);
}

.dark .sheet-preview-header,
.dark .sheet-preview-body,
.dark .sheet-preview-body th,
.dark .sheet-preview-body td {
    border-color: rgb(55 65 81);
}

.dark .sheet-preview-close:hover {
    background: rgb(31 41 55);
    color: rgb(243 244 246);
}

.dark .sheet-preview-tabs button {
    border-color: rgb(75 85 99);
    background: transparent;
}

.dark .sheet-preview-tabs button[aria-pressed='true'] {
    border-color: rgb(129 140 248);
    background: rgb(49 46 129);
    color: rgb(224 231 255);
}

.dark .sheet-preview-status {
    color: rgb(156 163 175);
}

.dark .sheet-preview-body thead th,
.dark .sheet-preview-body thead td,
.dark .sheet-preview-body tbody th {
    background: rgb(31 41 55);
    color: rgb(156 163 175);
}
