/* =============================================
   theme.css — MobiWebX Next UI theming
   Design tokens as CSS custom properties + the handful of genuine
   component classes that don't reduce cleanly to utilities.

   Pairs with tailwind-theme.js, which registers these variables as
   Tailwind colors — so `bg-surface-2`, `text-content-muted`,
   `border-border`, `hover:bg-surface-3`, `bg-surface/50` all work
   and no `dark:` prefixes are needed anywhere.

   DESIGN LANGUAGE (neutral-first):
     - Neutrals carry ~90% of the interface. Hierarchy comes from
       spacing, typography, elevation and size — not from color.
     - There is exactly ONE accent (--mwx-primary). --mwx-accent and
       --mwx-ring are aliases of it, not separate blues.
     - Semantic colors (success / danger / warning) communicate STATE.
       They are not decoration for ordinary actions.

   NOTE: this does NOT affect generated modules or preview iframes —
   those live in separate documents and carry their own designSystem.
   ============================================= */

:root,
html.light {
  color-scheme: light;

  /* --- Channel triples (R G B, space-separated, NO commas, NO hex) ---
     This format is required so Tailwind can emit
     rgb(var(--x) / <alpha-value>) for opacity modifiers.
     Never use these directly as a color value — always wrap them:
       WRONG: background-color: var(--mwx-surface);
       RIGHT: background-color: rgb(var(--mwx-surface));            */
  --mwx-app:            241 245 249;
  --mwx-surface:        255 255 255;
  --mwx-surface-2:      248 250 252;
  --mwx-surface-3:      226 232 240;
  --mwx-border:         226 232 240;
  --mwx-border-strong:  203 213 225;
  --mwx-content:         15  23  42;
  --mwx-content-muted:  100 116 139;
  --mwx-content-faint:  148 163 184;
  --mwx-canvas:         238 242 247;
  --mwx-canvas-dot:     203 213 225;
  --mwx-frame:          203 213 225;

  /* --- The single accent ---
     A deep, saturated navy blue. Hue ~217°, which is the same hue as the
     slate neutrals above (~215°) — the accent and the greys are the same
     color family at different saturations, which is why nothing else in
     this palette needs to move. #1F4C92 on white → 8.4:1 with white text
     (AAA), so the primary button is now the strongest thing on screen by
     contrast alone and doesn't need extra weight to read as focal.

     The FILL is identical in dark mode so a primary button looks the same
     on both themes. `soft` (readable text on a tint) and `accent` (thin
     marks on a dark background) both flip — see html.dark below.      */
  --mwx-primary:         31  76 146;
  --mwx-primary-hover:   25  61 118;
  --mwx-primary-soft:    27  66 126;

  /* Still ONE accent, not two blues — but the roles now genuinely differ
     by theme. `primary` is a fill that carries white text; `accent`/`ring`
     are hairlines, dots and focus rings drawn ON a background. In light
     mode those are the same color. In dark mode they cannot be.       */
  --mwx-accent: var(--mwx-primary);
  --mwx-ring:   var(--mwx-primary);

  /* --- Composite values: used as-is, alpha already baked in --- */
  --mwx-overlay: rgba(15, 23, 42, 0.45);
  --mwx-loader:  rgba(255, 255, 255, 0.92);
  --mwx-shadow:  0 10px 25px -5px rgba(15, 23, 42, 0.12);

  /* --- Semantic: state, not decoration ---
     `-soft` is the text color to use ON a tinted background of the same
     hue (e.g. rgb(var(--mwx-success) / .12)). It flips between themes.
     `-solid` is the fill for the rare filled treatment.               */
  --mwx-success:         5 150 105; /* emerald-600 */
  --mwx-success-hover:   4 120  87; /* emerald-700 */
  --mwx-success-soft:    4 108  78;

  --mwx-danger:        220  38  38; /* red-600 */
  --mwx-danger-hover:  185  28  28; /* red-700 */
  --mwx-danger-soft:   185  28  28;

  /* Solid destructive fill. Same in both themes: red-400 is too light to
     carry white text, so the filled variant must not follow --mwx-danger. */
  --mwx-danger-solid:  220  38  38;

  --mwx-warning:       217 119   6; /* amber-600 */
  --mwx-warning-hover: 180  83   9; /* amber-700 */
  --mwx-warning-soft:  146  64  14; /* amber-800 */
}

html.dark {
  color-scheme: dark;

  --mwx-app:             15  23  42;
  --mwx-surface:         30  41  59;
  --mwx-surface-2:       15  23  42;
  --mwx-surface-3:       51  65  85;
  --mwx-border:          51  65  85;
  --mwx-border-strong:   71  85 105;
  --mwx-content:        241 245 249;
  --mwx-content-muted:  148 163 184;
  --mwx-content-faint:  100 116 139;
  --mwx-canvas:           2   6  23;
  --mwx-canvas-dot:      51  65  85;
  --mwx-frame:           30  41  59;

  /* --mwx-primary / --mwx-primary-hover intentionally NOT redeclared —
     the filled button is the same navy on both themes.               */
  --mwx-primary-soft:   160 190 238; /* readable on dark primary tints */

  /* Accent and ring DO diverge here. #1F4C92 against surface #1E293B is
     1.7:1 — a focus ring at that contrast is not an affordance, and the
     resizer hover would vanish. This lighter tint of the same hue gives
     5.4:1 on surface and 6.7:1 on the app background.                 */
  --mwx-accent: 123 159 219;
  --mwx-ring:   var(--mwx-accent);

  --mwx-overlay: rgba(2, 6, 23, 0.80);
  --mwx-loader:  rgba(15, 23, 42, 0.92);
  --mwx-shadow:  0 10px 25px -5px rgba(0, 0, 0, 0.6);

  --mwx-success:        16 185 129; /* emerald-500 */
  --mwx-success-hover:   5 150 105; /* emerald-600 */
  --mwx-success-soft:  110 231 183; /* emerald-300 */

  --mwx-danger:        248 113 113; /* red-400 */
  --mwx-danger-hover:  239  68  68; /* red-500 */
  --mwx-danger-soft:   252 165 165; /* red-300 */

  --mwx-warning:       251 191  36; /* amber-400 */
  --mwx-warning-hover: 245 158  11; /* amber-500 */
  --mwx-warning-soft:  252 211  77; /* amber-300 */
}

/* =============================================
   Component classes
   Only what genuinely doesn't reduce to utilities: multi-property
   bundles with pseudo-elements, gradients, or long repeated state
   chains. Everything that was a single-property alias (.mwx-text,
   .mwx-border, .mwx-surface-*, .mwx-panel, ...) now lives in
   tailwind-theme.js as a real Tailwind color instead.

   The `html` prefix raises specificity to (0,1,1) so these beat
   Tailwind's single-class utilities (0,1,0) regardless of the order
   the Play CDN injects its stylesheet. Tailwind's `!` important
   modifier (e.g. `!border-0 !bg-transparent`) still overrides them,
   which is how the AI chat textarea already opts out.
   ============================================= */

/* ---- Control size scale ----
   Desktop-first, so the baseline is 32px, not the 40px a touch target would
   need. Four rungs on an 8pt ladder; radius is 25% of height at every rung.

     rung     height   radius   font    icon   padding   gap
     -sm      24px     6px      12px    14px   8px       4px
     (bare)   32px     8px      12px    14px   14px      6px
     -lg      40px     10px     14px    18px   20px      8px
     -xl      48px     12px     16px    20px   24px      8px

   The BARE class is the default — most of the app carries no suffix at all.
   A suffix names a rung on this table, never "one notch smaller than this
   component's own base", which is what makes .mwx-btn-sm and
   .mwx-icon-btn-sm the same height by construction.

   -sm and bare deliberately share type (12px label, 14px icon) and are told
   apart by box alone. The type ramp starts at -lg. Keeping the label at 12px
   on a 32px control is what makes the default read as dense rather than
   roomy — this is a desktop tool, not a marketing page.

   One documented exception, so it doesn't read as drift: icon-ONLY buttons
   (.mwx-icon-btn) take the icon size the box can carry — 16px at bare, 20px
   at -lg / -xl — rather than the table's inline value. With no label beside
   it, the larger glyph is correct. Inline icons (.mwx-btn i, .mwx-segment i)
   follow the table.

   Variant suffixes (-primary, -danger, -quiet, -ghost, -active) must NEVER
   touch height, padding, radius or border-width — they swap colors only, so
   no state change can reflow a row.

   Containers are not on this ladder: .mwx-segmented and .mwx-theme-segmented
   size themselves from their contents plus padding.                     */

html .mwx-input {
  background-color: rgb(var(--mwx-surface-2));
  color: rgb(var(--mwx-content));
  border: 1px solid rgb(var(--mwx-border));
  border-radius: .5rem;
  font-family: inherit;
  font-size: .75rem;
}
html .mwx-input:hover:not(:focus) { border-color: rgb(var(--mwx-border-strong)); }

/* Element-scoped so multiline fields keep their own height — the AI chat
   textarea is unaffected and still opts out with `!` utilities.

   Vertical padding must be ZERO on a fixed-height single-line field. The box
   is border-box, so 2rem minus the 2px borders leaves a 28px content box,
   and any py-* left over in the markup eats into that: the text clips while
   the space is still reserved. Browsers centre an input's own text inside
   the content box, so removing the padding is the whole fix — no line-height
   required. Horizontal padding comes from the rung, not the markup. */
html input.mwx-input,
html select.mwx-input {
  height: 2rem;
  padding: 0 .875rem;
}
html input.mwx-input-sm,
html select.mwx-input-sm {
  height: 1.5rem;
  padding: 0 .5rem;
  border-radius: .375rem;
}
html input.mwx-input-lg,
html select.mwx-input-lg {
  height: 2.5rem;
  padding: 0 1.25rem;
  font-size: .875rem;
}
html .mwx-input::placeholder { color: rgb(var(--mwx-content-faint)); }
html .mwx-input:focus        { outline: none; border-color: rgb(var(--mwx-accent)); }

/* Native dropdown lists don't inherit from the <select> in most browsers */
html.dark select option {
  background-color: rgb(var(--mwx-surface));
  color: rgb(var(--mwx-content));
}

/* Chrome/Safari paint autofilled inputs with a hardcoded pale yellow that
   ignores every background utility on the element. This is a global reset,
   not a component: it applies to every input on every page, and there is no
   class you could put in the markup that would win against it. */
html input:-webkit-autofill,
html input:-webkit-autofill:hover,
html input:-webkit-autofill:focus,
html input:-webkit-autofill:active {
  -webkit-box-shadow: 0 0 0 1000px rgb(var(--mwx-surface-2)) inset !important;
  -webkit-text-fill-color: rgb(var(--mwx-content)) !important;
  caret-color: rgb(var(--mwx-content));
  transition: background-color 5000s ease-in-out 0s;
}

html .mwx-canvas {
  background-color: rgb(var(--mwx-canvas));
  background-image: radial-gradient(rgb(var(--mwx-canvas-dot)) 1px, transparent 1px);
  background-size: 30px 30px;
}

/* ---- Focus ring ----
   The accent's most defensible job. Applied via :focus-visible so mouse
   users never see it. Keep this rule near the top of the component layer
   so individual components can still override outline-offset if needed. */
html .mwx-btn:focus-visible,
html .mwx-icon-btn:focus-visible,
html .mwx-segment:focus-visible,
html .mwx-menu-item:focus-visible {
  outline: 2px solid rgb(var(--mwx-ring));
  outline-offset: 2px;
}

/* At the 24px rung, controls sit 4px apart inside .mwx-segmented and the
   strip. A 2px ring at 2px offset reaches 4px past the box and would touch
   its neighbour, so the ring tightens with the rung. Declared after the rule
   above and at equal specificity, so it wins on source order. */
html .mwx-btn-sm:focus-visible,
html .mwx-icon-btn-sm:focus-visible,
html .mwx-segment-sm:focus-visible {
  outline-width: 1px;
  outline-offset: 1px;
}

/* ---- Uppercase micro-label ----
   Was .mwx-theme-label and .mwx-theme-segment-label, which were the same
   rule written twice. Sits inside a button or segment, so it inherits size
   and weight from the rung and only adds the casing treatment. */
html .mwx-label-caps { letter-spacing: .04em; text-transform: uppercase; }

/* The theme picker used to have its own segmented control here. It was a
   copy of .mwx-segmented / .mwx-segment / .mwx-segment-active with two
   differences that are both Tailwind utilities — full width and equal-width
   items — so the markup composes it instead:
     <div class="mwx-segmented flex w-full">
       <button class="mwx-segment flex-1 justify-center mwx-segment-active">
   Deleting it means the theme picker can never drift from the segmented
   control it is supposed to look like.                                  */

/* ---- Generation settings strip (framework / base file / prompt / php chip) ---- */
/* Holds -sm segments: 24 + 3px padding × 2 + 1px border × 2 = 32px outer,
   so the group itself lands on the bare rung and sits flush next to a plain
   button. Gap is 4px to clear the tightened -sm focus ring. */
html .mwx-segmented {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .1875rem;
  border-radius: .5rem;
  background-color: rgb(var(--mwx-surface));
  border: 1px solid rgb(var(--mwx-border));
}

/* Matches the rounded-2xl / p-1.5 / gap-1 spec used by every other floating
   toolbar group (size-controls, top-action-group). Holds -lg segments.

   Named -toolbar, not -lg: this modifies the CONTAINER's padding and radius,
   it does not move a control to a rung on the size scale. Reusing a size
   suffix for a different axis is how "same suffix, same height" stopped
   being true. -lg kept as an alias until markup is migrated. */
html .mwx-segmented-toolbar,
html .mwx-segmented-lg {
  gap: .25rem;
  padding: .375rem;
  border-radius: 1rem;
}

html .mwx-segment {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  height: 2rem;
  padding: 0 .875rem;
  border-radius: .5rem;
  border: none;
  background: transparent;
  color: rgb(var(--mwx-content-muted));
  font-size: .75rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s ease;
}
html .mwx-segment i { font-size: .875rem; }

/* Matches .mwx-icon-btn-quiet:hover — surface-3 is the one hover step used
   everywhere in this file, so a segment feels like the same kind of control
   as a toolbar icon button. The active segment also picks this up (it has no
   fill of its own), which is correct: its ring is what marks it selected,
   and hover is orthogonal feedback. */
html .mwx-segment:hover {
  background-color: rgb(var(--mwx-surface-3));
  color: rgb(var(--mwx-content));
}

/* The active segment is already marked by its ring, not a fill — hovering
   it should not borrow the inactive hover's background, or selected and
   hovered-but-unselected become visually identical for a moment. Its own
   hover just deepens the ring. */
html .mwx-segment-active:hover {
  background-color: transparent;
  box-shadow: inset 0 0 0 1px rgb(var(--mwx-content-faint));
}

/* Real modifier classes instead of !h-9/!px-4 utility overrides — mixing
   !important utilities with a component that already sets height, padding
   and line-height is what produced the uneven top/bottom spacing last time.

   -lg is what the floating toolbar's icon+label controls (All Pages, Run
   App) use, matching .mwx-icon-btn-lg beside them. -sm is the dense rung for
   the generation-settings strip. */
html .mwx-segment-sm {
  height: 1.5rem;
  padding: 0 .5rem;
  gap: .25rem;
  font-size: .75rem;
  border-radius: .375rem;
}
html .mwx-segment-lg {
  height: 2.5rem;
  padding: 0 1.25rem;
  gap: .5rem;
  font-size: .875rem;
  border-radius: .625rem;
}
html .mwx-segment-xl {
  height: 3rem;
  padding: 0 1.5rem;
  gap: .5rem;
  font-size: 1rem;
  border-radius: .75rem;
}
html .mwx-segment-sm i { font-size: .875rem; }
html .mwx-segment-lg i { font-size: 1.125rem; }
html .mwx-segment-xl i { font-size: 1.25rem; }

html .mwx-segment    svg { width: .875rem;  height: .875rem;  flex-shrink: 0; }
html .mwx-segment-sm svg { width: .875rem;  height: .875rem;  flex-shrink: 0; }
html .mwx-segment-lg svg { width: 1.125rem; height: 1.125rem; flex-shrink: 0; }
html .mwx-segment-xl svg { width: 1.25rem;  height: 1.25rem;  flex-shrink: 0; }

/* Selection is a ring, not a fill. The strip stays one continuous surface
   with the page; what changes on the selected item is a hairline outline
   plus text going from muted to full contrast. This introduces no new
   surface level, so it can't collide with whatever background the strip
   happens to sit on — which is exactly how the old version broke. The ring
   is inset so it can never alter the control's height. */
html .mwx-segment-active {
  background-color: transparent;
  color: rgb(var(--mwx-content));
  box-shadow: inset 0 0 0 1px rgb(var(--mwx-border-strong));
}
html .mwx-segment-active:hover { color: rgb(var(--mwx-content)); }

/* The generation-settings strip used to define its own select, button, chip
   and dot here — four classes that were the -sm rung of components this file
   already had. They are gone; the strip composes from the generic ones. See
   the migration note in the scale comment for the class mapping.

   The strip is a 24px row, so everything in it takes -sm. That was always
   the real rule; naming them strip-* just hid it and let them drift.     */

/* =============================================
   AI Copilot components
   Extracted from the Copilot page's old hand-written stylesheet.
   Same rules as above: tokens only, no hex, no `dark:` anywhere.
   Anything that appeared once in the markup was converted to Tailwind
   utilities instead and is NOT here — these are the pieces that repeat,
   or that JavaScript injects as HTML strings.
   ============================================= */

/* ---- Buttons ----
   HIERARCHY (in order of how often it should appear on a screen):
     .mwx-btn              neutral bordered — the default, use freely
     .mwx-btn-quiet        transparent — toolbars, dismissals
     .mwx-btn-primary      solid accent — ideally ONE per screen/dialog
     .mwx-btn-danger       tinted red — destructive
     .mwx-btn-danger-solid filled red — final confirmation step only
     .mwx-btn-success      tinted green — CONFIRMED success, not an action

   .mwx-btn now carries the neutral treatment itself, so a bare
   `class="mwx-btn"` is already a correct default button. Variants below
   are declared after the base and win on source order.               */
html .mwx-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  height: 2rem;
  padding: 0 .875rem;
  border-radius: .5rem;
  border: 1px solid rgb(var(--mwx-border));
  background-color: rgb(var(--mwx-surface-2));
  color: rgb(var(--mwx-content));
  font-family: inherit;
  font-size: .75rem;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease, transform .1s ease;
}
html .mwx-btn:hover:not(:disabled) {
  background-color: rgb(var(--mwx-surface-3));
  border-color: rgb(var(--mwx-border-strong));
}
html .mwx-btn:active:not(:disabled) { transform: scale(.96); }
html .mwx-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

html .mwx-btn-sm {
  height: 1.5rem;
  padding: 0 .5rem;
  gap: .25rem;
  border-radius: .375rem;
  font-size: .75rem;
}
html .mwx-btn-lg {
  height: 2.5rem;
  padding: 0 1.25rem;
  gap: .5rem;
  border-radius: .625rem;
  font-size: .875rem;
}
html .mwx-btn-xl {
  height: 3rem;
  padding: 0 1.5rem;
  gap: .5rem;
  border-radius: .75rem;
  font-size: 1rem;
}

/* Icon-only .mwx-btn. Drops the label padding and squares off to whatever
   height its rung already set, so a button can shed its text without
   changing height, radius or variant.

   This is NOT a duplicate of .mwx-icon-btn. That class is its own component
   with its own background and border, so it cannot carry -primary or
   -danger. This one is a modifier on a real .mwx-btn, which is what lets a
   labelled action collapse to its icon and expand back while keeping its
   accent — the pattern the builder toolbar uses to keep exactly one worded
   button visible at a time. Reach for .mwx-icon-btn when the button is
   never labelled; reach for this when the label comes and goes. */
html .mwx-btn-square          { width: 2rem;    padding: 0; }
html .mwx-btn-sm.mwx-btn-square { width: 1.5rem; }
html .mwx-btn-lg.mwx-btn-square { width: 2.5rem; }
html .mwx-btn-xl.mwx-btn-square { width: 3rem; }

/* A button-shaped REPORT: it sits in a row of buttons and matches them, but
   it states what happened rather than offering to do anything.

   Leave the `disabled` ATTRIBUTE off when using this. Disabled means "this
   action exists and you may not take it right now", and it renders that with
   cursor: not-allowed — a refusal, aimed at a user who did nothing wrong.
   A finished job is not a refusal. Worse, browsers suppress the `title`
   tooltip on a disabled control, so the sentence explaining the state is the
   one thing a disabled button cannot say. Use aria-disabled instead: screen
   readers still hear that it is not actionable, and the tooltip survives.

   Pair with .mwx-btn-quiet for a resting state the user will look at for the
   rest of the session, and reserve .mwx-btn-success for a result that is
   genuinely worth announcing at the moment it happens — a status that never
   goes away should recede, not celebrate.

   The press animation is suppressed because nothing is being pressed; the
   hover tint is deliberately kept, since it confirms what the pointer is on
   and invites the tooltip that carries the actual explanation. */
html .mwx-btn-static { cursor: default; }
html .mwx-btn-static:active:not(:disabled) { transform: none; }

/* Fully rounded. A shape modifier, not a size one — it deliberately does not
   touch height, so it composes with every rung. Used by the prompt chip. */
html .mwx-btn-pill { border-radius: 9999px; }
html .mwx-btn    i { font-size: .875rem; }
html .mwx-btn-sm i { font-size: .875rem; }
html .mwx-btn-lg i { font-size: 1.125rem; }
html .mwx-btn-xl i { font-size: 1.25rem; }

/* Inline SVG, sized to match the Font Awesome glyph at each rung. The theme
   toggle used to hardcode 1rem here; now every button gets it. */
html .mwx-btn    svg { width: .875rem;  height: .875rem;  flex-shrink: 0; }
html .mwx-btn-sm svg { width: .875rem;  height: .875rem;  flex-shrink: 0; }
html .mwx-btn-lg svg { width: 1.125rem; height: 1.125rem; flex-shrink: 0; }
html .mwx-btn-xl svg { width: 1.25rem;  height: 1.25rem;  flex-shrink: 0; }

/* The one focal point. If a screen has two of these, one of them is wrong. */
html .mwx-btn-primary {
  background-color: rgb(var(--mwx-primary));
  border-color: rgb(var(--mwx-primary));
  color: #fff;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}
html .mwx-btn-primary:hover:not(:disabled) {
  background-color: rgb(var(--mwx-primary-hover));
  border-color: rgb(var(--mwx-primary-hover));
}

/* Explicit neutral. Identical to the base — kept as a name for markup that
   wants to say "deliberately secondary" rather than "unstyled". */
html .mwx-btn-ghost {
  background-color: rgb(var(--mwx-surface-2));
  border-color: rgb(var(--mwx-border));
  color: rgb(var(--mwx-content-muted));
}
html .mwx-btn-ghost:hover:not(:disabled) {
  background-color: rgb(var(--mwx-surface-3));
  border-color: rgb(var(--mwx-border-strong));
  color: rgb(var(--mwx-content));
}

html .mwx-btn-quiet {
  background-color: transparent;
  border-color: transparent;
  color: rgb(var(--mwx-content-faint));
}
html .mwx-btn-quiet:hover:not(:disabled) {
  background-color: rgb(var(--mwx-surface-3));
  border-color: transparent;
  color: rgb(var(--mwx-content));
}

/* NOT an action button. Green here means "this already succeeded".
   Save / Import / Connect should use .mwx-btn or .mwx-btn-primary —
   coloring them green before anything has happened is what drained the
   meaning out of green in the first place. Deliberately no longer a solid
   fill, so existing markup calms down without being edited. */
html .mwx-btn-success {
  background-color: rgb(var(--mwx-success) / .12);
  border-color: rgb(var(--mwx-success) / .35);
  color: rgb(var(--mwx-success-soft));
  box-shadow: none;
}
html .mwx-btn-success:hover:not(:disabled) {
  background-color: rgb(var(--mwx-success) / .2);
  border-color: rgb(var(--mwx-success) / .45);
  color: rgb(var(--mwx-success-soft));
}

/* Destructive, default treatment. */
html .mwx-btn-danger {
  background-color: rgb(var(--mwx-danger) / .12);
  border-color: rgb(var(--mwx-danger) / .35);
  color: rgb(var(--mwx-danger-soft));
}
html .mwx-btn-danger:hover:not(:disabled) {
  background-color: rgb(var(--mwx-danger) / .2);
  border-color: rgb(var(--mwx-danger) / .45);
  color: rgb(var(--mwx-danger-soft));
}

/* Destructive, final confirmation only — the last button in a confirm
   dialog, never a button that merely opens one. */
html .mwx-btn-danger-solid {
  background-color: rgb(var(--mwx-danger-solid));
  border-color: rgb(var(--mwx-danger-solid));
  color: #fff;
}
html .mwx-btn-danger-solid:hover:not(:disabled) {
  background-color: rgb(var(--mwx-danger-hover));
  border-color: rgb(var(--mwx-danger-hover));
}

/* Low-risk removal: neutral at rest, red only on intent.
   Remove an attached image, dismiss a chip, clear a field. */
html .mwx-btn-danger-quiet {
  background-color: transparent;
  border-color: transparent;
  color: rgb(var(--mwx-content-faint));
}
html .mwx-btn-danger-quiet:hover:not(:disabled) {
  background-color: rgb(var(--mwx-danger) / .12);
  border-color: rgb(var(--mwx-danger) / .3);
  color: rgb(var(--mwx-danger-soft));
}

/* Selected state for a labelled button acting as a toggle. Same language as
   .mwx-segment-active and .mwx-icon-btn-active: a ring, not a fill.

   REQUIRES a transparent baseline — pair it with .mwx-btn-quiet (or -ghost).
   On a bare .mwx-btn this is close to a no-op: the base already carries
   surface-2, a border and full-contrast text, so "selected" would read as
   weaker than unselected, and border-strong at rest is indistinguishable
   from the base button's own hover.

   Use this for a standalone toggle (Show grid, Wrap lines). For 2–4 mutually
   exclusive choices reach for .mwx-segmented / .mwx-segment instead — that's
   what it's for. Declared after every -quiet variant so it wins on source
   order, which lets the markup keep .mwx-btn-quiet on all buttons in the
   group instead of dropping it on the selected one. */
html .mwx-btn-active {
  background-color: transparent;
  border-color: rgb(var(--mwx-border-strong));
  color: rgb(var(--mwx-content));
}
html .mwx-btn-active:hover:not(:disabled) {
  background-color: transparent;
  border-color: rgb(var(--mwx-content-faint));
  color: rgb(var(--mwx-content));
}

/* ---- Icon buttons ---- */
html .mwx-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 2rem;
  height: 2rem;
  border-radius: .5rem;
  border: 1px solid rgb(var(--mwx-border));
  background-color: rgb(var(--mwx-surface-2));
  color: rgb(var(--mwx-content-muted));
  font-size: 1rem;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease, transform .1s ease;
}
html .mwx-icon-btn:hover:not(:disabled) {
  background-color: rgb(var(--mwx-surface-3));
  border-color: rgb(var(--mwx-border-strong));
  color: rgb(var(--mwx-content));
}
html .mwx-icon-btn:active:not(:disabled) { transform: scale(.94); }
html .mwx-icon-btn:disabled { opacity: .45; cursor: not-allowed; }

/* Icon-only, so the glyph takes the scale's full icon size — there is no
   label beside it to overpower. */
html .mwx-icon-btn-sm { width: 1.5rem; height: 1.5rem; border-radius: .375rem; font-size: .875rem; }
html .mwx-icon-btn-lg { width: 2.5rem; height: 2.5rem; border-radius: .625rem; font-size: 1.25rem; }
html .mwx-icon-btn-xl { width: 3rem;   height: 3rem;   border-radius: .75rem;  font-size: 1.25rem; }

/* Chromeless icon button for dense toolbars. This is the replacement for
   canvas-manager.js's per-icon color scheme: every icon looks identical,
   hover simply darkens it. */
html .mwx-icon-btn-quiet {
  background-color: transparent;
  border-color: transparent;
  color: rgb(var(--mwx-content-faint));
}
html .mwx-icon-btn-quiet:hover:not(:disabled) {
  background-color: rgb(var(--mwx-surface-3));
  border-color: transparent;
  color: rgb(var(--mwx-content));
}

/* Icon button whose action is destructive: neutral until hovered. */
html .mwx-icon-btn-danger:hover:not(:disabled) {
  background-color: rgb(var(--mwx-danger) / .12);
  border-color: rgb(var(--mwx-danger) / .3);
  color: rgb(var(--mwx-danger-soft));
}

/* Selected state for an icon button acting as a segment (the canvas size
   switcher). Same language as .mwx-segment-active: a ring, not a fill —
   including on hover, where it only deepens the ring instead of picking up
   the general quiet-button hover fill.

   Declared after -quiet so it wins on source order, which lets the markup
   keep .mwx-icon-btn-quiet on every button in the group instead of dropping
   it on the selected one. Uses border-color rather than an inset ring
   because .mwx-icon-btn already reserves a 1px border. */
html .mwx-icon-btn-active {
  background-color: transparent;
  border-color: rgb(var(--mwx-border-strong));
  color: rgb(var(--mwx-content));
}
html .mwx-icon-btn-active:hover:not(:disabled) {
  background-color: transparent;
  border-color: rgb(var(--mwx-content-faint));
  color: rgb(var(--mwx-content));
}

/* ---- Badges / status pills ----
   Tinted, never solid. Use the neutral variant unless the pill is genuinely
   reporting state. These exist so Phase 2 has somewhere to send the
   hardcoded bg-emerald-*/text-amber-* pills in the builders. */
html .mwx-badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  height: 1.5rem;
  padding: 0 .5rem;
  border-radius: 9999px;
  border: 1px solid transparent;
  font-size: .75rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: .02em;
  white-space: nowrap;
  background-color: rgb(var(--mwx-surface-2));
  border-color: rgb(var(--mwx-border));
  color: rgb(var(--mwx-content-muted));
}
html .mwx-badge-primary {
  background-color: rgb(var(--mwx-primary) / .12);
  border-color: rgb(var(--mwx-primary) / .3);
  color: rgb(var(--mwx-primary-soft));
}
html .mwx-badge-success {
  background-color: rgb(var(--mwx-success) / .12);
  border-color: rgb(var(--mwx-success) / .3);
  color: rgb(var(--mwx-success-soft));
}
html .mwx-badge-danger {
  background-color: rgb(var(--mwx-danger) / .12);
  border-color: rgb(var(--mwx-danger) / .3);
  color: rgb(var(--mwx-danger-soft));
}
html .mwx-badge-warning {
  background-color: rgb(var(--mwx-warning) / .12);
  border-color: rgb(var(--mwx-warning) / .3);
  color: rgb(var(--mwx-warning-soft));
}

/* ---- Dropdown menu ----
   The overflow surface behind a toolbar's "…" button, and the home for the
   actions a session touches once or twice — save, load, settings, reset.
   Those were each paying permanent width in the floating toolbar for the
   sake of one click a session, which is the width the canvas wanted back.

   Labelled by construction: every item is icon + words. That is the point of
   moving an action here rather than shrinking it. An icon-only Reset in a
   toolbar asks the user to recognise a trash can and be sure; a menu row can
   simply say "Reset project" — which matters most for the people these
   builders are aimed at, who do not read a glyph vocabulary.

   Placement is the markup's job (absolute inside a relative wrapper) and
   open/close is menu.js's — this file only dresses the surface. */
html .mwx-menu {
  min-width: 13.5rem;
  padding: .375rem;
  border-radius: .875rem;
  border: 1px solid rgb(var(--mwx-border));
  background-color: rgb(var(--mwx-surface));
  box-shadow: var(--mwx-shadow);
  color: rgb(var(--mwx-content));
}
html .mwx-menu-item {
  display: flex;
  align-items: center;
  gap: .625rem;
  width: 100%;
  padding: .5rem .625rem;
  border: 0;
  border-radius: .5rem;
  background-color: transparent;
  color: rgb(var(--mwx-content-muted));
  font-family: inherit;
  font-size: .8125rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
/* The glyph inherits — one grey for the whole row. Giving the icon its own
   (fainter) color made the two halves of a row read as two different states,
   which is exactly the mismatch a resting menu should not have. The row
   brightens as a unit on hover instead, which is what "this one" means. */
html .mwx-menu-item svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
html .mwx-menu-item:hover:not(:disabled) {
  background-color: rgb(var(--mwx-surface-3));
  color: rgb(var(--mwx-content));
}
html .mwx-menu-item:disabled { opacity: .45; cursor: not-allowed; }

/* A trailing note on the row — why an item is unavailable, or what it will
   act on. Pushed right so the labels stay in one column. */
html .mwx-menu-item-note {
  margin-left: auto;
  padding-left: .75rem;
  font-size: .6875rem;
  font-weight: 600;
  color: rgb(var(--mwx-content-faint));
}

/* Destructive rows: neutral-to-red like .mwx-icon-btn-danger, not red at
   rest — the menu should not look alarming just for being open. */
html .mwx-menu-item-danger:hover:not(:disabled) {
  background-color: rgb(var(--mwx-danger) / .12);
  color: rgb(var(--mwx-danger-soft));
}

html .mwx-menu-sep {
  height: 1px;
  margin: .375rem .25rem;
  background-color: rgb(var(--mwx-border));
}

/* ---- Toolbar readout ----
   A non-interactive figure (token count, counters) that has to sit in the
   floating toolbar row beside .mwx-segmented-toolbar and the icon-button
   groups. Those groups are 54px tall — 40px control + 6px padding + 1px
   border on each side — so a readout gets its own class on that rung rather
   than a .mwx-badge patched up with !h-9/!rounded-xl/!px-3 utilities, which
   left it 18px shorter than everything next to it and re-introduced exactly
   the !important-over-a-sized-component mix .mwx-segment-lg exists to avoid.

   Label sits after the value and stays muted: the number is the content, the
   unit is only there to say what it counts. */
html .mwx-toolbar-readout {
  display: inline-flex;
  /* center, not baseline: in a fixed-height flex box, baseline alignment
     puts the shared baseline at the top of the box, so the text rides high
     instead of sitting in the middle. Both parts use line-height 1, so
     centering keeps them optically aligned with each other anyway. */
  align-items: center;
  gap: .375rem;
  height: 3.375rem;
  padding: 0 1rem;
  border-radius: 1rem;
  background-color: rgb(var(--mwx-surface));
  border: 1px solid rgb(var(--mwx-border));
  color: rgb(var(--mwx-content));
  white-space: nowrap;
}
html .mwx-toolbar-readout-value {
  font-size: .875rem;
  font-weight: 700;
  line-height: 1;
  /* Tabular figures so the pill does not twitch as the count grows. */
  font-variant-numeric: tabular-nums;
}
html .mwx-toolbar-readout-label {
  font-size: .6875rem;
  font-weight: 600;
  line-height: 1;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: rgb(var(--mwx-content-muted));
}

/* ---- Status dot ----
   Replaces canvas-manager.js's red/blue/indigo/emerald dot soup. Idle and
   busy are NEUTRAL on purpose — "working" is motion, not a color. Only a
   finished outcome earns a hue. */
html .mwx-status-dot {
  display: inline-block;
  flex: 0 0 auto;
  width: .5rem;
  height: .5rem;
  border-radius: 9999px;
  background-color: rgb(var(--mwx-content-faint));
}
html .mwx-status-dot-busy {
  background-color: rgb(var(--mwx-content-muted));
  animation: mwx-status-pulse 1.4s ease-in-out infinite;
}
/* Absorbed .mwx-strip-dot: "a non-default value is set". One of the few
   places a tiny spot of color is doing real informational work, which is why
   it keeps the accent while ok/warn/error carry semantic hues. */
html .mwx-status-dot-accent { background-color: rgb(var(--mwx-accent)); }
html .mwx-status-dot-ok    { background-color: rgb(var(--mwx-success)); }
html .mwx-status-dot-warn  { background-color: rgb(var(--mwx-warning)); }
html .mwx-status-dot-error { background-color: rgb(var(--mwx-danger)); }

@keyframes mwx-status-pulse {
  0%, 100% { opacity: .35; }
  50%      { opacity: 1; }
}

/* ---- Split-pane handle ---- */
html .mwx-resizer {
  position: relative;
  flex: 0 0 auto;
  width: 2px; /* Physical layout width — shrinks panel distance from 8px to 2px */
  cursor: col-resize;
  background-color: rgb(var(--mwx-border-strong));
  transition: background-color .15s ease;
}

/* Invisible hit target spanning 10px wide so dragging remains effortless */
html .mwx-resizer::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -4px;
  right: -4px;
  z-index: 10;
}

html .mwx-resizer:hover {
  background-color: rgb(var(--mwx-accent));
}

/* ---- Collapsible prompt sections (<details>) ---- */
html .mwx-prompt-section {
  border: 1px solid rgb(var(--mwx-border));
  border-radius: .75rem;
  background-color: rgb(var(--mwx-surface-2));
  overflow: hidden;
}
html .mwx-prompt-section > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .85rem 1rem;
  list-style: none;
  cursor: pointer;
  user-select: none;
  transition: background-color .15s ease;
}
html .mwx-prompt-section > summary::-webkit-details-marker { display: none; }
html .mwx-prompt-section > summary:hover { background-color: rgb(var(--mwx-surface-3)); }
html .mwx-prompt-section-arrow {
  flex: 0 0 auto;
  color: rgb(var(--mwx-content-faint));
  transition: transform .2s ease;
}
html .mwx-prompt-section[open] .mwx-prompt-section-arrow { transform: rotate(180deg); }

/* ---- AI Chat Log (message bubbles + scroll-to-bottom) ---- */
html .mwx-chatlog-scroll {
  display: flex;
  flex-direction: column;
  gap: .75rem;
  padding: 1rem;
  font-size: .8125rem;
}
html .mwx-chatlog-bubble {
  max-width: 85%;
  padding: .75rem 1rem;
  border-radius: 1rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, .05);
}
html .mwx-chatlog-bubble pre,
html .mwx-chatlog-bubble code { white-space: pre-wrap; }
html .mwx-chat-text { white-space: pre-wrap; }
html .mwx-chat-markdown { line-height: 1.8; }
html .mwx-chat-markdown p { margin: 0 0 .8em; }
html .mwx-chat-markdown h4 { font-size: 1em; font-weight: 700; margin: 1em 0 .4em; }
html .mwx-chat-markdown ul { list-style: disc outside; }
html .mwx-chat-markdown ol { list-style: decimal outside; }
html .mwx-chat-markdown ul, html .mwx-chat-markdown ol { padding-left: 1.5em; margin: .4em 0 .8em; }
html .mwx-chat-markdown li { margin: .35em 0; }
html .mwx-chat-markdown pre { padding: .65em; margin: .7em 0; background: rgb(var(--mwx-surface-2)); border-radius: .4em; }
html .mwx-chat-markdown > :first-child { margin-top: 0; }
html .mwx-chat-markdown > :last-child { margin-bottom: 0; }

/* Authorship is already carried by alignment and the asymmetric corner —
   a saturated blue slab for every user turn was doing the same job twice
   and dominating the panel. */
html .mwx-chatlog-bubble-user {
  align-self: flex-end;
  border-bottom-right-radius: .25rem;
  background-color: rgb(var(--mwx-surface-3));
  color: rgb(var(--mwx-content));
}
html .mwx-chatlog-bubble-ai {
  align-self: flex-start;
  border-bottom-left-radius: .25rem;
  background-color: rgb(var(--mwx-surface));
  border: 1px solid rgb(var(--mwx-border));
  color: rgb(var(--mwx-content));
}
html .mwx-chatlog-bubble-system {
  align-self: stretch;
  max-width: 100%;
  background-color: rgb(var(--mwx-surface-2));
  border: 1px solid rgb(var(--mwx-border));
  color: rgb(var(--mwx-content-muted));
  box-shadow: none;
}

html .mwx-chatlog-role-label {
  display: block;
  margin-bottom: .125rem;
  font-size: .625rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  opacity: .5;
}

/* ---- AI "thinking" indicator (shimmering text + bouncing dots) ----
   Shared by every AI tool's chat log — drop this markup into an appended
   chat bubble while a response is in flight:
     <span class="mwx-thinking">
       <span class="mwx-thinking-text">AI is thinking…</span>
       <span class="mwx-thinking-dots" aria-hidden="true"><i></i><i></i><i></i></span>
     </span>
   The text span's innerHTML can be swapped later (e.g. a retry message)
   without losing the shimmer — the animation lives on the class, not the
   content. */
html .mwx-thinking {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  vertical-align: middle;
}
html .mwx-thinking-text {
  background-image: linear-gradient(
    90deg,
    rgb(var(--mwx-content-faint)) 0%,
    rgb(var(--mwx-content)) 50%,
    rgb(var(--mwx-content-faint)) 100%
  );
  background-size: 200% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-style: italic;
  animation: mwx-thinking-shimmer 1.8s ease-in-out infinite;
}
html .mwx-thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  flex-shrink: 0;
}
html .mwx-thinking-dots i {
  display: block;
  width: .35rem;
  height: .35rem;
  border-radius: 9999px;
  background-color: rgb(var(--mwx-content-faint));
  font-style: normal;
  animation: mwx-thinking-bounce 1.1s ease-in-out infinite;
}
html .mwx-thinking-dots i:nth-child(2) { animation-delay: .15s; }
html .mwx-thinking-dots i:nth-child(3) { animation-delay: .3s; }

@keyframes mwx-thinking-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes mwx-thinking-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30%           { transform: translateY(-3px); opacity: 1; }
}

/* =============================================
   Keyframes
   A @keyframes is not a component — it has no declarations of its own to
   inline, and Tailwind has no core utility that defines one. Reference it
   from the markup with an arbitrary animation value, e.g.
   `animate-[mwx-toast-in_.3s_ease-out]`.
   ============================================= */
@keyframes mwx-toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* =============================================
   Theme cross-fade
   Only the always-on surfaces are handled here. For anything else you
   want to cross-fade, add Tailwind's `transition-colors` in the markup —
   now that backgrounds are real utilities, it composes naturally.
   Deliberately excludes border/shadow so dragging cards stays cheap.
   ============================================= */
html body,
html .mwx-input,
html .mwx-canvas {
  transition: background-color .18s ease, color .18s ease;
}

@media (prefers-reduced-motion: reduce) {
  html .mwx-btn,
  html .mwx-icon-btn,
  html .mwx-prompt-section > summary { transition-duration: .01ms; }

  html .mwx-thinking-text   { animation: none; color: rgb(var(--mwx-content-faint)); }
  html .mwx-thinking-dots i { animation: none; opacity: .6; }
  html .mwx-status-dot-busy { animation: none; opacity: .8; }
}

/* ---- Scrollbars ---- */
html ::-webkit-scrollbar        { width: 8px; height: 8px; }
html ::-webkit-scrollbar-track  { background: transparent; }
html ::-webkit-scrollbar-thumb {
  background-color: rgb(var(--mwx-border-strong));
  border-radius: 9999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
html ::-webkit-scrollbar-thumb:hover { background-color: rgb(var(--mwx-content-faint)); }
html ::-webkit-scrollbar-corner      { background: transparent; }
