:root {
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: rgba(29, 78, 216, 0.14);
  --surface: rgba(255, 255, 255, 0.9);
  --surface-solid: #f8fbff;
  --panel: #ffffff;
  --accent: #0066cc;
  --accent-2: #2997ff;
  --accent-soft: rgba(0, 102, 204, 0.1);
  --accent-light: rgba(41, 151, 255, 0.12);
  --danger: #dc2626;
  --ok: #059669;
  --shadow: 0 20px 60px rgba(29, 78, 216, 0.1);
  --shadow-soft: 0 8px 24px rgba(29, 78, 216, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "Source Sans 3", "Segoe UI", sans-serif;
  --display: "Cormorant Garamond", "Times New Roman", serif;
  --invoice-font: "EB Garamond", Georgia, "Times New Roman", serif;
  --signature-font: "Great Vibes", "Segoe Script", cursive;
  --bg-1: #ffffff;
  --bg-2: #eff6ff;
  --bg-3: #dbeafe;
  --sheet: #ffffff;
  --sheet-ink: #0f172a;
  --sheet-muted: #64748b;
  --touch: 44px;
}

[data-theme="dark"] {
  --ink: #f1f5f9;
  --ink-soft: #cbd5e1;
  --muted: #94a3b8;
  --line: rgba(147, 197, 253, 0.16);
  --surface: rgba(15, 23, 42, 0.88);
  --surface-solid: #0f172a;
  --panel: #111827;
  --accent: #60a5fa;
  --accent-2: #38bdf8;
  --accent-soft: rgba(96, 165, 250, 0.16);
  --accent-light: rgba(56, 189, 248, 0.1);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.3);
  --bg-1: #020617;
  --bg-2: #0f172a;
  --bg-3: #1e3a8a;
  --sheet: #ffffff;
  --sheet-ink: #0f172a;
  --sheet-muted: #64748b;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background:
    radial-gradient(1000px 520px at 0% -8%, #bfdbfe, transparent 58%),
    radial-gradient(900px 480px at 100% 0%, #93c5fd66, transparent 52%),
    radial-gradient(700px 400px at 50% 100%, #dbeafe88, transparent 55%),
    linear-gradient(165deg, #ffffff 0%, #eff6ff 42%, #dbeafe 100%);
  background-attachment: fixed;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image:
    linear-gradient(rgba(29, 78, 216, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(29, 78, 216, 0.04) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(ellipse at center, black 25%, transparent 78%);
  z-index: 0;
}

[data-theme="dark"] body {
  background:
    radial-gradient(900px 480px at 0% -10%, #1e3a8a88, transparent 55%),
    radial-gradient(800px 420px at 100% 0%, #2563eb44, transparent 50%),
    linear-gradient(165deg, #020617 0%, #0f172a 50%, #1e293b 100%);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--panel);
  padding: 0.75rem 1rem;
  z-index: 100;
}

.skip-link:focus {
  left: 1rem;
  top: 1rem;
}

.container {
  width: min(1240px, calc(100% - clamp(1rem, 4vw, 2rem)));
  margin-inline: auto;
  position: relative;
  z-index: 1;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(16px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 68px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
  color: var(--ink);
}

.brand-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
  object-position: center;
  display: block;
  flex-shrink: 0;
}

.brand-mark {
  /* legacy fallback if a page still uses the old mark */
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: linear-gradient(135deg, #0066cc 0%, #2997ff 100%);
  border: 1px solid rgba(0, 102, 204, 0.25);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.brand-text {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.55rem;
  letter-spacing: 0.02em;
  line-height: 1;
}

.menu-toggle {
  display: none;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  width: var(--touch);
  height: var(--touch);
  border-radius: var(--radius-sm);
  font-size: 1.25rem;
  cursor: pointer;
  margin-left: auto;
}

.nav {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.nav-link {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  text-decoration: none;
  cursor: pointer;
}

.nav-link:hover,
.nav-link.is-active {
  color: var(--ink);
  background: var(--accent-soft);
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.65rem 1.05rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, #0066cc, #0071e3 55%, #2997ff);
  color: #fff;
  box-shadow: 0 10px 24px rgba(0, 102, 204, 0.28);
}

.btn-sm {
  min-height: 36px;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
}

[data-theme="dark"] .btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
}

.btn-soft {
  background: var(--accent-soft);
  color: var(--ink);
  border-color: var(--line);
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border-color: var(--line);
}

.link-btn {
  appearance: none;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

.hero {
  padding: 2.5rem 0 1.25rem;
  animation: rise 0.7s ease both;
}

.eyebrow {
  display: inline-flex;
  margin: 0 0 0.75rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.hero h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(2.6rem, 8vw, 4.8rem);
  line-height: 1;
  letter-spacing: 0.01em;
  font-weight: 700;
}

.hero-lead {
  max-width: 42rem;
  margin: 1rem 0 0;
  color: var(--ink-soft);
  font-size: 1.08rem;
  line-height: 1.6;
}

.trust-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  list-style: none;
  padding: 0;
  margin: 1.4rem 0 0;
}

.trust-row li {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.workspace {
  padding-bottom: 3rem;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 1.25rem;
  align-items: start;
}

.template-customizer {
  background: var(--surface-solid);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.customizer-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.customizer-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
}

.template-select {
  padding: 0.4rem 0.65rem;
  border-radius: 8px;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.currency-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.currency-row label {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.currency-row select {
  flex: 1;
  min-width: 200px;
  border: 1px solid var(--line);
  background: var(--surface-solid);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem;
  font: inherit;
}

.color-swatches {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

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

.color-swatch.is-active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
  transform: scale(1.1);
}

.color-swatch.is-active::after {
  content: "✓";
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

.color-picker-input {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: none;
  overflow: hidden;
}

.color-picker-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker-input::-webkit-color-swatch {
  border: 1px solid var(--line);
  border-radius: 50%;
}

.preview-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.65rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.form-panel {
  padding: 1.15rem;
  animation: rise 0.75s ease 0.08s both;
}

.preview-panel {
  position: sticky;
  top: 84px;
  padding: 1rem;
  animation: rise 0.8s ease 0.15s both;
  min-width: 0;
}

.doc-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  margin-bottom: 1rem;
  padding: 0.35rem;
  border-radius: 14px;
  background: var(--surface-solid);
  border: 1px solid var(--line);
}

.doc-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 700;
  padding: 0.7rem 0.5rem;
  border-radius: 10px;
  cursor: pointer;
}

.doc-tab.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(19, 34, 28, 0.08);
}

.field-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.field-row.wrap {
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
  min-width: 0;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.field.grow {
  flex: 1;
}

.field input,
.field select,
.field textarea,
.inline-actions select,
.totals-box input,
.sig-panel input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-solid);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem;
  font: inherit;
  font-weight: 500;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.inline-actions select:focus,
.totals-box input:focus,
.sig-panel input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-color: var(--accent);
}

.block {
  margin-top: 1.35rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--line);
}

.block h2,
.preview-toolbar h2,
.info h2,
.design-panel h2 {
  margin: 0 0 0.85rem;
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.block-tight {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.design-panel {
  padding: 1rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, var(--accent-light), transparent 85%);
  border: 1px solid var(--line);
  margin-bottom: 1rem;
}

.color-picker-block {
  margin-top: 0.85rem;
}

.field-label {
  display: block;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 0.35rem;
}

.color-swatches {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.55rem;
  margin: 0.65rem 0 0.85rem;
}

.swatch {
  appearance: none;
  border: 2px solid transparent;
  background: var(--swatch);
  aspect-ratio: 1;
  min-height: 36px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.swatch:hover {
  transform: scale(1.08);
}

.swatch.is-active {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--panel), 0 0 0 5px var(--swatch);
}

.custom-color {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.custom-color-label {
  font-weight: 700;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

.custom-color-input {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
}

.custom-color-input input[type="color"] {
  width: 48px;
  height: 48px;
  padding: 0;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}

.custom-color-input output {
  font-family: ui-monospace, monospace;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-soft);
  min-width: 4.5rem;
}

.font-picker-block {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.font-preview {
  margin-top: 0.65rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  display: grid;
  gap: 0.35rem;
}

.font-preview-title {
  font-family: var(--preview-display, var(--display));
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.font-preview-body {
  font-family: var(--preview-body, var(--invoice-font));
  font-size: 0.95rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.block-head h2 {
  margin: 0;
}

.inline-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}

.inline-actions select {
  min-width: 180px;
}

.chip-row,
.sig-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.55rem 0 0.85rem;
}

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-solid);
  color: var(--ink-soft);
  font: inherit;
  font-weight: 700;
  font-size: 0.82rem;
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
}

.chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

[data-theme="dark"] .chip.is-active {
  color: #fff;
}

.upload-box {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 46px;
  padding: 0.65rem 0.8rem;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.86rem;
}

.upload-box input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.table-wrap {
  overflow-x: auto;
  margin-bottom: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

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

.items-table th,
.items-table td {
  padding: 0.55rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.86rem;
}

.items-table th {
  background: var(--surface-solid);
  color: var(--muted);
  font-weight: 700;
}

.items-table input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font: inherit;
  padding: 0.4rem;
  border-radius: 8px;
}

.items-table input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-solid);
}

.items-table .col-num {
  width: 40px;
  color: var(--muted);
  font-weight: 700;
}

.items-table .col-qty,
.items-table .col-rate {
  width: 90px;
}

.items-table .col-amt {
  width: 100px;
  font-weight: 700;
  white-space: nowrap;
}

.items-table .col-del {
  width: 42px;
}

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--danger);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem;
}

.totals-box {
  margin-top: 1rem;
  max-width: 340px;
  margin-left: auto;
  display: grid;
  gap: 0.55rem;
}

.total-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.total-line.edit label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.total-line.edit input {
  width: 72px;
  padding: 0.4rem 0.5rem;
}

.total-line.grand {
  margin-top: 0.25rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  color: var(--ink);
  font-size: 1.1rem;
}

.hint {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0.5rem 0 0;
}

.sig-panel {
  margin-top: 0.65rem;
}

#sigCanvas {
  width: 100%;
  max-width: 480px;
  height: 160px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  touch-action: none;
  cursor: crosshair;
  display: block;
}

.sig-typed-preview {
  min-height: 64px;
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: #111;
  font-family: var(--signature-font);
  font-size: 2rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1.35rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 0;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(8px);
  z-index: 5;
}

.autosave {
  margin-left: auto;
  color: var(--ok);
  font-size: 0.82rem;
  font-weight: 700;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.preview-toolbar h2 {
  margin: 0;
}

.preview-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.preview-panel.is-collapsed .preview-stage {
  display: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.preview-stage {
  overflow: visible;
  max-height: none;
  border-radius: 14px;
  background:
    linear-gradient(160deg, #eff6ff, #f8fbff 40%, #dbeafe66),
    var(--surface-solid);
  padding: 0.85rem;
  position: relative;
}

.preview-scale-wrap {
  width: 100%;
  max-width: 100%;
}

.invoice-sheet {
  position: relative;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  background: var(--sheet);
  color: var(--sheet-ink);
  border-radius: 6px;
  box-shadow:
    0 1px 0 rgba(26, 35, 50, 0.06),
    0 16px 48px rgba(26, 35, 50, 0.12);
  padding: 1.5rem;
  overflow: hidden;
  font-family: var(--inv-font, var(--invoice-font));
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid rgba(26, 35, 50, 0.08);
}

/* Desktop sticky preview */
@media (min-width: 981px) {
  .preview-stage {
    max-height: calc(100vh - 140px);
    overflow: auto;
  }

  .invoice-sheet {
    min-height: 720px;
  }
}

/* PDF capture uses A4 desktop layout */
.invoice-sheet.is-pdf-capture {
  width: 794px !important;
  max-width: 794px !important;
  min-height: 1123px;
  padding: 1.75rem;
  font-size: 13px;
}

.invoice-sheet.is-pdf-capture .inv-top {
  flex-direction: row !important;
}

.invoice-sheet.is-pdf-capture .inv-meta {
  text-align: right !important;
}

.invoice-sheet.is-pdf-capture .inv-parties,
.invoice-sheet.is-pdf-capture .inv-bottom {
  grid-template-columns: 1fr 1fr !important;
}

.invoice-sheet.is-pdf-capture .inv-table {
  display: table !important;
  width: 100% !important;
}

.invoice-sheet * {
  box-sizing: border-box;
}

.invoice-sheet::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: min(140px, 30%);
  height: min(140px, 22%);
  pointer-events: none;
  background: linear-gradient(
    225deg,
    color-mix(in srgb, var(--inv-accent, var(--accent)) 14%, transparent) 0%,
    transparent 68%
  );
}

.watermark {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 2;
  font-family: var(--inv-display, var(--display));
  font-size: clamp(3rem, 10vw, 5rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  transform: rotate(-28deg);
  opacity: 0.13;
}

.watermark.paid {
  color: #067647;
}

.watermark.draft {
  color: #667085;
}

.inv-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.inv-brand {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.inv-logo {
  max-width: 72px;
  max-height: 72px;
  object-fit: contain;
}

.inv-biz-name {
  font-family: var(--inv-display, var(--display));
  font-size: clamp(1.15rem, 3vw, 1.45rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0 0 0.2rem;
}

.inv-meta {
  text-align: right;
}

.inv-title {
  margin: 0;
  font-family: var(--inv-display, var(--display));
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.inv-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin: 1rem 0 1.25rem;
}

.inv-label {
  font-family: var(--inv-display, var(--display));
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sheet-muted);
  margin-bottom: 0.25rem;
}

.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0 1rem;
}

.inv-table th {
  font-family: var(--inv-display, var(--display));
  text-align: left;
  padding: 0.55rem 0.4rem;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  background: var(--inv-accent, var(--accent, #1b365d));
}

.inv-table td {
  padding: 0.55rem 0.4rem;
  border-bottom: 1px solid #e5ebe8;
  vertical-align: top;
}

.inv-table .num {
  text-align: right;
  white-space: nowrap;
}

.inv-bottom {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1rem;
  margin-top: 0.5rem;
}

.inv-totals {
  display: grid;
  gap: 0.35rem;
}

.inv-totals .row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.inv-totals .grand {
  margin-top: 0.25rem;
  padding-top: 0.45rem;
  border-top: 2px solid var(--inv-accent, var(--accent));
  font-weight: 700;
  font-size: 1.08rem;
  color: var(--inv-accent, var(--accent));
}

.inv-words {
  margin-top: 0.55rem;
  font-style: italic;
  color: var(--sheet-muted);
}

.inv-qr {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.85rem;
}

.inv-qr canvas,
.inv-qr img {
  width: 88px !important;
  height: 88px !important;
}

.inv-sign {
  margin-top: 1.5rem;
  display: flex;
  justify-content: flex-end;
}

.inv-sign-box {
  min-width: 180px;
  text-align: center;
}

.inv-sign-box img {
  max-width: 160px;
  max-height: 70px;
  object-fit: contain;
}

.inv-sign-line {
  border-top: 1px solid #cfd8d3;
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--sheet-muted);
}

/* Styles — InvoiceFast set: modern / classic / minimal */
.style-modern .inv-title {
  color: var(--inv-accent, var(--accent));
}

.style-classic .inv-table th {
  background: var(--inv-accent, var(--accent));
}

.style-classic {
  border-top: 8px solid var(--inv-accent, var(--accent));
}

.style-classic .inv-top {
  background: #f8fbff;
  margin: -1.5rem -1.5rem 1.25rem;
  padding: 1.5rem;
}

.style-minimal .inv-table th {
  background: transparent;
  color: var(--sheet-muted);
  border-bottom: 2px solid var(--inv-accent, var(--accent));
}

.style-minimal .inv-title {
  font-weight: 600;
  letter-spacing: 0.18em;
  font-size: 1.25rem;
  color: var(--inv-accent, var(--accent));
}

.style-minimal {
  background:
    linear-gradient(90deg, var(--inv-accent, var(--accent)) 0 8px, transparent 8px),
    #fff;
  padding-left: calc(1.5rem + 8px);
}

.info {
  padding: 2rem 0 1rem;
}

.steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.steps article,
.faq-list details {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem;
  box-shadow: var(--shadow);
}

.step-num {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #1d4ed8, #3b82f6);
  color: #fff;
  font-weight: 800;
  margin-bottom: 0.65rem;
}

[data-theme="dark"] .step-num {
  color: #fff;
}

.steps h3 {
  margin: 0 0 0.4rem;
  font-family: var(--display);
}

.steps p,
.faq-list p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.55;
}

.faq-list {
  display: grid;
  gap: 0.65rem;
}

.faq-list summary {
  cursor: pointer;
  font-weight: 750;
  font-family: var(--display);
}

.faq-list details[open] summary {
  margin-bottom: 0.55rem;
}

.site-footer {
  margin-top: 2rem;
  border-top: 1px solid var(--line);
  padding: 2rem 0 5.5rem;
  color: var(--muted);
}

.footer-inner {
  display: grid;
  gap: 0.55rem;
}

.brand-sm .brand-text {
  font-size: 1.1rem;
}

.brand-sm .brand-logo {
  width: 28px;
  height: 28px;
}

.copy {
  margin: 0;
  font-size: 0.86rem;
}

.fab-download {
  display: none;
  position: fixed;
  left: max(1rem, env(safe-area-inset-left));
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 45;
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.95rem 1rem;
  background: linear-gradient(135deg, #1d4ed8, #3b82f6);
  color: #fff;
  font: inherit;
  font-weight: 800;
  box-shadow: 0 14px 30px rgba(29, 78, 216, 0.35);
  cursor: pointer;
}

[data-theme="dark"] .fab-download {
  color: #fff;
}

.modal[hidden],
.toast[hidden],
[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 16, 14, 0.55);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: min(80vh, 700px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--panel);
}

.modal-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.15rem;
}

.modal-body {
  padding: 0.75rem 1.1rem 1.1rem;
  display: grid;
  gap: 0.65rem;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
}

.history-item strong {
  display: block;
}

.history-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

.history-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 70;
  background: var(--ink);
  color: var(--panel);
  padding: 0.8rem 1.1rem;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========== Tablet & Phone (InvoiceFast-style layout) ========== */
@media (max-width: 1068px) {
  .workspace-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .form-panel {
    order: 1;
  }

  .preview-panel {
    order: 2;
    position: static;
    top: auto;
  }
}

@media (max-width: 980px) {
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  .container {
    width: calc(100% - 1.25rem);
    max-width: 100%;
  }

  .header-inner {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 0.5rem;
    position: relative;
    min-height: 56px;
  }

  .menu-toggle {
    display: inline-grid;
    place-items: center;
    margin-left: 0;
  }

  .header-actions { justify-self: end; }
  .header-actions .btn-primary { display: none; }

  .nav {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    margin: 0;
    padding: 0.65rem;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 50;
  }

  .nav.is-open { display: flex; }

  .nav-link {
    width: 100%;
    min-height: var(--touch);
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .fab-download { display: block; }
  .action-bar #downloadPdf { display: none; }

  main#app {
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0));
  }

  .steps { grid-template-columns: 1fr; }

  .template-customizer {
    flex-direction: column;
    align-items: stretch;
  }

  .customizer-group {
    width: 100%;
    justify-content: space-between;
  }

  /* Same display method as InvoiceFast: keep full invoice width, scroll horizontally */
  .preview-panel {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 0.5rem;
  }

  .preview-stage,
  .preview-scale-wrap {
    width: max-content;
    max-width: none;
    height: auto !important;
    transform: none !important;
    padding: 0;
    overflow: visible;
    background: transparent;
  }

  .invoice-sheet {
    width: 520px !important;
    min-width: 520px !important;
    max-width: none !important;
    min-height: 0 !important;
    height: auto !important;
    transform: none !important;
    padding: 1.5rem 1.15rem;
    font-size: 13px;
  }

  .inv-top {
    flex-direction: row;
    align-items: flex-start;
  }

  .inv-meta { text-align: right; }

  .inv-parties,
  .inv-bottom {
    grid-template-columns: 1fr 1fr;
  }

  .inv-table {
    display: table;
    width: 100%;
    table-layout: auto;
  }

  .inv-table th:nth-child(1),
  .inv-table td:nth-child(1) {
    display: table-cell;
  }
}

@media (max-width: 640px) {
  .container { width: calc(100% - 0.9rem); }

  .field-row, .field-row.wrap { flex-direction: column; }

  .hero { padding: 0.85rem 0 0.6rem; }
  .hero h1 { font-size: clamp(1.9rem, 10vw, 2.4rem); }
  .hero-lead { font-size: 0.92rem; }

  .trust-row { gap: 0.35rem; }
  .trust-row li { font-size: 0.7rem; padding: 0.28rem 0.5rem; }

  .form-panel, .preview-panel {
    padding: 1rem 0.85rem;
    border-radius: 14px;
    width: 100%;
    box-sizing: border-box;
  }

  .invoice-sheet {
    width: 480px !important;
    min-width: 480px !important;
    padding: 1.35rem 1rem;
  }

  .doc-tabs { grid-template-columns: repeat(3, 1fr); }
  .doc-tab { font-size: 0.78rem; min-height: 42px; }

  .block-head { flex-direction: column; align-items: stretch; }
  .inline-actions { flex-direction: column; align-items: stretch; }

  .inline-actions select,
  .inline-actions .btn,
  .field input,
  .field select,
  .field textarea {
    width: 100%;
    min-height: var(--touch);
    font-size: 16px;
  }

  .btn {
    min-height: var(--touch);
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .totals-box { max-width: none; margin-left: 0; width: 100%; }

  .items-table { min-width: 0; width: 100%; }
  .items-table input { font-size: 16px; }

  .action-bar {
    flex-wrap: wrap;
    gap: 0.45rem;
    padding-bottom: 0.5rem;
  }

  .action-bar .btn {
    flex: 1 1 calc(50% - 0.25rem);
    width: auto;
  }

  .autosave { width: 100%; margin-left: 0; text-align: center; }

  .fab-download {
    left: max(0.75rem, env(safe-area-inset-left));
    right: max(0.75rem, env(safe-area-inset-right));
    bottom: max(0.75rem, env(safe-area-inset-bottom));
    min-height: 50px;
  }

  .site-footer { padding-bottom: 6.5rem; }

  .currency-row {
    flex-direction: column;
    align-items: stretch;
  }

  .currency-row select { min-width: 0; width: 100%; }
}

@media (max-width: 420px) {
  .color-swatch { width: 28px; height: 28px; }
  .trust-row li { font-size: 0.66rem; }
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  html,
  body {
    background: #ffffff !important;
    color: #000 !important;
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    overflow: visible !important;
  }

  body::before {
    display: none !important;
  }

  /* Hide everything except the dedicated print root */
  body.printing-invoice > *:not(#printRoot) {
    display: none !important;
  }

  body.printing-invoice #printRoot,
  #printRoot {
    display: block !important;
    position: static !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    overflow: visible !important;
  }

  #printRoot .invoice-sheet,
  #printRoot #invoicePreview {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #ffffff !important;
    overflow: visible !important;
    transform: none !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  #printRoot .invoice-sheet *,
  #printRoot #invoicePreview * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  #printRoot .watermark {
    opacity: 0.12 !important;
  }
}

/* Screen: print root must stay hidden */
#printRoot[hidden],
#printRoot:not(.is-ready) {
  display: none !important;
}
