/* ============ Tokens ============ */
:root {
  color-scheme: light;
  --page: #f4f5f7;
  --surface: #fcfcfb;
  --surface-2: #f0f1f4;
  --border: rgba(11, 11, 11, 0.10);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --brand: #14284b;
  --brand-ink: #ffffff;
  --accent: #2a78d6;
  --accent-soft: #e3eefb;
  --good: #006300;
  --good-bg: #e2f3e2;
  --warn-bg: #fff3d6;
  --warn-ink: #7a5300;
  --crit: #d03b3b;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --seq-lo: #cde2fb; --seq-hi: #184f95;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232322;
    --border: rgba(255,255,255,0.10); --text: #f0efec; --text-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --brand: #101c33; --accent: #3987e5; --accent-soft: #1b2b44;
    --good: #0ca30c; --good-bg: #13301a; --warn-bg: #3a2e10; --warn-ink: #fab219;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
    --seq-lo: #1c3350; --seq-hi: #86b6ef;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232322;
  --border: rgba(255,255,255,0.10); --text: #f0efec; --text-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --brand: #101c33; --accent: #3987e5; --accent-soft: #1b2b44;
  --good: #0ca30c; --good-bg: #13301a; --warn-bg: #3a2e10; --warn-ink: #fab219;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  --seq-lo: #1c3350; --seq-hi: #86b6ef;
  --shadow: none;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--text); font-size: 14px; line-height: 1.45; }
.hidden { display: none !important; }
.loading-screen { position: fixed; inset: 0; display: grid; place-items: center; color: var(--text-2); font-size: 16px; padding: 16px; text-align: center; background: var(--page); }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--text-2); }
small { color: var(--muted); }

.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.full { width: 100%; }
.icon-btn { border: 0; background: transparent; color: var(--text); font-size: 18px; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }

select, input[type=search], input[type=text], input[type=email], input[type=password] {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}

/* ============ Brand ============ */
.brand { display: flex; align-items: center; gap: 10px; font-size: 19px; letter-spacing: .2px; padding: 20px 18px; color: var(--brand-ink); }
.brand b { font-weight: 800; }
.logo { width: 28px; height: 28px; border-radius: 50%; border: 3px solid currentColor; position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: #6da7ec; }
.brand.big { font-size: 26px; padding: 0; }
.brand.big .logo { width: 36px; height: 36px; }

/* ============ Login ============ */
.login { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.login-brand { background: var(--brand); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center; gap: 28px; }
.login-brand h1 { font-size: 38px; font-weight: 750; }
.usp { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; color: #cfd8ea; font-size: 16px; }
.usp li::before { content: "✓"; color: #6da7ec; font-weight: 700; margin-right: 10px; }
.login-form-wrap { display: flex; align-items: center; justify-content: center; padding: 32px 16px; background: var(--surface); }
.login-form { width: 100%; max-width: 360px; display: grid; gap: 16px; }
.login-form h2 { font-size: 26px; }
.login-form label { display: grid; gap: 6px; font-weight: 500; }
.login-form input { padding: 10px 12px; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
@media (max-width: 800px) {
  .login { grid-template-columns: 1fr; }
  .login-brand { padding: 32px 16px; }
  .login-brand h1 { font-size: 28px; }
}

/* ============ App shell ============ */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--brand); color: #dfe6f3; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
#nav { display: grid; gap: 2px; padding: 4px 10px; overflow-y: auto; }
#nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #8797b5; padding: 14px 10px 6px; }
#nav a { display: flex; align-items: center; gap: 10px; color: #dfe6f3; text-decoration: none; padding: 9px 10px; border-radius: 8px; font-weight: 500; }
#nav a:hover { background: rgba(255,255,255,.07); }
#nav a.active { background: rgba(109,167,236,.18); color: #fff; box-shadow: inset 3px 0 0 #6da7ec; }
#nav a .ico { width: 20px; text-align: center; opacity: .9; }
#nav a .count { margin-left: auto; font-size: 11px; background: rgba(255,255,255,.12); padding: 1px 7px; border-radius: 10px; }
.sidebar-foot { margin-top: auto; padding: 14px; border-top: 1px solid rgba(255,255,255,.08); display: grid; gap: 10px; }
.sidebar-foot .btn { color: #dfe6f3; border-color: rgba(255,255,255,.2); }
.sidebar-foot .btn:hover { background: rgba(255,255,255,.07); }
.user { display: flex; gap: 10px; align-items: center; }
.user small { display: block; color: #8797b5; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #2a78d6; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.search { flex: 1; max-width: 560px; }
.search input { width: 100%; padding: 9px 12px; }
.updated { font-size: 12px; color: var(--muted); margin-left: auto; white-space: nowrap; }
.menu-btn { display: none; }
.badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.demo { background: var(--warn-bg); color: var(--warn-ink); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.filters select { max-width: 230px; }
.check { display: flex; gap: 6px; align-items: center; color: var(--text-2); }

.view { padding: 24px; display: grid; gap: 20px; align-content: start; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; width: 260px; left: -270px; transition: left .2s; }
  .sidebar.open { left: 0; }
  .menu-btn { display: inline-block; }
  .topbar, .filters { padding-left: 16px; padding-right: 16px; }
  .view { padding: 16px; }
  .updated { display: none; }
  .filters select { flex: 1 1 140px; max-width: none; }
}

/* ============ Cards / grid ============ */
.grid { display: grid; gap: 20px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3-1 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .g-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .g-3-1, .g-2 { grid-template-columns: 1fr; } }
@media (max-width: 520px) { .g-4 { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card h3 { font-size: 15px; font-weight: 650; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.card-head { display: flex; justify-content: space-between; align-items: start; gap: 10px; margin-bottom: 14px; }

.kpi .label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 30px; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.kpi .delta { font-size: 12px; margin-top: 4px; color: var(--muted); }
.kpi .delta.up { color: var(--good); }

.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 360px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--text-2); padding: 10px 10px; border-bottom: 1px solid var(--axis); white-space: nowrap; cursor: pointer; user-select: none; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th .arrow { color: var(--accent); }
td { padding: 10px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
td .title { font-weight: 600; color: var(--text); }
td .meta { color: var(--muted); font-size: 12px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; color: var(--text-2); font-size: 13px; gap: 8px; flex-wrap: wrap; }
.pager .btns { display: flex; gap: 6px; }

.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.pill.open { background: var(--good-bg); color: var(--good); }
.pill.soon { background: var(--warn-bg); color: var(--warn-ink); }
.pill.won { background: var(--accent-soft); color: var(--accent); }
.pill.pre { background: var(--surface-2); color: var(--text-2); }
.pill.eu { background: var(--surface-2); color: var(--text-2); }

/* lijstjes */
.list { display: grid; }
.list .row { display: flex; gap: 12px; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--grid); cursor: pointer; }
.list .row:last-child { border-bottom: 0; }
.list .row:hover .title { color: var(--accent); }
.list .title { font-weight: 600; }
.list .right { text-align: right; flex: none; }

.bar-list { display: grid; gap: 10px; }
.bar-item { display: grid; gap: 4px; cursor: pointer; }
.bar-item .top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.bar-item .top b { font-weight: 600; }
.bar-item .track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-item .fill { height: 100%; background: var(--s1); border-radius: 4px; }
.bar-item:hover .top b { color: var(--accent); }

/* heatmap tabel diensten */
td.heat { text-align: right; font-variant-numeric: tabular-nums; }

/* ============ Drawer ============ */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 60; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: var(--surface); z-index: 70; box-shadow: -8px 0 24px rgba(0,0,0,.15); overflow-y: auto; padding: 24px; display: grid; gap: 18px; align-content: start; }
.drawer h2 { font-size: 20px; }
.drawer dl { display: grid; grid-template-columns: 170px 1fr; gap: 8px 14px; margin: 0; }
.drawer dt { color: var(--muted); }
.drawer dd { margin: 0; font-weight: 500; }
.drawer .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.drawer-close { position: absolute; top: 14px; right: 14px; }
.timeline { display: grid; gap: 8px; border-left: 2px solid var(--grid); padding-left: 14px; }
.timeline div { position: relative; }
.timeline div::before { content: ""; position: absolute; left: -20px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
@media (max-width: 520px) { .drawer dl { grid-template-columns: 1fr; } .drawer dt { margin-top: 6px; } }

/* ============ Map ============ */
#map { height: 520px; border-radius: 10px; z-index: 1; }
.leaflet-container { background: var(--surface-2); font: inherit; }

/* ============ Misc ============ */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; z-index: 90; font-weight: 500; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.profile { display: grid; gap: 6px; padding: 14px; border: 1px solid var(--border); border-radius: 10px; }
.profile .tags { display: flex; gap: 6px; flex-wrap: wrap; }
.profile-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
/* bedrijfsprofiel, matchscore, inschrijf-assistent */
.pill.crit { background: color-mix(in oklab, var(--crit) 16%, transparent); color: var(--crit); }
.cta-note { padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); color: var(--text); font-size: 13px; }
.cta-note.warn { background: var(--warn-bg); color: var(--warn-ink); }
.cta-note.warn a { color: inherit; font-weight: 600; }
.form-card { display: grid; gap: 14px; align-content: start; }
.form-card h3 { margin-top: 4px; }
.form-card label:not(.cb) { display: grid; gap: 6px; font-weight: 500; }
.form-card label small { font-weight: 400; }
.form-card input:not([type=checkbox]), .form-card select, .form-card textarea { width: 100%; }
textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; resize: vertical; min-width: 0; }
input[type=number] { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.cb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 14px; }
.cb-grid.wide { max-height: 320px; overflow-y: auto; padding-right: 4px; }
.cb { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--text-2); cursor: pointer; }
.cb input { margin-top: 2px; }
.profile-meter { display: grid; gap: 6px; min-width: 180px; font-size: 13px; color: var(--text-2); }
.profile-meter .track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.profile-meter .fill { height: 100%; background: var(--s3); border-radius: 4px; }
.write-btn { white-space: nowrap; }
.schrijf { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr); gap: 20px; align-items: start; }
@media (max-width: 1100px) { .schrijf { grid-template-columns: 1fr; } }
.schrijf-links, .schrijf-rechts { display: grid; gap: 20px; min-width: 0; }
.tender-titel { font-size: 17px; margin: 4px 0; text-wrap: balance; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.mini-dl { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0 0 12px; font-size: 13px; }
.mini-dl dt { color: var(--muted); }
.mini-dl dd { margin: 0; }
details.oms { margin-bottom: 10px; font-size: 13px; }
details.oms summary { cursor: pointer; font-weight: 600; color: var(--text-2); }
details.oms p { color: var(--text-2); white-space: pre-line; }
ul.why { margin: 8px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 13px; }
ul.why li::before { display: inline-block; width: 18px; font-weight: 700; }
ul.why li.plus::before { content: "+"; color: var(--good); }
ul.why li.min::before { content: "–"; color: var(--crit); }
.big-pill { font-size: 13px; padding: 5px 12px; }
.advies-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 20px; }
.advies-grid h4 { margin: 10px 0 4px; font-size: 13px; }
.advies-grid ul { margin: 0; padding-left: 18px; font-size: 13px; color: var(--text-2); display: grid; gap: 4px; }
.concept .btns { display: flex; gap: 6px; }
.md-out { font-size: 14px; line-height: 1.6; max-width: 75ch; }
.md-out h3 { font-size: 16px; margin: 18px 0 6px; }
.md-out h3:first-child { margin-top: 0; }
.md-out h4 { font-size: 14px; margin: 14px 0 4px; }
.md-out p { margin: 0 0 10px; }
.md-out ul, .md-out ol { margin: 0 0 10px; padding-left: 22px; }
mark.fill-in { background: var(--warn-bg); color: var(--warn-ink); padding: 0 3px; border-radius: 3px; }
.thinking { color: var(--text-2); padding: 20px 0; }
.thinking::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-right: 10px; animation: puls 1.2s ease-in-out infinite; }
@keyframes puls { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .thinking::before { animation: none; } }

/* zoeklijst bedrijven */
.ac-field { position: relative; flex: 1; min-width: 0; }
.ac-field input { width: 100%; }
.ac-list { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-height: 320px; overflow-y: auto; }
.ac-list li { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 400; }
.ac-list li span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.ac-list li small { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.ac-list li b { font-weight: 700; color: var(--accent); }
.ac-list li.actief, .ac-list li[data-i]:hover { background: var(--surface-2); }
.ac-list li.ac-leeg { color: var(--muted); cursor: default; }

/* tenderwinnaars: eigen slagingspercentage */
.mijn-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 12px; }
.mijn-stats > div { display: grid; gap: 2px; padding: 12px; border-radius: 10px; background: var(--surface-2); }
.mijn-stats b { font-size: 24px; font-variant-numeric: tabular-nums; }
.mijn-stats b.ok { color: var(--good); }
.mijn-stats b.nok { color: var(--crit); }
.mijn-stats span { font-size: 12px; color: var(--text-2); }
#mijnCard .list { margin-top: 4px; }

/* concurrentievergelijking */
.cmp-slots { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .cmp-slots { grid-template-columns: 1fr; } }
.cmp-slot { display: grid; gap: 6px; min-width: 0; }
.cmp-role { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.cmp-input { display: flex; gap: 4px; align-items: center; }
.cmp-input input { flex: 1; min-width: 0; padding: 9px 12px; }
.cmp-slot .meta { color: var(--muted); font-size: 12px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; flex: none; vertical-align: baseline; }
table.cmp th { cursor: default; }
table.cmp td.lbl { color: var(--text-2); white-space: nowrap; }
table.cmp td.best { font-weight: 700; }
table.cmp tbody tr { cursor: default; }
table#gedeeld tbody tr { cursor: pointer; }
.who { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; white-space: nowrap; }
.new-prof { display: grid; gap: 12px; }
.new-prof .sub .pill { margin-left: 4px; }
.new-prof-row { display: flex; gap: 8px; flex-wrap: wrap; }
.new-prof-row input { flex: 1 1 240px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 9px; width: fit-content; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer; font: inherit; color: var(--text-2); }
.tabs button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.select-company { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.select-company select { min-width: 260px; }
