/* Quillbill: a blotter desk, white paper, carbon-blue ink, one rubber stamp. */
:root {
  --desk: #dde5e1;
  --desk-deep: #cbd6d1;
  --paper: #ffffff;
  --ink: #13203a;
  --muted: #56637a;
  --carbon: #2440c9;
  --carbon-soft: #e7ebfb;
  --stamp: #c4161c;
  --rule: #c7d1cc;
  --field-border: #768397; /* form fields: at least 3:1 against white and the editor background */
  --brand: #2440c9; /* overridden by the user's brand colour on the invoice */

  /* System fonts only: no third-party font requests, which keeps the "nothing leaves your browser" promise. */
  --font: "Segoe UI Variable Display", "Segoe UI", -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Roboto, ui-sans-serif, sans-serif;
  --step--1: 0.833rem;
  --step-0: 1rem;
  --step-1: 1.2rem;
  --step-2: 1.44rem;
  --step-3: 2.074rem;
  --step-4: 2.986rem;
  --radius-control: 6px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.5;
  color: var(--ink);
  background: var(--desk);
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
/* Free-only build (config proEnabled: false): no Pro tabs, buttons, prices or locked settings. */
.no-pro [data-pro-ui], .no-pro [data-pro-tab], .no-pro [data-pro], .no-pro #upgrade { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: #fff; padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: 1rem; }
:focus-visible { outline: 3px solid var(--carbon); outline-offset: 2px; }
a { color: var(--carbon); }

/* ───────── Top bar ───────── */
.bar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .75rem clamp(1rem, 3vw, 2rem);
  background: var(--ink); color: #fff;
  position: sticky; top: 0; z-index: 5;
}
.wordmark {
  font-weight: 900; font-size: var(--step-2); letter-spacing: -0.04em;
  color: #fff; text-decoration: none; font-style: italic;
}
.tabs { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.tab {
  font: inherit; font-weight: 600; color: #c9d2e6; background: none; border: 0;
  padding: .45rem .8rem; border-radius: var(--radius-control); cursor: pointer; white-space: nowrap;
}
.tab:hover { color: #fff; }
.tab[aria-current="page"] { color: #fff; background: rgba(255,255,255,.12); }
.tab[data-pro-tab]::after { content: "Pro"; font-size: .7em; margin-left: .4em; padding: .05em .35em; border-radius: 3px; background: var(--carbon); color: #fff; vertical-align: .15em; }
body.is-pro .tab[data-pro-tab]::after { display: none; }
.plan-btn {
  font: inherit; font-weight: 700; color: var(--ink); background: #fff; border: 0;
  padding: .45rem 1rem; border-radius: 999px; cursor: pointer;
}
body.is-pro .plan-btn { background: transparent; color: #fff; box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.5); }

/* ───────── Controls ───────── */
button, .file-btn {
  font: inherit; font-weight: 600; font-size: var(--step--1);
  padding: .55rem .95rem; border-radius: var(--radius-control);
  border: 1.5px solid var(--ink); background: var(--paper); color: var(--ink); cursor: pointer;
}
button:hover, .file-btn:hover { background: var(--carbon-soft); }
button.primary { background: var(--carbon); border-color: var(--carbon); color: #fff; }
button.primary:hover { background: #1b33a8; }
button.ghost { border-color: transparent; background: transparent; color: var(--carbon); text-decoration: underline; text-underline-offset: 3px; padding-inline: .4rem; }
button.ghost:hover { background: transparent; color: var(--ink); }
button.danger { border-color: var(--stamp); color: var(--stamp); }
.file-btn { display: inline-flex; align-items: center; }
.file-btn input { position: absolute; opacity: 0; width: 1px; }
.file-btn:focus-within { outline: 3px solid var(--carbon); outline-offset: 2px; }
.icon-btn { border: 0; background: none; font-size: 1.6rem; line-height: 1; padding: .2rem .5rem; }

label { display: grid; gap: .25rem; font-size: var(--step--1); font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: var(--step-0); color: var(--ink); font-weight: 400;
  padding: .5rem .6rem; border: 1.5px solid var(--field-border); border-radius: var(--radius-control);
  background: var(--paper); width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--carbon); outline: none; box-shadow: 0 0 0 3px var(--carbon-soft); }
textarea { resize: vertical; }
input[type="color"] { padding: .15rem; height: 2.4rem; width: 4rem; }
input[type="file"] { border: 0; padding: .3rem 0; background: none; }
.row-inline { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; }
.row-inline select { width: auto; flex: 1 1 12rem; }
.grow { flex: 1 1 18rem; }
.hint { font-size: var(--step--1); color: var(--muted); margin: .4rem 0 0; }

/* ───────── Workspace: editor + desk ───────── */
.workspace {
  display: grid;
  grid-template-columns: minmax(20rem, 30rem) 1fr;
  min-height: calc(100vh - 3.5rem);
}
.editor {
  background: #f5f8f7; border-right: 1.5px solid var(--desk-deep);
  padding: 1.5rem clamp(1rem, 2.5vw, 1.75rem) 2rem;
  display: grid; gap: 1.25rem; align-content: start;
}
.editor-intro h1 { font-size: var(--step-3); line-height: 1.05; letter-spacing: -0.03em; margin: 0 0 .4rem; font-weight: 800; }
.editor-intro p { margin: 0; color: var(--muted); }
fieldset {
  border: 0; border-top: 1.5px solid var(--rule); margin: 0; padding: .9rem 0 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: .7rem .8rem;
}
legend { font-weight: 800; font-size: var(--step-0); padding: 0 .5rem 0 0; color: var(--ink); }
.span2 { grid-column: 1 / -1; }
.lines-set { grid-template-columns: 1fr; }
.lines-head, .line { display: grid; grid-template-columns: 1fr 4.2rem 6rem 2rem; gap: .4rem; align-items: center; }
.lines-head { font-size: var(--step--1); font-weight: 600; color: var(--muted); }
#lines { display: grid; gap: .4rem; }
.line button { padding: .3rem; border: 0; background: none; color: var(--muted); font-size: 1.2rem; line-height: 1; }
.line button:hover { color: var(--stamp); background: none; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; padding-top: .5rem; border-top: 1.5px solid var(--rule); }

.desk {
  padding: clamp(1rem, 4vw, 3.5rem);
  display: flex; justify-content: center; align-items: flex-start;
}

/* ───────── The paper ───────── */
.paper {
  --brand: var(--carbon);
  position: relative; overflow: hidden;
  background: var(--paper);
  width: 100%; max-width: 50rem; aspect-ratio: 1 / 1.414; min-height: fit-content;
  padding: clamp(1.5rem, 5vw, 3.5rem);
  box-shadow: 0 1px 0 var(--desk-deep), 0 18px 40px -22px rgba(19,32,58,.45);
  display: flex; flex-direction: column; gap: 1.8rem;
  font-size: .95rem;
}
.paper::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 6px; background: var(--brand); }
.p-head { display: flex; justify-content: space-between; gap: 2rem; align-items: flex-start; }
.p-from { display: grid; gap: .3rem; max-width: 60%; }
.p-logo { max-height: 56px; max-width: 200px; object-fit: contain; object-position: left; margin-bottom: .4rem; }
.p-name { font-size: var(--step-2); font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
.p-small { color: var(--muted); white-space: pre-line; font-size: .88rem; }
.p-title { text-align: right; }
.p-title h2 { margin: 0; font-size: var(--step-4); font-weight: 900; letter-spacing: -0.05em; line-height: .9; color: var(--brand); }
.p-meta { margin: .7rem 0 0; display: grid; grid-template-columns: auto auto; gap: .15rem 1rem; justify-content: end; font-size: .88rem; }
.p-meta dt { color: var(--muted); }
.p-meta dd { margin: 0; font-weight: 600; text-align: right; }
.p-to h3 { margin: 0 0 .3rem; font-size: .8rem; color: var(--muted); font-weight: 600; }
.p-to .p-client { font-weight: 700; font-size: 1.05rem; }
.p-table { width: 100%; border-collapse: collapse; }
.p-table th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 0 0 .5rem; border-bottom: 2px solid var(--ink); }
.p-table td { padding: .6rem 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.p-table .num, .list .num { text-align: right; padding-left: 1rem; }
.p-totals { margin-left: auto; min-width: 16rem; display: grid; grid-template-columns: 1fr auto; gap: .3rem 2rem; }
.p-totals dt { color: var(--muted); }
.p-totals dd { margin: 0; text-align: right; font-weight: 600; }
.p-totals .grand { font-size: var(--step-1); font-weight: 900; color: var(--ink); padding-top: .4rem; border-top: 2px solid var(--ink); }
.p-notes { display: grid; gap: .8rem; white-space: pre-line; font-size: .88rem; }
.p-notes h3 { margin: 0 0 .15rem; font-size: .8rem; color: var(--muted); font-weight: 600; }
.p-notes p { margin: 0; }
.p-foot { margin-top: auto; font-size: .75rem; color: var(--muted); }
.p-empty { color: #677386; }

/* The one loud thing: a rubber stamp. */
.stamp {
  position: absolute; top: 36%; right: 9%;
  font-weight: 900; font-size: clamp(2.2rem, 6vw, 3.6rem); letter-spacing: .06em;
  color: var(--stamp); border: .22em solid var(--stamp); border-radius: .18em;
  padding: .05em .35em; transform: rotate(-14deg);
  opacity: .82; mix-blend-mode: multiply; pointer-events: none;
  -webkit-mask-image: radial-gradient(circle at 30% 40%, #000 55%, rgba(0,0,0,.55) 75%, #000 100%);
          mask-image: radial-gradient(circle at 30% 40%, #000 55%, rgba(0,0,0,.55) 75%, #000 100%);
}
.stamp.overdue { color: var(--stamp); background: transparent; font-size: clamp(1.6rem, 4.5vw, 2.6rem); border-style: double; border-width: .3em; }
.stamp.sent { color: var(--carbon); border-color: var(--carbon); font-size: clamp(1.4rem, 3.6vw, 2rem); opacity: .6; transform: rotate(-8deg); top: auto; bottom: 14%; }
.stamp.thud { animation: thud .38s cubic-bezier(.2,.9,.3,1.4) both; }
@keyframes thud {
  0% { transform: rotate(-14deg) scale(1.9); opacity: 0; }
  60% { transform: rotate(-14deg) scale(.94); opacity: .9; }
  100% { transform: rotate(-14deg) scale(1); opacity: .82; }
}

/* ───────── Pages: invoices, time, settings ───────── */
.page { max-width: 64rem; margin: 0 auto; padding: 2rem clamp(1rem, 3vw, 2rem) 3rem; }
.page h2 { font-size: var(--step-3); letter-spacing: -0.03em; margin: 0 0 1.25rem; }
.locked-note { background: var(--paper); padding: 1.25rem 1.5rem; border-left: 6px solid var(--carbon); margin-bottom: 1.5rem; }
.locked-note p { margin: 0 0 .8rem; max-width: 60ch; }
body.is-pro [data-locked-note] { display: none; }
body:not(.is-pro) [data-pro-body] { opacity: .45; pointer-events: none; user-select: none; filter: grayscale(.4); }
.totals-strip { display: flex; flex-wrap: wrap; gap: 2.5rem; margin: 0 0 1.5rem; }
.totals-strip div { display: grid; }
.totals-strip dt { font-size: var(--step--1); color: var(--muted); font-weight: 600; }
.totals-strip dd { margin: 0; font-size: var(--step-2); font-weight: 800; }
.totals-strip .warn dd { color: var(--stamp); }
.table-wrap { overflow-x: auto; background: var(--paper); }
.list { width: 100%; border-collapse: collapse; font-size: .95rem; }
.list th { text-align: left; font-size: var(--step--1); color: var(--muted); padding: .7rem .8rem; border-bottom: 2px solid var(--ink); }
.list td { padding: .6rem .8rem; border-bottom: 1px solid var(--rule); }
.list td.acts { white-space: nowrap; text-align: right; }
.list td.acts button { padding: .3rem .55rem; margin-left: .25rem; }
.chip { font-size: var(--step--1); font-weight: 700; padding: .1rem .5rem; border-radius: 3px; border: 1.5px solid currentColor; }
.chip.paid { color: #13784a; }
.chip.overdue { color: var(--stamp); }
.chip.sent { color: var(--carbon); }
.chip.draft { color: var(--muted); }
.empty { color: var(--muted); }
.timer { display: grid; grid-template-columns: 2fr 1.4fr 1fr auto auto; gap: .8rem; align-items: end; background: var(--paper); padding: 1.25rem; margin-bottom: 1rem; }
.clock { font-size: var(--step-3); font-weight: 800; letter-spacing: -0.02em; padding: 0 .5rem; }
.timer.running .clock { color: var(--stamp); }
.manual { margin-bottom: 1rem; }
.manual summary { cursor: pointer; font-weight: 600; color: var(--carbon); }
.manual .row-inline { margin-top: .6rem; }
#t-bill { margin-top: 1rem; }
.set-block { background: var(--paper); padding: 1.25rem 1.5rem; margin-bottom: 1rem; }
.set-block h3 { margin: 0 0 .6rem; font-size: var(--step-1); }
.set-block p { margin: 0 0 .8rem; max-width: 65ch; }
.pro-tag { font-size: .65em; background: var(--carbon); color: #fff; padding: .1em .45em; border-radius: 3px; vertical-align: .2em; }
body.is-pro .pro-tag { display: none; }
.plain { list-style: none; padding: 0; margin: 0 0 .8rem; }
.plain li { display: flex; justify-content: space-between; gap: 1rem; padding: .4rem 0; border-bottom: 1px solid var(--rule); }
.plain li button { padding: .2rem .5rem; }
.plain .sub { color: var(--muted); font-size: var(--step--1); font-weight: 700; border: 0; padding-top: .8rem; }
body:not(.is-pro) .set-block[data-pro] > :not(h3) { opacity: .5; pointer-events: none; }
body:not(.is-pro) [data-pro].pro-only, body:not(.is-pro) #item-pick { display: none; }

/* ───────── About / pricing ───────── */
.about { background: var(--paper); border-top: 1.5px solid var(--desk-deep); }
.about-inner { max-width: 46rem; margin: 0 auto; padding: 3.5rem clamp(1rem, 4vw, 2rem); }
.about h2 { font-size: var(--step-3); letter-spacing: -0.03em; line-height: 1.1; margin: 2.5rem 0 1rem; }
.about h2:first-child { margin-top: 0; }
.why { display: grid; gap: 1.2rem; margin: 0; }
.why dt { font-weight: 800; font-size: var(--step-1); }
.why dd { margin: .15rem 0 0; color: var(--muted); max-width: 60ch; }
.pricing { width: 100%; border-collapse: collapse; margin-bottom: 1.2rem; }
.pricing th, .pricing td { padding: .55rem .6rem; border-bottom: 1px solid var(--rule); text-align: center; }
.pricing th[scope="row"] { text-align: left; font-weight: 400; }
.pricing thead th { font-size: var(--step-1); border-bottom: 2px solid var(--ink); }
.pricing thead th:last-child, .pricing td:last-child { background: var(--carbon-soft); font-weight: 700; }
.pricing tfoot th, .pricing tfoot td { font-weight: 800; border-bottom: 0; }
.about details { border-bottom: 1px solid var(--rule); padding: .8rem 0; }
.about summary { cursor: pointer; font-weight: 700; }
.about details p { margin: .5rem 0 0; color: var(--muted); }
.templates-link { margin-top: 2rem; }
.foot { text-align: center; color: var(--muted); font-size: var(--step--1); padding: 1.5rem; }
.foot p { margin: 0 0 .5rem; }
.foot-links { display: flex; flex-wrap: wrap; justify-content: center; gap: .3rem 1.4rem; }
.foot-links a { color: var(--muted); }
.foot-links a:hover { color: var(--ink); }

/* ───────── Dialog & toast ───────── */
dialog {
  border: 0; padding: 2rem; max-width: 30rem; width: calc(100% - 2rem);
  border-radius: 10px; color: var(--ink); box-shadow: 0 30px 60px -20px rgba(19,32,58,.5);
}
dialog::backdrop { background: rgba(19,32,58,.55); }
dialog h2 { margin: 0 0 .5rem; font-size: var(--step-3); letter-spacing: -0.03em; }
.up-close-form { position: absolute; top: .6rem; right: .6rem; }
.up-plans { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin: 1.2rem 0 .4rem; }
.plan {
  display: grid; gap: .2rem; padding: 1rem; border: 1.5px solid var(--ink); border-radius: 8px;
  text-decoration: none; color: var(--ink); cursor: pointer;
}
.plan strong { font-size: var(--step-1); }
.plan span:last-child { color: var(--muted); font-size: var(--step--1); }
.plan:hover { background: var(--carbon-soft); }
.plan-year { border-color: var(--carbon); box-shadow: inset 0 0 0 1.5px var(--carbon); }
.plan[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 150%);
  background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: 8px;
  font-weight: 600; transition: transform .25s ease; z-index: 20; max-width: calc(100% - 2rem);
}
.toast.show { transform: translate(-50%, 0); }

/* ───────── Responsive ───────── */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .editor { border-right: 0; border-bottom: 1.5px solid var(--desk-deep); }
  .paper { aspect-ratio: auto; }
  .timer { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .bar { flex-wrap: wrap; gap: .5rem 1rem; }
  .tabs { order: 3; flex-basis: 100%; }
  fieldset { grid-template-columns: 1fr; }
  .p-head { flex-direction: column-reverse; gap: 1rem; }
  .p-title { text-align: left; }
  .p-meta { justify-content: start; }
  .p-from { max-width: none; }
  .up-plans { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .stamp.thud { animation: none; }
  .toast { transition: none; }
  .notice { animation: none; }
}

/* ───────── Print: only the paper ───────── */
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  .bar, .editor, .about, .foot, .toast, .notice, dialog, .skip, .view:not(#view-editor) { display: none !important; }
  .workspace { display: block; min-height: 0; }
  .desk { padding: 0; display: block; }
  .paper { box-shadow: none; max-width: none; aspect-ratio: auto; min-height: 297mm; padding: 16mm 16mm; }
  .stamp.sent { display: none; }
  .stamp { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .paper::before { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ── Cookie & storage notice: bottom of the screen, never blocks the page or traps focus ── */
.notice { position: fixed; left: 1rem; right: 1rem; bottom: 1rem; z-index: 40; max-width: 46rem; margin: 0 auto;
  display: flex; gap: 1rem; align-items: center; background: var(--ink); color: #fff; border-radius: 8px;
  padding: .9rem 1rem .9rem 1.2rem; box-shadow: 0 18px 40px -18px rgba(19,32,58,.6); animation: notice-in .3s ease-out; }
.notice p { margin: 0; font-size: var(--step--1); line-height: 1.5; }
.notice a { color: #c9d2e6; margin-right: .6rem; }
.notice a:hover { color: #fff; }
.notice button { flex: none; }
.notice :focus-visible { outline-color: #fff; }
@keyframes notice-in { from { transform: translateY(1rem); opacity: 0; } }
@media (max-width: 560px) { .notice { flex-direction: column; align-items: stretch; } }

/* ── Checkboxes with their text (terms and age confirmation, full erase) ── */
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 400; margin: .8rem 0; line-height: 1.45; }
.check input { width: 1.15rem; height: 1.15rem; margin: .15rem 0 0; flex: none; accent-color: var(--carbon); }
.buy-agree { background: var(--carbon-soft); border-radius: 6px; padding: .7rem .8rem; }
.plan[aria-disabled="true"] { cursor: not-allowed; }

/* ── Footer business details and legal pages ── */
.foot-biz { margin: .8rem 0 0; }
.foot-biz a { color: var(--muted); }
.doc ol { padding-left: 1.3rem; }
.doc ol li { margin-bottom: .5rem; }
.doc-table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-size: var(--step--1); background: var(--paper); }
.doc-table th, .doc-table td { text-align: left; vertical-align: top; padding: .6rem .7rem; border: 1px solid var(--rule); }
.doc-table code { font-size: .95em; }

@media (prefers-reduced-motion: reduce) { .notice { animation: none; } }
