:root {
  color-scheme: light;
  --surface: rgba(255, 251, 245, 0.88);
  --sheet: #fffdf9;
  --ink: #1e1c1a;
  --muted: #6f665e;
  --line: #ddd1c3;
  --shadow: 0 24px 60px rgba(66, 43, 19, 0.12);
  --radius-lg: 28px;
  --accent: #c85b31;
  --accent-soft: #ffe8df;
  --accent-deep: #8a3a1d;
  --accent-ghost: rgba(200, 91, 49, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-top: 88px;
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255, 231, 214, 0.85), transparent 34%),
    radial-gradient(circle at bottom right, rgba(239, 219, 181, 0.55), transparent 30%),
    linear-gradient(135deg, #f6f0e8 0%, #efe6dc 100%);
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: auto auto 12% 6%;
  width: 320px;
  height: 320px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.42);
  filter: blur(28px);
  pointer-events: none;
  z-index: 0;
}

body::after {
  inset: 10% 8% auto auto;
  width: 280px;
  height: 280px;
  background: rgba(255, 244, 233, 0.9);
}

.site-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  background: rgba(8, 9, 13, 0.9);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(38, 42, 58, 0.78);
}

.site-logo {
  color: #fff;
  text-decoration: none;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 22px;
}

.site-nav a {
  color: #b7bfd2;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  transition: color 180ms ease;
}

.site-nav a:hover {
  color: #fff;
}

.site-nav-cta {
  padding: 10px 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, #7c3aed, #9d5cf6);
  color: #fff !important;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1560px;
  margin: 0 auto;
  padding: 36px 24px 48px;
}

.page-header {
  margin-bottom: 28px;
}

.eyebrow,
.section-eyebrow,
.sheet-label,
.preview-toolbar p {
  margin: 0 0 6px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-deep);
}

.page-header h1,
.section-title-row h2 {
  margin: 0;
}

.page-header h1 {
  font-size: clamp(2.4rem, 5vw, 4.4rem);
  line-height: 0.98;
  max-width: 680px;
}

.intro {
  max-width: 700px;
  margin: 14px 0 0;
  font-size: 1.02rem;
  line-height: 1.65;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 600px) minmax(420px, 1fr);
  gap: 24px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.62);
  box-shadow: var(--shadow);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
}

.controls {
  padding: 22px;
}

#invoice-form {
  display: grid;
  gap: 18px;
}

.section-card {
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(220, 208, 195, 0.8);
  border-radius: 24px;
  padding: 20px;
}

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

.section-title-row h2 {
  font-size: 1.15rem;
  line-height: 1.2;
}

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

.field {
  display: grid;
  gap: 8px;
}

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

.field span {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
}

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

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(255, 253, 249, 0.96);
  color: var(--ink);
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ghost);
}

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

input[type="file"] {
  padding: 10px 12px;
}

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

.theme-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  cursor: pointer;
  text-align: left;
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.theme-chip:hover,
.theme-chip.is-active {
  transform: translateY(-1px);
  border-color: var(--accent);
  box-shadow: 0 14px 24px rgba(54, 39, 25, 0.1);
}

.theme-swatch {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.72);
}

.theme-name {
  font-size: 0.88rem;
  font-weight: 700;
}

.line-items-head,
.line-item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 3.25rem 3.8rem 3.5rem minmax(5.8rem, 0.95fr) 42px;
  gap: 8px;
  align-items: center;
}

.line-items-head {
  margin-bottom: 10px;
  padding: 0 6px;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

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

.line-item-row {
  overflow: hidden;
  padding: 10px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(204, 189, 171, 0.92);
  border-radius: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.line-item-row > * {
  min-width: 0;
}

.line-item-row input {
  min-height: 48px;
  background: rgba(255, 253, 250, 0.98);
  border-color: rgba(188, 169, 149, 0.92);
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 700;
}

.line-item-row input::placeholder {
  color: #776b60;
  font-weight: 500;
}

.line-item-row input[type="number"] {
  appearance: textfield;
  padding-inline: 6px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.line-item-row input[data-line-field="qty"] {
  min-width: 0;
}

.line-item-row input[data-line-field="rate"] {
  min-width: 0;
}

.line-item-row input[data-line-field="tax"] {
  min-width: 0;
}

.line-item-row input[data-line-field="tax"] {
  background: #fff1e7;
  border-color: rgba(138, 58, 29, 0.34);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
  color: var(--accent-deep);
}

.line-item-row input[data-line-field="tax"]:focus {
  border-color: var(--accent);
}

.line-item-row input[type="number"]::-webkit-outer-spin-button,
.line-item-row input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.line-item-amount {
  min-height: 48px;
  min-width: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 14px;
  background: rgba(200, 91, 49, 0.18);
  border: 1px solid rgba(200, 91, 49, 0.2);
  border-radius: 14px;
  font-weight: 700;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  color: var(--accent-deep);
}

.line-item-row .icon-button {
  justify-self: end;
}

.totals-snapshot {
  display: grid;
  gap: 10px;
}

.snapshot-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(221, 210, 198, 0.82);
}

.snapshot-row span {
  color: var(--muted);
  font-size: 0.92rem;
}

.snapshot-row strong {
  font-size: 0.96rem;
}

.snapshot-grand-total {
  background: var(--accent-soft);
  border-color: transparent;
}

.icon-button,
.primary-button,
.secondary-button,
.ghost-button {
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  font-weight: 700;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    background 180ms ease,
    color 180ms ease;
}

.icon-button:hover,
.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.icon-button:disabled,
.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
  transform: none;
  box-shadow: none;
}

.icon-button {
  width: 42px;
  height: 42px;
  background: rgba(44, 31, 18, 0.08);
  color: var(--ink);
}

.primary-button,
.secondary-button,
.ghost-button {
  padding: 13px 18px;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 14px 28px rgba(114, 53, 27, 0.18);
}

.secondary-button {
  background: rgba(44, 31, 18, 0.08);
  color: var(--ink);
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.action-card {
  position: sticky;
  bottom: 16px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.template-actions {
  margin-top: 14px;
}

.template-hint,
.template-status {
  margin: 14px 0 0;
  font-size: 0.9rem;
  line-height: 1.55;
}

.template-hint {
  color: var(--muted);
}

.template-status {
  min-height: 1.5em;
  color: var(--muted);
}

.template-status.is-success {
  color: #2d7344;
}

.template-status.is-error {
  color: #9d3224;
}

.preview-pane {
  position: sticky;
  top: 104px;
  padding: 18px;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 0 8px;
}

.preview-toolbar p {
  margin-bottom: 0;
}

.preview-toolbar span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.invoice-sheet {
  overflow: hidden;
  background: var(--sheet);
  border-radius: 28px;
  border: 1px solid rgba(221, 210, 198, 0.92);
  min-height: 1120px;
  padding: 0 36px 38px;
  box-shadow: 0 34px 70px rgba(65, 42, 17, 0.12);
}

.sheet-accent {
  height: 14px;
  margin: 0 -36px 34px;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-deep) 100%);
}

.invoice-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 34px;
}

.brand-block {
  display: flex;
  align-items: start;
  gap: 18px;
  flex: 1 1 auto;
}

.logo-frame {
  width: 82px;
  height: 82px;
  border-radius: 22px;
  border: 1px solid rgba(213, 198, 180, 0.9);
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
}

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

.brand-copy {
  max-width: 440px;
}

.serif-title,
.invoice-meta-panel h3,
.bill-to-card h4 {
  font-family: "Source Serif 4", Georgia, serif;
}

.serif-title {
  margin: 0 0 12px;
  font-size: clamp(1.9rem, 4vw, 2.6rem);
  line-height: 1;
}

.multiline-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  white-space: pre-line;
}

.multiline-text.is-placeholder {
  color: #a09487;
}

.invoice-meta-panel {
  min-width: 220px;
  padding: 22px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 249, 243, 0.98) 0%, rgba(250, 243, 236, 0.95) 100%);
  border: 1px solid rgba(219, 207, 194, 0.92);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 0.82rem;
  font-weight: 700;
}

.status-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.status-pill.status-paid {
  background: #e5f4e9;
  color: #2d7344;
}

.status-pill.status-overdue {
  background: #fde3de;
  color: #9d3224;
}

.status-pill.status-sent {
  background: #e6eef9;
  color: #275a9b;
}

.status-pill.status-due {
  background: #fff1d7;
  color: #946b12;
}

.invoice-meta-panel h3 {
  margin: 0 0 18px;
  font-size: 1.8rem;
}

.meta-list {
  margin: 0;
  display: grid;
  gap: 12px;
}

.meta-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.meta-list dt,
.meta-list dd {
  margin: 0;
}

.meta-list dt {
  color: var(--muted);
}

.meta-list dd {
  font-weight: 700;
}

.bill-to-card,
.table-card,
.note-card,
.totals-card {
  border-radius: 24px;
  border: 1px solid rgba(219, 207, 194, 0.92);
  background: rgba(255, 252, 246, 0.98);
}

.bill-to-card {
  padding: 24px;
  margin-bottom: 24px;
}

.bill-to-card h4 {
  margin: 0 0 10px;
  font-size: 1.5rem;
}

.table-card {
  padding: 10px 20px 6px;
  margin-bottom: 24px;
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.preview-table th,
.preview-table td {
  padding: 14px 6px;
  border-bottom: 1px solid rgba(221, 210, 198, 0.72);
  text-align: left;
  vertical-align: top;
}

.preview-table th {
  font-size: 0.76rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.preview-table th:first-child,
.preview-table td:first-child {
  width: 52%;
}

.preview-line-description {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.preview-table td:nth-child(2),
.preview-table th:nth-child(2) {
  width: 8%;
}

.preview-table td:nth-child(3),
.preview-table th:nth-child(3) {
  width: 14%;
}

.preview-table td:nth-child(4),
.preview-table th:nth-child(4) {
  width: 8%;
}

.preview-table td:nth-child(5),
.preview-table th:nth-child(5) {
  width: 18%;
}

.preview-table td:nth-child(2),
.preview-table td:nth-child(3),
.preview-table td:nth-child(4),
.preview-table td:nth-child(5),
.preview-table th:nth-child(2),
.preview-table th:nth-child(3),
.preview-table th:nth-child(4),
.preview-table th:nth-child(5) {
  text-align: right;
  white-space: nowrap;
}

.preview-table tbody tr:last-child td {
  border-bottom: 0;
}

.line-items-card {
  container-type: inline-size;
}

@container (max-width: 34rem) {
  .line-items-card .line-items-head {
    display: none;
  }

  .line-items-card .line-item-row {
    grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(5.8rem, 1.15fr) 42px;
  }

  .line-items-card .line-item-description {
    grid-column: 1 / -1;
  }
}

.summary-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.8fr);
  gap: 24px;
}

.note-stack {
  display: grid;
  gap: 18px;
}

.note-card {
  padding: 22px;
}

.totals-card {
  padding: 22px;
  align-self: start;
}

.total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(221, 210, 198, 0.72);
}

.total-row:last-child {
  border-bottom: 0;
}

.grand-total {
  margin-top: 8px;
  padding-top: 16px;
  font-size: 1.12rem;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .preview-pane {
    position: static;
  }

  .invoice-sheet {
    min-height: auto;
  }
}

@media (max-width: 760px) {
  body {
    padding-top: 76px;
  }

  .site-topbar {
    padding: 14px 16px;
  }

  .site-nav {
    gap: 14px;
  }

  .site-nav a {
    font-size: 0.84rem;
  }

  .app-shell {
    padding: 20px 14px 32px;
  }

  .controls,
  .preview-pane {
    padding: 14px;
  }

  .section-card,
  .invoice-meta-panel,
  .bill-to-card,
  .table-card,
  .note-card,
  .totals-card {
    padding-left: 16px;
    padding-right: 16px;
  }

  .field-grid,
  .summary-grid,
  .theme-grid {
    grid-template-columns: 1fr;
  }

  .line-items-head {
    display: none;
  }

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

  .line-item-row .line-item-description {
    grid-column: 1 / -1;
  }

  .line-item-row .line-item-amount {
    grid-column: 1 / 2;
    justify-content: flex-start;
  }

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

  .invoice-meta-panel {
    width: 100%;
  }

  .invoice-sheet {
    padding: 0 18px 20px;
  }

  .sheet-accent {
    margin-left: -18px;
    margin-right: -18px;
  }
}

@media print {
  @page {
    size: Letter portrait;
    margin: 0.4in;
  }

  html,
  body {
    width: auto;
    min-height: auto;
    margin: 0;
    padding-top: 0;
    background: #fff;
    font-size: 14px;
    line-height: 1.4;
    overflow: visible;
  }

  body::before,
  body::after,
  .site-topbar,
  .page-header,
  .controls,
  .preview-toolbar {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .preview-pane {
    max-width: none;
    margin: 0;
    padding: 0;
    display: block;
    box-shadow: none;
    border: 0;
    background: transparent;
  }

  .invoice-sheet {
    width: 100%;
    max-width: 7.7in;
    min-height: auto;
    margin: 0 auto;
    box-shadow: none;
    border: 0;
    border-radius: 0;
    padding: 0 0.3in 0.28in;
    break-inside: auto;
  }

  .sheet-accent {
    height: 10px;
    margin: 0 -0.3in 0.24in;
  }

  .invoice-header {
    gap: 0.2in;
    margin-bottom: 0.2in;
  }

  .brand-block {
    gap: 0.16in;
  }

  .logo-frame {
    width: 0.7in;
    height: 0.7in;
    border-radius: 0.14in;
  }

  .serif-title {
    margin-bottom: 0.08in;
    font-size: 1.6rem;
  }

  .multiline-text {
    line-height: 1.45;
  }

  .invoice-meta-panel {
    min-width: 2.1in;
    padding: 0.16in;
    border-radius: 0.18in;
  }

  .invoice-meta-panel h3 {
    margin-bottom: 0.12in;
    font-size: 1.45rem;
  }

  .status-pill {
    margin-bottom: 0.12in;
    padding: 0.06in 0.1in;
    font-size: 0.72rem;
  }

  .meta-list {
    gap: 0.08in;
  }

  .invoice-header,
  .bill-to-card,
  .table-card,
  .note-card,
  .totals-card,
  .preview-table tr {
    break-inside: avoid;
  }

  .summary-grid,
  .note-stack {
    display: block;
    gap: 0;
  }

  .bill-to-card,
  .note-card,
  .totals-card {
    padding: 0.16in;
    border-radius: 0.18in;
  }

  .bill-to-card {
    margin-bottom: 0.18in;
  }

  .bill-to-card h4 {
    margin-bottom: 0.06in;
    font-size: 1.2rem;
  }

  .table-card {
    margin-bottom: 0.18in;
    padding: 0.05in 0.14in 0.04in;
    border-radius: 0.18in;
  }

  .note-card + .note-card,
  .totals-card {
    margin-top: 0.12in;
  }

  .preview-table {
    table-layout: fixed;
  }

  .preview-table th,
  .preview-table td {
    padding: 0.08in 0.03in;
    font-size: 0.92rem;
  }

  .preview-table th {
    font-size: 0.62rem;
  }

  .preview-table th:first-child,
  .preview-table td:first-child,
  .multiline-text {
    overflow-wrap: anywhere;
  }

  .total-row {
    padding: 0.06in 0;
  }

  .grand-total {
    margin-top: 0.04in;
    padding-top: 0.08in;
    font-size: 1rem;
  }
}
