:root {
  --bg: oklch(0.982 0.006 225);
  --bg-grid: oklch(0.56 0.032 230 / 0.1);
  --bg-wash: oklch(0.66 0.092 185 / 0.08);
  --surface: oklch(0.996 0.004 225);
  --surface-strong: oklch(0.965 0.007 225);
  --surface-raised: oklch(0.996 0.004 225 / 0.94);
  --ink: oklch(0.218 0.024 240);
  --muted: oklch(0.48 0.025 235);
  --line: oklch(0.89 0.012 230);
  --accent: oklch(0.52 0.105 185);
  --accent-hover: oklch(0.46 0.108 188);
  --accent-soft: oklch(0.94 0.035 185);
  --accent-deep: oklch(0.26 0.054 220);
  --warn-soft: oklch(0.962 0.025 78);
  --invoice-paper: oklch(0.996 0.004 225);
  --shadow: 0 18px 46px oklch(0.24 0.028 240 / 0.08);
  --radius-xl: 16px;
  --radius-lg: 10px;
  --radius-md: 8px;
  --radius-sm: 6px;
  --font-display: "Avenir Next", "Segoe UI", sans-serif;
  --font-body: "Avenir Next", "Segoe UI", sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: oklch(0.178 0.022 238);
  --bg-grid: oklch(0.78 0.02 220 / 0.07);
  --bg-wash: oklch(0.57 0.09 190 / 0.12);
  --surface: oklch(0.235 0.022 238);
  --surface-strong: oklch(0.285 0.024 235);
  --surface-raised: oklch(0.235 0.022 238 / 0.95);
  --ink: oklch(0.93 0.008 225);
  --muted: oklch(0.72 0.017 228);
  --line: oklch(0.39 0.02 235);
  --accent: oklch(0.72 0.11 182);
  --accent-hover: oklch(0.78 0.105 180);
  --accent-soft: oklch(0.36 0.055 190);
  --accent-deep: oklch(0.88 0.025 205);
  --warn-soft: oklch(0.31 0.035 82);
  --invoice-paper: oklch(0.965 0.006 225);
  --shadow: 0 22px 58px oklch(0.05 0.018 240 / 0.42);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, var(--bg-wash) 0%, transparent 34%),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px),
    linear-gradient(180deg, var(--bg-grid) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 28px 28px, 28px 28px, auto;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
}

body.is-printing {
  background: var(--invoice-paper);
}

.shell {
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding: 16px 0 44px;
}

.topbar,
.product-intro,
.strip,
.templates-section,
.panel,
.saved-drafts {
  background: var(--surface-raised);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  position: sticky;
  top: 10px;
  z-index: 10;
  backdrop-filter: blur(16px);
}

.brand,
.topbar-actions,
.theme-control {
  display: inline-flex;
  align-items: center;
}

.brand {
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font: 800 0.98rem/1 var(--font-display);
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--surface);
  font-size: 0.82rem;
}

.topbar-actions {
  gap: 14px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-actions a {
  color: var(--muted);
  text-decoration: none;
  font: 750 0.86rem/1 var(--font-display);
}

.topbar-actions a:hover {
  color: var(--ink);
}

.theme-control {
  gap: 8px;
  color: var(--muted);
  font: 750 0.78rem/1 var(--font-display);
}

.theme-control select {
  width: auto;
  min-height: 36px;
  padding: 8px 28px 8px 10px;
}

.product-intro {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(260px, 0.75fr);
  gap: 22px;
  padding: 24px;
  border-radius: var(--radius-xl);
  align-items: center;
  margin-top: 14px;
}

.eyebrow {
  margin: 0 0 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font: 800 11px/1 var(--font-display);
  color: var(--accent);
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 3.3vw, 3.75rem);
  line-height: 1.02;
  max-width: 13ch;
}

h2 {
  font-size: clamp(1.45rem, 1.8vw, 2rem);
}

h3 {
  font-size: 1.02rem;
}

.hero-text,
.helper,
.template-card p,
.saved-item p,
.strip p,
.section-heading p:last-child {
  color: var(--muted);
}

.hero-text {
  max-width: 62ch;
  font-size: 1rem;
  line-height: 1.65;
}

.builder-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  text-decoration: none;
  cursor: pointer;
  font: 800 0.9rem/1 var(--font-display);
  transition:
    transform 0.18s cubic-bezier(0.16, 1, 0.3, 1),
    border-color 0.18s ease,
    background 0.18s ease,
    box-shadow 0.18s ease;
}

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

.button:focus-visible,
.template-pill:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}

.button-primary {
  background: var(--accent);
  color: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 10px 20px oklch(0.5 0.09 185 / 0.2);
}

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

.button-secondary {
  background: var(--surface);
  color: var(--ink);
}

.button-secondary:hover {
  border-color: var(--muted);
}

.hero-points {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  padding: 0;
  margin: 20px 0 0;
  list-style: none;
  color: var(--muted);
  font-weight: 650;
}

.hero-points li::before {
  content: "•";
  color: var(--accent);
  margin-right: 8px;
}

.intro-panel {
  display: grid;
  gap: 10px;
  align-content: start;
}

.intro-panel div {
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
}

.intro-panel span {
  display: block;
  font: 700 0.75rem/1 var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.intro-panel strong {
  display: block;
  margin-top: 10px;
  font: 700 1.45rem/1.1 var(--font-display);
}

.strip,
.templates-section,
.content-section {
  margin-top: 24px;
  border-radius: var(--radius-xl);
  padding: 24px;
}

.steps,
.template-grid,
.faq-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.steps article,
.template-card,
.faq-grid article {
  padding: 16px;
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  border: 1px solid var(--line);
}

.faq-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.faq-grid p,
.seo-copy {
  color: var(--muted);
  line-height: 1.7;
}

.seo-copy {
  max-width: 78ch;
}

.disclaimer {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--warn-soft);
  border: 1px solid var(--line);
}

.steps article span {
  display: inline-flex;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  color: var(--accent);
  font: 700 0.86rem/1 var(--font-display);
}

.section-heading {
  display: grid;
  gap: 6px;
}

.builder {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(400px, 540px);
  gap: 22px;
  margin-top: 18px;
  align-items: start;
}

.panel,
.saved-drafts {
  border-radius: var(--radius-xl);
  min-width: 0;
  padding: 22px;
}

.product-intro > *,
.builder > *,
.field-grid > *,
.line-item > * {
  min-width: 0;
}

.preview-panel {
  position: sticky;
  top: 78px;
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-header.compact {
  margin-bottom: 10px;
}

.template-switch {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.template-pill {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  font: 700 0.82rem/1 var(--font-display);
}

.template-pill.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-deep);
}

.form-section + .form-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

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

.field-grid .full {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 8px;
}

label span {
  color: var(--muted);
  font: 700 0.82rem/1.1 var(--font-display);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  padding: 12px 14px;
  font: 500 0.95rem/1.4 var(--font-body);
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--muted);
}

textarea {
  resize: vertical;
  min-height: 84px;
}

.items-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.line-items {
  display: grid;
  gap: 12px;
}

.line-item {
  display: grid;
  grid-template-columns: minmax(0, 2.6fr) repeat(3, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.line-item button {
  min-height: 44px;
}

.invoice-preview {
  border-radius: var(--radius-lg);
  background: var(--surface-strong);
  padding: 14px;
  border: 1px solid var(--line);
}

.invoice-surface {
  background: var(--invoice-paper);
  min-height: 900px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  padding: 32px;
  color: oklch(0.218 0.024 240);
  box-shadow: 0 12px 28px oklch(0.24 0.028 240 / 0.08);
}

.template-professional .invoice-surface {
  background:
    linear-gradient(135deg, oklch(0.64 0.08 185 / 0.12), transparent 32%),
    var(--invoice-paper);
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid oklch(0.89 0.012 230);
  padding-bottom: 18px;
}

.invoice-kicker,
.label {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font: 700 0.72rem/1 var(--font-display);
  color: oklch(0.52 0.105 185);
}

#preview-title {
  font-size: 2.25rem;
}

.invoice-meta p,
.totals-card p {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.invoice-meta p span,
.totals-card p span,
.notes-block {
  color: oklch(0.48 0.025 235);
}

.invoice-parties {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  padding: 24px 0;
}

.invoice-parties h2 {
  font-size: 1.22rem;
  margin-bottom: 8px;
}

.invoice-parties p {
  margin: 4px 0;
}

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

.invoice-table th,
.invoice-table td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid oklch(0.89 0.012 230);
}

.invoice-table th {
  color: oklch(0.48 0.025 235);
  font: 700 0.78rem/1 var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.invoice-table td:nth-child(2),
.invoice-table td:nth-child(3),
.invoice-table td:nth-child(4) {
  text-align: right;
}

.invoice-summary {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 24px;
  padding-top: 24px;
}

.totals-card {
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid oklch(0.89 0.012 230);
  background: oklch(0.962 0.025 78);
}

.grand-total {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid oklch(0.89 0.012 230);
  font-family: var(--font-display);
  font-size: 1.08rem;
}

.saved-drafts {
  margin-top: 20px;
}

.saved-list {
  display: grid;
  gap: 10px;
}

.saved-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--line);
}

.saved-item h4 {
  margin: 0 0 6px;
  font-family: var(--font-display);
}

.saved-item p {
  margin: 0;
}

.saved-item button {
  white-space: nowrap;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  color: var(--muted);
}

@media (max-width: 1080px) {
  .product-intro,
  .builder,
  .steps,
  .template-grid,
  .faq-grid,
  .invoice-summary {
    grid-template-columns: 1fr;
  }

  .builder {
    align-items: stretch;
  }

  .preview-panel {
    position: static;
  }

  .line-item {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100% - 18px, 100%);
    padding-top: 10px;
  }

  .topbar,
  .product-intro,
  .strip,
  .templates-section,
  .content-section,
  .panel,
  .saved-drafts {
    padding: 16px;
    border-radius: 14px;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    gap: 10px;
  }

  .topbar-actions a {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  .theme-control {
    display: grid;
    grid-column: 1 / -1;
    grid-template-columns: auto minmax(0, 1fr);
  }

  .theme-control select {
    width: 100%;
  }

  h1 {
    font-size: 2.2rem;
  }

  .hero-points,
  .field-grid,
  .invoice-parties {
    grid-template-columns: 1fr;
  }

  .line-item {
    grid-template-columns: 1fr;
  }

  .panel-header {
    flex-direction: column;
  }

  .builder-actions {
    flex-direction: column;
  }

  .button {
    width: 100%;
  }

  .invoice-surface {
    min-height: 0;
    padding: 20px;
  }

  .invoice-header {
    flex-direction: column;
  }

  .invoice-table-wrap {
    overflow-x: auto;
  }

  .invoice-table {
    min-width: 520px;
  }
}

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

  html,
  body {
    width: auto;
    min-height: 0;
    background: var(--invoice-paper);
  }

  body > * {
    display: none;
  }

  .shell,
  main,
  .builder,
  .preview-panel,
  .invoice-preview,
  #print-surface {
    display: block;
  }

  .topbar,
  .product-intro,
  .form-panel,
  .panel-header,
  .saved-drafts,
  .templates-section,
  .strip,
  .content-section {
    display: none;
  }

  #print-surface {
    font-size: 12px;
    width: 100%;
    min-height: 0;
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }

  .shell,
  .preview-panel,
  .invoice-preview {
    width: 100%;
    margin: 0;
    background: var(--invoice-paper);
    padding: 0;
    border: none;
    box-shadow: none;
  }

  .invoice-table {
    min-width: 0;
  }

  .invoice-header {
    padding-bottom: 10px;
  }

  .invoice-parties {
    padding: 14px 0;
  }

  .invoice-table th,
  .invoice-table td {
    padding: 8px 6px;
  }

  .invoice-summary {
    padding-top: 14px;
  }

  #preview-title {
    font-size: 1.8rem;
  }
}
