:root {
  --accent: #315cff; --accent-soft: #e8edff; --accent-ink: #1d3bb8;
  --ink: #111413; --paper: #f6f6f2; --surface: #ffffff; --muted: #5b6474; --line: #e2e5ec; --line-strong: #c6ccd8;
  --ok-bg: #dcebd2; --ok-fg: #2f4f25; --warn-bg: #fff1cc; --warn-fg: #6b4a00; --bad-bg: #fbe1de; --bad-fg: #8a1f12; --info-bg: #e8edff; --info-fg: #1d3bb8;
  --side: #111413; --side-ink: #e9ebe7; --side-muted: #9aa19c;
  --radius: 12px; --shadow: 0 1px 2px rgba(17,20,19,.06), 0 4px 16px rgba(17,20,19,.05);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 var(--font); color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
h1 { font-size: 24px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand img { height: 22px; width: auto; }
.brand span { font-weight: 700; font-size: 12px; letter-spacing: .12em; color: var(--side-muted); }
.nav-group { font-size: 11px; color: var(--side-muted); text-transform: uppercase; letter-spacing: .08em; padding: 14px 10px 4px; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--side-ink); padding: 8px 10px; border-radius: 8px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--accent); color: #fff; }
.nav .count { background: rgba(255,255,255,.14); border-radius: 99px; font-size: 11px; padding: 0 7px; min-width: 20px; text-align: center; }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.1); font-size: 12px; color: var(--side-muted); }
.side-foot strong { color: var(--side-ink); display: block; }
.side-foot button { margin-top: 8px; }
.main { min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.menu-btn { display: none; }
.search { position: relative; flex: 1; max-width: 520px; }
.search input { width: 100%; padding-left: 34px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; max-height: 70vh; overflow: auto; z-index: 20; }
.search-results h3 { padding: 8px 8px 2px; margin: 0; }
.search-results a { display: block; padding: 7px 8px; border-radius: 6px; color: var(--ink); }
.search-results a:hover, .search-results a:focus { background: var(--accent-soft); text-decoration: none; }
.content { padding: 24px 28px 64px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { margin-top: 4px; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 6px; }

/* Controls */
button, .btn { font: inherit; font-weight: 600; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); padding: 7px 13px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover { border-color: var(--ink); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
button.danger { color: var(--bad-fg); }
button.danger:hover { border-color: var(--bad-fg); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--accent-soft); }
.side button.ghost { color: var(--side-ink); padding-left: 0; }
.side button.ghost:hover { background: transparent; text-decoration: underline; }
button.sm { padding: 4px 9px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { min-height: 84px; resize: vertical; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
label { display: block; font-weight: 600; font-size: 12px; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.field .err { color: var(--bad-fg); font-size: 12px; margin-top: 3px; }
.field.invalid input, .field.invalid select { border-color: var(--bad-fg); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 180px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.cols { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }
.stack > * + * { margin-top: 18px; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; }

/* Badges */
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--line); color: var(--ink); white-space: nowrap; }
.badge::first-letter { text-transform: uppercase; }
.content > div > .card + .stack, .content > div > .card + .card { margin-top: 18px; }
.b-ok { background: var(--ok-bg); color: var(--ok-fg); }
.b-warn { background: var(--warn-bg); color: var(--warn-fg); }
.b-bad { background: var(--bad-bg); color: var(--bad-fg); }
.b-info { background: var(--info-bg); color: var(--info-fg); }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
tbody tr:hover { background: #fafbff; }
tr.done td { color: var(--muted); }
tr.done .subj { text-decoration: line-through; }
td.right, th.right { text-align: right; }
.table-card { padding: 0; overflow: hidden; }

/* Pipeline */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.col { background: #eceee8; border-radius: var(--radius); padding: 10px; min-height: 300px; display: flex; flex-direction: column; gap: 8px; }
.col.over { outline: 2px dashed var(--accent); background: var(--accent-soft); }
.col-head { display: flex; justify-content: space-between; align-items: baseline; padding: 2px 4px 6px; }
.col-head strong { font-size: 13px; }
.col-head .small { font-variant-numeric: tabular-nums; }
.deal-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.deal-card:active { cursor: grabbing; }
.deal-card.dragging { opacity: .4; }
.deal-card a { color: var(--ink); font-weight: 600; display: block; }
.deal-card .meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.deal-card .warn { color: var(--bad-fg); font-weight: 600; }
.dropzones { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.dropzone { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 16px; text-align: center; font-weight: 600; color: var(--muted); }
.dropzone.won.over { border-color: var(--ok-fg); background: var(--ok-bg); color: var(--ok-fg); }
.dropzone.lost.over { border-color: var(--bad-fg); background: var(--bad-bg); color: var(--bad-fg); }

/* Stage stepper */
.stepper { display: flex; gap: 4px; margin: 4px 0 18px; flex-wrap: wrap; }
.stepper button { flex: 1; min-width: 110px; justify-content: center; border-radius: 6px; font-size: 12px; background: #eceee8; border-color: transparent; }
.stepper button.past { background: var(--accent-soft); color: var(--accent-ink); }
.stepper button.current { background: var(--accent); color: #fff; }

/* Bars */
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.over > i { background: var(--bad-fg); }
.stage-row { display: grid; grid-template-columns: 140px 1fr 120px; gap: 10px; align-items: center; margin-bottom: 8px; font-size: 13px; }

/* Timeline */
.timeline { list-style: none; padding: 0; margin: 12px 0 0; }
.timeline li { border-left: 2px solid var(--line); padding: 0 0 14px 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.timeline .when { font-size: 12px; color: var(--muted); }
.timeline p { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Agents */
.engine { display: block; background: var(--warn-bg); color: var(--warn-fg); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 18px; font-size: 13px; }
.agents { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 18px; }
.agent { display: flex; flex-direction: column; gap: 6px; }
.agent .n { font-size: 22px; font-weight: 700; }
.sugg { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.sugg:last-child { border-bottom: 0; }
.sugg .body { flex: 1; min-width: 0; }
.sugg .title { font-weight: 600; }
.score { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 50%; font-weight: 700; background: var(--accent-soft); color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.score.hi { background: var(--ok-bg); color: var(--ok-fg); }
.score.lo { background: #eceee8; color: var(--muted); }

/* Quote lines */
.lines td input, .lines td select { padding: 5px 8px; }
.totals { margin-left: auto; max-width: 300px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand { border-top: 2px solid var(--ink); font-weight: 700; font-size: 16px; margin-top: 4px; padding-top: 8px; }

/* Modal & toasts */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(17,20,19,.45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fafbfc; }
.form-error { background: var(--bad-bg); color: var(--bad-fg); padding: 8px 12px; border-radius: 8px; margin-bottom: 12px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; }
.toast.bad { background: var(--bad-fg); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--side); }
.login .card { width: min(400px, 100%); padding: 28px; }
.login img { height: 26px; margin-bottom: 16px; filter: invert(1); }
.login h1 { margin-bottom: 4px; }
.login form { margin-top: 20px; }
.login button { width: 100%; justify-content: center; padding: 10px; }
.demo-hint { margin-top: 16px; font-size: 12px; color: var(--muted); background: var(--paper); border-radius: 8px; padding: 10px; }

/* Responsive */
@media (max-width: 1100px) { .cols { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .menu-btn { display: inline-flex; }
  .top { padding: 10px 16px; }
  .content { padding: 18px 16px 48px; }
  .grid2 { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; gap: 0; }
  .dl dd { margin-bottom: 8px; }
  .toolbar input, .toolbar select { min-width: 0; flex: 1 1 140px; }
  .stage-row { grid-template-columns: 1fr 70px; }
  .stage-row .bar { grid-column: 1 / -1; grid-row: 2; }
  /* Tabellen als kaarten */
  table.responsive thead { display: none; }
  table.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 12px; text-align: right; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; font-weight: 600; }
  table.responsive td:first-child { font-weight: 600; }
  .dropzones { grid-template-columns: 1fr 1fr; }
  .board { grid-auto-columns: 82vw; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* AI-assistent */
.ai-out { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.ai-text { white-space: pre-wrap; margin: 0; }
.ai-card details { margin-top: 12px; }
.ai-card summary { cursor: pointer; color: var(--muted); }
.timeline p { white-space: pre-wrap; }
td.field.invalid input { border-color: var(--bad-fg); background: var(--bad-bg, #fff4f4); }

/* Targets */
.tg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.tg { display: flex; flex-direction: column; gap: 8px; }
.tg-num .big { font-size: 24px; font-weight: 700; }
.tg-bar { position: relative; height: 10px; background: var(--line); border-radius: 99px; overflow: visible; }
.tg-bar > i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.tg-bar.s-behaald > i, .tg-bar.s-op-schema > i { background: var(--ok-fg); }
.tg-bar.s-achter > i { background: #c98a00; }
.tg-bar.s-risico > i, .tg-bar.s-niet-behaald > i { background: var(--bad-fg); }
.tg-bar .pace { position: absolute; top: -4px; width: 2px; height: 18px; background: var(--ink); border-radius: 1px; transform: translateX(-1px); }
.tg-meta div { margin-top: 2px; }
.tg-mini { display: flex; flex-direction: column; gap: 6px; color: inherit; text-decoration: none; }
.tg-mini:hover span:first-child { text-decoration: underline; }

/* ---------- ERP (v0.4) ---------- */
ul.plain { list-style: none; padding: 0; margin: 0 0 8px; }
ul.plain li { padding: 3px 0; border-bottom: 1px solid var(--line); }
.legend { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-left: 8px; }
.lg-rev, .fin-bars .rev { background: var(--accent); }
.lg-cost, .fin-bars .cost { background: #e0a43a; }
.fin-chart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 8px; align-items: end; height: 180px; margin-top: 8px; }
.fin-col { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; }
.fin-bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; border-bottom: 1px solid var(--line-strong); }
.fin-bars i { display: block; width: 40%; max-width: 18px; border-radius: 3px 3px 0 0; min-height: 1px; }
table.planning { width: 100%; border-collapse: collapse; min-width: 760px; }
table.planning th, table.planning td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.planning thead th { font-size: 12px; }
.pl-cell { min-width: 120px; }
.pl-cell.off { background: repeating-linear-gradient(45deg, transparent 0 6px, var(--line) 6px 7px); }
.pl-cell.over .pl-num strong { color: var(--bad-fg); }
.pl-btn { display: block; width: 100%; text-align: left; background: transparent; border: 1px solid transparent; padding: 6px; font-weight: 400; white-space: normal; }
.pl-btn:hover { border-color: var(--line-strong); background: var(--accent-soft); }
.pl-btn .bar, .pl-cell .bar { margin: 4px 0; }
.print-doc { display: none; }
@media print {
  body > *:not(.print-doc) { display: none !important; }
  body { background: #fff; }
  .print-doc { display: block; color: #000; font: 11pt/1.45 var(--font); padding: 0; }
  .print-doc h1 { font-size: 18pt; }
  .print-doc h2 { font-size: 16pt; margin: 0 0 6px; }
  .pd-head { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
  .pd-meta dl { display: grid; grid-template-columns: auto auto; gap: 2px 12px; margin: 0; }
  .pd-meta dt { color: #555; } .pd-meta dd { margin: 0; }
  .pd-to { margin-bottom: 24px; }
  .print-doc table { width: 100%; border-collapse: collapse; margin: 8px 0 16px; }
  .print-doc th, .print-doc td { border-bottom: 1px solid #ccc; padding: 6px 4px; text-align: left; }
  .print-doc th:nth-child(n+2), .print-doc td:nth-child(n+2) { text-align: right; }
  .pd-tot { margin-left: auto; width: 260px; text-align: right; }
  .pd-tot .grand { font-weight: 700; border-top: 2px solid #000; margin-top: 4px; padding-top: 4px; }
  .pd-foot { margin-top: 36px; font-size: 9pt; color: #444; }
}

/* Agentgroepen (v0.5) */
.agent-group { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted, #888); }
.card.agent.quiet { opacity: .7; }
