:root {
  --paper: #f3f6f9;
  --ink: #15202b;
  --muted: #5a6b7a;
  --line: rgba(21, 32, 43, 0.12);
  --grid: rgba(14, 116, 144, 0.07);
  --accent: #0e7490;
  --accent-hot: #e85d04;
  --accent-ink: #fffaf5;
  --sheet: #ffffff;
  --sheet-edge: #d7e0e8;
  --warn: #c2410c;
  --font: "Manrope", system-ui, sans-serif;
  --display: "Archivo Black", "Manrope", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
}
.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    radial-gradient(ellipse 70% 45% at 85% 0%, rgba(14, 116, 144, 0.16), transparent 55%),
    radial-gradient(ellipse 45% 35% at 5% 90%, rgba(232, 93, 4, 0.1), transparent 50%);
  background-size: 28px 28px, 28px 28px, auto, auto;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  background: rgba(243, 246, 249, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-family: var(--display);
  font-weight: 400;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.03em;
  font-size: 1.05rem;
}
.top nav { display: flex; gap: 0.75rem; align-items: center; }
.top nav a:not(.btn) { color: var(--muted); text-decoration: none; font-size: 0.95rem; font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  text-decoration: none;
  font: inherit;
  font-weight: 700;
  padding: 0.65rem 1.1rem;
  border-radius: 2px;
  transition: transform 0.15s ease, background 0.15s ease;
}
.btn.buy { background: var(--accent-hot); color: var(--accent-ink); }
.btn.buy:hover { transform: translateY(-1px); }
.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* Landing */
.hero {
  min-height: calc(100vh - 4rem);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem 1.5rem 4rem;
  max-width: 42rem;
  position: relative;
}
.hero::before {
  content: "";
  position: absolute;
  right: -8%;
  top: 18%;
  width: min(42vw, 320px);
  height: min(55vh, 420px);
  border: 1.5px solid rgba(14, 116, 144, 0.35);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.92), rgba(255,255,255,0.75)),
    repeating-linear-gradient(0deg, transparent, transparent 23px, rgba(14,116,144,0.08) 24px);
  box-shadow: 12px 16px 0 rgba(14, 116, 144, 0.08);
  transform: rotate(3deg);
  pointer-events: none;
  z-index: -1;
}
.hero::after {
  content: "INV-0042";
  position: absolute;
  right: 2%;
  top: 22%;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  color: var(--accent);
  transform: rotate(3deg);
  opacity: 0.7;
  pointer-events: none;
}
.brand-hero {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(2.6rem, 9vw, 4.4rem);
  letter-spacing: -0.04em;
  margin: 0 0 1rem;
  line-height: 0.95;
  color: var(--ink);
  animation: rise 0.7s ease both;
}
.hero h1 {
  font-size: clamp(1.2rem, 2.8vw, 1.55rem);
  font-weight: 700;
  margin: 0 0 0.75rem;
  max-width: 24ch;
  letter-spacing: -0.02em;
  animation: rise 0.7s ease 0.08s both;
}
.lede {
  color: var(--muted);
  margin: 0 0 1.75rem;
  max-width: 34ch;
  font-weight: 500;
  animation: rise 0.7s ease 0.16s both;
}
.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  animation: rise 0.7s ease 0.24s both;
}

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

.strip {
  padding: 2.5rem 1.5rem 3rem;
  border-top: 1px solid var(--line);
  max-width: 42rem;
}
.strip h2 {
  font-family: var(--display);
  font-weight: 400;
  margin: 0 0 1rem;
  letter-spacing: -0.02em;
}
.strip ul { margin: 0; padding-left: 1.1rem; color: var(--muted); font-weight: 500; }
.strip li { margin-bottom: 0.45rem; }

.foot {
  padding: 1.5rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}
.foot a { color: var(--accent); font-weight: 700; }

/* App */
.app-body .workspace {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 1.25rem;
  align-items: start;
}
.status {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
  font-family: var(--mono);
  letter-spacing: 0.02em;
}
.status.unlocked { color: var(--accent); }

.editor, .preview-col {
  min-width: 0;
}
.editor {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.15rem 1.2rem 1.35rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
}
.editor h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  margin: 0;
}
.section-label {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0.35rem 0 0;
}
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}
.field-grid .span-2 { grid-column: 1 / -1; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}
input, textarea, select {
  font: inherit;
  color: var(--ink);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 0.55rem 0.65rem;
  font-weight: 500;
}
input:focus, textarea:focus {
  outline: 2px solid rgba(14, 116, 144, 0.35);
  border-color: var(--accent);
}

.line-items { display: flex; flex-direction: column; gap: 0.5rem; }
.line-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) 64px 80px 28px;
  gap: 0.4rem;
  align-items: end;
}
.line-row .remove-line {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.4rem 0;
}
.line-row .remove-line:hover { color: var(--warn); }
.add-row {
  align-self: flex-start;
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  border-radius: 2px;
}
.add-row:hover { border-color: var(--accent); background: rgba(14, 116, 144, 0.06); }

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 0.25rem;
}

.preview-col {
  position: sticky;
  top: 4.5rem;
}
.preview-shell {
  border: 1px solid var(--sheet-edge);
  background: var(--sheet);
  box-shadow: 8px 10px 0 rgba(21, 32, 43, 0.06);
}
.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(243, 246, 249, 0.7);
}
.invoice {
  padding: 1.5rem 1.4rem 1.75rem;
  position: relative;
  min-height: 420px;
}
.invoice.watermark::after {
  content: "DEMO";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--display);
  font-size: clamp(3rem, 12vw, 5rem);
  letter-spacing: 0.08em;
  color: rgba(21, 32, 43, 0.06);
  pointer-events: none;
  transform: rotate(-18deg);
}
.inv-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--ink);
}
.inv-brand {
  font-family: var(--display);
  font-size: 1.35rem;
  letter-spacing: -0.03em;
  margin: 0 0 0.35rem;
  line-height: 1.1;
}
.inv-meta {
  text-align: right;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.6;
}
.inv-meta strong {
  display: block;
  color: var(--ink);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}
.inv-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1.35rem;
}
.inv-party h3 {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.35rem;
  font-weight: 500;
}
.inv-party p {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: pre-line;
  line-height: 1.45;
}
.inv-party .empty { color: var(--muted); font-weight: 500; }

.inv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin-bottom: 1.25rem;
}
.inv-table th {
  text-align: left;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid var(--line);
}
.inv-table th.num, .inv-table td.num { text-align: right; }
.inv-table td {
  padding: 0.55rem 0.35rem;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  vertical-align: top;
}
.inv-table .empty-row td { color: var(--muted); font-weight: 500; }

.inv-totals {
  margin-left: auto;
  width: min(220px, 100%);
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
}
.inv-totals div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-weight: 600;
  color: var(--muted);
}
.inv-totals .grand {
  margin-top: 0.25rem;
  padding-top: 0.45rem;
  border-top: 2px solid var(--ink);
  color: var(--ink);
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.inv-notes {
  margin-top: 1.5rem;
  padding-top: 0.85rem;
  border-top: 1px dashed var(--line);
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
  white-space: pre-line;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--sheet);
  color: var(--ink);
  padding: 1.25rem;
  max-width: 22rem;
  width: calc(100% - 2rem);
}
dialog::backdrop { background: rgba(21, 32, 43, 0.45); }
dialog h2 {
  font-family: var(--display);
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  font-weight: 400;
}
dialog p { color: var(--muted); font-size: 0.9rem; font-weight: 500; }
.err { color: var(--warn); font-size: 0.85rem; font-weight: 600; }

@media (max-width: 900px) {
  .app-body .workspace {
    grid-template-columns: 1fr;
  }
  .preview-col { position: static; }
  .hero::before, .hero::after { display: none; }
}

@media (max-width: 560px) {
  .top { flex-wrap: wrap; gap: 0.75rem; }
  .field-grid { grid-template-columns: 1fr; }
  .field-grid .span-2 { grid-column: auto; }
  .line-row {
    grid-template-columns: 1fr 1fr;
  }
  .line-row label:first-child { grid-column: 1 / -1; }
  .inv-parties { grid-template-columns: 1fr; }
  .inv-top { flex-direction: column; }
  .inv-meta { text-align: left; }
}

@media print {
  .atmosphere, .top, .editor, .preview-toolbar, dialog { display: none !important; }
  .app-body .workspace {
    display: block;
    max-width: none;
    padding: 0;
  }
  .preview-col { position: static; }
  .preview-shell {
    border: none;
    box-shadow: none;
  }
  .invoice {
    padding: 0;
    min-height: 0;
  }
  .invoice.watermark::after { display: none; }
  body { background: white; }
}
