:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --ink: #1f2733;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --pop: #0f172a;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
  --radius: 14px;
  --doc-line: #d5dbe4;
  --doc-strong: #1f2733;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.55;
  font-size: 17px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 900px; margin: 0 auto; padding: 0 18px; }

/* header / footer / crumbs */
.site-head { border-bottom: 1px solid var(--line); background: var(--card); }
.site-head .wrap { display: flex; align-items: center; justify-content: space-between; height: 58px; }
.brand { font-weight: 800; font-size: 19px; color: var(--pop); letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.nav a { color: var(--muted); font-size: 15px; margin-left: 18px; }
.crumbs { font-size: 13px; color: var(--muted); margin: 18px 0 4px; }
.crumbs a { color: var(--muted); }
h1 { font-size: 28px; line-height: 1.2; letter-spacing: -.02em; margin: 10px 0 14px; }
.lead { color: var(--muted); margin: 0 0 20px; }
h2 { font-size: 20px; margin: 30px 0 12px; letter-spacing: -.01em; }
.site-foot { border-top: 1px solid var(--line); margin-top: 40px; padding: 22px 0 50px; color: var(--muted); font-size: 14px; background: var(--card); }
.site-foot a { color: var(--muted); }
.site-foot .wrap { display: flex; flex-wrap: wrap; gap: 8px 18px; }

/* controls */
.controls { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin: 8px 0 18px; }
.controls label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 5px; font-weight: 600; }
.row { display: flex; flex-wrap: wrap; gap: 14px; }
.row > div { flex: 1; min-width: 160px; max-width: 280px; }
.controls input, .controls select { width: 100%; padding: 10px 12px; font-size: 16px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.ctl-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 14px; }
.print-btn { font: inherit; font-weight: 700; font-size: 16px; cursor: pointer; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 10px; padding: 11px 20px; }
.print-btn:hover { filter: brightness(1.1); }
.hint { color: var(--muted); font-size: 13px; flex: 1; min-width: 200px; }

/* ---- the invoice document (paper) ---- */
.invoice-doc {
  background: #fff; border: 1px solid var(--line); border-radius: 4px;
  box-shadow: var(--shadow); padding: 40px 44px; margin: 0 0 18px; color: var(--ink);
}
.invoice-doc [contenteditable]:hover { background: #f1f5f9; }
.invoice-doc [contenteditable] { outline: none; border-radius: 3px; }
.invoice-doc [contenteditable]:focus { background: #eef4ff; box-shadow: 0 0 0 2px #dbe6ff; }

.inv-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
.biz { max-width: 55%; }
.logo-ph {
  display: inline-block; border: 1px dashed #b8c2d0; color: #94a3b8;
  font-size: 12px; padding: 14px 22px; border-radius: 6px; margin-bottom: 10px;
  text-transform: uppercase; letter-spacing: .08em;
}
.biz-name { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.biz-body { font-size: 13.5px; color: var(--muted); white-space: pre-wrap; margin-top: 4px; }
.inv-headright { text-align: right; min-width: 240px; }
.inv-heading { font-size: 30px; font-weight: 800; letter-spacing: .04em; color: var(--doc-strong); }
.meta { margin-top: 12px; font-size: 14px; }
.m-row { display: flex; justify-content: flex-end; gap: 12px; margin: 2px 0; }
.m-label { color: var(--muted); }
.m-val { min-width: 120px; text-align: right; font-weight: 600; border-bottom: 1px solid var(--doc-line); padding: 0 2px; }

.parties { display: flex; gap: 40px; margin: 26px 0 22px; flex-wrap: wrap; }
.party { flex: 1; min-width: 200px; }
.party-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin-bottom: 5px; }
.party-body { font-size: 14px; white-space: pre-wrap; min-height: 3em; }

/* items table */
.inv-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; }
.inv-table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: #fff; background: var(--doc-strong); font-weight: 700; padding: 9px 10px;
}
.inv-table th.c-qty, .inv-table th.c-rate, .inv-table th.c-amt { text-align: right; }
.inv-table td { border-bottom: 1px solid var(--doc-line); padding: 7px 10px; vertical-align: middle; }
.inv-table .c-desc { width: 52%; }
.inv-table .c-qty, .inv-table .c-rate, .inv-table .c-amt { width: 15%; text-align: right; }
.inv-table .c-amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.inv-table td.c-desc { white-space: pre-wrap; }
.inv-table input.in-qty, .inv-table input.in-rate {
  width: 100%; border: 0; background: transparent; font: inherit; color: inherit;
  text-align: right; padding: 2px 0; border-bottom: 1px dotted transparent;
}
.inv-table input:hover { border-bottom-color: var(--doc-line); }
.inv-table input:focus { outline: none; border-bottom-color: var(--accent); background: #eef4ff; }
.c-rm { width: 30px; text-align: center !important; }
.rm-btn { border: 0; background: transparent; color: #cbd5e1; font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px; }
.rm-btn:hover { color: #ef4444; }
.add-btn {
  margin-top: 10px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  background: #eef2ff; color: var(--accent); border: 1px solid #dbe4ff; border-radius: 8px; padding: 8px 14px;
}
.add-btn:hover { background: #e2e9ff; }

/* footer: notes + totals */
.inv-foot { display: flex; gap: 40px; justify-content: space-between; margin-top: 26px; flex-wrap: wrap; }
.notes { flex: 1.4; min-width: 220px; }
.notes-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin-bottom: 5px; }
.notes-body { font-size: 13.5px; color: #334155; white-space: pre-wrap; min-height: 2.5em; }
.pay-line { margin-top: 12px; font-size: 13.5px; }
.pay-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-right: 8px; }
.pay-val { border-bottom: 1px solid var(--doc-line); padding: 0 2px; }

.totals { flex: 1; min-width: 240px; max-width: 320px; align-self: flex-start; font-size: 14.5px; }
.t-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--doc-line); }
.t-label { color: var(--muted); }
.t-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.t-val input { width: 90px; text-align: right; border: 0; border-bottom: 1px dotted var(--doc-line); background: transparent; font: inherit; color: inherit; padding: 1px 0; }
.t-val input:focus { outline: none; border-bottom-color: var(--accent); background: #eef4ff; }
.in-tax { width: 44px !important; text-align: right; border: 0; border-bottom: 1px dotted var(--doc-line); background: transparent; font: inherit; color: inherit; }
.in-tax:focus { outline: none; border-bottom-color: var(--accent); }
.t-grand { border-bottom: none; border-top: 2px solid var(--doc-strong); margin-top: 4px; padding-top: 10px; font-size: 18px; }
.t-grand .t-label { color: var(--ink); font-weight: 800; }
.t-grand .t-val { font-weight: 800; }

/* link grids */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; margin-bottom: 10px; }
.grid a { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; color: var(--ink); font-size: 15px; }
.grid a:hover { border-color: var(--accent); text-decoration: none; }
.chip-emoji { margin-right: 6px; }

/* prose + ads */
.prose { margin: 22px 0; }
.prose p { margin: 0 0 14px; }
.fineprint { font-size: 13px; color: var(--muted); }
.ad-slot {
  margin: 22px 0;
  min-height: 90px;
  display: flex; align-items: center; justify-content: center;
  background: repeating-linear-gradient(45deg, #eef2f6, #eef2f6 10px, #f4f7fa 10px, #f4f7fa 20px);
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  color: #94a3b8; font-size: 12px; letter-spacing: .1em; text-transform: uppercase;
}

@media (max-width: 620px) {
  h1 { font-size: 23px; }
  .invoice-doc { padding: 22px 16px; }
  .inv-head { flex-direction: column; }
  .inv-headright { text-align: left; min-width: 0; }
  .m-row { justify-content: flex-start; }
  .m-val { text-align: left; }
  .biz { max-width: 100%; }
  .inv-table { font-size: 13px; }
  .inv-table th, .inv-table td { padding: 6px 6px; }
}

/* print: the document is the page, everything else disappears */
@media print {
  @page { size: letter portrait; margin: 0.5in; }
  body { background: #fff; font-size: 11pt; }
  .no-print, .ad-slot { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .invoice-doc { border: none; box-shadow: none; border-radius: 0; padding: 0; margin: 0; }
  .invoice-doc [contenteditable]:hover, .inv-table input:hover { background: none; border-bottom-color: transparent; }
  .inv-table thead { display: table-header-group; }
  .inv-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .rm-btn, .add-btn { display: none !important; }
}
