/**
 * Sparkles Table Component Styles
 * Data tables for orders, comparisons, product lists
 * Extends: sparkles-utilities.css, sparkles-animations.css, sparkles-tokens.css
 * All 3 optimization layers applied: keyframes consolidated, patterns extracted, component organization
 */

/* ========== TABLE CONTAINER ========== */
/* Card border styling moved to sparkles-utilities.css (.sparkles-card-bordered-lg) */
.sparkles-table-container {
    width: 100%;
    overflow-x: auto;
    container-type: inline-size;
}

.sparkles-table-responsive {
    min-width: 600px;
}

/* ========== TABLE BASE ========== */
.sparkles-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 1rem;
    line-height: 1.5rem;
    line-height: 1.25;
}

/* ========== TABLE HEADER ========== */
.sparkles-table-header {
    background-color: var(--gray-50);
    border-bottom-width: 2px;
    border-color: var(--gray-200);
}

.sparkles-table-header th {
    padding-left: 1rem;
    padding-right: 1rem;
    padding-top: .75rem;
    padding-bottom: .75rem;
    text-align: left;
    font-size: .75rem;
    line-height: 1rem;
    font-weight: 500;
    color: var(--gray-700);
    text-transform: uppercase;
    letter-spacing: .05em;
}

/* ========== TABLE BODY ========== */
.sparkles-table-body {
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
}

.sparkles-table-body td,
.sparkles-table-expand-content td {
    padding-left: 1rem;
    padding-right: 1rem;
    padding-top: .75rem;
    padding-bottom: .75rem;
    border-bottom-width: 1px;
    border-color: var(--gray-200);
}

.sparkles-table-body td {
    color: var(--gray-700);
}

.sparkles-table-body tr:last-child td {
    border-bottom-width: 0;
}

.sparkles-table-body tr:last-child td:first-child {
    border-bottom-left-radius: var(--radius-lg);
}

/* ========== TABLE ROW STATES ========== */
.sparkles-table-row {
    cursor: pointer;
}

.sparkles-table-row:hover {
    background-color: var(--gray-50);
}

.sparkles-table-row-selected {
    background-color: var(--color-accent);
}

.sparkles-table-row-selected:hover {
    background-color: var(--color-primary) bg-opacity-15;
}

/* ========== SORTABLE HEADERS ========== */
.sparkles-table-sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 2rem;
}

.sparkles-table-sortable:hover {
    background-color: var(--gray-100);
}

.sparkles-table-sort-icon {
    position: absolute;
    right: .75rem;
    width: 1rem;
    height: 1rem;
    opacity: .5;
    transition-property: all;
    transition-duration: .15s;
    transition-timing-function: cubic-bezier(0, 0, .2, 1);
}

.sparkles-table-sortable:hover .sparkles-table-sort-icon {
    opacity: 1;
}

.sparkles-table-sort-asc .sparkles-table-sort-icon {
    transform: translateY(-50%) rotate(0deg);
    opacity: 1;
}

.sparkles-table-sort-desc .sparkles-table-sort-icon {
    transform: translateY(-50%) rotate(180deg);
    opacity: 1;
}

/* ========== TABLE CELL TYPES ========== */
.sparkles-table-cell-number {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.sparkles-table-cell-currency {
    color: var(--color-secondary);
    text-align: right;
    font-weight: 500;
}

.sparkles-table-cell-date {
    font-variant-numeric: tabular-nums;
    color: var(--gray-600);
}

.sparkles-table-cell-status {
    text-align: center;
}

.sparkles-table-cell-actions {
    text-align: right;
    white-space: nowrap;
}

.sparkles-order-total-label {
    text-align: left;
    padding: 3px 10px;
}

.sparkles-order-total-value {
    text-align: right;
    padding: 3px 10px;
}

/* ========== STATUS BADGES - REMOVED (Phase 7) ========== */
/* Use utilities from sparkles-utilities.css instead:
 * .sparkles-status-badge → .sparkles-status-base
 * .sparkles-status-success → .sparkles-status-success
 * .sparkles-status-warning → .sparkles-status-warning
 * .sparkles-status-error → .sparkles-status-error
 * .sparkles-status-info → .sparkles-status-info
 * .sparkles-status-neutral → .sparkles-status-neutral
 */

/* ========== TABLE ACTIONS ========== */
.sparkles-table-actions,
.sparkles-dropdown-toggle {
    justify-content: center;
    gap: .5rem;
}

.sparkles-table-action-btn,
.sparkles-table-export-button,
.sparkles-table-filter-button {
    padding-left: .75rem;
    padding-right: .75rem;
    font-size: .875rem;
    line-height: 1.25rem;
    border-width: 1px;
    border-color: var(--gray-300);
    border-radius: var(--radius-sm);
    color: var(--gray-700);
    transition-timing-function: cubic-bezier(0, 0, .2, 1);
    transition-duration: .3s;
}

.sparkles-table-action-btn,
.sparkles-table-filter-button {
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
}

.sparkles-table-action-btn {
    padding-top: .25rem;
    padding-bottom: .25rem;
    transition-property: all;
}

.sparkles-table-action-btn:hover {
    background-color: var(--gray-100);
    border-color: var(--gray-400);
}

:is(.sparkles-table-action-primary,
    .sparkles-pagination-button.active,
    .sparkles-table-filter-button.active,
    .sparkles-review-filter-btn-active,
    .sparkles-pagination-active .sparkles-pagination-link,
    .sparkles-pagination-link[aria-current="page"],
    .product-options-wrapper .swatch-option.text.selected,
    .sparkles-step-current .sparkles-step-indicator) {
    background-color: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.sparkles-table-action-primary:hover {
    background-color: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
}

/* ========== TABLE VARIANTS ========== */

/* Striped table */
.sparkles-table-striped .sparkles-table-body tr:nth-child(even) {
    background-color: var(--gray-50);
}

.sparkles-table-striped .sparkles-table-body tr:nth-child(even):hover {
    background-color: var(--gray-100);
}

/* Bordered table */
.sparkles-table-bordered {
    border-width: 1px;
    border-color: var(--gray-200);
}

.sparkles-table-bordered th,
.sparkles-table-bordered td {
    border-right-width: 1px;
    border-color: var(--gray-200);
}

.sparkles-table-bordered th:last-child,
.sparkles-table-bordered td:last-child {
    border-right-width: 0;
}

/* Compact table */
.sparkles-table-compact th,
.sparkles-table-compact td {
    padding-left: 1rem;
    padding-right: 1rem;
    padding-top: .5rem;
    padding-bottom: .5rem;
}

.sparkles-table-compact {
    font-size: .875rem;
    line-height: 1.25rem;
}

/* Large table */
.sparkles-table-large th,
.sparkles-table-large td,
.sparkles-spacing-comfortable {
    padding-left: 2rem;
    padding-right: 2rem;
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
}

.sparkles-table-large {
    font-size: 1.125rem;
    line-height: 1.75rem;
}

/* ========== COMPARISON TABLE ========== */
.sparkles-comparison-table {
    text-align: center;
}

.sparkles-comparison-table th {
    text-align: center;
}

.sparkles-comparison-table .sparkles-table-header th:first-child {
    text-align: left;
}

.sparkles-comparison-table td:first-child {
    text-align: left;
    font-weight: 500;
    background-color: var(--gray-50);
}

.sparkles-action-desc,
.sparkles-comparison-check {
    --tw-text-opacity: 1;
}

.sparkles-comparison-check {
    color: rgba(16, 185, 129, var(--tw-text-opacity, 1));
    font-size: 1.25rem;
    line-height: 1.75rem;
}

.sparkles-comparison-cross {
    color: var(--gray-400);
    font-size: 1.25rem;
    line-height: 1.75rem;
}

/* ========== TABLE FOOTER ========== */
.sparkles-table-footer {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
    padding-top: 1rem;
    padding-bottom: 1rem;
    background-color: var(--gray-50);
    border-top-width: 1px;
    border-color: var(--gray-200);
    font-size: .875rem;
    line-height: 1.25rem;
    color: var(--gray-600);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sparkles-table-summary {
    font-weight: 500;
}

/* ========== EMPTY STATE ========== */
.sparkles-table-empty {
    text-align: center;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
    padding-top: 3rem;
    padding-bottom: 3rem;
    color: var(--gray-500);
}

.sparkles-table-empty-icon {
    width: 3rem;
    height: 3rem;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 1rem;
    color: var(--gray-400);
}

.sparkles-table-empty-title,
.sparkles-upload-text,
.sparkles-loading-title,
.sparkles-file-upload-text {
    font-size: 1.125rem;
    line-height: 1.75rem;
    margin-bottom: .5rem;
}

.sparkles-table-empty-title {
    font-weight: 500;
    color: var(--gray-700);
}

.sparkles-table-empty-description {
    margin-bottom: 1rem;
}

/* ========== LOADING STATE ========== */
.sparkles-table-loading {
    position: relative;
}

.sparkles-table-loading::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
    --tw-bg-opacity: 0.8;
    z-index: var(--z-dropdown);
}

.sparkles-table-loading::after {
    content: '';
    animation: sparkles-spin 1s linear infinite;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    z-index: var(--z-sticky);
}

/* ========== CHECKBOX COLUMN ========== */
.sparkles-table-checkbox {
    width: 1.25rem;
    text-align: center;
}

.sparkles-table-checkbox input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    border-radius: var(--radius-sm);
    border-width: 1px;
    border-color: var(--gray-300);
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
    cursor: pointer;
}

.sparkles-table-checkbox input[type="checkbox"]:checked {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

/* ========== EXPANDABLE ROWS ========== */
.sparkles-table-expandable .sparkles-table-row {
    cursor: pointer;
}

.sparkles-table-expand-icon {
    width: 1rem;
    height: 1rem;
    transition-property: transform;
    transition-timing-function: cubic-bezier(0, 0, .2, 1);
    transition-duration: .3s;
}

.sparkles-table-row-expanded .sparkles-table-expand-icon {
    transform: rotate(90deg);
}

.sparkles-table-expand-content {
    background-color: var(--gray-50);
    border-top-width: 1px;
    border-color: var(--gray-200);
}

/* ========== RESPONSIVE DESIGN (consolidated below) ========== */

@container (max-width: 475px) {

    /* Stack table for very small screens */
    .sparkles-table-stack {
        display: block;
    }

    .sparkles-table-stack .sparkles-table-header {
        display: none;
    }

    .sparkles-table-stack .sparkles-table-body,
    .sparkles-table-stack .sparkles-table-row,
    .sparkles-table-stack td {
        display: block;
        width: 100%;
    }

    .sparkles-table-stack .sparkles-table-row {
        border-width: 1px;
        border-color: var(--gray-200);
        border-radius: var(--radius-lg);
        margin-bottom: 1rem;
        padding: 1rem;
        --tw-bg-opacity: 1;
        background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
        --tw-shadow: 0 1px 2px 0 #0000000d;
        --tw-shadow-colored: 0 1px 2px 0 var(--tw-shadow-color);
    }

    .sparkles-table-stack td {
        padding-left: 40%;
        padding-top: .5rem;
        padding-bottom: .5rem;
        border-bottom-width: 1px;
        --tw-border-opacity: 1;
        border-color: rgba(243, 244, 246, var(--tw-border-opacity, 1));
        position: relative;
    }

    .sparkles-table-stack td:before {
        content: attr(data-label);
        width: 35%;
        position: absolute;
        left: 0;
        padding-right: .75rem;
        white-space: nowrap;
        font-weight: 500;
        color: var(--gray-600);
        font-size: .875rem;
        line-height: 1.25rem;
    }

    .sparkles-table-stack td:last-child {
        border-bottom-width: 0;
    }
}

/* ========== ACCESSIBILITY ========== */
.sparkles-table-sortable:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--color-primary), 0 0 0 4px rgb(var(--color-primary-rgb)/.1);
}

.sparkles-table-action-btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--color-primary), 0 0 0 4px rgb(var(--color-primary-rgb)/.1);
}

/* Reduced motion support - inherits from sparkles-utilities.css */
@media (prefers-reduced-motion: reduce) {
    .sparkles-table-loading::after {
        animation: none;
    }
}

/* ========== DYNAMIC TABLE CONTROLS ========== */
.sparkles-table-controls,
.sparkles-admin-card-header,
.sparkles-pagination {
    display: flex;
    align-items: center;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
    padding-top: 1rem;
    padding-bottom: 1rem;
    background-color: var(--gray-50);
    border-color: var(--gray-200);
}

.sparkles-table-controls {
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: space-between;
    border-bottom-width: 1px;
}

.sparkles-table-search {
    position: relative;
    flex: 1 1 0%;
    max-width: 24rem;
}

.sparkles-table-search-input {
    border-width: 1px;
    border-color: var(--gray-300);
    border-radius: var(--radius-btn);
    padding-left: .75rem;
    padding-top: .5rem;
    padding-bottom: .5rem;
    padding-right: 2.5rem;
    font-size: .875rem;
    line-height: 1.25rem;
}

.sparkles-table-search-input:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--color-primary), 0 0 0 4px rgb(var(--color-primary-rgb)/.1);
}

.sparkles-table-search-clear {
    position: absolute;
    right: .75rem;
    width: 1.25rem;
    height: 1.25rem;
    background-color: initial;
    border-width: 0;
    cursor: pointer;
    opacity: 0;
    transition-property: all;
    transition-timing-function: cubic-bezier(0, 0, .2, 1);
    transition-duration: .15s;
}

.sparkles-table-search-input:not(:placeholder-shown)+.sparkles-table-search-clear {
    opacity: 1;
}

/* ========== PAGINATION ========== */
.sparkles-pagination {
    gap: .5rem;
    border-top-width: 1px;
    justify-content: center;
}

.sparkles-social-share-label,
.sparkles-social-proof-meta,
.sparkles-rating-label,
.sparkles-rating-percent,
.sparkles-testimonial-role,
.sparkles-notification-message,
.sparkles-loading-description,
.sparkles-comment-date,
.sparkles-cart-item-meta,
.sparkles-pagination-info {
    font-size: .875rem;
    line-height: 1.25rem;
    color: var(--gray-600);
}

.sparkles-pagination-info {
    margin-right: 1rem;
}

.sparkles-pagination-button,
.sparkles-pagination-link {
    min-width: 40px;
    display: inline-flex;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 2.5rem;
    padding-left: .75rem;
    padding-right: .75rem;
    font-size: .875rem;
    line-height: 1.25rem;
    border-color: var(--gray-300);
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
    color: var(--gray-700);
    -webkit-text-decoration-line: none;
    text-decoration-line: none;
    transition-property: all;
    transition-timing-function: cubic-bezier(0, 0, .2, 1);
    transition-duration: .3s;
}

.sparkles-pagination-button {
    border-width: 1px;
    border-radius: var(--radius-sm);
}

.sparkles-pagination-button:hover:not(:disabled) {
    background-color: var(--gray-100);
    border-color: var(--gray-400);
}

.sparkles-pagination-button:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.sparkles-pagination-ellipsis {
    padding-left: .5rem;
    padding-right: .5rem;
    color: var(--gray-500);
}

/* ========== BULK ACTIONS ========== */
.sparkles-table-bulk-actions {
    background-color: var(--color-accent);
    animation: slideDown 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: .75rem;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
    padding-top: .75rem;
    padding-bottom: .75rem;
    border-bottom-width: 1px;
    border-color: var(--gray-200);
}

.sparkles-bulk-actions-buttons {
    display: flex;
    gap: .5rem;
    margin-left: auto;
}

/* ========== EXPORT CONTROLS ========== */
.sparkles-table-export {
    position: relative;
}

.sparkles-table-export-button {
    padding-top: .25rem;
    padding-bottom: .25rem;
    background-color: var(--gray-100);
    transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, -webkit-text-decoration-color;
}

.sparkles-table-export-button:hover {
    background-color: var(--gray-200);
    border-color: var(--gray-400);
}

.sparkles-table-export-menu {
    min-width: 150px;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: .5rem;
    --tw-bg-opacity: 1;
    background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
    border-width: 1px;
    border-color: var(--gray-200);
    border-radius: var(--radius-btn);
    --tw-shadow: 0 10px 15px -3px #0000001a, 0 4px 6px -4px #0000001a;
    --tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);
    z-index: var(--z-dropdown);
}

.sparkles-table-export-option,
.sparkles-dropdown-option {
    display: flex;
    align-items: center;
    border-width: 0;
    background-color: initial;
    color: var(--gray-700);
    cursor: pointer;
    transition-property: all;
    transition-timing-function: cubic-bezier(0, 0, .2, 1);
    transition-duration: .15s;
    text-align: left;
    width: 100%;
}

.sparkles-btn-sm,
.sparkles-table-export-option {
    padding-left: 1rem;
    padding-right: 1rem;
    padding-top: .5rem;
    padding-bottom: .5rem;
    font-size: .875rem;
    line-height: 1.25rem;
}

.sparkles-table-export-option {
    gap: .5rem;
}

.sparkles-table-export-option:hover {
    color: var(--color-primary);
    background-color: var(--gray-50);
}

/* ========== FILTERS ========== */
.sparkles-table-filters {
    display: flex;
    gap: .5rem;
}

.sparkles-table-filter {
    position: relative;
}

.sparkles-table-filter-button {
    padding-top: .5rem;
    padding-bottom: .5rem;
    transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, -webkit-text-decoration-color;
}

.sparkles-table-filter-button:hover {
    background-color: var(--gray-100);
    border-color: var(--gray-400);
}

/* ========== CONSOLIDATED RESPONSIVE DESIGN ========== */
@container (max-width: 768px) {

    /* Base table responsive behavior */
    .sparkles-table-responsive {
        min-width: 500px;
    }

    .sparkles-table-actions {
        flex-direction: column;
        gap: .25rem;
    }

    .sparkles-table-action-btn {
        width: 100%;
        justify-content: center;
    }

    .sparkles-table-footer {
        flex-direction: column;
        gap: .5rem;
        text-align: center;
    }

    /* Table controls and search */
    .sparkles-table-search {
        max-width: none;
        width: 100%;
        order: -9999;
    }

    /* Pagination adjustments */
    .sparkles-pagination {
        flex-wrap: wrap;
    }

    .sparkles-pagination-info {
        width: 100%;
        text-align: center;
        margin-bottom: .5rem;
    }
}

/* ========== PRINT STYLES ========== */
@media print {
    .sparkles-table-container {
        overflow: visible;
        --tw-shadow: 0 0 #0000;
        --tw-shadow-colored: 0 0 #0000;
    }

    .sparkles-table {
        border-collapse: collapse;
    }

    .sparkles-table th,
    .sparkles-table td {
        border-width: 1px;
        padding: .5rem;
    }

    .sparkles-table-actions,
    .sparkles-table-action-btn {
        display: none;
    }

    .sparkles-status-badge {
        border-width: 1px;
        border-style: solid;
        --tw-bg-opacity: 1;
        background-color: rgba(255, 255, 255, var(--tw-bg-opacity, 1));
    }
}
