/**
 * Table Shortcode Styles
 *
 * BEM naming convention: .bf-table (block), __element, --modifier
 * Styles: default, striped, bordered, minimal, compact
 * Responsive: scroll, stack, collapse
 *
 * @since 1.1.0
 */

/* ==========================================================================
   Wrapper
   ========================================================================== */

.bf-table-wrapper {
    margin: 1.5em 0;
    font-family: inherit;
}

/* Alignment modifiers */
.bf-table-wrapper--center {
    margin-left: auto;
    margin-right: auto;
}

.bf-table-wrapper--right {
    margin-left: auto;
}

/* Caption */
.bf-table__caption {
    margin-bottom: 0.75em;
    font-size: 1.125em;
    font-weight: 600;
    color: #1f2937;
}

/* ==========================================================================
   Scroll Container
   ========================================================================== */

.bf-table__scroll-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.bf-table__scroll-container:focus {
    outline: 2px solid #0066cc;
    outline-offset: 2px;
}

.bf-table__scroll-container:focus:not(:focus-visible) {
    outline: none;
}

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

.bf-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9375em;
    line-height: 1.5;
    background: #fff;
}

/* Header cells */
.bf-table th {
    padding: 0.75em 1em;
    font-weight: 600;
    text-align: left;
    color: #1f2937;
    background: #f9fafb;
    border-bottom: 2px solid #e5e7eb;
}

/* Data cells */
.bf-table td {
    padding: 0.75em 1em;
    color: #374151;
    border-bottom: 1px solid #e5e7eb;
}

/* Last row no border */
.bf-table tbody tr:last-child td {
    border-bottom: none;
}

/* Numeric cells - right aligned */
.bf-table__cell--numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Footer cells */
.bf-table tfoot td {
    font-weight: 600;
    background: #f9fafb;
    border-top: 2px solid #e5e7eb;
    border-bottom: none;
}

/* Highlight row */
.bf-table__row--highlight {
    background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%) !important;
}

.bf-table__row--highlight td {
    font-weight: 600;
    color: #065f46;
}

/* Links in cells */
.bf-table a {
    color: #0066cc;
    text-decoration: underline;
}

.bf-table a:hover {
    text-decoration: none;
}

/* ==========================================================================
   Style: Striped
   ========================================================================== */

.bf-table-wrapper--striped .bf-table tbody tr:nth-child(odd) {
    background: #f9fafb;
}

.bf-table-wrapper--striped .bf-table tbody tr:nth-child(even) {
    background: #fff;
}

/* ==========================================================================
   Style: Bordered
   ========================================================================== */

.bf-table-wrapper--bordered .bf-table {
    border: 1px solid #e5e7eb;
}

.bf-table-wrapper--bordered .bf-table th,
.bf-table-wrapper--bordered .bf-table td {
    border: 1px solid #e5e7eb;
}

/* ==========================================================================
   Style: Minimal
   ========================================================================== */

.bf-table-wrapper--minimal .bf-table th {
    background: transparent;
    border-bottom: 1px solid #e5e7eb;
}

.bf-table-wrapper--minimal .bf-table td {
    border-bottom: 1px solid #f3f4f6;
}

.bf-table-wrapper--minimal .bf-table tfoot td {
    background: transparent;
    border-top: 1px solid #e5e7eb;
}

/* ==========================================================================
   Style: Compact
   ========================================================================== */

.bf-table-wrapper--compact .bf-table {
    font-size: 0.875em;
}

.bf-table-wrapper--compact .bf-table th,
.bf-table-wrapper--compact .bf-table td {
    padding: 0.5em 0.75em;
}

/* ==========================================================================
   Sortable Tables
   ========================================================================== */

.bf-table--sortable th {
    padding: 0;
}

.bf-table__sort-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.75em 1em;
    margin: 0;
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    gap: 0.5em;
}

.bf-table__sort-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.bf-table__sort-btn:focus {
    outline: 2px solid #0066cc;
    outline-offset: -2px;
}

.bf-table__sort-icon {
    flex-shrink: 0;
    color: #9ca3af;
    transition: opacity 0.2s;
}

/* Active sort states */
.bf-table th[aria-sort="ascending"] .bf-table__sort-icon,
.bf-table th[aria-sort="descending"] .bf-table__sort-icon {
    color: #1f2937;
}

.bf-table th[aria-sort="ascending"] .bf-table__sort-icon path:last-child,
.bf-table th[aria-sort="descending"] .bf-table__sort-icon path:first-child {
    opacity: 0.2;
}

.bf-table th[aria-sort="ascending"] .bf-table__sort-icon path:first-child,
.bf-table th[aria-sort="descending"] .bf-table__sort-icon path:last-child {
    opacity: 1;
}

/* ==========================================================================
   Responsive: Scroll (default)
   ========================================================================== */

/* Already handled by scroll container */

/* ==========================================================================
   Responsive: Stack
   ========================================================================== */

@media (max-width: 640px) {
    .bf-table-wrapper--stack .bf-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .bf-table-wrapper--stack .bf-table tbody tr {
        display: block;
        margin-bottom: 1em;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        background: #fff;
    }

    .bf-table-wrapper--stack .bf-table tbody tr:last-child {
        margin-bottom: 0;
    }

    .bf-table-wrapper--stack .bf-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.625em 1em;
        border-bottom: 1px solid #f3f4f6;
        text-align: right;
    }

    .bf-table-wrapper--stack .bf-table td:last-child {
        border-bottom: none;
    }

    .bf-table-wrapper--stack .bf-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #1f2937;
        text-align: left;
        margin-right: 1em;
    }

    .bf-table-wrapper--stack .bf-table__row--highlight {
        border-color: #10b981;
    }

    /* Numeric cells in stack mode */
    .bf-table-wrapper--stack .bf-table__cell--numeric {
        text-align: right;
    }
}

/* ==========================================================================
   Responsive: Collapse
   ========================================================================== */

@media (max-width: 640px) {
    .bf-table-wrapper--collapse .bf-table td:nth-child(n+4),
    .bf-table-wrapper--collapse .bf-table th:nth-child(n+4) {
        display: none;
    }
}

/* ==========================================================================
   Dark Mode
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .bf-table__caption {
        color: #f9fafb;
    }

    .bf-table {
        background: #1f2937;
    }

    .bf-table th {
        color: #f9fafb;
        background: #374151;
        border-color: #4b5563;
    }

    .bf-table td {
        color: #e5e7eb;
        border-color: #374151;
    }

    .bf-table tfoot td {
        background: #374151;
        border-color: #4b5563;
    }

    /* Striped */
    .bf-table-wrapper--striped .bf-table tbody tr:nth-child(odd) {
        background: #374151;
    }

    .bf-table-wrapper--striped .bf-table tbody tr:nth-child(even) {
        background: #1f2937;
    }

    /* Bordered */
    .bf-table-wrapper--bordered .bf-table {
        border-color: #4b5563;
    }

    .bf-table-wrapper--bordered .bf-table th,
    .bf-table-wrapper--bordered .bf-table td {
        border-color: #4b5563;
    }

    /* Minimal */
    .bf-table-wrapper--minimal .bf-table th {
        border-color: #4b5563;
    }

    .bf-table-wrapper--minimal .bf-table td {
        border-color: #374151;
    }

    /* Highlight */
    .bf-table__row--highlight {
        background: linear-gradient(135deg, #064e3b 0%, #065f46 100%) !important;
    }

    .bf-table__row--highlight td {
        color: #a7f3d0;
    }

    /* Sortable */
    .bf-table__sort-btn:hover {
        background: rgba(255, 255, 255, 0.05);
    }

    .bf-table__sort-icon {
        color: #6b7280;
    }

    .bf-table th[aria-sort="ascending"] .bf-table__sort-icon,
    .bf-table th[aria-sort="descending"] .bf-table__sort-icon {
        color: #f9fafb;
    }

    /* Stack mode */
    .bf-table-wrapper--stack .bf-table tbody tr {
        border-color: #4b5563;
        background: #1f2937;
    }

    .bf-table-wrapper--stack .bf-table td {
        border-color: #374151;
    }

    .bf-table-wrapper--stack .bf-table td::before {
        color: #f9fafb;
    }

    .bf-table-wrapper--stack .bf-table__row--highlight {
        border-color: #059669;
    }
}

/* ==========================================================================
   Print
   ========================================================================== */

@media print {
    .bf-table-wrapper {
        page-break-inside: avoid;
    }

    .bf-table {
        background: none !important;
        font-size: 10pt;
    }

    .bf-table th,
    .bf-table td {
        border: 1px solid #999 !important;
        background: none !important;
    }

    .bf-table th {
        background: #eee !important;
    }

    .bf-table__row--highlight {
        background: #eee !important;
    }

    .bf-table__row--highlight td {
        color: #000;
    }

    .bf-table__sort-icon {
        display: none;
    }
}
