/* ============================================================================
   app.css — EDITOR CHROME ONLY
   Interactive HTML Document Builder

   This stylesheet styles the APPLICATION UI around the document:
     - the top app bar / toolbar
     - the mode toggle segmented control
     - the document workspace background (muted canvas behind the .document sheet)
     - per-block editing chrome (.block-shell + .block-toolbar)
     - the settings modal/dialog + backdrop
     - the add-block / import dropdown menus
     - file inputs

   It MUST NOT restyle the document's own internals (.document, .doc-meta,
   .statement, .pill, table, .chart, components, …) — those live in document.css.

   Editor chrome is fully hidden for printing (body.printing and @media print)
   so PDF export is clean even though this sheet is editor-only.
   ============================================================================ */

/* ---------------------------------------------------------------------------
   Editor-chrome design tokens.
   Kept INDEPENDENT of document.css so load order never matters. We loosely
   coordinate with the document accent via a fallback chain: if document.css is
   present its --accent wins; otherwise we fall back to our own value.
   --------------------------------------------------------------------------- */
:root {
  /* App-chrome palette */
  --app-accent: var(--accent, #2f6df6);
  --app-accent-deep: var(--accent-deep, #1f4fc4);
  --app-accent-soft: var(--accent-soft, #e7efff);

  --app-bg: #eef0f4;            /* muted workspace canvas behind the sheet */
  --app-surface: #ffffff;       /* bars, menus, dialogs */
  --app-surface-2: #f6f7f9;     /* subtle raised/hover fills */
  --app-surface-3: #eceef2;     /* pressed / active fills */

  --app-ink: #1d2129;           /* primary chrome text */
  --app-ink-soft: #5a6473;      /* secondary chrome text */
  --app-ink-faint: #8a94a6;     /* tertiary / icon text */

  --app-line: #dfe3ea;          /* hairline borders */
  --app-line-strong: #c7cdd8;   /* stronger borders */

  --app-danger: #d6453d;        /* destructive actions */
  --app-danger-soft: #fbe8e7;

  --app-focus: #2f6df6;         /* focus ring color */
  --app-focus-ring: 0 0 0 3px rgba(47, 109, 246, 0.35);

  /* Elevation */
  --app-shadow-1: 0 1px 2px rgba(20, 28, 45, 0.06),
                  0 1px 1px rgba(20, 28, 45, 0.04);
  --app-shadow-2: 0 6px 18px rgba(20, 28, 45, 0.12),
                  0 2px 6px rgba(20, 28, 45, 0.08);
  --app-shadow-3: 0 18px 48px rgba(20, 28, 45, 0.24),
                  0 6px 16px rgba(20, 28, 45, 0.16);

  /* Geometry */
  --app-radius: 8px;
  --app-radius-sm: 6px;
  --app-radius-lg: 12px;

  /* Layout metrics */
  --app-bar-h: 56px;

  /* Motion */
  --app-ease: cubic-bezier(0.2, 0.6, 0.2, 1);
  --app-fast: 120ms;
  --app-med: 180ms;

  /* Editor chrome fonts (independent of document fonts) */
  --app-sans: var(--sans, "Noto Sans", system-ui, -apple-system,
              "Segoe UI", Roboto, Helvetica, Arial, sans-serif);
  --app-mono: var(--mono, "JetBrains Mono", "Noto Sans Mono", ui-monospace,
              SFMono-Regular, Menlo, Consolas, monospace);
}

/* ---------------------------------------------------------------------------
   App shell / global page frame (chrome only — NOT the document sheet)
   --------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

/* Use min-height (not height) so <body> grows with its content. A hard
   height:100% would pin <body> to one viewport, and a position:sticky child
   (.app-bar) can only stay stuck within its parent's box — so the toolbar
   would scroll out of view once you scrolled past the first screenful. */
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--app-sans);
  color: var(--app-ink);
  background: var(--app-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Workspace canvas — the area that scrolls behind/around the document sheet. */
main {
  display: block;
  min-height: calc(100vh - var(--app-bar-h));
  background: var(--app-bg);
  /* subtle dotted texture to read as a "canvas" without distracting */
  background-image: radial-gradient(rgba(20, 28, 45, 0.05) 1px, transparent 1px);
  background-size: 22px 22px;
  padding: 32px 24px 96px;
}

/* The wrapper that centers the document sheet. The .document sheet itself is
   styled in document.css; here we only give it a comfortable max width and an
   editor-context drop shadow / sheet feel. */
#doc-root {
  max-width: 920px;
  margin: 0 auto;
}

/* Give the document a "sheet on a desk" elevation while editing. This targets
   the .document element only for its OUTER framing (shadow / rounding); its
   internals remain owned by document.css. */
#doc-root > .document {
  box-shadow: var(--app-shadow-2);
  border-radius: var(--app-radius-lg);
}

/* ---------------------------------------------------------------------------
   App bar (top toolbar) — sticky
   --------------------------------------------------------------------------- */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--app-bar-h);
  padding: 0 16px;
  background: var(--app-surface);
  border-bottom: 1px solid var(--app-line);
  box-shadow: var(--app-shadow-1);
}

.app-bar .brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.01em;
  color: var(--app-ink);
  white-space: nowrap;
  user-select: none;
}

.app-bar .brand .brand-mark,
.app-bar .brand svg {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  color: var(--app-accent);
}

/* Slot that main.js injects the mode toggle into */
.app-bar .mode-toggle-slot {
  display: inline-flex;
  align-items: center;
}

/* Toolbar groups push to the right; a flexible spacer separates brand/toggle
   from the action cluster. */
.app-bar .spacer {
  flex: 1 1 auto;
}

.app-bar .toolbar,
.app-bar .toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.app-bar .toolbar-sep {
  width: 1px;
  align-self: stretch;
  margin: 10px 4px;
  background: var(--app-line);
}

/* ---------------------------------------------------------------------------
   Buttons (editor chrome)
   .btn is the base; modifiers tune intent/emphasis.
   These are application controls, NOT document .action buttons.
   --------------------------------------------------------------------------- */
.btn,
.app-bar button,
.menu-trigger {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  color: var(--app-ink);
  background: var(--app-surface);
  border: 1px solid var(--app-line-strong);
  border-radius: var(--app-radius-sm);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  transition: background var(--app-fast) var(--app-ease),
              border-color var(--app-fast) var(--app-ease),
              color var(--app-fast) var(--app-ease),
              box-shadow var(--app-fast) var(--app-ease);
}

.btn:hover,
.app-bar button:hover,
.menu-trigger:hover {
  background: var(--app-surface-2);
  border-color: var(--app-line-strong);
}

.btn:active,
.app-bar button:active,
.menu-trigger:active {
  background: var(--app-surface-3);
}

.btn:disabled,
.app-bar button:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Primary / accent button */
.btn-primary {
  color: #fff;
  background: var(--app-accent);
  border-color: var(--app-accent);
}
.btn-primary:hover {
  background: var(--app-accent-deep);
  border-color: var(--app-accent-deep);
}
.btn-primary:active {
  background: var(--app-accent-deep);
}

/* Ghost / borderless icon-ish button */
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--app-surface-2);
  border-color: transparent;
}

/* Destructive button */
.btn-danger {
  color: var(--app-danger);
  background: var(--app-surface);
  border-color: var(--app-line-strong);
}
.btn-danger:hover {
  color: #fff;
  background: var(--app-danger);
  border-color: var(--app-danger);
}

/* Small / icon-only button */
.btn-icon {
  width: 34px;
  padding: 0;
}
.btn-sm {
  height: 28px;
  padding: 0 9px;
  font-size: 12px;
}

/* ---------------------------------------------------------------------------
   Inline text-formatting group (Bold / Italic / Underline / color / highlight)
   --------------------------------------------------------------------------- */
.fmt-group {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.fmt-group .btn-icon {
  width: 30px;
}
.fmt-group .fmt-b { font-weight: 800; }
.fmt-group .fmt-i { font-style: italic; font-family: Georgia, "Times New Roman", serif; }
.fmt-group .fmt-u { text-decoration: underline; }
.fmt-group .fmt-eyedropper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.fmt-group .fmt-eyedropper svg { display: block; }
/* A class selector's `display` would otherwise override the UA `[hidden]` rule,
   leaving a visible-but-dead control. Keep hidden meaning hidden. */
.fmt-group [hidden] { display: none !important; }

/* Color/highlight: a compact swatch label wrapping a native color input. The
   glyph sits above a thin underline tinted to the picked color. */
.fmt-color {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 34px;
  border-radius: var(--app-radius);
  cursor: pointer;
}
.fmt-color:hover {
  background: var(--app-surface-2);
}
.fmt-color .fmt-color-glyph {
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  color: var(--app-ink);
}
.fmt-color.fmt-hl .fmt-color-glyph {
  color: var(--app-ink-soft);
}
/* The native color input fills the swatch but is visually hidden; its own
   value is reflected by the bottom border so the user sees the current color. */
.fmt-color input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}
.fmt-color::after {
  content: "";
  position: absolute;
  left: 5px;
  right: 5px;
  bottom: 5px;
  height: 3px;
  border-radius: 2px;
  background: currentColor;
  pointer-events: none;
}
.fmt-color:focus-within {
  outline: none;
  box-shadow: var(--app-focus-ring);
}

/* Caret affordance on dropdown triggers */
.menu-trigger .caret,
.btn .caret {
  font-size: 10px;
  line-height: 1;
  opacity: 0.7;
}

/* Unified focus treatment for all chrome controls */
.btn:focus-visible,
.app-bar button:focus-visible,
.menu-trigger:focus-visible,
.block-toolbar button:focus-visible,
.mode-toggle button:focus-visible,
.menu [role="menuitem"]:focus-visible,
.menu button:focus-visible,
.dialog button:focus-visible,
.dialog [tabindex]:focus-visible {
  outline: 2px solid transparent;
  box-shadow: var(--app-focus-ring);
}

/* Remove default outline only where we provide a ring; keep it everywhere else */
.btn:focus,
.app-bar button:focus,
.menu-trigger:focus {
  outline: none;
}

/* ---------------------------------------------------------------------------
   Mode toggle — segmented control (Edit / Run)
   modes.js builds two real <button>s with aria-pressed inside .mode-toggle.
   --------------------------------------------------------------------------- */
.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--app-surface-3);
  border: 1px solid var(--app-line);
  border-radius: 999px;
}

.mode-toggle button {
  appearance: none;
  -webkit-appearance: none;
  height: 28px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--app-ink-soft);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--app-fast) var(--app-ease),
              color var(--app-fast) var(--app-ease),
              box-shadow var(--app-fast) var(--app-ease);
}

.mode-toggle button:hover {
  color: var(--app-ink);
}

/* Active segment — driven by aria-pressed for accessibility correctness */
.mode-toggle button[aria-pressed="true"],
.mode-toggle button.is-active {
  color: var(--app-ink);
  background: var(--app-surface);
  box-shadow: var(--app-shadow-1);
}

.mode-toggle button:focus-visible {
  outline: none;
  box-shadow: var(--app-focus-ring);
}

/* ---------------------------------------------------------------------------
   Body mode flags (set by modes.js / main.js on <body> or #doc-root):
     - .mode-edit shows block chrome
     - .mode-run / .is-running hides all editing chrome so preview is clean
   We hide chrome in run mode here as a defensive layer; render.js also omits
   it. This guarantees Run preview looks like the export.
   --------------------------------------------------------------------------- */
body.mode-run .block-toolbar,
body.mode-run .block-shell::before,
body.is-running .block-toolbar,
.mode-run .block-toolbar {
  display: none !important;
}

body.mode-run .block-shell,
body.is-running .block-shell,
.mode-run .block-shell {
  outline: none !important;
  cursor: default;
}

/* In run mode, drop the editor sheet shadow framing back to whatever
   document.css defines (we simply stop adding our own extra outline cues). */

/* ---------------------------------------------------------------------------
   Page bar — switch / add / rename / delete the pages of the open document.
   EDIT chrome only: hidden in run mode (readers use the in-document .page-nav)
   and when printing. Built by main.js into <nav id="page-bar">.
   --------------------------------------------------------------------------- */
.page-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  max-width: 880px;
  margin: 18px auto 0;
  padding: 0 16px;
}
body.mode-run .page-bar,
body.printing .page-bar {
  display: none;
}

.page-tab {
  display: inline-flex;
  align-items: center;
  background: var(--app-surface);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius-sm);
  overflow: hidden;
}
.page-tab.is-active {
  border-color: var(--app-accent);
  box-shadow: 0 0 0 1px var(--app-accent);
}
.page-tab-label {
  border: 0;
  background: transparent;
  font: inherit;
  color: var(--app-ink);
  padding: 6px 10px;
  cursor: pointer;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page-tab.is-active .page-tab-label {
  font-weight: 600;
}
.page-tab-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--app-ink-soft);
  padding: 6px 8px;
  font-size: 12px;
  line-height: 1;
}
.page-tab-btn:hover:not(:disabled) {
  color: var(--app-accent);
}
.page-tab-btn:disabled {
  opacity: 0.35;
  cursor: default;
}
.page-tab-add {
  border: 1px dashed var(--app-line);
  background: transparent;
  border-radius: var(--app-radius-sm);
  font: inherit;
  color: var(--app-ink-soft);
  padding: 6px 12px;
  cursor: pointer;
}
.page-tab-add:hover {
  color: var(--app-accent);
  border-color: var(--app-accent);
}

/* ---------------------------------------------------------------------------
   Link dialog — opened by the toolbar 🔗 Link button (or Ctrl/Cmd-K) to link
   the current text selection to a page (#slug) or a URL. Reuses the modal
   .settings-overlay / .settings-dialog shell; the rules below style its body.
   --------------------------------------------------------------------------- */
.link-dialog {
  max-width: 460px;
}
.link-dialog-sel {
  margin: 0 0 14px;
  padding: 8px 10px;
  background: var(--app-bg);
  border-radius: var(--app-radius-sm);
  color: var(--app-ink-soft);
  font-style: italic;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.link-dialog-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--app-ink-faint);
  margin: 0 0 8px;
}
.link-dialog-pages {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.link-dialog-url {
  display: flex;
  gap: 8px;
}
.link-dialog input.link-url {
  flex: 1;
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--app-line);
  border-radius: 5px;
  background: #fff;
  color: var(--app-ink);
}
.link-dialog button {
  font: inherit;
  cursor: pointer;
  padding: 8px 14px;
  border: 1px solid var(--app-line);
  border-radius: 5px;
  background: var(--app-surface);
  color: var(--app-ink);
}
.link-dialog button:hover {
  border-color: var(--app-accent);
  color: var(--app-accent);
}
/* Page target buttons — the primary, one-click way to link to a page. */
.link-dialog .link-page {
  background: var(--app-accent-soft, #e7f0fa);
  border-color: transparent;
  color: var(--app-accent-deep, #1f4fc4);
  font-weight: 600;
}
.link-dialog .link-page:hover {
  background: var(--app-accent);
  color: #fff;
  border-color: var(--app-accent);
}
.link-dialog .link-apply {
  background: var(--app-accent);
  border-color: var(--app-accent);
  color: #fff;
}
.link-dialog .link-apply:hover {
  color: #fff;
  opacity: 0.92;
}
.link-dialog .settings-dialog-footer .link-unlink:hover {
  border-color: var(--app-danger, #c5443c);
  color: var(--app-danger, #c5443c);
}

/* ---------------------------------------------------------------------------
   Block shell — per-block editing chrome (EDIT mode only)
   render.js wraps each block:
     <div class="block-shell" data-block-id data-block-type>
       <div class="block-toolbar"> … toolbar <button data-action> … </div>
       <the block element>
     </div>
   We surface a hover/focus outline and reveal the toolbar on hover/focus-within.
   --------------------------------------------------------------------------- */
.block-shell {
  position: relative;
  border-radius: var(--app-radius);
  outline: 1.5px solid transparent;
  outline-offset: 2px;
  transition: outline-color var(--app-fast) var(--app-ease),
              background var(--app-fast) var(--app-ease);
}

/* Hover & focus reveal a soft outline so blocks feel "pickable" */
.block-shell:hover {
  outline-color: var(--app-accent-soft);
}

.block-shell:focus-within {
  outline-color: var(--app-accent);
}

/* Selected block (edit.js may toggle .is-selected) */
.block-shell.is-selected {
  outline-color: var(--app-accent);
  background: color-mix(in srgb, var(--app-accent-soft) 35%, transparent);
}

/* Subtle type label in the corner while hovering (uses data-block-type).
   Inert and pointer-transparent; purely informational. */
.block-shell::before {
  content: attr(data-block-type);
  position: absolute;
  top: 0;
  left: 8px;
  transform: translateY(-50%);
  z-index: 3;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--app-ink-faint);
  background: var(--app-surface);
  border: 1px solid var(--app-line);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--app-fast) var(--app-ease);
}

.block-shell:hover::before,
.block-shell:focus-within::before {
  opacity: 1;
}

/* The SELECTED block keeps its type pill visible and accented, so the user can
   always see what Copy/Cut/Paste & ＋ Add will act on — and whether they landed
   on the component or its enclosing section/container. Wins over a parent
   shell's hover label because only the innermost shell carries .is-selected. */
.block-shell.is-selected::before {
  opacity: 1;
  color: #fff;
  background: var(--app-accent);
  border-color: var(--app-accent);
}

/* ---------------------------------------------------------------------------
   Block toolbar — compact button row, appears on hover / focus-within
   Buttons carry data-action: move-up, move-down, duplicate, delete,
   settings, add-after.
   --------------------------------------------------------------------------- */
.block-toolbar {
  position: absolute;
  top: -14px;
  right: 8px;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: var(--app-surface);
  border: 1px solid var(--app-line);
  border-radius: 999px;
  box-shadow: var(--app-shadow-2);
  opacity: 0;
  transform: translateY(-3px);
  pointer-events: none;
  transition: opacity var(--app-med) var(--app-ease),
              transform var(--app-med) var(--app-ease);
}

.block-shell:hover > .block-toolbar,
.block-shell:focus-within > .block-toolbar,
.block-toolbar:focus-within {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.block-toolbar button {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  color: var(--app-ink-soft);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--app-fast) var(--app-ease),
              color var(--app-fast) var(--app-ease);
}

.block-toolbar button:hover {
  color: var(--app-ink);
  background: var(--app-surface-2);
}

.block-toolbar button:active {
  background: var(--app-surface-3);
}

.block-toolbar button[data-action="delete"]:hover {
  color: #fff;
  background: var(--app-danger);
}

.block-toolbar button:focus-visible {
  outline: none;
  box-shadow: var(--app-focus-ring);
}

/* A label-only divider inside the toolbar if needed */
.block-toolbar .sep {
  width: 1px;
  height: 16px;
  margin: 0 2px;
  background: var(--app-line);
}

/* ---------------------------------------------------------------------------
   Element editor (imported docs) — a highlight box over the selected element
   plus a floating action toolbar. Both are fixed-position, appended to <body>
   by element-edit.js, and shown only while an element is selected.
   --------------------------------------------------------------------------- */
.el-overlay {
  position: fixed;
  z-index: 60;
  display: none;
  pointer-events: none; /* never intercept clicks meant for the document */
  border: 2px solid var(--app-accent);
  border-radius: var(--app-radius-sm);
  background: color-mix(in srgb, var(--app-accent-soft) 22%, transparent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--app-accent) 20%, transparent);
}
.el-overlay.is-visible { display: block; }

.el-toolbar {
  position: fixed;
  z-index: 61;
  display: none;
  align-items: center;
  gap: 2px;
  padding: 3px 4px;
  background: var(--app-surface);
  border: 1px solid var(--app-line);
  border-radius: 999px;
  box-shadow: var(--app-shadow-2);
}
.el-toolbar.is-visible { display: inline-flex; }

.el-toolbar .el-tag {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px 0 4px;
  font-family: var(--app-mono, monospace);
  font-size: 11px;
  font-weight: 700;
  color: var(--app-accent-deep);
}

.el-toolbar button {
  appearance: none;
  -webkit-appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  color: var(--app-ink-soft);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: background var(--app-fast) var(--app-ease),
              color var(--app-fast) var(--app-ease);
}
.el-toolbar button:hover {
  color: var(--app-ink);
  background: var(--app-surface-2);
}
.el-toolbar button:active { background: var(--app-surface-3); }
.el-toolbar button.is-danger:hover { color: #fff; background: var(--app-danger); }
.el-toolbar button:focus-visible { outline: none; box-shadow: var(--app-focus-ring); }

/* Hide the element editor's chrome when printing / in run mode (body class). */
body.mode-run .el-overlay,
body.mode-run .el-toolbar,
body.printing .el-overlay,
body.printing .el-toolbar { display: none !important; }

/* ---------------------------------------------------------------------------
   "Add block" inline affordance (a per-shell add-after, or the global menu)
   data-action="add-after" buttons render as a thin "+ insert" bar.
   --------------------------------------------------------------------------- */
.add-affordance,
.block-toolbar button[data-action="add-after"] {
  color: var(--app-accent);
}

.add-block-line {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 22px;
  margin: 4px auto;
  opacity: 0;
  transition: opacity var(--app-fast) var(--app-ease);
}

.block-shell:hover + .add-block-line,
.add-block-line:hover,
.add-block-line:focus-within {
  opacity: 1;
}

.add-block-line button {
  height: 22px;
  padding: 0 12px;
  font-size: 12px;
  color: var(--app-accent);
  background: var(--app-surface);
  border: 1px dashed var(--app-line-strong);
  border-radius: 999px;
  cursor: pointer;
}

.add-block-line button:hover {
  background: var(--app-accent-soft);
  border-color: var(--app-accent);
}

/* ---------------------------------------------------------------------------
   Dropdown menus — Add ▾, Import ▾, Open list, etc.
   Structure (built by main.js):
     <div class="menu-wrap">
       <button class="menu-trigger" aria-haspopup="menu" aria-expanded>…</button>
       <div class="menu" role="menu" hidden> … items … </div>
     </div>
   The .menu is shown when not [hidden] / when .is-open is present.
   --------------------------------------------------------------------------- */
.menu-wrap {
  position: relative;
  display: inline-flex;
}

.menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 200;
  min-width: 200px;
  max-height: min(60vh, 420px);
  overflow: auto;
  padding: 6px;
  background: var(--app-surface);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow-2);
}

/* Right-aligned menus (e.g. export/open near the right edge) */
.menu.menu-right {
  left: auto;
  right: 0;
}

/* Hidden state — support both [hidden] and an .is-open convention */
.menu[hidden] {
  display: none;
}
.menu-wrap:not(.is-open) > .menu:not([open]):not(.is-open) {
  /* no-op guard; visibility is primarily driven by [hidden] from main.js */
}

.menu .menu-section-title {
  padding: 6px 10px 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--app-ink-faint);
}

.menu [role="menuitem"],
.menu button.menu-item,
.menu .menu-item {
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  color: var(--app-ink);
  background: transparent;
  border: 0;
  border-radius: var(--app-radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--app-fast) var(--app-ease),
              color var(--app-fast) var(--app-ease);
}

.menu [role="menuitem"]:hover,
.menu .menu-item:hover,
.menu [role="menuitem"][data-active="true"] {
  background: var(--app-accent-soft);
  color: var(--app-accent-deep);
}

.menu [role="menuitem"]:focus-visible,
.menu .menu-item:focus-visible {
  outline: none;
  box-shadow: var(--app-focus-ring);
}

.menu .menu-item .item-icon {
  flex: 0 0 auto;
  width: 18px;
  text-align: center;
  color: var(--app-ink-faint);
}

.menu .menu-item .item-desc {
  margin-left: auto;
  padding-left: 16px;
  font-size: 11px;
  color: var(--app-ink-faint);
}

.menu .menu-divider {
  height: 1px;
  margin: 6px 4px;
  background: var(--app-line);
}

/* Named-doc rows in the Open menu often pair a label + a delete button */
.menu .doc-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.menu .doc-row .doc-open {
  flex: 1 1 auto;
}
.menu .doc-row .doc-delete {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  color: var(--app-ink-faint);
}
.menu .doc-row .doc-delete:hover {
  color: #fff;
  background: var(--app-danger);
}
.menu .doc-meta-line {
  font-size: 11px;
  color: var(--app-ink-faint);
}
.menu .menu-empty {
  padding: 12px 10px;
  font-size: 12.5px;
  color: var(--app-ink-faint);
  text-align: center;
}

/* ---------------------------------------------------------------------------
   File inputs — hidden native input + styled label/button pattern.
   import.js / main.js trigger the hidden input; we style any visible variant.
   --------------------------------------------------------------------------- */
.file-input {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* If a visible file input is shown inside a dialog, give it a tidy look */
.dialog input[type="file"] {
  font-family: inherit;
  font-size: 13px;
  color: var(--app-ink-soft);
}
.dialog input[type="file"]::file-selector-button {
  margin-right: 10px;
  height: 30px;
  padding: 0 12px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--app-ink);
  background: var(--app-surface-2);
  border: 1px solid var(--app-line-strong);
  border-radius: var(--app-radius-sm);
  cursor: pointer;
}
.dialog input[type="file"]::file-selector-button:hover {
  background: var(--app-surface-3);
}

/* ---------------------------------------------------------------------------
   Settings dialog / modal + backdrop
   Used for component editorPanel (and any other editor settings).
   Structure (built by edit.js):
     <div class="dialog-backdrop">
       <div class="dialog" role="dialog" aria-modal="true">
         <div class="dialog-head"> <h2 class="dialog-title"> … <button data-action="close"> </div>
         <div class="dialog-body"> editorPanel(...) </div>
         <div class="dialog-foot"> actions </div>
       </div>
     </div>
   Works whether implemented as a div overlay OR a native <dialog>.
   --------------------------------------------------------------------------- */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 20px 40px;
  background: rgba(18, 24, 38, 0.42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: app-fade-in var(--app-med) var(--app-ease);
}

.dialog-backdrop[hidden] {
  display: none;
}

.dialog,
dialog.dialog {
  width: min(560px, 100%);
  max-height: 84vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
  background: var(--app-surface);
  color: var(--app-ink);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius-lg);
  box-shadow: var(--app-shadow-3);
  animation: app-pop-in var(--app-med) var(--app-ease);
}

/* Native <dialog> backdrop styling (when a real <dialog> element is used) */
dialog.dialog::backdrop {
  background: rgba(18, 24, 38, 0.42);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--app-line);
}

.dialog-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--app-ink);
}

.dialog-head .dialog-close,
.dialog [data-action="close"] {
  margin-left: auto;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  color: var(--app-ink-faint);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}
.dialog-head .dialog-close:hover,
.dialog [data-action="close"]:hover {
  color: var(--app-ink);
  background: var(--app-surface-2);
}

.dialog-body {
  padding: 18px;
  overflow: auto;
}

.dialog-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--app-line);
  background: var(--app-surface-2);
}

/* Generic form controls inside dialogs / editor panels (component editorPanel
   returns an HTMLElement that lives here). These style only chrome forms. */
.dialog .field,
.editor-panel .field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 14px;
}

.dialog .field > label,
.editor-panel .field > label,
.dialog label.field-label,
.editor-panel label.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--app-ink-soft);
}

.dialog input[type="text"],
.dialog input[type="number"],
.dialog input[type="url"],
.dialog input[type="search"],
.dialog select,
.dialog textarea,
.editor-panel input[type="text"],
.editor-panel input[type="number"],
.editor-panel input[type="url"],
.editor-panel input[type="search"],
.editor-panel select,
.editor-panel textarea {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  color: var(--app-ink);
  background: var(--app-surface);
  border: 1px solid var(--app-line-strong);
  border-radius: var(--app-radius-sm);
  padding: 8px 10px;
  transition: border-color var(--app-fast) var(--app-ease),
              box-shadow var(--app-fast) var(--app-ease);
}

.dialog textarea,
.editor-panel textarea {
  min-height: 90px;
  resize: vertical;
  line-height: 1.5;
}

.dialog input:focus-visible,
.dialog select:focus-visible,
.dialog textarea:focus-visible,
.editor-panel input:focus-visible,
.editor-panel select:focus-visible,
.editor-panel textarea:focus-visible {
  outline: none;
  border-color: var(--app-accent);
  box-shadow: var(--app-focus-ring);
}

.dialog .field-hint,
.editor-panel .field-hint {
  font-size: 11px;
  color: var(--app-ink-faint);
}

/* Repeatable rows (e.g. languages/tabs lists in a component editor) */
.editor-panel .row-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.editor-panel .row-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
  background: var(--app-surface-2);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius-sm);
}
.editor-panel .row-item .row-fields {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.editor-panel .row-item .row-remove {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  color: var(--app-ink-faint);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}
.editor-panel .row-item .row-remove:hover {
  color: #fff;
  background: var(--app-danger);
}
.editor-panel .add-row {
  align-self: flex-start;
  margin-top: 4px;
}

/* Generic block style panel (color / spacing / sizing / typography knobs) */
/* Component settings dialog: stacked "Settings" + "Style" sections. */
.settings-section + .settings-section {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--app-line);
}
.settings-section-title {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--app-ink-soft, var(--app-ink));
}

.block-style-panel .style-group {
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--app-line);
}
.block-style-panel .style-group:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}
.block-style-panel .style-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--app-ink-faint);
  margin-bottom: 10px;
}
.block-style-panel .style-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.block-style-panel .style-color-row input[type="color"] {
  width: 44px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--app-line-strong);
  border-radius: var(--app-radius-sm);
  background: var(--app-surface);
  cursor: pointer;
}
.block-style-panel .style-clear {
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 5px 10px;
  color: var(--app-ink-soft);
  background: var(--app-surface-2);
  border: 1px solid var(--app-line-strong);
  border-radius: var(--app-radius-sm);
}
.block-style-panel .style-clear:hover {
  color: var(--app-ink);
  border-color: var(--app-accent);
}

/* ---------------------------------------------------------------------------
   Component edit-mode overlay
   components.js (EDIT mode) adds an inert overlay label "⚙ <label>" on a
   component instance and makes inner controls non-interactive. We style the
   overlay; selection is handled by the surrounding .block-shell.
   --------------------------------------------------------------------------- */
.comp-overlay,
.component-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 6px;
  pointer-events: none; /* clicks fall through to the block-shell for selection */
  background: transparent;
  border-radius: var(--app-radius);
}

.comp-overlay .comp-label,
.component-overlay .comp-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--app-accent-deep);
  background: var(--app-accent-soft);
  border: 1px solid color-mix(in srgb, var(--app-accent) 40%, transparent);
  border-radius: 999px;
}

/* When a component is in edit mode, dim its live controls slightly so it reads
   as "configurable, not clickable". This styles only the editor wrapper, not
   the component's own internal classes. */
body.mode-edit .block-shell[data-block-type="component"] {
  cursor: pointer;
}

/* ---------------------------------------------------------------------------
   Toast / status (autosave + dirty indicator) — optional chrome
   --------------------------------------------------------------------------- */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 1100;
  transform: translateX(-50%) translateY(8px);
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  background: rgba(24, 30, 42, 0.94);
  border-radius: 999px;
  box-shadow: var(--app-shadow-2);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--app-med) var(--app-ease),
              transform var(--app-med) var(--app-ease);
}
.app-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.save-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--app-ink-faint);
  white-space: nowrap;
}
.save-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--app-line-strong);
}
.save-status.is-dirty .dot {
  background: var(--app-accent);
}
.save-status.is-saved .dot {
  background: var(--green, #2e9e5b);
}

/* ---------------------------------------------------------------------------
   Animations
   --------------------------------------------------------------------------- */
@keyframes app-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes app-pop-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------------------------------------------------------------------------
   Responsive — narrow viewports
   --------------------------------------------------------------------------- */
@media (max-width: 720px) {
  :root {
    --app-bar-h: auto;
  }
  .app-bar {
    flex-wrap: wrap;
    gap: 8px;
    height: auto;
    padding: 10px 12px;
  }
  .app-bar .spacer {
    flex-basis: 100%;
    height: 0;
  }
  .app-bar .toolbar {
    flex-wrap: wrap;
  }
  main {
    padding: 18px 12px 80px;
  }
  #doc-root {
    max-width: 100%;
  }
  .btn .btn-label,
  .app-bar button .btn-label {
    /* allow main.js to wrap long labels in .btn-label to hide on small screens */
  }
  .dialog {
    width: 100%;
  }
  .dialog-backdrop {
    padding: 4vh 12px 24px;
  }
}

@media (max-width: 480px) {
  .app-bar .brand .brand-text {
    display: none; /* keep just the mark to save room */
  }
}

/* ---------------------------------------------------------------------------
   Reduced motion
   --------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------------------------------------------------------------------------
   PRINT — hide ALL editor chrome so PDF export is clean.
   Two layers:
     (1) body.printing  — set transiently by export-pdf.js before window.print()
     (2) @media print   — the real print pipeline
   Either path removes the app bar, block chrome, menus, dialogs, toasts, and
   collapses the workspace canvas so only the .document sheet remains.
   We deliberately DO NOT style .document internals (document.css owns print
   rules for the document body / components).
   --------------------------------------------------------------------------- */
body.printing .app-bar,
body.printing .block-toolbar,
body.printing .add-block-line,
body.printing .comp-overlay,
body.printing .component-overlay,
body.printing .menu,
body.printing .dialog-backdrop,
body.printing .app-toast,
body.printing .save-status {
  display: none !important;
}

body.printing main {
  padding: 0 !important;
  background: #fff !important;
  background-image: none !important;
}

body.printing .block-shell {
  outline: none !important;
  background: transparent !important;
}
body.printing .block-shell::before {
  display: none !important;
}

body.printing #doc-root {
  max-width: none;
  margin: 0;
}
body.printing #doc-root > .document {
  box-shadow: none !important;
  border-radius: 0 !important;
}

@media print {
  .app-bar,
  .block-toolbar,
  .add-block-line,
  .comp-overlay,
  .component-overlay,
  .menu,
  .menu-wrap,
  .dialog-backdrop,
  .app-toast,
  .save-status,
  .mode-toggle {
    display: none !important;
  }

  html,
  body {
    background: #fff !important;
  }

  main {
    min-height: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    background-image: none !important;
  }

  #doc-root {
    max-width: none !important;
    margin: 0 !important;
  }

  #doc-root > .document {
    box-shadow: none !important;
    border-radius: 0 !important;
  }

  .block-shell {
    outline: none !important;
    background: transparent !important;
    break-inside: avoid;
  }
  .block-shell::before {
    display: none !important;
  }
}

/* ===========================================================================
   INTEGRATION BRIDGE
   Styles for the class names actually emitted by edit.js (settings dialog) and
   components.js (editor panels + component edit-mode wrappers) and render.js
   (.block-add) that the sections above did not yet cover. Purely additive and
   built from the same --app-* tokens, so nothing above needs editing.
   =========================================================================== */

/* --- Component instance host (components.js renderComponent) ------------- */
.component-block { position: relative; }
.component-missing {
  padding: 10px 12px;
  font-size: 13px;
  color: var(--app-danger);
  background: var(--app-danger-soft);
  border: 1px dashed var(--app-danger);
  border-radius: var(--app-radius-sm);
}
/* Edit mode shows the live markup but inert, so a click selects the block. */
.component-inert { pointer-events: none; }

/* The "⚙ <label>" text sits directly on .component-overlay — render it as a
   small chip at the component's top-right instead of a full-cover layer. */
.component-edit > .component-overlay {
  inset: 6px 6px auto auto;
  width: auto;
  height: auto;
  padding: 2px 9px;
  color: var(--app-accent-deep);
  background: var(--app-accent-soft);
  border: 1px solid var(--app-line-strong);
  border-radius: 999px;
}

/* --- Settings modal (edit.js openSettings) ------------------------------ */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 20px 40px;
  background: rgba(18, 24, 38, 0.42);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: app-fade-in var(--app-med) var(--app-ease);
}
.settings-dialog {
  width: min(560px, 100%);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--app-surface);
  color: var(--app-ink);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius-lg);
  box-shadow: var(--app-shadow-3);
  animation: app-pop-in var(--app-med) var(--app-ease);
}
.settings-dialog-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--app-line);
}
.settings-dialog-title { margin: 0; font-size: 15px; font-weight: 700; }
.settings-dialog-close {
  margin-left: auto;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  color: var(--app-ink-faint);
  background: transparent;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}
.settings-dialog-close:hover { color: var(--app-ink); background: var(--app-surface-2); }
.settings-dialog-body { padding: 18px; overflow: auto; }
.settings-dialog-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--app-line);
  background: var(--app-surface-2);
}
.settings-dialog-done {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 16px;
  color: #fff;
  background: var(--app-accent);
  border: 1px solid var(--app-accent-deep);
  border-radius: var(--app-radius-sm);
}
.settings-dialog-done:hover { background: var(--app-accent-deep); }
.settings-dialog-done:focus-visible,
.settings-dialog-close:focus-visible { outline: none; box-shadow: var(--app-focus-ring); }

/* --- Component editor panels (components.js editorPanel) ----------------- */
.comp-editor { display: flex; flex-direction: column; gap: 12px; }
.comp-field { display: flex; flex-direction: column; gap: 5px; }
.comp-field-label { font-size: 12px; font-weight: 600; color: var(--app-ink-soft); }
.comp-input {
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 13px;
  color: var(--app-ink);
  background: var(--app-surface);
  border: 1px solid var(--app-line-strong);
  border-radius: var(--app-radius-sm);
  padding: 8px 10px;
  transition: border-color var(--app-fast) var(--app-ease),
              box-shadow var(--app-fast) var(--app-ease);
}
.comp-textarea { min-height: 64px; resize: vertical; line-height: 1.5; }
.comp-input:focus-visible {
  outline: none;
  border-color: var(--app-accent);
  box-shadow: var(--app-focus-ring);
}
.comp-lang-row,
.comp-tab-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
  padding: 10px;
  background: var(--app-surface-2);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius-sm);
}
.comp-lang-row .comp-field,
.comp-tab-row .comp-field { flex: 1 1 120px; min-width: 0; }
.comp-lang-row .comp-field:has(input[type="radio"]),
.comp-tab-row .comp-field:has(input[type="radio"]) { flex: 0 0 auto; }
.comp-btn {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 7px 12px;
  color: var(--app-ink);
  background: var(--app-surface);
  border: 1px solid var(--app-line-strong);
  border-radius: var(--app-radius-sm);
}
.comp-btn:hover { background: var(--app-surface-2); }
.comp-btn:focus-visible { outline: none; box-shadow: var(--app-focus-ring); }
.comp-btn-danger { color: var(--app-danger); border-color: var(--app-danger); }
.comp-btn-danger:hover { color: #fff; background: var(--app-danger); }

/* --- Per-shell "＋ add block after" affordance (render.js) --------------- */
.block-add {
  appearance: none;
  -webkit-appearance: none;
  position: absolute;
  left: 50%;
  bottom: -11px;
  transform: translateX(-50%);
  z-index: 4;
  width: 22px;
  height: 22px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  color: var(--app-accent-deep);
  background: var(--app-surface);
  border: 1px solid var(--app-line-strong);
  border-radius: 999px;
  opacity: 0;
  transition: opacity var(--app-fast) var(--app-ease);
}
.block-shell:hover > .block-add,
.block-shell:focus-within > .block-add { opacity: 1; }
.block-add:hover { color: #fff; background: var(--app-accent); border-color: var(--app-accent); }
.block-add:focus-visible { opacity: 1; outline: none; box-shadow: var(--app-focus-ring); }

/* --- Editor UI language switch (i18n) ----------------------------------- */
.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--app-surface-2);
  border: 1px solid var(--app-line);
  border-radius: 999px;
}
.lang-switch-btn {
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  padding: 5px 10px;
  color: var(--app-ink-soft);
  background: transparent;
  border: 0;
  border-radius: 999px;
  transition: color var(--app-fast) var(--app-ease),
              background var(--app-fast) var(--app-ease);
}
.lang-switch-btn:hover { color: var(--app-ink); }
.lang-switch-btn.is-active { color: #fff; background: var(--app-accent); }
.lang-switch-btn:focus-visible { outline: none; box-shadow: var(--app-focus-ring); }

/* --- Imported-document WYSIWYG toolbar (embed-edit.js) ------------------- */
.embed-toolbar {
  position: sticky;
  top: var(--app-bar-h);
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  margin-bottom: 8px;
  background: var(--app-surface);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow-1);
}
.embed-tool {
  appearance: none;
  -webkit-appearance: none;
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  color: var(--app-ink);
  background: var(--app-surface);
  border: 1px solid var(--app-line-strong);
  border-radius: var(--app-radius-sm);
}
.embed-tool:hover { background: var(--app-surface-2); }
.embed-tool:focus-visible { outline: none; box-shadow: var(--app-focus-ring); }
.embed-tool.b { font-weight: 700; }
.embed-tool.i { font-style: italic; }
.embed-tool.u { text-decoration: underline; }
.embed-color {
  width: 32px;
  height: 28px;
  padding: 2px;
  background: none;
  border: 1px solid var(--app-line-strong);
  border-radius: var(--app-radius-sm);
  cursor: pointer;
}
.embed-sep {
  width: 1px;
  height: 20px;
  margin: 0 3px;
  background: var(--app-line);
}

/* Link control: 🔗 button + compact dropdown (jump targets, URL field, unlink).
   Kept small + scrollable so a long view list never covers the page. */
.embed-link-wrap {
  position: relative;
  display: inline-flex;
}
.embed-link-pop {
  /* Pinned to the right margin (out of the centered document column) so it never
     covers the page content. `top` is set by JS to sit just under the toolbar. */
  position: fixed;
  right: 16px;
  z-index: 1100;
  width: 256px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--app-surface);
  border: 1px solid var(--app-line);
  border-radius: var(--app-radius-sm);
  box-shadow: var(--app-shadow-1, 0 8px 28px rgba(0, 0, 0, 0.18));
}
.embed-link-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--app-ink-soft);
}
/* Jump targets as a scrollable vertical list. */
.embed-link-targets {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 184px;
  overflow-y: auto;
  margin: 0 -2px;
}
.embed-link-target {
  display: block;
  width: 100%;
  min-width: 0;
  height: auto;
  padding: 7px 9px;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 14.5px;
  line-height: 1.3;
  color: var(--app-ink);
  background: transparent;
  border: 0;
  border-radius: var(--app-radius-sm);
}
.embed-link-target::before {
  content: "→ ";
  color: var(--app-ink-faint);
}
.embed-link-target:hover {
  background: var(--app-accent-soft, #e7f0fa);
  color: var(--app-accent-deep, #1f4fc4);
}
.embed-link-pop hr,
.embed-link-sep {
  border: 0;
  border-top: 1px solid var(--app-line);
  margin: 2px 0;
}
.embed-link-row {
  display: flex;
  gap: 6px;
}
.embed-link-row .embed-tool {
  height: 32px;
  font-size: 14px;
}
.embed-link-url {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 9px;
  font: inherit;
  font-size: 14px;
  color: var(--app-ink);
  background: #fff;
  border: 1px solid var(--app-line-strong);
  border-radius: var(--app-radius-sm);
}
/* Unlink: a quiet full-width action, not a loud button. */
.embed-link-pop .link-unlink {
  width: 100%;
  height: auto;
  padding: 7px 9px;
  font-size: 13.5px;
  color: var(--app-ink-soft);
}
.embed-link-pop .link-unlink:hover {
  color: var(--app-danger, #c5443c);
  border-color: var(--app-danger, #c5443c);
}

/* Hide the bridge chrome in preview / print. */
body.mode-run .block-add { display: none; }
body.printing .settings-overlay,
body.printing .block-add { display: none !important; }
@media print {
  .settings-overlay,
  .block-add { display: none !important; }
  .component-overlay { display: none !important; }
}
