:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #667085;
  --line: #e5e7eb;
  --soft: #f1f5f9;
  --blue: #4f46e5;
  --blue-dark: #3730a3;
  --green: #10b981;
  --shadow: 0 24px 80px rgba(15, 23, 42, 0.12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 5%, rgba(79, 70, 229, 0.12), transparent 28rem),
    radial-gradient(circle at 90% 10%, rgba(16, 185, 129, 0.12), transparent 24rem),
    var(--bg);
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 5vw, 4rem);
  background: rgba(255, 255, 255, 0.78);
  border-bottom: 1px solid rgba(229, 231, 235, 0.8);
  backdrop-filter: blur(18px);
}

.brand, .app-header nav, .pill-row, .hero-actions, .preview-toolbar, .app-footer, .app-footer nav {
  display: flex;
  align-items: center;
}

.brand { gap: 0.65rem; font-weight: 800; }
.brand span {
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 0.7rem;
  color: white;
  background: linear-gradient(135deg, var(--blue), #06b6d4);
  box-shadow: 0 12px 24px rgba(79, 70, 229, 0.25);
}

.app-header nav { gap: 1rem; color: var(--muted); font-size: 0.9rem; font-weight: 700; }
.nav-cta { color: white; background: var(--blue); padding: 0.65rem 0.95rem; border-radius: 999px; }

.hero {
  min-height: 78vh;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  align-items: center;
  gap: clamp(2rem, 6vw, 5rem);
  padding: clamp(4rem, 8vw, 7rem) clamp(1rem, 5vw, 4rem) 3rem;
}

.hero h1 {
  margin: 1.2rem 0 1rem;
  max-width: 760px;
  font-size: clamp(2.6rem, 8vw, 5.7rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.hero p { max-width: 620px; margin: 0; color: var(--muted); font-size: clamp(1.05rem, 2vw, 1.35rem); line-height: 1.65; }
.pill-row { flex-wrap: wrap; gap: 0.7rem; }
.pill-row span, .eyebrow {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.78);
  color: var(--blue);
  border-radius: 999px;
  padding: 0.48rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 800;
}

.hero-actions { flex-wrap: wrap; gap: 0.85rem; margin-top: 1.8rem; }
.btn {
  border: 0;
  border-radius: 0.9rem;
  padding: 0.9rem 1.05rem;
  cursor: pointer;
  text-align: center;
  font-weight: 800;
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}
.btn:hover { transform: translateY(-2px); }
.primary { color: white; background: linear-gradient(135deg, var(--blue), #2563eb); box-shadow: 0 16px 34px rgba(79, 70, 229, 0.24); }
.secondary, .ghost { color: var(--ink); background: white; border: 1px solid var(--line); }
.ghost { box-shadow: none; }

.hero-card {
  min-height: 420px;
  border-radius: 2rem;
  padding: 1.2rem;
  background: linear-gradient(145deg, rgba(255,255,255,0.9), rgba(255,255,255,0.55));
  box-shadow: var(--shadow);
  transform: perspective(1000px) rotateY(-8deg) rotateX(4deg);
}

.mini-invoice {
  height: 100%;
  border-radius: 1.4rem;
  padding: 2rem;
  background: white;
  border: 1px solid var(--line);
}
.mini-invoice div { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3rem; }
.mini-invoice span { width: 4.5rem; height: 4.5rem; border-radius: 1.2rem; background: linear-gradient(135deg, var(--blue), #06b6d4); }
.mini-invoice i { display: block; height: 0.8rem; border-radius: 999px; background: var(--soft); margin: 1rem 0; }
.mini-invoice i:nth-child(3) { width: 70%; }
.mini-invoice b { display: block; margin-top: 5rem; color: var(--blue); font-size: 2.4rem; }

.builder-shell {
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(360px, 1.08fr);
  gap: 1.25rem;
  padding: 1rem clamp(1rem, 5vw, 4rem) 4rem;
  align-items: start;
}

.builder-panel, .preview-panel, .price-card {
  border: 1px solid var(--line);
  border-radius: 1.35rem;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.08);
}
.builder-panel { padding: 1.2rem; }
.panel-heading h2, .section-copy h2 { margin: 0.8rem 0 1.2rem; font-size: clamp(1.7rem, 3vw, 2.5rem); letter-spacing: 0; }

fieldset {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 0;
  padding: 1.2rem 0;
}
legend { padding-right: 0.8rem; font-weight: 800; }
label { display: grid; gap: 0.45rem; color: #344054; font-size: 0.85rem; font-weight: 750; margin-bottom: 0.85rem; }
input, textarea, select {
  width: 100%;
  border: 1px solid #d0d5dd;
  border-radius: 0.75rem;
  background: white;
  color: var(--ink);
  padding: 0.78rem 0.85rem;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12); }
textarea { resize: vertical; }
.two-col, .three-col, .four-col { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.85rem; }
.three-col { grid-template-columns: repeat(3, 1fr); }
.four-col { grid-template-columns: repeat(4, 1fr); }
.upload-box input { padding: 0.65rem; background: var(--soft); }
.cloud-save {
  border-radius: 1rem;
  border: 1px solid #dbeafe;
  padding: 1rem;
  background: #f8fbff;
}
.cloud-save p { margin: 0 0 0.9rem; color: var(--muted); font-size: 0.88rem; line-height: 1.55; }
.cloud-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }

.line-item {
  display: grid;
  grid-template-columns: 1.2fr 0.45fr 0.7fr auto;
  gap: 0.6rem;
  align-items: end;
}
.remove-item {
  width: 2.65rem;
  height: 2.65rem;
  border-radius: 0.75rem;
  border: 1px solid #fecaca;
  color: #dc2626;
  background: #fff1f2;
  cursor: pointer;
}
.text-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
  cursor: pointer;
  padding: 0.25rem 0;
}

.signature-block {
  display: grid;
  gap: 0.7rem;
  padding: 0.9rem;
  border-radius: 1rem;
  background: var(--soft);
}
.signature-block div { display: flex; justify-content: space-between; gap: 1rem; color: var(--muted); font-size: 0.84rem; }
canvas { width: 100%; height: 120px; background: white; border: 1px dashed #cbd5e1; border-radius: 0.85rem; touch-action: none; }

.preview-panel { position: sticky; top: 5.25rem; padding: 1rem; }
.preview-toolbar { justify-content: space-between; align-items: end; gap: 0.8rem; margin-bottom: 1rem; flex-wrap: wrap; }
.toolbar-field { min-width: 145px; margin: 0; color: var(--muted); font-size: 0.76rem; font-weight: 850; }
.toolbar-field select { margin-top: 0.35rem; min-width: 145px; max-width: 180px; }
#planBadge { font-size: 0.75rem; font-weight: 850; color: var(--blue); background: #eef2ff; border-radius: 999px; padding: 0.5rem 0.7rem; }

.invoice-preview {
  position: relative;
  min-height: 760px;
  padding: clamp(1rem, 3vw, 2rem);
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: white;
  overflow: hidden;
}
.pdf-export-wrap {
  position: absolute;
  left: 0;
  top: 0;
  z-index: -1;
  background: #ffffff;
  opacity: 1;
  pointer-events: none;
  overflow: hidden;
  box-sizing: border-box;
}
.invoice-preview.pdf-export {
  min-height: auto;
  border-radius: 0;
  box-shadow: none;
  overflow: visible;
  transform: none;
  font-family: Inter, Arial, sans-serif;
  box-sizing: border-box;
  max-width: none;
}
.invoice-preview.pdf-export,
.invoice-preview.pdf-export * {
  color-adjust: exact;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.invoice-preview.pdf-export .invoice-title { font-size: 34px; }
.invoice-preview.pdf-export .watermark {
  left: 50%;
  top: 72%;
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%) rotate(-18deg);
  color: rgba(79, 70, 229, 0.08);
  font-size: 46px;
  line-height: 1;
  white-space: nowrap;
}
.invoice-preview.pdf-export .invoice-top,
.invoice-preview.pdf-export .invoice-parties,
.invoice-preview.pdf-export .invoice-table,
.invoice-preview.pdf-export .invoice-totals,
.invoice-preview.pdf-export .invoice-notes {
  position: relative;
  z-index: 1;
}
.invoice-preview.pdf-export .invoice-parties { gap: 24px; }
.invoice-preview.pdf-export .invoice-parties p,
.invoice-preview.pdf-export .invoice-notes,
.invoice-preview.pdf-export .invoice-table td {
  overflow-wrap: anywhere;
  word-break: normal;
}
.invoice-preview.pdf-export .invoice-table {
  table-layout: fixed;
  width: 100%;
}
.invoice-preview.pdf-export .item-col { width: 46%; }
.invoice-preview.pdf-export .qty-col { width: 11%; }
.invoice-preview.pdf-export .price-col,
.invoice-preview.pdf-export .total-col { width: 21.5%; }
.invoice-preview.pdf-export .item-name {
  white-space: normal;
  overflow: visible;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.invoice-preview.pdf-export .invoice-table th,
.invoice-preview.pdf-export .invoice-table td { padding: 10px 8px; }
.invoice-top { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; border-bottom: 1px solid var(--line); padding-bottom: 1.4rem; }
.invoice-logo { width: 76px; height: 76px; object-fit: contain; border-radius: 1rem; background: var(--soft); }
.invoice-title { margin: 0; font-size: 2.2rem; letter-spacing: 0; }
.invoice-meta { text-align: right; color: var(--muted); line-height: 1.7; }
.invoice-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin: 1.5rem 0; }
.invoice-parties h4, .invoice-table th { color: var(--muted); text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.08em; }
.invoice-parties p { white-space: pre-line; color: #344054; line-height: 1.55; }
.invoice-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.invoice-table .item-col { width: 46%; }
.invoice-table .qty-col { width: 11%; }
.invoice-table .price-col,
.invoice-table .total-col { width: 21.5%; }
.invoice-table th, .invoice-table td { padding: 0.85rem 0.55rem; border-bottom: 1px solid var(--line); text-align: left; }
.invoice-table .item-name { white-space: normal; overflow-wrap: anywhere; word-break: break-word; }
.invoice-table td:nth-child(2), .invoice-table td:nth-child(3), .invoice-table td:nth-child(4),
.invoice-table th:nth-child(2), .invoice-table th:nth-child(3), .invoice-table th:nth-child(4) { text-align: right; }
.invoice-totals { width: min(100%, 320px); margin-left: auto; margin-top: 1.2rem; display: grid; gap: 0.65rem; }
.invoice-totals div { display: flex; justify-content: space-between; }
.invoice-totals .grand { border-top: 1px solid var(--line); padding-top: 0.7rem; font-size: 1.35rem; font-weight: 850; color: var(--blue); }
.invoice-notes { margin-top: 1.5rem; color: #475467; line-height: 1.6; white-space: pre-line; }
.signature-image { max-width: 170px; max-height: 80px; margin-top: 1.4rem; object-fit: contain; }
.watermark {
  position: absolute;
  left: 50%;
  top: 74%;
  right: auto;
  bottom: auto;
  transform: translate(-50%, -50%) rotate(-18deg);
  color: rgba(79, 70, 229, 0.09);
  font-size: clamp(2rem, 8vw, 4.6rem);
  line-height: 1;
  font-weight: 900;
  white-space: nowrap;
  pointer-events: none;
}

.template-stripe { border-top: 8px solid var(--blue); }
.template-notion { font-family: Georgia, "Times New Roman", serif; }
.template-ledger { background: linear-gradient(#fff 31px, #f1f5f9 32px); background-size: 100% 32px; }
.template-studio .invoice-title, .template-studio .grand { color: #db2777; }
.template-executive { color: #0f172a; border-color: #111827; }
.template-executive .invoice-title { color: #111827; }

.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; margin-top: 1rem; }
.action-grid .primary { grid-column: 1 / -1; }
.action-status { min-height: 1.35rem; margin: 0.8rem 0 0; color: var(--muted); font-size: 0.85rem; line-height: 1.5; }
.action-status.error { color: #dc2626; }
.action-status.success { color: #047857; }

.templates, .pricing {
  padding: 4rem clamp(1rem, 5vw, 4rem);
}
.section-copy { max-width: 680px; }
.section-copy p { color: var(--muted); line-height: 1.7; }
.template-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.pricing { display: grid; grid-template-columns: repeat(2, minmax(0, 420px)); justify-content: center; gap: 1rem; }
.template-grid button {
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: white;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.07);
  cursor: pointer;
  font-weight: 850;
}
.template-grid button.active { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12); }
.price-card { padding: 1.2rem; }
.price-card h3 { margin: 0.8rem 0; font-size: 2rem; letter-spacing: 0; }
.price-card p { color: var(--muted); line-height: 1.65; }
.price-card.featured { border-color: rgba(79, 70, 229, 0.35); box-shadow: var(--shadow); }

.app-footer {
  justify-content: space-between;
  gap: 1rem;
  padding: 1.5rem clamp(1rem, 5vw, 4rem);
  color: var(--muted);
  border-top: 1px solid var(--line);
}
.app-footer span { font-weight: 850; color: var(--ink); }
.app-footer nav { gap: 1rem; flex-wrap: wrap; }

@media (max-width: 980px) {
  .hero, .builder-shell, .pricing { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
}

@media (max-width: 680px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .app-header nav { width: 100%; overflow-x: auto; padding-bottom: 0.2rem; }
  .hero { min-height: auto; padding-top: 2rem; }
  .hero-card { display: none; }
  .two-col, .three-col, .four-col, .line-item, .invoice-parties, .template-grid, .action-grid { grid-template-columns: 1fr; }
  .cloud-actions { grid-template-columns: 1fr; }
  .invoice-top { flex-direction: column; }
  .invoice-meta { text-align: left; }
  .invoice-preview { min-height: 680px; }
  .app-footer { align-items: flex-start; flex-direction: column; }
}

@media print {
  body { background: white; }
  .app-header, .hero, .builder-panel, .preview-toolbar, .action-grid, .templates, .pricing, .app-footer { display: none !important; }
  .builder-shell { display: block; padding: 0; }
  .preview-panel { border: 0; box-shadow: none; padding: 0; }
  .invoice-preview { border: 0; border-radius: 0; min-height: auto; }
}
