/*
 * Tables, site-wide.
 *
 * A deliberate departure from the live site, which styles its 86 content
 * tables with a 1px row border and leaves them to run off the side of a phone.
 * This covers all three shapes the site actually contains:
 *
 *   1. thead + tbody            the comparison tables on pages and articles
 *   2. a colspan heading row    the "Regler & Villkor" tables on reviews
 *   3. label / value rows       quick facts, provider specs, the list table
 *
 * Shapes 2 and 3 have no <thead>, so lib/html.ts marks them
 * `.content-table--plain` as it wraps them; the two component-rendered tables
 * (`.quick-facts-table`, `#casino-list-table`) are styled here by name so the
 * whole site reads as one design.
 *
 * Colours come from the CMS design tokens rather than being hard-coded, with
 * one correction: white text on `--color-primary` (#4da8b3) is a 2.6:1
 * contrast ratio, which fails WCAG AA. The header band mixes the primary down
 * to about 5.3:1 and keeps the hue. The flat hex before each `color-mix` is
 * the fallback for browsers without it.
 */

/* ------------------------------------------------------------- container */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 0 30px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  background: #fff;
}

/* Scrollable regions must be reachable from the keyboard; `tabindex="0"` on
   the container does that, and this makes the focus visible. */
.table-scroll:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.entry-content .table-scroll > table,
.table-scroll > table {
  width: 100%;
  /* Below this the columns start wrapping mid-word; the container scrolls
     instead. Three-column tables are the reason it is not lower. */
  min-width: 460px;
  margin: 0;
  border-collapse: collapse;
  font-size: 15px;
  line-height: 1.45;
}

/* A two-column label/value table fits a phone; three or more have to scroll. */
.table-scroll > table[data-cols="1"],
.table-scroll > table[data-cols="2"] {
  min-width: 0;
}

/* ----------------------------------------------------------------- cells */

.content-table th,
.content-table td,
.quick-facts-table th,
.quick-facts-table td,
#casino-list-table th,
#casino-list-table td {
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  text-align: left;
  vertical-align: middle;
  color: var(--color-body);
}

.content-table tr:last-child th,
.content-table tr:last-child td,
.quick-facts-table tr:last-child th,
.quick-facts-table tr:last-child td,
#casino-list-table tr:last-child th,
#casino-list-table tr:last-child td {
  border-bottom: 0;
}

/* ------------------------------------------------------------ header band */

.content-table thead th,
.content-table--plain > tbody > tr:first-child > td[colspan],
.content-table--plain > tr:first-child > td[colspan] {
  background: #31757d;
  background: color-mix(in srgb, var(--color-primary) 60%, #06282d);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 0;
}

.content-table thead th + th {
  border-left: 1px solid rgba(255, 255, 255, 0.18);
}

.content-table thead th a,
.content-table--plain > tbody > tr:first-child > td[colspan] a {
  color: #fff;
  text-decoration: underline;
}

/* ------------------------------------------------------- label / value rows */

/*
 * The first column of a table with no header row is a label — "Omsättningskrav:",
 * "Grundat", "Licenser" — so it is set apart from the value beside it. The
 * component-rendered tables already use a <th> for that column; the migrated
 * ones use a plain <td>.
 */
.content-table--plain > tbody > tr > td:first-child,
.quick-facts-table th,
#casino-list-table th {
  width: 35%;
  font-weight: 600;
  color: var(--color-headings);
  background: rgba(0, 0, 0, 0.025);
}

/* …except the heading row, which is already a band. */
.content-table--plain > tbody > tr:first-child > td[colspan] {
  width: auto;
}

/* `#casino-list-table` keeps its own teal label column from the theme — the
   same correction as the header band, since it is white on the primary. */
#casino-list-table th.bg-p,
#casino-list-table th {
  background: #31757d;
  background: color-mix(in srgb, var(--color-primary) 60%, #06282d);
  color: #fff;
  font-weight: 700;
}

/* ----------------------------------------------------------------- rows */

.content-table > tbody > tr:nth-child(even),
.quick-facts-table > tbody > tr:nth-child(even) {
  background: rgba(77, 168, 179, 0.06);
}

.content-table > tbody > tr:hover,
.quick-facts-table > tbody > tr:hover {
  background: rgba(77, 168, 179, 0.12);
}

.content-table--plain > tbody > tr:first-child:hover {
  background: none;
}

/* A caption reads as a title above the table, not as a stray line of body copy. */
.content-table caption {
  padding: 10px 14px;
  font-weight: 600;
  text-align: left;
  color: var(--color-headings);
}

/* ---------------------------------------------------------------- mobile */

@media (max-width: 575px) {
  .entry-content .table-scroll > table,
  .table-scroll > table {
    font-size: 14px;
  }

  .content-table th,
  .content-table td {
    padding: 9px 11px;
  }

  /* The theme's own stacking class, which the migrated tables never carry and
     the list table does: at this width a two-column table reads better as
     stacked blocks than as a scroll. */
  #casino-list-table.table-responsive-100 th,
  #casino-list-table.table-responsive-100 td {
    width: 100%;
    display: block;
  }
}


/* ------------------------------------------------------- stacked on phones */

/*
 * A table of three to five columns becomes one block per row below 576px,
 * rather than scrolling sideways inside its container.
 *
 * Scrolling is a poor read on a phone: the headings leave the screen as soon
 * as you move right, and "50x på pengarna" on its own means nothing without
 * "Omsättningskrav" beside it. `lib/html.ts` copies each column's heading onto
 * its cells as `data-label` and marks the table `data-stack`, which is what
 * the `::before` below prints. The header row is then redundant and hidden —
 * every cell carries its own heading.
 *
 * The first cell of a row is the row's name — "Första välkomstbonusen",
 * "Rött eller svart" — so it reads as the block's title rather than as another
 * label/value pair.
 *
 * Nothing here applies above 575px: the desktop table is untouched.
 */

@media (max-width: 575px) {
  .table-scroll > table[data-stack] {
    min-width: 0;
  }

  /* Every cell carries its heading now, so the row of headings would only
     repeat itself. A banner row naming the whole table is not a heading row
     and stays. */
  .content-table[data-stack] .content-table__head {
    display: none;
  }

  .content-table[data-stack] tr {
    display: block;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    margin: 0 0 10px;
    overflow: hidden;
  }

  .content-table[data-stack] tr:last-child {
    margin-bottom: 0;
  }

  /* The container already draws a border and the blocks now draw their own. */
  .table-scroll:has(> table[data-stack]) {
    border: 0;
    border-radius: 0;
    background: none;
  }

  /* Striping and hover belong to rows in a grid, not to separate blocks. */
  .content-table[data-stack] > tbody > tr:nth-child(even),
  .content-table[data-stack] > tbody > tr:hover {
    background: none;
  }

  .content-table[data-stack] td[data-label],
  .content-table[data-stack] th[data-label] {
    display: flex;
    gap: 14px;
    align-items: baseline;
    justify-content: space-between;
    width: auto;
    text-align: right;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    background: none;
  }

  .content-table[data-stack] td[data-label]::before,
  .content-table[data-stack] th[data-label]::before {
    content: attr(data-label);
    flex: 0 0 42%;
    text-align: left;
    font-weight: 600;
    color: var(--color-headings);
  }

  /*
   * The first cell leads the block. It keeps its heading rather than becoming
   * a bare title: the first column is usually the row's name -- "Forsta
   * valkomstbonusen" -- but not always. On the homepage's casino tables it is
   * the licence, and a block headed "Curacao" with the word "Spellicens"
   * dropped says the wrong thing. Tinting it is enough to lead with.
   */
  .content-table[data-stack] tr > [data-label]:first-child {
    padding: 9px 12px;
    font-weight: 700;
    color: var(--color-headings);
    background: rgba(0, 0, 0, 0.04);
  }

  /* A banner row names the table, so it reads as a line above the blocks
     rather than as a block of its own. */
  .content-table[data-stack] tr:has(> [colspan]) {
    border: 0;
    border-radius: 0;
    margin-bottom: 6px;
  }

  .content-table[data-stack] tr > :last-child {
    border-bottom: 0;
  }

  /* The banner row that names the table keeps its band across the full width. */
  .content-table[data-stack] td:not([data-label]),
  .content-table[data-stack] th:not([data-label]) {
    display: block;
    width: auto;
    text-align: left;
  }

  .content-table[data-stack] td:not([data-label])::before,
  .content-table[data-stack] th:not([data-label])::before {
    content: none;
  }
}
