/**
 * ============================================================================
 * ROOTS ARCHIVES — TABLES (tables.css)
 * ============================================================================
 *
 * artist-table, credits-table, general .table overrides,
 * fixed-layout columns, responsive mobile transforms.
 * ============================================================================
 */


/* ── Base table ────────────────────────────────────── */

/* Sortable column headers */
th.sortable {
    cursor: pointer;
}

th.th-cover {
    width: var(--table-col-cover);
    text-align: center;
}

.table,
.credits-table,
.artist-table {
    font-size: var(--font-size-base);
    color: var(--color-table-text);
}

.table td,
.table th,
.credits-table td,
.credits-table th,
.artist-table td,
.artist-table th {
    padding: var(--spacing-cell);
    vertical-align: middle;
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
}

/* Everything inside tables inherits the base size */
.table *,
.artist-table *,
.credits-table * {
    font-size: var(--font-size-base);
}

/* Table headers */
.table thead th,
.credits-table thead th,
.artist-table thead th {
    font-size: var(--font-size-base);
    font-weight: 600;
    padding: var(--spacing-cell);
    border-color: var(--color-table-border);
}

/* Force buttons in table headers to have no extra spacing */
.artist-table thead th button,
.credits-table thead th button,
.table thead th button {
    width: 100%;
    padding: 0;
    margin: 0;
    display: block;
    text-align: inherit;
}

/* Table body text */
.table tbody td,
.credits-table tbody td,
.artist-table tbody td {
    font-size: var(--font-size-base);
    padding: var(--spacing-cell);
    border-color: var(--color-table-border);
}

/* Links inside tables */
.table tbody td a,
.credits-table tbody td a,
.artist-table tbody td a,
.table tbody td span,
.credits-table tbody td span,
.artist-table tbody td span {
    font-size: var(--font-size-base);
    color: var(--color-link);
}

.table tbody td a:hover,
.credits-table tbody td a:hover,
.artist-table tbody td a:hover {
    color: var(--color-link-hover);
}

/* Table header links — keep text-color */
.table thead th a,
.table thead th button,
.credits-table thead th a,
.credits-table thead th button,
.artist-table thead th a,
.artist-table thead th button {
    color: var(--color-text);
}

.table thead .btn-link {
    color: var(--color-text);
}

.table thead .btn-link:hover {
    color: var(--color-primary);
}

/* Small text in tables */
.table small,
.artist-table small,
small {
    font-size: var(--font-size-base);
}

.table tbody td small,
.credits-table tbody td small,
.artist-table tbody td small,
.table thead th small,
.credits-table thead th small,
.artist-table thead th small {
    font-size: var(--font-size-base);
}

/* Table responsive wrapper */
.table-responsive {
    overflow-x: hidden;
}

/* Table cells — compact padding */
.table td,
.table th,
.artist-table td,
.artist-table th {
    padding: var(--spacing-cell);
    vertical-align: middle;
}


/* ── Credits table ─────────────────────────────────── */

.credits-table {
    table-layout: fixed;
}

.credits-table th,
.credits-table td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Credits column widths */
.credits-table thead th:nth-child(1),
.credits-table tbody td:nth-child(1) { width: var(--table-col-cover); }

.credits-table thead th:nth-child(2),
.credits-table tbody td:nth-child(2) { width: var(--table-col-artist); }

.credits-table thead th:nth-child(3),
.credits-table tbody td:nth-child(3) { width: var(--table-col-album); }

.credits-table thead th:nth-child(4),
.credits-table tbody td:nth-child(4) { width: var(--table-col-release); }

.credits-table thead th:nth-child(5),
.credits-table tbody td:nth-child(5) {
    width: var(--table-col-type);
    text-align: center;
}

.credits-table thead th:nth-child(6),
.credits-table tbody td:nth-child(6) { width: var(--table-col-label); }

.credits-table thead th:nth-child(7),
.credits-table tbody td:nth-child(7) {
    width: var(--table-col-rec);
    text-align: center;
}

.credits-table thead th:nth-child(8),
.credits-table tbody td:nth-child(8) {
    width: var(--table-col-role);
    text-align: center;
}

.credits-table thead th:nth-child(9),
.credits-table tbody td:nth-child(9) {
    width: var(--table-col-rel);
    text-align: center;
}


/* ── Artist table ──────────────────────────────────── */

.artist-table {
    table-layout: fixed;
}

.artist-table th,
.artist-table td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.artist-table a {
    color: var(--color-link);
    font-weight: 500;
}

.artist-table a:hover {
    color: var(--color-link-hover);
    text-decoration: underline;
}

/* Artist table column widths */
.artist-table thead th:nth-child(1),
.artist-table tbody td:nth-child(1) { width: var(--table-col-cover); }

.artist-table thead th:nth-child(2),
.artist-table tbody td:nth-child(2) { width: var(--table-col-artist); }

.artist-table thead th:nth-child(3),
.artist-table tbody td:nth-child(3) { width: var(--table-col-album); }

.artist-table thead th:nth-child(4),
.artist-table tbody td:nth-child(4) { width: var(--table-col-release); }

.artist-table thead th:nth-child(5),
.artist-table tbody td:nth-child(5) {
    width: var(--table-col-type);
    text-align: center;
}

.artist-table thead th:nth-child(6),
.artist-table tbody td:nth-child(6) { width: var(--table-col-label); }

.artist-table thead th:nth-child(7),
.artist-table tbody td:nth-child(7) {
    width: var(--table-col-rec);
    text-align: center;
}

.artist-table thead th:nth-child(8),
.artist-table tbody td:nth-child(8) {
    width: var(--table-col-rel);
    text-align: center;
}

/* Artist table headers — force single line */
.artist-table th {
    white-space: nowrap;
    overflow: visible;
    text-overflow: unset;
}

/* Truncate long text (all columns except cover) */
.artist-table td:not(:first-child) {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Center badges in Type column */
.artist-table td:nth-child(5) {
    text-align: center;
    vertical-align: middle;
}

/* Remove bold from album titles */
.artist-table tbody td:nth-child(3) strong,
.artist-table tbody td:nth-child(3) a strong {
    font-weight: 500;
}

/* Cover thumbnails — 50×50 squares */
.cover-thumb {
    width: 50px;
    height: 50px;
    object-fit: cover;
}

.cover-thumb-placeholder {
    width: 50px;
    height: 50px;
}


/* ── Credits uniform / tracklist tables ────────────── */

/* Accordion release details */
.accordion .card-body dl,
.accordion .card-body dt,
.accordion .card-body dd {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-link);
    margin-bottom: 0.2rem;
    line-height: 1.1;
}

.accordion .card-body dt {
    padding-top: 2px;
    padding-bottom: 2px;
}

.accordion .card-body dd {
    padding-top: 2px;
    padding-bottom: 2px;
}

.accordion .release-summary small,
.accordion .release-summary span {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-link);
    line-height: 1.1;
}

/* Credits uniform ordered list (tracklist) */
ol.credits-uniform-table {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-link);
    margin-bottom: 0;
    padding-left: 1.2em;
}

ol.credits-uniform-table li {
    padding-top: 2px;
    padding-bottom: 2px;
    line-height: 1.1;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-link);
}

/* Credits uniform table content */
.credits-uniform-table td,
.credits-uniform-table a,
.credits-uniform-table strong,
.credits-uniform-table small {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-link);
}

/* Credits tables — compact spacing */
table[style*="margin-left:1.8rem"] td {
    padding-top: 2px;
    padding-bottom: 2px;
    line-height: 1.1;
}

/* Remove bold from studios credits second column */
.studios-credits-table td:nth-child(2) small {
    font-weight: 400;
    color: #444;
}

.credits-uniform-table td:nth-child(2) a,
.credits-uniform-table td:nth-child(2),
.studios-credits-table td:nth-child(2) a,
.studios-credits-table td:nth-child(2) {
    font-weight: 400;
}

/* Force single-line for credit roles */
.credits-table td[style*="white-space:nowrap"],
.credits-table td .credit-role-nowrap {
    white-space: nowrap;
}

.table-releases td strong {
    font-size: 0.95em;
    font-weight: 600;
}

.ultra-compact-table td strong {
    font-size: 0.95em;
    font-weight: 600;
}

.credits-table td strong {
    color: var(--color-link);
    font-weight: 600;
}

.credits-table td strong.role-text {
    color: var(--color-link);
    font-weight: bold;
}

/* Credits section borders */
.credits-section .border-bottom {
    border-color: var(--color-secondary);
    color: var(--color-primary);
}

/* Legacy deprecated tables */
.discog-table {
    font-size: 0.95rem;
}

.discog-table a {
    color: var(--color-primary);
    font-weight: 500;
}

.discog-table a:hover {
    color: var(--color-dark);
    text-decoration: underline;
}

.credits-table .credit-cell {
    padding: 0.5rem 0.3rem 0.5rem 50px;
    vertical-align: middle;
    line-height: 1.5;
}

.credits-table .role-label {
    color: var(--color-muted);
    font-weight: 500;
    font-size: 0.9rem;
}

.credits-table a {
    color: var(--color-link);
    font-weight: 500;
}

.credits-table a:hover {
    color: var(--color-link-hover);
    text-decoration: underline;
}


/* ── Forum posts table ─────────────────────────────── */

#search-advanced-posts table {
    table-layout: fixed;
    width: 100%;
}

#search-advanced-posts thead th:nth-child(1),
#search-advanced-posts tbody td:nth-child(1) { width: 30%; }

#search-advanced-posts thead th:nth-child(2),
#search-advanced-posts tbody td:nth-child(2) { width: 40%; }

#search-advanced-posts thead th:nth-child(3),
#search-advanced-posts tbody td:nth-child(3) { width: 15%; }

#search-advanced-posts thead th:nth-child(4),
#search-advanced-posts tbody td:nth-child(4) { width: 15%; }

#search-advanced-posts tbody td:nth-child(2) {
    max-height: 2.4em;
    overflow: hidden;
}

#search-advanced-posts tbody td:nth-child(2) small {
    display: block;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
}


/* ── Responsive tables ─────────────────────────────── */

@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto;
    }

    .credits-table {
        font-size: 0.85rem;
    }

    .credits-table thead th {
        font-size: 0.8rem;
        padding: 0.5rem 0.3rem;
    }

    .credits-table tbody td {
        padding: 0.5rem 0.3rem;
    }

    .credits-table tbody td:nth-child(2) {
        padding-left: 0.5rem;
    }

    /* Hide release column on mobile */
    .credits-table thead th:nth-child(4),
    .credits-table tbody td:nth-child(4) {
        display: none;
    }

    /* Tracklist / credits on mobile */
    .card-body,
    .card-body *,
    .release-content,
    .release-content *,
    ol.credits-uniform-table,
    ol.credits-uniform-table li,
    .credits-uniform-table td,
    .credits-uniform-table a,
    .credits-uniform-table strong,
    .credits-uniform-table small {
        font-size: 0.8rem;
    }

    /* Hide release artwork on mobile */
    .release-artwork-col {
        display: none;
    }


    /* ── Credits/Appearances → 2-col card grid on mobile ── */

    body [id^="creditsTable-"] thead,
    body #appearsOnTable thead,
    body table[id^="creditsTable-"] thead,
    body table#appearsOnTable thead {
        display: none;
    }

    [id^="creditsTable-"] tbody,
    #appearsOnTable tbody {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.5rem;
        padding: 0.5rem;
        width: 100%;
    }

    [id^="creditsTable-"] tbody tr,
    #appearsOnTable tbody tr {
        display: flex;
        flex-direction: column;
        background: var(--color-card-bg);
        border: 1px solid var(--color-table-border);
        border-radius: var(--radius-card);
        padding: 0;
        margin: 0;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        overflow: hidden;
    }

    [id^="creditsTable-"] tbody tr[id$="-expand-btn"],
    #appearsOnTable tbody tr[id$="-expand-btn"] {
        display: none;
    }

    [id^="creditsTable-"] tbody td,
    #appearsOnTable tbody td {
        display: block;
        width: 100%;
        padding: 0;
        border: none;
        text-align: left;
    }

    /* Cover image — full width at top */
    [id^="creditsTable-"] tbody td:nth-child(1),
    #appearsOnTable tbody td:nth-child(1) {
        text-align: center;
        margin-bottom: 0;
        padding: 0;
        background: var(--color-table-header-bg);
        position: relative;
        width: 100%;
        padding-top: 100%; /* 1:1 aspect ratio */
    }

    [id^="creditsTable-"] tbody td:nth-child(1) a,
    #appearsOnTable tbody td:nth-child(1) a {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        display: block;
    }

    [id^="creditsTable-"] tbody td:nth-child(1) img,
    #appearsOnTable tbody td:nth-child(1) img,
    [id^="creditsTable-"] tbody td:nth-child(1) div,
    #appearsOnTable tbody td:nth-child(1) div {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100%;
        object-fit: cover;
        border-radius: 0;
    }

    /* Text cells padding */
    [id^="creditsTable-"] tbody td:nth-child(2),
    [id^="creditsTable-"] tbody td:nth-child(3),
    [id^="creditsTable-"] tbody td:nth-child(5),
    [id^="creditsTable-"] tbody td:nth-child(6),
    [id^="creditsTable-"] tbody td:nth-child(7),
    [id^="creditsTable-"] tbody td:nth-child(8),
    #appearsOnTable tbody td:nth-child(2),
    #appearsOnTable tbody td:nth-child(3),
    #appearsOnTable tbody td:nth-child(5),
    #appearsOnTable tbody td:nth-child(6),
    #appearsOnTable tbody td:nth-child(7),
    #appearsOnTable tbody td:nth-child(8) {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Album title */
    [id^="creditsTable-"] tbody td:nth-child(3),
    #appearsOnTable tbody td:nth-child(3) {
        font-weight: 600;
        font-size: 0.75rem;
        line-height: 1.2;
        padding-top: 0.4rem;
        padding-bottom: 0.3rem;
        margin-bottom: 0.3rem;
    }

    /* Artist name */
    [id^="creditsTable-"] tbody td:nth-child(2),
    #appearsOnTable tbody td:nth-child(2) {
        font-size: 0.75rem;
        color: #666;
        padding-top: 0;
        padding-bottom: 0.3rem;
    }

    /* Release ref — hide on mobile */
    [id^="creditsTable-"] tbody td:nth-child(4),
    #appearsOnTable tbody td:nth-child(4) {
        display: none;
    }

    /* Type badge — inline */
    [id^="creditsTable-"] tbody td:nth-child(5),
    #appearsOnTable tbody td:nth-child(5) {
        display: inline-block;
        width: auto;
        margin-right: 0.3rem;
    }

    /* Label */
    [id^="creditsTable-"] tbody td:nth-child(6),
    #appearsOnTable tbody td:nth-child(6) {
        font-size: 0.75rem;
        color: #666;
        margin-top: 0.2rem;
    }

    /* Rec & Rel dates — inline */
    [id^="creditsTable-"] tbody td:nth-child(7),
    [id^="creditsTable-"] tbody td:nth-child(8),
    #appearsOnTable tbody td:nth-child(7),
    #appearsOnTable tbody td:nth-child(8) {
        display: inline-block;
        width: auto;
        font-size: 0.7rem;
        color: var(--color-muted);
        margin-right: 0.5rem;
    }

    /* Last cell bottom padding */
    [id^="creditsTable-"] tbody td:nth-child(8),
    #appearsOnTable tbody td:nth-child(8) {
        padding-bottom: 0.5rem;
    }

    /* Role section headers */
    .mb-4 h6 {
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
    }

    /* Role type headers */
    .mb-5 > h5 {
        font-size: 0.9rem;
        padding-bottom: 0.5rem;
        margin-bottom: 0.75rem;
    }
}

/* Vertical spacing uniformity on mobile */
@media (max-width: 768px) {
    .row.g-4 .col-6,
    .row.g-4 .col-6.mb-2 {
        margin-bottom: 0;
    }
}

/* Credits role headers margin (desktop) */
@media (min-width: 768px) {
    #credits-section .d-flex > h6.mb-0 {
        margin-left: 26px;
    }

    #credits-section .card-body .mb-4 .d-flex.align-items-center.justify-content-between.text-muted.mb-2 > h6.mb-0 {
        margin-left: 2.7rem;
    }
}
