/* CodeDE Table Viewer – Frontend Styles */

.cdtv-table-wrap {
    margin: 1.5em 0;
    width: 100%;
    max-width: 100%;
    /* Fallback: if inner scroll div fails, the wrap itself scrolls */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Use .cdtv-table-wrap as scope to beat theme specificity */

.cdtv-table-wrap .cdtv-table-scroll {
    width: 100%;
    display: block;
    -webkit-overflow-scrolling: touch;
}

/* ── Scroll modes – applied to BOTH wrap and inner scroll div ── */

/* Auto */
.cdtv-table-wrap.cdtv-scroll-auto,
.cdtv-table-wrap .cdtv-table-scroll.cdtv-scroll-auto {
    overflow-x: auto !important;
}
/* Always on */
.cdtv-table-wrap.cdtv-scroll-always,
.cdtv-table-wrap .cdtv-table-scroll.cdtv-scroll-always {
    overflow-x: scroll !important;
}
/* Off */
.cdtv-table-wrap.cdtv-scroll-off,
.cdtv-table-wrap .cdtv-table-scroll.cdtv-scroll-off {
    overflow-x: visible !important;
    overflow: visible !important;
}

.cdtv-table-wrap table.cdtv-table {
    border-collapse: collapse !important;
    width: auto !important;
    min-width: 100% !important;
    max-width: none !important;    /* prevent theme max-width:100% from blocking scroll */
    table-layout: auto !important;
    font-size: 14px;
    line-height: 1.5;
    background: #fff;
}

.cdtv-table-wrap table.cdtv-table thead th {
    background-color: #2271b1;
    color: #fff;
    font-weight: 600;
    text-align: left;
    padding: 10px 14px;
    border: 1px solid #dddddd;
    white-space: nowrap;
    overflow: visible !important; /* ensure filter button is not clipped */
    position: relative;           /* needed for dropdown positioning fallback */
}

.cdtv-table-wrap table.cdtv-table tbody td {
    padding: 9px 14px;
    border: 1px solid #dddddd;
    color: #333;
    vertical-align: top;
}

.cdtv-table-wrap table.cdtv-table tbody tr:nth-child(even) {
    background-color: #f7f9fc;
}

.cdtv-table-wrap table.cdtv-table tbody tr:hover {
    background-color: #eaf3fb;
}

/* -----------------------------------------------------------------------
   Top scrollbar mirror
   A thin div inserted ABOVE the table that mirrors the horizontal scrollbar,
   so it stays visible without needing to scroll all the way to the bottom.
   --------------------------------------------------------------------- */
/* Bottom scrollbar mirror – fixed to the viewport bottom, positioned by JS.
   Appears while the table is visible but its native scrollbar is off-screen. */
.cdtv-scroll-mirror-bottom {
    position: fixed;
    bottom: 0;
    overflow-x: auto;
    overflow-y: hidden;
    /* 20px accommodates native scrollbars on Windows (≈17px) and macOS */
    height: 20px;
    z-index: 9999;
    display: none; /* shown by JS only when table overflows and scrollbar is off-screen */
    box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.10);
}

.cdtv-scroll-spacer {
    /* Height must be > 0 for scrollbar to appear */
    height: 1px;
}

/* -----------------------------------------------------------------------
   Live Search (Pro)
   --------------------------------------------------------------------- */
.cdtv-search-wrap {
    margin-bottom: 10px;
}

.cdtv-search-input {
    width: 100%;
    max-width: 340px;
    padding: 7px 12px;
    font-size: 14px;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    box-sizing: border-box;
    outline: none;
    transition: border-color 0.15s;
}

.cdtv-search-input:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 2px rgba(34, 113, 177, 0.15);
}

/* -----------------------------------------------------------------------
   Column Sort (Pro)
   --------------------------------------------------------------------- */
.cdtv-table-wrap table.cdtv-table thead th.cdtv-sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.cdtv-table-wrap table.cdtv-table thead th.cdtv-sortable:hover {
    background-color: #1a5c96;
}

/* ── Shared badge base: sort indicator + filter button ─────────────── */
.cdtv-sort-indicator,
.cdtv-col-filter-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    margin-left: 5px;
    padding: 1px 5px 2px;
    background: rgba(255, 255, 255, 0.22);
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 3px;
    color: inherit;
    font-family: inherit;
    font-size: 9px;
    line-height: 1.2;
    user-select: none;
    -webkit-user-select: none;
}

/* Sort indicator: both direction spans — default (unsorted): equal, mid opacity */
.cdtv-sort-indicator .cdtv-si-asc,
.cdtv-sort-indicator .cdtv-si-desc {
    opacity: 0.55;
    line-height: 1;
}

/* Sorted ascending: ▲ fully visible, ▼ faded */
.cdtv-table-wrap table.cdtv-table thead th.cdtv-sorted-asc .cdtv-sort-indicator {
    background: rgba(255, 255, 255, 0.40);
    border-color: rgba(255, 255, 255, 0.85);
}
.cdtv-table-wrap table.cdtv-table thead th.cdtv-sorted-asc .cdtv-sort-indicator .cdtv-si-asc  { opacity: 1; }
.cdtv-table-wrap table.cdtv-table thead th.cdtv-sorted-asc .cdtv-sort-indicator .cdtv-si-desc { opacity: 0.25; }

/* Sorted descending: ▼ fully visible, ▲ faded */
.cdtv-table-wrap table.cdtv-table thead th.cdtv-sorted-desc .cdtv-sort-indicator {
    background: rgba(255, 255, 255, 0.40);
    border-color: rgba(255, 255, 255, 0.85);
}
.cdtv-table-wrap table.cdtv-table thead th.cdtv-sorted-desc .cdtv-sort-indicator .cdtv-si-asc  { opacity: 0.25; }
.cdtv-table-wrap table.cdtv-table thead th.cdtv-sorted-desc .cdtv-sort-indicator .cdtv-si-desc { opacity: 1; }

/* ── Sort indicator style variants ────────────────────────────────── */

/* outline: border only, transparent background */
.cdtv-table-wrap[data-sort-style="outline"] .cdtv-sort-indicator {
    background: transparent;
}
.cdtv-table-wrap[data-sort-style="outline"] table.cdtv-table thead th.cdtv-sorted-asc .cdtv-sort-indicator,
.cdtv-table-wrap[data-sort-style="outline"] table.cdtv-table thead th.cdtv-sorted-desc .cdtv-sort-indicator {
    background: rgba(255, 255, 255, 0.18);
}

/* text: plain character, no box at all */
.cdtv-table-wrap[data-sort-style="text"] .cdtv-sort-indicator {
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    margin-left: 4px;
    font-size: 11px;
    opacity: 0.75;
}
.cdtv-table-wrap[data-sort-style="text"] table.cdtv-table thead th.cdtv-sorted-asc .cdtv-sort-indicator,
.cdtv-table-wrap[data-sort-style="text"] table.cdtv-table thead th.cdtv-sorted-desc .cdtv-sort-indicator {
    opacity: 1;
}

/* none: hide the indicator entirely */
.cdtv-table-wrap[data-sort-style="none"] .cdtv-sort-indicator {
    display: none !important;
}

/* -----------------------------------------------------------------------
   Pagination
   --------------------------------------------------------------------- */
.cdtv-pagination {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 2px;
    font-size: 13px;
}

.cdtv-page-btn {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    padding: 5px 14px;
    cursor: pointer;
    font-size: 15px;
    line-height: 1.2;
    color: #333;
    transition: background 0.12s, border-color 0.12s;
}

.cdtv-page-btn:hover:not(:disabled) {
    background: #f0f6fc;
    border-color: #2271b1;
    color: #2271b1;
}

.cdtv-page-btn:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

.cdtv-page-info {
    font-size: 13px;
    color: #666;
    min-width: 80px;
    text-align: center;
}

/* -----------------------------------------------------------------------
   Column Filter Indicator (Pro)
   Rendered as <span role="button"> — a visible pill/badge so the user
   can clearly see which columns have a filter available.
   Base appearance is shared with .cdtv-sort-indicator (see above).
   --------------------------------------------------------------------- */
.cdtv-col-filter-btn {
    cursor: pointer;
    font-family: inherit;
    font-weight: normal;
    transition: background 0.12s;
}
.cdtv-col-filter-btn:hover {
    background: rgba(255, 255, 255, 0.40);
    border-color: rgba(255, 255, 255, 0.85);
}

/* Active filter: highlighted badge */
.cdtv-table-wrap table.cdtv-table thead th.cdtv-col-filter-active .cdtv-col-filter-btn {
    background: rgba(240, 180, 41, 0.35);
    border-color: #f0b429;
    color: #f0b429;
    font-weight: bold;
}

/* Filter dropdown – position: fixed is set by JS via getBoundingClientRect()
   so it escapes overflow:hidden ancestors (common in themes).              */
.cdtv-col-filter-dropdown {
    position: fixed; /* overridden inline by JS */
    z-index: 999999;
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.18);
    min-width: 200px;
    max-width: 320px;
    padding: 8px;
    display: none;
}
.cdtv-col-filter-dropdown.open { display: block; }

.cdtv-col-filter-search {
    width: 100%;
    box-sizing: border-box;
    padding: 5px 8px;
    font-size: 13px;
    border: 1px solid #c3c4c7;
    border-radius: 3px;
    margin-bottom: 6px;
}

.cdtv-col-filter-list {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid #f0f0f0;
    border-radius: 3px;
    margin-bottom: 8px;
}

.cdtv-col-filter-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 6px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cdtv-col-filter-item:hover { background: #f0f6fc; }
.cdtv-col-filter-item input { margin: 0; flex-shrink: 0; }

.cdtv-col-filter-select-all {
    border-bottom: 1px solid #e0e0e0;
    font-weight: 600;
    padding: 4px 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
.cdtv-col-filter-select-all input { margin: 0; }

.cdtv-col-filter-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.cdtv-col-filter-actions button {
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    border: 1px solid #c3c4c7;
    border-radius: 3px;
    background: #fff;
}
.cdtv-col-filter-actions .cdtv-filter-ok {
    background: #2271b1;
    color: #fff;
    border-color: #2271b1;
}

/* -----------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------- */
@media screen and (max-width: 600px) {
    .cdtv-table-wrap table.cdtv-table {
        font-size: 13px;
    }
    .cdtv-table-wrap table.cdtv-table thead th,
    .cdtv-table-wrap table.cdtv-table tbody td {
        padding: 7px 10px;
    }
}
