/* ============================================================
   GrapesJS chrome for the page builder's designed-block editor,
   recoloured to the portal's Fluent2 palette.

   Same technique as email-designer-theme.css, scoped to a
   different container: GrapesJS 0.21 drives its whole UI from
   --gjs-* variables, so deriving them from portal.css's --hb-*
   makes the editor follow the portal's light/dark toggle
   (data-theme on <html>) with no JS at all.

   This themes the CHROME only. The canvas is a separate iframe
   document that inherits none of it — the app's tokens, the
   client's brand and the light/dark preview are pushed in there
   by blockDesigner.js, which is a different problem with a
   different answer.
   ============================================================ */

#hb-block-designer {
    /* Panels + text */
    --gjs-primary-color: var(--hb-sidebar-bg);
    --gjs-main-color: var(--hb-sidebar-bg);
    --gjs-secondary-color: var(--hb-fg);
    --gjs-font-color: var(--hb-fg);
    --gjs-font-color-active: var(--hb-fg);
    /* Accent: selected tabs, component toolbar, badges, highlights */
    --gjs-tertiary-color: var(--hb-accent);
    --gjs-quaternary-color: var(--hb-accent);
    --gjs-color-highlight: var(--hb-accent);
    /* Selection outline + component toolbar (GrapesJS default is blue) */
    --gjs-color-blue: var(--hb-accent);
    /* Fields, hovers, borders */
    --gjs-main-dark-color: rgba(0, 0, 0, .06);
    --gjs-secondary-dark-color: rgba(0, 0, 0, .08);
    --gjs-main-light-color: var(--hb-hover);
    --gjs-soft-light-color: var(--hb-hover);
    --gjs-light-border: var(--hb-border);
    /* Text on the accent colour */
    --gjs-secondary-light-color: #ffffff;
    --gjs-arrow-color: rgba(0, 0, 0, .55);
    --gjs-dark-text-shadow: transparent;
}

[data-theme="dark"] #hb-block-designer {
    --gjs-main-dark-color: rgba(255, 255, 255, .08);
    --gjs-secondary-dark-color: rgba(255, 255, 255, .06);
    /* The dark accent (#a880ff) is light — dark text reads better on it */
    --gjs-secondary-light-color: #1b1a19;
    --gjs-arrow-color: rgba(255, 255, 255, .7);
}

/* ------------------------------------------------------------
   The --gjs-* variables above are necessary and, on their own,
   were doing nothing.

   GrapesJS paints its chrome through four palette classes, and
   grapes.min.css defines each one as var(--gjs-primary-color)
   and friends. grapesjs-preset-webpage.min.css then redefines
   all twelve with literal hex — #463a3c, #b9a5a6, #804f7b,
   #d97aa6 — and it is loaded second, so every panel, toolbar and
   badge in this editor came out that fixed dark mauve whichever
   theme the portal was in. Nothing was wrong with the variables;
   nothing was reading them.

   Pointing the classes back at the variables is what makes the
   block above take effect. Specificity does it — one id beats a
   bare class — so the preset's stylesheet is left alone and the
   host and email designers keep the look they have.
   ------------------------------------------------------------ */

#hb-block-designer .gjs-one-bg { background-color: var(--gjs-primary-color); }
#hb-block-designer .gjs-one-color { color: var(--gjs-primary-color); }
#hb-block-designer .gjs-one-color-h:hover { color: var(--gjs-primary-color); }

#hb-block-designer .gjs-two-bg { background-color: var(--gjs-secondary-color); }
#hb-block-designer .gjs-two-color { color: var(--gjs-secondary-color); }
#hb-block-designer .gjs-two-color-h:hover { color: var(--gjs-secondary-color); }

#hb-block-designer .gjs-three-bg { background-color: var(--gjs-tertiary-color); }
#hb-block-designer .gjs-three-color { color: var(--gjs-tertiary-color); }
#hb-block-designer .gjs-three-color-h:hover { color: var(--gjs-tertiary-color); }

#hb-block-designer .gjs-four-bg { background-color: var(--gjs-quaternary-color); }
#hb-block-designer .gjs-four-color { color: var(--gjs-quaternary-color); }
#hb-block-designer .gjs-four-color-h:hover { color: var(--gjs-quaternary-color); }

/* Blocks are cards: hardcoded rgba borders/shadows don't survive dark mode */
#hb-block-designer .gjs-block {
    background-color: var(--hb-card-bg);
    border: 1px solid var(--hb-border);
    box-shadow: 0 1px 0 0 var(--hb-border);
    color: var(--hb-fg);
}

/* A ticked checkbox in a component's settings (the Media block's "Say who and when", the Events block's date and
   buttons). GrapesJS draws the tick in translucent white, which on a light panel is white on a pale box - a
   checked control that looks the same as an unchecked one. The accent reads on both themes. */
.gjs-trt-trait .gjs-field-checkbox input:checked + .gjs-chk-icon { border-color: var(--hb-accent, #5b3fd6); }

/* The area around the block being designed */
#hb-block-designer .gjs-cv-canvas-bg {
    background-color: var(--hb-content-bg);
}
