/* ==========================================================================
   Table Styles
   ========================================================================== */

.app-table tbody .table-nums {
    letter-spacing: 1px;
}

.app-table tbody tr {
    border-color: var(--app-table-border);
}

/* Jede Tabelle schliesst unten mit derselben Linie ab, mit der sie ihre
   Zeilen trennt. Bis #732 blieb die letzte Zeile ohne, weil darunter die
   Kante der Karte kam — nur steht nicht jede Tabelle in einer Karte, und dort
   hoerte sie einfach auf. */

/* Und eine Tabelle ohne Kopf faengt mit derselben Linie an: sonst beginnt sie
   mit nichts und sieht aus, als waere oben etwas abgeschnitten (#732). Gesagt
   wird es mit einer Klasse statt mit `:has(thead)`, weil die alten
   Android-WebViews der App den Selektor nicht kennen. */
.app-table--headless > tbody > tr:first-child > * {
    border-top: var(--bs-border-width) solid var(--app-table-border);
}

.app-table.table-hover tr:hover {
    cursor: pointer;
}

.app-table td,
.app-table th[scope="row"] {
    vertical-align: middle;
    white-space: nowrap;
}

/* Der Kopf dreht sich mit dem Modus: auf heller Seite der dunkle Verlauf mit
   weisser Schrift, auf dunkler der helle mit dunkler. Die Werte stehen in
   `base.css` (--app-table-head-*), damit die invertierte Flaeche dieselbe
   Wendung bekommt wie der Dark Mode (#706). */
.app-table thead tr th {
    text-transform: uppercase;
    letter-spacing: 1px;
    background: linear-gradient(136deg, var(--app-table-head-bg) 0%, var(--app-table-head-bg-lift) 100%);
    color: var(--app-table-head-ink);
    border-radius: 255px 0 217px / 25px 225px 0 249px;
    border-bottom: none;
    line-height: 20px;
}

.card-body .app-table thead tr th {
    border-radius: 0;
}

/* Sort Headers */
th.sort-header {
    cursor: pointer;
    white-space: nowrap;
}

/* Only the column the table is sorted by carries an arrow — one in front of
   every sortable header made the columns so wide on a phone that the names
   wrapped (#665). */
th.sort-header.asc::before,
th.sort-header.desc::before {
    content: "▶";
    margin-right: 4px;
    display: inline-block;
}

th.sort-header.asc::before {
    transform: rotate(-90deg);
}

th.sort-header.desc::before {
    transform: rotate(90deg);
}

/* Table Divider Text */
td small.table-divider-text {
    display: block;
    margin: 1rem 0 -0.75rem;
    opacity: 0.75;
}

/* Responsive Tables */
@media screen and (max-width: 768px) {
    .app-table.wide-on-mobile {
        margin: 0 -2rem;
        width: calc(100% + 4rem);
    }
}

/* ==========================================================================
   Compact tables on a phone

   A wide table either scrolls sideways or drops columns, and the player picks
   with the switch above it — compact by default. Compact shows only the
   columns the table lists in `compactCols` and the short form of a value
   (`compactText()` in table.js); expanded is the full table, scrolling. Both
   forms are in the markup, so switching is a class and never a re-render.
   ========================================================================== */

/* The short forms only ever show in compact mode, which only exists below
   768px — on a desktop every cell keeps its full value. */
.table-compact-text {
    display: none;
}

@media screen and (max-width: 768px) {
    .table-compact-switch {
        margin-bottom: 0.75rem;
    }

    .table-container.is-compact .table-full-text {
        display: none;
    }

    .table-container.is-compact .table-compact-text {
        display: inline;
    }

    /* `table-compact-hide-N` names a hidden column by its place, so the rule
       reaches rows that render their own cells (`rowElement`) as well. Up to
       sixteen columns; the widest table in the game has ten. */
    .table-container.is-compact table.table-compact-hide-1 > * > tr > :nth-child(1),
    .table-container.is-compact table.table-compact-hide-2 > * > tr > :nth-child(2),
    .table-container.is-compact table.table-compact-hide-3 > * > tr > :nth-child(3),
    .table-container.is-compact table.table-compact-hide-4 > * > tr > :nth-child(4),
    .table-container.is-compact table.table-compact-hide-5 > * > tr > :nth-child(5),
    .table-container.is-compact table.table-compact-hide-6 > * > tr > :nth-child(6),
    .table-container.is-compact table.table-compact-hide-7 > * > tr > :nth-child(7),
    .table-container.is-compact table.table-compact-hide-8 > * > tr > :nth-child(8),
    .table-container.is-compact table.table-compact-hide-9 > * > tr > :nth-child(9),
    .table-container.is-compact table.table-compact-hide-10 > * > tr > :nth-child(10),
    .table-container.is-compact table.table-compact-hide-11 > * > tr > :nth-child(11),
    .table-container.is-compact table.table-compact-hide-12 > * > tr > :nth-child(12),
    .table-container.is-compact table.table-compact-hide-13 > * > tr > :nth-child(13),
    .table-container.is-compact table.table-compact-hide-14 > * > tr > :nth-child(14),
    .table-container.is-compact table.table-compact-hide-15 > * > tr > :nth-child(15),
    .table-container.is-compact table.table-compact-hide-16 > * > tr > :nth-child(16) {
        display: none;
    }

    /* A long name wraps rather than pushing the row past the screen; every
       cell is `nowrap` otherwise. Numbers stay whole — "12.3M €" broken
       after the M reads as two values. */
    .table-container.is-compact .app-table td,
    .table-container.is-compact .app-table th[scope="row"] {
        white-space: normal;
    }

    .table-container.is-compact .table-nums {
        white-space: nowrap;
    }

    /* Headers keep their letters together: the 1px tracking made "MORALE"
       wider than the number beneath it. */
    .table-container.is-compact .app-table thead th {
        letter-spacing: 0;
    }

    /* Half the side padding, so the columns that are left fit 390px. */
    .table-container.is-compact .app-table > * > tr > * {
        padding-left: 0.35rem;
        padding-right: 0.35rem;
    }

    /* …but 4px more on the outer edges, so the first and last values do not
       sit on the border of the card. `table-compact-first-N` / `-last-N` name
       the outermost shown column, since hidden ones may sit at either end. */
    .table-container.is-compact table.table-compact-first-1 > * > tr > :nth-child(1),
    .table-container.is-compact table.table-compact-first-2 > * > tr > :nth-child(2),
    .table-container.is-compact table.table-compact-first-3 > * > tr > :nth-child(3),
    .table-container.is-compact table.table-compact-first-4 > * > tr > :nth-child(4),
    .table-container.is-compact table.table-compact-first-5 > * > tr > :nth-child(5),
    .table-container.is-compact table.table-compact-first-6 > * > tr > :nth-child(6),
    .table-container.is-compact table.table-compact-first-7 > * > tr > :nth-child(7),
    .table-container.is-compact table.table-compact-first-8 > * > tr > :nth-child(8),
    .table-container.is-compact table.table-compact-first-9 > * > tr > :nth-child(9),
    .table-container.is-compact table.table-compact-first-10 > * > tr > :nth-child(10),
    .table-container.is-compact table.table-compact-first-11 > * > tr > :nth-child(11),
    .table-container.is-compact table.table-compact-first-12 > * > tr > :nth-child(12),
    .table-container.is-compact table.table-compact-first-13 > * > tr > :nth-child(13),
    .table-container.is-compact table.table-compact-first-14 > * > tr > :nth-child(14),
    .table-container.is-compact table.table-compact-first-15 > * > tr > :nth-child(15),
    .table-container.is-compact table.table-compact-first-16 > * > tr > :nth-child(16) {
        padding-left: calc(0.35rem + 4px);
    }

    .table-container.is-compact table.table-compact-last-1 > * > tr > :nth-child(1),
    .table-container.is-compact table.table-compact-last-2 > * > tr > :nth-child(2),
    .table-container.is-compact table.table-compact-last-3 > * > tr > :nth-child(3),
    .table-container.is-compact table.table-compact-last-4 > * > tr > :nth-child(4),
    .table-container.is-compact table.table-compact-last-5 > * > tr > :nth-child(5),
    .table-container.is-compact table.table-compact-last-6 > * > tr > :nth-child(6),
    .table-container.is-compact table.table-compact-last-7 > * > tr > :nth-child(7),
    .table-container.is-compact table.table-compact-last-8 > * > tr > :nth-child(8),
    .table-container.is-compact table.table-compact-last-9 > * > tr > :nth-child(9),
    .table-container.is-compact table.table-compact-last-10 > * > tr > :nth-child(10),
    .table-container.is-compact table.table-compact-last-11 > * > tr > :nth-child(11),
    .table-container.is-compact table.table-compact-last-12 > * > tr > :nth-child(12),
    .table-container.is-compact table.table-compact-last-13 > * > tr > :nth-child(13),
    .table-container.is-compact table.table-compact-last-14 > * > tr > :nth-child(14),
    .table-container.is-compact table.table-compact-last-15 > * > tr > :nth-child(15),
    .table-container.is-compact table.table-compact-last-16 > * > tr > :nth-child(16) {
        padding-right: calc(0.35rem + 4px);
    }
}
