/* =============================================================================
   Reportworq client-side spreadsheet grid — POC stylesheet
   -----------------------------------------------------------------------------
   Everything here is engine chrome: the layout, the selection marquee, the
   edit box, the sheet tabs, the resize handles. The *cell* appearance (fills,
   borders, fonts, number alignment) is NOT defined here — it arrives from the
   server as a generated stylesheet (SnapshotStyleSheetModel.StylesSheetString,
   a set of ".rwd-N { ... }" rules) that the engine injects at load time. That
   is exactly how the Blazor version works today, so a real workbook looks
   identical whether Blazor or this engine renders it.
   ============================================================================= */

:root {
    --rwg-accent: #217346;          /* Excel-green selection accent (matches CellSelectionState.cs) */
    --rwg-accent-soft: rgba(33, 115, 70, 0.10);
    --rwg-grid-line: var(--rw-sheet-gridline, #d4d4d4);
    --rwg-header-bg: var(--rw-sheet-header-bg, #f6f7f8);
    --rwg-chrome-border: var(--rw-sheet-header-line, #e2e5e9);
    --rwg-font: "Segoe UI", "Calibri", system-ui, -apple-system, sans-serif;
}

.rwg-root {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    font-family: var(--rwg-font);
    font-size: 13px;
    /* RW-2909: unset and pale cell fills follow the sheet background, dark in the Dark theme, so the ink the grid's own labels
       inherit (a cell's text carries its own ink from the server's TextStyle class) follows the sheet ink there. Light is unchanged. */
    color: light-dark(#1b1b1b, var(--rw-sheet-ink, #1b1b1b));
    background: var(--rw-sheet-bg, #fff);
    user-select: none;
    outline: none;
}
/* The root also carries the shared `.datacollection-book-container` class (Blazor test parity), which the
   global data-collection SCSS gives `overflow: auto`. The inner .rwg-viewport is the real scroller, so let
   the root clip instead — otherwise the two stack into a double scrollbar. Also let the root shrink inside
   the flex row so a wide grid scrolls internally rather than pushing the sidebar off-screen. */
.rwg-host > .rwg-root { overflow: hidden; min-width: 0; }

/* GF-12 (Karen): the host itself is the FLEX ITEM inside the book+sidebar row
   (.datacollection-webview-container). A flex item's automatic minimum size is `min-width: auto`, so a wide
   print range keeps .rwg-host at its content's intrinsic width — it will NOT shrink, and the overflow spills
   onto the outer container (which has overflow:auto) as a SECOND horizontal scrollbar stacked over the inner
   .rwg-viewport's own, pushing the 400px Details sidebar out of reach. Putting min-width:0 on the CHILD
   (.rwg-root, above) is not enough — the flex item is .rwg-host. Let the host shrink so the wide grid scrolls
   internally in .rwg-viewport and the sidebar stays reachable. */
.rwg-host { min-width: 0; }

/* --- scrolling viewport that holds the table + overlays --------------------- */
.rwg-viewport {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    background: var(--rw-sheet-bg, #fff);
}

.rwg-table {
    border-collapse: separate;   /* separate so per-cell borders + sticky both behave */
    border-spacing: 0;
    table-layout: fixed;
    background: var(--rw-sheet-bg, #fff);
}

.rwg-table td,
.rwg-table th {
    box-sizing: border-box;
    padding: 1px 4px;
    overflow: hidden;
    white-space: nowrap;
    vertical-align: middle;
    background-clip: padding-box;
    /* server ".rwd-N" classes layer their own borders/fills/fonts on top of this */
}

/* RW-1120: collapse the value wrapper to its child's height so a row keeps its declared height.
   The RWGrid emits `td > span.dc-cell-value-wrapper > div`, where the value <div> (Aspose's
   GetHtmlString output) is `display:block`. Left at its default `display:inline`, the span
   establishes its own line-box AND wraps a block-level box, so the cell stacks ~two line-heights
   (a 22px row balloons to ~44px — "two lines"), inflating the whole grid ~36%.
   The Server (Blazor) engine already avoids this via `.dc-table .dc-cell .dc-cell-value-wrapper
   { display:flex }` (_data-collection.scss ~1773), but that rule requires a `.dc-cell` ancestor
   the RWGrid never emits, and reportworq-grid.css had no base wrapper rule — so the wrapper stayed
   inline here. `display:flex` makes the span a flex container that shrink-wraps its block child to
   one line-box, exactly like the Server grid. Scoped to `.rwg-table` so it can never reach the
   Server `.dc-table` path. The child combinator targets only the direct-td-child value-div wrappers
   (Text/Input/Sparkline-fallback) — the ones with the block <div> that had the doubling — and
   deliberately spares the nested List/Filter/Checkbox affordance wrappers, which never had the
   doubling and lay themselves out: .rwg-filter-cell and .rwg-list-cell are their own flex rows (value
   ellipsis plus a `flex: none` caret; the caret's `float: right` is ignored inside flex), so a broad
   descendant rule would break that ellipsis and displace the caret. */
.rwg-table td > .dc-cell-value-wrapper { display: flex; }

/* GF-11-align: a frozen-ROW cell is emitted as a <th> (reportworq-grid.js: `el(frozenRow ? "th" : "td")`)
   purely as a sticky-positioning structural element — it is NOT a semantic header. Browsers give <th> a
   User-Agent default `text-align: center`, which the base rule above does not reset, so a frozen-row cell
   whose horizontal alignment is Excel's General/default (where Aspose's GetHtmlString omits `text-align` on
   the value <div>) inherits that center. Excel left-aligns General TEXT (numbers right, via the GF-4 inline
   patch on the value div; text/bool default left) — and the Blazor engine already does (its flex `.dc-cell`
   wrapper pins the value at flex-start). Reset the th default to match a <td> so a General/default-aligned
   frozen-row cell left-aligns instead of centering (Karen/Andy: the "Fixed Costs" A1 overflow title + the
   A2 merged subtitle rendered centered on the HTML grid, left on Excel/Blazor).
   :where() keeps this at (0,0,0) specificity so it overrides ONLY the UA default: an explicit Left/Center/
   Right alignment (Aspose bakes `TEXT-ALIGN` inline onto the value <div>, e.g. the centered green header
   row) and the GF-4 General-number `text-align:right` inline patch both still win, and any future server
   `.rwd-N` alignment wins too. */
:where(.rwg-table th) { text-align: left; }

/* Default gridlines are OFF; toggle the .rwg-gridlines class on the root to show them.
   :where() keeps this at (0,0,1) specificity so a server cell border (.rwd-N, 0,1,0) always
   wins — gridlines only fill the edges the server left undefined. */
:where(.rwg-root.rwg-gridlines .rwg-table) td,
:where(.rwg-root.rwg-gridlines .rwg-table) th {
    border-right: 1px solid var(--rwg-grid-line);
    border-bottom: 1px solid var(--rwg-grid-line);
}

/* floating images / charts, anchored over the grid content */
.rwg-image {
    position: absolute;
    z-index: 5;
    max-width: none;
    pointer-events: none;
    user-select: none;
}

/* Frozen panes: rows/cols the server flagged IsFrozen become sticky.
   Z-order (canonical sticky-table stack — GF-1 freeze bleed-through fix): the top frozen-ROW
   band must sit ABOVE the left frozen-COL band, not below it. A frozen-col cell is sticky-LEFT
   but still scrolls VERTICALLY, so as the body scrolls down it slides UP into the top band's
   region and the top band has to cover it. This overlap is real whenever a frozen-row cell
   shares a column with a frozen-col cell — e.g. a title merged across the vertical freeze split:
   it is pinned frozen-row but (being merged across cols) scrolls horizontally, so its left
   portion overlaps the sticky frozen column. With frozen-col below frozen-row that scrolled
   frozen-col body cell can no longer paint THROUGH the frozen title; the corner (both) still
   tops both bands.
   Ladder (low→high): frozen-col (2) < frozen-col overflow title (3, below) < band backing
   (4, the GF-1 Option-A backdrop below) < frozen-row (5) < corner (6) < frozen-ROW overflow
   title in the band (7). The backdrop plugs the remaining GAP case — a hidden/absent frozen
   row where NO frozen-row cell exists to cover the frozen-col body cell scrolling up
   underneath. A frozen-COL overflow BODY cell (e.g. a spilling value in column A, row 18)
   stays UNDER the backdrop (3 < 4) so it can no longer bleed through the band. */
.rwg-table th.rwg-frozen-col,
.rwg-table td.rwg-frozen-col { position: sticky; z-index: 2; }
.rwg-table th.rwg-frozen-row,
.rwg-table td.rwg-frozen-row { position: sticky; z-index: 5; }
.rwg-table th.rwg-frozen-row.rwg-frozen-col,
.rwg-table td.rwg-frozen-row.rwg-frozen-col { z-index: 6; }
/* Frozen cells must be opaque so scrolled content can't bleed through them. A server
   cell fill (.rwd-N, injected later in the DOM) still wins over this default white. */
.rwg-frozen-row, .rwg-frozen-col { background: var(--rw-sheet-bg, #fff); }

/* GF-1 (Option A) — opaque sticky backing behind the ENTIRE frozen-ROW band.
   Raising the frozen-row band above the frozen-col band (z 4 > 2, above) covers a
   frozen-col body cell that scrolls up wherever a frozen-row cell OVERLAPS it — but the
   real bleed Karen sees is through a GAP in the band: a hidden/absent frozen row (or a
   frozen row whose col-A cell is transparent) leaves a strip with NO frozen-row cell to
   cover the sticky-left frozen-col body cell scrolling up underneath. One opaque backdrop
   pinned to the top band (sized to the full frozen-row-band height, spanning the grid
   width, positioned by JS translateY to follow vertical scroll) hides any body cell that
   would show through such a gap. Its z-index sits ABOVE the frozen-col cells (z2) and the
   frozen-col overflow titles (z3), and BELOW the frozen-row band's own cells (z5): the backdrop
   covers scrolled body / frozen-col / frozen-col-overflow cells but the real frozen band cells
   (z5), the frozen corner (z6) and frozen-ROW overflow titles (z7) still paint on top of it, so
   no legitimate frozen content is hidden. */
.rwg-frozen-band-backing {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 4;
    background: var(--rw-sheet-bg, #fff);
    /* NB: no `pointer-events: none` — the backdrop must be hit-testable so it is the topmost element
       returned by elementFromPoint over a band gap (a plain div, not a c_ cell), instead of the hidden
       body cell showing through. The real frozen band cells sit above it (z5+) and still take clicks. */
}

/* Light tint on every selected cell — robust under merges + frozen panes where
   a single bounding rectangle can't reach. The crisp border is drawn by the
   overlay below; this just fills the interior like Excel. */
.rwg-table td.rwg-selected,
.rwg-table th.rwg-selected { background-image: linear-gradient(var(--rwg-accent-soft), var(--rwg-accent-soft)); }

/* While drag-selecting we suppress native text selection so a drag paints a
   range instead of highlighting text (mirrors .dc-drag-selecting today). */
.rwg-root.rwg-drag-selecting,
.rwg-root.rwg-drag-selecting * { user-select: none !important; }

.rwg-input-cell { cursor: cell; }

/* Excel-style text spill into adjacent empty cells (no merge). The cell keeps its
   fixed column width but paints its text past the edge; z-index lifts it above the
   empty neighbours it spills over. How far it may paint is bounded by an inline
   `clip-path` that _applyTextOverflow sizes to the free cells (RW-2540), so the spill
   stops at the next shown value and never paints into the rows above or below. */
.rwg-table td.rwg-overflow,
.rwg-table th.rwg-overflow { overflow: visible; position: relative; z-index: 1; }
/* The spilled text paints over its empty neighbours but must never take their clicks: a click on the
   painted part lands on the empty cell under it, as in Excel (RW-2540). Clicks inside the spilling
   cell's own box still hit that cell's <td>. */
.rwg-table .rwg-overflow > .dc-cell-value-wrapper { pointer-events: none; }

/* A number too wide for its cell shows #### across the cell, as in Excel, and never spills (RW-2542).
   _applyTextOverflow puts the #### on the value wrapper (data-rwg-hash) and the class on the cell. The
   number stays in the DOM (hidden), so its text, the editor and copy still read the real value. The
   cell is the containing block of the ::after: relative here, sticky when frozen (that rule wins). */
.rwg-table td.rwg-num-overflow:not(.rwg-frozen-col):not(.rwg-frozen-row) { position: relative; }
.rwg-table .rwg-num-overflow > .dc-cell-value-wrapper { visibility: hidden; }
.rwg-table .rwg-num-overflow > .dc-cell-value-wrapper[data-rwg-hash]::after {
    content: attr(data-rwg-hash);
    visibility: visible;
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
.rwg-table td.rwg-overflow-left,
.rwg-table th.rwg-overflow-left { text-align: right; }

/* Overflow title inside a frozen band (GF-11). A title built as text spilling across
   empty cells — not a merge — clips to its own cell when its row/column is frozen:
   the base `.rwg-overflow` rule drops the cell to `position:relative; z-index:1`, but
   its spill-target neighbours are opaque frozen cells (`background:#fff`), so they cover
   the overflowing glyphs and the title looks "partially blank" (Karen's report). Keep the
   cell sticky (it must stay in the frozen band) and lift it above the opaque frozen
   neighbours it spills across so the full title paints, matching Excel/Blazor. Only frozen
   overflow cells are raised — a non-frozen body cell spilling *toward* a frozen band keeps
   z-index:1 and is still correctly covered (GF-4/TC_GRF_042).

   Split by band (GF-1): a frozen-COL overflow cell sits at z3 — above its frozen-col
   neighbours (z2) so its spill paints, but BELOW the band backing (z4). This matters because
   the SAME rule matches a frozen-col overflow BODY cell (a spilling value deep in column A,
   e.g. c_18_0 row 18): lifting it to the band-title tier let it bleed THROUGH the frozen-row
   band when scrolled up (GF-1). Keeping it under the backdrop fixes that while a genuine
   frozen-col title still clears its neighbours. A frozen-ROW overflow cell (a title that
   lives IN the top band) stays at z7, above the band + corner, so it paints fully. A cell
   that is BOTH (a corner overflow title) matches both selectors; the frozen-row rule is
   ordered LAST so it wins → z7, keeping corner titles on top. */
.rwg-table td.rwg-overflow.rwg-frozen-col,
.rwg-table th.rwg-overflow.rwg-frozen-col { position: sticky; z-index: 3; }
.rwg-table td.rwg-overflow.rwg-frozen-row,
.rwg-table th.rwg-overflow.rwg-frozen-row { position: sticky; z-index: 7; }

/* --- selection overlays (absolutely positioned inside the viewport) --------- */
.rwg-overlay-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}
.rwg-range-border {
    position: absolute;
    border: 2px solid var(--rwg-accent);
    background: transparent;
    display: none;
    box-sizing: border-box;
}
.rwg-active-border {
    position: absolute;
    border: 2px solid var(--rwg-accent);
    box-shadow: 0 0 0 1px #fff inset;
    background: transparent;
    display: none;
    box-sizing: border-box;
}
.rwg-fill-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--rwg-accent);
    border: 1px solid #fff;
    display: none;
    pointer-events: auto;
    cursor: crosshair;
    z-index: 18;   /* above resizer grab-strips (z 15) so the corner is always grabbable */
}
/* marching-ants copy marquee */
.rwg-copy-marquee {
    position: absolute;
    display: none;
    box-sizing: border-box;
    border: 2px dashed var(--rwg-accent);
    animation: rwg-march 0.6s linear infinite;
}
/* RW-2506: a pending cut reads differently from a copy (Excel keeps the marching border until the paste or Esc) */
.rwg-copy-marquee.rwg-cut { border-style: solid; border-color: var(--rwg-cut, #d9822b); animation: none; background: rgba(217, 130, 43, 0.08); }
@keyframes rwg-march { to { background-position: 12px 0, 12px 100%, 0 -12px, 100% 12px; } }

/* --- inline editor ---------------------------------------------------------- */
.rwg-editor {
    position: absolute;
    display: none;
    z-index: 20;
    box-sizing: border-box;
    border: 2px solid var(--rwg-accent);
    padding: 0 3px;
    margin: 0;
    font-family: var(--rwg-font);
    font-size: 13px;
    outline: none;
    background: var(--rw-surface-overlay);
    color: var(--rw-text-primary);
    box-shadow: 0 1px 6px rgba(0,0,0,0.18);
}

/* --- dropdown (List / Filter cells) ---------------------------------------- */
.rwg-dropdown-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 100%;
    min-height: 16px;
    float: right;
    color: var(--rw-text-secondary);
    cursor: pointer;
}
.rwg-dropdown-btn:hover { color: var(--rwg-accent); }
.rwg-popup {
    position: absolute;
    z-index: 30;
    min-width: 140px;
    max-width: 300px;   /* RW-1612: a long option wraps instead of widening the popup without limit */
    max-height: 240px;
    overflow: auto;
    background: var(--rw-surface-overlay);
    border: 1px solid var(--rw-border-default);
    border-radius: 4px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.18);
    padding: 4px;
    display: none;
    font-size: 13px;
}
.rwg-popup-item {
    display: flex;
    align-items: baseline;
    padding: 5px 10px;
    border-radius: 3px;
    cursor: pointer;
    white-space: normal;
    overflow-wrap: anywhere;
}
.rwg-popup-item:hover { background: var(--rwg-accent-soft); }
/* RW-1612: the selected option is white on the accent green. Telerik's .k-selected paints the green, so accent-coloured
   text and check read green on green. The .rwg-popup ancestor outranks the Telerik theme's .k-list-item.k-selected. */
.rwg-popup .rwg-popup-item.rwg-selected-item,
.rwg-popup .rwg-popup-item.rwg-selected-item:hover { font-weight: 600; color: #fff; background-color: var(--rwg-accent); }
.rwg-popup-check {
    display: inline-block;
    flex: none;
    width: 16px;
    color: var(--rwg-accent);
}
.rwg-popup .rwg-selected-item .rwg-popup-check { color: #fff; }
/* RW-2577: keyboard highlight of an open list or filter popup */
.rwg-popup .rwg-popup-item.rwg-popup-active { outline: 2px solid var(--rwg-accent); outline-offset: -2px; }

/* --- filter cell + multi-select popup -------------------------------------- */
.rwg-filter-cell,
.rwg-list-cell {
    display: flex;
    align-items: center;
    width: 100%;
    min-width: 0;
}
.rwg-filter-cell .rwg-cell-text,
.rwg-list-cell .rwg-cell-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
}
.rwg-filter-cell .rwg-dropdown-btn,
.rwg-list-cell .rwg-dropdown-btn { flex: none; }
/* an active (partial) filter tints the caret so it reads like the Blazor .excel-filter-drop-down-filtered marker */
.rwg-dropdown-btn.excel-filter-drop-down-filtered { color: var(--rwg-accent); font-weight: 700; }
.rwg-filter-popup { min-width: 200px; }
.rwg-filter-rows { max-height: 180px; overflow: auto; }
.rwg-filter-all { border-bottom: 1px solid var(--rw-border-subtle); margin-bottom: 4px; }
.rwg-filter-save-options {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    padding: 6px 4px 2px;
    border-top: 1px solid var(--rw-border-subtle);
    margin-top: 4px;
}
.rwg-filter-save-options .rwg-btn {
    padding: 3px 12px;
    border-radius: 4px;
    border: 1px solid var(--rw-border-default);
    background: var(--rw-surface-1);
    cursor: pointer;
    font-size: 13px;
}
.rwg-filter-save-options .rwg-filter-ok {
    background: var(--rwg-accent);
    border-color: var(--rwg-accent);
    color: #fff;
}

/* --- sparkline cell --------------------------------------------------------- */
.rwg-sparkline {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* --- cell comment editor popover -------------------------------------------- */
.rwg-comment-pop {
    position: absolute;
    z-index: 32;
    display: none;
    width: 260px;
    background: var(--rw-surface-overlay);
    border: 1px solid var(--rw-border-default);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    padding: 10px;
    font-size: 13px;
}
.rwg-comment-pop-title { font-weight: 600; margin-bottom: 6px; color: var(--rw-text-primary); }
/* Read-only committed comment history (contributor + prior approver notes), mirroring PopupCommentView. */
.rwg-comment-hist {
    max-height: 180px;
    overflow-y: auto;
    margin-bottom: 8px;
    border: 1px solid var(--rw-border-subtle);
    border-radius: 6px;
    background: var(--rw-surface-sunken);
}
.rwg-comment-hist-item { padding: 6px 8px; border-bottom: 1px solid var(--rw-border-subtle); }
.rwg-comment-hist-item:last-child { border-bottom: none; }
.rwg-comment-hist-contact { font-weight: 600; color: var(--rw-text-primary); font-size: 12.5px; }
.rwg-comment-hist-text { color: var(--rw-text-secondary); white-space: pre-wrap; word-break: break-word; margin: 2px 0; }
.rwg-comment-hist-time { color: var(--rw-text-muted); font-size: 11px; }
.rwg-comment-pop-input {
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    min-height: 54px;
    padding: 6px 8px;
    border: 1px solid var(--rw-border-default);
    border-radius: 6px;
    font-family: var(--rwg-font);
    font-size: 13px;
    outline: none;
}
.rwg-comment-pop-input:focus { border-color: var(--rwg-accent); box-shadow: 0 0 0 3px rgba(33, 115, 70, 0.16); }
.rwg-comment-pop-actions { display: flex; gap: 6px; margin-top: 8px; }
.rwg-comment-pop-actions button {
    font-family: var(--rwg-font);
    font-size: 12.5px;
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid var(--rw-border-default);
    background: var(--rw-surface-1);
    color: var(--rw-text-primary);
    cursor: pointer;
}
.rwg-comment-pop-actions .rwg-comment-save {
    background: var(--rwg-accent);
    border-color: var(--rwg-accent);
    color: #fff;
    font-weight: 600;
    margin-right: auto;
}
.rwg-comment-pop-actions button:hover { filter: brightness(0.97); }

/* --- resize handles --------------------------------------------------------- */
.rwg-col-resizer,
.rwg-row-resizer {
    position: absolute;
    z-index: 15;
    pointer-events: auto;
}
.rwg-col-resizer { top: 0; width: 6px; cursor: col-resize; }
.rwg-row-resizer { left: 0; height: 6px; cursor: row-resize; }
.rwg-col-resizer:hover,
.rwg-row-resizer:hover { background: var(--rwg-accent-soft); }
.rwg-resize-guide {
    position: absolute;
    background: var(--rwg-accent);
    display: none;
    z-index: 40;
    pointer-events: none;
}
.rwg-resize-guide.rwg-col { width: 1px; top: 0; }
.rwg-resize-guide.rwg-row { height: 1px; left: 0; }

/* --- Excel outline groups (RW-1613) ------------------------------------------
   reportworq-grid.js _layoutGroupGutters turns the content into a 2x2 grid when the sheet has row or column
   groups: corner | column band / row band | table. Each band is 20px per outline level, which is exactly the
   offset the frozen rows/columns are seeded with, so the frozen header now starts below the band instead of
   sliding over the first data row. The bands are sticky grid items of the scrolled content (no scroll
   handler): the column band holds the top, the row band holds the left, and each band's frozen part holds the
   other axis so brackets over frozen rows/columns stay with them.
   Z-order: above every table cell (frozen tiers go up to 7) so scrolled cells pass UNDER the bands, below the
   selection overlay (10), resizers (15) and editor (20). The corner covers both bands where they cross. */
.rwg-content.rwg-has-groups { display: grid; }
.rwg-col-gutter,
.rwg-row-gutter,
.rwg-group-corner {
    position: sticky;
    background: var(--rw-surface-2, #fafafa);
    box-sizing: border-box;
}
.rwg-col-gutter {
    grid-area: 1 / 2;
    top: 0;
    z-index: 8;
    display: flex;
    border-bottom: 1px solid var(--rwg-chrome-border);
}
.rwg-row-gutter {
    grid-area: 2 / 1;
    left: 0;
    z-index: 8;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--rwg-chrome-border);
}
.rwg-group-corner {
    grid-area: 1 / 1;
    top: 0;
    left: 0;
    z-index: 9;
}
.rwg-group-frozen,
.rwg-group-scrollable { position: relative; flex: 0 0 auto; }
.rwg-col-gutter .rwg-group-frozen { position: sticky; z-index: 1; background: var(--rw-surface-2, #fafafa); height: 100%; }
.rwg-row-gutter .rwg-group-frozen { position: sticky; z-index: 1; background: var(--rw-surface-2, #fafafa); width: 100%; }
.rwg-col-gutter .rwg-group-scrollable { height: 100%; }
.rwg-row-gutter .rwg-group-scrollable { flex: 1 1 auto; width: 100%; }

.rwg-group {
    position: absolute;
    display: flex;
    box-sizing: border-box;
    cursor: pointer;
}
.rwg-group.col-group { flex-direction: row; align-items: center; }
.rwg-group.row-group { flex-direction: column; align-items: center; }
/* The frozen stretch of a bracket that crosses the freeze line: clickable like the rest of the bracket (it toggles
   the same group) but not focusable; the toggle in the scrolling part is the group's one control. */
.rwg-group.col-group-segment { flex-direction: row; align-items: center; }
.rwg-group.row-group-segment { flex-direction: column; align-items: center; }
.rwg-group .col-group-marker,
.rwg-group .row-group-marker { display: flex; align-items: center; flex: 0 0 auto; }
.rwg-group .col-group-marker { flex-direction: row; }
.rwg-group .row-group-marker { flex-direction: column; }
/* The bracket: a 3px line over the group's rendered members with a tick at the start, Excel-style. It
   shrinks to nothing (and the tick hides) when the group is collapsed; the button stays on the summary
   column/row after the group, so a collapsed group is always reachable. */
.rwg-group .col-group-endcap { width: 1px; height: 9px; background: var(--darkblue, #1f3b57); flex: 0 0 auto; }
.rwg-group .row-group-endcap { width: 9px; height: 1px; background: var(--darkblue, #1f3b57); flex: 0 0 auto; }
.rwg-group .col-group-line { border-top: 3px solid var(--darkblue, #1f3b57); height: 0; }
.rwg-group .row-group-line { border-left: 3px solid var(--darkblue, #1f3b57); width: 0; }
.rwg-group .group-button-cell { display: flex; align-items: center; flex: 0 0 auto; }
.rwg-group.col-group .group-button-cell { height: 100%; padding-left: 2px; }
.rwg-group.row-group .group-button-cell { width: 100%; flex-direction: column; justify-content: flex-start; padding-top: 2px; }
.rwg-group .group-button {
    height: 14px;
    width: 14px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--lightblue, #eaf1f8);
    border: 1px solid var(--medblue, #4a78a6);
}
.rwg-group:hover .group-button,
.rwg-group.rwg-group-hover .group-button { box-shadow: inset 0 0 0 14px var(--rw-hover-overlay, rgba(0, 0, 0, 0.04)); }
/* Hovering any part of a bracket (the toggle or its frozen segment) highlights the whole bracket line. */
.rwg-group.rwg-group-hover .col-group-line,
.rwg-group.rwg-group-hover .row-group-line { border-color: var(--rwg-accent); }
.rwg-group.rwg-group-hover .col-group-endcap,
.rwg-group.rwg-group-hover .row-group-endcap { background: var(--rwg-accent); }
/* The toggle is a focusable control (role=button): show where keyboard focus is. */
.rwg-group:focus { outline: none; }
.rwg-group:focus-visible .group-button { outline: 2px solid var(--rwg-accent); outline-offset: 1px; }
.rwg-group .group-button-icon { display: flex; color: var(--darkblue, #1f3b57); line-height: 1; }
.rwg-group .group-button-icon .rw-icon { display: flex; }
.rwg-group .group-button-icon .far { font-size: 9px; font-weight: bold; }
/* While the host applies a toggle (a full reload follows), show it is busy and ignore further clicks. */
.rwg-root.rwg-group-toggling .rwg-group { cursor: progress; pointer-events: none; }

/* --- validation markers ----------------------------------------------------- */
/* The corner triangle is the box-shadow; the whole cell carries a native `title` so hovering it
   (help cursor) shows the validation message. */
.rwg-table td.rwg-has-warning { box-shadow: inset -8px 8px 0 -4px #e0a800; cursor: help; }
.rwg-table td.rwg-has-blocker { box-shadow: inset -8px 8px 0 -4px #c0392b; cursor: help; }

/* --- cell comment bookmark -------------------------------------------------- */
/* A purple corner flag (top-left, so it never collides with the top-right validation marker) marking cells
   that carry a comment. Click it to open the comment popover. */
.rwg-table td:has(> .dc-cell-comment.dc-cell-has-comment) { position: relative; }
.dc-cell-comment.dc-cell-has-comment {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    border-top: 9px solid #7c3aed;      /* purple */
    border-right: 9px solid transparent;
    cursor: pointer;
    z-index: 6;
}
.dc-cell-comment.dc-cell-has-comment:hover { border-top-color: #6d28d9; }

/* --- highlight input cells (client-only toggle from the planning command bar) ---------------- */
/* Fill the WHOLE input cell with the highlight colour. The old `box-shadow: inset … var(--rwg-accent-soft)`
   was a faint 10%-opacity green painted BEHIND the cell's inner value wrapper, so an input cell whose inner
   <span>/<div> carries an opaque fill hid all but the padding edges of it (Andy: "only bleeds through on the
   sides"). Paint an opaque fill on the td AND force the inner wrappers transparent so the highlight reads as a
   fully-coloured cell — parity with the server grid's `.dc-highlight-input-cell { background-color:#D1F8D1 }`. */
.rwg-root.rwg-highlight-inputs .rwg-table td.rwg-input-cell {
    background-image: linear-gradient(var(--rw-status-success-subtle, #D1F8D1), var(--rw-status-success-subtle, #D1F8D1)) !important;
}
.rwg-root.rwg-highlight-inputs .rwg-table td.rwg-input-cell .dc-cell-value-wrapper,
.rwg-root.rwg-highlight-inputs .rwg-table td.rwg-input-cell .dc-cell-value-wrapper > * {
    background-color: transparent !important;
}

/* --- sheet tabs ------------------------------------------------------------- */
.rwg-tabs-wrap {
    flex: 0 0 auto;
    display: flex;
    align-items: stretch;
    background: var(--rwg-header-bg);
    border-top: 1px solid var(--rwg-chrome-border);
}
.rwg-tab-scroll {
    display: none;                 /* shown only when the strip overflows (.rwg-tabs-overflow) */
    flex: 0 0 auto;
    width: 26px;
    border: none;
    border-right: 1px solid var(--rwg-chrome-border);
    background: var(--rwg-header-bg);
    color: var(--rw-text-secondary);
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}
.rwg-tab-scroll.rwg-tab-scroll-r { border-right: none; border-left: 1px solid var(--rwg-chrome-border); }
.rwg-tab-scroll:hover:not(:disabled) { background: var(--rw-hover-overlay); color: var(--rwg-accent); }
.rwg-tab-scroll:disabled { opacity: 0.3; cursor: default; }
.rwg-tabs-wrap.rwg-tabs-overflow .rwg-tab-scroll { display: inline-flex; align-items: center; justify-content: center; }
.rwg-tabs {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: stretch;
    height: 30px;
    overflow-x: auto;
    scrollbar-width: thin;
}
.rwg-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 16px;
    border-right: 1px solid var(--rwg-chrome-border);
    font-size: 12.5px;
    color: var(--rw-text-secondary);
    cursor: pointer;
    white-space: nowrap;
    position: relative;
}
.rwg-tab { transition: color .12s ease, box-shadow .12s ease, background .12s ease; }
.rwg-tab:hover {
    background: var(--rw-hover-overlay);                 /* teal-tinted hover (Option C sheet-tab restyle) */
    color: var(--rwg-accent);
    box-shadow: inset 0 -2px 0 0 rgba(34, 128, 102, 0.35);
}
.rwg-tab.rwg-tab-active,
.rwg-tab.rwg-tab-active:hover {
    background: var(--rw-surface-1);
    color: var(--rwg-accent);
    font-weight: 600;
    box-shadow: inset 0 -2px 0 0 var(--rwg-accent);   /* bottom underline, matches the mockup */
}
.rwg-tab .rwg-tab-warn { color: #e0a800; }
.rwg-tab .rwg-tab-block { color: #c0392b; }

/* Screen-reader-only text (the outline-group keyboard hint, RW-1613): read via aria-describedby, never shown. */
.rwg-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}
