/*
 * ADMIN REDESIGN Step 12 — Pages (page builder).
 *
 * Token-driven inner layout only (the shared kit owns cards / buttons / fields
 * / badges / data-table / .menu). New reusable pattern documented in
 * DESIGN-SYSTEM.md: the .block-card builder. Everything is scoped under .main
 * so it inherits the light-content tokens. No hardcoded hex; no admin.css growth.
 */

/* ── LIST ─────────────────────────────────────────────────────────────── */

.main .pages-card { overflow-x: auto; }
.main .pages-table th:last-child,
.main .pages-table td:last-child { width: 1%; white-space: nowrap; }

.main .pages-title {
    font-weight: 600;
    color: var(--color-text);
}

.main .pages-title-line {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

.main .pages-system-badge {
    font-size: 10px;
}

.main .pages-actions {
    display: flex;
    gap: 2px;
    align-items: center;
    justify-content: flex-end;
}

.main .pages-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    text-align: center;
    padding: var(--space-2xl, 40px) var(--space-lg);
}
.main .pages-empty .btn { margin-top: var(--space-sm); }

/* ── EDITOR shell ─────────────────────────────────────────────────────── */

.main .pages-editor {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

/* Sticky top bar — pins to the top of the .main scroller so the page identity
   + Save/Preview/Published never scroll away. Opaque (page-canvas fill) so block
   content scrolls cleanly under it; the bottom hairline + soft shadow lift it. */
.main .pages-editor__bar {
    position: sticky;
    /* .main is the scroll container and carries padding, so sticky top:0 would
       pin to its content-box edge (inside the padding) and leak content above.
       Offset by the negative of .main's padding-top so the bar pins to the true
       visible top. (matches admin.css .main padding: --space-xl desktop). */
    top: calc(-1 * var(--space-xl));
    z-index: 5;
    display: flex;
    align-items: center;
    gap: var(--space-base);
    flex-wrap: wrap;
    padding: var(--space-base) 0;
    background: var(--color-background);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 6px 10px -8px rgba(16, 24, 40, 0.18);
}

.main .pages-editor__back { flex: 0 0 auto; }

.main .pages-editor__identity {
    flex: 1 1 220px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.main .pages-editor__eyebrow {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
}
.main .pages-editor__title {
    font-size: var(--text-lg);
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.main .pages-editor__bar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Unsaved-changes indicator — amber dot + label, carries text so it never
   relies on colour alone. The inline-flex display would otherwise beat the UA
   [hidden] rule, so re-hide it explicitly when clean. */
.main .pages-editor__dirty {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-sm);
    color: var(--color-warning);
    white-space: nowrap;
}
.main .pages-editor__dirty[hidden] { display: none; }
.main .pages-editor__dirty-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-warning);
}

/* ── EDITOR body: the visual builder ─────────────────────────────────── */

/* Compact settings strip (under the sticky bar). */
.main .pages-settings-strip {
    display: flex;
    flex-wrap: wrap;
    /* flex-start so the slug field's "/page/<slug>" hint can hang BELOW its
       input without pushing the input up relative to the hint-less columns —
       every label + input lines up on one tidy row. */
    align-items: flex-start;
    gap: var(--space-base);
    padding: var(--space-base) 0 var(--space-lg);
}
.main .pages-settings-strip .field { gap: 4px; margin: 0; }
/* Slug's "/page/<slug>" helper: a quiet hint hanging below the input, matching
   the kit field hint, without disturbing the aligned input row above it. */
.main .pages-settings-strip .field__hint { margin-top: 2px; }
.main .pages-settings-strip .field__label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    font-weight: 600;
}
.main .pages-settings-strip .select { min-width: 150px; }
.main .pages-settings-strip .field:first-child { flex: 1 1 180px; max-width: 300px; }
.main .pages-settings-strip__note {
    margin: 0 0 0 auto;
    max-width: 240px;
    align-self: center;
    font-size: 11.5px;
    line-height: 1.45;
    color: var(--color-text-muted);
}
.main .pages-full-lobby-preset {
    flex: 1 1 260px;
    max-width: 360px;
    align-self: center;
    display: grid;
    gap: 6px;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--surface-sunken);
}
.main .pages-full-lobby-preset[hidden] { display: none; }
.main .pages-full-lobby-preset__head {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
}
.main .pages-full-lobby-preset__btn { flex: 0 0 auto; }
.main .pages-full-lobby-preset__state {
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.main .pages-full-lobby-preset__state.is-applied { color: var(--color-success); }
.main .pages-full-lobby-preset__hint {
    margin: 0;
    font-size: 11.5px;
    line-height: 1.4;
    color: var(--color-text-muted);
}

/* Working area: palette | canvas. (Per-widget config now opens in a modal, so
   the canvas reclaims the old drawer column and gets noticeably more room.) */
.main .pages-builder {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: var(--space-lg);
    align-items: start;
}
.main .pages-builder .is-hidden { display: none !important; }

/* Palette rail. */
.main .pages-builder__palette {
    position: sticky;
    top: 0;
    align-self: start;
    max-height: calc(100vh - 88px);
    overflow: auto;
    padding: var(--space-base);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--surface-raised);
}
.main .pgwb-palette__h {
    margin: 0 0 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
}
.main .pgwb-palette__hint {
    margin: 0 0 14px;
    font-size: 11px;
    line-height: 1.45;
    color: var(--color-text-muted);
}
.main .pgwb-palette__hint svg { width: 11px; height: 11px; vertical-align: -1px; color: #9E77ED; }
.main .pgwb-grp { margin-bottom: 14px; }
.main .pgwb-grp__l {
    margin: 0 0 7px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--color-text-secondary);
}
.main .pgwb-grp__l::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 2px;
    background: var(--fam, #98A2B3);
}
.main .pgwb-chips { display: flex; flex-direction: column; gap: 6px; }
.main .pgwb-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 9px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--surface-raised);
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    text-align: left;
    color: var(--color-text);
    cursor: grab;
    transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}
.main .pgwb-chip:hover { border-color: #D0D5DD; box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.main .pgwb-chip:focus-visible { outline: 0; box-shadow: var(--shadow-glow); }
.main .pgwb-chip.is-dragging { opacity: 0.5; }
.main .pgwb-chip__grip { flex: none; display: flex; color: #C2C7D0; }
.main .pgwb-chip__grip svg { width: 13px; height: 13px; }
.main .pgwb-chip__ic {
    width: 24px;
    height: 24px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 6px;
    color: var(--fam, #475467);
    background: color-mix(in srgb, var(--fam, #98A2B3) 14%, var(--surface-raised));
}
.main .pgwb-chip__ic svg { width: 14px; height: 14px; }
.main .pgwb-chip__t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main .pgwb-chip__lock { flex: none; margin-left: auto; display: flex; color: #9E77ED; }
.main .pgwb-chip__lock svg { width: 13px; height: 13px; }

/* Canvas column: toolbar + framed live-page mirror. */
.main .pages-builder__canvas { min-width: 0; display: grid; gap: var(--space-base); }
.main .pages-canvas__toolbar { display: flex; align-items: center; gap: var(--space-base); flex-wrap: wrap; }
.main .pages-canvas__toolbar-hint { margin: 0; font-size: 11.5px; color: var(--color-text-muted); }
.main .pages-canvas-frame {
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--surface-raised);
    box-shadow: var(--shadow-md);
}
.main .pages-canvas-frame__chrome {
    height: 34px;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 0 12px;
    background: var(--surface-sunken);
    border-bottom: 1px solid var(--color-border);
}
.main .pages-canvas-frame__dot { width: 9px; height: 9px; border-radius: 50%; background: var(--color-border); }
.main .pages-canvas-frame__url {
    margin-left: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 10.5px;
    color: var(--color-text-muted);
    font-family: var(--font-mono, ui-monospace, Menlo, monospace);
}
.main .pages-canvas-cols {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr) 210px;
    gap: 14px;
    padding: 14px;
    align-items: start;
}
/* The canvas mirrors the live page: it carries only the rails the current
   Layout enables, and the main column resizes to fill the rest. Disabled rails
   are removed (hidden host), never shown as greyed placeholder columns. */
.main .pages-canvas-cols[data-rails="left"]  { grid-template-columns: 210px minmax(0, 1fr); }
.main .pages-canvas-cols[data-rails="right"] { grid-template-columns: minmax(0, 1fr) 210px; }
.main .pages-canvas-cols[data-rails="none"]  { grid-template-columns: minmax(0, 1fr); }
.main .pgwb-col { min-width: 0; }
.main .pgwb-col[hidden] { display: none; }
.main .pgwb-col__l,
.main .pgwb-col__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 0 0 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--color-text-muted);
}
.main .pgwb-col__count { font-variant-numeric: tabular-nums; color: #98A2B3; }
.main .pages-canvas__add { padding: 5px 10px; font-size: 12px; }

/* Visual ⇄ Code segmented toggle. Active pill = raised white + soft shadow;
   gold stays reserved for primary actions + focus. */
.main .pages-mode-toggle {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    background: var(--surface-sunken);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}
.main .pages-mode-toggle__btn {
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    background: transparent;
    padding: 5px 14px;
    font-size: var(--text-sm);
    font-weight: 500;
    font-family: inherit;
    color: var(--color-text-secondary);
    border-radius: calc(var(--radius-md) - 2px);
    cursor: pointer;
    transition: background-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
}
.main .pages-mode-toggle__btn:hover { color: var(--color-text); }
.main .pages-mode-toggle__btn[aria-pressed="true"] {
    background: var(--surface-raised);
    color: var(--color-text);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}
.main .pages-mode-toggle__btn:focus-visible { outline: 0; box-shadow: var(--shadow-glow); }

/* Reusable link picker used by page blocks and sidebar widgets. It still
   writes one URL string; server validators keep the security boundary. */
.main .pages-link-picker,
.modal-overlay .pages-link-picker {
    display: grid;
    gap: 7px;
}
.main .pages-link-picker__segment,
.modal-overlay .pages-link-picker__segment {
    display: inline-flex;
    width: max-content;
    max-width: 100%;
    gap: 2px;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--surface-sunken);
}
.main .pages-link-picker__mode,
.modal-overlay .pages-link-picker__mode {
    appearance: none;
    border: 0;
    border-radius: calc(var(--radius-md) - 2px);
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.2;
    padding: 5px 10px;
    white-space: nowrap;
}
.main .pages-link-picker__mode[aria-pressed="true"],
.modal-overlay .pages-link-picker__mode[aria-pressed="true"] {
    background: var(--surface-raised);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
}
.main .pages-link-picker__mode:focus-visible,
.modal-overlay .pages-link-picker__mode:focus-visible {
    outline: 0;
    box-shadow: var(--shadow-glow);
}
.main .pages-link-picker__field,
.modal-overlay .pages-link-picker__field,
.main .pages-link-picker__input,
.modal-overlay .pages-link-picker__input,
.main .pages-link-picker__select,
.modal-overlay .pages-link-picker__select {
    width: 100%;
    min-width: 0;
}

/* Code (block source) pane — full-width editor surface in Code mode. */
.main .pages-code-pane { display: grid; gap: var(--space-sm); }

/* Code mode collapses the palette|canvas grid to a single full-width column.
   With the palette set to display:none, the canvas would otherwise auto-place
   into the leftover 240px palette track and the editor would render as a narrow
   left sliver — this lets the editor use the whole canvas area instead. */
.main .pages-builder--code { grid-template-columns: minmax(0, 1fr); }

.main .pages-code {
    min-height: clamp(420px, calc(100vh - 300px), 880px);
    width: 100%;
    box-sizing: border-box;
    line-height: 1.65;
}

/* Editor-grade dark surface for the JSON source — overrides the light kit
   .code-block treatment, scoped to the full-width code mode only. */
.main .pages-builder--code .pages-code {
    font-size: 13px;
    color: #E7ECF7;
    background: var(--sidebar-bg, #0E1322);
    background-image: linear-gradient(180deg, var(--sidebar-bg, #0E1322), var(--sidebar-bg-end, #141B2D));
    border: 1px solid #28324C;
    border-radius: var(--radius-lg);
    padding: var(--space-md) var(--space-lg);
    caret-color: var(--color-accent);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 10px 28px rgba(13, 18, 32, 0.14);
}
.main .pages-builder--code .pages-code::selection { background: rgba(245, 200, 66, 0.30); }
.main .pages-builder--code textarea.pages-code:focus-visible {
    outline: 0;
    border-color: var(--color-accent);
    box-shadow: var(--shadow-glow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* Compact help bar sitting above the editor. */
.main .pages-code-pane .callout {
    margin: 0;
    padding: var(--space-sm) var(--space-md);
    font-size: var(--text-xs, 12px);
    line-height: 1.5;
}
.main .pages-code__error {
    margin: 0;
    color: var(--color-danger);
    font-size: var(--text-sm);
}
.main .pages-code__error[hidden] { display: none; }

.main .pages-blocks {
    display: grid;
    gap: var(--space-base);
}

.menu__group-label {
    padding: 6px 10px 3px;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

/* ── Block picker (grid variant of .menu) ─────────────────────────────────
 * Scoped to .menu--block-picker only — the other admin .menu popovers keep
 * their vertical-list rendering. Turns the long "Add block" list into a
 * compact, scannable tile grid grouped Basic / Elements. */
.menu--block-picker {
    width: min(432px, calc(100vw - 16px));
    min-width: 0;
    max-width: calc(100vw - 16px);
    padding: 8px;
    gap: 2px;
    overflow: auto;
    overscroll-behavior: contain;
}
.menu--block-picker .menu__group-label {
    padding: 8px 6px 5px;
}
.menu--block-picker .menu__group-label:first-child {
    padding-top: 4px;
}
.menu--block-picker .block-picker__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
    gap: 6px;
    padding: 0 2px 4px;
}
.menu--block-picker .block-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-height: 80px;
    padding: 12px 8px;
    background: var(--surface-raised, #FFFFFF);
    border: 1px solid #E4E7EC;
    border-radius: var(--radius-md);
    color: #101828;
    font-family: inherit;
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.25;
    text-align: center;
    cursor: pointer;
    transition: background-color 140ms ease, border-color 140ms ease, transform 90ms ease;
}
.menu--block-picker .block-tile__icon {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    background: #F9FAFB;
    color: #667085;
}
.menu--block-picker .block-tile__icon svg { width: 18px; height: 18px; }
.menu--block-picker .block-tile__label { display: block; }
.menu--block-picker .block-tile:hover { background: #F9FAFB; border-color: #D0D5DD; }
.menu--block-picker .block-tile:focus-visible {
    outline: 0;
    border-color: rgba(245, 200, 66, 0.65);
    box-shadow: 0 0 0 3px rgba(245, 200, 66, 0.35);
}
.menu--block-picker .block-tile:active { transform: translateY(1px); }

/* ── Empty canvas state ───────────────────────────────────────────────── */

.main .pages-canvas__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    text-align: center;
    padding: var(--space-2xl, 40px) var(--space-lg);
    background: var(--surface-sunken);
    border: 1.5px dashed var(--color-border);
    border-radius: var(--radius-lg);
}
.main .pages-canvas__empty-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-bottom: var(--space-xs);
    border-radius: 50%;
    background: var(--surface-raised);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
}
.main .pages-canvas__empty-title {
    margin: 0;
    font-weight: 600;
    color: var(--color-text);
}
.main .pages-canvas__empty-hint {
    margin: 0;
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}
.main .pages-canvas__empty .btn { margin-top: var(--space-sm); }

/* ── Sidebar drop zones + placed widget cards + config drawer ─────────── */

.main .pgwb-zone {
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-height: 120px;
    padding: 8px;
    border: 1.5px dashed #D0D5DD;
    border-radius: 10px;
    background: var(--surface-sunken);
    transition: border-color 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}
.main .pgwb-zone.is-focused { border-color: color-mix(in srgb, var(--color-accent) 60%, var(--color-border)); }
.main .pgwb-zone.is-over {
    border-color: var(--color-accent);
    background: color-mix(in srgb, var(--color-accent) 8%, var(--surface-sunken));
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--color-accent) 45%, transparent);
}
.main .pgwb-zone__empty {
    margin: 0;
    padding: 12px 6px;
    text-align: center;
    line-height: 1.5;
    font-size: 11.5px;
    color: var(--color-text-muted);
}
.main .pgwb-dropline {
    position: relative;
    height: 0;
    margin: 1px 4px;
    border-top: 2px solid var(--color-accent);
    border-radius: 2px;
}
.main .pgwb-dropline::before {
    content: "";
    position: absolute;
    left: -4px;
    top: -4px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-accent);
}

.main .pgwb-w {
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: 9px;
    background: var(--surface-raised);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}
.main .pgwb-w.is-selected { border-color: var(--color-accent); box-shadow: var(--shadow-glow); }
.main .pgwb-w.is-dragging { opacity: 0.45; }
.main .pgwb-w__bar { display: flex; align-items: center; gap: 7px; padding: 7px 8px; }
.main .pgwb-w__grip {
    flex: none;
    display: flex;
    padding: 0;
    border: 0;
    background: transparent;
    color: #C2C7D0;
    cursor: grab;
}
.main .pgwb-w__grip svg { width: 14px; height: 14px; }
.main .pgwb-w__grip:focus-visible { outline: 0; border-radius: 4px; box-shadow: var(--shadow-glow); }
.main .pgwb-w__ic {
    width: 22px;
    height: 22px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 6px;
    color: var(--fam, #475467);
    background: color-mix(in srgb, var(--fam, #98A2B3) 14%, var(--surface-raised));
}
.main .pgwb-w__ic svg { width: 13px; height: 13px; }
.main .pgwb-w__meta { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main .pgwb-w__name { font-size: 12px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main .pgwb-w__sum { font-size: 10.5px; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main .pgwb-w__edit,
.main .pgwb-w__x {
    flex: none;
    display: flex;
    padding: 3px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #98A2B3;
    cursor: pointer;
}
.main .pgwb-w__edit svg,
.main .pgwb-w__x svg { width: 14px; height: 14px; }
.main .pgwb-w__edit:hover { color: var(--color-text); background: var(--surface-hover); }
.main .pgwb-w__x:hover { color: var(--color-danger); background: color-mix(in srgb, var(--color-danger) 10%, transparent); }

/* ── Per-widget config modal ──────────────────────────────────────────────
   The modal is appended to <body> (outside .main), so these rules are scoped
   to .modal-overlay, NOT .main. It reuses the kit .modal--light .modal--form
   shell (header / scrolling body / pinned footer). */
.modal-overlay .pgwb-modal__id { display: flex; align-items: center; gap: 11px; min-width: 0; }
.modal-overlay .pgwb-modal__ic {
    width: 34px;
    height: 34px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: 8px;
    color: var(--fam, #475467);
    background: color-mix(in srgb, var(--fam, #98A2B3) 16%, #fff);
}
.modal-overlay .pgwb-modal__ic svg { width: 18px; height: 18px; }
.modal-overlay .pgwb-modal__sub { margin: 2px 0 0; font-size: 12px; color: var(--color-text-muted); }
/* Even spacing between the widget's config fields (scoped to this modal only,
   so the shared .modal__scroll kit rule is untouched). */
.modal-overlay .pgwb-modal .modal__scroll { display: grid; gap: var(--space-base); align-content: start; }
.modal-overlay .pgwb-modal__del { margin-right: auto; }
.modal-overlay .pgwb-move { display: flex; gap: var(--space-sm); }
.modal-overlay .pgwb-move__btn { flex: 1; justify-content: center; }
/* The inline SVGs in modal buttons (Up / Down / Remove) carry a viewBox but no
   width/height, and the .main-scoped icon sizes don't reach the body-appended
   modal — constrain them here so the arrows are glyph-sized, not full-button. */
.modal-overlay .pgwb-modal .btn svg { width: 15px; height: 15px; flex: none; }
/* Field primitives carry their .main color overrides; restate the few the modal
   needs since it lives outside .main (the .modal--light tokens do the rest). */
.modal-overlay .modal--light .field { margin-bottom: 0; }
.modal-overlay .modal--light .field__label { color: var(--color-text-secondary); }
.modal-overlay .modal--light .field__hint { color: var(--color-text-muted); }
.modal-overlay .pages-textarea { min-height: 120px; resize: vertical; }
/* Stacked link rows: [network select | remove] on top, full-width URL below. */
.modal-overlay .pages-widget-social-links { display: grid; gap: var(--space-md); }
.modal-overlay .pages-widget-social-links__row { display: grid; gap: 6px; }
.modal-overlay .pages-widget-social-links__head { display: flex; align-items: center; gap: var(--space-sm); }
.modal-overlay .pages-widget-social-links__head .select { flex: 1 1 auto; min-width: 0; }
.modal-overlay .pages-widget-social-links__row .input { width: 100%; min-width: 0; }

body.pages-widget-modal-open {
    overflow: hidden;
}

/* ════════════════════════════════════════════════════════════════════════
   .block-card — the reusable page-builder block (NEW; see DESIGN-SYSTEM.md)
   A light card: a header row (static type icon+label + reorder/delete tools)
   over a body holding the type's kit fields.
   ════════════════════════════════════════════════════════════════════════ */

.main .block-card {
    background: var(--surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}
.main .block-card:hover { border-color: var(--color-text-muted); box-shadow: var(--shadow-md); }
@media (prefers-reduced-motion: reduce) { .main .block-card { transition: none; } }

.main .block-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-base);
    padding: var(--space-sm) var(--space-base);
    background: var(--surface-sunken);
    border-bottom: 1px solid var(--color-border);
}
.main .block-card__type {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
}
.main .block-card__type-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md);
    background: var(--surface-raised);
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    flex: 0 0 auto;
}
.main .block-card__type-name {
    font-weight: 600;
    color: var(--color-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.main .block-card__tools {
    display: flex;
    gap: 2px;
    align-items: center;
    flex: 0 0 auto;
    margin-left: auto;
}
/* Drag handle (block reorder) sits before the type label; tools push right. */
.main .block-card__head { justify-content: flex-start; }
.main .block-card__grip {
    flex: none;
    display: flex;
    padding: 2px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #C2C7D0;
    cursor: grab;
}
.main .block-card__grip:hover { color: var(--color-text-secondary); }
.main .block-card__grip:focus-visible { outline: 0; box-shadow: var(--shadow-glow); }
.main .block-card.is-dragging { opacity: 0.5; }

.main .block-card__body { padding: var(--space-base) var(--space-lg) var(--space-lg); }

.main .block-card__fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-base);
}
.main .block-card__field--wide { grid-column: 1 / -1; }
.main .block-card__field--narrow { max-width: 220px; }

.main .block-feature-grid__items,
.main .block-steps__items,
.main .block-stat-strip__items { display: grid; gap: var(--space-base); }
.main .block-feature-grid__item,
.main .block-steps__item,
.main .block-stat-strip__item {
    display: grid;
    gap: var(--space-base);
    padding: var(--space-base);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: rgba(255,255,255,0.03);
}
.main .block-feature-grid__item-head,
.main .block-steps__item-head,
.main .block-stat-strip__item-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
}
.main .block-feature-grid__foot,
.main .block-steps__foot,
.main .block-stat-strip__foot { margin-top: var(--space-base); }

.main .pages-textarea {
    min-height: 120px;
    resize: vertical;
}

/* Divider preview — a clean rule the buyer will get on the page. */
.main .block-card__divider-preview {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-sm) 0;
}
.main .block-card__divider-line {
    display: block;
    width: 100%;
    height: 0;
    border-top: 2px solid var(--color-border);
    border-radius: 2px;
}

/* Module block — registry-backed native platform modules.
   Dense, grouped config form: Identity (Module + Slug) · Display options ·
   Reference. Conditional fields (Slug, Extended preview) flow through auto-fit
   rows and a toggle column, so a missing field never leaves an orphaned void. */
.main .block-module { display: grid; gap: var(--space-sm); }
.main .block-module .field { margin: 0; }
.main .block-module__summary,
.main .block-card__unsupported {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-base);
    background: var(--surface-sunken);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
}
.main .block-module__summary-icon {
    display: inline-flex;
    color: var(--color-text);
}
.main .block-card__unsupported {
    align-items: flex-start;
    flex-direction: column;
}
.main .block-card__unsupported-title {
    color: var(--color-text);
    font-weight: 600;
}

/* Body = stacked logical groups. */
.main .block-module__body { display: grid; gap: var(--space-base); }
.main .block-module__group { display: grid; gap: var(--space-sm); }
/* Quiet eyebrow + hairline introducing each secondary group. */
.main .block-module__group-label {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--color-border);
}
/* Two-column row that collapses to one when a cell is hidden (auto-fit) or on
   narrow viewports — never a forced half-width void. */
.main .block-module__row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-base);
    align-items: start;
}
/* Toggle column — checkbox + label on one line, aligned and grouped. The
   column centres against the taller label-above-control "Header title" field so
   a single toggle reads balanced (no void beneath it), and 2+ toggles stay tidy
   — uniform "square" regardless of how many toggles a module exposes. */
.main .block-module__checks {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    align-self: center;
}
.main .block-module__check {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-text-secondary);
}
.main .block-module__check input {
    margin: 0;
    cursor: pointer;
    flex: 0 0 auto;
}

/* ── tournament_lobby Instances picker ────────────────────────────────────
   Scoped to .block-module__slug so ONLY the format-instances picker is
   affected — the Display-options toggle column reuses the same
   .block-module__checks class but lives OUTSIDE the slug mount, so it keeps
   the plain stacked-flex treatment above.

   The picker stacks two full-width "mode" radios over a responsive grid of
   template checkboxes. A long template list was a single tall column that
   towered over the short Module field beside it (big void under Module); the
   grid collapses that height onto ≥2 desktop columns, rebalancing the row. */
.main .block-module__slug {
    display: grid;
    gap: var(--space-base);
    align-content: start;
}
.main .block-module__slug .block-module__checks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: var(--space-sm) var(--space-md);
    align-self: stretch;
}
/* Mode choice (All instances / Selected templates) — a clear segmented header
   spanning the full width above the list; the two radios never mix into the
   checkbox grid. */
.main .block-module__slug .block-module__check:has(input[type="radio"]) {
    grid-column: 1 / -1;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--surface-sunken);
    color: var(--color-text-secondary);
}
.main .block-module__slug .block-module__check:has(input[type="radio"]:checked) {
    border-color: var(--color-accent);
    background: var(--surface-raised);
    color: var(--color-text);
    box-shadow: inset 0 0 0 1px var(--color-accent);
}
/* Template list — subordinate plain rows beneath the mode header. */
.main .block-module__slug .block-module__check:has(input[type="checkbox"]) {
    min-height: 32px;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
}
.main .block-module__slug .block-module__check:has(input[type="checkbox"]:hover:not(:disabled)) {
    background: var(--surface-hover);
}
/* "All instances" active → JS already disables the template checkboxes; dim
   the list to signal it is inactive. Pure CSS reading the existing disabled
   state — no JS state class added. */
.main .block-module__slug .block-module__check:has(input[type="checkbox"]:disabled) {
    opacity: 0.5;
    cursor: default;
}
.main .block-module__slug .block-module__check:has(input:focus-visible) {
    outline: 2px solid var(--color-ring);
    outline-offset: 2px;
}
@media (prefers-reduced-motion: no-preference) {
    .main .block-module__slug .block-module__check {
        transition: opacity 120ms ease, background-color 120ms ease, border-color 120ms ease;
    }
}

/* When the tournament_lobby picker makes the right column tall, reflow the
   module body into two columns at desktop width: the Format + Instances picker
   keeps the right column while Module, Display options and Reference stack down
   the otherwise-empty left column (no wasted void beside the picker). Scoped
   via :has() to the picker — every other module has a short Slug column (no
   void) and is NOT matched, so it keeps the simple stacked layout. A
   template-load failure swaps the picker for a plain field (no .checks) and
   also falls back to the stacked layout. */
@media (min-width: 1024px) {
    .main .block-module__body:has(.block-module__slug .block-module__checks) {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        column-gap: var(--space-lg);
        align-items: start;
    }
    /* Promote the identity row so Module + slug mount become body grid items. */
    .main .block-module__body:has(.block-module__slug .block-module__checks) > .block-module__group:first-child,
    .main .block-module__body:has(.block-module__slug .block-module__checks) > .block-module__group:first-child > .block-module__row {
        display: contents;
    }
    /* Left column: Module, then the two trailing groups stacked down the void. */
    .main .block-module__body:has(.block-module__slug .block-module__checks) > .block-module__group:first-child > .block-module__row > .field,
    .main .block-module__body:has(.block-module__slug .block-module__checks) > .block-module__group:nth-child(2),
    .main .block-module__body:has(.block-module__slug .block-module__checks) > .block-module__group:nth-child(3) {
        grid-column: 1;
    }
    /* Right column: Format + Instances, spanning the three left rows. */
    .main .block-module__body:has(.block-module__slug .block-module__checks) > .block-module__group:first-child > .block-module__row > .block-module__slug {
        grid-column: 2;
        grid-row: 1 / span 3;
    }
}

.main .block-module__shortcode {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
}

/* ── Image block — dropzone + thumbnail ───────────────────────────────── */

.main .block-card__image { display: grid; gap: var(--space-base); }
.main .block-card__image-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-base);
}

.main .block-card__dropzone {
    position: relative;            /* sr-only file input anchor */
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 132px;
    padding: var(--space-base);
    background: var(--surface-sunken);
    border: 1.5px dashed var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    text-align: center;
    transition: border-color 150ms ease, background-color 150ms ease;
}
.main .block-card__dropzone:hover,
.main .block-card__dropzone.is-dragover {
    border-color: var(--color-accent);
    background: var(--surface-hover);
}
.main .block-card__dropzone.has-image { border-style: solid; }

/* Visually-hidden but focusable file input — must keep top/left:0 inside the
   position:relative dropzone so focus never hijacks document scroll. */
.main .block-card__file {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}
.main .block-card__file:focus-visible ~ .block-card__dropzone-prompt {
    color: var(--color-text);
}

.main .block-card__dropzone-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--color-text-muted);
}
.main .block-card__dropzone-icon {
    display: inline-flex;
    color: var(--color-text-secondary);
    margin-bottom: 2px;
}
.main .block-card__dropzone-text {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-text-secondary);
}
.main .block-card__dropzone.has-image .block-card__dropzone-prompt { display: none; }

.main .block-card__thumb {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
}
.main .block-card__dropzone.has-image .block-card__thumb { display: flex; }
.main .block-card__thumb img {
    max-width: 100%;
    max-height: 180px;
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    display: block;
}
.main .block-card__thumb-replace {
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--color-text-secondary);
}
/* Broken-image fallback — hide the img, reveal a muted label (no inline style). */
.main .block-card__dropzone.is-broken .block-card__thumb img { display: none; }
.main .block-card__dropzone.is-broken .block-card__thumb::before {
    content: "Image unavailable";
    color: var(--color-text-muted);
    font-size: var(--text-sm);
}

/* ── Rich text (Quill) framed on the light surface — container CSS only,
      Quill + the server sanitizer are untouched. ─────────────────────────── */

.main .pages-richtext-editor {
    background: var(--surface-raised);
    border-radius: var(--radius-md);
}
.main .pages-richtext-editor .ql-toolbar.ql-snow {
    border-color: var(--color-border);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    background: var(--surface-sunken);
}
.main .pages-richtext-editor .ql-container.ql-snow {
    min-height: 150px;
    border-color: var(--color-border);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.95rem;
}
.main .pages-richtext-editor .ql-editor { min-height: 150px; }
.main .pages-richtext-editor .ql-editor.ql-blank::before { color: var(--color-text-muted); }
.main .pages-richtext-editor .ql-picker,
.main .pages-richtext-editor .ql-stroke { color: var(--color-text-secondary); stroke: currentColor; }
.main .pages-richtext-editor .ql-fill { fill: var(--color-text-secondary); }
.main .pages-richtext-editor .ql-picker-options {
    background: var(--surface-raised);
    border-color: var(--color-border);
}

/* ── Columns layout block (editor) ────────────────────────────────────── */

.main .block-columns-wrap { display: grid; gap: var(--space-base); }
.main .block-columns__bar { display: flex; align-items: center; gap: var(--space-sm); }
.main .block-columns__bar .select { max-width: 160px; }

.main .block-columns { display: grid; gap: var(--space-base); align-items: start; }
.main .block-columns--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.main .block-columns--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.main .block-column {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    min-width: 0;
    padding: var(--space-sm);
    background: var(--surface-sunken);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}
.main .block-column__label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}
.main .block-column__list { display: grid; gap: var(--space-sm); min-width: 0; }
.main .block-column__empty {
    margin: 0;
    padding: var(--space-base) var(--space-sm);
    text-align: center;
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-sm);
}
.main .block-column__foot .btn { width: 100%; justify-content: center; }

/* Nested block cards sit on the sunken column — flatten the shadow, tighten the
   padding, and force single-column fields (a column is narrow). */
.main .block-card--nested { box-shadow: none; }
.main .block-column .block-card__head { padding: var(--space-xs) var(--space-sm); }
.main .block-column .block-card__body { padding: var(--space-sm); }
.main .block-column .block-card__fields { grid-template-columns: 1fr; }
.main .block-column .block-card__field--narrow { max-width: none; }

/* ── Responsive ───────────────────────────────────────────────────────── */

/* Below ~1180px the 2-up builder + multi-up canvas cols get cramped: stack the
   palette + canvas into one column and let the rails sit under the main column,
   so nothing is squeezed on a narrow admin window. The [data-rails] selector is
   restated here so it wins over the layout-specific grid templates above. */
@media (max-width: 1180px) {
    .main .pages-builder { grid-template-columns: 1fr; }
    .main .pages-builder__palette { position: static; max-height: none; }
    .main .pages-canvas-cols,
    .main .pages-canvas-cols[data-rails] { grid-template-columns: 1fr; }
}

/* .main padding drops to --space-lg at this breakpoint (admin.css) — keep the
   sticky offset in lockstep so the bar still pins to the visible top. */
@media (max-width: 768px) {
    .main .pages-editor__bar { top: calc(-1 * var(--space-lg)); }
    .main .block-columns--2,
    .main .block-columns--3 { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .main .pages-editor__bar { gap: var(--space-sm); }
    .main .pages-editor__bar-actions { width: 100%; justify-content: space-between; }
    .main .block-card__fields,
    .main .block-card__image-meta { grid-template-columns: 1fr; }
    .main .block-card__field--narrow { max-width: none; }
}
