/* ==========================================================================
   Onix EditGrid — the surface of Components/Shared/Grid/EditGrid.razor: a
   form's line editor that looks like the DataGrid and is edited in place.

   It IS a .dxg (frame, header, rows, footer come from onix-datagrid.css);
   this sheet adds what editing needs:

     .edg-scroll        the table scrolls sideways in a narrow pane
     tr.edg-editing     the row being edited: its cells hold the editors
     td.edg-cell-edit   a cell with its editor in place
     .edg-handle        move up / down      .edg-command   remove
     .edg-bar           "Add a line" and its kin, under the rows

   A row keeps its height when it is entered: editors are as tall as a line
   of text plus the cell's padding. Every colour is a token.
   ========================================================================== */

.edg { margin: 0 0 8px; }

.edg-scroll {
    position: relative;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: thin;
}

/* The grid is as tall as its rows: the page scrolls, so header and footer are not pinned. */
/* Not sticky; positioned as the box its column edge (.dxg-resizer) sits in, without a layer over the pinned head. */
.edg .dxg-table thead th { position: relative; z-index: auto; }
.edg .dxg-table tfoot td { position: static; }

/* ─── Rows ─────────────────────────────────────────────────────────────── */

.edg .dxg-table thead th { padding: 0 8px; }
.edg .dxg-table tbody tr.edg-row > td {
    height: 30px;
    max-width: none;
    padding: 0 8px;
    vertical-align: middle;
}
.edg .dxg-table tbody tr.edg-row > td.wrap { padding-top: 3px; padding-bottom: 3px; }
/* A cell that runs over several columns is a cell like the others (app.css centres and pads
   every td[colspan] of a table.grid: its "nothing to show" row). */
.edg .dxg-table tbody tr.edg-row > td[colspan] {
    padding: 0 8px;
    color: inherit;
    text-align: left;
    font-style: inherit;
}
.edg .dxg-table tfoot td[colspan] { text-align: left; }

/* The figures a line comes to stay in view while the table scrolls sideways. */
.edg .dxg-table th.edg-pinned, .edg .dxg-table td.edg-pinned {
    position: sticky;
    right: 0;
    z-index: 1;
    box-shadow: inset 1px 0 0 var(--hairline);
}
.edg .dxg-table thead th.edg-pinned { z-index: 2; background: var(--dxg-head); }
.edg .dxg-table tfoot td.edg-pinned { background: var(--dxg-head); }
.edg-removable .dxg-table th.edg-pinned:not(.edg-command),
.edg-removable .dxg-table td.edg-pinned:not(.edg-command) { right: 40px; }
/* Duplicate and remove side by side: the command cell is wider, the pinned figure sits before it. */
.edg-two-tools .dxg-table th.edg-pinned:not(.edg-command),
.edg-two-tools .dxg-table td.edg-pinned:not(.edg-command) { right: 64px; }

/* A cell that waits for a value says so quietly. */
.edg-blank { color: var(--muted-2); }
.edg-needed { color: var(--warn); }

/* Section, subsection and note rows of a document. */
.edg .dxg-table tbody tr.edg-section { --dxg-row: var(--dxg-group); }
.edg .dxg-table tbody tr.edg-section > td { font-weight: 660; color: var(--ink); }
.edg .dxg-table tbody tr.edg-subsection > td { font-weight: 600; color: var(--ink-soft); }
.edg .dxg-table tbody tr.edg-note > td { font-style: italic; color: var(--muted); }
/* Rows the document made itself (tax, payment term, rounding): read, not typed. */
.edg .dxg-table tbody tr.edg-derived > td { color: var(--ink-soft); }

/* A cell that opens for typing says so before the click: the text cursor, and a frame where
   the field will be — the click lands in that cell, the row stays where it is. */
.edg .dxg-table tbody tr.edg-row.dxg-clickable > td[data-edg-editable] { cursor: text; }
@media (hover: hover) {
    .edg .dxg-table tbody tr.edg-row.dxg-clickable > td[data-edg-editable]:hover {
        box-shadow: inset 0 0 0 1px var(--line-strong);
        border-radius: 8px;
        background-color: var(--dxg-surface);
    }
}

/* ─── The row being edited ─────────────────────────────────────────────── */

.edg .dxg-table tbody tr.edg-editing,
.edg .dxg-table tbody tr.edg-editing:hover { --dxg-row: var(--dxg-selected); }
.edg .dxg-table tbody tr.edg-editing > td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
.edg .dxg-table tbody tr.edg-editing > td.edg-cell-edit {
    padding: 2px 3px;
    overflow: visible;
    white-space: normal;
    text-overflow: clip;
}

.edg .dxg-table td input:not([type=checkbox]):not([type=radio]),
.edg .dxg-table td select,
.edg .dxg-table td textarea {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    min-height: 0;
    height: 26px;
    margin: 0;
    padding: 0 6px;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    background: var(--dxg-surface);
    color: var(--ink);
    font: inherit;
    font-size: 0.86rem;
    line-height: 1.2;
    box-shadow: none;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.edg .dxg-table td textarea { height: auto; min-height: 26px; padding: 4px 6px; }
.edg .dxg-table td select { padding-right: 4px; }
.edg .dxg-table td input:hover, .edg .dxg-table td select:hover { border-color: var(--muted-2); }
.edg .dxg-table td input:focus, .edg .dxg-table td select:focus, .edg .dxg-table td textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 2px var(--ring);
}
.edg .dxg-table td.num input { text-align: right; font-variant-numeric: tabular-nums; }
/* A figure is typed: no spin buttons over its digits (Up / Down travel the rows — onix-editgrid.js). */
.edg .dxg-table td input[type=number] { -moz-appearance: textfield; appearance: textfield; }
.edg .dxg-table td input[type=number]::-webkit-outer-spin-button,
.edg .dxg-table td input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.edg .dxg-table td input.invalid, .edg .dxg-table td select.invalid { border-color: var(--danger); }

/* Several controls in one cell: two dates, the analytic editor. */
.edg-stack { display: flex; flex-direction: column; gap: 3px; }
.edg .dxg-table td .analytic-editor select { width: auto; max-width: 150px; }
.edg .dxg-table td .analytic-editor input.analytic-percent { width: 72px; }
/* A select still waiting for its value — the VAT code of a product line (REV-025) — says so like the cell it edits. */
.edg .dxg-table td select.edg-needed { border-color: var(--warn); color: var(--warn); }
.edg .dxg-table td select.edg-needed option { color: var(--ink); }

/* ─── Handle and command columns ───────────────────────────────────────── */

.edg .dxg-table th.edg-handle, .edg .dxg-table tbody tr.edg-row > td.edg-handle {
    padding: 0 0 0 6px;
    white-space: nowrap;
    text-overflow: clip;
}
.edg .dxg-table th.edg-command, .edg .dxg-table tbody tr.edg-row > td.edg-command {
    padding: 0 4px;
    text-align: center;
}
/* The column chooser (FieldChooser ForColumns) in the head of the command column: its icon alone. */
.edg .dxg-table th.edg-command .edg-chooser { padding: 2px 4px; min-height: 0; border-color: transparent; background: transparent; }
.edg .dxg-table th.edg-command .edg-chooser svg { width: 15px; height: 15px; }
.edg-icon {
    display: inline-grid;
    place-items: center;
    width: 20px; height: 22px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--muted);
    cursor: pointer;
    vertical-align: middle;
    transition: background var(--dur) var(--ease), color var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.edg-icon svg { width: 14px; height: 14px; stroke-width: 2.2; }
.edg-icon:hover:not(:disabled) { background: var(--brand-soft); color: var(--brand-strong); }
.edg-icon.danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.edg-icon:disabled { opacity: 0.25; cursor: default; }
.edg-icon:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
/* The tools of a row show with the row: a grid at rest is figures and text. */
@media (hover: hover) {
    .edg tr.edg-row:not(:hover):not(.edg-editing) .edg-icon { opacity: 0; }
    .edg tr.edg-row:not(:hover):not(.edg-editing) .edg-icon:focus-visible { opacity: 1; }
}

/* What is shown belongs to an earlier state of the form: a newer computation is on its way. */
.edg.is-stale .dxg-table { opacity: 0.6; }

/* ─── Footer and bar ───────────────────────────────────────────────────── */

.edg .dxg-table tfoot td { height: 30px; padding: 0 8px; }
.edg .dxg-table tfoot td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }

.edg-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 6px;
    padding: 4px 8px;
    background: var(--dxg-head);
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.78rem;
}
.edg-bar .edg-bar-note { margin-left: auto; }
.edg .dxg-empty { position: static; width: auto; padding: 14px 16px; }

/* ─── Small screens · print ────────────────────────────────────────────── */

@media (max-width: 760px) {
    .edg .dxg-table tbody tr.edg-row > td { padding: 0 8px; }
    /* The command column scrolls with the rows, its head with it; the pinned figure takes the edge it
       leaves (kept at its offset, it showed the cells scrolling past through the gap). */
    .edg .dxg-table td.dxg-command, .edg .dxg-table th.dxg-command { position: static; box-shadow: none; }
    .edg .dxg-table th.edg-pinned:not(.edg-command), .edg .dxg-table td.edg-pinned:not(.edg-command) { right: 0; }
}

@media print {
    .edg-handle, .edg-command, .edg-bar { display: none !important; }
    .edg-scroll { overflow: visible; }
}
