:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --input-bg: #ffffff;
  --th-bg: #f9fafb;
  --ink: #1a1d21;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #0f62fe;
  --ok: #198038;
  --ok-bg: #defbe6;
  --warn: #b28600;
  --warn-bg: #fdf2c8;
  --danger: #da1e28;
  --danger-bg: #ffd7d9;
  --grey-bg: #e5e7eb;
  --overlay: rgba(15,23,42,0.45);
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --panel: #1a1d24;
  --input-bg: #20242c;
  --th-bg: #20242c;
  --ink: #e7e9ee;
  --muted: #9aa3b2;
  --line: #2a2e38;
  --brand: #4c8dff;
  --ok: #4ade80;
  --ok-bg: #163a26;
  --warn: #eab308;
  --warn-bg: #3a2f0e;
  --danger: #f87171;
  --danger-bg: #3a1418;
  --grey-bg: #2a2e38;
  --overlay: rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  background: #0b1220;
  color: #fff;
  padding: 0 20px;
  height: 54px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand span { color: #9db1d6; font-weight: 400; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.topbar nav a {
  color: #cbd5e1; text-decoration: none; padding: 6px 12px; border-radius: 6px; font-size: 13.5px;
}
.topbar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.topbar nav a.active { background: var(--brand); color: #fff; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.periodeselect select {
  background: #1a2742; color: #e6edf7; border: 1px solid #33415e; border-radius: 7px;
  padding: 6px 10px; font-size: 13px; cursor: pointer;
}
.periodeselect-mobile { display: none; }

.theme-toggle {
  background: rgba(255,255,255,.08); border: 1px solid #33415e; border-radius: 7px;
  width: 34px; height: 34px; cursor: pointer; font-size: 15px; line-height: 1;
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.theme-toggle .icon-dark { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-light { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-dark { display: inline; }

.hamburger {
  display: none; flex-direction: column; justify-content: center; gap: 4px;
  width: 30px; height: 30px; background: none; border: none; cursor: pointer; padding: 0; flex: 0 0 auto;
}
.hamburger span { display: block; width: 22px; height: 2px; background: #fff; border-radius: 2px; }

main { max-width: 1180px; margin: 24px auto; padding: 0 20px; }

h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 24px 0 10px; }
h3 { font-size: 14px; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
a { color: var(--brand); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; margin-bottom: 16px; }

/* KPI-kaarten */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 2px; }
.kpi .sub { color: var(--muted); font-size: 12px; }
a.kpi { display: block; text-decoration: none; color: inherit; cursor: pointer; }
a.kpi:hover { border-color: var(--brand); }
a.kpi:hover .label { color: var(--brand); }

/* badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-open { background: var(--danger-bg); color: var(--danger); }
.badge-gekoppeld { background: var(--ok-bg); color: var(--ok); }
.badge-betaald { background: var(--ok-bg); color: var(--ok); }
.badge-verstuurd { background: var(--warn-bg); color: var(--warn); }
.badge-prive, .badge-genegeerd { background: var(--grey-bg); color: var(--muted); }
.badge-opgelost { background: var(--ok-bg); color: var(--ok); }

/* tabellen */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--th-bg); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
.num { text-align: right; white-space: nowrap; }
.pos { color: var(--ok); font-weight: 600; }
.neg { color: var(--danger); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* sorteerbare kolom-titels */
th a.sort { color: inherit; text-decoration: none; cursor: pointer; white-space: nowrap; }
th a.sort:hover { color: var(--brand); text-decoration: underline; }

/* formulieren */
form.inline { display: inline; }
label { display: block; font-weight: 600; margin: 10px 0 3px; font-size: 13px; }
input[type=text], input[type=date], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 14px;
  font-family: inherit; background: var(--input-bg); color: var(--ink);
}
textarea { min-height: 70px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-row .full { grid-column: 1 / -1; }

.btn {
  display: inline-block; padding: 8px 16px; border-radius: 7px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; background: var(--brand); color: #fff;
}
.btn:hover { opacity: .92; }
.btn.secondary { background: var(--panel); border-color: var(--line); color: var(--ink); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn.danger { background: var(--danger); }
.btn.grey { background: #4b5563; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; }
.spacer { flex: 1; }

.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 600; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-error { background: var(--danger-bg); color: var(--danger); }

/* status-banner (koppel-status op bewerkpagina) */
.status-banner { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.status-banner.green { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); }
.status-banner.amber { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.status-banner.red { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.status-banner ul.clean { margin: 6px 0 0; }
.status-banner ul.clean li { padding: 4px 0; }
.status-banner a { color: inherit; font-weight: 600; }

label.inline-check { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
label.inline-check input[type=checkbox] { width: auto; }

.gapbox { border-left: 4px solid var(--warn); background: var(--warn-bg); }
ul.clean { list-style: none; padding: 0; margin: 0; }
ul.clean li { padding: 10px 0; border-bottom: 1px solid var(--line); }
ul.clean li:last-child { border-bottom: none; }

/* Inkoopbewijs-preview (afbeelding / PDF inline op bewerkpagina) */
.bon-preview { display: block; max-width: 100%; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.bon-preview.pdf { width: 100%; height: 70vh; }

/* Upload-progress overlay (inkoop-upload) */
.spinner { width: 32px; height: 32px; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: mcspin 0.8s linear infinite; margin: 0 auto 12px; }
@keyframes mcspin { to { transform: rotate(360deg); } }
#upload-progress { position: fixed; inset: 0; background: var(--overlay); z-index: 9999; display: none; align-items: center; justify-content: center; }
#upload-progress .box { background: var(--panel); padding: 24px 34px; border-radius: 10px; text-align: center; }

/* ---------------- mobiel (<= 860px) ---------------- */
@media (max-width: 860px) {
  .hamburger { display: flex; }
  .periodeselect-desktop { display: none; }
  .periodeselect-mobile { display: block; margin-top: 10px; }
  .periodeselect-mobile select { width: 100%; }

  .topbar { flex-wrap: wrap; height: auto; min-height: 54px; padding: 10px 14px; gap: 12px; }
  .brand { font-size: 15px; margin-right: auto; }

  .topbar nav {
    display: none; flex-direction: column; align-items: stretch; width: 100%;
    gap: 2px; order: 10;
  }
  .topbar nav.open { display: flex; }
  .topbar nav a { padding: 10px 12px; border-radius: 6px; }

  .topbar-right { margin-left: 0; order: 2; }

  main { margin: 16px auto; padding: 0 12px; }

  .form-row { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  th, td { padding: 8px 10px; font-size: 13px; }
  h1 { font-size: 19px; }
}

/* rol-badge + uitloggen in de topbar */
.rol-badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.rol-eigenaar { background: rgba(255,255,255,.14); color: #cbd5e1; }
.rol-boekhouder { background: rgba(234,179,8,.18); color: #fbbf24; }
.rol-logout { color: #9db1d6; text-decoration: none; font-size: 12.5px; white-space: nowrap; }
.rol-logout:hover { color: #fff; }
