/* ============================================================
   MagpieToolbox - Invoice "Customize" layer
   Drives the live A4 preview from model.style (set as inline
   vars on #invoicePreview) and houses the side-drawer editor.
   Loaded AFTER invoice.css so same-specificity overrides win.
   ============================================================ */

/* paper hooks: accent + a text-size multiplier (default = neutral) */
.ipreview{ --pp-accent:#0aa5b1; --inv-fs:1; }

/* multi-page preview: #invoicePreview becomes a vertical stack of A4 pages,
   each .ipage is its own A4 (aspect-locked, clipped, query container). */
.ipreview{ aspect-ratio:auto; width:100%; height:auto; overflow:visible; background:transparent; box-shadow:none; border-radius:0; container-type:normal; display:flex; flex-direction:column; gap:clamp(12px,2.4cqw,18px); }
.ipage{ flex:0 0 auto; width:100%; aspect-ratio:210 / 297; container-type:inline-size; overflow:hidden; border-radius:8px; box-shadow:var(--shadow-md); background:var(--pp-bg); color:var(--pp-ink); }

/* ---- accent recolours the title + the two structural rules ---- */
.inv-doc__title h2{ color:var(--pp-accent); }
.inv-table__h{ border-bottom:1.5px solid var(--pp-accent); }
.inv-trow--grand{ border-top:2px solid var(--pp-accent); }

/* ---- text-size scale: every content size * --inv-fs ---- */
.inv-doc__logo--ph{ font-size:calc(2.4cqw * var(--inv-fs,1)); }
.inv-doc__title h2{ font-size:calc(6cqw * var(--inv-fs,1)); }
.inv-doc__title .inv-num{ font-size:calc(2.7cqw * var(--inv-fs,1)); }
.inv-party__k{ font-size:calc(2.2cqw * var(--inv-fs,1)); }
.inv-party__name{ font-size:calc(3.1cqw * var(--inv-fs,1)); }
.inv-party__line{ font-size:calc(2.7cqw * var(--inv-fs,1)); }
.inv-meta div{ font-size:calc(2.5cqw * var(--inv-fs,1)); }
.inv-table__h{ font-size:calc(2.1cqw * var(--inv-fs,1)); }
.inv-row{ font-size:calc(2.7cqw * var(--inv-fs,1)); }
.inv-trow{ font-size:calc(2.7cqw * var(--inv-fs,1)); }
.inv-trow--grand{ font-size:calc(3.6cqw * var(--inv-fs,1)); }
.inv-note{ font-size:calc(2cqw * var(--inv-fs,1)); }
.inv-doc__notes p,
.inv-doc__fblock p{ font-size:calc(2.5cqw * var(--inv-fs,1)); }
.inv-cf__row{ font-size:calc(2.6cqw * var(--inv-fs,1)); }
.inv-sig__lbl{ font-size:calc(2cqw * var(--inv-fs,1)); }

/* ---- header alignment variants on the top (logo + title) ---- */
.inv-doc[data-align="center"] .inv-doc__top{ flex-direction:column; align-items:center; gap:3cqw; }
.inv-doc[data-align="center"] .inv-doc__title h2,
.inv-doc[data-align="center"] .inv-doc__title .inv-num{ text-align:center; }
.inv-doc[data-align="right"] .inv-doc__top{ flex-direction:row-reverse; }
.inv-doc[data-align="right"] .inv-doc__title h2,
.inv-doc[data-align="right"] .inv-doc__title .inv-num{ text-align:left; }

/* ---- body wrapper clips content so it never collides with the footer (fix #1) ---- */
.inv-doc__body{ flex:1 1 auto; min-height:0; display:flex; flex-direction:column; overflow:hidden; }
/* the notes/sections group only hugs the bottom when it is genuinely last */
.inv-doc__foot{ margin-top:0; }
.inv-doc__foot--pin{ margin-top:auto; }

/* ---- optional header line across the top ---- */
.inv-hd{ flex:0 0 auto; font-size:calc(2.45cqw * var(--inv-fs,1)); font-weight:600; color:var(--pp-mut);
  padding-bottom:2.6cqw; margin-bottom:4.5cqw; border-bottom:1.5px solid var(--pp-accent); white-space:pre-line; letter-spacing:.01em; }

/* ---- optional footer line + page number, pinned to the bottom ---- */
.inv-ft{ flex:0 0 auto; display:flex; align-items:center; gap:3cqw; margin-top:4.5cqw; padding-top:2.6cqw;
  border-top:1px solid var(--pp-line); font-size:calc(2.3cqw * var(--inv-fs,1)); color:var(--pp-mut); }
.inv-ft__t{ min-width:0; white-space:pre-line; }
.inv-ft__pn{ font-family:var(--font-mono); flex:0 0 auto; font-variant-numeric:tabular-nums; }
.inv-ft[data-pos="right"]{ justify-content:space-between; }
.inv-ft[data-pos="left"]{ flex-direction:row-reverse; justify-content:flex-end; }
.inv-ft[data-pos="center"]{ justify-content:center; }
.inv-ft[data-pos="center"] .inv-ft__t{ display:none; }

/* ============================================================
   Customize trigger (above the preview)
   ============================================================ */
.icz-bar{ display:flex; justify-content:flex-end; }
.icz-trigger{ display:inline-flex; align-items:center; gap:8px; font:inherit; font-size:var(--text-sm); font-weight:600;
  color:var(--text-strong); background:var(--surface); border:1.5px solid var(--border-strong); border-radius:var(--radius-pill);
  padding:8px 16px; cursor:pointer; box-shadow:var(--shadow-xs); transition:border-color var(--dur-fast), color var(--dur-fast); }
.icz-trigger:hover{ border-color:var(--brand); color:var(--brand); }
.icz-trigger:focus-visible{ outline:none; box-shadow:var(--ring-focus); }
.icz-trigger svg{ width:16px; height:16px; }

/* ============================================================
   Side drawer
   ============================================================ */
.icz-scrim{ position:fixed; inset:0; z-index:190; background:rgba(9,14,24,.42); opacity:0; pointer-events:none;
  transition:opacity var(--dur-base) var(--ease-out); }
.icz-scrim.is-open{ opacity:1; pointer-events:auto; }

.icz-drawer{ position:fixed; top:0; right:0; z-index:200; height:100dvh; width:min(384px,94vw);
  display:flex; flex-direction:column; background:var(--surface); border-left:1px solid var(--border-default);
  box-shadow:-18px 0 50px -28px rgba(9,14,24,.55); transform:translateX(100%);
  transition:transform var(--dur-base) var(--ease-out); }
.icz-drawer.is-open{ transform:translateX(0); }
@media (prefers-reduced-motion: reduce){ .icz-drawer, .icz-scrim{ transition:none; } }

.icz-drawer__h{ display:flex; align-items:center; justify-content:space-between; gap:var(--space-3);
  padding:var(--space-4) var(--space-5); border-bottom:1px solid var(--border-default); flex:0 0 auto; }
.icz-drawer__h h2{ font-family:var(--font-body); font-size:var(--text-md); font-weight:700; letter-spacing:-0.01em; color:var(--text-strong); margin:0; }
.icz-x{ display:inline-flex; align-items:center; justify-content:center; width:34px; height:34px; border:none; border-radius:var(--r-ctrl);
  background:transparent; color:var(--text-subtle); cursor:pointer; font-size:20px; line-height:1; transition:background var(--dur-fast), color var(--dur-fast); }
.icz-x:hover{ background:var(--surface-sunken); color:var(--text-strong); }
.icz-x svg{ width:18px; height:18px; }

.icz-drawer__b{ flex:1 1 auto; overflow:auto; padding:var(--space-5); display:flex; flex-direction:column; gap:var(--space-6); }
.icz-drawer__f{ flex:0 0 auto; display:flex; gap:var(--space-3); padding:var(--space-4) var(--space-5); border-top:1px solid var(--border-default); }
.icz-drawer__f .btn{ flex:1; justify-content:center; }

/* ============================================================
   Drawer control fragments
   ============================================================ */
.iczg{ display:flex; flex-direction:column; }
.iczg__h{ display:flex; align-items:center; gap:8px; margin-bottom:12px; }
.iczg__h h3{ font-family:var(--font-body); font-size:var(--text-sm); font-weight:700; color:var(--text-strong); margin:0; }
.iczg__b{ display:flex; flex-direction:column; gap:12px; }
.iczlbl{ font-family:var(--font-mono); font-size:var(--text-2xs); letter-spacing:.08em; text-transform:uppercase; color:var(--text-subtle); }
.iczhint{ font-size:var(--text-xs); color:var(--text-subtle); margin:0 0 2px; }

/* swatches */
.iczsw{ display:flex; gap:10px; flex-wrap:wrap; }
.iczsw__b{ width:30px; height:30px; border-radius:8px; border:2px solid var(--surface); box-shadow:0 0 0 1.5px var(--border-strong);
  cursor:pointer; padding:0; transition:box-shadow var(--dur-fast), transform var(--dur-fast); position:relative; }
.iczsw__b:hover{ box-shadow:0 0 0 1.5px var(--text-subtle); transform:translateY(-1px); }
.iczsw__b.on{ box-shadow:0 0 0 2px var(--brand); }
.iczsw__more{ background:conic-gradient(from 90deg,#db4b5a,#d9882b,#15a06b,#2e63e8,#7b5bfb,#db4b5a); }
.iczsw__auto{ background:linear-gradient(135deg,#fff 0 49%,var(--border-strong) 49% 51%,#0f1830 51% 100%); }
.iczsw__auto::after{ content:"A"; position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  font-family:var(--font-mono); font-size:10px; font-weight:700; color:var(--text-strong); mix-blend-mode:difference; color:#fff; }

/* full-width segmented control (fix #4 - fills the panel, no dead space) */
.iczseg{ display:flex; width:100%; gap:3px; padding:3px; background:var(--surface-sunken);
  border:1px solid var(--border-default); border-radius:var(--radius-pill); }
.iczseg button{ flex:1 1 0; min-width:0; border:none; background:transparent; cursor:pointer; color:var(--text-muted);
  font:inherit; font-size:var(--text-xs); font-weight:600; padding:7px 8px; border-radius:var(--radius-pill);
  text-align:center; white-space:nowrap; transition:background var(--dur-fast), color var(--dur-fast); }
.iczseg button:hover{ color:var(--text-strong); }
.iczseg button.on{ background:var(--brand); color:var(--on-accent,#fff); box-shadow:var(--shadow-xs); }

/* select (Google-font browser) */
.iczsel{ width:100%; box-sizing:border-box; font:inherit; font-size:var(--text-sm); font-weight:600; color:var(--text-strong);
  background:var(--surface); border:1.6px solid var(--border-strong); border-radius:var(--r-ctrl); padding:9px 34px 9px 11px; min-height:42px;
  cursor:pointer; appearance:none; -webkit-appearance:none;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-position:right 11px center; }
.iczsel:focus{ outline:none; border-color:var(--brand); box-shadow:0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
[data-theme="dark"] .iczsel{ background-color:#18233a; border-color:#3a486b; }

/* size: slider + number box bound together */
.iczsize{ display:flex; align-items:center; gap:var(--space-3); }
.iczsize input[type="range"]{ flex:1; min-width:0; accent-color:var(--brand); }
.iczsize__num{ display:flex; align-items:center; gap:5px; flex:0 0 auto; }
.iczsize__num input{ width:54px; box-sizing:border-box; font:inherit; font-family:var(--font-mono); font-size:var(--text-sm); font-weight:600;
  color:var(--text-strong); text-align:right; background:var(--surface); border:1.6px solid var(--border-strong); border-radius:var(--r-ctrl); padding:7px 8px; }
.iczsize__num input:focus{ outline:none; border-color:var(--brand); box-shadow:0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.iczsize__num span{ font-family:var(--font-mono); font-size:var(--text-xs); color:var(--text-subtle); }
[data-theme="dark"] .iczsize__num input{ background:#18233a; border-color:#3a486b; }

/* toggle row */
.icztog{ display:flex; align-items:center; justify-content:space-between; gap:12px; cursor:pointer; user-select:none; }
.icztog__tx{ display:flex; flex-direction:column; gap:1px; min-width:0; }
.icztog__tx b{ font-size:var(--text-sm); font-weight:600; color:var(--text-strong); }
.icztog__tx i{ font-style:normal; font-size:var(--text-xs); color:var(--text-subtle); }
.icztog__sw{ position:relative; flex:0 0 auto; display:inline-flex; }
.icztog__sw input{ position:absolute; opacity:0; width:0; height:0; }
.icztog__tk{ width:42px; height:24px; border-radius:999px; background:var(--border-strong); position:relative; transition:background var(--dur-fast); }
.icztog__th{ position:absolute; top:3px; left:3px; width:18px; height:18px; border-radius:50%; background:#fff; box-shadow:var(--shadow-xs);
  transition:transform var(--dur-base) var(--ease-spring,cubic-bezier(.5,1.4,.5,1)); }
.icztog__sw input:checked + .icztog__tk{ background:var(--brand); }
.icztog__sw input:checked + .icztog__tk .icztog__th{ transform:translateX(18px); }
.icztog__sw input:focus-visible + .icztog__tk{ box-shadow:var(--ring-focus); }

/* text field */
.iczfield{ width:100%; box-sizing:border-box; font:inherit; font-size:var(--text-sm); color:var(--text-strong);
  background:var(--surface); border:1.6px solid var(--border-strong); border-radius:var(--r-ctrl); padding:10px 11px; min-height:42px; }
.iczfield::placeholder{ color:var(--text-subtle); }
.iczfield:focus{ outline:none; border-color:var(--brand); box-shadow:0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
[data-theme="dark"] .iczfield{ background:#18233a; border-color:#3a486b; }

/* drag-reorder list */
.iczord{ list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:7px; }
.iczord__i{ display:flex; align-items:center; gap:10px; padding:10px 12px; background:var(--surface-sunken);
  border:1px solid var(--border-default); border-radius:var(--r-ctrl); font-size:var(--text-sm); font-weight:600; color:var(--text-strong); cursor:grab; }
.iczord__i:active{ cursor:grabbing; }
.iczord__i svg{ color:var(--text-subtle); flex:0 0 auto; }
.iczord__i.is-drag{ opacity:.4; }

/* shared color popover (appended to <body>) */
.iczpop{ position:fixed; z-index:210; width:236px; background:var(--surface); border:1.5px solid var(--border-strong);
  border-radius:var(--r-ctrl); box-shadow:var(--shadow-lg); padding:12px; }
.iczpop[hidden]{ display:none; }
.iczpop__grid{ display:grid; grid-template-columns:repeat(6,1fr); gap:7px; }
.iczpop__sw{ width:100%; aspect-ratio:1; border-radius:6px; border:1.5px solid rgba(16,24,38,.12); cursor:pointer; padding:0; transition:transform var(--dur-fast); }
[data-theme="dark"] .iczpop__sw{ border-color:rgba(255,255,255,.14); }
.iczpop__sw:hover{ transform:scale(1.12); }
.iczpop__row{ display:flex; align-items:center; gap:9px; margin-top:11px; padding-top:11px; border-top:1px solid var(--border-default); }
.iczpop__dot{ width:26px; height:26px; border-radius:7px; flex:0 0 auto; box-shadow:inset 0 0 0 1px rgba(16,24,38,.18); }
.iczpop__hex{ flex:1; min-width:0; box-sizing:border-box; min-height:36px; font-family:var(--font-mono); text-transform:uppercase; letter-spacing:.04em;
  font-size:var(--text-sm); color:var(--text-strong); background:var(--surface); border:1.5px solid var(--border-strong); border-radius:var(--r-ctrl); padding:7px 9px; }
.iczpop__hex:focus{ outline:none; border-color:var(--brand); box-shadow:0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
[data-theme="dark"] .iczpop__hex{ background:#18233a; border-color:#3a486b; }
