/**
 * Spreadsheet Display Styles
 *
 * Provides styling for table/spreadsheet displays with support for:
 * - Multiple border styles (default, bordered, minimal, rounded)
 * - Header styling themes (default, dark, primary, gradient)
 * - Row striping and hover effects
 * - Cell-level and row-level selection
 * - Responsive scrolling
 */

/* ==========================================================================
   Container Styles
   ========================================================================== */

.spreadsheet-display {
    position: relative;
    border-radius: var(--radius, 0.5rem);
    background-color: var(--card, #ffffff);
    overflow: auto;
}

/* ==========================================================================
   Base Table Styles
   ========================================================================== */

.spreadsheet-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    line-height: 1.5;
    background-color: var(--card, #ffffff);
}

.spreadsheet-table th,
.spreadsheet-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    vertical-align: middle;
}

/* Default border style */
.spreadsheet-table {
    border: 1px solid var(--border, #e4e4e7);
}

.spreadsheet-table th {
    border-bottom: 2px solid var(--border, #e4e4e7);
}

.spreadsheet-table td {
    border-bottom: 1px solid var(--border, #e4e4e7);
}

/* ==========================================================================
   Border Style Variants
   ========================================================================== */

/* Bordered - all cells have visible borders */
.spreadsheet-table.border-bordered {
    border: 1px solid var(--border, #e4e4e7);
}

.spreadsheet-table.border-bordered th,
.spreadsheet-table.border-bordered td {
    border: 1px solid var(--border, #e4e4e7);
}

/* Minimal - only horizontal lines */
.spreadsheet-table.border-minimal {
    border: none;
}

.spreadsheet-table.border-minimal th {
    border: none;
    border-bottom: 2px solid var(--border, #e4e4e7);
}

.spreadsheet-table.border-minimal td {
    border: none;
    border-bottom: 1px solid var(--border, #e4e4e7);
}

.spreadsheet-table.border-minimal tbody tr:last-child td {
    border-bottom: none;
}

/* Rounded - rounded corners with border */
.spreadsheet-display.border-rounded {
    border: 1px solid var(--border, #e4e4e7);
    border-radius: var(--radius, 0.5rem);
    overflow: hidden;
}

.spreadsheet-table.border-rounded {
    border: none;
    border-radius: 0;
}

.spreadsheet-table.border-rounded th,
.spreadsheet-table.border-rounded td {
    border-bottom: 1px solid var(--border, #e4e4e7);
}

.spreadsheet-table.border-rounded tbody tr:last-child td {
    border-bottom: none;
}

/* None - no borders */
.spreadsheet-table.border-none,
.spreadsheet-table.border-none th,
.spreadsheet-table.border-none td {
    border: none;
}

.spreadsheet-table.border-none th {
    border-bottom: 1px solid var(--border, #e4e4e7);
}

/* ==========================================================================
   Header Style Variants
   ========================================================================== */

/* Default header style */
.spreadsheet-table thead th {
    font-weight: 600;
    color: var(--foreground, #09090b);
    background-color: var(--muted, #f4f4f5);
    text-transform: none;
    letter-spacing: normal;
}

/* Dark header */
.spreadsheet-table.header-dark thead th {
    background-color: var(--dark-color, #09090b);
    color: var(--light-color, #fafafa);
    border-color: var(--dark-color, #09090b);
}

/* Primary header */
.spreadsheet-table.header-primary thead th {
    background-color: var(--primary, #6e56cf);
    color: var(--primary-foreground, #ffffff);
    border-color: var(--primary, #6e56cf);
}

/* Gradient header */
.spreadsheet-table.header-gradient thead th {
    background: linear-gradient(135deg, var(--primary, #6e56cf) 0%, var(--accent-color, #a18fff) 100%);
    color: var(--primary-foreground, #ffffff);
    border-color: var(--primary, #6e56cf);
}

/* Light header */
.spreadsheet-table.header-light thead th {
    background-color: var(--light-bg, #f5f7fb);
    color: var(--foreground, #09090b);
}

/* Transparent header */
.spreadsheet-table.header-transparent thead th {
    background-color: transparent;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    color: var(--muted-foreground, #71717a);
}

/* ==========================================================================
   Row Striping
   ========================================================================== */

.spreadsheet-table.table-striped tbody tr:nth-child(even) {
    background-color: var(--muted, #f4f4f5);
}

/* Alternate striping pattern */
.spreadsheet-table.table-striped-odd tbody tr:nth-child(odd) {
    background-color: var(--muted, #f4f4f5);
}

/* ==========================================================================
   Hover Effects
   ========================================================================== */

.spreadsheet-table.table-hoverable tbody tr:hover {
    background-color: var(--accent, #f4f4f5);
    cursor: default;
}

/* Stronger hover for selectable tables */
.spreadsheet-table.table-selectable.table-hoverable tbody tr:hover {
    background-color: color-mix(in srgb, var(--primary, #6e56cf) 10%, transparent);
    cursor: pointer;
}

/* ==========================================================================
   Compact Mode
   ========================================================================== */

.spreadsheet-table.table-compact th,
.spreadsheet-table.table-compact td {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
}

/* ==========================================================================
   Selection Styles
   ========================================================================== */

.spreadsheet-table .select-col {
    width: 40px;
    text-align: center;
    padding: 0.5rem;
}

.spreadsheet-table .row-select {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary, #6e56cf);
}

/* Row selection highlight */
.spreadsheet-table tbody tr.row-selected {
    background-color: color-mix(in srgb, var(--primary, #6e56cf) 15%, transparent);
}

.spreadsheet-table tbody tr.row-selected:hover {
    background-color: color-mix(in srgb, var(--primary, #6e56cf) 20%, transparent);
}

/* Cell selection highlight */
.spreadsheet-table td.cell-selected {
    background-color: color-mix(in srgb, var(--primary, #6e56cf) 20%, transparent);
    outline: 2px solid var(--primary, #6e56cf);
    outline-offset: -2px;
}

.spreadsheet-table.table-selectable td.selectable-cell:hover {
    background-color: color-mix(in srgb, var(--primary, #6e56cf) 10%, transparent);
    cursor: pointer;
}

/* ==========================================================================
   Selection Summary
   ========================================================================== */

.spreadsheet-selection-summary {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    color: var(--muted-foreground, #71717a);
    background-color: var(--muted, #f4f4f5);
    border-top: 1px solid var(--border, #e4e4e7);
}

.spreadsheet-selection-summary .selected-count {
    font-weight: 600;
    color: var(--primary, #6e56cf);
}

/* ==========================================================================
   Sortable Headers
   ========================================================================== */

.spreadsheet-table th[data-sortable="true"] {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.5rem;
}

.spreadsheet-table th[data-sortable="true"]:hover {
    background-color: color-mix(in srgb, var(--primary, #6e56cf) 10%, var(--muted, #f4f4f5));
}

.spreadsheet-table th[data-sortable="true"]::after {
    content: '';
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    border: 4px solid transparent;
    border-top-color: var(--muted-foreground, #71717a);
    opacity: 0.4;
}

.spreadsheet-table th[data-sortable="true"].sort-asc::after {
    border-top-color: var(--primary, #6e56cf);
    opacity: 1;
}

.spreadsheet-table th[data-sortable="true"].sort-desc::after {
    border-top-color: transparent;
    border-bottom-color: var(--primary, #6e56cf);
    transform: translateY(-80%);
    opacity: 1;
}

/* ==========================================================================
   Span Target Mode
   ========================================================================== */

.spreadsheet-display.span-target-spreadsheet .spreadsheet-cell {
    user-select: text;
}

.spreadsheet-display.span-target-spreadsheet .spreadsheet-cell::selection {
    background-color: color-mix(in srgb, var(--primary, #6e56cf) 30%, transparent);
}

/* ==========================================================================
   Error State
   ========================================================================== */

.spreadsheet-error {
    padding: 2rem;
    text-align: center;
    color: var(--destructive, #ef4444);
    background-color: color-mix(in srgb, var(--destructive, #ef4444) 10%, transparent);
    border-radius: var(--radius, 0.5rem);
}

/* ==========================================================================
   Responsive Adjustments
   ========================================================================== */

@media (max-width: 640px) {
    .spreadsheet-table th,
    .spreadsheet-table td {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .spreadsheet-table.table-compact th,
    .spreadsheet-table.table-compact td {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
}
