﻿/* ==========================================================================
   1. STICKY WORKSPACE HEADER (Toolbar + Editing File Title)
 */
.st-table-workspace {
    position: sticky;
    top: var(--nav-height, 0px);
    z-index: 1030;
    overflow: hidden !important;
    contain: layout size !important;
    height: 85vh !important; /* calc(100vh - var(--header-height, 120px)- var(--workspace-header-height, 68px)) !important; */
    max-height: 85vh !important; /* calc(100vh - var(--header-height, 120px)- var(--workspace-header-height, 68px)) !important;  */
    min-height: 0;
    display: flex;
    flex-direction: column;
}

    .st-table-workspace .card {
        border: none;
        background: transparent;
        margin-bottom: 0;
    }

    .st-table-workspace > .pb-3 {
        flex: 0 0 auto;
    }

#grid-container {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#st-grid-scroll.st-table-wrapper {
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    background-color: #ffffff;
    flex: 1 1 auto;
    height: auto;
    max-height: 100%;
    overflow: auto;
}


/* ==========================================================================
   2. TABLE CONTAINER & INTERNAL STICKY HEADERS
   ========================================================================== */
/* ==========================================================================
   2. TABLE VIEWPORT — only this element scrolls
   ========================================================================== */

    /* Base Table Typography & Sizing */
    .st-table-wrapper table.st-table {
        margin-bottom: 0;
        width: 100%;
        border-collapse: separate;
        border-spacing: 0;
        font-size: var(--st-font-size, 0.8125rem);
    }

        .st-table-wrapper table.st-table th,
        .st-table-wrapper table.st-table td {
            padding: var(--st-cell-padding-y) var(--st-cell-padding-x);
            font-size: inherit;
            vertical-align: middle;
            white-space: nowrap;
        }

        /* Sticky Column Headers (Pins inside the table wrapper) */
        .st-table-wrapper table.st-table thead th {
            position: sticky;
            top: 0;
            z-index: 20;
            background-color: #f8f9fa !important;
            border-bottom: 2px solid #dee2e6;
            font-weight: 600;
        }

            /* Header Sticky Columns (Top Left Intersection) */
            .st-table-wrapper table.st-table thead th.st-sticky-col {
                position: sticky;
                top: 0;
                z-index: 25;
                background-color: #f8f9fa !important;
                color: #212529;
            }

        /* Body Sticky Columns (Frozen Left) */
        .st-table-wrapper table.st-table tbody td.st-sticky-col {
            position: sticky;
            z-index: 10;
            background-color: #ffffff !important;
        }

        /* Preserve Alternating Striped Rows on Sticky Cells */
        .st-table-wrapper table.st-table.table-striped tbody tr:nth-of-type(odd) td.st-sticky-col {
            background-color: #f2f2f2 !important;
        }

        /* Preserve Hover Effect on Sticky Cells */
        .st-table-wrapper table.st-table tbody tr:hover td.st-sticky-col {
            background-color: #eceff1 !important;
        }


    /* ==========================================================================
   4. CUSTOM FORM CONTROLS (Dense Inputs)
   ========================================================================== */
    .st-table-wrapper .st-form-control {
        display: block;
        width: 100%;
        height: var(--st-input-height, 1.85rem);
        min-height: var(--st-input-height, 1.85rem);
        padding: var(--st-input-padding-y, 0.15rem) var(--st-input-padding-x, 0.4rem);
        font-size: var(--st-font-size, 0.8125rem);
        font-weight: 400;
        line-height: 1.2;
        color: #212529;
        background-color: #fff;
        background-clip: padding-box;
        border: 1px solid #ced4da;
        border-radius: 0.25rem;
        transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    }

        .st-table-wrapper .st-form-control:focus {
            color: #212529;
            background-color: #fff;
            border-color: #86b7fe;
            outline: 0;
            box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
        }

        .st-table-wrapper .st-form-control:read-only,
        .st-table-wrapper .st-form-control:disabled {
            background-color: #e9ecef;
            opacity: 1;
            border-color: transparent;
        }


    /* ==========================================================================
   5. DENSITY MODIFIER PRESETS
   ========================================================================== */
    .st-table-wrapper.st-density-compact {
        --st-input-height: 1.55rem;
        --st-input-padding-y: 0.05rem;
        --st-input-padding-x: 0.25rem;
        --st-cell-padding-y: 0.1rem;
        --st-cell-padding-x: 0.35rem;
    }

    .st-table-wrapper.st-density-spacious {
        --st-input-height: 2.25rem;
        --st-input-padding-y: 0.35rem;
        --st-input-padding-x: 0.6rem;
        --st-cell-padding-y: 0.5rem;
        --st-cell-padding-x: 0.75rem;
    }

/* --- 1. Scroll Container Physics --- */

.table-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 65vh; /* Prevents the table from growing past the viewport */
    border: 2px solid #212529; /* Brutalist heavy outer border */
    position: relative;
    box-sizing: border-box;
    background-color: #fff;
}

    /* --- 2. Table Layout Engine --- */
    .table-scroll table {
        table-layout: fixed; /* Forces the browser to respect your C# width/min-width */
        width: max-content; /* Allows the table to stretch beyond the container to trigger scroll */
        border-collapse: separate !important; /* REQUIRED for sticky headers/columns to work */
        border-spacing: 0;
        margin-bottom: 0;
    }

    /* --- 3. Base Cell Styling --- */
    .table-scroll th,
    .table-scroll td {
        padding: 0; /* Padding is handled inside the cell contents */
        border-bottom: 1px solid #dee2e6;
        border-right: 1px solid #dee2e6;
        font-size: var(--st-font-size, 0.8125rem) !important;
        vertical-align: middle;
        text-align: center;
        white-space: nowrap !important;
        overflow: hidden;
        height: 2.5rem; /* Base row height */
    }

    /* --- 4. Sticky Header (Top) --- */
    .table-scroll thead th {
        position: sticky;
        top: 0;
        z-index: 20; /* High z-index so it floats above normal rows */
        background-color: #212529;
        color: #fff;
        white-space: normal !important;
        text-align: center;
        line-height: 1.2;
        padding: 0.5rem 0.25rem;
        border-bottom: 2px solid #000; /* Distinct separation from data */
    }

        /* Ensure intersection of Sticky Header + Sticky Column stays on top */
        .table-scroll thead th[style*="position: sticky"] {
            z-index: 22 !important;
        }

    .table-scroll td {
        text-overflow: ellipsis;
    }

    /* --- 5. Global Input Resets (Edge-to-Edge) --- */
    .table-scroll tbody td .form-control-sm,
    .table-scroll tbody td .form-select-sm,
    .table-scroll tbody td .notes-input {
        width: 100%;
        height: 100%;
        min-height: 2.25rem;
        padding: 2px 6px;
        margin: 0;
        /*font-size: var(--st-font-size, 0.7125rem) !important;*/
        text-align: center;
        border: none !important;
        border-radius: 0 !important;
        background-color: transparent; /* Lets row highlight show through */
        box-shadow: none !important; /* Removes Bootstrap focus rings inside the table */
    }
    /* --- 6. Row Interactions --- */
    .table-scroll tbody tr:nth-child(even) {
        background-color: #f8fafc;
    }

    .table-scroll tbody tr:hover {
        background-color: #e2e8f0 !important;
    }
    /* Brutalist Selected Row Highlight */
    .table-scroll tr.selected-row td {
        background-color: #fffbeb !important;
        border-top: 2px solid #000 !important;
        border-bottom: 2px solid #000 !important;
    }

        .table-scroll tr.selected-row td[style*="position: sticky"] {
            background-color: #fef3c7 !important; /* Slightly darker for sticky area contrast */
        }
    /* --- 7. Alignment Overrides & Dynamic Padding --- */
    /* Left-justified cells & headers with 1.5rem offset */
    .table-scroll th.table-text-start,
    .table-scroll td.table-text-start {
        text-align: left !important;
        padding-left: 1.5rem !important;
        padding-right: 0.75rem !important;
    }
    /* Left-align inputs inside table-text-start cells and align with the text offset */
    .table-scroll tbody td.table-text-start .form-control-sm,
    .table-scroll tbody td.table-text-start .form-select-sm,
    .table-scroll tbody td.table-text-start .notes-input,
    .table-scroll tbody td .form-control-sm.table-text-start {
        text-align: left !important;
        padding-left: 1.5rem !important;
    }
    /* Center-aligned utility fallback */
    .table-scroll th.table-text-center,
    .table-scroll td.table-text-center {
        text-align: center !important;
    }
    /* Font size utility modifiers */
    .table-scroll .font-xs {
        font-size: 0.725rem !important;
    }
    /* ~11.5px */
    .table-scroll .font-sm {
        font-size: 0.8125rem !important;
    }
    /* ~13px */
    .table-scroll .font-md {
        font-size: 0.875rem !important;
    }
/* ~14px */
