/* GK-RD-3: shared table block.
   Table:        [datatablewrap] > table[datatable], cells [num] (right, tabular), [tabular] (left, tabular), [cellname] (first column), [rowactions].
   Partials:     _StatusBadge ([statusbadge]), _EmptyState ([emptystate]), _Pager ([pager]).
   Import per view, before the page CSS. Tokens come from goeksperv2.css. See DESIGN.md.
   Only the task that owns this file changes it. */

/* ---------- Table ---------- */
[datatablewrap] {
    width: var(--wfull);
    overflow-x: auto;
    background: var(--white);
    border: 1px solid var(--bordergray);
    border-radius: var(--br10);
}

table[datatable] {
    width: var(--wfull);
    margin: 0;
    padding: 0;
    border: 0;
    border-collapse: collapse;
    table-layout: auto;
}

    table[datatable] th,
    table[datatable] td {
        padding: 0.75rem 1rem;
        text-align: left;
        vertical-align: middle;
        font-size: var(--fs14);
        line-height: 1.4;
        color: var(--graydark);
    }

    table[datatable] thead th {
        background: var(--background);
        font-size: var(--fs13);
        font-weight: 600;
        white-space: nowrap;
        border-bottom: 1px solid var(--bordergray);
    }

    table[datatable] tbody tr {
        background: var(--white);
        border: 0;
        border-top: 1px solid var(--bordergray);
        transition: background-color var(--t2s);
    }

        table[datatable] tbody tr:first-child {
            border-top: 0;
        }

        /* Hover tint only on rows that have an action. */
        table[datatable] tbody tr:has([rowactions] a):hover {
            background: var(--soft);
        }

    table[datatable] [cellname] {
        font-weight: 600;
        color: var(--themedarkblue);
    }

    table[datatable] [num] {
        text-align: right;
        white-space: nowrap;
        font-variant-numeric: tabular-nums;
    }

    table[datatable] [tabular] {
        white-space: nowrap;
        font-variant-numeric: tabular-nums;
    }

    table[datatable] th[num] {
        text-align: right;
    }

    table[datatable] [rowactions] {
        text-align: right;
        white-space: nowrap;
    }

    /* Single line with ellipsis; the full text stays in the DOM. Give the cell a max width on the view. */
    table[datatable] [ellipsis] {
        max-width: 24rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* GK-RD-P9a: the row action looks like uibtn="ghost" uisize="sm" (ui-buttons.css) */
    table[datatable] [rowactions] a {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: var(--i10);
        min-height: 36px; /* px: root font-size shrinks on phones; the 720 px rule below makes it 44 px */
        padding: 0 var(--i15);
        font-size: var(--fs15);
        font-weight: 600;
        line-height: 1.2;
        text-decoration: none;
        color: var(--themedarkblue);
        background: transparent;
        border: 1px solid transparent;
        border-radius: var(--br30);
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        transition: background-color var(--t-base) var(--ease-out), color var(--t-base) var(--ease-out), transform var(--t-fast) var(--ease-out);
    }

        table[datatable] [rowactions] a .material-icons {
            font-size: var(--fs16);
            line-height: 1;
        }

        table[datatable] [rowactions] a:active {
            transform: scale(.98);
        }

@media (hover: hover) {
    table[datatable] [rowactions] a:hover {
        background: var(--blueback); /* ghost tint; --background would vanish on the --soft row hover */
    }
}

/* ---------- Status badge ---------- */
/* GK-RD-P9a: same look and tones as [uichip] (ui-cards.css); neutral = the gray chip */
[statusbadge] {
    display: inline-flex;
    align-items: center;
    gap: var(--i5);
    min-height: 28px;
    padding: 0 var(--i10);
    border-radius: var(--br30);
    font-size: var(--fs13);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    background: var(--background);
    color: var(--graydark);
}

    [statusbadge="success"] {
        background: var(--greenback);
        color: var(--greentext);
    }

    [statusbadge="warning"] {
        background: var(--orangeback);
        color: var(--orangetext);
    }

    [statusbadge="danger"] {
        background: var(--redback);
        color: var(--redtext);
    }

    [statusbadge="info"] {
        background: var(--blueback);
        color: var(--themedarkblue);
    }

/* ---------- Empty state ---------- */
[emptystate] {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--i10);
    padding: var(--i40) var(--i20);
    text-align: center;
    background: var(--white);
    border: 1px solid var(--bordergray);
    border-radius: var(--br15);
    box-shadow: var(--elev1); /* the card look of [uicard] (ui-cards.css) */
}

[emptystateicon] {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3.5rem;
    height: 3.5rem;
    font-size: var(--fs24);
    color: var(--themeblue);
    background: var(--blueback);
    border-radius: 50%;
}

[emptystatetitle] {
    margin: 0;
    font-size: var(--fs16);
    font-weight: 700;
    color: var(--themedarkblue);
}

[emptystatedesc] {
    margin: 0;
    max-width: 40ch;
    font-size: var(--fs14);
    line-height: 1.5;
    font-weight: 500;
    color: var(--graydark);
}

[emptystateaction] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--i10);
    min-height: 44px; /* px: phone root font-size is 14px */
    margin-top: var(--i10);
    padding: 0 var(--i20);
    font-size: var(--fs15);
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
    color: var(--themedarkblue);
    background: var(--white);
    border: 1px solid var(--themedarkblue);
    border-radius: var(--br30);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background-color var(--t-base) var(--ease-out), color var(--t-base) var(--ease-out), box-shadow var(--t-base) var(--ease-out), transform var(--t-fast) var(--ease-out);
}

    /* looks like uibtn="secondary" (ui-buttons.css) */
    [emptystateaction] .material-icons {
        font-size: var(--fs16);
        line-height: 1;
    }

@media (hover: hover) {
    [emptystateaction]:hover {
        background: var(--themedarkblue);
        color: var(--white);
        box-shadow: var(--elev2);
        transform: translateY(-1px);
    }
}

[emptystateaction]:active {
    transform: translateY(0) scale(.98);
    box-shadow: none;
}

/* ---------- Pager ---------- */
[pager] ul {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--i5);
    margin: 0;
    padding: 0;
    list-style: none;
}

[pager] li {
    margin: 0;
    padding: 0;
}

[pagerlink],
[pagergap] {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px; /* px: root font-size shrinks to 14px on phones, rem would give < 44 px */
    height: 44px;
    padding: 0 var(--i10);
    font-size: var(--fs14);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* GK-RD-P9a: chip look (pill, as [uichip] in ui-cards.css) */
[pagerlink] {
    color: var(--graydark);
    background: var(--white);
    border: 1px solid var(--bordergray);
    border-radius: var(--br30);
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background-color var(--t-base) var(--ease-out), color var(--t-base) var(--ease-out), border-color var(--t-base) var(--ease-out), transform var(--t-fast) var(--ease-out);
}

    [pagerlink] .material-icons {
        font-size: var(--fs20);
    }

    [pagerlink]:active {
        transform: scale(.96);
    }

@media (hover: hover) {
    [pagerlink]:hover {
        color: var(--themedarkblue);
        background: var(--blueback);
        border-color: var(--blueback);
    }
}

[pagerlink][aria-current="page"] {
    color: var(--themedarkblue);
    background: var(--blueback);
    border-color: var(--themedarkblue);
}

[pagergap] {
    color: var(--graydark);
}

/* ---------- Focus ---------- */
table[datatable] [rowactions] a:focus-visible,
[emptystateaction]:focus-visible,
[pagerlink]:focus-visible {
    outline: 2px solid var(--themedarkblue);
    outline-offset: 2px;
}

/* ---------- Phones (DESIGN breakpoint 720): each row is a small card ---------- */
@media (max-width: 720px) {
    [datatablewrap] {
        overflow: visible;
        background: transparent;
        border: 0;
        border-radius: 0;
    }

    table[datatable],
    table[datatable] tbody {
        display: block;
    }

        table[datatable] thead {
            border: 0;
            clip: rect(0 0 0 0);
            height: 1px;
            margin: -1px;
            overflow: hidden;
            padding: 0;
            position: absolute;
            width: 1px;
        }

        table[datatable] tbody tr {
            display: block;
            margin-bottom: var(--i15);
            padding: 0.75rem 1rem;
            background: var(--white);
            border: 1px solid var(--bordergray);
            border-radius: var(--br10);
        }

            table[datatable] tbody tr:first-child {
                border-top: 1px solid var(--bordergray);
            }

            table[datatable] tbody tr:has([rowactions] a):hover {
                background: var(--white);
            }

        table[datatable] td {
            display: flex;
            align-items: baseline;
            justify-content: space-between;
            gap: var(--i15);
            padding: 0.375rem 0;
            text-align: right;
            min-width: 0;
            overflow-wrap: anywhere;
        }

            table[datatable] td::before {
                content: attr(data-label);
                flex: none;
                font-size: var(--fs13);
                font-weight: 600;
                text-align: left;
                color: var(--graydark);
            }

            /* The first cell is the card title: no label, full width. */
            table[datatable] td[cellname] {
                justify-content: flex-start;
                padding-top: 0;
                padding-bottom: 0.5rem;
                margin-bottom: 0.25rem;
                border-bottom: 1px solid var(--bordergray);
                text-align: left;
                font-size: var(--fs16);
            }

                table[datatable] td[cellname]::before {
                    content: none;
                }

            /* Actions: full width at the bottom, 44 px. */
            table[datatable] td[rowactions] {
                display: block;
                padding: 0.75rem 0 0 0;
            }

                table[datatable] td[rowactions]::before {
                    content: none;
                }

                table[datatable] [rowactions] a {
                    display: flex;
                    width: var(--wfull);
                    min-height: 44px; /* px: phone root font-size is 14px */
                    background: var(--background); /* a visible target on the card */
                }

            table[datatable] [ellipsis] {
                max-width: none;
                white-space: normal;
            }

    [pager] ul {
        justify-content: center;
        gap: var(--i5);
    }

    [pagerlink],
    [pagergap] {
        padding: 0;
    }

    [emptystateaction] {
        width: var(--wfull);
    }
}

@media (prefers-reduced-motion: reduce) {
    table[datatable] tbody tr {
        transition: none;
    }

    table[datatable] [rowactions] a,
    [emptystateaction],
    [pagerlink] {
        transition: background-color var(--t-base) var(--ease-out), color var(--t-base) var(--ease-out), border-color var(--t-base) var(--ease-out);
    }

    table[datatable] [rowactions] a:active,
    [emptystateaction][emptystateaction]:hover,
    [emptystateaction][emptystateaction]:active,
    [pagerlink]:active {
        transform: none;
    }
}
