/* ---- Library "Start from a preset": minimal swatch + name cards ---- */
.lib-preset-scroll {
  max-height: 430px;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 2px 4px;
}

.lib-preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}

.lib-preset {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.lib-preset:hover {
  border-color: var(--accent);
  background: var(--accent-weak);
}

.lib-preset-swatch {
  flex: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.lib-preset-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.lib-preset-name {
  font-weight: 680;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lib-preset-meta {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lib-preset.is-locked {
  cursor: not-allowed;
}

.lib-preset.is-locked:hover {
  border-color: var(--line);
  background: #fff;
}

.lib-preset.is-locked .lib-preset-swatch {
  filter: grayscale(1);
  opacity: 0.55;
}

.lib-preset.is-locked .lib-preset-name {
  color: var(--muted);
}

/* --- Block builder ------------------------------------------------------
   Block content classes (.bb-text/-img/-cols/-items/-totals/-divider) are
   shared by the printed invoice (partials/invoice_blocks.erb) and the editor
   canvas; the .bb-block chrome is editor-only. */
.bb-text { white-space: pre-line; }
.bb-img { max-width: 100%; display: inline-block; }
.bb-cols { display: grid; gap: 20px; }
.bb-cols-2 { grid-template-columns: 1fr 1fr; }
.bb-cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.bb-items { width: 100%; border-collapse: collapse; margin: 4px 0; }
.bb-items th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .03em; background: var(--invoice-accent, #147c64); color: #fff; padding: 7px 8px; }
.bb-items td { padding: 8px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.bb-items .r { text-align: right; }
.bb-totals { max-width: 260px; margin-left: auto; }
.bb-total-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.bb-total-grand { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 7px; font-weight: 700; color: var(--invoice-accent, #147c64); }
.bb-divider { border: 0; }
.bb-muted { color: var(--muted); font-style: italic; }
.bb-doc { color: #24282d; font-family: var(--invoice-font, inherit); }

.bb-brandbar { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; padding: 14px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 16px; }
.bb-brandbar .field { margin: 0; }
.bb-brandbar input[type="text"] { min-width: 160px; }
.bb-logo-thumb { height: 30px; margin-left: 8px; vertical-align: middle; }

.bb-editor-grid { display: grid; grid-template-columns: 150px minmax(0, 1fr) 260px; gap: 18px; align-items: start; }
.bb-palette { display: flex; flex-direction: column; gap: 8px; position: sticky; top: calc(var(--topbar-height) + 12px); }
.bb-palette .eyebrow { margin-bottom: 2px; }
.bb-canvas-wrap { background: #ececea; border: 1px solid var(--line); border-radius: 12px; padding: 20px; max-height: 80vh; overflow: auto; }
.bb-canvas { background: #fff; border-radius: 4px; padding: 40px 44px; box-shadow: 0 1px 3px rgba(0,0,0,.08); font-size: 13px; color: #24282d; }
.bb-props { position: sticky; top: calc(var(--topbar-height) + 12px); border: 1px solid var(--line); border-radius: 10px; padding: 14px; max-height: 80vh; overflow: auto; }
.bb-props-empty { color: var(--muted); font-size: 13px; }
.bb-props .field { margin-bottom: 10px; }
.bb-props textarea { min-height: 80px; }
.bb-token-chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 12px; }
.bb-token-chips .ph-label { width: 100%; margin: 0 0 2px; }
.bb-chip { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 1px 8px; font-size: 11px; color: var(--muted); cursor: pointer; }
.bb-chip:hover { color: var(--text); border-color: var(--accent); }

.bb-block { position: relative; border: 1px dashed transparent; border-radius: 6px; margin: 2px 0; }
.bb-block:hover { border-color: var(--line); }
.bb-block.is-selected { border-color: var(--accent); border-style: solid; }
.bb-block.is-dragging { opacity: .5; }
.bb-block-bar { display: none; align-items: center; gap: 6px; position: absolute; top: -11px; right: 6px; background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 1px 6px; font-size: 11px; z-index: 2; }
.bb-block:hover .bb-block-bar, .bb-block.is-selected .bb-block-bar { display: flex; }
.bb-block-type { color: var(--muted); text-transform: capitalize; }
.bb-drag { cursor: grab; color: var(--muted); }
.bb-block-actions button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 12px; padding: 0 2px; }
.bb-block-actions button:hover { color: var(--text); }
.bb-block-body { cursor: pointer; padding: 2px; }

@media (max-width: 1000px) {
  .bb-editor-grid { grid-template-columns: 1fr; }
  .bb-palette { position: static; flex-direction: row; flex-wrap: wrap; }
  .bb-props { position: static; }
}

/* "Show all N presets" - spans the grid; hidden once expanded or when filtering. */

.style-tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* Bundled IBM Plex families (app/assets/fonts, OFL) so the on-screen
   invoice renders the SAME face the Prawn PDF embeds. Only the family actually
   referenced by --invoice-font is fetched by the browser. */
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("/assets/IBMPlexSans-Regular-dc244000.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 700; font-display: swap; src: url("/assets/IBMPlexSans-Bold-59908dd7.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Sans"; font-style: italic; font-weight: 400; font-display: swap; src: url("/assets/IBMPlexSans-Italic-e7ed684d.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Sans"; font-style: italic; font-weight: 700; font-display: swap; src: url("/assets/IBMPlexSans-BoldItalic-b67bbef8.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Serif"; font-style: normal; font-weight: 400; font-display: swap; src: url("/assets/IBMPlexSerif-Regular-1f61978b.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Serif"; font-style: normal; font-weight: 700; font-display: swap; src: url("/assets/IBMPlexSerif-Bold-580fe936.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Serif"; font-style: italic; font-weight: 400; font-display: swap; src: url("/assets/IBMPlexSerif-Italic-aae1d91c.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Serif"; font-style: italic; font-weight: 700; font-display: swap; src: url("/assets/IBMPlexSerif-BoldItalic-c35a2ff6.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("/assets/IBMPlexMono-Regular-923ca06c.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 700; font-display: swap; src: url("/assets/IBMPlexMono-Bold-ac6d30f8.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Mono"; font-style: italic; font-weight: 400; font-display: swap; src: url("/assets/IBMPlexMono-Italic-895c9a28.ttf") format("truetype"); }
@font-face { font-family: "IBM Plex Mono"; font-style: italic; font-weight: 700; font-display: swap; src: url("/assets/IBMPlexMono-BoldItalic-e02c9d85.ttf") format("truetype"); }
/* Display-only script face for the calligraphic wordmark on the
   `script_aesthetic` format. Regular only - see InvoiceFonts::SCRIPT_FAMILY. */
@font-face { font-family: "Invoice Script"; font-style: normal; font-weight: 400; font-display: swap; src: url("/assets/GreatVibes-Regular-056a76e5.ttf") format("truetype"); }

/* The A-J theme faces (InvoiceFonts::THEME_STYLE_FILES, all OFL). Declared here
   because InvoiceFonts.theme_css_stack leads with these family names, and a
   family the browser cannot load falls back to a system face WITHOUT any error -
   the HTML would quietly stop matching the PDF, which is the one thing the
   self-hosting is for.
   Weight RANGES, not single weights: each file is one static cut, so the range
   maps every weight a theme might ask for onto the nearest cut we actually ship
   rather than letting the browser synthesise a bolder face than Prawn embeds.
   Where a family has no true italic the italic rule points at the upright file,
   mirroring how InvoiceFonts aliases those slots - a browser-synthesised oblique
   would look nothing like the PDF. */
@font-face { font-family: "Space Grotesk"; font-style: normal; font-weight: 300 500; font-display: swap; src: url("/assets/SpaceGrotesk-Medium-c65dbd35.ttf") format("truetype"); }
@font-face { font-family: "Space Grotesk"; font-style: normal; font-weight: 600 700; font-display: swap; src: url("/assets/SpaceGrotesk-Bold-5f81027f.ttf") format("truetype"); }
@font-face { font-family: "Space Grotesk"; font-style: italic; font-weight: 300 500; font-display: swap; src: url("/assets/SpaceGrotesk-Medium-c65dbd35.ttf") format("truetype"); }
@font-face { font-family: "Space Grotesk"; font-style: italic; font-weight: 600 700; font-display: swap; src: url("/assets/SpaceGrotesk-Bold-5f81027f.ttf") format("truetype"); }
@font-face { font-family: "Newsreader"; font-style: normal; font-weight: 300 500; font-display: swap; src: url("/assets/Newsreader-Regular-396caf21.ttf") format("truetype"); }
@font-face { font-family: "Newsreader"; font-style: normal; font-weight: 600 700; font-display: swap; src: url("/assets/Newsreader-SemiBold-217eda82.ttf") format("truetype"); }
@font-face { font-family: "Newsreader"; font-style: italic; font-weight: 300 500; font-display: swap; src: url("/assets/Newsreader-Italic-19b1a9e7.ttf") format("truetype"); }
@font-face { font-family: "Newsreader"; font-style: italic; font-weight: 600 700; font-display: swap; src: url("/assets/Newsreader-SemiBoldItalic-a64c3cc8.ttf") format("truetype"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 200 300; font-display: swap; src: url("/assets/Manrope-Light-77c6d5c7.ttf") format("truetype"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 400 500; font-display: swap; src: url("/assets/Manrope-Regular-9b466567.ttf") format("truetype"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 600 800; font-display: swap; src: url("/assets/Manrope-Bold-2740f0f8.ttf") format("truetype"); }
@font-face { font-family: "Manrope"; font-style: italic; font-weight: 200 500; font-display: swap; src: url("/assets/Manrope-Regular-9b466567.ttf") format("truetype"); }
@font-face { font-family: "Manrope"; font-style: italic; font-weight: 600 800; font-display: swap; src: url("/assets/Manrope-Bold-2740f0f8.ttf") format("truetype"); }
@font-face { font-family: "Fraunces"; font-style: normal; font-weight: 300 500; font-display: swap; src: url("/assets/Fraunces-Medium-77b3edbc.ttf") format("truetype"); }
@font-face { font-family: "Fraunces"; font-style: normal; font-weight: 600 700; font-display: swap; src: url("/assets/Fraunces-SemiBold-aba81d1d.ttf") format("truetype"); }
@font-face { font-family: "Fraunces"; font-style: italic; font-weight: 300 500; font-display: swap; src: url("/assets/Fraunces-Medium-77b3edbc.ttf") format("truetype"); }
@font-face { font-family: "Fraunces"; font-style: italic; font-weight: 600 700; font-display: swap; src: url("/assets/Fraunces-SemiBold-aba81d1d.ttf") format("truetype"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 300 500; font-display: swap; src: url("/assets/Inter-Regular-912de628.ttf") format("truetype"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap; src: url("/assets/Inter-SemiBold-e66a0128.ttf") format("truetype"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 700 800; font-display: swap; src: url("/assets/Inter-Bold-8ac93012.ttf") format("truetype"); }
@font-face { font-family: "Inter"; font-style: italic; font-weight: 300 500; font-display: swap; src: url("/assets/Inter-Regular-912de628.ttf") format("truetype"); }
@font-face { font-family: "Inter"; font-style: italic; font-weight: 600 800; font-display: swap; src: url("/assets/Inter-Bold-8ac93012.ttf") format("truetype"); }

.template-preview {
  --invoice-accent: var(--accent);
  --invoice-font: "IBM Plex Sans", "Aptos", "Segoe UI", sans-serif;
  position: sticky;
  top: 94px;
  padding: 28px;
  color: #24282d;
  background: #ffffff;
  font-family: var(--invoice-font);
  /* A document's size is its own, not the app chrome's: pinned to the 13px the
     previews were drawn against, so restyling the app never rescales an invoice. */
  font-size: 13px;
  transition: background 180ms ease, color 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 2px solid #24282d;
}

.preview-meta,
.totals-stack {
  display: grid;
  gap: 5px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin: 22px 0;
}

.preview-line-items {
  width: 100%;
  border-collapse: collapse;
}

.preview-line-items th,
.preview-line-items td {
  padding: 9px 0;
  border-bottom: 1px solid var(--line-soft);
}

.preview-brand {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.preview-logo-mark {
  display: inline-grid;
  place-items: center;
  min-width: 42px;
  height: 42px;
  padding: 0 10px;
  border-radius: 12px;
  color: #fff;
  background: var(--invoice-accent);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

/* The logo is either the image OR the monogram, never both. The display rules
   above would otherwise beat the [hidden] attribute's UA display:none, so the
   hidden one must be explicitly removed - and with !important, because every
   design sets the slot's display more specifically
   (.template-preview[data-theme] .preview-logo-mark is display: flex), which
   showed an uploaded logo AND the monogram box in every themed preview. */
.preview-logo-mark[hidden],
.preview-logo-img[hidden] {
  display: none !important;
}

/* Status banner: what this document is about, stated above the parties. Matches
   InvoicePdf#render_status_banner - a tinted full-width strip in the accent. Only
   payment reminders carry one today; credit notes will reuse it. */
.preview-status-banner {
  margin: 14px 0 0;
  padding: 6px 10px;
  border-radius: 4px;
  color: var(--invoice-accent);
  background: color-mix(in srgb, var(--invoice-accent) 9%, white);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

/* On a reminder the emphasized figure is the BALANCE, so the invoice total steps
   back rather than competing with it. */
.totals-stack.is-reminder span[data-section="totals"]:not(.totals-owing) {
  color: var(--muted);
  font-weight: 400;
}
.totals-stack .totals-owing {
  margin-top: 3px;
  padding-top: 6px;
  border-top: 1px solid var(--line-soft);
  color: var(--invoice-accent);
  font-weight: 700;
}

/* "This template is what your Invoice, Receipt and Credit Note go out as." */
.format-serves { margin: -4px 0 0; font-size: 12px; line-height: 1.55; }
.format-serves strong { color: var(--text); font-weight: 650; }
.format-serves a { color: var(--accent); margin-left: 4px; text-decoration: underline; }

/* PAID marker on a receipt's meta column. */
.preview-paid-badge {
  display: inline-flex;
  align-items: center;
  align-self: flex-end;
  margin-top: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--invoice-accent);
  background: color-mix(in srgb, var(--invoice-accent) 12%, white);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.template-preview [data-preview-key="address"],
.template-preview [data-preview-key="client_address"],
.template-preview [data-preview-key="notes"],
.template-preview [data-preview-key="bank_details"],
.template-preview [data-preview-key="terms"] {
  white-space: pre-line;
}

.template-preview[data-surface-tone="paper"] {
  background: #fffdf8;
}

.template-preview[data-surface-tone="mist"] {
  background: #f7fbff;
}

.template-preview[data-surface-tone="sand"] {
  background: #fff7eb;
}

.template-preview[data-surface-tone="mint"] {
  background: #f3fcf8;
}

.template-preview[data-surface-tone="night"] {
  color: #f8fafc;
  background: #0f1720;
  border-color: #0f1720;
}

.template-preview[data-surface-tone="night"] .muted,
.template-preview[data-surface-tone="night"] .eyebrow,
.template-preview[data-surface-tone="night"] .preview-line-items th,
.template-preview[data-surface-tone="night"] .preview-line-items td,
.template-preview[data-surface-tone="night"] .preview-meta,
.template-preview[data-surface-tone="night"] .totals-stack {
  color: #d7dee7;
}

.template-preview[data-surface-tone="night"] .preview-line-items th,
.template-preview[data-surface-tone="night"] .preview-line-items td {
  border-bottom-color: rgba(255, 255, 255, 0.14);
}

.template-preview[data-header-align="stacked"] .preview-header {
  align-items: flex-start;
  flex-direction: column;
}

.template-preview[data-header-align="left"] .preview-header {
  display: grid;
  justify-content: flex-start;
}

.template-preview[data-density="compact"] {
  padding: 20px;
}

.template-preview[data-density="compact"] .preview-grid {
  gap: 12px;
  margin: 14px 0;
}

.template-preview[data-density="compact"] .preview-line-items th,
.template-preview[data-density="compact"] .preview-line-items td {
  padding: 6px 0;
}

.template-preview[data-density="spacious"] {
  padding: 38px;
}

.template-preview[data-density="spacious"] .preview-grid {
  margin: 28px 0;
}

.template-preview[data-density="spacious"] .preview-line-items th,
.template-preview[data-density="spacious"] .preview-line-items td {
  padding: 12px 0;
}

