/* ============ InvoiceForge app — v2 (matches the marketing site) ============ */
:root {
  --bg: #f4f3f0;
  --card: #ffffff;
  --field: #f5f4f1;
  --ink: #111113;
  --ink-60: rgba(17, 17, 19, .62);
  --ink-40: rgba(17, 17, 19, .45);
  --line: rgba(17, 17, 19, .1);
  --plum: #2b2644;
  --lav: #e4dffb;
  --lav-2: #cfc6f5;
  --violet: #6b5ce7;
  --danger: #d6455d;
  --ok: #1f8f5f;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  /* invoice paper */
  --paper-ink: #1b1f2a;
  --ink-muted: #6b7280;
  --ink-line: #e5e7eb;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); }
body {
  font-family: var(--sans);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
::selection { background: rgba(107, 92, 231, .3); }
:focus-visible { outline: 2px solid var(--violet); outline-offset: 2px; }

.app { display: flex; gap: 12px; padding: 12px; min-height: 100vh; }
.hidden { display: none !important; }
.pre-line { white-space: pre-line; }

/* ---------- Editor panel ---------- */
.editor {
  width: 440px;
  min-width: 440px;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 28px;
  height: calc(100vh - 24px);
  position: sticky;
  top: 12px;
  overflow: hidden;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-width: 0; }
.brand-mark { width: 38px; height: 38px; flex: none; display: block; }
.brand h1 { font-size: 16.5px; font-weight: 600; letter-spacing: -.03em; line-height: 1.15; }
.brand p { display: none; }

.editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  scrollbar-width: thin;
  scrollbar-color: rgba(17, 17, 19, .18) transparent;
}

.panel h2 {
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .18em;
  color: var(--ink-40);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.panel h2::before { content: ""; width: 20px; height: 1px; background: var(--ink-40); }

input, textarea, select {
  width: 100%;
  background: var(--field);
  border: 1px solid transparent;
  color: var(--ink);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 8px;
  transition: border-color .2s, background .2s, box-shadow .2s;
}
input:hover, textarea:hover, select:hover { border-color: var(--line); }
input:focus, textarea:focus, select:focus {
  outline: none;
  background: #fff;
  border-color: var(--violet);
  box-shadow: 0 0 0 4px rgba(107, 92, 231, .14);
}
input::placeholder, textarea::placeholder { color: rgba(17, 17, 19, .34); }
textarea { resize: vertical; line-height: 1.45; }
select { appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%23111113' stroke-opacity='.55' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'><path d='M1 1.5l5 5 5-5'/></svg>");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
input[type="number"] { font-variant-numeric: tabular-nums; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-60);
  margin-bottom: 6px;
}
.field input, .field select { margin-bottom: 0; }

/* logo */
.logo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.logo-drop {
  width: 76px; height: 76px;
  border: 1.5px dashed rgba(17, 17, 19, .22);
  border-radius: 18px;
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--ink-60);
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  background-color: var(--field);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transition: border-color .2s, color .2s, background-color .2s;
}
.logo-drop:hover { border-color: var(--violet); color: var(--violet); background-color: #fff; }
.logo-drop.has-logo span { display: none; }

/* line items */
.item-row {
  display: grid;
  grid-template-columns: 1fr 58px 84px 30px;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}
.item-row input { margin-bottom: 0; padding-left: 12px; padding-right: 12px; }
.item-remove {
  background: none;
  border: none;
  color: var(--ink-40);
  cursor: pointer;
  font-size: 13px;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  transition: background .2s, color .2s;
}
.item-remove:hover { color: var(--danger); background: rgba(214, 69, 93, .1); }

/* buttons */
.btn {
  border: none;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  letter-spacing: -.01em;
  padding: 12px 20px;
  transition: background .25s, color .2s, border-color .2s, transform .2s var(--ease);
}
.btn:active { transform: scale(.97); }
a.btn { display: inline-block; text-align: center; text-decoration: none; }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 12.5px; }
.btn-primary { background: var(--ink); color: #fff; padding: 16px 22px; font-size: 15px; }
.btn-primary:hover { background: #2a2a30; }
.btn-ghost {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink);
}
.btn-ghost:hover { background: rgba(17, 17, 19, .05); }
#btn-add-item { border-radius: 14px; box-shadow: inset 0 0 0 1.5px rgba(17, 17, 19, .14); color: var(--ink-60); }
#btn-add-item:hover { color: var(--ink); background: var(--field); }

/* header plan UI */
.header-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.pill {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--ink-60);
  background: var(--field);
  border-radius: 999px;
  padding: 6px 12px;
  white-space: nowrap;
}
.pill-pro { color: var(--lav-2); background: var(--plum); letter-spacing: .1em; }
.btn-gold { background: var(--lav-2); color: var(--plum); font-weight: 600; }
.btn-gold:hover { background: #bfb4f0; }

/* upgrade modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 24, 56, .5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 20px;
}
.modal {
  position: relative;
  background: var(--card);
  border-radius: 32px;
  padding: 36px 32px 28px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 30px 80px rgba(30, 24, 56, .35);
}
.modal h2 { font-size: 28px; font-weight: 500; letter-spacing: -.04em; margin-bottom: 10px; }
.modal-sub { font-size: 14.5px; color: var(--ink-60); margin-bottom: 20px; line-height: 1.5; }
.modal-close {
  position: absolute;
  top: 18px; right: 18px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: none;
  border: none;
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink-60);
  font-size: 13px;
  cursor: pointer;
  transition: background .2s, color .2s;
}
.modal-close:hover { color: var(--ink); background: var(--field); }
.pro-perks { list-style: none; margin-bottom: 26px; display: flex; flex-direction: column; gap: 12px; }
.pro-perks li { font-size: 14.5px; padding-left: 28px; position: relative; color: var(--ink-60); }
.pro-perks li::before {
  content: "";
  position: absolute;
  left: 2px; top: 5px;
  width: 14px; height: 8px;
  border-left: 2.2px solid var(--violet);
  border-bottom: 2.2px solid var(--violet);
  transform: rotate(-45deg);
}
.license-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 14px;
  color: var(--ink-40);
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .14em;
}
.license-divider::before, .license-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.license-row { display: flex; gap: 8px; }
.license-row input { margin-bottom: 0; font-family: Consolas, "SF Mono", monospace; letter-spacing: 1px; }
.license-msg { font-size: 13px; margin-top: 10px; min-height: 18px; }
.license-msg.ok { color: var(--ok); }
.license-msg.err { color: var(--danger); }

.editor-footer { padding: 18px 24px 20px; border-top: 1px solid var(--line); }
.foot-meta { margin-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.autosave-note { text-align: right; font-size: 12px; color: var(--ink-40); margin-left: auto; }

/* ---------- Preview ---------- */
.preview-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 56px 40px;
  border-radius: 32px;
  background:
    radial-gradient(700px 420px at 85% 0%, rgba(255, 255, 255, .55), transparent 70%),
    linear-gradient(160deg, #ebe7fc 0%, #cfc6f5 100%);
}

.paper {
  background: #fff;
  color: var(--paper-ink);
  width: 100%;
  max-width: 760px;
  min-height: 1000px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(43, 38, 68, .06), 0 28px 70px rgba(43, 38, 68, .24);
  padding: 56px 60px;
  display: flex;
  flex-direction: column;
  height: fit-content;
}

.inv-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 44px; }
.inv-identity { display: flex; flex-direction: column; gap: 14px; }
.inv-logo { max-height: 64px; max-width: 200px; object-fit: contain; align-self: flex-start; }
.inv-from { display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; }
.inv-from strong { font-size: 15px; }
.inv-from span { color: var(--ink-muted); }

.inv-title { text-align: right; }
.inv-title h2 { font-size: 30px; letter-spacing: 4px; font-weight: 800; color: var(--paper-ink); }
.inv-number { color: var(--ink-muted); font-size: 14px; }

.inv-meta { display: flex; justify-content: space-between; margin-bottom: 36px; gap: 24px; }
.inv-meta h3 { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--ink-muted); margin-bottom: 5px; }
.inv-billto { display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; }
.inv-billto strong { font-size: 15px; }
.inv-billto span { color: var(--ink-muted); }
.inv-dates { display: flex; gap: 36px; text-align: right; font-size: 13.5px; }

.inv-table { width: 100%; border-collapse: collapse; font-size: 13.5px; margin-bottom: 24px; }
.inv-table th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--ink-muted);
  padding: 0 8px 10px;
  border-bottom: 2px solid var(--paper-ink);
}
.inv-table td { padding: 11px 8px; border-bottom: 1px solid var(--ink-line); vertical-align: top; }
.inv-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.inv-table .empty td { color: var(--ink-muted); font-style: italic; }

.inv-totals { margin-left: auto; width: 280px; font-size: 13.5px; margin-bottom: 36px; font-variant-numeric: tabular-nums; }
.trow { display: flex; justify-content: space-between; padding: 7px 8px; color: var(--ink-muted); }
.trow.total { border-top: 2px solid var(--paper-ink); margin-top: 6px; padding-top: 12px; color: var(--paper-ink); font-weight: 800; font-size: 17px; }

.inv-notes { margin-bottom: 28px; }
.inv-notes h3 { font-size: 10.5px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--ink-muted); margin-bottom: 6px; }
.inv-notes p { font-size: 13px; color: var(--ink-muted); line-height: 1.55; }

.inv-footer { margin-top: auto; text-align: center; font-size: 11px; color: #b3b8c4; padding-top: 24px; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .app { flex-direction: column; padding: 8px; gap: 8px; }
  .editor { width: 100%; min-width: 0; height: auto; position: static; border-radius: 24px; }
  .editor-body { overflow: visible; padding: 20px; }
  .editor-header { padding: 16px 20px; flex-wrap: wrap; }
  .editor-footer { padding: 16px 20px 18px; }
  .preview-wrap { padding: 24px 10px; border-radius: 24px; }
  .paper { padding: 32px 24px; min-height: 0; }
  .inv-title h2 { font-size: 22px; letter-spacing: 2px; }
  .inv-dates { gap: 20px; }
  .modal { padding: 30px 22px 22px; border-radius: 26px; }
}
@media (max-width: 480px) {
  .editor-body { padding: 18px 16px; }
  .item-row { grid-template-columns: 1fr 50px 74px 26px; gap: 6px; }
  .item-row input { padding-left: 10px; padding-right: 8px; font-size: 13.5px; }
  .paper { padding: 24px 18px; }
  .inv-table { font-size: 12.5px; }
  .inv-table td, .inv-table th { padding-left: 4px; padding-right: 4px; }
  .inv-totals { width: 100%; }
}

/* ---------- Print: only the invoice ---------- */
@media print {
  @page { margin: 0; size: A4; }
  html, body { background: #fff; }
  .app { display: block; padding: 0; min-height: 0; }
  .no-print { display: none !important; }
  .preview-wrap { padding: 0; overflow: visible; background: none; border-radius: 0; display: block; }
  .paper {
    box-shadow: none;
    border-radius: 0;
    max-width: none;
    min-height: 100vh;
    padding: 48px 52px;
  }
}
