/* ── Script tab ────────────────────────────────────────────────────────── */

.script-page {
  display: none;
  padding: 0;
  height: 100%;
  overflow: hidden;
}
.script-page.active,
/* Workspace Shell forces `.ws-panel-body > .page.active { display: block }`
   (3 classes), which would outrank the rule above and collapse the flex
   column the scrolling relies on. Match its specificity to keep flex. */
.ws-panel-body > .page.script-page.active {
  display: flex;
  flex-direction: column;
}

/* ── Library view ──────────────────────────────────────────────────────── */

.script-library {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 24px 32px;
  overflow: auto;
}

.script-lib-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.script-lib-title-wrap { display: flex; flex-direction: column; gap: 4px; }
.script-lib-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.script-lib-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

.script-lib-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 820px;
}
.script-lib-empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 28px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

.script-lib-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 14px 18px;
  transition: border-color var(--speed), box-shadow var(--speed);
}
.script-lib-row:hover {
  border-color: var(--border);
  box-shadow: 0 2px 8px rgba(var(--shadow-rgb), 0.06);
}
.script-lib-row.is-active {
  border-color: var(--gold);
  background: linear-gradient(0deg, var(--gold-soft), var(--gold-soft)), var(--surface);
}

.script-lib-row-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}
.script-lib-name {
  background: none;
  border: 0;
  padding: 0;
  text-align: left;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  width: fit-content;
}
.script-lib-name:hover { color: var(--gold-hover); }
.script-lib-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.script-lib-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.btn-ghost-sm {
  background: transparent;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--speed);
}
.btn-ghost-sm:hover {
  border-color: var(--border);
  color: var(--text);
  background: var(--bg-warm);
}
.btn-danger-sm:hover {
  border-color: var(--red);
  color: var(--red);
  background: var(--red-soft);
}

/* ── Doc view (reader / editor) ────────────────────────────────────────── */

.script-doc {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Flat command bar — mirrors the CRM ribbon. No drag-resize, no collapse:
   it's a single wrapping row of Fluent-style commands, and its dropdowns
   overlay the surface (position:fixed) instead of expanding the bar. */
.script-ribbon {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}
.ribbon-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.ribbon-group + .ribbon-group {
  border-left: 1px solid var(--border-light);
  padding-left: 12px;
}
.ribbon-script-name {
  margin-left: 8px;
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}
/* Command button — matches .crm-ribbon .btn-ribbon (Fluent flat command). */
.ribbon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 5px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--speed), color var(--speed);
  min-width: 32px;
}
.ribbon-btn:hover {
  background: var(--gold-soft);
  color: var(--gold);
}
.ribbon-btn:active {
  background: var(--gold-soft);
  color: var(--gold-hover);
}
.ribbon-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -1px;
}
.ribbon-btn.is-on {
  background: var(--gold-soft);
  color: var(--gold-hover);
  border-color: var(--gold);
}

.script-surface {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 32px 48px;
  background: var(--bg);
}

.script-editor-mount {
  /* --base-fs is updated by the zoom buttons in script.js. Everything
     inside (.ProseMirror, headings) sizes from this via em units so the
     whole document scales together. */
  --base-fs: 15px;
  max-width: 820px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 40px 56px;
  min-height: 480px;
  box-shadow: 0 1px 3px rgba(var(--shadow-rgb), 0.04);
}

/* TipTap renders its own contenteditable inside .script-editor-mount as
   .ProseMirror — we style that directly. */
.script-editor-mount .ProseMirror {
  outline: none;
  font-family: var(--font-body);
  font-size: var(--base-fs);
  line-height: 1.65;
  color: var(--text);
}
.script-editor-mount .ProseMirror:focus { outline: none; }
.script-editor-mount .ProseMirror p { margin: 0 0 0.8em; }
.script-editor-mount .ProseMirror h1,
.script-editor-mount .ProseMirror h2,
.script-editor-mount .ProseMirror h3 {
  font-family: var(--font-display);
  color: var(--text);
  line-height: 1.25;
  margin: 1.6em 0 0.4em;
}
.script-editor-mount .ProseMirror h1 { font-size: 1.87em; }
.script-editor-mount .ProseMirror h2 { font-size: 1.47em; }
.script-editor-mount .ProseMirror h3 { font-size: 1.2em; }
.script-editor-mount .ProseMirror ul,
.script-editor-mount .ProseMirror ol { margin: 0 0 12px 24px; padding: 0; }
.script-editor-mount .ProseMirror li { margin: 4px 0; }
.script-editor-mount .ProseMirror mark {
  background: var(--gold-soft);
  padding: 0 2px;
  border-radius: 2px;
}

/* ── Collapsible section node (NodeView) ─────────────────────────────────── */
.script-editor-mount .cs {
  margin: 14px 0;
  border-left: 3px solid var(--border);
  padding: 4px 0 4px 12px;
  background: transparent;
}
.script-editor-mount .cs[data-open="true"]  { border-left-color: var(--gold); }
.script-editor-mount .cs[data-open="false"] { border-left-color: var(--text-muted); }

.script-editor-mount .cs-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  user-select: none;
}
.script-editor-mount .cs-toggle {
  background: transparent;
  border: 0;
  font: inherit;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.script-editor-mount .cs-toggle:hover { background: var(--gold-soft); color: var(--gold-hover); }

.script-editor-mount .cs-title-input {
  flex: 1;
  background: transparent;
  border: 0;
  border-bottom: 1px dashed transparent;
  font: inherit;
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
  padding: 2px 4px;
  outline: none;
  font-family: var(--font-display);
}
.script-editor-mount .cs-title-input:focus {
  border-bottom-color: var(--gold);
}
.script-editor-mount .cs-title-input::placeholder { color: var(--text-dim); font-style: italic; }
.script-editor-mount .cs-title-input.is-readonly {
  border-bottom-color: transparent;
  cursor: default;
}

.script-editor-mount .cs[data-open="false"] > .cs-body { display: none; }
.script-editor-mount .cs-body > *:last-child { margin-bottom: 0; }

/* TextAlign output — TipTap renders style="text-align: X" on paragraphs/headings.
   Nothing to add here; the inline style works on its own. */

/* View mode — hide ribbon focus outline / contenteditable feedback */
.script-surface.is-viewing .ProseMirror { cursor: default; }

/* Ribbon controls — colour palette popover + select */
.ribbon-popover {
  position: relative;
  display: inline-block;
}
.ribbon-popover > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.ribbon-popover > summary::-webkit-details-marker { display: none; }
.ribbon-popover[open] > summary { background: var(--gold-soft); color: var(--gold-hover); border-color: var(--gold); }

/* Overlay panel — position:fixed escapes the ribbon so it floats over the
   surface. JS (wireEditTools) sets top/left from the summary's live rect,
   matching the CRM ribbon dropdowns. */
.ribbon-popover-panel {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 22px rgba(var(--shadow-rgb), 0.14);
  padding: 10px;
  z-index: 9999;
  min-width: 200px;
}
.cp-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

/* ── Import menu ──────────────────────────────────────────────────────────
   Lists every supported format and what it costs you, so PDF's read-only
   trade-off is visible before the file picker opens. */
.import-panel {
  min-width: 300px;
  padding: 6px;
}
.import-panel-head {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 6px 8px 4px;
}
.import-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 7px 8px;
  cursor: pointer;
  font: inherit;
  color: var(--text);
}
.import-row:hover { background: var(--gold-soft); }
.import-row-name { font-size: 13px; font-weight: 600; }
.import-row-ext {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
}
.import-row-note { font-size: 11px; color: var(--text-muted); }
.import-row.is-readonly {
  border-top: 1px solid var(--border-light);
  margin-top: 4px;
  padding-top: 9px;
}
.import-row-any {
  border-top: 1px solid var(--border-light);
  margin-top: 4px;
  padding-top: 9px;
  color: var(--text-muted);
}
.ribbon-import-summary.is-busy,
#script-lib-import.is-busy { opacity: 0.6; pointer-events: none; }

/* ── PDF scripts ──────────────────────────────────────────────────────────
   Rendered by the browser's own PDF viewer, which is the whole point: it
   reproduces the file exactly. The surface drops its padding so the viewer
   gets the full canvas. */
.script-surface.is-pdf { padding: 0; overflow: hidden; }
.script-pdf-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.script-pdf-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--surface);
}
.script-pdf-status {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-muted);
}
.script-pdf-error p { margin: 0; max-width: 40ch; text-align: center; }

.script-pdf-badge,
.script-lib-chip {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--gold-soft);
  color: var(--gold-hover);
  border: 1px solid var(--gold);
  white-space: nowrap;
}
.script-pdf-badge { margin-left: 8px; }
.script-lib-chip { margin-left: 6px; vertical-align: middle; }

.script-lib-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.cp-swatch {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border-light);
  border-radius: 5px;
  padding: 0;
  cursor: pointer;
  transition: transform var(--speed), border-color var(--speed);
}
.cp-swatch:hover {
  transform: scale(1.08);
  border-color: var(--text-muted);
}
.cp-swatch-default {
  background: linear-gradient(135deg, var(--surface) 45%, var(--border) 55%);
  color: var(--text);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.cp-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
  font-size: 12px;
  color: var(--text-muted);
}
.cp-custom {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.cp-custom-input {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
}

.ribbon-select {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 8px;
  font: inherit;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--speed);
}
.ribbon-select:hover { background: var(--gold-soft); color: var(--gold); border-color: transparent; }

.ribbon-zoom-label {
  min-width: 48px;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

/* View mode — hide ribbon focus outline / contenteditable feedback */
.script-surface.is-viewing .ProseMirror { cursor: default; }

/* ── Split-pane: tighten everything when the script tab is sharing the canvas
   with another pane. Single-pane layout keeps its generous spacing. ────── */
#content[data-panes="2"] .script-library {
  padding: 16px 18px;
}
#content[data-panes="2"] .script-ribbon {
  padding: 6px 10px;
  gap: 8px;
}
#content[data-panes="2"] .ribbon-group + .ribbon-group {
  padding-left: 8px;
}
#content[data-panes="2"] .script-surface {
  padding: 12px 14px;
}
#content[data-panes="2"] .script-editor-mount {
  max-width: 100%;
  padding: 20px 24px;
}

/* Ribbon controls — colour + select */
.ribbon-color-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font: inherit;
  font-size: 13px;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.ribbon-color-wrap:hover { background: var(--bg-warm); color: var(--text); }
.ribbon-color-input {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
}
.ribbon-select {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 8px;
  font: inherit;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--speed);
}
.ribbon-select:hover { background: var(--gold-soft); color: var(--gold); border-color: transparent; }
