/**
 * Esyasoft Unified Utility Cloud (UUC) Table Styles
 * Aligned with Ant Design v5 Table and UUC Design Tokens
 */

:root {
    --uuc-table-font-family: var(--uuc-font-primary, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif);
    --uuc-table-header-bg: #fafafa;
    --uuc-table-header-color: rgba(0, 0, 0, 0.88);
    --uuc-table-header-sort-bg: #f5f5f5;
    --uuc-table-header-sort-active-bg: #f0f0f0;
    --uuc-table-body-bg: #ffffff;
    --uuc-table-row-hover-bg: #fafafa;
    --uuc-table-row-selected-bg: #e6f4ff;
    --uuc-table-row-selected-hover-bg: #bae0ff;
    --uuc-table-border-color: #f0f0f0;
    --uuc-table-text-color: #1f2937;
    --uuc-table-text-secondary: #6b7280;
    --uuc-table-primary-color: var(--uuc-color-primary, #1677ff);
}

/* =========================================
   1. Root Table Wrapper
   ========================================= */
.uuc-table-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    font-family: var(--uuc-table-font-family);
    color: var(--uuc-table-text-color);
    box-sizing: border-box;
}

.uuc-table-wrapper *,
.uuc-table-wrapper *::before,
.uuc-table-wrapper *::after {
    box-sizing: border-box;
}

/* =========================================
   2. Table Toolbar
   ========================================= */
.uuc-table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 0;
    flex-wrap: wrap;
}

.uuc-table-toolbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    min-width: 250px;
}

.uuc-table-title-group {
    display: flex;
    flex-direction: column;
}

.uuc-table-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--uuc-table-text-color);
}

.uuc-table-subtitle {
    font-size: 12px;
    color: var(--uuc-table-text-secondary);
}

.uuc-table-search {
    position: relative;
    display: inline-flex;
    align-items: center;
    min-width: 260px;
    max-width: 380px;
    width: 100%;
}

.uuc-table-search-icon {
    position: absolute;
    left: 10px;
    color: #9ca3af;
    font-size: 13px;
    pointer-events: none;
}

.uuc-table-search-input {
    width: 100%;
    height: 34px;
    padding: 4px 32px 4px 30px;
    font-size: 13px;
    color: var(--uuc-table-text-color);
    background-color: #ffffff;
    border: 1px solid #d9d9d9;
    border-radius: 6px;
    outline: none;
    transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.uuc-table-search-input:hover {
    border-color: var(--uuc-color-primary-hover, #4096ff);
}

.uuc-table-search-input:focus {
    border-color: var(--uuc-table-primary-color);
    box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.15);
}

.uuc-table-search-clear {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 14px;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    transition: color 0.15s;
}

.uuc-table-search-clear:hover {
    color: #4b5563;
}

.uuc-table-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Toolbar Buttons */
.uuc-table-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    white-space: nowrap;
}

.uuc-table-btn-outline {
    background: #ffffff;
    color: #374151;
    border: 1px solid #d9d9d9;
}

.uuc-table-btn-outline:hover {
    color: var(--uuc-table-primary-color);
    border-color: var(--uuc-table-primary-color);
}

.uuc-table-btn-primary {
    background: var(--uuc-table-primary-color);
    color: #ffffff;
    border: 1px solid var(--uuc-table-primary-color);
}

.uuc-table-btn-primary:hover {
    background: var(--uuc-color-primary-hover, #4096ff);
    border-color: var(--uuc-color-primary-hover, #4096ff);
}

/* =========================================
   3. Table Container & Element
   ========================================= */
.uuc-table-container {
    position: relative;
    border: 1px solid var(--uuc-table-border-color);
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
}

/* The one scrolling box: sideways when the table is wider than the container,
   and vertically when ScrollY sets a max-height on it. */
.uuc-table-content {
    width: 100%;
    overflow: auto;
}

.uuc-table {
    width: 100%;
    text-align: left;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

/* Header */
.uuc-table-thead > tr > th {
    position: relative;
    background: var(--uuc-table-header-bg);
    color: var(--uuc-table-header-color);
    font-weight: 600;
    border-bottom: 1px solid var(--uuc-table-border-color);
    padding: 12px 14px;
    transition: background 0.2s;
    user-select: none;
}

.uuc-table-thead > tr > th.uuc-table-cell-sortable {
    cursor: pointer;
}

.uuc-table-thead > tr > th.uuc-table-cell-sortable:hover {
    background: var(--uuc-table-header-sort-bg);
}

.uuc-table-thead > tr > th.uuc-table-cell-sorted {
    background: var(--uuc-table-header-sort-active-bg);
}

.uuc-table-header-content {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.uuc-table-header-title {
    flex: 1;
}

.uuc-table-sort-trigger {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
}

.uuc-sort-neutral {
    color: #bfbfbf;
}

.uuc-sort-active {
    color: var(--uuc-table-primary-color);
    font-weight: bold;
}

/* Body */
.uuc-table-tbody > tr > td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--uuc-table-border-color);
    color: var(--uuc-table-text-color);
    background: var(--uuc-table-body-bg);
    transition: background 0.2s;
}

.uuc-table-tbody > tr:last-child > td {
    border-bottom: none;
}

.uuc-table-hover .uuc-table-tbody > tr:hover > td {
    background: var(--uuc-table-row-hover-bg);
}

.uuc-table-tbody > tr.uuc-table-row-selected > td {
    background: var(--uuc-table-row-selected-bg);
}

.uuc-table-tbody > tr.uuc-table-row-selected:hover > td {
    background: var(--uuc-table-row-selected-hover-bg);
}

/* Striped */
.uuc-table-striped .uuc-table-tbody > tr:nth-child(even) > td {
    background: #fafbfc;
}

/* Bordered */
.uuc-table-bordered .uuc-table-thead > tr > th,
.uuc-table-bordered .uuc-table-tbody > tr > td {
    border-right: 1px solid var(--uuc-table-border-color);
}

.uuc-table-bordered .uuc-table-thead > tr > th:last-child,
.uuc-table-bordered .uuc-table-tbody > tr > td:last-child {
    border-right: none;
}

/* =========================================
   4. Density Sizes (Small, Middle, Large)
   ========================================= */
/* Small */
.uuc-table-small .uuc-table {
    font-size: 12px;
}
.uuc-table-small .uuc-table-thead > tr > th,
.uuc-table-small .uuc-table-tbody > tr > td {
    padding: 8px 10px;
}
.uuc-table-small .uuc-table-toolbar {
    padding: 8px 0;
}
.uuc-table-small .uuc-table-btn {
    height: 30px;
    padding: 0 10px;
    font-size: 12px;
}
.uuc-table-small .uuc-table-search-input {
    height: 30px;
    font-size: 12px;
}

/* Middle (Default) */
.uuc-table-middle .uuc-table {
    font-size: 13px;
}
.uuc-table-middle .uuc-table-thead > tr > th,
.uuc-table-middle .uuc-table-tbody > tr > td {
    padding: 12px 14px;
}

/* Large */
.uuc-table-large .uuc-table {
    font-size: 14px;
}
.uuc-table-large .uuc-table-thead > tr > th,
.uuc-table-large .uuc-table-tbody > tr > td {
    padding: 16px 18px;
}

/* =========================================
   5. Sticky Columns
   ========================================= */
/* Selectors include th/td so they beat the "th { position: relative }" header rule.
   The left/right offset is set inline per column (from its px Width) so several pinned
   columns sit side by side. Cell backgrounds come from the normal header/body rules. */
.uuc-table-thead > tr > th.uuc-table-cell-fixed-left,
.uuc-table-tbody > tr > td.uuc-table-cell-fixed-left {
    position: sticky;
    left: 0;
    z-index: 2;
}

.uuc-table-thead > tr > th.uuc-table-cell-fixed-right,
.uuc-table-tbody > tr > td.uuc-table-cell-fixed-right {
    position: sticky;
    right: 0;
    z-index: 2;
    box-shadow: -2px 0 6px rgba(0, 0, 0, 0.05);
}

/* ScrollY: header stays at the top of the scrolling box */
.uuc-table-scroll-y .uuc-table-thead > tr > th {
    position: sticky;
    top: 0;
    z-index: 3;
}

/* Pinned header cells sit above pinned body cells and the sticky header row */
.uuc-table-thead > tr > th.uuc-table-cell-fixed-left,
.uuc-table-thead > tr > th.uuc-table-cell-fixed-right {
    z-index: 4;
}

/* Selection Column Checkbox */
.uuc-table-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--uuc-table-primary-color);
}

/* =========================================
   6. Footer & Summary
   ========================================= */
.uuc-table-tfoot > tr > td {
    padding: 12px 14px;
    font-weight: 600;
    background: #f8fafc;
    border-top: 2px solid var(--uuc-table-border-color);
}

/* =========================================
   7. Loading Spinner & Empty State
   ========================================= */
.uuc-table-loading-mask {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.65);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(1px);
}

.uuc-table-spinner {
    display: flex;
    align-items: center;
    justify-content: center;
}

.uuc-table-empty-cell {
    padding: 40px 16px !important;
    text-align: center;
}

.uuc-table-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
}

.uuc-table-empty-icon {
    font-size: 38px;
    margin-bottom: 8px;
    opacity: 0.7;
}

.uuc-table-empty-text {
    font-size: 13px;
}

/* =========================================
   8. Ant Design Style Pagination
   ========================================= */
.uuc-table-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 4px 6px;
    font-size: 13px;
    color: var(--uuc-table-text-secondary);
    width: 100%;
    box-sizing: border-box;
    gap: 16px;
}

/* Three Flexible Placement Zones: Left, Center, Right */
.uuc-pagination-zone {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1 1 0%;
    min-width: 0;
}

.uuc-pagination-zone-left {
    justify-content: flex-start;
}

.uuc-pagination-zone-center {
    justify-content: center;
}

.uuc-pagination-zone-right {
    justify-content: flex-end;
}

.uuc-table-pagination-total {
    white-space: nowrap;
    color: var(--uuc-table-text-secondary);
    font-size: 13px;
}

.uuc-table-selected-badge {
    color: var(--uuc-table-primary-color);
    font-weight: 500;
    margin-left: 4px;
}

.uuc-table-pagination-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.uuc-pagination-btn,
.uuc-pagination-item {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 6px;
    font-size: 13px;
    font-weight: 400;
    background: #ffffff;
    border: 1px solid #d9d9d9;
    border-radius: 6px;
    color: var(--uuc-table-text-color);
    cursor: pointer;
    outline: none;
    transition: all 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.uuc-pagination-btn:hover:not(:disabled),
.uuc-pagination-item:hover {
    color: var(--uuc-table-primary-color);
    border-color: var(--uuc-table-primary-color);
}

.uuc-pagination-item.active {
    background: var(--uuc-table-primary-color);
    border-color: var(--uuc-table-primary-color);
    color: #ffffff;
    font-weight: 500;
}

.uuc-pagination-btn:disabled {
    color: #d9d9d9;
    border-color: #f0f0f0;
    cursor: not-allowed;
    background: #fafafa;
}

.uuc-pagination-ellipsis {
    padding: 0 4px;
    color: #9ca3af;
}

.uuc-table-pagesize {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.uuc-table-pagesize-select {
    height: 32px;
    min-width: 60px;
    padding: 0 8px;
    font-size: 13px;
    text-align: center;
    color: var(--uuc-table-text-color);
    background: #ffffff;
    border: 1px solid #d9d9d9;
    border-radius: 6px;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.uuc-table-pagesize-select:hover {
    border-color: var(--uuc-table-primary-color);
}

.uuc-table-pagesize-select:focus {
    border-color: var(--uuc-table-primary-color);
    box-shadow: 0 0 0 2px var(--uuc-table-primary-focus-shadow, rgba(99, 102, 241, 0.2));
}

.uuc-table-pagesize-label {
    font-size: 13px;
    color: var(--uuc-table-text-secondary);
    white-space: nowrap;
}

@media (max-width: 768px) {
    .uuc-table-pagination {
        flex-direction: column;
        gap: 12px;
        align-items: center;
    }
    .uuc-pagination-zone {
        justify-content: center !important;
        flex: none;
        width: 100%;
    }
}

/* =========================================
   9. Column Customizer Modal
   ========================================= */
.uuc-table-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1050;
    animation: uucTableModalFadeIn 0.2s ease;
}

.uuc-customizer-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 620px;
    max-width: 95vw;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    z-index: 1060;
    display: flex;
    flex-direction: column;
    animation: uucTableModalScaleIn 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
}

@keyframes uucTableModalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes uucTableModalScaleIn {
    from {
        opacity: 0;
        transform: translate(-50%, -48%) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.uuc-table-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--uuc-table-border-color);
}

.uuc-table-modal-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--uuc-table-text-color);
}

.uuc-table-modal-close {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s;
}

.uuc-table-modal-close:hover {
    color: #374151;
}

.uuc-table-modal-body {
    padding: 18px 20px;
    max-height: 65vh;
    overflow-y: auto;
}

.uuc-table-modal-hint {
    font-size: 12.5px;
    color: var(--uuc-table-text-secondary);
    margin-bottom: 14px;
}

.uuc-customizer-columns-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.uuc-customizer-box {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    background: #fafafa;
}

.uuc-customizer-box-title {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
    color: #4b5563;
}

.uuc-customizer-list {
    padding: 8px;
    max-height: 240px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.uuc-customizer-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 12.5px;
}

.uuc-customizer-item-btn {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 2px 4px;
    font-size: 13px;
    border-radius: 4px;
    transition: all 0.15s;
}

.uuc-customizer-item-btn:hover:not(:disabled) {
    background: #f3f4f6;
    color: var(--uuc-table-primary-color);
}

.uuc-customizer-item-btn:disabled {
    color: #d1d5db;
    cursor: not-allowed;
}

.uuc-btn-show {
    color: var(--uuc-table-primary-color);
}

.uuc-btn-hide:hover {
    color: #ef4444 !important;
}

.uuc-customizer-empty {
    padding: 24px 8px;
    text-align: center;
    font-size: 12px;
    color: #9ca3af;
}

.uuc-table-modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-top: 1px solid var(--uuc-table-border-color);
    background: #fafafa;
    border-radius: 0 0 10px 10px;
}

/* =========================================
   10. Row Actions, Clickable Cells, Row States
   ========================================= */
.uuc-table-actions-col {
    white-space: nowrap;
}

.uuc-table-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.uuc-table-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 28px;
    height: 28px;
    padding: 0 6px;
    font-size: 13px;
    color: var(--uuc-table-text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}

.uuc-table-action-btn:hover:not(:disabled) {
    color: var(--uuc-table-primary-color);
    background: var(--uuc-color-primary-bg, #e6f4ff);
}

.uuc-table-action-btn--danger:hover:not(:disabled) {
    color: var(--uuc-color-danger, #ef4444);
    background: var(--uuc-color-danger-bg, #fef2f2);
}

.uuc-table-action-btn:disabled {
    color: #d1d5db;
    cursor: not-allowed;
}

.uuc-table-action-btn:focus-visible,
.uuc-table-cell-link:focus-visible {
    outline: 2px solid var(--uuc-table-primary-color);
    outline-offset: 1px;
}

/* A cell value that opens details (e.g. a count) */
.uuc-table-cell-link {
    padding: 0;
    font: inherit;
    color: var(--uuc-color-link, #2563eb);
    background: none;
    border: none;
    text-align: inherit;
    text-decoration: underline;
    text-decoration-color: transparent;
    text-underline-offset: 2px;
    cursor: pointer;
    transition: text-decoration-color 0.15s;
}

.uuc-table-cell-link:hover {
    text-decoration-color: currentColor;
}

/* Ready-made row/cell states for RowClass / CellClass */
.uuc-table-tbody > tr.uuc-row-danger > td { background: var(--uuc-color-danger-bg, #fef2f2); }
.uuc-table-tbody > tr.uuc-row-warning > td { background: var(--uuc-color-warning-bg, #fffbeb); }
.uuc-table-tbody > tr.uuc-row-success > td { background: var(--uuc-color-success-bg, #ecfdf5); }
.uuc-table-tbody > tr.uuc-row-muted > td { color: var(--uuc-table-text-secondary); }
.uuc-table-tbody > tr > td.uuc-cell-danger { color: var(--uuc-color-danger-active, #dc2626); font-weight: 500; }
.uuc-table-tbody > tr > td.uuc-cell-warning { color: var(--uuc-color-warning-active, #d97706); font-weight: 500; }
.uuc-table-tbody > tr > td.uuc-cell-success { color: var(--uuc-color-success-active, #059669); font-weight: 500; }

/* Numbers line up: use Class="uuc-cell-num" with Align="right" */
.uuc-table-tbody > tr > td.uuc-cell-num {
    font-variant-numeric: tabular-nums;
}

/* Long header titles wrap instead of widening the column */
.uuc-table-wrap-headers .uuc-table-thead > tr > th {
    white-space: normal;
    overflow-wrap: anywhere;
    vertical-align: bottom;
}

/* =========================================
   11. Export Menu, Load More, Load Error
   ========================================= */
.uuc-table-export {
    position: relative;
}

.uuc-table-export-caret {
    font-size: 11px;
}

.uuc-table-export-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
}

.uuc-table-export-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 21;
    min-width: 180px;
    padding: 4px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: var(--uuc-menu-popup-shadow, 0 6px 16px rgba(0, 0, 0, 0.08));
    display: flex;
    flex-direction: column;
}

.uuc-table-export-item {
    padding: 7px 10px;
    font-size: 13px;
    text-align: left;
    color: var(--uuc-table-text-color);
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.uuc-table-export-item:hover {
    background: var(--uuc-color-primary-bg, #e6f4ff);
}

.uuc-table-load-more {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 4px 0;
    font-size: 13px;
    color: var(--uuc-table-text-secondary);
}

.uuc-table-empty--error {
    gap: 8px;
    color: var(--uuc-color-danger-active, #dc2626);
}

/* Column customizer drag & drop */
.uuc-customizer-item[draggable="true"] {
    cursor: grab;
}

.uuc-customizer-item--dragging {
    opacity: 0.45;
}

.uuc-customizer-item--drop {
    border-color: var(--uuc-table-primary-color);
    box-shadow: 0 -2px 0 var(--uuc-table-primary-color);
}
