/* ============================================================
   INVOICEFREE DESIGN SYSTEM & STYLESHEET
   Clean, Apple-inspired UI with functional hierarchy,
   dark mode support, 5 structural invoice templates,
   and comprehensive @media print stylesheet.
   ============================================================ */

:root {
  /* Color Palette - Light Mode */
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface2: #fbfbfd;
  --surface-hover: #f0f0f2;
  --ink: #1d1d1f;
  --ink2: #6e6e73;
  --ink3: #86868b;
  --line: #d2d2d7;
  --line2: #e8e8ed;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-bg: #e8f0fe;
  --good: #0a7d33;
  --good-bg: #e6f6ec;
  --warn: #9a6200;
  --warn-bg: #fdf3e0;
  --bad: #b00020;
  --bad-bg: #fdecec;
  --code-bg: #1d1d1f;
  --code-ink: #f5f5f7;

  /* Typography & Sizing */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", Times, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --font-script: "Brush Script MT", "Segoe Script", "Apple Chancery", cursive;

  --radius: 24px;
  --radius-sm: 16px;
  --radius-xs: 8px;
  --radius-pill: 980px;

  --shadow-subtle: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-card: 0 8px 28px rgba(0, 0, 0, 0.07);
  --shadow-float: 0 12px 32px rgba(0, 0, 0, 0.12);

  --max-w: 1040px;
  --max-w-tool: 1280px;

  /* Active Template Accent */
  --tmpl-accent: #0066cc;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1d1d1f;
    --surface2: #161617;
    --surface-hover: #262629;
    --ink: #f5f5f7;
    --ink2: #a1a1a6;
    --ink3: #86868b;
    --line: #424245;
    --line2: #2c2c2e;
    --accent: #2997ff;
    --accent-hover: #47a6ff;
    --accent-bg: #12283f;
    --good: #30d158;
    --good-bg: #0d2b18;
    --warn: #ffd60a;
    --warn-bg: #332a05;
    --bad: #ff6961;
    --bad-bg: #3a1215;
    --code-bg: #161617;
    --code-ink: #f5f5f7;

    --shadow-subtle: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-card: 0 4px 14px rgba(0, 0, 0, 0.4);
    --shadow-float: 0 12px 32px rgba(0, 0, 0, 0.5);

    --tmpl-accent: #2997ff;
  }
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  color-scheme: light dark;
  scrollbar-gutter: stable;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  width: 100%;
}

/* Tabular figures for all financial values */
.tabular-nums, .num, .amount, .rate, .total-val, .subtotal, .balance {
  font-variant-numeric: tabular-nums;
}

/* Accessibility Focus States */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Typography Utilities */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.15;
}

h1 {
  font-size: clamp(34px, 5.5vw, 54px);
  font-weight: 700;
}

h2 {
  font-size: clamp(26px, 4vw, 36px);
  font-weight: 700;
  margin-bottom: 12px;
}

h3 {
  font-size: clamp(19px, 2.5vw, 24px);
  font-weight: 600;
  margin-bottom: 8px;
}

p {
  margin-bottom: 14px;
  color: var(--ink);
}

.lede {
  font-size: clamp(18px, 2.2vw, 21px);
  color: var(--ink2);
  line-height: 1.45;
  font-weight: 400;
}

.small-text {
  font-size: 13.5px;
  color: var(--ink2);
}

.tiny-text {
  font-size: 12px;
  color: var(--ink3);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  text-decoration: underline;
}

/* Layout Containers */
.container {
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 20px;
}

.container-tool {
  width: 100%;
  max-width: var(--max-w-tool);
  margin: 0 auto;
  padding: 0 20px;
}

/* Buttons & Touch Targets */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  user-select: none;
  text-decoration: none !important;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--accent);
  color: #ffffff !important;
  border-color: var(--accent);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
}

.btn-secondary {
  background-color: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}

.btn-secondary:hover {
  background-color: var(--surface-hover);
  border-color: var(--ink3);
}

.btn-danger {
  background-color: var(--bad-bg);
  color: var(--bad);
  border-color: transparent;
}

.btn-danger:hover {
  background-color: var(--bad);
  color: #ffffff;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 14px;
  font-size: 13.5px;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
}

/* SVG Icons */
.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* Badges / Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
}

.chip b {
  color: var(--accent);
}

.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
}

.badge-good {
  background: var(--good-bg);
  color: var(--good);
}

.badge-warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge-bad {
  background: var(--bad-bg);
  color: var(--bad);
}

/* ============================================================
   TOP NAVIGATION
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line2);
  height: 68px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.site-header .container-tool,
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.brand-link {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.03em;
  text-decoration: none !important;
}

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-block;
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 20px;
  list-style: none;
}

.nav-link {
  font-size: 14.5px;
  font-weight: 500;
  color: var(--ink2);
  text-decoration: none;
  transition: color 0.15s ease;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.nav-link:hover, .nav-link.active {
  color: var(--accent);
  text-decoration: none;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ============================================================
   HERO / BANNER (ZONE 1 TOP)
   ============================================================ */
.tool-hero {
  padding: 34px 0 14px;
  text-align: center;
}
.tool-hero-inner {
  margin: 0 auto;
  text-align: center;
}
.tool-hero h1 {
  font-size: clamp(34px, 5vw, 52px);
  letter-spacing: -0.03em;
}
.tool-hero .lede {
  font-size: clamp(16px, 2vw, 19px);
  margin-bottom: 0;
  color: var(--ink2);
}
.eyebrow {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}
.template-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}
.template-pills a {
  display: inline-flex;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--line2);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none !important;
  box-shadow: var(--shadow-subtle);
}
.template-pills a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.tool-hero-inner {
  max-width: 860px;
}

.tool-hero h1 {
  margin-bottom: 10px;
}

.tool-hero .lede {
  margin-bottom: 16px;
}

.hero-features {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

/* ============================================================
   TOOL WORKSPACE (ZONE 1)
   Desktop: 2 columns (Form ~55%, Live Preview ~45%)
   Mobile: 1 column with Segmented Switcher & Sticky Bar
   ============================================================ */
.tool-controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  padding: 12px 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-subtle);
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.control-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.control-select {
  height: 38px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  padding: 0 10px;
  cursor: pointer;
}

/* Accent Color Picker */
.color-picker {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.color-swatch:hover {
  transform: scale(1.15);
}

.color-swatch.active {
  border-color: var(--ink);
  transform: scale(1.1);
}

/* Mobile Segmented Control [ Edit | Preview ] */
.mobile-view-toggle {
  display: none;
  position: sticky;
  top: 60px;
  z-index: 90;
  background: var(--surface);
  border-bottom: 1px solid var(--line2);
  padding: 8px 16px;
  margin-bottom: 16px;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface2);
  border: 1px solid var(--line2);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 4px;
}

.seg-btn {
  min-height: 44px;
  border: none;
  background: transparent;
  color: var(--ink2);
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Tool Grid */
.tool-grid {
  display: grid;
  grid-template-columns: 55fr 45fr;
  gap: 24px;
  align-items: start;
}

/* ============================================================
   TOOL FORM (LEFT COLUMN)
   ============================================================ */
.tool-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  /* Safe padding so sticky mobile bar never overlaps last form field */
  padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
}

.form-card {
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-subtle);
}

.form-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line2);
  padding-bottom: 10px;
}

.form-card-title {
  font-size: 16.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Form Fields & Grid */
.field-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.field-grid-4 {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr;
  gap: 8px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: 14.5px;
  padding: 9px 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.form-textarea {
  min-height: 72px;
  resize: vertical;
  line-height: 1.4;
}

.helper-text {
  font-size: 12px;
  color: var(--ink3);
  margin-top: 4px;
  line-height: 1.35;
}

.helper-text a {
  color: var(--accent);
}

/* Logo Upload Area */
.logo-upload-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-preview-box {
  width: 140px;
  height: 60px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--surface2);
  position: relative;
}

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

.logo-upload-btn-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Due Date Preset Chips */
.preset-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.preset-chip {
  min-height: 32px;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line2);
  background: var(--surface2);
  color: var(--ink2);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-chip:hover {
  background: var(--surface);
  border-color: var(--ink3);
  color: var(--ink);
}

.preset-chip.active {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

/* Line Items Table & Rows — desktop-first: columns keep their width
   instead of squeezing the Type dropdown, table scrolls on narrow screens */
.items-table-wrap {
  width: 100%;
  overflow-x: auto;
  scrollbar-gutter: stable;
}

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

.items-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink3);
  padding: 8px 6px;
  border-bottom: 1px solid var(--line2);
}

.items-table td {
  padding: 8px 6px;
  vertical-align: top;
}

.item-row {
  border-bottom: 1px solid var(--line2);
}

.item-desc-cell {
  width: 44%;
}

.item-type-cell {
  width: 18%;
}

.item-qty-cell {
  width: 12%;
}

.item-rate-cell {
  width: 16%;
}

.item-amount-cell {
  width: 14%;
  text-align: right;
  font-weight: 600;
  padding-top: 18px !important;
}

.item-actions-cell {
  width: 44px;
  text-align: right;
}

.item-delete-btn, .item-dup-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--ink3);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.item-delete-btn:hover {
  color: var(--bad);
  background: var(--bad-bg);
}

.item-dup-btn:hover {
  color: var(--accent);
  background: var(--accent-bg);
}

/* Totals Form Block */
.totals-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line2);
}

.discount-toggle-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.toggle-pill-btn {
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line2);
  background: var(--surface2);
  color: var(--ink2);
  cursor: pointer;
}

.toggle-pill-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Signature Area */
.sig-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.sig-tab {
  padding: 4px 12px;
  font-size: 13px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--line2);
  background: var(--surface2);
  color: var(--ink2);
  cursor: pointer;
}

.sig-tab.active {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--ink3);
  font-weight: 600;
}

.sig-canvas-wrap {
  border: 1px dashed var(--line);
  border-radius: var(--radius-xs);
  background: #ffffff;
  position: relative;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#sigCanvas {
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.sig-script-input {
  font-family: var(--font-script), cursive;
  font-size: 24px;
}

/* Duplicate Invoice Warning */
.dup-warning {
  display: none;
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: var(--radius-xs);
  padding: 8px 12px;
  font-size: 12.5px;
  margin-top: 6px;
}

/* ============================================================
   LIVE PREVIEW CONTAINER (RIGHT COLUMN)
   Sticky on desktop, toggleable on mobile
   ============================================================ */
.preview-sticky-wrap {
  position: sticky;
  top: 80px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  padding: 10px 16px;
  box-shadow: var(--shadow-subtle);
}

.preview-scale-wrap {
  background: #ffffff;
  color: #1d1d1f;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  position: relative;
}

/* ============================================================
   5 STRUCTURAL INVOICE TEMPLATES
   Rendered in both Screen Preview & PDF Generator
   ============================================================ */

/* Common Invoice Canvas Defaults */
.invoice-doc {
  background: #ffffff;
  color: #1d1d1f;
  width: 100%;
  min-height: 780px;
  padding: 40px;
  font-size: 14px;
  line-height: 1.5;
  box-sizing: border-box;
}

.doc-logo-box img {
  max-width: 150px;
  max-height: 60px;
  object-fit: contain;
}

/* --- TEMPLATE 1: MODERN (DEFAULT) ---
   Structural traits: Sans-serif system stack, left-aligned layout,
   bold accent top band, generous spacing, clean modern tags.
   Fonts: System sans-serif. */
.tmpl-modern {
  font-family: var(--font-sans);
}

.tmpl-modern .doc-top-bar {
  height: 6px;
  background: var(--tmpl-accent);
  margin: -40px -40px 30px;
}

.tmpl-modern .doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 30px;
}

.tmpl-modern .doc-title {
  font-size: 32px;
  font-weight: 800;
  color: var(--tmpl-accent);
  letter-spacing: -0.03em;
}

.tmpl-modern .doc-meta {
  text-align: right;
  font-size: 13.5px;
}

.tmpl-modern .doc-meta-item b {
  color: #6e6e73;
}

.tmpl-modern .doc-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 28px;
}

.tmpl-modern .doc-party-title {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--tmpl-accent);
  margin-bottom: 6px;
}

.tmpl-modern .doc-party-name {
  font-size: 16px;
  font-weight: 700;
  color: #1d1d1f;
}

.tmpl-modern .doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
}

.tmpl-modern .doc-table th {
  background: #f5f5f7;
  color: #1d1d1f;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 14px;
  text-align: left;
}

.tmpl-modern .doc-table th:last-child {
  text-align: right;
}

.tmpl-modern .doc-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #e8e8ed;
}

.tmpl-modern .doc-table td:last-child {
  text-align: right;
  font-weight: 600;
}

.tmpl-modern .doc-footer-split {
  display: grid;
  grid-template-columns: 55fr 45fr;
  gap: 20px;
  align-items: start;
}

.tmpl-modern .doc-totals-box {
  background: #fbfbfd;
  border: 1px solid #e8e8ed;
  border-radius: 12px;
  padding: 16px;
}

.tmpl-modern .total-line {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13.5px;
}

.tmpl-modern .balance-due-line {
  display: flex;
  justify-content: space-between;
  padding: 10px 0 0;
  margin-top: 8px;
  border-top: 2px solid var(--tmpl-accent);
  font-size: 19px;
  font-weight: 800;
  color: var(--tmpl-accent);
}

/* --- TEMPLATE 2: CLASSIC ---
   Structural traits: Serif headings (Georgia/"Times New Roman"),
   ruled horizontal borders mimicking traditional legal ledgers,
   centred header, formal grid.
   Fonts: Georgia, "Times New Roman", serif. */
.tmpl-classic {
  font-family: var(--font-serif);
}

.tmpl-classic .doc-top-bar {
  display: none;
}

.tmpl-classic .doc-header {
  text-align: center;
  border-bottom: 3px double #1d1d1f;
  padding-bottom: 18px;
  margin-bottom: 24px;
}

.tmpl-classic .doc-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1d1d1f;
}

.tmpl-classic .doc-meta {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 8px;
  font-size: 14px;
  font-style: italic;
}

.tmpl-classic .doc-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid #1d1d1f;
  margin-bottom: 22px;
}

.tmpl-classic .doc-party-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #d2d2d7;
  padding-bottom: 3px;
  margin-bottom: 6px;
}

.tmpl-classic .doc-party-name {
  font-size: 16px;
  font-weight: 700;
}

.tmpl-classic .doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
}

.tmpl-classic .doc-table th {
  border-top: 1px solid #1d1d1f;
  border-bottom: 1px solid #1d1d1f;
  font-size: 12px;
  text-transform: uppercase;
  padding: 8px 10px;
  text-align: left;
}

.tmpl-classic .doc-table th:last-child {
  text-align: right;
}

.tmpl-classic .doc-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #e8e8ed;
}

.tmpl-classic .doc-table td:last-child {
  text-align: right;
}

.tmpl-classic .doc-footer-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  border-top: 1px solid #1d1d1f;
  padding-top: 16px;
}

.tmpl-classic .balance-due-line {
  border-top: 1px solid #1d1d1f;
  border-bottom: 3px double #1d1d1f;
  padding: 8px 0;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
}

/* --- TEMPLATE 3: MINIMAL ---
   Structural traits: Ultra-clean hairline dividers, generous white space,
   small quiet typography, airy Swiss aesthetic.
   Fonts: System sans-serif with thin/light weight accents. */
.tmpl-minimal {
  font-family: var(--font-sans);
  padding: 50px;
}

.tmpl-minimal .doc-top-bar {
  display: none;
}

.tmpl-minimal .doc-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 36px;
}

.tmpl-minimal .doc-title {
  font-size: 26px;
  font-weight: 300;
  letter-spacing: -0.01em;
  color: #1d1d1f;
}

.tmpl-minimal .doc-meta {
  font-size: 12.5px;
  color: #6e6e73;
  text-align: right;
}

.tmpl-minimal .doc-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
  margin-bottom: 36px;
}

.tmpl-minimal .doc-party-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #86868b;
  margin-bottom: 4px;
}

.tmpl-minimal .doc-party-name {
  font-size: 14.5px;
  font-weight: 600;
}

.tmpl-minimal .doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 32px;
}

.tmpl-minimal .doc-table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #86868b;
  padding: 8px 0;
  border-bottom: 1px solid #e8e8ed;
  text-align: left;
}

.tmpl-minimal .doc-table th:last-child {
  text-align: right;
}

.tmpl-minimal .doc-table td {
  padding: 12px 0;
  border-bottom: 1px solid #f5f5f7;
  font-size: 13.5px;
}

.tmpl-minimal .doc-table td:last-child {
  text-align: right;
}

.tmpl-minimal .doc-footer-split {
  display: grid;
  grid-template-columns: 60fr 40fr;
  gap: 32px;
}

.tmpl-minimal .total-line {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 12.5px;
  color: #6e6e73;
}

.tmpl-minimal .balance-due-line {
  display: flex;
  justify-content: space-between;
  padding: 8px 0 0;
  margin-top: 6px;
  border-top: 1px solid #1d1d1f;
  font-size: 16.5px;
  font-weight: 600;
  color: #1d1d1f;
}

/* --- TEMPLATE 4: BOLD ---
   Structural traits: Chunky heavy typography, oversized numerals
   for Invoice Number and Balance Due, solid high-contrast accent blocks.
   Fonts: System sans-serif with extra bold weights. */
.tmpl-bold {
  font-family: var(--font-sans);
}

.tmpl-bold .doc-top-bar {
  display: none;
}

.tmpl-bold .doc-header {
  background: var(--tmpl-accent);
  color: #ffffff;
  padding: 24px;
  margin: -40px -40px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tmpl-bold .doc-title {
  font-size: 38px;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: #ffffff;
}

.tmpl-bold .doc-meta {
  text-align: right;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
}

.tmpl-bold .doc-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
  background: #f5f5f7;
  padding: 16px;
  border-radius: 8px;
}

.tmpl-bold .doc-party-title {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--tmpl-accent);
}

.tmpl-bold .doc-party-name {
  font-size: 17px;
  font-weight: 800;
}

.tmpl-bold .doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
}

.tmpl-bold .doc-table th {
  background: #1d1d1f;
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 10px 12px;
  text-align: left;
}

.tmpl-bold .doc-table th:last-child {
  text-align: right;
}

.tmpl-bold .doc-table td {
  padding: 12px;
  border-bottom: 2px solid #e8e8ed;
  font-weight: 500;
}

.tmpl-bold .doc-table td:last-child {
  text-align: right;
  font-weight: 700;
}

.tmpl-bold .doc-footer-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.tmpl-bold .balance-due-line {
  background: var(--tmpl-accent);
  color: #ffffff;
  padding: 14px 18px;
  border-radius: 8px;
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 22px;
  font-weight: 900;
}

/* --- TEMPLATE 5: CONSULTING ---
   Structural traits: Narrow columns with rate/hours breakdown emphasis,
   prominent PO number & project reference at top, muted corporate palette.
   Fonts: System sans-serif with compact tabular metrics. */
.tmpl-consulting {
  font-family: var(--font-sans);
}

.tmpl-consulting .doc-top-bar {
  border-top: 4px solid #334155;
  margin: -40px -40px 24px;
}

.tmpl-consulting .doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  border-bottom: 1px solid #cbd5e1;
  padding-bottom: 16px;
}

.tmpl-consulting .doc-title {
  font-size: 28px;
  font-weight: 700;
  color: #1e293b;
}

.tmpl-consulting .project-ref-banner {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
}

.tmpl-consulting .doc-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.tmpl-consulting .doc-party-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 4px;
}

.tmpl-consulting .doc-party-name {
  font-size: 15px;
  font-weight: 700;
  color: #0f172a;
}

.tmpl-consulting .doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

.tmpl-consulting .doc-table th {
  background: #f8fafc;
  color: #475569;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 8px 10px;
  border-top: 1px solid #cbd5e1;
  border-bottom: 2px solid #cbd5e1;
  text-align: left;
}

.tmpl-consulting .doc-table th:last-child {
  text-align: right;
}

.tmpl-consulting .doc-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 13px;
}

.tmpl-consulting .doc-table td:last-child {
  text-align: right;
  font-weight: 600;
}

.tmpl-consulting .doc-footer-split {
  display: grid;
  grid-template-columns: 55fr 45fr;
  gap: 20px;
}

.tmpl-consulting .balance-due-line {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  margin-top: 6px;
  border-top: 2px solid #0f172a;
  border-bottom: 1px solid #0f172a;
  font-size: 17.5px;
  font-weight: 800;
  color: #0f172a;
}

/* Common Doc Element Helpers */
.doc-signature-box {
  margin-top: 20px;
  padding-top: 10px;
}

.doc-signature-line {
  width: 180px;
  border-top: 1px solid #1d1d1f;
  margin-top: 6px;
  font-size: 11px;
  color: #6e6e73;
}

.doc-signature-img {
  max-height: 44px;
  object-fit: contain;
}

.doc-signature-text {
  font-family: var(--font-script), cursive;
  font-size: 26px;
  color: #1d1d1f;
}

/* ============================================================
   STICKY MOBILE ACTION BAR
   ============================================================ */
.sticky-mobile-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 95;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 10px 16px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}

.sticky-mobile-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--max-w-tool);
  margin: 0 auto;
}

.sticky-mobile-total-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--ink2);
  font-weight: 600;
}

.sticky-mobile-total-val {
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
}

/* ============================================================
   HISTORY DRAWER / MODAL
   ============================================================ */
.history-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.history-modal-backdrop.active {
  display: flex;
}

.history-modal {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-float);
  border: 1px solid var(--line2);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line2);
}

.history-storage-meter {
  padding: 12px 22px;
  background: var(--surface2);
  border-bottom: 1px solid var(--line2);
}

.storage-bar-track {
  width: 100%;
  height: 8px;
  background: var(--line2);
  border-radius: 999px;
  overflow: hidden;
  margin: 6px 0;
}

.storage-bar-fill {
  height: 100%;
  width: 2%;
  background: var(--good);
  border-radius: 999px;
  transition: width 0.3s ease, background-color 0.3s ease;
}

.history-list {
  padding: 12px 22px;
  overflow-y: auto;
  flex: 1;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line2);
}

.history-item:last-child {
  border-bottom: none;
}

.history-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--line2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

/* ============================================================
   ZONE 2: BELOW THE FOLD NARRATIVE CONTENT
   Lazy rendered (content-visibility: auto)
   ============================================================ */
.zone-2 {
  content-visibility: auto;
  contain-intrinsic-size: 1000px;
  padding: 70px 0 30px;
  border-top: 1px solid var(--line2);
  margin-top: 40px;
}

.zone-sec {
  margin-bottom: 70px;
}

.zone-sec-head {
  max-width: 760px;
  margin-bottom: 30px;
}

.zone-sec-head p {
  font-size: 18px;
  color: var(--ink2);
}

/* 3-Step Flow */
.steps-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.step-card {
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  padding: 24px;
}

.step-num {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

/* Features Grid */
.features-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.feature-card {
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  padding: 22px;
}

.feature-icon-wrap {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-xs);
  background: var(--accent-bg);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

/* Worked Numerical Example Card */
.example-card {
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow-subtle);
}

.example-breakdown-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 15px;
}

.example-breakdown-table th {
  text-align: left;
  border-bottom: 2px solid var(--line2);
  padding: 8px 10px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--ink2);
}

.example-breakdown-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line2);
}

.example-breakdown-table tr.total-row {
  font-weight: 700;
  border-top: 2px solid var(--line);
}

/* Accordions (Details & Summary) */
.accordion {
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 12px;
  overflow: hidden;
  transition: all 0.2s ease;
}

.accordion summary {
  padding: 18px 22px;
  font-size: 16.5px;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.accordion summary::-webkit-details-marker {
  display: none;
}

.accordion summary::after {
  content: "+";
  font-size: 20px;
  font-weight: 400;
  color: var(--ink3);
  transition: transform 0.2s ease;
}

.accordion[open] summary::after {
  content: "–";
}

.accordion-body {
  padding: 0 22px 20px;
  font-size: 15.5px;
  color: var(--ink);
  line-height: 1.6;
}

/* Curated Guides Cluster Grid */
.guides-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.guide-card {
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s ease, border-color 0.15s ease;
  text-decoration: none !important;
}

.guide-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.guide-card h3 {
  font-size: 17.5px;
  margin-bottom: 8px;
  color: var(--ink);
}

.guide-card p {
  font-size: 14px;
  color: var(--ink2);
  margin-bottom: 14px;
}

/* ============================================================
   ARTICLE / GUIDE SPECIFIC STYLING
   ============================================================ */
.article-wrap {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

.article-header {
  margin-bottom: 32px;
}

.article-header h1 {
  font-size: clamp(32px, 4.8vw, 48px);
  margin-bottom: 14px;
}

.article-meta-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 13.5px;
  color: var(--ink2);
  border-bottom: 1px solid var(--line2);
  padding-bottom: 16px;
  margin-bottom: 24px;
}

.geo-direct-answer {
  background: var(--accent-bg);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  padding: 18px 22px;
  font-size: 17.5px;
  line-height: 1.5;
  color: var(--ink);
  margin-bottom: 30px;
}

.article-body {
  font-size: 17px;
  line-height: 1.68;
}

.article-body h2 {
  font-size: 26px;
  margin: 40px 0 16px;
  border-top: 1px solid var(--line2);
  padding-top: 24px;
}

.article-body h3 {
  font-size: 20px;
  margin: 28px 0 12px;
}

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  background: var(--surface);
  border-radius: var(--radius-xs);
  overflow: hidden;
  border: 1px solid var(--line2);
}

.article-body th {
  background: var(--surface2);
  text-align: left;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line2);
}

.article-body td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line2);
  vertical-align: top;
}

.article-body tr:last-child td {
  border-bottom: none;
}

.table-intro {
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--ink2);
}

.table-takeaway {
  background: var(--good-bg);
  color: var(--good);
  padding: 10px 14px;
  border-radius: var(--radius-xs);
  font-size: 14.5px;
  font-weight: 600;
  margin: -10px 0 20px;
}

.article-callout {
  background: var(--surface);
  border: 1px solid var(--line2);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin: 24px 0;
}

.article-cta-box {
  background: linear-gradient(135deg, var(--accent-bg) 0%, var(--surface) 100%);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 30px;
  margin: 40px 0;
  text-align: center;
}

.article-cta-box h3 {
  font-size: 24px;
  margin-bottom: 10px;
}

.article-cta-box p {
  color: var(--ink2);
  max-width: 560px;
  margin: 0 auto 18px;
}

/* Breadcrumbs */
.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink3);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.breadcrumbs a {
  color: var(--ink2);
}

.breadcrumbs span.separator {
  color: var(--ink3);
}

/* ============================================================
   FOOTER
   ============================================================ */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--line2);
  padding: 56px 0 40px;
  margin-top: 80px;
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1.2fr 1.2fr 1.2fr;
  gap: 32px;
  margin-bottom: 40px;
}

.footer-col-title {
  font-size: 13.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink2);
  margin-bottom: 14px;
}

.footer-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.footer-links a {
  font-size: 14px;
  color: var(--ink);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.footer-bottom {
  border-top: 1px solid var(--line2);
  padding-top: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
  color: var(--ink3);
}

.footer-disclaimer {
  font-size: 12.5px;
  color: var(--ink3);
  max-width: 780px;
  margin-top: 8px;
}

/* ============================================================
   RESPONSIVE MEDIA QUERIES (DESKTOP / TABLET / MOBILE)
   ============================================================ */
@media (max-width: 1024px) {
  .tool-grid {
    grid-template-columns: 1fr;
  }
  .preview-sticky-wrap {
    position: static;
  }
  .features-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .guides-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .footer-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .mobile-view-toggle {
    display: block;
  }
  .sticky-mobile-bar {
    display: block;
  }
  .steps-grid {
    grid-template-columns: 1fr;
  }
  .features-grid {
    grid-template-columns: 1fr;
  }
  .guides-grid {
    grid-template-columns: 1fr;
  }
  .field-grid-2, .field-grid-3, .field-grid-4 {
    grid-template-columns: 1fr;
  }
  .totals-form-grid {
    grid-template-columns: 1fr;
  }
  .footer-grid {
    grid-template-columns: 1fr;
  }
  .nav-links {
    display: none; /* Accessible mobile drawer or condensed links */
  }

  /* In mobile view, toggle between Edit and Preview */
  body.mobile-preview-active .tool-form {
    display: none !important;
  }
  body:not(.mobile-preview-active) .preview-sticky-wrap {
    display: none !important;
  }
}

/* ============================================================
   MANDATORY @media print STYLESHEET
   Accurate pagination, repeating header thead, no cut-off rows,
   totals block only on final page, hides all UI elements.
   ============================================================ */
@media print {
  @page {
    size: letter portrait;
    margin: 12mm 10mm 15mm 10mm;
  }

  /* Reset body and background */
  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 12pt;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  /* Hide ALL website navigation, forms, buttons, controls, and narrative sections */
  .site-header,
  .tool-hero,
  .tool-controls-bar,
  .tool-form,
  .mobile-view-toggle,
  .preview-actions-bar,
  .sticky-mobile-bar,
  .history-modal-backdrop,
  .zone-2,
  .site-footer,
  .btn,
  .copybtn,
  .dup-warning,
  .sig-tabs {
    display: none !important;
  }

  /* Make sure Tool container and preview take 100% of printable page */
  .container,
  .container-tool,
  .tool-grid,
  .preview-sticky-wrap,
  .preview-scale-wrap {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    position: static !important;
  }

  .invoice-doc {
    display: block !important;
    width: 100% !important;
    min-height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    box-shadow: none !important;
    color: #000000 !important;
    background: #ffffff !important;
  }

  /* Repeating Table Header on every page */
  .doc-table {
    width: 100% !important;
    border-collapse: collapse !important;
    page-break-inside: auto;
  }

  .doc-table thead {
    display: table-header-group !important;
  }

  .doc-table tbody {
    display: table-row-group !important;
  }

  /* Prevent row cut-off across pages */
  .doc-table tr,
  .item-row {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .doc-header,
  .doc-parties {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Totals block and signature only on final page */
  .doc-footer-split,
  .doc-totals-box,
  .doc-signature-box {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Ensure colors and background bands print properly */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}


/* --- Publish polish: smooth desktop feel, no layout jump --- */
@media (min-width: 1025px) {
  .preview-sticky-wrap {
    position: sticky;
    top: 76px;
  }
  .invoice-doc {
    transition: box-shadow 0.2s ease;
  }
  .guide-card, .form-card {
    transition: box-shadow 0.2s ease, transform 0.2s ease;
  }
  .guide-card:hover {
    transform: translateY(-2px);
  }
}
.item-type-cell {
  min-width: 136px;
}
.item-type-select {
  min-width: 128px;
  padding-right: 30px;
  white-space: nowrap;
}
.item-qty-cell {
  min-width: 86px;
}
.item-rate-cell {
  min-width: 112px;
}
.item-amount-cell {
  min-width: 98px;
}


/* --- TEMPLATE 6: ELEGANT (serif, centered, double rule) --- */
.tmpl-elegant { font-family: var(--font-serif); }
.tmpl-elegant .doc-top-bar { height: 2px; background: var(--tmpl-accent); margin: -40px -40px 24px; }
.tmpl-elegant .doc-header { text-align: center; margin-bottom: 28px; }
.tmpl-elegant .doc-brand-col { width: 100%; }
.tmpl-elegant .doc-title { font-size: 30px; font-weight: 400; letter-spacing: 0.18em; color: #1d1d1f; }
.tmpl-elegant .doc-meta { text-align: center; font-size: 13px; margin-top: 10px; }
.tmpl-elegant .doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 28px; border-top: 3px double #d2d2d7; border-bottom: 3px double #d2d2d7; padding: 18px 0; }
.tmpl-elegant .doc-party-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.14em; color: var(--tmpl-accent); }
.tmpl-elegant .doc-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.tmpl-elegant .doc-table th { border-bottom: 2px solid #1d1d1f; padding: 10px 8px; text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.tmpl-elegant .doc-table td { padding: 11px 8px; border-bottom: 1px solid #e8e8ed; }
.tmpl-elegant .doc-footer-split { display: grid; grid-template-columns: 55fr 45fr; gap: 24px; }
.tmpl-elegant .balance-due-line { display: flex; justify-content: space-between; font-size: 18px; font-weight: 700; border-top: 2px solid #1d1d1f; padding-top: 10px; margin-top: 8px; }

/* --- TEMPLATE 7: COMPACT (dense, more lines per page) --- */
.tmpl-compact { font-family: var(--font-sans); font-size: 12.5px; }
.tmpl-compact .invoice-doc, .tmpl-compact.invoice-doc { padding: 28px; }
.tmpl-compact .doc-top-bar { height: 4px; background: var(--tmpl-accent); margin: -28px -28px 18px; }
.tmpl-compact .doc-header { display: flex; justify-content: space-between; margin-bottom: 16px; }
.tmpl-compact .doc-title { font-size: 24px; font-weight: 800; color: var(--tmpl-accent); }
.tmpl-compact .doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.tmpl-compact .doc-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.tmpl-compact .doc-table th { background: #f5f5f7; padding: 6px 10px; text-align: left; font-size: 11px; text-transform: uppercase; }
.tmpl-compact .doc-table td { padding: 6px 10px; border-bottom: 1px solid #e8e8ed; }
.tmpl-compact .doc-footer-split { display: grid; grid-template-columns: 55fr 45fr; gap: 16px; }
.tmpl-compact .balance-due-line { display: flex; justify-content: space-between; font-size: 16px; font-weight: 800; border-top: 2px solid var(--tmpl-accent); padding-top: 8px; margin-top: 6px; }

/* --- TEMPLATE 8: DETAILED (full breakdown box) --- */
.tmpl-detailed { font-family: var(--font-sans); }
.tmpl-detailed .doc-top-bar { height: 6px; background: var(--tmpl-accent); margin: -40px -40px 30px; }
.tmpl-detailed .doc-header { display: flex; justify-content: space-between; margin-bottom: 26px; }
.tmpl-detailed .doc-title { font-size: 30px; font-weight: 800; color: var(--tmpl-accent); }
.tmpl-detailed .doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 26px; }
.tmpl-detailed .doc-table { width: 100%; border-collapse: collapse; margin-bottom: 22px; }
.tmpl-detailed .doc-table th { background: #1d1d1f; color: #fff; padding: 10px 14px; text-align: left; font-size: 12px; }
.tmpl-detailed .doc-table tbody tr:nth-child(even) td { background: #fbfbfd; }
.tmpl-detailed .doc-table td { padding: 11px 14px; border-bottom: 1px solid #e8e8ed; }
.tmpl-detailed .doc-footer-split { display: grid; grid-template-columns: 55fr 45fr; gap: 20px; }
.tmpl-detailed .doc-totals-box { border-left: 4px solid var(--tmpl-accent); background: #fbfbfd; padding: 16px; border-radius: 0 12px 12px 0; }
.tmpl-detailed .total-line { display: flex; justify-content: space-between; padding: 4px 0; }
.tmpl-detailed .balance-due-line { display: flex; justify-content: space-between; font-size: 19px; font-weight: 800; border-top: 2px solid var(--tmpl-accent); padding-top: 10px; margin-top: 8px; }

/* --- TEMPLATE 9: STUDIO (creative, large title, accent sidebar) --- */
.tmpl-studio { font-family: var(--font-sans); border-left: 10px solid var(--tmpl-accent); }
.tmpl-studio .doc-top-bar { display: none; }
.tmpl-studio .doc-header { display: block; margin-bottom: 28px; }
.tmpl-studio .doc-title { font-size: 42px; font-weight: 900; letter-spacing: -0.04em; color: #1d1d1f; line-height: 1; }
.tmpl-studio .doc-meta { text-align: left; font-size: 13px; margin-top: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.tmpl-studio .doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin-bottom: 28px; }
.tmpl-studio .doc-party-title { font-size: 12px; font-weight: 800; text-transform: uppercase; color: var(--tmpl-accent); }
.tmpl-studio .doc-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; }
.tmpl-studio .doc-table th { border-bottom: 3px solid var(--tmpl-accent); padding: 10px 8px; text-align: left; font-size: 12px; text-transform: uppercase; }
.tmpl-studio .doc-table td { padding: 13px 8px; border-bottom: 1px solid #e8e8ed; }
.tmpl-studio .doc-footer-split { display: grid; grid-template-columns: 55fr 45fr; gap: 24px; }
.tmpl-studio .balance-due-line { display: flex; justify-content: space-between; font-size: 22px; font-weight: 900; color: var(--tmpl-accent); border-top: 3px solid var(--tmpl-accent); padding-top: 10px; margin-top: 8px; }

/* --- TEMPLATE 10: RETAIL (receipt-style, mono amounts, dashed rules) --- */
.tmpl-retail { font-family: var(--font-sans); }
.tmpl-retail .doc-top-bar { height: 0; border-top: 2px dashed #d2d2d7; margin: -40px -40px 24px; }
.tmpl-retail .doc-header { text-align: center; margin-bottom: 24px; }
.tmpl-retail .doc-brand-col { width: 100%; }
.tmpl-retail .doc-title { font-size: 28px; font-weight: 800; letter-spacing: 0.08em; }
.tmpl-retail .doc-meta { text-align: center; font-family: var(--font-mono); font-size: 12.5px; margin-top: 8px; }
.tmpl-retail .doc-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 22px; padding-bottom: 16px; border-bottom: 2px dashed #d2d2d7; }
.tmpl-retail .doc-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.tmpl-retail .doc-table th { border-bottom: 2px dashed #d2d2d7; padding: 9px 8px; text-align: left; font-size: 12px; text-transform: uppercase; }
.tmpl-retail .doc-table td { padding: 10px 8px; border-bottom: 1px dashed #e8e8ed; font-family: var(--font-mono); font-size: 13px; }
.tmpl-retail .doc-table td:first-child { font-family: var(--font-sans); }
.tmpl-retail .doc-footer-split { display: grid; grid-template-columns: 55fr 45fr; gap: 20px; }
.tmpl-retail .balance-due-line { display: flex; justify-content: space-between; font-size: 19px; font-weight: 800; border-top: 2px dashed #1d1d1f; border-bottom: 2px dashed #1d1d1f; padding: 10px 0; margin-top: 8px; }
