/* ============================================================================
   editor.css — the form editor screen.

   Kept apart from management.css because it is the one screen with a layout of
   its own: a three-column workbench that has to fill the viewport exactly, with
   the canvas as the only thing that scrolls.

   The palette still comes from site.css (colours, buttons, inputs), so when the
   design competition of chapter 7 is decided this file needs no change — the
   variables under it do.
   ========================================================================== */

.editorScreen {
    display: flex;
    flex-direction: column;
    /* the management layout gives #inner its own padding; the editor wants the height */
    height: calc(100vh - 7rem);
    min-height: 30rem;
    gap: 0.5rem;
}

/* --------------------------------------------------------------- toolbars -- */

.editorBar, .stepBar, .canvasBar {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.editorBar { border-bottom: 0.08rem solid var(--glass-line, #dde3ea); padding-bottom: 0.5rem; }

.editorName { font-size: 1.25rem; font-weight: 700; }

.barSpacer { flex: 1 1 auto; }

.badgeWarn {
    background: #fff4e5;
    color: #8a5300;
    border: 0.08rem solid #e8a33d;
    border-radius: 1rem;
    padding: 0.1rem 0.7rem;
    font-size: 0.85rem;
}

.staticLinkRow { font-size: 0.9rem; }
.staticLinkRow a { direction: ltr; unicode-bidi: embed; overflow-wrap: anywhere; }

.stepTabs { display: flex; gap: 0.25rem; flex-wrap: wrap; }

.stepTab {
    border: 0.08rem solid var(--glass-line, #dde3ea);
    border-bottom: none;
    border-radius: var(--radius-s, 0.35rem) var(--radius-s, 0.35rem) 0 0;
    background: transparent;
    padding: 0.35rem 0.9rem;
    cursor: pointer;
}

.stepTab.active { background: var(--glass-2, rgba(0, 0, 0, 0.05)); font-weight: 700; }

/* ------------------------------------------------------------- the body --- */

.editorBody {
    display: grid;
    /* palette · canvas · element panel — the canvas takes everything that is left */
    grid-template-columns: 10rem minmax(0, 1fr) 22rem;
    gap: 0.6rem;
    flex: 1 1 auto;
    min-height: 0;              /* without this the grid refuses to shrink and the page scrolls */
}

/* a form that does not exist yet has nothing to edit — only the details panel matters */
.editorBody.noForm .palette,
.editorBody.noForm .canvasArea,
.editorBody.noForm .elementPanel { opacity: 0.35; pointer-events: none; }

.palette, .elementPanel {
    border: 0.08rem solid var(--glass-line, #dde3ea);
    border-radius: var(--radius-s, 0.35rem);
    padding: 0.6rem;
    overflow: auto;
    min-height: 0;
}

.palette h2 { font-size: 0.95rem; margin: 0 0 0.5rem; }

.paletteItem {
    display: block;
    width: 100%;
    text-align: start;
    margin-bottom: 0.3rem;
    padding: 0.4rem 0.6rem;
    border: 0.08rem solid var(--glass-line, #dde3ea);
    border-radius: var(--radius-s, 0.35rem);
    background: var(--glass-2, rgba(0, 0, 0, 0.03));
    cursor: pointer;
    font: inherit;
}

.paletteItem:hover { background: var(--glass-3, rgba(0, 0, 0, 0.08)); }

.canvasArea { display: flex; flex-direction: column; gap: 0.4rem; min-height: 0; }

.modeChoice { display: inline-flex; align-items: center; gap: 0.25rem; }

.canvas, .sourcePane {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    border: 0.08rem solid var(--glass-line, #dde3ea);
    border-radius: var(--radius-s, 0.35rem);
    background: #fff;
}

.canvas { display: block; }

/* ------------------------------------------------------ the element panel -- */

.panelHint { color: var(--ink-soft, #555); font-size: 0.88rem; margin: 0 0 0.6rem; }

.panelHead { font-weight: 700; display: flex; justify-content: space-between; gap: 0.5rem; }
.panelId { direction: ltr; font-family: Consolas, monospace; color: var(--ink-soft, #555); }

/* the ancestor chain: latin tag names inside a right-to-left panel, so it is its own island */
.crumbs {
    direction: ltr;
    text-align: left;
    font-family: Consolas, monospace;
    font-size: 0.8rem;
    background: var(--glass-2, rgba(0, 0, 0, 0.04));
    border-radius: var(--radius-s, 0.35rem);
    padding: 0.3rem 0.5rem;
    margin: 0.4rem 0;
    overflow-wrap: anywhere;
}

.crumbs.kids { direction: rtl; text-align: start; }

.panelTabs { display: flex; gap: 0.2rem; border-bottom: 0.15rem solid var(--glass-line, #dde3ea); }

.panelTab {
    border: none;
    background: transparent;
    padding: 0.35rem 0.7rem;
    cursor: pointer;
    font: inherit;
    color: var(--ink-soft, #555);
}

.panelTab.active {
    color: inherit;
    font-weight: 700;
    box-shadow: inset 0 -0.15rem 0 var(--accent, #17a398);
}

.panelBody { padding-top: 0.6rem; }

.propGrid { display: grid; grid-template-columns: 1fr; gap: 0.15rem; }
.propGrid label { font-size: 0.85rem; color: var(--ink-soft, #555); margin-top: 0.35rem; }
.propGrid input[type=text], .propGrid input[type=number], .propGrid select { width: 100%; }
.propGrid input[type=checkbox] { justify-self: start; }

.groupPick { margin-top: 0.8rem; display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.groupPick > span { width: 100%; font-size: 0.85rem; color: var(--ink-soft, #555); }
.groupPick label { display: inline-flex; align-items: center; gap: 0.2rem; }

/* the raw attribute table */
.attrRow { display: grid; grid-template-columns: 7rem 1fr auto; gap: 0.3rem; align-items: center; margin-bottom: 0.25rem; }
.attrName { direction: ltr; font-family: Consolas, monospace; font-size: 0.82rem; overflow-wrap: anywhere; }
.attrRow input { width: 100%; direction: ltr; }
.attrNew { grid-template-columns: 7rem 1fr auto; }
.attrDrop, .attrAdd { border: none; background: transparent; cursor: pointer; font: inherit; }
.attrDrop { color: #d6203c; font-weight: 700; }
.attrAdd { color: var(--accent, #17a398); font-weight: 700; }

.contentText { width: 100%; direction: ltr; font-family: Consolas, monospace; }

.panelActions { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.8rem; border-top: 0.08rem solid var(--glass-line, #dde3ea); padding-top: 0.6rem; }
.panelActions button { font: inherit; padding: 0.25rem 0.6rem; cursor: pointer; border: 0.08rem solid var(--glass-line, #dde3ea); border-radius: 1rem; background: transparent; }
.panelActions button:hover { background: var(--glass-2, rgba(0, 0, 0, 0.06)); }

/* ------------------------------------------------------------- overlays --- */

/* The top padding clears the page header, and it is load-bearing rather than
   decorative: #upperPanel is sticky with z-index:50 (site.css), while this overlay
   is a plain fixed box with none — so a card that is `height: 100%` has its whole
   head row, tab strip and ✕ painted OVER by the header. Starting below the bar
   fixes that without introducing a z-index the rest of the app does not use. */
.editorOverlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 16, 32, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    padding-block-start: 5.5rem;
}

.editorOverlay[hidden] { display: none; }

.overlayCard {
    background: var(--card, #fff);
    color: var(--ink, #1e212b);
    border-radius: var(--radius-m, 0.6rem);
    padding: 1rem 1.2rem;
    width: min(60rem, 100%);
    max-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    overflow: auto;
}

.overlayCard.wide { width: min(90rem, 100%); height: 100%; }

.overlayHead { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.overlayHead h2 { margin: 0; font-size: 1.15rem; }
.overlayClose { margin-inline-start: auto; border: none; background: transparent; font-size: 1.1rem; cursor: pointer; }

.overlayFoot { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-top: auto; }

/* Label and control are SIBLINGS in the markup, not wrapped pairs, so the column
   count has to be fixed at two — an auto-fill track count would put a label in a
   control's column the moment the card changed width, and the whole panel would
   read as nonsense. */
.detailsGrid {
    display: grid;
    grid-template-columns: minmax(9rem, 14rem) 1fr;
    align-items: center;
    gap: 0.35rem 1rem;
}

.detailsGrid label { font-size: 0.95rem; color: var(--ink-soft, #555); margin: 0; }
.detailsGrid input, .detailsGrid select { width: 100%; }
.detailsGrid .checkRow { display: flex; align-items: center; margin: 0; }

@media (max-width: 40rem) {
    .detailsGrid { grid-template-columns: 1fr; }
}

.groupBoxes { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.3rem; }
.groupBoxes label { display: inline-flex; align-items: center; gap: 0.2rem; }

.jsonText { width: 100%; flex: 1 1 20rem; min-height: 20rem; direction: ltr; font-family: Consolas, monospace; }
.versionList { width: 100%; direction: ltr; font-family: Consolas, monospace; }

.codeTabs { display: flex; gap: 0.2rem; flex-wrap: wrap; }
.codeTab, .previewTab {
    border: 0.08rem solid var(--glass-line, #dde3ea);
    border-radius: 1rem;
    background: transparent;
    padding: 0.2rem 0.8rem;
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
}
.codeTab.active, .previewTab.active { background: var(--accent, #17a398); color: #fff; border-color: transparent; }

.monacoHost, .previewFrame { flex: 1 1 auto; width: 100%; min-height: 24rem; border: 0.08rem solid var(--glass-line, #dde3ea); }
.previewFrame { background: #fff; }

/* ⚠ THE reason both code editors showed an empty white pane (measured 25/08).
   Monaco lays its text out in an absolutely positioned layer and assumes an LTR containing
   block. Inheriting direction:rtl from <html dir="rtl">, that layer lands at left ≈ 16,776,165px
   — off screen — so the editor is alive, the model holds the text, the DOM looks right, and a
   person sees nothing. Code is not right-to-left: every other latin/code island in this file
   (.panelId, .crumbs, .attrName, .contentText, .jsonText, .tplPage) already says so; the two
   Monaco hosts were the ones that did not. */
.sourcePane, .monacoHost { direction: ltr; }

/* -------------------------------------------------------- pdf template ---- */

/* The page is held at its true authoring size — 790x1117 — so one screen pixel is
   one stored unit and the coordinates need no scaling anywhere. It is therefore
   the one thing here that is allowed to be measured in px rather than rem. */

/* This card is sized in px, and only this one: the page inside it is 790 px wide by
   contract, so the room it needs is a pixel count and not a multiple of the font.
   It also does not scroll itself — .tplBody does — so the head, the warning line and
   the close button stay put while the page is being worked on. */
.overlayCard.tplCard {
    width: min(1500px, 100%);
    overflow: hidden;
}

.tplScopePick { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }
.tplScopePick select { max-width: 22rem; }

.tplBody {
    display: grid;
    grid-template-columns: 13rem minmax(0, 1fr) 17rem;
    gap: 0.6rem;
    flex: 1 1 auto;
    min-height: 0;
}

.tplFields, .tplSide {
    border: 0.08rem solid var(--glass-line, #dde3ea);
    border-radius: var(--radius-s, 0.35rem);
    padding: 0.6rem;
    overflow: auto;
    min-height: 0;
}

.tplFields h3, .tplSide h3 { font-size: 0.95rem; margin: 0 0 0.5rem; }

.tplItem {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    padding: 0.3rem 0.5rem;
    margin-bottom: 0.2rem;
    border: 0.08rem solid var(--glass-line, #dde3ea);
    border-radius: var(--radius-s, 0.35rem);
    background: var(--glass-2, rgba(0, 0, 0, 0.03));
    cursor: grab;
    font-size: 0.88rem;
    touch-action: none;                 /* the pointer gesture is a drag, not a scroll */
    user-select: none;
}

.tplItem:hover { background: var(--glass-3, rgba(0, 0, 0, 0.08)); }
.tplItem.placed { border-inline-start: 0.25rem solid var(--accent, #17a398); }
.tplItem.active { outline: 0.12rem solid var(--accent, #17a398); }
.tplItem.tplDragging { opacity: 0.4; }

.tplBadge { font-size: 0.75rem; color: var(--ink-soft, #555); white-space: nowrap; }
.tplItem.here .tplBadge { color: var(--accent, #17a398); font-weight: 700; }

.tplPageArea { display: flex; flex-direction: column; gap: 0.4rem; min-height: 0; }
.tplBar { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.tplName { font-family: Consolas, monospace; direction: ltr; unicode-bidi: embed; }

.tplScroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    background: #a0a0a0;                /* the legacy's grey desk, so the page edge is visible */
    border-radius: var(--radius-s, 0.35rem);
    padding: 0.5rem;
}

/* Width is fixed at 790 and the HEIGHT follows the page's own proportions, because
   that is exactly how DocService maps the overlay: one uniform scale taken from
   pageWidthPt / 790. A4 lands on 1117 (the default below, for when no page is
   showing yet); a Letter template is simply shorter, and its coordinates still
   line up. */
.tplPage {
    position: relative;
    direction: ltr;                     /* left/top are physical here, whatever the app's direction */
    width: 790px;
    min-height: 1117px;
    margin: 0 auto;
    background: #fff;
    box-shadow: 0 0 0.5rem rgba(0, 0, 0, 0.35);
}

.tplImage { display: block; width: 790px; height: auto; }

.tplChip {
    position: absolute;
    box-sizing: border-box;
    padding: 0 0.1rem;
    font-family: Arial, sans-serif;
    font-size: 0.8rem;
    line-height: 1.2;
    color: #0033cc;
    background: rgba(240, 240, 240, 0.75);
    border: 0.06rem dashed #0033cc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.tplChip.active { background: rgba(23, 163, 152, 0.25); border-style: solid; }
.tplChip.tplDragging { opacity: 0.3; }

/* a tick box prints an X, not its value — show it as what it will be */
.tplChip.radio, .tplChip.checkbox { background: transparent; }
.tplChip.radio::before, .tplChip.checkbox::before { content: 'X'; }

/* The one that follows the pointer. Fixed, so it is not clipped by the scroller it
   started in, and transparent to hit-testing so the drop lands on the page. */
.tplGhost { position: fixed; pointer-events: none; opacity: 0.85; }

.tplSide .tplDrop { margin-bottom: 0.6rem; }
.tplAvailableRow { display: block; font-size: 0.85rem; color: var(--ink-soft, #555); }
.tplAvailableRow select { width: 100%; direction: ltr; }
.tplFileActions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.5rem; }

@media (max-width: 70rem) {
    .tplBody { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------ narrow ------ */

@media (max-width: 70rem) {
    .editorBody { grid-template-columns: 1fr; grid-template-rows: auto minmax(20rem, 1fr) auto; }
    .editorScreen { height: auto; }
    .palette { display: flex; flex-wrap: wrap; gap: 0.3rem; }
    .paletteItem { width: auto; }
    .palette h2 { width: 100%; }
}
