/*
 * Mobile-first responsive tables.
 *
 * - Shared desktop/tablet baseline for Gutenberg .wp-block-table and our
 *   server-side .bp-table-scroll wrapper.
 * - On mobile, server-annotated 2-column tables (data-bp-columns="2")
 *   stack as cards with the header text rendered as a ::before label.
 * - Wider tables stay horizontally scrollable.
 *
 * All colors come from the Cores do Tema Customizer tokens, defined in
 * inc/frontend/theme-color-tokens.php as :root CSS variables.
 */

figure.wp-block-table,
.bp-table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 32px 0;
  border: 1px solid var(--bp-color-border);
  border-radius: 12px;
  background: var(--bp-color-bg);
  scrollbar-width: thin;
  scrollbar-color: var(--bp-color-text-light) var(--bp-color-bg-alt);
}

figure.wp-block-table table,
.bp-table-scroll > table {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: auto;
  background: var(--bp-color-bg);
}

figure.wp-block-table thead th,
.bp-table-scroll thead th,
figure.wp-block-table tbody th,
.bp-table-scroll tbody th {
  background: var(--bp-color-bg-alt);
  color: var(--bp-color-text);
  font-weight: 700;
}

figure.wp-block-table th,
figure.wp-block-table td,
.bp-table-scroll th,
.bp-table-scroll td {
  padding: 14px 16px;
  border-right: 1px solid var(--bp-color-border);
  border-bottom: 1px solid var(--bp-color-border);
  text-align: left;
  vertical-align: top;
  color: var(--bp-color-text);
  line-height: 1.6;
  background: transparent;
}

figure.wp-block-table tr > *:last-child,
.bp-table-scroll tr > *:last-child {
  border-right: 0;
}

figure.wp-block-table tbody tr:last-child > *,
.bp-table-scroll tbody tr:last-child > * {
  border-bottom: 0;
}

.bp-table-scroll::-webkit-scrollbar,
figure.wp-block-table::-webkit-scrollbar {
  height: 8px;
}

.bp-table-scroll::-webkit-scrollbar-track,
figure.wp-block-table::-webkit-scrollbar-track {
  background: var(--bp-color-bg-alt);
  border-radius: 999px;
}

.bp-table-scroll::-webkit-scrollbar-thumb,
figure.wp-block-table::-webkit-scrollbar-thumb {
  background: var(--bp-color-text-light);
  border-radius: 999px;
}

@media (max-width: 700px) {
  .bp-table-scroll table[data-bp-columns="2"] {
    width: 100%;
    min-width: 0;
    display: block;
    background: transparent;
  }

  /*
   * Keep thead in the accessibility tree so screen readers still announce
   * column headers. `display: none` would drop the header associations,
   * and ::before content is not surfaced as a table header by AT.
   */
  .bp-table-scroll table[data-bp-columns="2"] thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  .bp-table-scroll table[data-bp-columns="2"] tbody,
  .bp-table-scroll table[data-bp-columns="2"] tr,
  .bp-table-scroll table[data-bp-columns="2"] td,
  .bp-table-scroll table[data-bp-columns="2"] th {
    display: block;
    width: 100%;
  }

  .bp-table-scroll table[data-bp-columns="2"] tr {
    margin: 0 0 16px;
    border: 1px solid var(--bp-color-border);
    border-radius: 12px;
    background: var(--bp-color-bg);
    overflow: hidden;
  }

  .bp-table-scroll table[data-bp-columns="2"] td,
  .bp-table-scroll table[data-bp-columns="2"] th {
    border-right: 0;
    border-bottom: 1px solid var(--bp-color-border);
    padding: 12px 16px 14px;
  }

  .bp-table-scroll table[data-bp-columns="2"] tr > *:last-child {
    border-bottom: 0;
  }

  .bp-table-scroll table[data-bp-columns="2"] td::before,
  .bp-table-scroll table[data-bp-columns="2"] th::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--bp-color-primary);
  }

  .bp-table-scroll table:not([data-bp-columns="2"]) th,
  .bp-table-scroll table:not([data-bp-columns="2"]) td,
  figure.wp-block-table th,
  figure.wp-block-table td {
    padding: 12px 14px;
    font-size: 0.96rem;
    line-height: 1.55;
    white-space: normal;
  }
}
