:root {
  --bg: #f4f5f3;
  --surface: #ffffff;
  --ink: #1b2430;
  --muted: #64707d;
  --line: #e1e4e0;
  --line-strong: #c9cec8;
  --accent: #0b1023;
  --brand: #3764ff;
  --brand-grad: linear-gradient(100deg, #3764ff 0%, #713cff 100%);
  --accent-ink: #ffffff;
  --accent-soft: #e9edff;
  --ok: #1d6b47;
  --ok-bg: #e2f1e8;
  --warn: #8a5a00;
  --warn-bg: #fbefd2;
  --bad: #a3271f;
  --bad-bg: #fbe4e1;
  --info: #2a4f7a;
  --info-bg: #e3ecf7;
  --radius: 8px;
  --sidebar: 224px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
[hidden] { display: none !important; }
h1 { font-size: 24px; line-height: 1.2; margin: 0; font-weight: 650; letter-spacing: -0.01em; text-wrap: balance; }
h2 { font-size: 16px; margin: 0; font-weight: 650; }
h3 { font-size: 14px; margin: 0; font-weight: 650; }
p { margin: 0 0 10px; }
a { color: #2a4fd6; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }

/* --- shell --- */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--accent); color: #cfd5ea;
  display: flex; flex-direction: column; padding: 20px 12px 16px; gap: 2px; z-index: 30;
}
.brand { display: inline-flex; align-items: center; text-decoration: none; }
.brand img { display: block; }
.sidebar .brand { padding: 4px 12px 22px; }
.nav { display: block; padding: 9px 12px; border-radius: 6px; color: inherit; text-decoration: none; font-weight: 500; }
.nav:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav.active { background: var(--brand-grad); color: #fff; }
.sidebar-foot { margin-top: auto; font-size: 13px; }
.account { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 8px; align-items: center; padding: 10px 10px 10px 12px; border: 1px solid rgba(255, 255, 255, 0.16); border-radius: 8px; background: rgba(255, 255, 255, 0.04); }
.account #user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .gear { grid-row: 1 / 3; grid-column: 2; display: inline-flex; padding: 8px; border-radius: 6px; color: #cfd5ea; }
.account .gear:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.account .gear.active { background: var(--brand-grad); color: #fff; }
.account .link { color: #fff; justify-self: start; }
.topbar { display: none; }
.scrim { display: none; }
.view { margin-left: var(--sidebar); padding: 32px 40px 80px; max-width: calc(var(--sidebar) + 1120px); outline: none; }

/* --- knoppen --- */
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 7px 14px;
  border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface); color: var(--ink);
  font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand-grad); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.1); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: #2a4fd6; text-decoration: underline; cursor: pointer; font-size: inherit; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 6px; cursor: pointer; color: inherit; display: inline-flex; }
.icon-btn:hover { background: rgba(0, 0, 0, 0.06); }
:focus-visible { outline: 2px solid #3764ff; outline-offset: 2px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* --- pagina-opbouw --- */
.page-head { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.crumb { font-size: 13px; color: var(--muted); text-decoration: none; display: inline-block; margin-bottom: 6px; }
.crumb:hover { text-decoration: underline; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card + .card, .card + .grid, .grid + .card, .notice + .card, .card + .notice { margin-top: 18px; }
.card-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-body { padding: 16px 18px; }
.grid { display: grid; gap: 18px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
.grid > .card { margin-top: 0; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.bad .value { color: var(--bad); }

/* --- lijsten --- */
.rows { list-style: none; margin: 0; padding: 0; }
.rows > li + li { border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 4px 16px; align-items: center; padding: 12px 18px; text-decoration: none; color: inherit; }
a.row:hover { background: #f8f9f7; }
.row .main { min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.row .amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.row .tags { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-arrow { color: var(--muted); font-size: 18px; line-height: 1; }
a.row:hover .row-arrow { color: var(--brand); }
.empty { padding: 22px 18px; color: var(--muted); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #eceeeb; color: #45505b; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.demo { background: #efe7f7; color: #5b3a86; }
.notice { border: 1px solid var(--line-strong); border-left: 4px solid var(--info); background: var(--surface); border-radius: 6px; padding: 12px 14px; margin-bottom: 18px; }
.notice.warn { border-left-color: #c48a12; }
.notice.bad { border-left-color: var(--bad); }
.notice p:last-child { margin-bottom: 0; }

/* --- formulieren --- */
.field { display: grid; gap: 4px; min-width: 0; }
.field > span, .field > label { font-size: 13px; font-weight: 550; color: #3c4753; }
.field .hint { font-size: 12.5px; color: var(--muted); font-weight: 400; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"], input[type="search"], input[type="url"], input[type="tel"], input:not([type]), select, textarea {
  width: 100%; min-height: 38px; padding: 7px 10px; border: 1px solid var(--line-strong); border-radius: 6px; background: #fff;
}
textarea { resize: vertical; min-height: 76px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid #3764ff; outline-offset: 0; border-color: #3764ff; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: flex-start; }
.check input { margin-top: 3px; }
.form-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.error-text { color: var(--bad); font-size: 13.5px; margin-top: 10px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input[type="search"] { max-width: 340px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 9px 12px; text-decoration: none; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--ink); border-bottom-color: var(--brand); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; font-weight: 550; }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
dl.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13.5px; }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }

/* --- documentregels --- */
.lines { display: grid; gap: 8px; }
.line-head, .line { display: grid; grid-template-columns: minmax(0, 1fr) 70px 80px 100px 84px 70px 104px 34px; gap: 8px; align-items: start; }
.line-head { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.line label > span { display: none; }
.line textarea { min-height: 38px; height: 38px; }
.line input { text-align: right; }
.line input[data-f="unit"] { text-align: left; }
.line .amt { padding-top: 8px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.line .del { min-height: 38px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 14px; }
.totals { margin-left: auto; width: min(100%, 320px); display: grid; gap: 5px; margin-top: 16px; }
.totals div { display: flex; justify-content: space-between; gap: 16px; }
.totals .grand { border-top: 2px solid var(--ink); padding-top: 8px; margin-top: 4px; font-weight: 700; font-size: 17px; }
table.doc { width: 100%; border-collapse: collapse; }
table.doc th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); text-align: left; padding: 6px 8px 6px 0; border-bottom: 1px solid var(--ink); }
table.doc td { padding: 9px 8px 9px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.doc .r { text-align: right; }
table.doc th:last-child, table.doc td:last-child { padding-right: 0; }
.scroll-x { overflow-x: auto; }

/* --- stappen van een lead --- */
.steps { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 18px; padding: 0; }
.steps li { display: flex; align-items: center; gap: 7px; padding: 5px 13px 5px 6px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: 13px; font-weight: 550; color: var(--muted); }
.steps .dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: #eceeeb; font-size: 12px; font-variant-numeric: tabular-nums; }
.steps li.done { color: var(--ink); }
.steps li.done .dot { background: var(--ok-bg); color: var(--ok); }
.steps li.current { border-color: var(--brand); color: var(--ink); }
.steps li.current .dot { background: var(--brand-grad); color: #fff; }
.steps.lost li { opacity: 0.55; }

/* --- login --- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(100%, 400px); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 28px; }
.auth-card .brand { display: block; margin-bottom: 18px; }
.auth-card form { display: grid; gap: 14px; margin-top: 18px; }

/* --- modal en meldingen --- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 28, 36, 0.45); display: grid; place-items: start center; padding: 6vh 16px 16px; z-index: 50; overflow-y: auto; }
.modal { width: min(100%, 620px); background: var(--surface); border-radius: 10px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.22); }
.modal.narrow { width: min(100%, 440px); }
.modal.wide { width: min(100%, 720px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px 20px 20px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; max-width: min(92vw, 420px); }
.toast { background: var(--ink); color: #fff; padding: 11px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); }
.toast.bad { background: var(--bad); }

/* --- telefoon en smalle schermen --- */
@media (max-width: 1040px) {
  .grid.side { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .topbar { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 20; background: var(--accent); color: #fff; padding: 6px 10px; }
  .topbar .icon-btn:hover { background: rgba(255, 255, 255, 0.12); }
  .sidebar { transform: translateX(-100%); transition: transform 0.18s ease; width: 260px; }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(20, 28, 36, 0.45); z-index: 25; }
  .view { margin-left: 0; padding: 20px 16px 72px; }
  .grid.two, .form-grid { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 21px; }
  .row { grid-template-columns: minmax(0, 1fr) auto; padding: 12px 14px; }
  .row .tags { grid-column: 1 / -1; justify-content: flex-start; }
  .row:has(.tags.arrow) { grid-template-columns: minmax(0, 1fr) auto auto; }
  .row .tags.arrow { grid-column: auto; }
  .card-head, .card-body { padding-left: 14px; padding-right: 14px; }
  .line-head { display: none; }
  .line { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fafbf9; }
  .line label { display: grid; gap: 3px; }
  .line label > span { display: block; font-size: 12px; color: var(--muted); font-weight: 550; }
  .line .f-desc { grid-column: 1 / -1; }
  .line input { text-align: left; }
  .line .amt { grid-column: 1 / 3; text-align: left; padding-top: 6px; }
  .line .del { justify-self: end; }
  .page-head .btn-row { width: 100%; }
  input, select, textarea { font-size: 16px; } /* voorkomt inzoomen op iOS */
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
