/* =====================================================================================
   The builder workspace — tree, canvas, inspector — shared by the page builder and the
   form builder.

   Extracted verbatim from PageBuilder.razor's own <style> block (which still carries its
   copy; the two are identical and this file is the one to edit). Every colour comes from
   the portal's own tokens (--hb-fg, --hb-border, --hb-accent…), which the light/dark
   toggle swaps in one place — see portal.css. Nothing here states a colour of its own.
   ===================================================================================== */
    /* Every colour here comes from the portal's own tokens, which the light/dark toggle swaps in
       one place — see portal.css. Nothing in this file states a colour of its own, and nothing
       inherits one either: Bootstrap's body colour is near-black in BOTH themes, so text that
       simply inherits is invisible in dark. That is the trap this whole block exists to avoid. */

    .hb-builder {
        color: var(--hb-fg);
        /* How much of the screen is not the workspace: this screen's own header and the padding
           around it — and the notice, on the pages that have one. Named rather than written into
           the height twice, because the two numbers have to move together. */
        --hb-work-taken: 132px;
    }

    .hb-builder.has-notice { --hb-work-taken: 224px; }

    /* Said once, at the top, in the colour of something being explained rather than something going
       wrong: a page opening on the default is normal, it just isn't obvious. */
    .hb-notice {
        display: flex;
        align-items: flex-start;
        gap: 10px;
        padding: 12px 14px;
        margin-bottom: 14px;
        border-radius: 8px;
        border: 1px solid var(--hb-border);
        background: var(--hb-active-bg);
        color: var(--hb-fg);
        font-size: 0.85rem;
        line-height: 1.5;
    }

    .hb-notice > i { color: var(--hb-accent); margin-top: 2px; }
    .hb-notice > div { flex: 1 1 auto; min-width: 0; }
    .hb-notice strong { display: block; }

    .hb-notice-x {
        flex: none;
        border: 0;
        background: none;
        color: var(--hb-muted);
        padding: 2px 4px;
        line-height: 1;
        cursor: pointer;
    }

    .hb-notice-x:hover { color: var(--hb-fg); }

    /* Whether the page is saved, beside the buttons that save it. Quiet on purpose: it is only
       worth noticing when it says something unexpected. */
    .hb-saved {
        font-size: 0.78rem;
        color: var(--hb-muted);
        white-space: nowrap;
    }

    .hb-panel {
        background: var(--hb-card-bg);
        border: 1px solid var(--hb-border);
        border-radius: 10px;
        padding: 14px;
        color: var(--hb-fg);
    }

    .hb-panel-title {
        margin: 0 0 12px;
        font-size: 0.8rem;
        font-weight: 600;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--hb-muted);
    }

    .hb-tree {
        padding: 6px;
        /* Fills its column, so the panel's edge is the column's edge rather than a short box with
           the page showing under it. */
        min-height: 100%;
    }

    .hb-tree-head {
        display: flex;
        flex-direction: column;
        gap: 2px;
        padding: 4px 8px 10px;
        margin-bottom: 4px;
        border-bottom: 1px solid var(--hb-border);
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--hb-muted);
    }

    .hb-tree-hint {
        font-size: 0.75rem;
        font-weight: 400;
        letter-spacing: 0;
        text-transform: none;
    }

    .hb-tree-foot {
        margin: 8px 8px 2px;
        font-size: 0.72rem;
        line-height: 1.4;
        color: var(--hb-muted);
    }

    /* The elbow that says "inside". Indentation alone reads as a margin; a line from the row above
       to this one reads as containment, which is the whole question this panel answers. */
    .hb-row-tick {
        flex: none;
        width: 10px;
        height: 10px;
        margin-left: 4px;
        border-left: 1px solid var(--hb-border);
        border-bottom: 1px solid var(--hb-border);
        border-bottom-left-radius: 3px;
    }

    .hb-row[draggable="true"] { cursor: grab; }

    /* Where it would land. A line rather than a fill: it is between two rows, not on one of them. */
    .hb-row.over {
        box-shadow: inset 0 2px 0 0 var(--hb-accent);
        background: var(--hb-hover);
    }

    .hb-row-tag {
        margin-left: 6px;
        padding: 0 6px;
        border-radius: 999px;
        background: var(--hb-hover);
        color: var(--hb-muted);
        font-size: 0.65rem;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    /* One row per node. The whole row is the target, not the label inside it — a tree where only
       the words are clickable is a tree you keep missing. */
    .hb-row {
        position: relative;
        display: flex;
        align-items: center;
        gap: 4px;
        border-radius: 6px;
        padding: 2px 4px 2px 0;
        border-left: 2px solid transparent;
    }

    .hb-row:hover { background: var(--hb-hover); }

    /* Selection is a tint of the accent, not a light slab. .bg-light — which this used to be — is
       near-white in both themes, so in dark it was a white block carrying the shell's near-white
       text: the selected row was the one row you couldn't read. */
    .hb-row.on {
        background: var(--hb-active-bg);
        border-left-color: var(--hb-accent);
    }

    .hb-row-pick {
        flex: 1 1 auto;
        min-width: 0;
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 5px 8px;
        border: 0;
        background: transparent;
        color: var(--hb-fg);
        font-size: 0.9rem;
        text-align: left;
        cursor: pointer;
        overflow: hidden;
    }

    /* The name, and the only thing here that truncates. On the button itself `overflow: hidden`
       clips at the border box — which is outside the padding reserved for the buttons — so a long
       name ran underneath them instead of ending before them. */
    .hb-row-pick > span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .hb-row.on .hb-row-pick { font-weight: 600; }

    .hb-row-pick > i {
        width: 16px;
        text-align: center;
        color: var(--hb-muted);
    }
    .hb-row.on .hb-row-pick > i { color: var(--hb-accent); }

    /* Switched off, and everything under something switched off.

       The name is what dims, not the row: the row still has to be pointed at, dragged and pressed,
       and a control at 45% reads as one that cannot be. Two strengths rather than one — the node
       that was actually turned off is fainter than the rows that only inherit it — so a glance at
       a dim branch says which row has the switch that brings it back.

       Nothing here restates a colour. Fading the whole button lets the row's own background, the
       selection tint and the hover all keep working underneath. */
    .hb-row.off .hb-row-pick { opacity: 0.45; }
    .hb-row.dim .hb-row-pick { opacity: 0.6; }

    /* Struck through as well, because opacity alone is what a disabled control looks like and this
       is not one — the row is still fully live. */
    .hb-row.off .hb-row-pick > span { text-decoration: line-through; }

    .hb-row-off-mark {
        flex: none;
        font-size: 0.75rem;
    }

    /* The move and delete buttons: quiet until the row is under the pointer, so a deep tree reads
       as a tree rather than as three columns of icons. */
    .hb-row .e-btn.e-flat { opacity: 0; transition: opacity .12s ease; }
    .hb-row:hover .e-btn.e-flat,
    .hb-row.on .e-btn.e-flat { opacity: 1; }

    .hb-quiet { color: var(--hb-muted); }

    .hb-builder .form-label {
        color: var(--hb-fg);
        font-size: 0.85rem;
        margin-bottom: 4px;
    }

    .hb-builder .form-text { color: var(--hb-muted); }

    /* Over the row rather than in it. Four buttons in the flow take 110px, and in a column this
       narrow that is a third of the width taken from the names — which are the thing the panel is
       for. They only appear on hover or on the selected row, so what they cover is a name nobody is
       reading at that moment. */
    .hb-row-act {
        position: absolute;
        right: 2px;
        top: 50%;
        transform: translateY(-50%);
        flex: none;
        width: 26px;
        height: 26px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border: 0;
        border-radius: 6px;
        background: transparent;
        color: var(--hb-muted);
        font-size: 0.9rem;
        line-height: 1;
        cursor: pointer;
        opacity: 0;
        transition: opacity .12s ease;
    }

    .hb-row:hover .hb-row-act,
    .hb-row.on .hb-row-act { opacity: 1; }

    /* Stacked right to left in the order they are written, so the markup stays readable and the
       buttons still come out in the order an author expects.

       There must be a slot for every button a row can carry. A stack carries five — four that fade
       in, plus the plus — and while there were only four rules the fifth fell back to the shared
       right: 2px above and sat underneath the one that deletes things. */
    .hb-row-act:nth-last-of-type(1) { right: 2px; }
    .hb-row-act:nth-last-of-type(2) { right: 30px; }
    .hb-row-act:nth-last-of-type(3) { right: 58px; }
    .hb-row-act:nth-last-of-type(4) { right: 86px; }
    .hb-row-act:nth-last-of-type(5) { right: 114px; }
    .hb-row-act:nth-last-of-type(6) { right: 142px; }

    /* Room at the end of the name for the buttons — but only while they are there. Reserving it
       always would truncate every name in the panel to pay for buttons that are not on screen, and
       reading the names is what the panel is for.

       So the row says how many it carries, and there is one number per case rather than one number
       for the widest row in the panel. The plus is the exception in the other direction: it is on
       screen whether the row is pointed at or not, so its 32px is always reserved. */
    .hb-row.acts1 .hb-row-pick,
    .hb-row.acts6 .hb-row-pick { padding-right: 32px; }

    /* Three: the form builder's send button, which can be hidden and moved but not copied or removed. */
    .hb-row.acts3:hover .hb-row-pick,
    .hb-row.acts3.on .hb-row-pick { padding-right: 88px; }

    .hb-row.acts5:hover .hb-row-pick,
    .hb-row.acts5.on .hb-row-pick { padding-right: 144px; }

    .hb-row.acts6:hover .hb-row-pick,
    .hb-row.acts6.on .hb-row-pick { padding-right: 172px; }

    .hb-row-act:hover { background: var(--hb-hover); color: var(--hb-fg); }
    .hb-row-act.danger:hover { color: #d13438; }

    /* Nowhere to go. Still there, so the row's controls do not shuffle sideways as the selection
       moves down the list, and plainly not pressable — but hidden until the row is hovered or
       selected like every other button here. Left visible always, a greyed arrow would be the only
       thing on an untouched row, which reads as something being wrong with it. */
    .hb-row-act:disabled {
        cursor: default;
        background: none;
    }

    .hb-row:hover .hb-row-act:disabled,
    .hb-row.on .hb-row-act:disabled { opacity: 0.32; }

    /* The one that adds something is the only always-visible control on a stack: it is what an
       empty page is waiting for, and a plus that only appears on hover is a plus nobody finds. */
    .hb-row-act.add {
        opacity: 1;
        font-size: 1.1rem;
        color: var(--hb-accent);
        background: var(--hb-active-bg);
    }

    /* ---- The inspector -----------------------------------------------------------------

       Laid out the way every builder of this kind lays one out, because that shape is what an
       author has already met: what you are editing at the top, three tabs under it, and a column
       of rows with the label beside its control rather than above it. Labels above make a panel
       twice as tall and turn scanning it into reading it. */

/* ---- The workspace ------------------------------------------------------------------

       A builder is not a document. The page itself does not scroll: the three columns stand side
       by side, each exactly as tall as the room there is, and each scrolling inside itself.

       That is what stops the thing that kept looking like a fade. While the page scrolled, a panel
       taller than the window was cut off BY the window — the last line half drawn, its descenders
       gone, and nothing to say whether it had been clipped or had failed to render. Nothing is cut
       by the page now, because the page has no bottom to cut anything with.

       Below xl the columns stack and take their natural height instead: at that width they are too
       narrow to stand beside each other, and a short scroller inside a scrolling page is worse than
       either on its own. */

    .hb-work {
        display: flex;
        gap: 16px;
        align-items: stretch;
        height: calc(100vh - var(--hb-appbar-h, 56px) - var(--hb-work-taken));
        min-height: 460px;
    }

    .hb-work-col {
        min-width: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    /* The tree is a list of short names and the inspector is a column of controls with prose
       under them, so the room goes to the inspector. The canvas takes what is left and scales its
       frame to fit — it is the one part that can. */
    .hb-work-tree { flex: 0 0 280px; }
    .hb-work-canvas { flex: 1 1 auto; min-width: 360px; }
    .hb-work-ins { flex: 0 0 420px; }

    @media (max-width: 1399.98px) {
        .hb-work {
            display: block;
            height: auto;
            min-height: 0;
        }

        .hb-work-col {
            overflow: visible;
            margin-bottom: 16px;
        }
    }

    /* The panel fills its column and ends with it. It does not need to be sticky: the column it
       sits in is already exactly as tall as the screen allows, and does not scroll away. */
    .hb-ins {
        display: flex;
        flex-direction: column;
        max-height: 100%;
        background: var(--hb-card-bg);
        border: 1px solid var(--hb-border);
        border-radius: 10px;
        overflow: hidden;
    }

    @media (max-width: 1399.98px) {
        .hb-ins { max-height: none; }
        .hb-ins-body { max-height: 70vh; }
    }

    .hb-ins-head {
        flex: none;
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 12px 14px;
        border-bottom: 1px solid var(--hb-border);
        font-weight: 600;
        color: var(--hb-fg);
    }

    .hb-ins-head > i { color: var(--hb-accent); }

    .hb-ins-tabs {
        flex: none;
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        border-bottom: 1px solid var(--hb-border);
        background: var(--hb-sidebar-bg);
    }

    .hb-ins-tabs > button {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 3px;
        padding: 9px 4px;
        border: 0;
        border-bottom: 2px solid transparent;
        background: transparent;
        color: var(--hb-muted);
        font-size: 0.76rem;
        cursor: pointer;
    }

    .hb-ins-tabs > button > i { font-size: 1rem; }
    .hb-ins-tabs > button:hover { background: var(--hb-hover); color: var(--hb-fg); }

    .hb-ins-tabs > button.on {
        color: var(--hb-fg);
        border-bottom-color: var(--hb-accent);
        background: var(--hb-card-bg);
    }

    .hb-ins-body {
        /* The only part that scrolls, and it takes whatever height is left. min-height:0 is what
           lets it: a flex item's floor is its content, so without it a long panel pushes the box
           past the screen instead of scrolling inside it. */
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        /* A scroll that reaches the end stops there rather than carrying on into the page behind. */
        overscroll-behavior: contain;
        /* Room at the foot so the last control ends clear of the edge rather than against it. */
        padding: 14px 14px 22px;
        color: var(--hb-fg);
    }

    .hb-ins-group + .hb-ins-group { margin-top: 16px; }

    .hb-ins-group-head {
        margin-bottom: 10px;
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--hb-muted);
    }

    /* One setting: its name on the left, the control on the right. The label column is fixed so
       every control in the panel starts on the same line down the whole column. */
    /* Token chips under a text box. Small and quiet — they are a reminder that the feature
       exists, not a control anybody needs to look at while writing. */
    .hb-token-hint { margin-top: 6px; display: flex; flex-wrap: wrap; align-items: center; gap: 5px; font-size: 11px; }
    .hb-token-hint > span { opacity: .65; }
    .hb-token-chip {
        border: 1px solid rgba(128,128,128,.4); background: transparent;
        color: var(--color-sf-on-surface, inherit);
        border-radius: 999px; padding: 1px 8px; font-size: 11px; cursor: pointer; font-family: monospace;
    }
    .hb-token-chip:hover { border-color: var(--color-sf-primary, #2f6fed); }
    .hb-token-note { flex-basis: 100%; opacity: .6; margin-top: 2px; }

    .hb-ins-row {
        display: grid;
        grid-template-columns: 92px minmax(0, 1fr);
        align-items: center;
        gap: 10px;
        margin-bottom: 10px;
    }

    .hb-ins-row > label {
        margin: 0;
        font-size: 0.8rem;
        color: var(--hb-muted);
        line-height: 1.25;
    }

    /* Some controls are not a box on a line: a picture with a thumbnail and an uploader under it, a
       grid of four spacing boxes. Beside a 92px label those get about 280px and everything in them
       wraps. These take the whole width and put their label above. */
    .hb-ins-row.wide {
        display: block;
    }

    .hb-ins-row.wide > label {
        display: block;
        margin-bottom: 6px;
    }

    .hb-ins-help,
    .hb-ins-note {
        margin: 4px 0 0;
        font-size: 0.75rem;
        line-height: 1.4;
        color: var(--hb-muted);
    }

    .hb-ins-note { margin: 8px 0 0; }

    /* The way into the block designer. A button rather than a box, because what it edits is a
       layout — see the Designer case in FieldControl. */
    .hb-designer-slot {
        display: flex;
        gap: 8px;
        flex-wrap: wrap;
    }

    .hb-designer-slot .e-btn i { margin-right: 6px; }

    /* Four edges, two by two — one per line would be four rows for one idea. */
    .hb-pad {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px 12px;
    }

    .hb-pad > .hb-ins-help { grid-column: 1 / -1; }

    .hb-pad-box > label {
        display: block;
        margin-bottom: 4px;
        font-size: 0.78rem;
        color: var(--hb-muted);
    }

    /* Something that is true now and will stop being true as soon as it is dealt with — a state,
       not an error. Amber rather than red, and its own tint rather than a border, so it reads as
       "worth knowing" rather than as something having gone wrong. */
    .hb-ins-warn {
        display: flex;
        gap: 8px;
        margin: 10px 0 0;
        padding: 8px 10px;
        border-radius: 6px;
        background: rgba(234, 165, 0, 0.14);
        color: var(--hb-fg);
        font-size: 0.75rem;
        line-height: 1.4;
    }

    .hb-ins-warn > i { color: #d38b00; margin-top: 2px; }

    /* The style panel is a component of its own, written for a wider dialog; inside this column it
       gets the same padding as everything else and nothing more. */
    .hb-ins-body .hb-style-editor .hb-dlg-section {
        margin: 14px 0 8px;
        font-size: 0.75rem;
        font-weight: 600;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--hb-muted);
        opacity: 1;
    }

    /* ---- The widget picker -------------------------------------------------------------- */

    .hb-pick-search { margin-bottom: 12px; }

    .hb-pick-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
        gap: 10px;
    }

    .hb-pick {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
        padding: 12px;
        border: 1px solid var(--hb-border);
        border-radius: 8px;
        background: transparent;
        color: var(--hb-fg);
        text-align: left;
        cursor: pointer;
    }

    .hb-pick:hover {
        border-color: var(--hb-accent);
        background: var(--hb-hover);
    }

    .hb-pick > i {
        font-size: 1.25rem;
        color: var(--hb-accent);
    }

    .hb-hist { display: flex; flex-direction: column; }

    .hb-hist-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        padding: 10px 0;
        border-bottom: 1px solid var(--hb-border);
    }

    .hb-hist-row:last-child { border-bottom: 0; }

    .hb-hist-actions { display: flex; gap: 6px; flex: none; }

    .hb-pick-name { font-weight: 600; font-size: 0.85rem; }
    .hb-pick-blurb { font-size: 0.75rem; line-height: 1.35; color: var(--hb-muted); }
