* {
  box-sizing: border-box;
}

:root {
  --page: #f5f7fb;
  --surface: #ffffff;
  --ink: #0b1020;
  --text: #344054;
  --muted: #6b7280;
  --line: #e5e9f2;
  --line-strong: #cbd5e1;
  --blue: #2563eb;
  --blue-dark: #1649c7;
  --blue-soft: #edf4ff;
  --green: #14966f;
  --green-soft: #e9f9f2;
  --rose-soft: #fff1f3;
  --shadow: 0 28px 80px rgba(15, 23, 42, 0.12);
  --shadow-soft: 0 16px 45px rgba(15, 23, 42, 0.08);
  --shadow-hard: 0 36px 100px rgba(15, 23, 42, 0.18);
  --radius-lg: 26px;
  --radius-md: 18px;
  --preview-scale: 0.66;
}

html {
  width: 100%;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

body {
  width: 100%;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(37, 99, 235, 0.08), transparent 28%),
    radial-gradient(circle at 88% 18%, rgba(20, 150, 111, 0.08), transparent 24%),
    linear-gradient(180deg, #ffffff 0, #f9fbff 340px, var(--page) 100%);
  font-family:
    Inter,
    "Plus Jakarta Sans",
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Arial,
    sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.invoice-container {
  width: min(1440px, calc(100% - 48px));
  margin: 0 auto;
}

.invoice-header {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid rgba(226, 232, 240, 0.86);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(22px);
}

.header-inner {
  min-height: 72px;
  display: grid;
  grid-template-columns: 172px minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
}

.logo {
  display: inline-flex;
  align-items: center;
}

.logo img {
  height: 58px;
  width: auto;
  object-fit: contain;
}

.tool-nav {
  display: flex;
  justify-content: center;
  gap: 10px;
  color: #465166;
  font-size: 14px;
  font-weight: 800;
}

.tool-nav a {
  padding: 9px 13px;
  border-radius: 999px;
  transition:
    color 0.18s ease,
    background 0.18s ease;
}

.tool-nav a:hover,
.tool-nav a[aria-current="page"] {
  color: var(--blue);
  background: var(--blue-soft);
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.ghost-action,
.quiet-action,
.print-action {
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  padding: 0 16px;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease;
}

.ghost-action {
  color: var(--blue);
  background: var(--blue-soft);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.14);
}

.quiet-action {
  color: #667085;
  background: #f3f6fb;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.06);
}

.print-action {
  color: #ffffff;
  background: linear-gradient(135deg, #2563eb, #174ec9);
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.28);
}

.ghost-action:hover,
.quiet-action:hover,
.print-action:hover {
  transform: translateY(-1px);
}

.print-action.is-exporting {
  opacity: 0.82;
  pointer-events: none;
}

.invoice-page {
  padding: 40px 0 80px;
}

.page-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 28px;
  margin: 0 0 28px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.page-hero h1 {
  max-width: 820px;
  margin: 0;
  font-size: clamp(42px, 5vw, 72px);
  line-height: 0.98;
  letter-spacing: 0;
}

.page-hero p:not(.eyebrow) {
  max-width: 680px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.72;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 10px;
  padding: 10px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow:
    inset 0 0 0 1px rgba(226, 232, 240, 0.8),
    var(--shadow-soft);
}

.hero-stats span {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 13px 14px;
  border-radius: 14px;
  color: var(--muted);
  background: #ffffff;
  font-size: 12px;
  font-weight: 850;
}

.hero-stats strong {
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
}

.template-area {
  margin-bottom: 26px;
}

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

.section-heading h2 {
  margin: 0;
  font-size: 25px;
  letter-spacing: 0;
}

.section-heading > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.template-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.template-choice {
  position: relative;
  display: grid;
  gap: 15px;
  border: 1px solid rgba(226, 232, 240, 0.88);
  border-radius: 24px;
  padding: 14px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(255, 255, 255, 0.82)),
    #ffffff;
  color: var(--ink);
  text-align: left;
  box-shadow: var(--shadow-soft);
  transition:
    transform 0.22s ease,
    box-shadow 0.22s ease,
    border-color 0.22s ease;
}

.template-choice::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 18px;
  border: 1px solid transparent;
  pointer-events: none;
  transition: border-color 0.22s ease;
}

.template-choice:hover {
  transform: translateY(-6px);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.12);
}

.template-choice.active {
  border-color: rgba(37, 99, 235, 0.55);
  box-shadow: 0 28px 74px rgba(37, 99, 235, 0.16);
}

.template-choice.active::after {
  border-color: rgba(37, 99, 235, 0.2);
}

.template-preview-slot {
  position: relative;
  display: block;
  aspect-ratio: 1.42 / 1;
  min-height: 230px;
  overflow: hidden;
  border-radius: 18px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.9), rgba(238, 242, 247, 0.86)),
    #f8fafc;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.template-preview-slot img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  z-index: 2;
}

.template-preview-slot.image-missing img {
  display: none;
}

.invoice-mockup {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(64%, 230px);
  aspect-ratio: 210 / 297;
  transform: translate(-50%, -50%);
  border-radius: 10px;
  background: #ffffff;
  box-shadow:
    0 22px 48px rgba(15, 23, 42, 0.16),
    inset 0 0 0 1px rgba(15, 23, 42, 0.06);
}

.invoice-mockup span {
  position: absolute;
  display: block;
  border-radius: 999px;
}

.mock-head {
  left: 12%;
  top: 10%;
  width: 36%;
  height: 3%;
  background: #101828;
}

.mock-meta {
  right: 12%;
  top: 10%;
  width: 25%;
  height: 3%;
  background: #2563eb;
}

.mock-bill {
  left: 12%;
  top: 22%;
  width: 76%;
  height: 14%;
  border-radius: 8px !important;
  background: #f1f5f9;
}

.mock-row {
  left: 12%;
  top: 45%;
  width: 76%;
  height: 3%;
  background: #d7dee9;
  box-shadow:
    0 22px 0 #e3e8f0,
    0 44px 0 #e3e8f0;
}

.mock-row.short {
  top: 63%;
  width: 58%;
  box-shadow: none;
}

.mock-total {
  right: 12%;
  bottom: 11%;
  width: 34%;
  height: 8%;
  border-radius: 8px !important;
  background: #e4efff;
}

.modern-mockup {
  overflow: hidden;
}

.modern-mockup .mock-band {
  inset: 0 0 auto 0;
  height: 18%;
  border-radius: 10px 10px 0 0 !important;
  background: linear-gradient(135deg, #174ec9, #2563eb);
}

.modern-mockup .mock-head,
.modern-mockup .mock-meta {
  top: 7%;
  background: #ffffff;
}

.modern-mockup .mock-total {
  background: #2563eb;
}

.minimal-mockup .mock-head,
.minimal-mockup .mock-meta {
  background: #111827;
}

.minimal-mockup .mock-rule {
  left: 12%;
  top: 18%;
  width: 76%;
  height: 1px;
  background: #111827;
}

.minimal-mockup .mock-total {
  background: #111827;
}

.template-copy {
  display: grid;
  gap: 4px;
  padding: 0 2px 2px;
}

.template-copy strong {
  font-size: 18px;
  font-weight: 950;
}

.template-copy small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.48;
}

.invoice-builder {
  display: grid;
  grid-template-columns: minmax(420px, 0.45fr) minmax(560px, 0.55fr);
  gap: 24px;
  align-items: start;
  padding: 18px;
  border: 1px solid rgba(226, 232, 240, 0.76);
  border-radius: 30px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.76), rgba(244, 247, 252, 0.92)),
    #f4f6fa;
  box-shadow: var(--shadow);
}

.invoice-form,
.field-stack,
.items-list {
  display: grid;
  gap: 14px;
}

.form-panel {
  padding: 22px;
  border: 1px solid rgba(226, 232, 240, 0.86);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.06);
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  margin-bottom: 18px;
}

.panel-heading > span {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 12px;
  color: #ffffff;
  background: linear-gradient(135deg, #2563eb, #174ec9);
  font-size: 12px;
  font-weight: 950;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.23);
}

.panel-heading h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.panel-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.field-grid {
  display: grid;
  gap: 14px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.invoice-form label {
  display: block;
  color: #101828;
  font-size: 13px;
  font-weight: 850;
}

.invoice-form input,
.invoice-form textarea,
.invoice-form select {
  width: 100%;
  min-height: 48px;
  margin-top: 7px;
  border: 1px solid #d7deea;
  border-radius: 13px;
  outline: none;
  background: #fbfdff;
  color: var(--ink);
  padding: 13px 14px;
  font-size: 14px;
  line-height: 1.45;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease,
    transform 0.18s ease;
}

.invoice-form textarea {
  min-height: 98px;
  resize: vertical;
}

.invoice-form input::placeholder,
.invoice-form textarea::placeholder {
  color: #8a95a8;
}

.invoice-form select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #667085 50%),
    linear-gradient(135deg, #667085 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 50%,
    calc(100% - 13px) 50%;
  background-size:
    5px 5px,
    5px 5px;
  background-repeat: no-repeat;
}

.invoice-form input:focus,
.invoice-form textarea:focus,
.invoice-form select:focus {
  border-color: #7ea0ee;
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.09);
}

.logo-upload {
  position: relative;
  min-height: 126px;
  display: grid !important;
  place-items: center;
  gap: 7px;
  margin-top: 14px;
  border: 1.5px dashed #a7b8de;
  border-radius: 18px;
  color: #46516b !important;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(246, 249, 253, 0.92)),
    #fbfdff;
  text-align: center;
  overflow: hidden;
  transition:
    border-color 0.18s ease,
    background 0.18s ease;
}

.logo-upload:hover {
  border-color: var(--blue);
  background: #ffffff;
}

.logo-upload input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.logo-preview {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  overflow: hidden;
  color: #ffffff;
  background: linear-gradient(135deg, #2563eb, #69a7ff);
  font-weight: 950;
  box-shadow: 0 14px 28px rgba(37, 99, 235, 0.22);
}

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

.logo-upload small {
  color: var(--muted);
  font-size: 12px;
}

.item-card {
  padding: 16px;
  border: 1px solid rgba(226, 232, 240, 0.88);
  border-radius: 18px;
  background: #fbfcff;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.04);
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.item-card:hover {
  border-color: #c6d4f3;
  box-shadow: 0 16px 38px rgba(15, 23, 42, 0.08);
}

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

.item-head strong {
  font-size: 15px;
  font-weight: 950;
}

.remove-item,
.add-item-btn {
  border: 0;
  border-radius: 999px;
  font-weight: 900;
  transition:
    transform 0.18s ease,
    background 0.18s ease,
    box-shadow 0.18s ease;
}

.remove-item {
  min-height: 32px;
  padding: 0 12px;
  color: #b42318;
  background: var(--rose-soft);
  font-size: 12px;
}

.remove-item:hover,
.add-item-btn:hover {
  transform: translateY(-1px);
}

.add-item-btn {
  min-height: 46px;
  width: max-content;
  padding: 0 18px;
  color: var(--blue);
  background: #edf4ff;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.16);
}

.item-total {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
  color: var(--green);
  font-size: 13px;
  font-weight: 950;
  transition: transform 0.22s ease;
}

.item-total.bump,
.total-chip.bump {
  animation: totalBump 0.34s ease;
}

@keyframes totalBump {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.035);
  }
  100% {
    transform: scale(1);
  }
}

.draft-status {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-radius: 14px;
  color: #176552;
  background: var(--green-soft);
  font-size: 13px;
  font-weight: 850;
}

.draft-status.warning {
  color: #9f2f21;
  background: #fff1f0;
}

.preview-column {
  position: sticky;
  top: 92px;
  min-width: 0;
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 12px;
  padding: 16px 18px;
  border: 1px solid rgba(226, 232, 240, 0.8);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.07);
}

.preview-toolbar h2 {
  margin: 0;
  font-size: 24px;
}

.preview-toolbar span:not(.total-chip) {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.total-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 15px;
  border-radius: 999px;
  color: #0f5c46;
  background: linear-gradient(180deg, #effdf6, #dcf8ec);
  box-shadow:
    inset 0 0 0 1px rgba(20, 150, 111, 0.16),
    0 12px 28px rgba(20, 150, 111, 0.12);
  font-size: 14px;
  font-weight: 950;
  white-space: nowrap;
}

.paper-frame {
  width: 100%;
  min-height: calc(1123px * var(--preview-scale) + 36px);
  overflow: hidden;
  border: 1px solid rgba(226, 232, 240, 0.82);
  border-radius: 26px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.42), rgba(229, 234, 243, 0.74)),
    #eef2f7;
  padding: 18px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.58),
    var(--shadow-soft);
}

.invoice-paper {
  width: 794px;
  min-height: 1123px;
  transform: scale(var(--preview-scale));
  transform-origin: top left;
  margin: 0 auto calc(-1123px + (1123px * var(--preview-scale)));
  overflow: hidden;
  color: #1d2939;
  background: #ffffff;
  box-shadow: var(--shadow-hard);
  transition:
    opacity 0.2s ease,
    transform 0.22s ease,
    box-shadow 0.22s ease;
}

.invoice-paper.is-updating {
  opacity: 0.72;
}

.invoice-paper h1,
.invoice-paper h2,
.invoice-paper h3,
.invoice-paper h4,
.invoice-paper p {
  margin: 0;
}

.paper-inner {
  min-height: 1123px;
  padding: 58px;
}

.paper-header {
  display: flex;
  justify-content: space-between;
  gap: 36px;
  margin-bottom: 42px;
}

.brand-block {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.paper-logo {
  width: 68px;
  height: 68px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 16px;
  overflow: hidden;
  color: #ffffff;
  background: linear-gradient(135deg, #2563eb, #69a7ff);
  font-size: 28px;
  font-weight: 950;
}

.paper-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.brand-block h2 {
  font-size: 26px;
  line-height: 1.12;
}

.brand-block p,
.invoice-meta p,
.party-card p,
.payment-box p,
.notes-box p,
.footer-note {
  color: #667085;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-line;
}

.company-tax {
  display: block;
  margin-top: 5px;
  color: #475467;
  font-size: 12px;
  font-weight: 850;
}

.invoice-title {
  text-align: right;
}

.invoice-title h1 {
  color: var(--blue);
  font-size: 44px;
  letter-spacing: 0;
}

.invoice-meta {
  display: grid;
  gap: 5px;
  margin-top: 12px;
}

.invoice-meta strong {
  color: #101828;
}

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

.party-card {
  padding: 20px;
  border-radius: 16px;
  background: #f8fafc;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.06);
}

.party-card span,
.summary-row span,
.payment-box span,
.notes-box span {
  display: block;
  color: #667085;
  font-size: 12px;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

.party-card h3 {
  margin: 8px 0 6px;
  font-size: 18px;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 26px;
}

.invoice-table th,
.invoice-table td {
  padding: 14px 12px;
  border-bottom: 1px solid #e4eaf2;
  font-size: 13px;
  text-align: right;
  vertical-align: top;
}

.invoice-table th:first-child,
.invoice-table td:first-child {
  text-align: left;
}

.invoice-table th {
  color: #475467;
  background: #f8fafc;
  font-size: 11px;
  font-weight: 950;
  text-transform: uppercase;
}

.item-name {
  color: #101828;
  font-weight: 950;
}

.item-description {
  margin-top: 4px;
  color: #667085;
  line-height: 1.45;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 288px;
  gap: 24px;
  align-items: start;
  margin-top: 18px;
}

.payment-box,
.notes-box {
  padding: 18px;
  border-radius: 16px;
  background: #f8fafc;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.06);
}

.notes-box {
  margin-top: 14px;
}

.payment-box p,
.notes-box p {
  margin-top: 8px;
}

.totals-box {
  padding: 20px;
  border-radius: 18px;
  background: #ffffff;
  box-shadow:
    inset 0 0 0 1px rgba(15, 23, 42, 0.08),
    0 14px 32px rgba(15, 23, 42, 0.07);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 0;
  color: #344054;
  font-size: 14px;
}

.summary-row.total {
  margin-top: 10px;
  padding: 16px 0 0;
  border-top: 1px solid #d0d5dd;
  color: var(--blue);
  font-size: 22px;
  font-weight: 950;
}

.footer-note {
  margin-top: 34px !important;
  padding-top: 16px;
  border-top: 1px solid #e4eaf2;
  text-align: center;
}

.modern-template .paper-inner {
  padding-top: 0;
}

.modern-template .paper-header {
  margin: 0 -58px 38px;
  padding: 52px 58px 42px;
  color: #ffffff;
  background: linear-gradient(135deg, #174ec9, #2563eb);
}

.modern-template .brand-block p,
.modern-template .invoice-meta p,
.modern-template .invoice-meta strong,
.modern-template .company-tax {
  color: rgba(255, 255, 255, 0.86);
}

.modern-template .invoice-title h1 {
  color: #ffffff;
}

.modern-template .paper-logo {
  color: var(--blue);
  background: #ffffff;
}

.modern-template .summary-row.total {
  color: #ffffff;
  background: var(--blue);
  margin: 14px -20px -20px;
  padding: 18px 20px;
  border-radius: 0 0 18px 18px;
}

.minimal-template .paper-inner {
  padding: 64px;
}

.minimal-template .paper-logo {
  color: #ffffff;
  background: #111827;
}

.minimal-template .invoice-title h1,
.minimal-template .summary-row.total {
  color: #111827;
}

.minimal-template .party-card,
.minimal-template .payment-box,
.minimal-template .notes-box {
  background: #ffffff;
  box-shadow: inset 0 0 0 1px #d0d5dd;
}

@media print {
  body * {
    visibility: hidden;
  }

  #invoicePreview,
  #invoicePreview * {
    visibility: visible;
  }

  body {
    background: #ffffff;
  }

  #invoicePreview {
    position: absolute;
    left: 0;
    top: 0;
    width: 210mm !important;
    min-height: 297mm !important;
    margin: 0 !important;
    transform: none !important;
    box-shadow: none !important;
  }
}

@media (max-width: 1280px) {
  :root {
    --preview-scale: 0.58;
  }

  .invoice-builder {
    grid-template-columns: minmax(390px, 0.48fr) minmax(470px, 0.52fr);
  }
}

@media (max-width: 1120px) {
  :root {
    --preview-scale: 0.56;
  }

  .header-inner {
    grid-template-columns: 1fr auto;
  }

  .tool-nav {
    order: 3;
    grid-column: 1 / -1;
    justify-content: flex-start;
    overflow-x: auto;
    padding: 0 0 12px;
    scrollbar-width: none;
  }

  .tool-nav::-webkit-scrollbar {
    display: none;
  }

  .page-hero {
    grid-template-columns: 1fr;
  }

  .hero-stats {
    max-width: 560px;
  }

  .invoice-builder {
    grid-template-columns: 1fr;
  }

  .preview-column {
    position: static;
  }

  .paper-frame {
    overflow-x: auto;
  }

  .invoice-paper {
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 860px) {
  .template-strip {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding: 2px 2px 16px;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .template-choice {
    min-width: min(82vw, 360px);
    scroll-snap-align: start;
  }

  .template-preview-slot {
    min-height: 210px;
  }
}

@media (max-width: 760px) {
  :root {
    --preview-scale: 0.42;
  }

  .invoice-container {
    width: min(100% - 24px, 1440px);
  }

  .header-inner {
    min-height: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 10px 12px;
    padding: 12px 0 0;
  }

  .logo {
    flex: 1 1 auto;
  }

  .logo img {
    height: 46px;
  }

  .header-actions {
    flex: 0 0 auto;
    gap: 8px;
  }

  .ghost-action,
  .quiet-action,
  .print-action {
    min-height: 38px;
    padding: 0 12px;
    font-size: 12px;
  }

  .tool-nav {
    width: 100%;
    gap: 6px;
    padding: 6px 0 12px;
    font-size: 13px;
  }

  .tool-nav a {
    padding: 8px 10px;
    white-space: nowrap;
  }

  .invoice-page {
    padding: 26px 0 54px;
  }

  .page-hero {
    gap: 18px;
    margin-bottom: 24px;
  }

  .page-hero h1 {
    font-size: 36px;
    line-height: 1.04;
  }

  .page-hero p:not(.eyebrow) {
    margin-top: 12px;
    font-size: 15px;
    line-height: 1.65;
  }

  .hero-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .hero-stats span {
    padding: 10px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .template-choice {
    min-width: 82vw;
    border-radius: 20px;
  }

  .template-preview-slot {
    min-height: 190px;
  }

  .invoice-builder {
    padding: 10px;
    border-radius: 22px;
  }

  .form-panel {
    padding: 18px;
    border-radius: 18px;
  }

  .panel-heading h2 {
    font-size: 21px;
  }

  .panel-heading p {
    font-size: 14px;
  }

  .field-grid.two,
  .field-grid.three,
  .party-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .add-item-btn {
    width: 100%;
  }

  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .total-chip {
    width: max-content;
  }

  .paper-frame {
    min-height: calc(1123px * var(--preview-scale) + 24px);
    overflow: hidden;
    padding: 12px;
  }
}

@media (max-width: 480px) {
  :root {
    --preview-scale: 0.335;
  }

  .invoice-container {
    width: min(100% - 18px, 1440px);
  }

  .page-hero h1 {
    font-size: 32px;
  }

  .hero-stats {
    gap: 6px;
    padding: 7px;
  }

  .hero-stats strong {
    font-size: 17px;
  }

  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 0.72fr 1fr;
  }

  .ghost-action,
  .quiet-action,
  .print-action {
    width: 100%;
    padding: 0 8px;
  }

  .template-choice {
    min-width: 86vw;
  }

  .template-preview-slot {
    min-height: 172px;
  }

  .invoice-form input,
  .invoice-form textarea,
  .invoice-form select {
    font-size: 14px;
  }
}
