/* ============================================================
   POS-STYLE BODY GRID (plain HTML <table>).
   Used by FormRenderer.razor / RenderPosStyleBodyGrid.
   Global stylesheet — no Blazor scoping so it also reaches
   inputs built by RenderTreeBuilder in RenderPosStyleBodyCell.
   ============================================================ */

/* Wrapper: keep DxGrid path (`.frm-body-grid-desktop` without .frm-body-grid-pos)
   completely unaffected. Only style when POS-style flag is on.
   Override existing scoped rule (.entry-grid-wrap.frm-grid-scroll-host {
     display: flex; overflow: hidden }) — it's higher-specificity than a plain
   .frm-body-grid-pos selector because Blazor scoping adds an [b-xxx] attr.
   Prefix `body ...` to add one tag to specificity so we win the tie-breaker. */
body .frm-page .entry-grid-wrap.frm-body-grid-pos,
body .frm-page .entry-grid-wrap.frm-body-grid-pos.frm-grid-scroll-host {
    display: block !important;
    overflow: auto !important;
    min-height: 0 !important;
}

/* Also override the paired rule that forces `.ix-form-body-grid { height:100% }`
   in case the class is ever re-added to the table. Safe for POS-style. */
body .frm-page .entry-grid-wrap.frm-body-grid-pos .ix-form-body-grid-pos {
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    flex: 0 0 auto !important;
}

/* Table itself */
.ix-form-body-grid-pos {
    border-collapse: separate !important;
    border-spacing: 0 !important;
    /* Do NOT set height — keeps rows at their own content height */
    width: max-content !important;
    table-layout: fixed !important;
    font-size: 12px !important;
    line-height: 1.2 !important;
    background: #fff !important;
}

.ix-form-body-grid-pos th,
.ix-form-body-grid-pos td {
    border: 1px solid #d8dee8 !important;
    padding: 0 !important;
    margin: 0 !important;
    text-align: left !important;
    /* top-align so cells never stretch vertically to fill an over-tall row */
    vertical-align: middle !important;
    line-height: 1.2 !important;
    box-sizing: border-box !important;
    /* Hard cap so table row height cannot balloon */
    height: 28px !important;
    max-height: 28px !important;
    min-height: 28px !important;
    min-width: 0 !important;
    overflow: hidden !important;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.ix-form-body-grid-pos thead {
    position: sticky;
    top: 0;
    z-index: 6;
}

.ix-form-body-grid-pos thead th {
    background: #f3f4f6 !important;
    padding: 4px 6px !important;
    font-weight: 700 !important;
    color: #334155 !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 6 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ix-form-body-grid-pos tbody {
    position: relative;
    z-index: 1;
}

.ix-form-body-grid-pos tbody tr {
    height: 28px !important;
    max-height: 28px !important;
}

/* Native inputs — full-cell, flat, no chrome, exactly 26 px tall. */
.ix-form-body-grid-pos input:not([type="checkbox"]):not([type="radio"]),
.ix-form-body-grid-pos select,
.ix-form-body-grid-pos .dynamic-grid-input {
    display: block !important;
    width: 100% !important;
    height: 26px !important;
    min-height: 26px !important;
    max-height: 26px !important;
    border: 0 !important;
    padding: 0 6px !important;
    margin: 0 !important;
    background: #fff !important;
    font: inherit !important;
    font-size: 12px !important;
    line-height: 26px !important;
    color: inherit !important;
    outline: none !important;
    box-sizing: border-box !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    min-width: 0 !important;
    max-width: 100% !important;
}

/* Native <select> — keep the OS chevron */
.ix-form-body-grid-pos select {
    padding-right: 18px !important;
    appearance: auto;
    -webkit-appearance: menulist;
}

.ix-form-body-grid-pos input:focus,
.ix-form-body-grid-pos select:focus {
    outline: 2px solid #0d6efd !important;
    outline-offset: -2px !important;
    background: #eff6ff !important;
}

.ix-form-body-grid-pos .dynamic-grid-number {
    text-align: right !important;
    font-variant-numeric: tabular-nums;
}

/* Checkbox: 16px, centered in cell */
.ix-form-body-grid-pos input[type="checkbox"],
.ix-form-body-grid-pos .dynamic-grid-check {
    display: block !important;
    width: 16px !important;
    height: 16px !important;
    min-height: 16px !important;
    max-height: 16px !important;
    margin: 6px auto !important;
    padding: 0 !important;
    appearance: auto;
    -webkit-appearance: checkbox;
}

/* Readonly cell — plain text, no input, non-focusable */
.ix-form-body-grid-pos .grid-cell-display {
    display: block !important;
    padding: 0 6px !important;
    margin: 0 !important;
    height: 26px !important;
    line-height: 26px !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #475569;
    background: transparent;
    box-sizing: border-box;
}

.ix-form-body-grid-pos .ix-grid-num-display {
    text-align: right !important;
    font-variant-numeric: tabular-nums;
}

.ix-form-body-grid-pos td.ix-grid-cell-readonly {
    background: #f9fafb !important;
}

/* Validation error highlight */
.ix-form-body-grid-pos .ix-field-error {
    outline: 2px solid #dc2626 !important;
    outline-offset: -2px !important;
    background: #fef2f2 !important;
}

/* Selected row highlight (kept for future — table currently doesn't set is-selected) */
.ix-form-body-grid-pos tbody tr.is-selected td {
    background: #dbeafe !important;
    color: #1d4ed8 !important;
}

    .ix-form-body-grid-pos tbody tr.is-selected td input,
    .ix-form-body-grid-pos tbody tr.is-selected td select,
    .ix-form-body-grid-pos tbody tr.is-selected td .dynamic-grid-input {
        background: transparent !important;
        color: inherit !important;
    }

/* Action column — compact icon buttons, out of tab order (tabindex=-1 in markup) */
.ix-form-body-grid-pos .ix-grid-action-cell {
    padding: 0 2px !important;
    text-align: center;
    white-space: nowrap;
}

    .ix-form-body-grid-pos .ix-grid-action-cell .ix-grid-row-actions {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        gap: 2px;
        height: 26px;
    }

    .ix-form-body-grid-pos .ix-grid-action-cell .ix-master-toolbtn {
        padding: 0 4px !important;
        min-height: 22px !important;
        height: 22px !important;
        line-height: 20px !important;
        font-size: 11px !important;
    }

    .ix-form-body-grid-pos .ix-grid-action-cell .ix-master-ico {
        width: 12px !important;
        height: 12px !important;
    }

/* SNo column */
.ix-form-body-grid-pos .ix-grid-sno-cell {
    padding: 0 6px !important;
    line-height: 26px !important;
    text-align: right;
    color: #64748b;
    font-variant-numeric: tabular-nums;
    background: #fafbfc;
}

/* Fallback DxComponent cells (dep combo / multi-select / memo / button):
   keep the editor flat and 26px inside the cell. */
.ix-form-body-grid-pos .grid-editor,
.ix-form-body-grid-pos .dxbl-text-edit,
.ix-form-body-grid-pos .dxbl-combobox,
.ix-form-body-grid-pos .dxbl-dropdown-edit,
.ix-form-body-grid-pos .dxbl-spin-edit,
.ix-form-body-grid-pos .dxbl-date-edit {
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    min-height: 26px !important;
    height: 26px !important;
    background: transparent !important;
}

    .ix-form-body-grid-pos .dxbl-text-edit input,
    .ix-form-body-grid-pos .dxbl-combobox input,
    .ix-form-body-grid-pos .dxbl-dropdown-edit input,
    .ix-form-body-grid-pos .dxbl-spin-edit input,
    .ix-form-body-grid-pos .dxbl-date-edit input {
        height: 24px !important;
        padding: 0 6px !important;
        font-size: 12px !important;
        line-height: 24px !important;
    }

/* ============================================================
   Column resize handle (drag right edge of <th> to resize)
   Persisted via SavePosGridColumnWidthAsync -> localStorage.
   ============================================================ */
.ix-form-body-grid-pos thead th {
    position: sticky !important;
    top: 0 !important;
}

.ix-form-body-grid-pos .ix-col-resize-handle {
    position: absolute;
    top: 0;
    right: -3px;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    z-index: 5;
    background: transparent;
    user-select: none;
    touch-action: none;
}

    .ix-form-body-grid-pos .ix-col-resize-handle:hover,
    .ix-form-body-grid-pos .ix-col-resize-handle.ix-resizing {
        background: rgba(59, 130, 246, 0.45);
    }

/* Suppress caption text-clipping so scrollWidth works for dblclick autofit */
.ix-form-body-grid-pos .pos-grid-col-caption {
    display: inline-block;
    max-width: calc(100% - 8px);
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

/* While dragging: force col-resize cursor everywhere + disable text selection */
body.ix-col-resizing,
body.ix-col-resizing * {
    cursor: col-resize !important;
    user-select: none !important;
}

/* ============================================================
   Column reorder (drag <th> onto another <th> to reposition)
   Persisted via MovePosGridColumnAsync -> GridLayoutState.Order.
   ============================================================ */
.ix-form-body-grid-pos thead th[draggable="true"] {
    cursor: grab;
}

    .ix-form-body-grid-pos thead th[draggable="true"]:active {
        cursor: grabbing;
    }

.ix-form-body-grid-pos thead th.ix-col-dragging {
    opacity: 0.5;
    background: #e0edff !important;
}

body.ix-col-reordering,
body.ix-col-reordering * {
    cursor: grabbing !important;
    user-select: none !important;
}

/* Blue vertical bar showing insertion point during a drag */
.ix-col-drop-marker {
    position: fixed;
    width: 2px;
    background: #2563eb;
    box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.35);
    z-index: 10000;
    pointer-events: none;
}

/* Red badge shown while dragging a header below the header row (hide gesture) */
.ix-col-hide-badge {
    position: fixed;
    z-index: 10001;
    padding: 4px 8px;
    background: #dc2626;
    color: #fff;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.2;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    pointer-events: none;
    white-space: nowrap;
}

/* ============================================================
   Header right-click context menu (Hide / Auto-fit / Chooser)
   ============================================================ */
.ix-col-context-menu {
    position: fixed;
    z-index: 10002;
    min-width: 200px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18);
    padding: 4px 0;
    font-size: 12px;
    color: #1f2937;
    user-select: none;
}

    .ix-col-context-menu .ix-col-ctx-item {
        display: block;
        width: 100%;
        padding: 6px 12px;
        text-align: left;
        background: transparent;
        border: 0;
        color: inherit;
        font-size: 12px;
        cursor: pointer;
        line-height: 1.4;
    }

        .ix-col-context-menu .ix-col-ctx-item:hover {
            background: #eff6ff;
            color: #1d4ed8;
        }

        .ix-col-context-menu .ix-col-ctx-item.danger {
            color: #b91c1c;
        }

            .ix-col-context-menu .ix-col-ctx-item.danger:hover {
                background: #fef2f2;
                color: #991b1b;
            }
