/**
 * PRODEFIS Data Table Styles
 */

/* Overlay */
.dtableOverlay {
    position: fixed;
    top: var(--chart-modal-offset, 0px);
    left: 0;
    width: 100vw;
    height: calc(100vh - var(--chart-modal-offset, 0px));
    background: rgba(60, 60, 60, 0.4);
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.dtableOverlay.visible {
    opacity: 1;
}

/* Floating Window */
.dtableWindow {
    position: fixed;
    background: #fff;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
    overflow: hidden;
    font-family: 'Open Sans', Arial, sans-serif;
    font-size: 12px;
    line-height: 1.4;
    text-align: left;
}

.dtableWindow,
.dtableWindow * {
    box-sizing: border-box;
}

.dtableWindow.dtableDragging {
    user-select: none;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

.dtableWindow.dtableDragging .dtableTableWrap {
    pointer-events: none;
}

/* Window Header */
.dtableHeader {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 15px;
    background: #3c3c3c;
    color: #fff;
    position: relative;
    z-index: 1;
    cursor: move;
    touch-action: none;
    flex-shrink: 0;
}

.dtableTitle {
    font-size: 14px;
    font-weight: bold;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dtableHeaderRight {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.dtableHeaderStats {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.75);
    white-space: nowrap;
}

.dtableClose {
    font-size: 22px;
    color: #fff;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    opacity: 0.8;
}

.dtableClose:hover {
    opacity: 1;
}

/* Tabs */
.dtableTabs {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    padding: 6px 12px 0;
    background: #fff;
    border-bottom: 1px solid rgb(225, 225, 225);
    flex-shrink: 0;
    overflow-x: auto;
}

.dtableTab {
    padding: 8px 14px;
    margin: 0;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 4px 4px 0 0;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    color: rgb(120, 120, 120);
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.15s ease;
}

.dtableTab:hover {
    background: rgb(248, 248, 248);
    color: rgb(60, 60, 60);
}

.dtableTab.active {
    color: #000;
    border-bottom-color: #3c3c3c;
}

/* Table Container */
.dtableTableWrap {
    flex: 1;
    overflow: auto;
    background: rgb(245, 245, 245);
    padding: 0 12px 12px;
}

/* Data Table */
.dtableTable {
    width: 100%;
    border-collapse: separate; /* sticky header */
    border-spacing: 0;
    background: #fff;
    table-layout: auto;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.dtableTable th {
    position: sticky;
    top: 0;
    background: rgb(248, 248, 248);
    color: #000;
    font-weight: 700;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 2px solid rgb(200, 200, 200);
    z-index: 100;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sortable headers */
.dtableSortableHeader {
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
}

.dtableSortableHeader:hover {
    background: rgb(242, 242, 242);
}

.dtableSortableHeader:focus {
    outline: 2px solid rgb(100, 100, 100);
    outline-offset: -2px;
}

.dtableSortIndicator {
    color: rgb(100, 100, 100);
    font-weight: 700;
    margin-left: 4px;
}

.dtableSortIndicator.loading {
    font-size: 0;
    width: 10px;
    height: 10px;
    display: inline-block;
    vertical-align: middle;
}

.dtableSortIndicator.loading::after {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 2px solid rgb(220, 220, 220);
    border-top-color: rgb(100, 100, 100);
    border-radius: 50%;
    animation: dtableSpinnerRotate 0.6s linear infinite;
}

@keyframes dtableSpinnerRotate {
    to { transform: rotate(360deg); }
}

/* Table Cells */
.dtableTable td {
    padding: 0;
    vertical-align: top;
    background: #fff;
    border-bottom: 1px solid rgb(240, 240, 240);
    transition: background 0.1s ease;
}

.dtableTable td > div {
    padding: 8px 12px;
    font-size: 12px;
    color: rgb(50, 50, 50);
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dtableEmptyCell {
    color: #ccc;
}

/* Zebra striping */
.dtableRecordRow:nth-child(odd) td {
    background: rgb(252, 252, 252);
}

.dtableRecordRow:nth-child(even) td {
    background: #fff;
}

.dtableTable tbody tr:hover td {
    background: rgb(248, 248, 248) !important;
}

.dtableTable tbody tr.dtableRecordRow:hover td:first-child {
    box-shadow: inset 3px 0 0 rgb(150, 150, 150);
}

/* Empty State */
.dtableEmptyRow td > div {
    padding: 40px 12px;
    text-align: center;
    color: rgb(160, 160, 160);
    font-size: 12px;
}

/* Load More Row */
.dtableLoadMoreRow {
    cursor: pointer;
    transition: all 0.15s ease;
}

.dtableLoadMoreRow td {
    background: rgb(250, 250, 250) !important;
    border-top: 1px dashed rgb(200, 200, 200) !important;
    border-bottom: 1px dashed rgb(200, 200, 200) !important;
}

.dtableLoadMoreRow td > div {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    color: rgb(100, 100, 100);
    font-weight: 600;
    font-size: 11px;
}

.dtableLoadMoreRow td > div svg {
    stroke: rgb(100, 100, 100);
    transition: transform 0.2s ease;
}

.dtableLoadMoreRow:hover td {
    background: rgb(245, 245, 245) !important;
}

.dtableLoadMoreRow:hover td > div {
    color: rgb(60, 60, 60);
}

.dtableLoadMoreRow:hover td > div svg {
    transform: translateY(2px);
}

/* Center Snap Guides */
.dtableGuide {
    display: none;
    position: fixed;
    z-index: 9998;
    pointer-events: none;
    filter: drop-shadow(0 0 3px #3c3c3c);
}

.dtableGuideV {
    top: 0;
    bottom: 0;
    width: 0;
    border-left: 3px dashed #3c3c3c;
    margin-left: -1px;
}

.dtableGuideH {
    left: 0;
    right: 0;
    height: 0;
    border-top: 3px dashed #3c3c3c;
    margin-top: -1px;
}

/* Resize Handles */
.dtableResizeHandle {
    position: absolute;
    z-index: 10;
    touch-action: none;
}

.dtableResizeN  { top: -4px; left: 10px; right: 10px; height: 9px; cursor: ns-resize; }
.dtableResizeS  { bottom: -4px; left: 10px; right: 10px; height: 9px; cursor: ns-resize; }
.dtableResizeE  { right: -4px; top: 10px; bottom: 10px; width: 9px; cursor: ew-resize; }
.dtableResizeW  { left: -4px; top: 10px; bottom: 10px; width: 9px; cursor: ew-resize; }
.dtableResizeNE { top: -4px; right: -4px; width: 18px; height: 18px; cursor: nesw-resize; }
.dtableResizeNW { top: -4px; left: -4px; width: 18px; height: 18px; cursor: nwse-resize; }
.dtableResizeSE { bottom: -4px; right: -4px; width: 20px; height: 20px; cursor: nwse-resize; }
.dtableResizeSW { bottom: -4px; left: -4px; width: 18px; height: 18px; cursor: nesw-resize; }

/* edge hover feedback */
.dtableResizeN:hover, .dtableResizeS:hover,
.dtableResizeE:hover, .dtableResizeW:hover {
    background: rgba(60, 60, 60, 0.3);
    border-radius: 4px;
}

/* diagonal grip in the bottom-right corner */
.dtableResizeSE::after {
    content: '';
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 16px;
    height: 16px;
    background: repeating-linear-gradient(
        135deg,
        rgb(110, 110, 110) 0 2.5px,
        transparent 2.5px 6px
    );
    clip-path: polygon(100% 0, 100% 100%, 0 100%);
    border-bottom-right-radius: 3px;
}

.dtableResizeSE:hover::after {
    background: repeating-linear-gradient(
        135deg,
        rgb(50, 50, 50) 0 2.5px,
        transparent 2.5px 6px
    );
}

/* Overlay Button */
.dtableBtn {
    position: fixed;
    z-index: 2;
    bottom: 21px;
    right: 16px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 12px;
    margin: 0;
    background: rgb(240, 240, 240);
    border: 2px solid white;
    border-radius: 6px;
    box-shadow: 0 1px 7px rgba(0, 0, 0, 0.35);
    box-sizing: border-box;
    font-family: 'Open Sans', Arial, sans-serif;
    font-size: 12px;
    line-height: 14px;
    white-space: nowrap;
    color: #3c3c3c;
    cursor: pointer;
    transition: background 0.15s ease;
}

.dtableBtn:hover {
    background: rgb(230, 230, 230);
}

.dtableBtn svg {
    width: 14px;
    height: 14px;
    color: #3c3c3c;
    flex-shrink: 0;
}

/* Mobile & Tablet */
@media screen and (max-width: 1024px) {
    .dtableWindow {
        left: 0 !important;
        top: var(--chart-modal-offset, 0px) !important;
        width: 100vw !important;
        height: calc(100vh - var(--chart-modal-offset, 0px)) !important;
        height: calc(100dvh - var(--chart-modal-offset, 0px)) !important;
        border-radius: 0;
    }

    .dtableHeader {
        cursor: default;
    }

    .dtableResizeHandle {
        display: none;
    }
}
