/* =========================================================
   table.css – Sorterbare tabeller + søk (universell)
   Dato: 2025-10-17 (ryddet/strukturert)
   ---------------------------------------------------------
   Innhold:
   1) Grunnleggende tabell
   2) Talljustering
   3) Header-variant (knapp i TH) + ikoner
   4) Row-variant (egen knapperad)
   5) Live-region (skjermleser)
   6) Verktøylinje (CSV + søk) – konsistent høyde/fokus
   7) Småjusteringer (caption, th[scope="row"])
   ========================================================= */


/* =========================
   1) Grunnleggende tabell
   ========================= */
table {
  border-collapse: collapse;
  width: 100%;
}

caption,
th,
td {
  text-align: left;
}

th,
td {
  padding: .55rem .75rem;
  vertical-align: top;
}

tbody tr:nth-child(even) td,
tbody tr:nth-child(even) th {
  background: #fafafa;
}

tbody tr:hover td,
tbody tr:hover th {
  background: #f2f7ff;
}

div:has(> table) { /* Påvirker div som er forelder for table */
	overflow-x: auto; /* Legger til horisontal scrollbar hvis table er for bred for main */
}


/* =========================
   2) Talljustering
   ========================= */
.num,
.num * {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}


/* =========================
   3) Header-variant (TH-knapp)
   ========================= */
.mt-sort-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font: inherit;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
}

.mt-sort-btn:focus-visible {
  outline: 2px solid var(--mt-sort-color, #0060df);
  outline-offset: 2px;
}

/* Ikoner for sorteringsretning */
.mt-sort-icon {
  display: inline-block;
  width: 1em;
  text-align: center;
}

[aria-sort="ascending"] .mt-sort-icon::before {
  content: "▲";
}

[aria-sort="descending"] .mt-sort-icon::before {
  content: "▼";
}

[aria-sort="none"] .mt-sort-icon::before {
  /* content: "–"; */
}


/* =========================
   4) Row-variant (egen rad)
   ========================= */
.mt-sort-controls-row td {
  padding: .4rem .75rem;
  background: #f8f8f8;
  text-align: left;
}

.mt-sort-btn-row {
  appearance: none;
  font: inherit;
  padding: .25rem .5rem;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, .2);
  background: #fff;
  color: #000;
  cursor: pointer;
}

.mt-sort-btn-row:hover {
  background: #f0f0f0;
}

.mt-sort-btn-row:focus-visible {
  outline: 2px solid var(--mt-sort-color, #0060df);
  outline-offset: 2px;
}

/* =========================
   5) Live-region (skjermleser)
   ========================= */
.mt-sort-live {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
}


/* =========================
   6) Verktøylinje (CSV + søk)
   ========================= */

/* Selve toolbaren: flukt med tabellen + plass til fokusring */
.mt-controls[role="toolbar"] {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: .6rem;
  padding-inline: .75rem;
  /* flukter med th/td */
  padding-block: 4px;
  /* nok luft til outline-offset */
  overflow: visible;
  /* ikke klipp fokusringer */
}

/* CSV- og Nullstill-knapper – felles, lik høyde som input */
.mt-controls[role="toolbar"] .mt-csv-btn,
.mt-controls[role="toolbar"] .mt-search-reset {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .4rem .6rem;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, .2);
  background: #fff;
  color: #000;
  font: inherit;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  height: 2rem;
}

.mt-controls[role="toolbar"] .mt-csv-btn:hover,
.mt-controls[role="toolbar"] .mt-search-reset:hover {
  background: rgba(0, 0, 0, .03);
}

.mt-controls[role="toolbar"] .mt-csv-btn:focus-visible,
.mt-controls[role="toolbar"] .mt-search-reset:focus-visible {
  outline: 2px solid var(--mt-sort-color, #0060df);
  outline-offset: 2px;
}

/* Kritisk: respekter [hidden] fra JS for Nullstill-knappen */
.mt-controls .mt-search-reset[hidden] {
  display: none !important;
}

/* Søkekomponent i toolbaren */
.mt-controls[role="toolbar"] .mt-searchbar {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
}

.mt-controls[role="toolbar"] .mt-search-label {
  font-weight: 600;
}

/* Input lik høyde som knappene + tydelig fokus */
.mt-controls[role="toolbar"] .mt-search-input {
  font: inherit;
  padding: .35rem .5rem;
  border: 1px solid rgba(0, 0, 0, .2);
  border-radius: 6px;
  background: #fff;
  line-height: 1.2;
  height: 2rem;
  box-sizing: border-box;
  min-width: clamp(14ch, 22vw, 28ch);
}

.mt-controls[role="toolbar"] .mt-search-input:focus-visible {
  outline: 2px solid var(--mt-sort-color, #0060df);
  outline-offset: 2px;
}

/* Smal skjerm: la søk flyte under og fylle bredden */
@media (max-width: 520px) {
  .mt-controls[role="toolbar"] .mt-searchbar {
    width: 100%;
  }

  .mt-controls[role="toolbar"] .mt-search-input {
    flex: 1 1 auto;
    min-width: 0;
  }
}


/* =========================
   7) Småjusteringer
   ========================= */
caption {
  font-weight: 600;
  margin-bottom: .3rem;
}

th[scope="row"] {
  font-weight: 600;
}

/* --- TH skal kunne bryte linjer og vokse i høyden --- */
thead th {
  padding-left: .75rem;
  background: #f6f6f6;
  white-space: normal;
  overflow: visible;
}
thead th .mt-sort-label { display: inline; }
thead th .mt-sort-btn { margin-left: 0; }
thead th:hover,
thead th .mt-sort-btn:hover {
  background: #f0f0f0 !important;
  color: inherit;
}
thead th:focus-within { background: #f0f0f0; }

/* --- Sorteringsknappen i TH: tillat linjebrudd i teksten --- */
.mt-sort-btn {
  display: inline-grid;
  /* bedre linjebryting enn flex for tekst + ikon */
  grid-auto-flow: column;
  align-items: center;
  column-gap: .35rem;
  white-space: normal;
  /* la teksten bryte */
  line-height: 1.2;
  /* litt luftigere ved 2 linjer */
}

/* Ikonet skal ikke strekke knappen, og holder fast bredde */
.mt-sort-icon {
  width: 1em;
  text-align: center;
}