/* my-gui table card view (MG4): in a narrow place every row is a card. Behaviour: js/table-cards.js. */

.m-cardbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; border-block-end: 1px solid var(--m-line); }
.m-cardbar[hidden] { display: none; }
.m-cardbar-all { display: flex; align-items: center; gap: 8px; min-height: 32px; font-size: 12.5px; color: var(--m-text-2); cursor: pointer; }
.m-cardbar-sort { max-width: 100%; margin-inline-start: auto; }
.m-cardbar-sort span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (pointer: coarse) { .m-cardbar-all, .m-cardbar-sort { min-height: 40px; } }

/* the page scrolls, not a box inside it */
.m-table-scroll.is-cards-box { max-height: none; overflow: visible; }

.m-table.is-cards { display: flex; flex-direction: column; width: 100% !important; table-layout: auto; }
.m-table.is-cards thead { display: contents; }
.m-table.is-cards thead tr:first-child { display: none; }
.m-table.is-cards tbody { display: block; order: 1; min-width: 0; }

/* ---------- a card ---------- */
.m-table.is-cards tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 14px; margin: 8px 10px; padding: 12px; border: 1px solid var(--m-line); border-radius: var(--m-r); background: rgba(var(--m-ink), .015); }
.m-table.is-cards tbody tr.is-sel { border-color: var(--m-accent); background: var(--m-accent-wash); }
.m-table.is-cards tbody tr.m-row-off, .m-table.is-cards tbody tr[hidden] { display: none; }
.m-table.is-cards tbody tr.m-empty-row:not([hidden]) { display: block; border-style: dashed; }
.m-table.is-cards tbody tr.m-empty-row td { display: block; width: auto; height: auto; padding: 0; border: 0; }
.m-table.is-cards tbody tr:not(.m-empty-row) td:nth-child(n) { position: static; display: block; min-width: 0; height: auto; padding: 0; border: 0; background: transparent; box-shadow: none; text-align: start; white-space: normal; overflow-wrap: anywhere; }
.m-table.is-cards tbody tr:not(.m-empty-row):hover td:first-child, .m-table.is-cards tbody tr:not(.m-empty-row):hover td.m-col-first { box-shadow: none; }
.m-table.is-cards tbody td[data-m-part="field"]::before { content: attr(data-label); display: block; margin-block-end: 1px; font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--m-text-3); }
.m-table.is-cards tbody tr td[data-m-wide] { grid-column: 1 / -1; }
.m-table.is-cards tbody tr td[data-m-part="title"] { order: -3; grid-column: 1 / -1; font-size: 14px; font-weight: 800; color: var(--m-text); }
.m-table.is-cards tbody tr td[data-m-part="badge"] { order: -2; justify-self: start; padding: 2px 9px; border-radius: 99px; background: var(--m-accent-wash); color: var(--m-text); font-size: 11.5px; font-weight: 800; }
.m-table.is-cards tbody tr td[data-m-part="meta"] { order: -1; grid-column: 1 / -1; font-size: 12px; color: var(--m-text-3); }
/* the checkbox sits in the top corner, beside the title */
.m-table.is-cards tbody tr:not(.m-empty-row) { position: relative; }
.m-table.is-cards tbody tr:not(.m-empty-row) td[data-m-part="select"]:nth-child(n) { position: absolute; inset-block-start: 12px; inset-inline-end: 12px; width: auto; }
.m-table.is-cards tbody tr td[data-m-part="select"] ~ td[data-m-part="title"], .m-table.is-cards tbody tr:has(td[data-m-part="select"]) td[data-m-part="title"] { padding-inline-end: 30px; }
@media (pointer: coarse) { .m-table.is-cards tbody td[data-m-part="select"] .m-checkbox { width: 22px; height: 22px; } }
.m-table.is-cards.m-table--compact tbody tr { gap: 5px 12px; margin-block: 6px; padding: 9px 11px; }
.m-table.is-cards.m-table--compact tbody tr:not(.m-empty-row) td[data-m-part="select"]:nth-child(n) { inset-block-start: 9px; inset-inline-end: 11px; }

/* ---------- the filter row: labelled fields ---------- */
.m-table.is-cards thead .m-filter-row:not([hidden]) { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; padding: 10px 12px; border-block-end: 1px solid var(--m-line); }
.m-table.is-cards thead .m-filter-row td { display: block; min-width: 0; padding: 0; border: 0; background: transparent; }
.m-table.is-cards thead .m-filter-row td::before { content: attr(data-label); display: block; margin-block-end: 3px; font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--m-text-3); }
.m-table.is-cards thead .m-filter-row td:empty { display: none; }
.m-table.is-cards .m-colfilter { min-width: 0; height: 36px; }
.m-table.is-cards .m-filter-row .m-combo { min-width: 0; }
.m-table.is-cards .m-filter-row .m-combo > .m-input { height: 36px; }
.m-table.is-cards .m-colrange .m-colfilter { min-width: 0; }

/* ---------- the summary: under the cards, kept at the bottom of the window ---------- */
.m-table.is-cards thead .m-sum-row:not([hidden]) { position: sticky; inset-block-end: 0; z-index: 3; order: 2; display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 9px 12px; border-block-start: 1px solid var(--m-line-strong); background: linear-gradient(var(--m-accent-wash), var(--m-accent-wash)), var(--m-card-solid); }
.m-table.is-cards thead .m-sum-row td { position: static; display: block; height: auto; padding: 0; border: 0; background: transparent; font-size: 12px; }
.m-table.is-cards thead .m-sum-row td:empty { display: none; }
.m-table.is-cards thead .m-sum-row td[data-label]::before { content: attr(data-label); margin-inline-end: 6px; color: var(--m-text-3); }
.m-table.is-cards thead .m-sum-row td:first-child { flex: 0 0 auto; }
/* the selection bar stays at the bottom then: the summary stays in its place */
.m-table-card:has(.m-selbar--bottom:not([hidden])) .m-table.is-cards thead .m-sum-row:not([hidden]) { position: static; }

.m-table.is-cards .m-col-off, .m-table.is-cards td[data-m-part="hide"] { display: none !important; }

/* ---------- the sort sheet ---------- */
.m-sortsheet .m-modal-box { width: min(440px, 100%); }
.m-sortsheet .m-modal-body { display: flex; flex-direction: column; gap: 8px; }
.m-sortline { display: flex; align-items: center; gap: 6px; }
.m-sortline-n { flex: 0 0 auto; width: 14px; font-size: 11px; font-weight: 800; color: var(--m-text-3); text-align: center; }
.m-sortline-col { flex: 1 1 0%; min-width: 0; }
.m-sortline-dir { flex: 0 0 auto; min-width: 96px; }
.m-sortline-foot { display: flex; flex-wrap: wrap; gap: 6px; }
@media (max-width: 640px) {
  .m-modal.m-sortsheet { place-items: end stretch; padding: 0; }
  .m-sortsheet .m-modal-box { width: 100%; max-height: 86vh; max-height: 86dvh; border-radius: 18px 18px 0 0; padding-block-end: env(safe-area-inset-bottom, 0px); }
  .m-sortline .m-btn, .m-sortline .m-select { min-height: 40px; }
}

@media print { .m-cardbar { display: none; } }
