/* ---- Invoice template library ---- */
.button-sm {
  min-height: 30px;
  padding: 0 11px;
  font-size: 12px;
}

/* ---- Section formatting (Phase 2) ---- */
.section-format-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-format-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sf-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
}

.fmt-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 8px;
  background: var(--panel-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.fmt-select {
  height: 30px;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 5px;
  font-size: 12px;
  color: var(--text);
  font-family: inherit;
  padding: 0 6px;
}

.fmt-check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--bg);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.fmt-check .fmt-i {
  font-style: italic;
  font-weight: 700;
}

.fmt-check:has(input:checked) {
  color: var(--accent);
  background: var(--accent-weak);
  border-color: transparent;
}

.fmt-color {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 8px 0 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--bg);
  cursor: pointer;
}

.fmt-color input[type="color"] {
  width: 26px;
  height: 20px;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

.fmt-color input[type="color"]:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Editor top bar (above the split layout). */
.editor-topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ---- Line-item columns + sample rows (Phase 3) ---- */
.chip-btn {
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--accent);
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 11px;
  cursor: pointer;
}

.chip-btn:disabled {
  color: var(--faint);
  border-color: var(--line-soft);
  cursor: default;
}

.column-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.column-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-subtle);
}

.column-item.dragging {
  opacity: 0.6;
  border-color: var(--accent);
}

.column-item .grip {
  color: var(--faint);
  cursor: grab;
  font-size: 12px;
  line-height: 1;
}

.column-item .col-vis {
  flex: none;
  cursor: pointer;
}

.column-item .col-label {
  flex: 1;
  min-width: 60px;
  height: 30px;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 5px;
  font-size: 12px;
  color: var(--text);
  font-family: inherit;
  padding: 0 7px;
}

.col-remove {
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.col-remove:hover {
  color: var(--red);
}

.col-remove:disabled {
  color: var(--line);
  cursor: default;
}

/* Merged Logo control: a Monogram | Image toggle inside Visual controls. */
.logo-field { grid-column: 1 / -1; }
.logo-seg {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  margin: 2px 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-subtle);
}
.logo-seg button {
  font: inherit;
  font-size: 12px;
  font-weight: 640;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 5px 14px;
  cursor: pointer;
}
.logo-seg button.is-on {
  color: var(--text);
  background: var(--panel);
  box-shadow: 0 1px 2px rgba(16, 35, 28, 0.08);
}
.logo-pane[hidden] { display: none; }
.logo-field .hint { margin-top: 4px; font-size: 11.5px; color: var(--faint); }

.logo-drop {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  padding: 14px;
  background: var(--panel-subtle);
}

.logo-cur {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
}

.logo-cur img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.logo-cur.mono {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  border: 0;
}

.logo-meta {
  flex: 1;
  min-width: 0;
}

.logo-meta .fname {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logo-meta .info {
  font-size: 11px;
  color: var(--faint);
  margin-top: 2px;
}

.logo-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  background: var(--text);
  color: var(--bg);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}

.ghost-btn {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}

.ghost-btn:hover {
  color: var(--text);
  border-color: #cfcfcf;
}

.logo-err {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--red);
}

.preview-logo-img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 8px;
}

/* ---- Layout: ordered blocks + custom fields/sections (Phase 5) ---- */
.preview-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.totals-block {
  display: flex;
  justify-content: flex-end;
}

.preview-footer-stack {
  border-top: 1px solid var(--line-soft);
  padding-top: 14px;
}

.preview-custom-fields {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.preview-custom-fields .cf-line {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.preview-custom-fields .cf-k { color: var(--muted); }
.preview-custom-fields .cf-v { color: var(--text); font-weight: 600; }

.footer-custom .eyebrow {
  margin-bottom: 2px;
}

/* editor: reorder + repeatable lists */
.order-list,
.cf-list,
.cs-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.order-item,
.cf-item,
.cs-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-subtle);
}

.cs-item {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.cs-item .cs-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.order-item.dragging,
.cf-item.dragging,
.cs-item.dragging {
  opacity: 0.6;
  border-color: var(--accent);
}

.order-item .grip,
.cf-item .grip,
.cs-item .grip {
  color: var(--faint);
  cursor: grab;
  font-size: 12px;
  line-height: 1;
}

.order-item .order-label {
  font-size: 12.5px;
  font-weight: 600;
}

/* Pro-gated layout sections: inline "Pro" tag on the header + a read-only,
   dimmed preview of the current config with an upgrade prompt. */

.acc-upsell {
  margin: 0 0 10px;
  padding: 9px 11px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--accent-weak);
  color: var(--muted);
  font-size: 12.5px;
}

.acc-upsell a {
  color: var(--accent);
  font-weight: 700;
}

.acc-locked .is-readonly {
  opacity: 0.55;
  pointer-events: none;
  user-select: none;
}

.acc-locked .is-readonly .grip {
  cursor: default;
}

.cf-item.is-static .cf-ro-label {
  font-weight: 600;
  font-size: 12.5px;
}

.cf-item.is-static .cf-ro-value {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cs-item.is-static .cs-ro-title {
  font-weight: 600;
  font-size: 12.5px;
}

.cs-item.is-static .cs-ro-body {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  white-space: pre-line;
}

.cf-input,
.cs-title {
  flex: 1;
  min-width: 50px;
  height: 30px;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 5px;
  font-size: 12px;
  color: var(--text);
  font-family: inherit;
  padding: 0 7px;
}

.cs-body {
  width: 100%;
  min-height: 46px;
  resize: vertical;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 5px;
  font-size: 12px;
  color: var(--text);
  font-family: inherit;
  padding: 6px 8px;
}

/* ---- Library "Start from a preset" gallery (Phase 6) ---- */

/* Let the card button sit directly in the grid; the wrapping form is invisible. */
.preset-card-form {
  display: contents;
}

[data-lib-preset].is-hidden,
[data-pack-preset].is-hidden {
  display: none;
}


/* ---- HTML (Liquid) templates: page, sandboxed preview, versions, errors ---- */
.html-tpl-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .html-tpl-layout { grid-template-columns: minmax(0, 1fr); }
}
/* An A4 sheet's proportions, so the frame shows a page rather than a strip. */
.html-tpl-frame-wrap {
  background: var(--panel-subtle);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.html-tpl-frame {
  display: block;
  width: 100%;
  aspect-ratio: 210 / 297;
  max-width: 100%;
  border: 0;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.html-tpl-file { display: flex; flex-direction: column; gap: 6px; }
.html-tpl-file label { font-weight: 600; font-size: 13px; }
.html-tpl-versions,
.html-tpl-errors { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.html-tpl-versions li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line-soft);
}
.html-tpl-versions li:first-child { border-top: 0; }
.html-tpl-version-name { font-weight: 600; }
.html-tpl-version-date { grid-column: 1; color: var(--muted); font-size: 12px; }
.html-tpl-versions li > s-badge,
.html-tpl-versions li > form { grid-column: 2; grid-row: 1 / span 2; }
.html-tpl-errors li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 0;
  border-top: 1px solid var(--line-soft);
}
.html-tpl-errors li:first-child { border-top: 0; }
.html-tpl-error-stage { font-weight: 600; font-size: 13px; }
.html-tpl-help summary { cursor: pointer; font-weight: 600; }
.html-tpl-help pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  background: var(--panel-subtle);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
}

/* ---- Visual editor (E2): palette · GrapesJS canvas · settings ---- */
.ve {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) 260px;
  gap: 12px;
  height: min(78vh, 900px);
  min-height: 560px;
}
@media (max-width: 1000px) {
  .ve { grid-template-columns: minmax(0, 1fr); height: auto; }
  .ve-stage { height: 70vh; }
}
.ve-side {
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ve-heading { margin: 4px 0 0; font-weight: 600; font-size: 13px; }
.ve-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.ve-stage { display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel-subtle); }
.ve-stage-bar { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); font-size: 12px; }
.ve-status { font-weight: 600; }
.ve-stage-note { color: var(--muted); }
.ve-canvas { flex: 1; min-height: 0; }
.ve-theme { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 4px; }
.ve-field { display: grid; grid-template-columns: 1fr 120px; align-items: center; gap: 8px; font-size: 12px; }
.ve-field select, .ve-field input { width: 100%; }
.ve-form { margin-top: 12px; }
/* GrapesJS's own chrome, quietened to match the admin. */
.ve .gjs-one-bg { background: var(--panel); }
/* No GrapesJS panels here, so its canvas takes the whole stage. */
.ve .gjs-editor-cont, .ve .gjs-editor { height: 100%; }
.ve .gjs-cv-canvas { width: 100%; height: 100%; top: 0; }
.ve .gjs-two-color { color: var(--text); }
.ve .gjs-block { width: calc(50% - 8px); min-height: 56px; margin: 4px; padding: 8px 4px; border: 1px solid var(--line); border-radius: 6px; box-shadow: none; font-size: 12px; color: var(--text); }
.ve .gjs-block:hover { border-color: var(--accent); color: var(--accent); }
.ve .gjs-blocks-c { display: flex; flex-wrap: wrap; }
.ve .gjs-trt-trait { padding: 6px 0; font-size: 12px; color: var(--text); }
.ve .gjs-label { color: var(--muted); }
.ve .gjs-field { background: var(--panel-subtle); border: 1px solid var(--control-line); border-radius: 6px; color: var(--text); }
.ve .ve-checklist { display: flex; flex-direction: column; gap: 4px; padding: 4px 0; }
.ve textarea { width: 100%; font: inherit; }
