html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

/* Desktop: fixed-height shell so the table scrolls internally */
.app-main {
    height: 100vh;
    overflow: hidden;
}

/* Mobile: let the page scroll naturally */
@media (max-width: 959px) {
    .app-main {
        height: auto;
        overflow: visible;
    }
}

/* Desktop: header + options fixed, table scrolls */
@media (min-width: 960px) {
    .page-outer {
        display: flex;
        flex-direction: column;
        height: 100vh;
        padding: 1.25rem 2rem 1rem 2rem;
        overflow: hidden;
    }
    .page-static {
        flex-shrink: 0;
        padding-bottom: 0.75rem;
    }
    .page-scroll {
        flex: 1;
        overflow: auto;
    }
}

/* Mobile: vertical natural scroll, horizontal scroll on table */
@media (max-width: 959px) {
    .page-outer {
        padding: 0.5rem;
    }
    .page-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .col-hide-mobile {
        display: none;
    }
    .library-table td.col-title {
        white-space: normal;
        max-width: 40vw;
    }
}

.library-table {
    width: auto;
    border-collapse: collapse;
    border: 1px solid var(--mud-palette-divider);
}

.library-table th,
.library-table td {
    padding: 4px 8px;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-right: 1px solid var(--mud-palette-table-lines);
}

/* Drag handle on the right edge of each header for resizing the column.
   The header is position:sticky (a positioning context), so the absolutely
   positioned handle anchors to it without needing position:relative. */
.col-resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
    touch-action: none;
}

.col-resizer:hover {
    background-color: var(--mud-palette-primary);
    opacity: 0.4;
}

/* Leave room so the sort icon / label don't sit under the resize handle. */
.library-table th .th-label {
    margin-right: 2px;
}

.library-table th {
    vertical-align: top;
}

.th-top {
    display: flex;
    align-items: center;
    gap: 2px;
}

/* Per-column filter input that lives inside the (sticky) header cell. */
.col-filter {
    width: 100%;
    box-sizing: border-box;
    margin-top: 3px;
    padding: 1px 4px;
    font-size: 0.8rem;
    font-weight: normal;
    color: inherit;
    background-color: var(--mud-palette-background);
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: 3px;
}

.library-table th:last-child,
.library-table td:last-child {
    border-right: none;
}

.library-table th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: color-mix(in srgb, var(--mud-palette-background) 75%, grey);
    border-bottom: 2px solid var(--mud-palette-divider);
    cursor: pointer;
    user-select: none;
}

.library-table th.no-sort {
    cursor: default;
}

.library-table tr:hover td {
    background-color: var(--mud-palette-action-default-hover);
}

.library-table td {
    border-bottom: 1px solid var(--mud-palette-divider);
}

/* Narrator can list many names; cap the width and truncate with an ellipsis
   (full list shown via the cell's title tooltip). An inner inline-block is used
   because max-width on a <td> is not honored in an auto-layout table. */
.narrator-cell {
    display: inline-block;
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
}

.title-unowned {
    font-weight: bold;
}

.title-link {
    color: var(--mud-palette-primary);
    cursor: pointer;
    text-decoration: underline;
}

.depth-1 {
    padding-left: 2.5rem;
}

.book-thumb {
    width: 32px;
    height: 32px;
    object-fit: contain;
    cursor: pointer;
}

.book-preview {
    width: 300px;
    height: 300px;
    object-fit: contain;
}

.series-image-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-width: 420px;
    padding: 4px;
}

.series-book-preview {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.toolbar-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 4px 8px;
}

.related-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.related-row:hover {
    background: var(--mud-palette-action-default-hover);
}

.related-row-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.related-row-title {
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.related-row-sub {
    font-size: 0.8rem;
    color: var(--mud-palette-text-secondary);
}

.similar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.5rem;
    padding: 6px 8px;
    justify-items: center;
}

.similar-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: 100%;
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
}

.similar-tile:hover {
    background: var(--mud-palette-action-default-hover);
}

.similar-tile-img {
    width: 88px;
    height: 88px;
    object-fit: contain;
}

.similar-tile-title {
    font-weight: 600;
    font-size: 0.8rem;
    line-height: 1.2;
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.similar-tile-author {
    font-size: 0.72rem;
    color: var(--mud-palette-text-secondary);
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.similar-tooltip {
    display: flex;
    gap: 0.75rem;
    max-width: 440px;
    padding: 4px;
    text-align: left;
}

.similar-tooltip-img {
    width: 170px;
    height: 170px;
    object-fit: contain;
    flex-shrink: 0;
}

.similar-tooltip-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.similar-tooltip-title {
    font-weight: 700;
    font-size: 1rem;
}

.similar-tooltip-author {
    font-size: 0.85rem;
    opacity: 0.85;
    margin-bottom: 0.35rem;
}

.similar-tooltip-desc {
    font-size: 0.8rem;
    line-height: 1.35;
}
