@font-face { font-family: 'SN Pro'; font-weight: 400; src: url(/fonts/sn-pro-latin-400-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'SN Pro'; font-weight: 500; src: url(/fonts/sn-pro-latin-500-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'SN Pro'; font-weight: 600; src: url(/fonts/sn-pro-latin-600-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'SN Pro'; font-weight: 700; src: url(/fonts/sn-pro-latin-700-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'SN Pro'; font-weight: 800; src: url(/fonts/sn-pro-latin-800-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Instrument Serif'; font-style: italic; src: url(/fonts/instrument-serif-latin-400-italic.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Instrument Serif'; font-style: normal; src: url(/fonts/instrument-serif-latin-400-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; font-weight: 400; src: url(/fonts/jetbrains-mono-latin-400-normal.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; font-weight: 500; src: url(/fonts/jetbrains-mono-latin-500-normal.woff2) format('woff2'); font-display: swap; }

:root {
  --background: #ffffff;
  --surface: #ffffff;
  --soft: #F7F5F2;
  --foreground: #1F242E;
  --foreground-rgb: 31, 36, 46;
  --ink: #14161F;
  --muted: rgba(var(--foreground-rgb), .6);
  --primary: #1F7A5C;
  --primary-rgb: 31, 122, 92;
  --stem: #3FA37F;
  --mint: #E7F4EE;
  --blush: #F6E3E1;
  --amber: #A66A12;
  --amberbg: #FBF0DD;
  --danger: #C0392B;
  --border: rgba(var(--foreground-rgb), .12);
  --shadow: 0 4px 30px rgba(0, 0, 0, .08);
  --shadow-strong: 0 8px 40px rgba(0, 0, 0, .14);
  --radius: 24px;
  --max-width: 1300px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'SN Pro', system-ui, sans-serif;
  color: var(--foreground);
  background: var(--background);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.serif { font-family: 'Instrument Serif', Georgia, serif; font-style: italic; font-weight: 400; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.muted { color: var(--muted); }
.width { max-width: var(--max-width); margin: 0 auto; padding: 0 20px; }
[hidden] { display: none !important; }

/* ---------- background pattern (Papillon-style soft glow) ---------- */
.glow {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 420px at 12% -8%, rgba(63, 163, 127, .16), transparent 60%),
    radial-gradient(700px 380px at 95% 0%, rgba(246, 211, 205, .55), transparent 60%),
    var(--background);
}

/* ---------- navbar ---------- */
.navbar {
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  background: rgba(255, 255, 255, .72);
  border-bottom: 1px solid var(--border);
}
.navbar .width { height: 72px; display: flex; align-items: center; gap: 18px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; font-size: 1.1rem; }
.logo .badge { width: 38px; height: 38px; border-radius: 12px; background: var(--ink); display: grid; place-items: center; box-shadow: 0 1px 6px rgba(0, 0, 0, .25); }
.logo .badge img { width: 30px; height: 30px; }
.logo small { display: block; font-family: 'Instrument Serif', serif; font-style: italic; font-weight: 400; color: var(--primary); font-size: .95rem; letter-spacing: 0; line-height: 1; }
.nav { display: flex; gap: 4px; margin-left: auto; padding: 4px; background: var(--soft); border-radius: 90px; border: 1px solid var(--border); }
.nav a { padding: 8px 16px; border-radius: 90px; font-weight: 600; font-size: .92rem; color: var(--muted); transition: background .2s, color .2s; }
.nav a:hover { color: var(--foreground); }
.nav a.active { background: #fff; color: var(--foreground); box-shadow: 0 1px 6px rgba(var(--foreground-rgb), .12); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 20px; border-radius: 90px; border: 1px solid var(--border);
  background: #fff; font-weight: 600; font-size: .95rem; cursor: pointer; white-space: nowrap;
  transition: transform .15s ease, box-shadow .2s ease, background .2s;
  box-shadow: 0 1px 6px rgba(var(--foreground-rgb), .08);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(var(--foreground-rgb), .12); }
.btn:active { transform: translateY(0) scale(.98); }
.btn:disabled { opacity: .55; cursor: progress; transform: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 30px rgba(var(--primary-rgb), .35); }
.btn.ink { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.danger { color: var(--danger); }
.btn.sm { height: 36px; padding: 0 14px; font-size: .87rem; }
.btn.icon { width: 36px; padding: 0; }
.btn svg { width: 18px; height: 18px; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 420px; background: rgba(255, 255, 255, .86); border: 1px solid var(--border); border-radius: 32px; padding: 40px 32px 32px; box-shadow: var(--shadow-strong); text-align: center; backdrop-filter: blur(10px); }
.login-card .badge { width: 88px; height: 88px; margin: 0 auto 22px; border-radius: 28px; background: var(--ink); display: grid; place-items: center; box-shadow: 0 10px 30px rgba(20, 22, 31, .35); }
.login-card .badge img { width: 70px; height: 70px; }
.login-card h1 { font-size: 1.9rem; letter-spacing: -.03em; font-weight: 800; }
.login-card p { margin-top: 6px; color: var(--muted); font-weight: 500; }
.login-card form { margin-top: 26px; display: flex; flex-direction: column; gap: 12px; text-align: left; }
.login-card .err { color: var(--danger); font-size: .9rem; font-weight: 600; min-height: 1.2em; text-align: center; }
.login-card .btn { width: 100%; height: 50px; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: .8rem; font-weight: 600; color: var(--muted); letter-spacing: .01em; }
.input, .field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--border); background: #fff; border-radius: 14px;
  padding: 11px 14px; font-size: .95rem; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 76px; line-height: 1.45; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(var(--primary-rgb), .14); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.seg { display: inline-flex; padding: 4px; background: var(--soft); border-radius: 90px; border: 1px solid var(--border); gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 90px; font-weight: 600; font-size: .85rem; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--foreground); box-shadow: 0 1px 6px rgba(var(--foreground-rgb), .14); }
.seg.status button.on[data-v="paid"] { background: var(--mint); color: var(--primary); }
.seg.status button.on[data-v="sent"] { background: var(--amberbg); color: var(--amber); }

/* ---------- cards & sections ---------- */
.page { padding: 36px 0 80px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-title h3 { font-size: 1.05rem; font-weight: 700; letter-spacing: -.01em; }
.card-title .hint { font-size: .85rem; color: var(--muted); }
.section-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.section-heading h1 { font-size: 2.6rem; line-height: 1.05; letter-spacing: -.035em; font-weight: 800; }
.section-heading h1 .serif { color: var(--primary); font-size: 1.08em; letter-spacing: -.01em; }
.section-heading p { color: var(--muted); font-weight: 500; font-size: 1.08rem; margin-top: 8px; }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 26px; }
.stat { border-radius: var(--radius); padding: 20px 22px; border: 1px solid var(--border); background: #fff; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat .k { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.stat .v { font-size: 1.75rem; font-weight: 800; letter-spacing: -.03em; margin-top: 6px; }
.stat.hero { background: var(--ink); color: #fff; border-color: var(--ink); }
.stat.hero .k { color: rgba(255, 255, 255, .6); }
.stat.hero img { position: absolute; right: -18px; bottom: -22px; width: 110px; opacity: .12; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .input { max-width: 320px; border-radius: 90px; padding-left: 18px; }
.docs { display: flex; flex-direction: column; gap: 10px; }
.doc-row {
  display: grid; grid-template-columns: 46px 1.4fr 1fr auto auto; align-items: center; gap: 16px;
  padding: 14px 18px; border-radius: 20px; border: 1px solid var(--border); background: #fff;
  transition: box-shadow .2s, transform .15s; cursor: pointer;
}
.doc-row:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.doc-row .ic { width: 46px; height: 46px; border-radius: 14px; background: var(--soft); display: grid; place-items: center; }
.doc-row .ic img { width: 30px; }
.doc-row .t { font-weight: 700; }
.doc-row .s { font-size: .86rem; color: var(--muted); margin-top: 2px; }
.doc-row .amt { font-weight: 700; font-family: 'JetBrains Mono', monospace; font-size: .95rem; text-align: right; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 90px; font-size: .8rem; font-weight: 600; white-space: nowrap; }
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.paid { background: var(--mint); color: var(--primary); }
.pill.sent { background: var(--amberbg); color: var(--amber); }
.pill.draft { background: #EEF0F3; color: #4A5060; }
.empty { text-align: center; padding: 60px 20px; border: 1.5px dashed var(--border); border-radius: var(--radius); }
.empty img { width: 64px; opacity: .9; }
.empty h3 { margin-top: 14px; font-size: 1.25rem; }
.empty p { color: var(--muted); margin: 6px 0 18px; }

/* ---------- editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.editor-actions { position: sticky; top: 72px; z-index: 10; padding: 12px 0; margin-bottom: 8px; background: linear-gradient(#fff 70%, rgba(255, 255, 255, 0)); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.editor-actions .title { font-weight: 800; font-size: 1.35rem; letter-spacing: -.02em; margin-right: auto; display: flex; align-items: center; gap: 10px; }
.editor-actions .title .mono { font-size: .95rem; color: var(--muted); font-weight: 500; }
.dirty-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.lines { display: flex; flex-direction: column; gap: 10px; }
.line { border: 1px solid var(--border); border-radius: 18px; padding: 12px; background: var(--soft); display: grid; gap: 8px; grid-template-columns: 1fr 120px; position: relative; }
.line .row2 { grid-column: 1 / -1; display: grid; grid-template-columns: 90px 96px 1fr 1fr; gap: 8px; align-items: end; }
.line .tools { position: absolute; top: -10px; right: 10px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.line:hover .tools, .line:focus-within .tools { opacity: 1; }
.line .tools button { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: .8rem; line-height: 1; box-shadow: 0 1px 6px rgba(0, 0, 0, .1); }
.line .lt { font-family: 'JetBrains Mono', monospace; font-size: .9rem; align-self: end; text-align: right; padding: 0 4px 12px; font-weight: 500; }
.line input, .line select, .line textarea { background: #fff; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: #fff; border-radius: 90px; padding: 4px 10px; font-size: .78rem; font-weight: 600; cursor: pointer; color: var(--muted); }
.chip:hover { color: var(--primary); border-color: rgba(var(--primary-rgb), .4); }
.add-line { width: 100%; border: 1.5px dashed rgba(var(--primary-rgb), .45); color: var(--primary); background: rgba(var(--primary-rgb), .04); border-radius: 18px; padding: 14px; font-weight: 700; cursor: pointer; }
.add-line:hover { background: rgba(var(--primary-rgb), .09); }
.totals-mini { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; padding: 16px 18px; border-radius: 18px; background: var(--ink); color: #fff; }
.totals-mini div { display: flex; justify-content: space-between; font-size: .92rem; color: rgba(255, 255, 255, .7); }
.totals-mini div b { font-family: 'JetBrains Mono', monospace; color: #fff; font-weight: 500; }
.totals-mini .g { font-size: 1.15rem; color: #fff; font-weight: 700; padding-top: 8px; margin-top: 4px; border-top: 1px dashed rgba(255, 255, 255, .2); }
.preview-wrap { position: sticky; top: 140px; }
.preview { border-radius: var(--radius); background: #EDEAE5; padding: 16px; border: 1px solid var(--border); box-shadow: inset 0 2px 12px rgba(0, 0, 0, .04); }
.preview-frame { position: relative; width: 100%; overflow: hidden; border-radius: 8px; box-shadow: 0 10px 30px rgba(0, 0, 0, .14); background: #fff; }
.preview-frame iframe { position: absolute; top: 0; left: 0; border: 0; width: 794px; height: 1123px; transform-origin: 0 0; background: #fff; }
.preview-cap { display: flex; justify-content: space-between; align-items: center; font-size: .82rem; color: var(--muted); margin-top: 10px; padding: 0 4px; }

/* ---------- brand kit ---------- */
.bk-hero { border-radius: 32px; background: var(--ink); color: #fff; padding: 56px 48px; position: relative; overflow: hidden; display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px; align-items: center; }
.bk-hero h1 { font-size: 3.4rem; line-height: 1; letter-spacing: -.04em; font-weight: 800; }
.bk-hero h1 .serif { display: block; color: #8FD3B6; font-size: .9em; letter-spacing: -.01em; margin-top: 6px; }
.bk-hero p { color: rgba(255, 255, 255, .7); font-size: 1.08rem; margin-top: 18px; max-width: 520px; line-height: 1.55; }
.bk-hero .stack { display: flex; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.bk-hero .stack span { border: 1px solid rgba(255, 255, 255, .18); border-radius: 90px; padding: 6px 14px; font-size: .85rem; font-weight: 600; color: rgba(255, 255, 255, .85); font-family: 'JetBrains Mono', monospace; }
.bk-hero .big-mark { width: 100%; max-width: 360px; justify-self: center; filter: drop-shadow(0 20px 60px rgba(63, 163, 127, .25)); }
.bk-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 16px; }
.bk-tile { border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; background: #fff; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.bk-tile .art { aspect-ratio: 4 / 3; display: grid; place-items: center; padding: 28px; }
.bk-tile .art img { width: 100%; height: 100%; object-fit: contain; }
.bk-tile .meta { padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--border); }
.bk-tile .meta b { font-size: .95rem; }
.bk-tile .meta .dl { display: flex; gap: 6px; }
.art.dark { background: var(--ink); }
.art.ivory { background: #F8F5F0; }
.art.check { background: repeating-conic-gradient(#f2f2f2 0 25%, #fff 0 50%) 0 0 / 20px 20px; }
.swatches { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.sw { border-radius: 20px; overflow: hidden; border: 1px solid var(--border); background: #fff; cursor: pointer; text-align: left; padding: 0; }
.sw .c { height: 96px; }
.sw .i { padding: 10px 12px; }
.sw .i b { display: block; font-size: .9rem; }
.sw .i span { font-family: 'JetBrains Mono', monospace; font-size: .78rem; color: var(--muted); }
.type-row { display: grid; grid-template-columns: 200px 1fr; gap: 20px; padding: 18px 0; border-top: 1px solid var(--border); align-items: baseline; }
.type-row:first-of-type { border-top: 0; }
.type-row .lbl b { display: block; }
.type-row .lbl span { font-size: .85rem; color: var(--muted); }
.rules { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.rule { border-radius: 20px; padding: 18px 20px; background: var(--soft); }
.rule.do { background: var(--mint); }
.rule.dont { background: var(--blush); }
.rule h4 { margin-bottom: 8px; }
.rule li { margin-left: 18px; font-size: .94rem; line-height: 1.6; }
.code-card { background: var(--ink); color: #E9E6E1; border-radius: 20px; padding: 20px 22px; font-family: 'JetBrains Mono', monospace; font-size: .88rem; line-height: 1.7; overflow-x: auto; }
.code-card .k { color: #8FD3B6; }
.code-card .s { color: #F2C6C2; }
.code-card .c { color: rgba(255, 255, 255, .4); }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: all .25s ease; background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 90px; font-weight: 600; font-size: .92rem; box-shadow: var(--shadow-strong); z-index: 100; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .editor { grid-template-columns: 1fr; }
  .preview-wrap { position: static; }
  .stats { grid-template-columns: 1fr 1fr; }
  .swatches { grid-template-columns: repeat(3, 1fr); }
  .bk-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .navbar .width { gap: 8px; height: 64px; }
  .logo span { display: none; }
  .logo .badge { width: 36px; height: 36px; }
  .nav { margin-left: auto; }
  .nav a { padding: 7px 10px; font-size: .8rem; }
  .signout span { display: none; }
  .signout { width: 36px; padding: 0; }
  .card-title { flex-wrap: wrap; }
  .seg button { padding: 6px 10px; font-size: .8rem; }
  .editor-actions { top: 64px; }
  .editor-actions .title { width: 100%; font-size: 1.15rem; }
  .editor-actions .btn { flex: 1; }
  .editor-actions .btn.icon { flex: 0 0 36px; }
  .page { padding-top: 24px; }
  .section-heading h1 { font-size: 2rem; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .doc-row { grid-template-columns: 40px 1fr auto; }
  .doc-row .client, .doc-row .pill { display: none; }
  .line { grid-template-columns: 1fr; }
  .line .row2 { grid-template-columns: 1fr 1fr; }
  .line .lt { text-align: left; padding: 0 4px; }
  .bk-hero { grid-template-columns: 1fr; padding: 36px 24px; }
  .bk-hero h1 { font-size: 2.4rem; }
  .bk-grid, .rules { grid-template-columns: 1fr; }
  .swatches { grid-template-columns: 1fr 1fr; }
  .type-row { grid-template-columns: 1fr; gap: 6px; }
  .card { padding: 18px; }
}
