/*
* Styling for core/table-block
*
* Tre Block Style Variations (registreras i inc/block-setup.php):
*   .is-style-simple      – Enkel: bara horisontella linjer, etikett vänster / värde höger
*   .is-style-striped     – Randig: färgad rubrikrad + zebraränder
*   .is-style-comparison  – Jämförelse: 3 kolumner, mittenkolumnen lyfts fram
*
* All färg/storlek styrs av --sm-table-* nedan. För att återanvända på en
* annan sajt räcker det att ändra tokens i första blocket (eller skriva över
* dem på .wp-block-table i den sajtens CSS).
*/

/* ==========================================================================
   TOKENS
   ========================================================================== */

.wp-block-table {
  /* Färger */
  --sm-table-text: var(--wp--preset--color--gray-700, #383838);
  --sm-table-label: var(--wp--preset--color--brand-primary-900, #012a5d);
  --sm-table-muted: var(--wp--preset--color--gray-500, #757575);
  --sm-table-border: var(--wp--preset--color--gray-300, #d9d9d9);
  --sm-table-stripe: var(--wp--preset--color--gray-100, #f9f9f9);
  --sm-table-hover: var(--wp--preset--color--brand-primary-100, #e6f2fc);

  --sm-table-head-bg: var(--wp--preset--color--brand-primary-900, #012a5d);
  --sm-table-head-text: var(--wp--preset--color--white, #fff);

  --sm-table-highlight-bg: var(--wp--preset--color--brand-primary-500, #0364b6);
  --sm-table-highlight-text: var(--wp--preset--color--white, #fff);
  --sm-table-highlight-border: rgb(255 255 255 / 0.25);

  /* Typografi */
  --sm-table-font-size: var(--wp--preset--font-size--small, 1rem);
  --sm-table-head-font-size: var(--wp--preset--font-size--extra-small, 0.875rem);
  --sm-table-label-weight: 600;
  --sm-table-head-weight: 600;

  /* Mått */
  --sm-table-cell-py: var(--wp--preset--spacing--40, 1rem);
  --sm-table-cell-px: var(--wp--preset--spacing--45, 1.5rem);
  --sm-table-radius: var(--wp--preset--border-radius--lg, 1.25rem);
  --sm-table-pop: 10px; /* hur långt mittenkolumnen sticker ut i Jämförelse */
  --sm-table-min-width: 560px; /* under denna bredd scrollar tabellen horisontellt */
  --sm-table-fade: 24px; /* fade-kant som visar att man kan scrolla */
}

/* ==========================================================================
   GEMENSAMT — Randig + Jämförelse
   Horisontell scroll på smala skärmar i stället för hoptryckta kolumner
   ========================================================================== */

.wp-block-table:is(.is-style-striped, .is-style-comparison) {
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--sm-table-border) transparent;
}

.wp-block-table:is(.is-style-striped, .is-style-comparison) table {
  width: 100%;
  min-width: var(--sm-table-min-width);
  border: 0;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  color: var(--sm-table-text);
  font-size: var(--sm-table-font-size);
  line-height: 1.5;
}

/* Nollställ cores standardkanter */
.wp-block-table:is(.is-style-striped, .is-style-comparison) :is(thead, tbody, tfoot, th, td) {
  border: 0;
}

.wp-block-table:is(.is-style-striped, .is-style-comparison) :is(th, td) {
  padding: var(--sm-table-cell-py) var(--sm-table-cell-px);
  border-bottom: 1px solid var(--sm-table-border);
  vertical-align: middle;
}

.wp-block-table:is(.is-style-striped, .is-style-comparison) thead th {
  background: var(--sm-table-head-bg);
  color: var(--sm-table-head-text);
  font-size: var(--sm-table-head-font-size);
  font-weight: var(--sm-table-head-weight);
  border-bottom: 0;
}

/* ==========================================================================
   1. ENKEL — .is-style-simple
   ========================================================================== */

.wp-block-table.is-style-simple table {
  width: 100%;
  border: 0;
  border-collapse: collapse;
  border-top: 1px solid var(--sm-table-border);
  font-size: var(--sm-table-font-size);
}

.wp-block-table.is-style-simple :is(thead, tbody, tfoot, th, td) {
  border: 0;
}

.wp-block-table.is-style-simple tr {
  border-bottom: 1px solid var(--sm-table-border);
}

.wp-block-table.is-style-simple :is(th, td) {
  padding: var(--sm-table-cell-py) 0;
  vertical-align: middle;
  color: var(--sm-table-text);
}

.wp-block-table.is-style-simple :is(th, td):first-child {
  color: var(--sm-table-label);
  font-weight: var(--sm-table-label-weight);
  text-align: left;
}

.wp-block-table.is-style-simple :is(th, td):last-child:not(:first-child) {
  text-align: right;
  padding-left: 1rem;
}

.wp-block-table.is-style-simple :is(th, td):not(:first-child):not(:last-child) {
  padding-inline: 1rem;
}

/* ==========================================================================
   2. RANDIG — .is-style-striped
   Prislistor, specar, generellt innehåll med rubrikrad
   ========================================================================== */

.wp-block-table.is-style-striped {
  border-radius: var(--sm-table-radius);
}

.wp-block-table.is-style-striped thead th {
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.wp-block-table.is-style-striped tbody tr:nth-child(even) {
  background: var(--sm-table-stripe);
}

.wp-block-table.is-style-striped tbody tr {
  transition: background-color 0.15s ease;
}

.wp-block-table.is-style-striped tbody tr:hover {
  background: var(--sm-table-hover);
}

.wp-block-table.is-style-striped tbody tr:last-child td {
  border-bottom: 0;
}

/* ==========================================================================
   3. JÄMFÖRELSE — .is-style-comparison
   3 kolumner: Område | [Vi] | [Alternativ]
   Mittenkolumnen sticker ut ovanför/nedanför tabellen via pseudo-element
   (ingen transform = inget glapp och ingen extra scrollyta).
   ========================================================================== */

.wp-block-table.is-style-comparison {
  padding-block: var(--sm-table-pop); /* plats åt mittenkolumnens utstick */
}

.wp-block-table.is-style-comparison :is(th, td) {
  text-align: center;
}

/* Första kolumnen: etiketter */
.wp-block-table.is-style-comparison :is(th, td):first-child {
  text-align: left;
}

.wp-block-table.is-style-comparison tbody td:first-child {
  color: var(--sm-table-label);
  font-weight: var(--sm-table-label-weight);
}

.wp-block-table.is-style-comparison thead th:first-child {
  border-top-left-radius: var(--sm-table-radius);
}

.wp-block-table.is-style-comparison thead th:last-child {
  border-top-right-radius: var(--sm-table-radius);
}

.wp-block-table.is-style-comparison tbody tr:nth-child(even) td:is(:first-child, :nth-child(3)) {
  background: var(--sm-table-stripe);
}

/* Tredje kolumnen: dämpad, för kontrast mot mittenkolumnen */
.wp-block-table.is-style-comparison tbody td:nth-child(3) {
  color: var(--sm-table-muted);
}

/* Tomma celler visas som ett diskret tankstreck */
.wp-block-table.is-style-comparison td:empty::after {
  content: "—";
  opacity: 0.4;
}

/* --- Mittenkolumnen: huvudvalet --- */

.wp-block-table.is-style-comparison :is(th, td):nth-child(2) {
  position: relative;
  background: var(--sm-table-highlight-bg);
  color: var(--sm-table-highlight-text);
  font-weight: var(--sm-table-label-weight);
  border-bottom-color: var(--sm-table-highlight-border);
}

.wp-block-table.is-style-comparison tbody tr:last-child td:nth-child(2) {
  border-bottom-color: transparent;
}

.wp-block-table.is-style-comparison thead th:nth-child(2)::before,
.wp-block-table.is-style-comparison tbody tr:last-child td:nth-child(2)::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  height: var(--sm-table-pop);
  background: var(--sm-table-highlight-bg);
}

.wp-block-table.is-style-comparison thead th:nth-child(2)::before {
  bottom: 100%;
  border-radius: var(--sm-table-radius) var(--sm-table-radius) 0 0;
}

.wp-block-table.is-style-comparison tbody tr:last-child td:nth-child(2)::before {
  top: 100%;
  border-radius: 0 0 var(--sm-table-radius) var(--sm-table-radius);
}

/* ==========================================================================
   MOBIL
   ========================================================================== */

@media (max-width: 782px) {
  .wp-block-table {
    --sm-table-cell-py: 0.75rem;
    --sm-table-cell-px: 0.9rem;
    --sm-table-font-size: var(--wp--preset--font-size--extra-small, 0.875rem);
    --sm-table-min-width: 480px;
  }

  /* Fade i högerkanten antyder att tabellen går att scrolla */
  .wp-block-table:is(.is-style-striped, .is-style-comparison) {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - var(--sm-table-fade)), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - var(--sm-table-fade)), transparent);
  }
}
