@font-face { font-family: Inter; src: url(/fonts/inter.woff2) format('woff2'); font-weight: 400 700; font-display: swap; }
@font-face { font-family: 'Space Grotesk'; src: url(/fonts/space-grotesk.woff2) format('woff2'); font-weight: 500 700; font-display: swap; }

:root {
  --bg: #F5F5F2; --card: #FFFFFF; --ink: #16181D; --ink2: #3D424C; --body: #4A505C; --muted: #5B616E; --soft: #6B7180; --off: #8A8F99;
  --line: #E4E4DF; --row: #ECECE8; --border: #D4D4CE; --field: #FAFAF8; --chip: #F0F0EC; --note: #EDEDE8;
  --blue: #1F4FD1; --blue-dark: #163A9E; --blue-ink: #1A3FA8; --blue-bg: #EEF2FD; --pill-blue: #E7EDFD;
  --amber-bg: #FFF6E8; --amber-line: #F4D9AE; --amber-ink: #5C3300; --amber-dot: #B86200; --concept-bg: #FFF1DC; --concept-ink: #8A4B00;
  --danger: #B42318; --err: #C2410C; --err-ink: #9A3412; --ok: #1F7A4D; --dash: #C9C9C2;
  --head: 'Space Grotesk', Inter, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); font: 15px/1.4 Inter, system-ui, -apple-system, 'Segoe UI', sans-serif; font-variant-numeric: tabular-nums; }
a { color: var(--blue); }
a:hover { color: var(--blue-dark); }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: var(--blue); }
h1, h2, p, dl, dd, ul { margin: 0; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
svg { flex-shrink: 0; }

/* app header */
.hdr { background: var(--card); border-bottom: 1px solid var(--line); }
.hdr > div { max-width: 1120px; margin: 0 auto; padding: 0 32px; height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.wide .hdr > div { max-width: 1360px; }
.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font: 700 19px var(--head); letter-spacing: -0.01em; }
.logo:hover { color: var(--ink); }
.logo i { width: 32px; height: 32px; border-radius: 8px; background: var(--blue); display: flex; align-items: center; justify-content: center; color: #fff; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 10px 14px; border-radius: 8px; color: var(--body); text-decoration: none; font-size: 14px; font-weight: 500; }
.nav a[aria-current] { background: var(--blue-bg); color: var(--blue-ink); font-weight: 600; }

#warn { background: #fef2f2; border-bottom: 1px solid var(--danger); color: var(--danger); padding: 10px 32px; }

/* buttons */
.btn { height: 44px; padding: 0 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--ink); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; white-space: nowrap; }
.btn:hover { color: var(--ink); background: var(--field); }
.btn:disabled { color: var(--off); background: var(--card); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; padding: 0 18px; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.primary:disabled { opacity: .55; background: var(--blue); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); }
.btn.link { height: 40px; padding: 0 12px; border: 0; background: transparent; color: var(--blue); }
.icon { width: 44px; height: 44px; border: 0; border-radius: 8px; background: transparent; color: var(--body); display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.icon:hover { background: var(--chip); color: var(--ink); }
.seg { display: inline-flex; gap: 4px; padding: 4px; background: var(--chip); border-radius: 10px; }
.seg button { height: 36px; padding: 0 14px; border: 0; border-radius: 7px; background: transparent; color: var(--body); font-size: 14px; font-weight: 500; }
.seg button span { color: var(--muted); }
.seg button[aria-pressed=true] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg button:disabled { cursor: not-allowed; opacity: .6; }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--concept-bg); color: var(--concept-ink); }
.pill i { width: 6px; height: 6px; border-radius: 50%; border: 1.5px solid var(--amber-dot); }
.pill.final { background: var(--pill-blue); color: var(--blue-ink); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.muted { color: var(--muted); }

/* list page */
.page { max-width: 1120px; margin: 0 auto; padding: 40px 32px 64px; display: flex; flex-direction: column; gap: 28px; }
.pagehead { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.pagehead > div { display: flex; flex-direction: column; gap: 6px; }
h1.title { font: 700 34px var(--head); letter-spacing: -0.02em; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.tile { padding: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.tile b { font-weight: 500; }
.tile strong { font: 600 28px var(--head); color: var(--ink); }
.tile a { font-weight: 500; }
.panel { overflow: hidden; }
.bar { padding: 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 1 1 280px; display: flex; align-items: center; }
.search svg { position: absolute; left: 14px; color: var(--soft); }
.search input { width: 100%; height: 44px; padding: 0 14px 0 42px; border: 1px solid var(--border); border-radius: 10px; font: inherit; background: var(--field); color: var(--ink); }
.scroll { overflow-x: auto; position: relative; }
table.list { width: 100%; min-width: 720px; border-collapse: collapse; }
.list th { text-align: left; padding: 12px 20px; background: var(--field); font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.list td { padding: 16px 20px; border-top: 1px solid var(--row); color: var(--body); }
.list td.act { padding: 8px 12px; text-align: right; width: 56px; }
.list .r { text-align: right; }
.list td a.nr { font-weight: 600; text-decoration: none; color: var(--ink); }
.list .none { color: var(--soft); font-style: italic; }
.list td.amt { font-weight: 600; color: var(--ink); }
.list td.amt.zero { font-weight: 400; color: var(--soft); }
#empty { padding: 24px 20px; color: var(--muted); }
#empty:empty { display: none; }
.aside { display: flex; gap: 14px; align-items: flex-start; padding: 16px 18px; border-radius: 12px; background: var(--note); color: var(--ink2); font-size: 14px; line-height: 1.55; }
.aside svg { color: var(--body); margin-top: 2px; }

/* editor */
.toolbar { background: var(--card); border-bottom: 1px solid var(--line); }
.toolbar > div { max-width: 1360px; margin: 0 auto; padding: 16px 32px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.toolbar .l, .toolbar .r { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.toolbar .r { gap: 8px; }
.toolbar h1 { font: 700 24px var(--head); letter-spacing: -0.01em; }
.toolbar .back { height: 44px; padding: 0 12px 0 8px; gap: 6px; border: 0; font-weight: 500; color: var(--body); }
.toolbar .sep { width: 1px; height: 24px; background: var(--line); }
.toolbar .small { font-size: 13px; color: var(--muted); }
#warn:not([hidden]) ~ .toolbar #saved { display: none; }
.editor { max-width: 1360px; margin: 0 auto; padding: 28px 32px 64px; display: flex; gap: 28px; flex-wrap: wrap; align-items: flex-start; }
.col { flex: 1 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.col form, #fields { display: flex; flex-direction: column; gap: 20px; }
.sec { padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.sec h2 { font: 600 18px var(--head); }
.check { display: flex; gap: 14px; align-items: flex-start; padding: 16px 18px; border-radius: 12px; background: var(--amber-bg); border: 1px solid var(--amber-line); color: var(--amber-ink); }
.check svg { color: var(--concept-ink); margin-top: 1px; }
.check div { display: flex; flex-direction: column; gap: 8px; }
.check p { font-weight: 600; }
.check ul { padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.check li { display: flex; gap: 8px; align-items: center; }
.check li i { width: 14px; height: 14px; border: 1.5px solid var(--amber-dot); border-radius: 50%; }
.check a { color: var(--amber-ink); }
.van { padding: 18px 22px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.van > div { display: flex; gap: 14px; align-items: center; min-width: 0; }
.van i { width: 40px; height: 40px; border-radius: 10px; background: var(--chip); display: flex; align-items: center; justify-content: center; color: var(--body); }
.van span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.van h2 { font: 600 13px Inter, sans-serif; color: var(--muted); }
.van strong { font-weight: 600; }
.van small { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.sechead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, legend { font-size: 14px; font-weight: 600; padding: 0; }
legend { margin-bottom: 8px; }
.field label small { color: var(--muted); font-weight: 400; font-size: inherit; }
.field input:not([type=checkbox]), .field textarea, .line input, .line select { width: 100%; height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: 10px; font: inherit; background: var(--card); color: var(--ink); min-width: 0; }
.field textarea { height: auto; padding: 12px 14px; resize: vertical; }
.field input:disabled, .field textarea:disabled, .line input:disabled, .line select:disabled { background: var(--field); color: var(--body); }
.t:invalid { border: 1.5px solid var(--err) !important; }
.err { display: none; font-size: 13px; color: var(--err-ink); }
.t ~ .err { display: block; }
.err:empty { display: none !important; }
.hint { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.hint svg { color: var(--ok); }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.term { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.term .field { flex-direction: row; align-items: center; gap: 8px; }
.term .field input { width: 80px; }
.term p { font-size: 14px; color: var(--body); }
.term strong { font-weight: 600; color: var(--ink); }
.lines { overflow-x: auto; }
.lines > div { min-width: 600px; display: flex; flex-direction: column; gap: 8px; }
.line, .linehead { display: grid; grid-template-columns: minmax(0, 3fr) 80px 130px 96px 100px 44px; gap: 10px; align-items: center; }
.linehead { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 0 2px; }
.line input[data-k=qty], .line input[data-k=price] { text-align: right; }
.line select { padding: 0 8px; }
.eur { position: relative; display: flex; align-items: center; }
.eur::before { content: '€'; position: absolute; left: 12px; color: var(--muted); }
.eur input { padding-left: 28px; }
.line .amt { text-align: right; color: var(--muted); }
.line .amt.on { color: var(--ink); }
.line .icon { color: var(--muted); }
#lineErr { color: var(--err-ink); font-size: 13px; }
#lineErr:empty { display: none; }
.add { height: 48px; border: 1.5px dashed var(--dash); border-radius: 10px; background: var(--field); color: var(--blue); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.add:disabled { opacity: .6; }
.sum { display: flex; justify-content: flex-end; }
.sum dl, .pv-sum dl { display: grid; grid-template-columns: 1fr auto; }
.sum dl { width: 280px; row-gap: 8px; column-gap: 16px; font-size: 14px; }
.sum dt { color: var(--body); }
.sum dd, .pv-sum dd { text-align: right; }
.sum .tot { font-weight: 700; font-size: 16px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--ink); }
.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.opt { display: flex; gap: 12px; align-items: flex-start; padding: 16px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.opt input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--blue); }
.opt span { display: flex; flex-direction: column; gap: 4px; }
.opt b { font-weight: 600; }
.opt small { font-size: 13px; color: var(--muted); line-height: 1.5; }
.note { font-size: 13px; color: var(--muted); line-height: 1.55; }
.pvwrap { flex: 1 1 480px; min-width: 0; display: flex; flex-direction: column; gap: 12px; position: sticky; top: 24px; }
.pvhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); }
.pvhead b { font-weight: 600; color: var(--body); text-transform: uppercase; letter-spacing: .05em; }

/* invoice preview (A4) */
#preview { background: #fff; border-radius: 6px; box-shadow: 0 1px 2px rgba(22,24,29,.06), 0 12px 32px rgba(22,24,29,.08); padding: 48px 48px 40px; display: flex; flex-direction: column; gap: 32px; font-size: 13px; line-height: 1.55; min-height: 880px; overflow-wrap: anywhere; }
#preview .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; flex-wrap: wrap; }
#preview .top > div { display: flex; flex-direction: column; gap: 2px; color: var(--body); white-space: pre-line; }
#preview .top strong { font: 700 20px var(--head); color: var(--ink); }
#preview h1 { font: 700 28px var(--head); letter-spacing: -0.01em; color: var(--blue); }
#preview .parties { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; }
#preview .parties > div { display: flex; flex-direction: column; gap: 4px; white-space: pre-line; }
#preview .lbl { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
#preview dl.meta { display: grid; grid-template-columns: auto 1fr; column-gap: 16px; row-gap: 2px; }
#preview dl.meta dt { color: var(--muted); }
#preview dl.meta dd { white-space: normal; }
#preview .ph { display: inline-block; align-self: flex-start; padding: 2px 8px; border: 1px dashed var(--err); border-radius: 4px; color: var(--err-ink); background: var(--amber-bg); }
#preview table { width: 100%; border-collapse: collapse; }
#preview th { padding: 8px 0 8px 10px; border-bottom: 1.5px solid var(--ink); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--ink2); text-align: left; }
#preview td { padding: 8px 0 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
#preview th:first-child, #preview td:first-child { padding-left: 0; }
#preview .n { text-align: right; white-space: nowrap; }
#preview td.empty { padding: 28px 0; text-align: center; color: var(--soft); }
.pv-sum { display: flex; justify-content: flex-end; padding-top: 12px; }
.pv-sum dl { width: 220px; row-gap: 4px; }
.pv-sum dt { color: var(--body); }
.pv-sum .tot { font-weight: 700; font-size: 15px; padding-top: 8px; margin-top: 4px; border-top: 1.5px solid var(--ink); color: var(--ink); }
#preview .pay { padding: 14px 16px; background: var(--bg); border-radius: 6px; color: var(--ink2); }
#preview .pay strong { font-weight: 600; color: var(--ink); }
#preview .foot { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--line); display: flex; gap: 20px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
#conceptNote { display: none; }

@media (max-width: 720px) {
  .hdr > div, .toolbar > div, .editor, .page { padding-left: 16px; padding-right: 16px; }
  .hdr > div { height: auto; min-height: 64px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
  .nav { flex-wrap: wrap; }
  .tiles { grid-template-columns: 1fr; }
  #preview { padding: 24px 20px; }
  .sec { padding: 16px; }
  #warn { padding: 10px 16px; }
}

@media print {
  body { background: #fff; }
  .hdr, #warn, .toolbar, .col, .pvhead { display: none; }
  .editor { display: block; padding: 0; max-width: none; }
  .pvwrap { position: static; display: block; }
  #preview { box-shadow: none; border-radius: 0; padding: 0; min-height: 0; font-size: 12px; }
  #preview .ph { border: 0; background: none; padding: 0; }
  body:not([data-final=true]) .pvwrap { display: none; }
  body:not([data-final=true]) #conceptNote { display: block; font-size: 16px; }
  tr { break-inside: avoid; }
  @page { size: A4; margin: 18mm; }
}
.linehead span:nth-child(5) { text-align: right; }
#lines { display: flex; flex-direction: column; gap: 8px; }
#preview dl.meta dd:first-of-type { font-weight: 600; }
.toolbar .r .btn { padding: 0 14px; }
.toolbar .r { gap: 4px; }

/* klanten, bedrijf, back-up, picker */
.narrow { max-width: 720px; }
.list.cust { min-width: 640px; }
.btn:has(input:focus-visible) { outline: 2px solid var(--blue); outline-offset: 2px; }
.backup { flex-wrap: wrap; align-items: center; justify-content: space-between; }
.backup > div { flex: 1 1 320px; display: flex; flex-direction: column; gap: 4px; }
.backup > span { display: flex; gap: 8px; flex-wrap: wrap; }
#bmsg:empty { display: none; }
#bmsg { font-weight: 600; }
.cform { padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.cform .saved { font-size: 13px; color: var(--muted); }
#warn:not([hidden]) ~ main #saved { display: none; }
dialog.pick { width: min(480px, calc(100vw - 32px)); max-height: 80vh; padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink); }
dialog.pick::backdrop { background: rgba(22,24,29,.4); }
dialog.pick h2 { font: 600 18px var(--head); margin-bottom: 12px; }
dialog.pick ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
dialog.pick li button { width: 100%; min-height: 44px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--ink); text-align: left; display: flex; flex-direction: column; gap: 2px; }
dialog.pick li button:hover { background: var(--field); }
dialog.pick small { color: var(--muted); overflow-wrap: anywhere; }
.pickbtn { align-self: flex-start; }
