/* ============================================================================
   Makery structure view — step 2, target order.
   Append to the existing fsi- stylesheet.

   Nothing here restyles a row: rows keep the washes RowClass already gives
   them, so a user who learned the colours in source order reads them the same
   way here. What is new is the frame around them — headers, sums, derived rows
   — and it is deliberately quieter than the rows it contains.
   ============================================================================ */

/* ---- Chip row now carries the view toggle on the right ------------------- */

.fsi-chips {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.fsi-order {
    display: inline-flex;
    flex: none;
    border: 1px solid var(--rz-base-300);
    border-radius: 8px;
    overflow: hidden;
    background: var(--rz-base-background-color);
}

    .fsi-order button {
        appearance: none;
        border: 0;
        background: transparent;
        padding: 0.3125rem 0.75rem;
        font: inherit;
        font-size: 0.8125rem;
        color: var(--rz-text-secondary-color);
        cursor: pointer;
        white-space: nowrap;
    }

        .fsi-order button + button {
            border-left: 1px solid var(--rz-base-300);
        }

        .fsi-order button:hover:not(.is-active) {
            background: var(--rz-base-100);
            color: var(--rz-text-color);
        }

        .fsi-order button.is-active {
            background: var(--rz-primary);
            color: var(--rz-on-primary, #fff);
        }

        .fsi-order button:focus-visible {
            outline: 2px solid var(--rz-primary);
            outline-offset: -2px;
        }

/* ---- Scroller ------------------------------------------------------------
   The structure view is not virtualized — section headers have to stay in
   flow, and the row count is bounded by the sheet. fsi-body-ledger clips, so
   the scrolling happens here.                                               */

.fsi-structure-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
}

.fsi-structure {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    padding-bottom: 1rem;
}

/* ---- Header track --------------------------------------------------------
   Shares PeriodTrackStyle with the grid, so a section sum sits in the same
   column as the row values underneath it.                                    */

.fsi-structure-head {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--rz-base-background-color);
    border-bottom: 1px solid var(--rz-base-300);
    padding: 0.375rem 0.75rem;
}

.fsi-structure-head-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--rz-text-secondary-color);
}

.fsi-structure-head .fsi-vals-head {
    flex: none;
}

/* ---- Section -------------------------------------------------------------- */

.fsi-structure-group {
    display: flex;
    flex-direction: column;
}

.fsi-structure-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    appearance: none;
    border: 0;
    border-radius: 6px;
    background: var(--rz-base-100);
    padding: 0.5rem 0.75rem;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

    .fsi-structure-header.is-static {
        cursor: default;
    }

    .fsi-structure-header:hover:not(.is-static) {
        background: var(--rz-base-200);
    }

    .fsi-structure-header:focus-visible {
        outline: 2px solid var(--rz-primary);
        outline-offset: -2px;
    }

.fsi-structure-title {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--rz-text-color);
}

/* Pushes the sums to the right edge, on the shared track. */
.fsi-structure-count {
    flex: 1 1 auto;
    font-size: 0.75rem;
    color: var(--rz-text-secondary-color);
}

.fsi-structure-header .fsi-vals {
    flex: none;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* An empty section is information — the import mapped nothing into it — so it
   stays visible and goes quiet rather than disappearing. */
.fsi-structure-group.is-empty .fsi-structure-header {
    background: transparent;
    color: var(--rz-text-disabled-color);
}

.fsi-structure-group.is-empty .fsi-structure-title,
.fsi-structure-group.is-empty .fsi-val {
    color: var(--rz-text-disabled-color);
    font-weight: 400;
}

/* ---- The two pseudo-groups ------------------------------------------------ */

/* Rows with figures and nowhere to go. Same violet as the unmapped wash, so
   the section and the rows inside it read as one thing. */
.fsi-structure-group.is-needs-target .fsi-structure-header {
    background: var(--fsi-unmapped-bg, #f5f3ff);
    box-shadow: inset 3px 0 0 var(--fsi-unmapped-edge, #7c3aed);
}

.fsi-structure-group.is-unplaced .fsi-structure-header {
    background: var(--rz-base-100);
    box-shadow: inset 3px 0 0 var(--rz-base-400);
}

.fsi-structure-group.is-not-imported .fsi-structure-header {
    background: transparent;
    color: var(--rz-text-secondary-color);
}

.fsi-structure-group.is-not-imported .fsi-structure-title {
    font-weight: 500;
    color: var(--rz-text-secondary-color);
}

.fsi-structure-note {
    margin: 0.25rem 0 0.375rem;
    padding: 0 0.75rem 0 1.75rem;
    font-size: 0.75rem;
    line-height: 1.45;
    color: var(--rz-text-secondary-color);
    max-width: 60ch;
}

/* ---- Rows -----------------------------------------------------------------
   Column widths mirror the grid's: 175 / 350 / 200 / 350 / track.            */

.fsi-structure-rows {
    display: flex;
    flex-direction: column;
}

.fsi-structure-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.25rem 0.75rem;
    border-bottom: 1px solid var(--rz-base-200);
}

.fsi-structure-cell {
    min-width: 0;
}

.fsi-cell-prov {
    flex: 0 0 175px;
}

.fsi-cell-item {
    flex: 0 0 350px;
}

.fsi-cell-target {
    flex: 0 0 200px;
}

.fsi-cell-learning {
    flex: 1 1 350px;
}

.fsi-cell-vals {
    flex: none;
}

/* ---- Derived rows ---------------------------------------------------------
   Styled after FinancialCalculatedRow: a rule above, bold figures, no fill.
   These are a preview of the import, not a reconciliation against the sheet.  */

.fsi-structure-derived {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4375rem 0.75rem;
    border-top: 1px solid var(--rz-base-400);
    font-weight: 600;
}

    .fsi-structure-derived.is-major {
        border-top-width: 2px;
        border-top-color: var(--rz-text-color);
        font-size: 1rem;
    }

.fsi-structure-derived-title {
    flex: 1 1 auto;
    min-width: 0;
}

.fsi-structure-derived .fsi-vals {
    flex: none;
    font-variant-numeric: tabular-nums;
}

.fsi-structure-gap {
    height: 1.25rem;
}

/* ---- Incomplete periods ---------------------------------------------------
   A contributing row had no figure here. The total is real for the rows that
   did, and the mark says so without inventing a zero.                         */

.fsi-val.is-partial {
    position: relative;
    color: var(--rz-warning-dark, #b45309);
}

    .fsi-val.is-partial::after {
        content: "*";
        margin-left: 0.125em;
        font-weight: 700;
    }

/* ---- Responsive -----------------------------------------------------------
   Below the grid's natural width the learning column is the first to give: it
   holds buttons that wrap cleanly, where the target dropdown does not.        */

@media (max-width: 1200px) {
    .fsi-cell-item {
        flex: 0 0 260px;
    }

    .fsi-cell-learning {
        flex: 1 1 220px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .fsi-structure-header {
        transition: none;
    }
}

/* ---- Balance break ------------------------------------------------------- */

/* Loud on purpose. Every other signal in this view is a wash or a hairline,
   so the one unrecoverable error gets the only saturated block on the page. */
.fsi-structure-balance {
    margin: 0 0 1rem;
    border-radius: 8px;
    font-size: .8125rem;
    line-height: 1.5;
}

    .fsi-structure-balance strong {
        display: block;
        font-size: .875rem;
    }

/* ---- Row washes ----------------------------------------------------------
   RowClass returns the SAME class in both views, but the source-order rules
   are written against Radzen's <tr>. These re-apply the identical washes to
   the structure view's rows so a colour a user learned in one view means the
   same thing in the other.

   Keep these hexes in sync with the .fsi-ledger tr rules. If they ever need to
   differ, the row state itself has changed meaning and both should move. */

.fsi-structure-row.fsi-unmapped-row {
    background: #f5f3ff;
    box-shadow: inset 3px 0 0 #7c3aed;
}

.fsi-structure-row.fsi-critical-row {
    background: #fef2f2;
    box-shadow: inset 3px 0 0 #dc2626;
}

.fsi-structure-row.fsi-verify-row {
    background: #fffbeb;
    box-shadow: inset 3px 0 0 #f59e0b;
}

.fsi-structure-row.fsi-total-row {
    background: #f8fafc;
    box-shadow: inset 3px 0 0 #94a3b8;
}

.fsi-structure-row.fsi-excluded-row {
    background: transparent;
    box-shadow: inset 3px 0 0 #e2e8f0;
    opacity: .62;
}
