/* =====================================================
   ResponsiveTable — scoped styles
   Uses pure CSS to switch desktop table <-> mobile cards.
   The component sets two CSS custom props on the root:
     --gs-rt-switch-max  e.g. "767.98px"
     --gs-rt-switch-min  e.g. "768px"
   so the breakpoint is configurable via the SwitchAtPx parameter
   without rewriting media queries.
   ===================================================== */

.gs-responsive-table {
    width: 100%;
}

/* -- visually hidden registry slot used to mount <Column> children -- */
.gs-responsive-table__column-registry {
    display: none;
}

/* -- accessible caption (visible to screen readers, hidden visually) -- */
.gs-responsive-table__caption {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* -- switch between desktop table and mobile cards -- */
.gs-responsive-table__desktop {
    display: block;
}

.gs-responsive-table__mobile {
    display: none;
    list-style: none;
    margin: 0;
    padding: 0;
}

@media (max-width: 767.98px) {
    .gs-responsive-table__desktop {
        display: none;
    }
    .gs-responsive-table__mobile {
        display: flex;
        flex-direction: column;
        gap: var(--gs-space-3);
    }
}

/* -- alignment helpers (scoped) --
   Right-aligned columns are almost always numeric (qty, price, totals).
   Force tabular figures so digits line up vertically across rows. */
.gs-responsive-table__cell--right {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-feature-settings:
        "tnum" 1,
        "lnum" 1;
}

.gs-responsive-table__cell--center {
    text-align: center;
}

/* -- breakpoint hide utilities (scoped to the table only) -- */
@media (max-width: 639.98px) {
    .gs-responsive-table__hide-sm {
        display: none;
    }
}

@media (max-width: 767.98px) {
    .gs-responsive-table__hide-md {
        display: none;
    }
}

@media (max-width: 1023.98px) {
    .gs-responsive-table__hide-lg {
        display: none;
    }
}

/* -- sortable header button -- */
.gs-responsive-table__sort-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--gs-space-2);
    background: transparent;
    border: 0;
    padding: 0;
    margin: 0;
    color: inherit;
    font: inherit;
    cursor: pointer;
    min-height: 44px; /* WCAG 2.5.5 touch target */
    touch-action: manipulation;
}

.gs-responsive-table__sort-btn:focus-visible {
    outline: 2px solid var(--gs-primary);
    outline-offset: 2px;
    border-radius: var(--gs-radius-sm);
}

.gs-responsive-table__sort-icon {
    font-size: var(--gs-text-sm);
    color: var(--gs-text-muted);
    line-height: 1;
}

@media (hover: hover) {
    .gs-responsive-table__sort-btn:hover .gs-responsive-table__sort-icon {
        color: var(--gs-text);
    }
}

/* -- skeleton (default LoadingTemplate) -- */
.gs-responsive-table__skeleton {
    display: flex;
    flex-direction: column;
    gap: var(--gs-space-2);
    padding: var(--gs-space-3) 0;
}

.gs-responsive-table__skeleton-row {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: var(--gs-space-3);
}

.gs-responsive-table__skeleton-cell {
    height: 1.25rem;
    background: linear-gradient(
        90deg,
        var(--gs-border) 0%,
        var(--gs-border-light) 50%,
        var(--gs-border) 100%
    );
    background-size: 200% 100%;
    animation: gs-rt-pulse 1.5s ease-in-out infinite;
    border-radius: var(--gs-radius-sm);
}

@keyframes gs-rt-pulse {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* -- empty fallback (default EmptyTemplate) -- */
.gs-responsive-table__empty {
    padding: var(--gs-space-8) var(--gs-space-4);
    text-align: center;
    border: 1px dashed var(--gs-border);
    border-radius: var(--gs-radius-md);
    background: var(--gs-surface);
}

.gs-responsive-table__empty-text {
    margin: 0;
    color: var(--gs-text-muted);
    font-size: var(--gs-text-base);
}

/* -- mobile fallback row (used when MobileCardTemplate is not supplied) -- */
.gs-responsive-table__mobile-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--gs-space-3);
    padding: var(--gs-space-2) 0;
    border-bottom: 1px solid var(--gs-border);
}

.gs-responsive-table__mobile-row:last-child {
    border-bottom: 0;
}

.gs-responsive-table__mobile-label {
    color: var(--gs-text-muted);
    font-size: var(--gs-text-sm);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex: 0 0 auto;
}

.gs-responsive-table__mobile-value {
    color: var(--gs-text);
    font-size: var(--gs-text-base);
    text-align: right;
    word-break: break-word;
}

.gs-responsive-table__mobile-item {
    list-style: none;
}

/* -- clickable row keyboard affordance -- */
.gs-table__row--clickable:focus-visible,
.gs-mobile-card--clickable:focus-visible {
    outline: 2px solid var(--gs-primary);
    outline-offset: -2px;
}

/* -- ensure row click target meets 44px on mobile -- */
@media (max-width: 767.98px) {
    .gs-mobile-card {
        min-height: 44px;
    }
}
