/* ============================================================
   EB Table Enhancements (v1 · 2026-05-18)
   Adds these to every list table on every role:
     - Contained vertical scroll (only the table scrolls,
       not the whole page) when rows exceed visible height.
     - Auto-injected search bar (client-side filtering).
     - Auto-injected pagination (15 rows per page) at bottom.
     - Multiple action buttons in a single cell laid out
       horizontally side-by-side instead of stacked.
   Driven by /static/js/eb_table_enhance.js — opt-out by
   adding `data-eb-skip-enhance="1"` on the <table>.
   ============================================================ */

/* ── Toolbar (search + filter slot) ─────────────────────────── */
.eb-table-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 10px 12px;
    border: 1px solid color-mix(in srgb, var(--eb-brand, #C84C4C) 18%, white);
    border-radius: 12px;
    background-color: #fffefc;
}

.eb-table-toolbar__search {
    position: relative;
    flex: 1 1 220px;
    min-width: 180px;
}

.eb-table-toolbar__search-icon {
    position: absolute;
    top: 50%;
    left: 10px;
    transform: translateY(-50%);
    font-size: 11px;
    color: #94a3b8;
    pointer-events: none;
}

.eb-table-toolbar__search input {
    width: 100%;
    padding: 8px 10px 8px 28px;
    font-size: 11px;
    color: #1e293b;
    background-color: #ffffff;
    border: 1px solid color-mix(in srgb, var(--eb-brand, #C84C4C) 22%, white);
    border-radius: 8px;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.eb-table-toolbar__search input:focus {
    border-color: var(--eb-brand, #C84C4C);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--eb-brand, #C84C4C) 22%, white);
}

.eb-table-toolbar__filter select {
    padding: 8px 10px;
    font-size: 11px;
    color: #1e293b;
    background-color: #ffffff;
    border: 1px solid color-mix(in srgb, var(--eb-brand, #C84C4C) 22%, white);
    border-radius: 8px;
    min-width: 140px;
}

.eb-table-toolbar__count {
    flex: 0 0 auto;
    font-size: 10px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-left: auto;
}

/* ── Vertical scroll container ──────────────────────────────── */
/* Wraps the table so only the table body scrolls, not the page. */
.eb-table-scroll {
    /* max-height tuned so ~12 rows fit; the rest scrolls inside.
       Subtracts space for header (sidebar/topbar) and pagination. */
    max-height: clamp(360px, calc(100vh - 360px), 720px);
    overflow-y: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    border: 1px solid color-mix(in srgb, var(--eb-brand, #C84C4C) 18%, white);
    background-color: #ffffff;
}

.eb-table-scroll > table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: #ffffff;
}

/* Custom scrollbar to make it discoverable. */
.eb-table-scroll::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.eb-table-scroll::-webkit-scrollbar-thumb {
    background-color: color-mix(in srgb, var(--eb-brand, #C84C4C) 35%, white);
    border-radius: 8px;
}

.eb-table-scroll::-webkit-scrollbar-track {
    background-color: transparent;
}

/* ── Pagination (always at the bottom) ──────────────────────── */
.eb-table-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 10px;
    padding: 10px 12px;
    border-top: 2px solid color-mix(in srgb, var(--eb-brand, #C84C4C) 25%, white);
    border-radius: 0 0 12px 12px;
    background-color: #fffefc;
}

.eb-table-pagination__summary {
    font-size: 10px;
    font-weight: 600;
    color: #64748b;
    letter-spacing: 0.04em;
}

.eb-table-pagination__pages {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.eb-page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--eb-brand, #C84C4C);
    background-color: #ffffff;
    border: 1px solid color-mix(in srgb, var(--eb-brand, #C84C4C) 28%, white);
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.eb-page-btn:hover:not(:disabled):not(.eb-page-btn--active) {
    background-color: color-mix(in srgb, var(--eb-brand, #C84C4C) 8%, white);
}

.eb-page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.eb-page-btn--active {
    background-color: var(--eb-brand, #C84C4C);
    color: #ffffff;
    border-color: var(--eb-brand, #C84C4C);
    cursor: default;
}

.eb-page-ellipsis {
    padding: 0 4px;
    font-size: 11px;
    color: #94a3b8;
}

/* Fallback for screen-reader-only text inside our pagination buttons.
   Tailwind already ships an `.sr-only` utility, but we redefine it here
   so the icon-only buttons have a guaranteed accessible label even if
   the Tailwind CDN finishes loading after the table JS runs. */
.eb-page-btn .sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* ── Empty state (no results from search) ───────────────────── */
.eb-table-empty {
    padding: 24px 16px;
    text-align: center;
    font-size: 11px;
    color: #64748b;
}

.eb-table-empty i {
    font-size: 22px;
    color: color-mix(in srgb, var(--eb-brand, #C84C4C) 35%, white);
    margin-bottom: 6px;
}

/* ── Action button group (multiple buttons in one cell) ─────── */
/* When a single <td> contains 2+ action <a>/<button> elements
   the JS adds .eb-actions-group to lay them out horizontally
   on a single row, wrapping only when truly out of space. */
.eb-actions-group {
    display: inline-flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.eb-actions-group > * {
    margin: 0 !important;
    flex: 0 0 auto;
}

.eb-actions-group form {
    display: inline-flex;
    margin: 0 !important;
}

/* On very small viewports allow wrapping so buttons don't push
   the row off-screen. */
@media (max-width: 540px) {
    .eb-actions-group {
        flex-wrap: wrap;
    }
}

/* ── Dark mode tweaks ───────────────────────────────────────── */
html[data-theme="dark"] .eb-table-toolbar,
html[data-theme="dark"] .eb-table-pagination {
    background-color: #111827 !important;
    border-color: rgba(148, 163, 184, 0.20) !important;
}

html[data-theme="dark"] .eb-table-toolbar__search input,
html[data-theme="dark"] .eb-table-toolbar__filter select {
    background-color: #0f172a !important;
    color: #e5e7eb !important;
    border-color: rgba(148, 163, 184, 0.25) !important;
}

html[data-theme="dark"] .eb-table-scroll {
    background-color: #111827 !important;
    border-color: rgba(148, 163, 184, 0.20) !important;
}

html[data-theme="dark"] .eb-table-scroll > table thead th {
    background-color: #0f172a !important;
}

html[data-theme="dark"] .eb-page-btn {
    background-color: #0f172a;
    color: #f1f5f9;
    border-color: rgba(148, 163, 184, 0.28);
}

html[data-theme="dark"] .eb-page-btn--active {
    background-color: var(--eb-brand, #C84C4C);
    color: #ffffff;
}
