/* gh-tables (DEB-3668, DEB-3681, DEB-3686, DEB-3691, DEB-3730, DEB-3755; spec/gh-tables.md). Loaded on the front end only where a switched-on table is rendered
 * (FR-4), and inside the editor iframe (FR-7, FR-14). Colours come from the theme's variables, with fallbacks. */

/* A wide table scrolls inside its own box on a phone; the page does not get wider (FR-9) */
.gh-table { overflow-x: auto; margin: 0 0 1.5em; }
.gh-table table { width: 100%; max-width: none; border-collapse: collapse; }
/* figure.gh-table: one step above core's .wp-block-table rules (cell borders, a 3px currentColor line under thead),
 * so the look does not depend on which stylesheet loads last */
figure.gh-table thead, figure.gh-table tfoot { border: 0; }
figure.gh-table th, figure.gh-table td { padding: .35em .6em; vertical-align: top; border: 0; border-bottom: 1px solid var(--rule, #ddd6c8); text-align: left; }
figure.gh-table thead th { background: var(--panel, #f3efe6); color: var(--ink, #222); border-bottom: 2px solid var(--mold, #8a7a5c); }
.gh-table__hidden, .gh-table__off { display: none; }   /* a search miss; a row on another page (FR-53) */
/* FR-95 (DEB-4190): core's Strípur, counted over the rows that are shown, so a search or a page keeps them alternating */
.wp-block-table.gh-table.is-style-stripes tbody tr:nth-child(odd) { background-color: transparent; }
.wp-block-table.gh-table.is-style-stripes tbody tr:nth-child(odd of :not(.gh-table__hidden, .gh-table__off)) { background-color: #f0f0f0; }
.gh-table__vh { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* FR-7, FR-29, FR-30 Talmerkt: a leading "Nr." column. Each body row shows its own fixed label, data-gh-nr, written by
 * the server (and by the editor in the canvas), so sorting, searching and moving rows never renumber them. A row with
 * no label (none should reach a page) falls back to a CSS counter */
.gh-table--numbered tbody { counter-reset: gh-row; }
.gh-table--numbered tbody tr { counter-increment: gh-row; }
.gh-table--numbered tr::before {
    /* a real width, not 1%: core saves tables with table-layout: fixed, which squeezed a 1% column under its numbers */
    display: table-cell; content: ""; width: 4.5ch; white-space: nowrap; text-align: right;
    padding: .35em .6em; border-bottom: 1px solid var(--rule, #ddd6c8); font-variant-numeric: tabular-nums; color: var(--ink-soft, #666);
}
/* Visual only ("… / ''" = no text for screen readers): they already announce "row 5 of 120", and a lone "Nr." with no
 * numbers under it would only confuse. Browsers without the alt-text syntax keep the first declaration */
.gh-table--numbered tbody tr::before { content: counter(gh-row) "."; content: counter(gh-row) "." / ""; }
.gh-table--numbered tbody tr[data-gh-nr]::before { content: attr(data-gh-nr) "."; content: attr(data-gh-nr) "." / ""; }
/* FR-71: a text label ("44. *", ".", empty, or no number at all) is shown exactly as written, with no dot added */
.gh-table--numbered tbody tr[data-gh-nr][data-gh-nrtext]::before { content: attr(data-gh-nr); content: attr(data-gh-nr) / ""; }
.gh-table--numbered thead tr::before { content: "Nr."; content: "Nr." / ""; font-weight: 600; color: var(--ink, #222); background: var(--panel, #f3efe6); border-bottom: 2px solid var(--mold, #8a7a5c); }
.gh-table--numbered thead tr + tr::before { content: ""; content: "" / ""; }   /* FR-67: "Nr." once, over a header of two rows */
/* FR-36: on a sortable table the script puts a real, pressable "Nr." header cell there instead, spanning every header row */
.gh-table--nrsort thead tr::before { display: none; }
figure.gh-table thead th.gh-table__nr { width: 6.5ch; white-space: nowrap; }

/* FR-33, FR-34: one small icon above the table, aligned right; the search status beside it stays visible when closed.
 * Pressing the icon opens a compact panel with the search field and Raða eftir */
.gh-table__tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .4em .6em; margin: 0 0 .45em; font-size: .9em; }
.gh-table__status { flex: 1 1 auto; margin: 0; color: var(--ink-soft, #666); text-align: right; }
/* FR-47: the table's title, alone above the table, or at the left of the icon's line */
.gh-table__title { margin: 0 0 .45em; font-size: 1.15em; font-weight: 600; line-height: 1.3; color: var(--ink, #222); }
.gh-table__tools .gh-table__title { flex: 1 1 auto; margin: 0 auto 0 0; min-width: 0; font-size: 1.28em; }
.gh-table__tools .gh-table__title ~ .gh-table__status { flex: 0 1 auto; }
.gh-table__toggle {
    position: relative; flex: none; display: inline-grid; place-items: center; box-sizing: border-box; width: 2.1rem; height: 2.1rem;
    margin: 0; padding: 0; border: 1px solid var(--rule, #ddd6c8); border-radius: 999px; background: #fff; color: var(--ink-soft, #666);
    cursor: pointer; transition: background-color .15s, border-color .15s, color .15s;
}
.gh-table__toggle svg { width: 1.05rem; height: 1.05rem; }
@media (hover: hover) { .gh-table__toggle:hover { color: var(--ink, #222); border-color: var(--mold, #8a7a5c); } }
.gh-table__toggle[aria-expanded="true"] { color: #fff; background: var(--mold, #8a7a5c); border-color: var(--mold, #8a7a5c); }
.gh-table__dot { position: absolute; top: .1rem; right: .1rem; width: .5rem; height: .5rem; border-radius: 50%; background: var(--blue, #1a5fb4); box-shadow: 0 0 0 2px #fff; }
.gh-table__dot[hidden] { display: none; }
@media (pointer: coarse) { .gh-table__toggle { width: 2.6rem; height: 2.6rem; } }   /* FR-34: 40 px and more on touch */

/* FR-35: "Navn ▲ ✕" beside the icon while the rows are re-sorted; one press takes the sort off */
.gh-table__clear {
    flex: none; display: inline-flex; align-items: center; gap: .35em; box-sizing: border-box; height: 2.1rem; margin: 0; padding: 0 .55em 0 .75em;
    font: inherit; border: 1px solid var(--rule, #ddd6c8); border-radius: 999px; background: var(--panel, #f3efe6); color: var(--ink, #222);
    cursor: pointer; white-space: nowrap; max-width: 16em; transition: background-color .15s, border-color .15s;
}
.gh-table__clear[hidden] { display: none; }
.gh-table__clear-text { overflow: hidden; text-overflow: ellipsis; }
.gh-table__clear svg { flex: none; width: .95rem; height: .95rem; color: var(--ink-soft, #666); }
@media (hover: hover) { .gh-table__clear:hover { border-color: var(--mold, #8a7a5c); } .gh-table__clear:hover svg { color: var(--ink, #222); } }
.gh-table__clear:focus-visible { outline: 2px solid var(--blue, #1a5fb4); outline-offset: 2px; }
@media (pointer: coarse) { .gh-table__clear { height: 2.6rem; } }

.gh-table__panel {
    flex: 0 0 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .45em .9em;
    box-sizing: border-box; padding: .5em .6em; border: 1px solid var(--rule, #ddd6c8); border-radius: 8px; background: var(--panel, #f3efe6);
}
.gh-table__panel[hidden] { display: none; }
.gh-table__panel input, .gh-table__panel select, .gh-table__dir {
    box-sizing: border-box; height: 2rem; font: inherit; margin: 0; padding: 0 .5em; border: 1px solid var(--rule, #ddd6c8); border-radius: 6px;
    background: #fff; color: var(--ink, #222);
}
.gh-table__panel select:disabled, .gh-table__dir:disabled { opacity: .5; cursor: default; }
.gh-table__toggle:focus-visible, .gh-table__panel input:focus-visible, .gh-table__panel select:focus-visible, .gh-table__dir:focus-visible {
    outline: 2px solid var(--blue, #1a5fb4); outline-offset: 2px;
}

/* FR-5 Leitiboks: a magnifying glass inside the field; the label is for screen readers, the placeholder for the eye */
.gh-table__search { position: relative; flex: 1 1 12em; max-width: 20em; display: flex; }
.gh-table__search svg { position: absolute; left: .55em; top: 50%; width: 1em; height: 1em; transform: translateY(-50%); color: var(--ink-soft, #666); pointer-events: none; }
.gh-table__search input { flex: 1 1 auto; width: 100%; min-width: 0; padding-left: 1.9em; }

/* FR-25 Raða eftir: a small label, the column, and a direction button with an arrow (up = Vaksandi) */
.gh-table__sortby { flex: none; display: flex; align-items: center; gap: .4em; }   /* the field gives way, not the select */
.gh-table__sortby label { color: var(--ink-soft, #666); white-space: nowrap; }
.gh-table__sortby select { min-width: 0; max-width: 13em; }
.gh-table__dir { flex: none; display: inline-grid; place-items: center; width: 2rem; padding: 0; cursor: pointer; }
.gh-table__dir svg { width: 1rem; height: 1rem; transition: transform .15s; }
.gh-table__dir[data-dir="desc"] svg { transform: rotate(180deg); }

/* FR-54, FR-56 Síðuskifti: under the table, the range at the left, Fyrra · 1 … 4 5 6 … 20 · Næsta and Røðir á síðu at the right.
 * It wraps rather than overflowing, so a phone at 390 px never scrolls sideways (FR-58) */
figure.gh-table:has(+ .gh-table__pager:not([hidden])) { margin-bottom: .6em; }
.gh-table__pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .45em .9em; margin: 0 0 1.5em; font-size: .9em; }
.gh-table__pager[hidden], .gh-table__pages[hidden] { display: none; }
.gh-table__range { flex: 1 1 auto; margin: 0; color: var(--ink-soft, #666); font-variant-numeric: tabular-nums; }
.gh-table__pages { display: flex; flex-wrap: wrap; align-items: center; gap: .3em; }
.gh-table__pg {
    box-sizing: border-box; min-width: 2.1rem; height: 2.1rem; margin: 0; padding: 0 .6em; font: inherit; font-variant-numeric: tabular-nums;
    border: 1px solid var(--rule, #ddd6c8); border-radius: 6px; background: #fff; color: var(--ink, #222); cursor: pointer;
    transition: background-color .15s, border-color .15s;
}
@media (hover: hover) { .gh-table__pg:not(:disabled):not([aria-current]):hover { border-color: var(--mold, #8a7a5c); background: var(--panel, #f3efe6); } }
.gh-table__pg[aria-current] { background: var(--mold, #8a7a5c); border-color: var(--mold, #8a7a5c); color: #fff; font-weight: 600; cursor: default; }
.gh-table__pg:disabled { opacity: .45; cursor: default; }
.gh-table__pg:focus-visible, .gh-table__size select:focus-visible { outline: 2px solid var(--blue, #1a5fb4); outline-offset: 2px; }
.gh-table__gap { min-width: 1.2em; text-align: center; color: var(--ink-soft, #666); }
.gh-table__size { display: flex; align-items: center; gap: .4em; }
.gh-table__size label { color: var(--ink-soft, #666); white-space: nowrap; }
.gh-table__size select {
    box-sizing: border-box; height: 2.1rem; margin: 0; padding: 0 .4em; font: inherit; border: 1px solid var(--rule, #ddd6c8); border-radius: 6px;
    background: #fff; color: var(--ink, #222);
}
@media (pointer: coarse) { .gh-table__pg, .gh-table__size select { min-width: 2.6rem; height: 2.6rem; } }   /* 40 px and more on touch */
/* FR-57: scrolled back to just under the admin bar of a logged-in editor */
.gh-table__tools, .gh-table__title, figure.gh-table { scroll-margin-top: .5rem; }
.admin-bar .gh-table__tools, .admin-bar .gh-table__title, .admin-bar figure.gh-table { scroll-margin-top: 3rem; }

/* FR-9, FR-28 on a phone: core saves tables with a fixed layout, which squeezes six columns into 360 px and breaks words
 * mid-letter. Below 600 px the columns keep a readable width and the table scrolls sideways in its own box instead.
 * FR-34: the open panel fills the width, the search field on its own line and Raða eftir under it */
@media (max-width: 600px) {
    figure.gh-table table.has-fixed-layout, figure.gh-table table { table-layout: auto; }
    figure.gh-table table.has-fixed-layout th, figure.gh-table table.has-fixed-layout td, figure.gh-table th, figure.gh-table td { min-width: 6.5em; word-break: normal; overflow-wrap: normal; }
    .gh-table__search, .gh-table__sortby { flex: 1 1 100%; max-width: none; }
    .gh-table__sortby select { flex: 1 1 auto; max-width: none; }
    .gh-table__panel input, .gh-table__panel select, .gh-table__dir { height: 2.4rem; }
    .gh-table__dir { width: 2.4rem; }
    figure.gh-table table th.gh-table__nr { min-width: 0; }   /* FR-36: the Nr. column stays narrow */
    .gh-table__pager { justify-content: space-between; }
    .gh-table__range { flex: 1 1 100%; }   /* FR-58: the range on its own line, the buttons under it */
    .gh-table__pg { padding: 0 .5em; }
}

/* FR-24 Kann sorterast: the whole header cell is pressable and looks it: ⇅, then ▲ / ▼ on the active column */
figure.gh-table thead th.gh-table__sortable { cursor: pointer; }
@media (hover: hover) {
    figure.gh-table thead th.gh-table__sortable:hover { background: color-mix(in srgb, var(--mold, #8a7a5c) 18%, var(--panel, #f3efe6)); }
}
figure.gh-table thead th[aria-sort] { background: color-mix(in srgb, var(--mold, #8a7a5c) 26%, var(--panel, #f3efe6)); }
.gh-table__sort { all: unset; box-sizing: border-box; display: inline-flex; align-items: baseline; gap: .4em; cursor: pointer; font-weight: 600; width: 100%; border-radius: 2px; }
.gh-table__sort:focus-visible { outline: 2px solid var(--blue, #1a5fb4); outline-offset: 2px; }
.gh-table__sort-icon { flex: none; line-height: 1; }
.gh-table__sort-icon::after { content: "⇅"; opacity: .7; }
th[aria-sort="ascending"] .gh-table__sort-icon::after { content: "▲"; opacity: 1; }
th[aria-sort="descending"] .gh-table__sort-icon::after { content: "▼"; opacity: 1; }

/* FR-43: column widths, as --gh-w1 … --gh-w20 on the figure (a percentage of the table). Counting skips FR-36's real Nr.
 * header cell; the body's Nr. box is a ::before and is never counted. Below 600 px FR-28's minimum width still wins */
.gh-table--widths tr > :nth-child(1 of :not(.gh-table__nr)) { width: var(--gh-w1, auto); }
.gh-table--widths tr > :nth-child(2 of :not(.gh-table__nr)) { width: var(--gh-w2, auto); }
.gh-table--widths tr > :nth-child(3 of :not(.gh-table__nr)) { width: var(--gh-w3, auto); }
.gh-table--widths tr > :nth-child(4 of :not(.gh-table__nr)) { width: var(--gh-w4, auto); }
.gh-table--widths tr > :nth-child(5 of :not(.gh-table__nr)) { width: var(--gh-w5, auto); }
.gh-table--widths tr > :nth-child(6 of :not(.gh-table__nr)) { width: var(--gh-w6, auto); }
.gh-table--widths tr > :nth-child(7 of :not(.gh-table__nr)) { width: var(--gh-w7, auto); }
.gh-table--widths tr > :nth-child(8 of :not(.gh-table__nr)) { width: var(--gh-w8, auto); }
.gh-table--widths tr > :nth-child(9 of :not(.gh-table__nr)) { width: var(--gh-w9, auto); }
.gh-table--widths tr > :nth-child(10 of :not(.gh-table__nr)) { width: var(--gh-w10, auto); }
.gh-table--widths tr > :nth-child(11 of :not(.gh-table__nr)) { width: var(--gh-w11, auto); }
.gh-table--widths tr > :nth-child(12 of :not(.gh-table__nr)) { width: var(--gh-w12, auto); }
.gh-table--widths tr > :nth-child(13 of :not(.gh-table__nr)) { width: var(--gh-w13, auto); }
.gh-table--widths tr > :nth-child(14 of :not(.gh-table__nr)) { width: var(--gh-w14, auto); }
.gh-table--widths tr > :nth-child(15 of :not(.gh-table__nr)) { width: var(--gh-w15, auto); }
.gh-table--widths tr > :nth-child(16 of :not(.gh-table__nr)) { width: var(--gh-w16, auto); }
.gh-table--widths tr > :nth-child(17 of :not(.gh-table__nr)) { width: var(--gh-w17, auto); }
.gh-table--widths tr > :nth-child(18 of :not(.gh-table__nr)) { width: var(--gh-w18, auto); }
.gh-table--widths tr > :nth-child(19 of :not(.gh-table__nr)) { width: var(--gh-w19, auto); }
.gh-table--widths tr > :nth-child(20 of :not(.gh-table__nr)) { width: var(--gh-w20, auto); }

/* FR-14: editor canvas only (the class is never rendered on the page). The row's ::before box is the grab handle;
 * with Talmerkt on it holds the handle and the number. Header and footer rows get an empty box, to keep the columns */
.gh-table--edit tr::before { display: table-cell; content: ""; width: 1.4em; padding: .35em .15em; border: 0; text-align: center; vertical-align: top; user-select: none; -webkit-user-select: none; }
.gh-table--edit tbody tr::before { content: "⠿"; cursor: grab; color: var(--ink-soft, #666); opacity: .5; }
.gh-table--edit tbody tr:hover::before { opacity: 1; color: var(--blue, #1a5fb4); }
.gh-table--edit.gh-table--numbered tr::before { width: 6ch; text-align: right; white-space: nowrap; }
.gh-table--edit.gh-table--numbered tbody tr::before { content: "⠿\2002" counter(gh-row) "."; }
.gh-table--edit.gh-table--numbered tbody tr[data-gh-nr]::before { content: "⠿\2002" attr(data-gh-nr) "."; }
.gh-table--edit.gh-table--numbered tbody tr[data-gh-nrtext]::before { content: "⠿\2002" attr(data-gh-nr); }   /* FR-71 */
/* FR-62: a row group has one handle, on its first row; the editor marks the rows after it data-gh-cont */
.gh-table--edit tbody tr[data-gh-cont]::before { content: ""; cursor: default; }
.gh-table--edit.gh-table--numbered tbody tr[data-gh-cont]::before { content: attr(data-gh-nr) "."; cursor: default; }
.gh-table--edit.gh-table--numbered tbody tr[data-gh-cont][data-gh-nrtext]::before { content: attr(data-gh-nr); }
.gh-table--edit .gh-drag-source { opacity: .35; }
.gh-table--edit .gh-drop-before > *, .gh-table--edit .gh-drop-before::before { box-shadow: inset 0 3px 0 var(--blue, #1a5fb4); }
.gh-table--edit .gh-drop-after > *, .gh-table--edit .gh-drop-after::before { box-shadow: inset 0 -3px 0 var(--blue, #1a5fb4); }
html.gh-dragging, html.gh-dragging * { cursor: grabbing !important; }

/* FR-8 print: the whole table, no controls, sort buttons as plain header text, header repeated on every page */
@media print {
    .gh-table__tools:not(:has(.gh-table__title)) { display: none !important; }
    .gh-table__tools > :not(.gh-table__title) { display: none !important; }   /* FR-47: the title prints */
    .gh-table { overflow: visible; }
    .gh-table tr.gh-table__hidden, .gh-table tr.gh-table__off { display: table-row; }   /* FR-58: every row, whatever page */
    /* FR-95: print shows every row, so the stripes count every row again (same specificity, later) */
    .wp-block-table.gh-table.is-style-stripes tbody tr:nth-child(odd of :not(.gh-table--none)) { background-color: #f0f0f0; }
    .wp-block-table.gh-table.is-style-stripes tbody tr:nth-child(even of :not(.gh-table--none)) { background-color: transparent; }
    .gh-table__pager { display: none !important; }
    .gh-table thead { display: table-header-group; }
    .gh-table tr { break-inside: avoid; }
    .gh-table__sort-icon { display: none; }
    figure.gh-table thead th[aria-sort] { background: var(--panel, #f3efe6); }
    .gh-table__sort { display: contents; }   /* Chromium paints no <button> in a header repeated on page 2+: drop its box */
}
