/* Designer-only additions. Bar, buttons, panel, status and hint styles come from
   brand.css + correct.css (linked first). */

main { grid-template-columns: 1fr 440px; transition: grid-template-columns .25s ease, column-gap .25s ease; } /* owner: 340px +30% */
/* Slide-away panel: the column animates to 0 and the stage takes the width. */
main.panel-collapsed { grid-template-columns: 1fr 0px; column-gap: 0; }
main > .panel { min-width: 0; overflow: hidden; transition: opacity .2s ease; }
main.panel-collapsed > .panel { opacity: 0; visibility: hidden; padding-left: 0; padding-right: 0; border-width: 0; }
.panel-toggle[aria-expanded="false"] svg { transform: scaleX(-1); }
.stage.designer-stage { overflow: auto; padding: 24px; line-height: normal; height: calc(100vh - var(--header-h, 120px) - 30px); box-sizing: border-box; display: flex; flex-direction: column; } /* --header-h = live header height (designer.js), so a wrapping header never pushes the page off screen; 30px = main padding */
/* margin:auto centres the page in the stage; unlike align/justify-content centring it
   collapses to 0 when the zoomed page overflows, so the top-left stays scrollable. */
#canvas-stage { position: relative; display: inline-block; line-height: 0; margin: auto; flex: none; }
#page-canvas { display: block; background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35); touch-action: none; }
#page-canvas g[data-item-id] { cursor: move; }
#page-canvas [data-handle] { cursor: pointer; }
#overlay { position: absolute; inset: 0; pointer-events: none; }

.pager select { font: inherit; padding: 5px 8px; border-radius: 6px; max-width: 220px; }
.pager .book-name { font: inherit; font-weight: 600; padding: 5px 8px; border-radius: 6px; border: 1px solid transparent; width: 220px; max-width: 32vw; }
.pager .book-name:hover, .pager .book-name:focus { border-color: currentColor; }

/* Tools row inside the sticky header bar, so every tool stays on screen while the
   page or panel scrolls. Full-width second row of the editor's .bar flex layout. */
.tool-bar { flex: 1 1 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding-top: 8px; border-top: 1px solid var(--mat-line); }
.tool-bar .sel-name { margin: 0 6px 0 0; font-size: 13px; font-weight: 600; opacity: 0.9; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-group { display: inline-flex; gap: 4px; padding-left: 10px; border-left: 1px solid var(--mat-line); }
.tool-group:first-of-type { border-left: 0; padding-left: 0; }
.tool-bar button.danger { width: auto; }
.tool-bar button:disabled { opacity: 0.4; }
.panel { top: calc(var(--header-h, 120px) + 4px); }
/* The account email is the first thing to go when the header gets crowded. */

.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 34px; height: 32px; padding: 0 8px; }
.icon-btn svg, button svg { flex: none; }
.inspector button.danger, .gen-box .primary { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.gen-box { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.gen-box input, .gen-box textarea { width: 100%; box-sizing: border-box; padding: 6px 8px; font: inherit; border: 1px solid #ccc; border-radius: 5px; }
.gen-box textarea { resize: none; overflow-y: auto; line-height: 1.35; max-height: calc(10 * 1.35em + 14px); }
.gen-count { margin: 0; font-size: 12px; text-align: right; }
.gen-count.warn { color: #b25b00; font-weight: 600; }
.lib-item .lib-rename { flex: 1; min-width: 0; padding: 2px 4px; font: inherit; border: 1px solid #ffb100; border-radius: 4px; }
.lib-item .lib-name[data-renamable] { cursor: text; }
.small { font-size: 12px; }
.panel-title { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: #666; }
#library-block { margin-bottom: 14px; }
.sel-name { margin: 0 0 8px; font-weight: 600; word-break: break-word; }
.status a { font-weight: 600; }
.status:empty { margin: 0; } /* no blank band at the top of the side panel */

#library { max-height: 40vh; overflow-y: auto; position: relative; } /* rows measure offsetTop against the list (syncLibrarySelection) */
.lib-item { display: flex; align-items: center; gap: 8px; padding: 6px; margin-bottom: 6px; border: 1px solid #e2e2e6; border-radius: 6px; font-size: 13px; word-break: break-word; }
.lib-item[draggable="true"] { cursor: grab; }
.lib-item[draggable="true"]:hover { border-color: #ffb100; }
.lib-item img { width: 48px; height: 48px; flex: none; object-fit: contain; background: var(--paper); border-radius: 4px; }
/* Name (+ description line) column takes the spare width; badges/buttons stay compact. */
.lib-item.inactive { opacity: 0.6; }
.badge { flex: none; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: 8px; background: #eef0f3; color: #555; }

@media (max-width: 860px) {
  main, main.panel-collapsed { grid-template-columns: 1fr; }
  .stage.designer-stage { padding: 12px; height: 70vh; }
}

/* Story wizard (dialog; look follows the editor's download dialog) */
dialog#story-wizard, dialog#split-wizard { border: none; border-radius: 10px; padding: 0; width: min(560px, 94vw); max-height: 90vh; color: #1a1a1a; }
dialog#story-wizard::backdrop, dialog#split-wizard::backdrop { background: rgba(0,0,0,.4); }
.wiz { padding: 18px 20px; font-size: 14px; }
.wiz-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.wiz-head h3 { margin: 0; }
.wiz-steps { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 0 0 14px; padding: 0; font-size: 12px; }
.wiz-step-item { padding: 3px 9px; border-radius: 12px; background: #eef0f3; color: #5d6b65; }
.wiz-step-item:not(:last-child)::after { content: " ›"; color: #6b7570; }
.wiz-step-item.current { background: #2873d6; color: #fff; font-weight: 600; }
.wiz-step-item.current::after { color: #fff; }
.wiz-step-item.done { background: #e3f3e6; color: #2a6b3a; }
.wiz-step { display: flex; flex-direction: column; gap: 8px; min-height: 180px; }
.wiz-step.hidden { display: none; }
.wiz select, .wiz textarea { width: 100%; padding: 6px 8px; font: inherit; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box; }
.wiz textarea { resize: vertical; }
.wiz-summary { justify-content: flex-start; margin: 4px 0 0; font-weight: 600; }
.wiz-progress { display: flex; flex-direction: column; gap: 6px; }
.wiz-progress .dl-progress-track { max-width: none; }
.wiz .primary { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.wiz .dl-actions { flex-wrap: wrap; }
.wiz .dl-actions .small { margin-right: auto; }
.story-open { position: relative; }
.story-badge { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 10px; background: #ffb100; color: #1a1a1a; white-space: nowrap; }
.story-badge.hidden { display: none; }
.story-busy { display: flex; align-items: center; gap: 10px; font-size: 14px; padding: 30px 0; justify-content: center; }
.story-list { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow-y: auto; border: 1px solid #e2e2e6; border-radius: 6px; }
.story-list li { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; padding: 6px 10px; border-bottom: 1px solid #eee; font-size: 13px; }
.story-list li:last-child { border-bottom: none; }
.story-list label { display: flex; gap: 8px; flex: 1; cursor: pointer; }
.story-idea-name { font-weight: 600; }
.story-idea-desc { display: block; font-size: 12px; color: #5d6b65; }
.story-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1px solid #aaa; margin-right: 4px; vertical-align: middle; }
.story-state { flex: none; text-transform: none; letter-spacing: 0; font-size: 12px; }
.story-state-done { background: #e3f3e6; color: #2a6b3a; }
.story-state-error, .story-state-stopped { background: #fbe4e4; color: #a02020; }
.story-state-running { background: #fff1cc; color: #7a5a00; }

.sp-preview-wrap { display: flex; justify-content: center; }
.sp-preview { position: relative; display: inline-block; max-width: 100%; border: 1px solid #e2e2e6; border-radius: 6px; background: #fafafa; line-height: 0; }
.sp-preview img { display: block; max-width: 100%; max-height: 220px; }
.sp-preview svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.sp-box { fill: rgba(40,115,214,.12); stroke: #2873d6; stroke-width: 2; vector-effect: non-scaling-stroke; }
.sp-box.off { fill: none; stroke: #aaa; stroke-dasharray: 4 3; stroke-width: 1; }

/* Stage bar (page label + zoom) and empty-page hint */
.stage-bar { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: -24px -24px 12px; padding: 4px 10px; background: rgba(255, 255, 255, 0.92); border-bottom: 1px solid #ddd; line-height: normal; }
.page-label { font-size: 13px; font-weight: 600; word-break: break-word; }
.zoom-controls { display: inline-flex; align-items: center; gap: 4px; }
.zoom-readout { min-width: 44px; text-align: center; font-size: 12px; }
.empty-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; line-height: normal; font-size: 16px; color: rgba(0, 0, 0, 0.35); pointer-events: none; user-select: none; }
.empty-hint.hidden { display: none; }
@media (max-width: 860px) {
  .stage-bar { margin: -12px -12px 12px; }
}

/* Page size dialog (stage bar ruler button) */
.page-meta { display: inline-flex; align-items: center; gap: 6px; }
dialog#page-size-dialog { border: none; border-radius: 10px; padding: 0; width: min(440px, 94vw); color: #1a1a1a; }
dialog#page-size-dialog::backdrop { background: rgba(0,0,0,.4); }
.page-size-fields { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.page-size-dims { display: flex; align-items: flex-end; gap: 8px; }
.page-size-dims label { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.page-size-dims input { width: 100%; padding: 6px 8px; font: inherit; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box; }
/* Wrap names dialog (header Names button), same frame as the page size dialog */
dialog#wrap-dialog { border: none; border-radius: 10px; padding: 0; width: min(480px, 94vw); color: #1a1a1a; }
dialog#wrap-dialog::backdrop { background: rgba(0,0,0,.4); }
.wrap-fields { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.wrap-fields textarea { width: 100%; padding: 6px 8px; font: inherit; border: 1px solid #ccc; border-radius: 5px; box-sizing: border-box; text-transform: uppercase; }
.page-size-save { display: flex; gap: 6px; }
.page-size-save input { flex: 1; min-width: 0; padding: 6px 8px; font: inherit; border: 1px solid #ccc; border-radius: 5px; }

/* Library drag image source (see setTrueSizeDragImage): rendered but off-screen. */
.drag-ghost { position: fixed; left: -10000px; top: 0; pointer-events: none; }

/* Library row delete (trash) button */
.lib-item .lib-delete { flex: none; min-width: 28px; height: 28px; padding: 0 6px; background: transparent; color: #a02020; border: 1px solid transparent; }
.lib-item .lib-delete:hover { border-color: #e7b3b3; background: #fbe4e4; }

/* Library colour swatch + colour-grid popup */
.lib-item .lib-colour { flex: none; width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #888; cursor: pointer; }
.lib-item .lib-colour:hover, .lib-item .lib-colour:focus-visible { box-shadow: 0 0 0 2px #ffb100; }
dialog#colour-grid { border: none; border-radius: 10px; padding: 0; width: min(360px, 94vw); color: #1a1a1a; }
dialog#colour-grid::backdrop { background: rgba(0,0,0,.4); }
.colour-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 8px; padding: 12px 16px; }
.colour-grid .swatch { width: 44px; height: 44px; padding: 0; border-radius: 8px; border: 2px solid #fff; box-shadow: 0 0 0 1px #888; cursor: pointer; }
.colour-grid .swatch:hover, .colour-grid .swatch:focus-visible { box-shadow: 0 0 0 3px #ffb100; }
.colour-grid .swatch.current { box-shadow: 0 0 0 3px #1a1a1a; }

/* Library details (material badge + description line) and the details dialog */
.lib-item .lib-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.lib-item .lib-desc { font-size: 11px; color: #5d6b65; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-item .lib-material { flex: none; text-transform: none; letter-spacing: 0; }
.lib-item .lib-details { flex: none; min-width: 28px; height: 28px; padding: 0 6px; background: transparent; color: #555; border: 1px solid transparent; }
.lib-item .lib-details:hover, .lib-item .lib-details:focus-visible { border-color: #ffb100; }
dialog#details-dialog { border: none; border-radius: 10px; padding: 0; width: min(440px, 94vw); color: #1a1a1a; }
dialog#details-dialog::backdrop, dialog#preview-dialog::backdrop { background: rgba(0,0,0,.4); }
.details-fields { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }

/* Page preview dialog: free mockup + optional AI photo */
dialog#preview-dialog { border: none; border-radius: 10px; padding: 0; width: min(1100px, 96vw); max-height: 94vh; color: #1a1a1a; }
.preview-panes { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.preview-pane { flex: 1 1 320px; margin: 0; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.preview-pane img { display: block; max-width: 100%; max-height: 62vh; object-fit: contain; border-radius: 6px; box-shadow: 0 1px 6px rgba(0,0,0,.25); background: #f4efe4; }
.preview-pane.hidden, #preview-busy.hidden, #preview-download.hidden { display: none; }

/* Library select mode (multi-delete / clear) */
.lib-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 0 0 8px; font-size: 13px; }
.lib-tools .hidden { display: none; }
.lib-select-tools { display: inline-flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.lib-link { background: none; border: 0; padding: 2px 0; color: #2873d6; text-decoration: underline; cursor: pointer; font: inherit; }
.lib-link[aria-pressed="true"] { font-weight: 700; }
.lib-danger { background: #fbe4e4; color: #a02020; border: 1px solid #e7b3b3; border-radius: 5px; padding: 3px 8px; font: inherit; cursor: pointer; }
.lib-danger:disabled { opacity: 0.45; cursor: default; }
.lib-item .lib-check { flex: none; width: 18px; height: 18px; }
.lib-item.picked { border-color: #e7b3b3; background: #fff6f6; }

/* Change with AI wizard */
dialog#change-wizard { border: none; border-radius: 10px; padding: 0; width: min(560px, 94vw); max-height: 90vh; color: #1a1a1a; }
dialog#change-wizard::backdrop { background: rgba(0,0,0,.4); }
#change-wizard .wiz-step.hidden, #change-wizard .hidden { display: none; }
#change-list li { align-items: center; }
#change-list select { font: inherit; padding: 2px 4px; }
.notion-badge { background: #eef3fb; color: #2b5ea8; border: 1px dashed #7aa2db; }

/* Fillings (inside a shape) */
.fillings-list { list-style: none; margin: 0 0 6px; padding: 0; font-size: 13px; }
.fillings-list li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.filling-add { display: flex; gap: 6px; margin-bottom: 8px; }
.filling-add input { flex: 1; padding: 5px 8px; font: inherit; border: 1px solid #ccc; border-radius: 5px; }
.filled-badge { background: #fff4e5; color: #8a5a00; }

/* Group panel: shows beside the side panel while a group (or part of one) is selected */
/* Dropdown under the page bar's zoom / fullscreen / panel buttons, at the page area's
   right edge (440px panel + main padding + gap = 468px from the window; 28px when the
   side panel is hidden), floating over the canvas. */
.group-panel {
  position: fixed; z-index: 25; width: 230px;
  top: calc(var(--header-h, 120px) + 86px); right: 482px; /* just below the page bar's buttons */
  max-height: calc(100vh - var(--header-h, 120px) - 120px); overflow-y: auto;
  background: #fff; color: #1a1a1a; border-radius: 8px; padding: 12px;
  box-shadow: 0 4px 18px rgba(0,0,0,.22);
  animation: group-panel-in .2s ease-out;
}
main.panel-collapsed > .group-panel { right: 42px; }
.group-panel::before {
  content: ""; position: absolute; top: -7px; right: 18px; width: 12px; height: 12px;
  background: #fff; transform: rotate(45deg); box-shadow: -2px -2px 3px rgba(0,0,0,.06);
}
.group-panel { overflow: visible; }
.group-panel .group-members { max-height: calc(100vh - var(--header-h, 120px) - 230px); overflow-y: auto; }
.group-panel[hidden] { display: none; }
@keyframes group-panel-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.group-members { list-style: none; margin: 8px 0 0; padding: 0; }
.group-members li { margin-bottom: 4px; }
.group-members button { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 5px 6px; border: 1px solid #e2e2e6; border-radius: 6px; background: #fff; color: #1a1a1a; font: inherit; font-size: 13px; cursor: pointer; text-transform: none; letter-spacing: 0; line-height: 1.3; }
.group-members button:hover { border-color: #ffb100; }
.group-members button.active { border-color: #ffb100; background: #fff7e6; font-weight: 600; }
.group-members img { width: 32px; height: 32px; object-fit: contain; flex: none; background: var(--paper); border-radius: 4px; }
.group-members .badge { margin-left: auto; }
@media (max-width: 860px) {
  .group-panel { position: static; width: auto; max-height: none; animation: none; }
}

/* Library row of the shape selected on the page */
.lib-item.current { border-color: #ffb100; box-shadow: 0 0 0 2px rgba(255, 177, 0, 0.45); background: #fffaf0; }

/* While the side panel is hidden (page-bar toggle), a tab on the right edge of the
   window brings it back. */
.panel-show {
  display: none; position: fixed; right: 0; top: 50%; z-index: 30;
  transform: translateY(-50%); writing-mode: vertical-rl;
  padding: 14px 7px; border-radius: 8px 0 0 8px; border: 0;
  background: var(--mat, #1f4a3c); color: #fff; font-size: 13px; letter-spacing: .06em;
  cursor: pointer; box-shadow: -2px 2px 8px rgba(0,0,0,.25);
}
.panel-show:hover { background: var(--thread, #e05a6d); }
body.panel-is-collapsed .panel-show { display: block; }
@media (max-width: 860px) { body.panel-is-collapsed .panel-show { display: none; } }

/* Basic shapes (no AI): a compact row under the describe box. */
.basic-box { margin: 8px 0 4px; font-size: 13.5px; }
.basic-box summary { cursor: pointer; font-weight: 600; }
.basic-row { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 8px; }
.basic-row input[type="number"] { width: 64px; }

#jobLabel { color: var(--chalk-light); }
