.study-table {
    table-layout: fixed !important;
    min-width: 100% !important;
    width: max-content !important;
    margin: 0 !important;
}

.study-table:not(.eai-cols-ready) { visibility: hidden !important; }

.eai-table-scroll-wrapper {
    width: 95%;
    margin: 0 auto;
    overflow-x: auto;
    overflow-y: visible;
    scrollbar-color: #334155 transparent;
    scrollbar-width: thin;
}

.eai-table-scroll-wrapper .study-table > thead {
    position: static !important;
}
.eai-table-scroll-wrapper::-webkit-scrollbar { height: 10px; }
.eai-table-scroll-wrapper::-webkit-scrollbar-track { background: transparent; }
.eai-table-scroll-wrapper::-webkit-scrollbar-thumb { background: #334155; border-radius: 5px; }
.eai-table-scroll-wrapper::-webkit-scrollbar-thumb:hover { background: #475569; }

.study-table thead tr.study-column-titles > th:first-child,
.study-table tbody > tr > td:first-child {
    width: 43px !important;
    min-width: 43px !important;
    max-width: 43px !important;
}
.study-table thead tr.study-column-titles > th:nth-child(2),
.study-table tbody > tr > td:nth-child(2) {
    width: 68px !important;
    min-width: 68px !important;
    max-width: 68px !important;
}

.study-table [data-column="PatientName"]                   { width: 235px !important; }
.study-table [data-column="PatientID"]                     { width: 230px !important; }
.study-table [data-column="PatientBirthDate"]              { width: 220px !important; }
.study-table [data-column="PatientSex"]                    { width: 110px !important; }
.study-table [data-column="StudyDate"]                     { width: 200px !important; }
.study-table [data-column="StudyTime"]                     { width: 180px !important; }
.study-table [data-column="StudyID"]                       { width: 255px !important; }
.study-table [data-column="StudyDescription"]              { width: 285px !important; }
.study-table [data-column="AccessionNumber"]               { width: 175px !important; }
.study-table [data-column="ReferringPhysicianName"]        { width: 158px !important; }
.study-table [data-column="RequestingPhysician"]           { width: 200px !important; }
.study-table [data-column="RequestedProcedureDescription"] { width: 250px !important; }
.study-table [data-column="InstitutionName"]               { width: 245px !important; }
.study-table [data-column="modalities"]                    { width: 145px !important; }
.study-table [data-column="seriesAndInstancesCount"]       { width: 130px !important; }
.study-table [data-column="aiReport"]                      { width: 215px !important; }

.study-table [data-column="PatientBirthDate"],
.study-table [data-column="PatientSex"],
.study-table [data-column="StudyTime"],
.study-table [data-column="StudyID"],
.study-table [data-column="RequestingPhysician"],
.study-table [data-column="RequestedProcedureDescription"],
.study-table [data-column="AccessionNumber"],
.study-table [data-column="seriesAndInstancesCount"] {
    display: none;
}

/* ── Header controls: gear + clear-filters ───────────────────────────────
   Stacked vertically inside the title row's column-1 TH (the empty utility
   column next to OE2's filter-button). This aligns both controls with the
   body row's viewer-icon button column-wise.

   OE2's original clear-filter X button at column 0 is hidden; our new
   button proxies its click. */
.eai-thead-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 4px 0;
}

.eai-cols-gear,
.eai-clear-filters {
    background: rgba(15, 23, 42, .65);
    border: 1px solid #334155;
    border-radius: 6px;
    color: #94A3B8;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 0.95rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    min-height: 28px;
    transition: background .12s, color .12s, border-color .12s;
}
.eai-cols-gear:hover,
.eai-clear-filters:hover {
    background: #1E293B;
    color: #E2E8F0;
    border-color: #475569;
}
.eai-clear-filters svg { display: block; }

/* Hide OE2's native clear-filter button (we proxy to it from our own).
   Keep the TH itself in the layout so column widths don't reflow. */
.eai-original-clear-hidden > * { display: none !important; }

/* ── Column chooser popover ─────────────────────────────────────────────── */
.eai-cols-popover {
    position: absolute;
    z-index: 9000;
    min-width: 240px;
    background: #06111F;
    border: 1px solid #1E293B;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.5);
    color: #CBD5E1;
    font-size: .875rem;
    padding: 10px 0;
}
.eai-cols-popover-list { list-style: none; margin: 0; padding: 0; }
.eai-cols-popover-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    cursor: default;
}
.eai-cols-popover-row:hover { background: #0E1A2A; }
.eai-cols-popover-row.eai-dragging { opacity: .5; }
.eai-cols-handle {
    cursor: grab;
    color: #475569;
    user-select: none;
    font-size: 1rem;
}
.eai-cols-handle:active { cursor: grabbing; }
.eai-cols-popover-row input[type="checkbox"]:disabled + .eai-cols-label {
    color: #475569;
}
.eai-cols-label { flex: 1; cursor: pointer; }
.eai-cols-popover-footer {
    border-top: 1px solid #1E293B;
    margin-top: 6px;
    padding: 8px 14px 2px;
    display: flex;
    justify-content: flex-end;
}
.eai-cols-reset {
    background: none;
    border: none;
    color: #60A5FA;
    cursor: pointer;
    font-size: .82rem;
    padding: 0;
}
.eai-cols-reset:hover { color: #93C5FD; text-decoration: underline; }

/* Inline error toast for failed saves */
.eai-cols-toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 9100;
    background: #7F1D1D;
    color: #FECACA;
    border: 1px solid #B91C1C;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: .85rem;
    box-shadow: 0 4px 12px rgba(0,0,0,.4);
}

.eai-header-dragging-source { opacity: .4; }

.eai-cols-dragging,
.eai-cols-dragging * {
    cursor: grabbing !important;
    user-select: none !important;
}

.eai-drop-indicator {
    position: fixed;
    width: 4px;
    background: #3B82F6;
    border-radius: 2px;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 0 8px rgba(59, 130, 246, .8);
    transition: left .12s ease-out;
}

.study-table thead th[data-column] { position: relative; }
.eai-th-handle {
    position: absolute;
    top: 4px;
    right: 4px;
    cursor: grab;
    user-select: none;
    color: #475569;
    font-size: .75rem;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 3px;
    opacity: 0;
    transition: opacity .12s, color .12s, background .12s;
    z-index: 2;
}
.study-table thead th[data-column]:hover .eai-th-handle {
    opacity: .55;
    color: #94A3B8;
}
.eai-th-handle:hover { background: rgba(148, 163, 184, .15); color: #E2E8F0 !important; }
.eai-th-handle:active { cursor: grabbing; }

.study-table thead tr.study-table-filters.eai-thead-filter-row-hidden { display: none; }

/* ── Pagination row ─────────────────────────────────────────────────────────
   Sits below the table's scroll wrapper, full-width-95% to match. Page-size
   dropdown on the left, position indicator + page nav on the right. Hidden-
   row class is what the paginator toggles on tbody <tr>s outside the current
   page window — orthogonal to .oe-status-filter-hidden so the two filters
   compose. */
tr.eai-pagination-hidden { display: none !important; }

.eai-pagination-row {
    width: 95%;
    margin: 12px auto 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: #FFFFFF;
    font-size: 14px;
}

.eai-pagination-left,
.eai-pagination-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.eai-pagination-size-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.eai-pagination-size-select {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, .4);
    border-radius: 6px;
    color: rgba(255, 255, 255, .4);
    padding: 4px 26px 4px 10px;
    font-size: 14px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none' stroke='%23FFFFFF' stroke-opacity='0.4' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: border-color .12s;
}
.eai-pagination-size-select:hover { border-color: rgba(255, 255, 255, .7); }
.eai-pagination-size-select:focus {
    outline: none;
    border-color: var(--ao-accent, #0DE4C4);
}
.eai-pagination-size-select option { background: #1A232F; color: #FFFFFF; }

.eai-pagination-indicator { color: #FFFFFF; }

.eai-pagination-nav {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.eai-page-btn {
    background: transparent;
    border: 1px solid #FFFFFF;
    border-radius: 6px;
    color: #FFFFFF;
    cursor: pointer;
    padding: 4px 10px;
    font-size: 14px;
    line-height: 1.2;
    min-width: 32px;
    opacity: .4;
    transition: opacity .12s;
}
.eai-page-btn:hover:not(:disabled):not(.eai-page-btn-active) {
    opacity: .75;
}
.eai-page-btn:disabled {
    opacity: .2;
    cursor: not-allowed;
}
.eai-page-btn-active {
    background: transparent;
    color: #FFFFFF;
    border-color: #FFFFFF;
    opacity: 1;
    cursor: default;
}

.eai-page-ellipsis {
    color: rgba(255, 255, 255, .4);
    padding: 0 4px;
    user-select: none;
}
