:root {
  --color-primary: #4f7a52;
  --color-primary-dark: #3c5f3f;
  --color-primary-soft: #e8f0e8;
  --color-accent: #c9844a;
  --color-accent-soft: #f6efe6;
  --color-bg: #f7f6f2;
  --color-surface: #ffffff;
  --color-surface-alt: #f1efe9;
  --color-border: #e0ddd4;
  --color-text: #2c2b27;
  --color-text-muted: #6f6c64;
  --color-text-inverse: #ffffff;
  --color-status-open: #c48a2a;
  --color-status-ok: #3f7d4e;
  --color-status-idle: #8a877e;
  --color-status-error: #a33b32;
  --color-status-running: #2f6294;
  --color-tag-a-bg: #e8f0e8;
  --color-tag-a-fg: #3c5f3f;
  --color-tag-b-bg: #f6efe6;
  --color-tag-b-fg: #8a5a2a;
  --font-xs: 0.72rem;
  --font-sm: 0.82rem;
  --font-md: 0.92rem;
  --font-lg: 1.1rem;
  --font-xl: 1.4rem;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius-1: 4px;
  --radius-2: 8px;
  --radius-3: 14px;
  --shadow-sm: 0 1px 2px rgba(44, 43, 39, 0.06);
  --shadow-md: 0 8px 24px rgba(44, 43, 39, 0.16);
  --topbar-h: 52px;
  --toolbar-h: 52px;
  --sidebar-w: 210px;
  --detail-w: 360px;
  --z-sticky: 100;
  --z-scrim: 750;
  --z-drawer: 800;
  --z-menu: 900;
  --z-overlay: 1000;
  --z-toast: 1100;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: var(--font-md);
  line-height: 1.45;
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--color-primary); }
a:hover { color: var(--color-primary-hover, var(--color-primary)); }

.shell {
  height: 100vh;
  overflow: hidden;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) var(--toolbar-h) minmax(0, 1fr);
  grid-template-areas:
    "brand topbar"
    "brand toolbar"
    "sidebar main";
}

.brand {
  grid-area: brand;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-1);
  padding: 0 var(--space-4);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}

.brand strong { font-size: var(--font-lg); }
.brand span, .topbar-brand span { color: var(--color-text-muted); font-size: var(--font-xs); }

.topbar, .toolbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  min-width: 0;
}

.toolbar { grid-area: toolbar; min-width: 0; }

.toolbar-inner {
  height: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  overflow-x: auto;
}

.module {
  margin: 0;
  font-size: var(--font-md);
  font-weight: 600;
  white-space: nowrap;
}

.spacer { flex: 1; }

.topbar-brand { display: none; flex-direction: column; min-width: 0; }
.topbar-brand strong { font-size: var(--font-sm); }

.btn.menu-btn { display: none; }

.context-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-3);
  background: var(--color-surface-alt);
  color: var(--color-text-muted);
  font-size: var(--font-xs);
  text-decoration: none;
  white-space: nowrap;
}

.context-badge strong { color: var(--color-text); font-weight: 600; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--color-status-ok);
  flex: none;
}

.sidebar {
  grid-area: sidebar;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow: auto;
  padding: var(--space-2) 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: var(--space-2) var(--space-4);
  color: var(--color-text);
  text-decoration: none;
  font-size: var(--font-sm);
}

.nav-link svg { flex: none; }
.nav-link:hover { background: var(--color-surface-alt); }

.nav-link.is-active {
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  font-weight: 600;
}

.nav-groep-kop {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: var(--space-2) var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--font-sm);
  font-weight: 600;
}

.nav-groep.is-open .nav-groep-kop { color: var(--color-text); }
.nav-sub { padding-left: calc(var(--space-4) + 18px + var(--space-2)); }

.main {
  grid-area: main;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: var(--space-4);
}

.page-fill {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.scrim {
  position: fixed;
  top: calc(var(--topbar-h) + var(--toolbar-h));
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: var(--z-scrim);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-1);
  border: 1px solid transparent;
  background: transparent;
  font-size: var(--font-sm);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: var(--color-text-inverse); }
.btn-primary:hover:not(:disabled) { background: var(--color-primary-dark); }
.btn-secondary, .btn-ghost { color: var(--color-text); }
.btn-secondary { background: var(--color-surface); border-color: var(--color-border); }
.btn-secondary:hover:not(:disabled) { background: var(--color-surface-alt); }
.btn-danger { background: var(--color-status-error); color: var(--color-text-inverse); }
.btn-ghost:hover:not(:disabled) { background: var(--color-surface-alt); }
.icon-btn { width: 36px; padding: 0; }

.field { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.field label, .check-row { font-size: var(--font-sm); }
.field input, .field select, .field textarea, .inline-input {
  min-height: 36px;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-1);
  background: var(--color-surface);
}
.field textarea { min-height: 72px; resize: vertical; }
.hint { margin: 0; color: var(--color-text-muted); font-size: var(--font-sm); }
.check-row { display: flex; align-items: center; gap: var(--space-2); min-height: 36px; }
.input-narrow { width: 6em; }

.filters { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: end; }
.filters .field-grow { flex: 1 1 220px; }
.stats { margin: 0; color: var(--color-text-muted); font-size: var(--font-sm); }

.view-toggle { display: inline-flex; border: 1px solid var(--color-border); border-radius: var(--radius-1); overflow: hidden; }
.view-toggle button {
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 0;
  background: var(--color-surface);
  cursor: pointer;
  font-size: var(--font-sm);
}
.view-toggle button.is-active { background: var(--color-primary); color: var(--color-text-inverse); }

.list-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-sm);
}

.list-body { flex: 1; min-height: 0; overflow: auto; }

.list-footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface-alt);
  border-top: 1px solid var(--color-border);
  font-size: var(--font-sm);
  color: var(--color-text-muted);
}

.list-footer .pager { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--font-sm); }
.data-table th, .data-table td {
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: middle;
}
.data-table th {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--color-surface-alt);
  font-weight: 600;
}
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .check { width: 40px; text-align: center; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: var(--color-surface-alt); }
.data-table tbody tr.is-selected { background: var(--color-primary-soft); }
.data-table tbody tr.is-selected:hover { background: var(--color-primary-soft); }
.nowrap { white-space: nowrap; }
.clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.is-neg { color: var(--color-status-error); }
.group-row td { font-weight: 600; background: var(--color-surface-alt); }
.child-row td:first-child { padding-left: var(--space-5); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-3);
  padding: var(--space-3);
}
.card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2);
  background: var(--color-surface);
  cursor: pointer;
  text-align: left;
}
.card:hover { background: var(--color-surface-alt); }
.card.is-selected { outline: 2px solid var(--color-primary); background: var(--color-primary-soft); }
.card h3 { margin: 0; font-size: var(--font-md); }
.card p { margin: 0; color: var(--color-text-muted); font-size: var(--font-sm); }
.card-foot { display: flex; justify-content: space-between; gap: var(--space-2); align-items: center; }

.master { flex: 1; min-height: 0; display: flex; gap: var(--space-3); }
.master .list-panel { flex: 1; }

.detail {
  width: var(--detail-w);
  flex: none;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-sm);
}
.detail-header, .detail-footer, .modal-header, .modal-footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.detail-header h2, .modal-header h2 { margin: 0; font-size: var(--font-md); flex: 1; min-width: 0; }
.detail-footer, .modal-footer { border-bottom: 0; border-top: 1px solid var(--color-border); justify-content: flex-end; }
.detail-body, .modal-body { flex: 1; min-height: 0; overflow: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-4); }
.detail[hidden] { display: none; }

.dl { display: grid; grid-template-columns: 120px 1fr; gap: var(--space-2) var(--space-3); margin: 0; font-size: var(--font-sm); }
.dl dt { color: var(--color-text-muted); }
.dl dd { margin: 0; overflow-wrap: anywhere; }

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-3);
  font-size: var(--font-xs);
  background: var(--color-tag-a-bg);
  color: var(--color-tag-a-fg);
}
.tag-b { background: var(--color-tag-b-bg); color: var(--color-tag-b-fg); }
.tag-idle { background: var(--color-surface-alt); color: var(--color-text-muted); }
.tag-ok { background: var(--color-primary-soft); color: var(--color-status-ok); }
.tag-error { background: var(--color-surface-alt); color: var(--color-status-error); }
.muted { color: var(--color-text-muted); }
.small { font-size: var(--font-xs); }
.pre-wrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.data-table .inline-input { width: 100%; min-width: 120px; }
.data-table .inline-input.num { text-align: right; }
.tags { display: inline-flex; flex-wrap: wrap; gap: var(--space-1); }
.detail-section { display: flex; flex-direction: column; gap: var(--space-2); }
.detail-section h3 { margin: 0; font-size: var(--font-sm); font-weight: 600; color: var(--color-text-muted); }
.detail-amount { font-size: var(--font-xl); font-weight: 600; font-variant-numeric: tabular-nums; }
.raw { margin: 0; padding: var(--space-2); background: var(--color-surface-alt); border-radius: var(--radius-1); font-size: var(--font-xs); white-space: pre-wrap; overflow-wrap: anywhere; }
.form-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }
.sub { display: block; color: var(--color-text-muted); font-size: var(--font-xs); font-weight: 400; }
.group-row .chevron, .staat .chevron { display: inline-flex; vertical-align: middle; margin-right: var(--space-1); color: var(--color-text-muted); }
.data-table tfoot td { position: sticky; bottom: 0; background: var(--color-surface-alt); font-weight: 600; border-top: 1px solid var(--color-border); }
.page-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 100%;
}
.page-stack .list-panel { flex: none; min-height: 0; overflow: visible; }
.page-stack .list-body { flex: none; overflow: visible; }
.sectiekop { margin: 0; font-size: var(--font-md); font-weight: 600; }
.staten { display: flex; flex-direction: column; gap: var(--space-3); }
.staat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.staat-kop { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-3) var(--space-3) var(--space-2); }
.staat-kop h2 { margin: 0; font-size: var(--font-md); font-weight: 600; }
.staat .data-table th { position: static; }
.eindverdeling .data-table th { font-size: var(--font-xs); }
.staat-regel td:first-child { font-weight: 600; }
.staat tr.memo td:first-child { color: var(--color-text-muted); font-weight: 400; }
.staat-detail > td { padding: var(--space-2) var(--space-3) var(--space-3); background: var(--color-surface-alt); }
.detail-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-1); background: var(--color-surface); }
.detail-wrap .data-table th { font-size: var(--font-xs); }
.child-row-2 td:first-child { padding-left: calc(var(--space-5) + var(--space-4)); }
.meldingen {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2);
  font-size: var(--font-sm);
}
.meldingen p { margin: 0; }
.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-3); }
.summary .card { color: inherit; text-decoration: none; cursor: default; }
.summary a.card { cursor: pointer; }
.summary .card:not(a):hover { background: var(--color-surface); }
.summary .card h3 { font-size: var(--font-sm); color: var(--color-text-muted); font-weight: 600; }
.data-table tr.muted td { color: var(--color-text-muted); }
.data-table tr.total-row td { font-weight: 600; border-top: 2px solid var(--color-border); }
.data-table tbody tr.no-hover { cursor: default; }
.data-table tbody tr.no-hover:hover { background: transparent; }

.menu-panel {
  position: fixed;
  z-index: var(--z-menu);
  min-width: 200px;
  padding: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-md);
}
.menu-panel button {
  display: block;
  width: 100%;
  min-height: 36px;
  padding: 0 var(--space-3);
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font-size: var(--font-sm);
  border-radius: var(--radius-1);
}
.menu-panel button:hover { background: var(--color-surface-alt); }
.menu-meta { display: flex; flex-direction: column; padding: var(--space-2) var(--space-3); margin-bottom: var(--space-1); border-bottom: 1px solid var(--color-border); font-size: var(--font-sm); }
.menu-meta span { color: var(--color-text-muted); font-size: var(--font-xs); }

.user-btn { gap: var(--space-2); padding: 0 var(--space-2); }
.avatar {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  font-size: var(--font-xs);
  font-weight: 600;
}
.user-naam { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.input-row { display: flex; gap: var(--space-2); }
.input-row input { flex: 1; min-width: 0; }
.footer-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); width: 100%; }
.clip.wide { max-width: 640px; }

.auth-body { display: grid; place-items: center; min-height: 100vh; padding: var(--space-4); }
.auth-card {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-sm);
}
.auth-card h1 { margin: 0; font-size: var(--font-lg); }
.auth-brand { display: flex; flex-direction: column; }
.auth-brand span { color: var(--color-text-muted); font-size: var(--font-xs); }
.auth-actions { display: flex; justify-content: flex-end; }
.auth-actions .btn { width: 100%; }
.auth-link { align-self: center; }
.auth-extra { margin: 0; text-align: center; }
.auth-extra a { color: var(--color-primary-dark); }

.empty {
  margin: auto;
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-muted);
}

.form-grid { display: flex; flex-direction: column; gap: var(--space-3); }
.alert {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-status-error);
  border-radius: var(--radius-1);
  color: var(--color-status-error);
  background: var(--color-surface);
  font-size: var(--font-sm);
}
.notice {
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-status-open);
  border-left-width: 4px;
  border-radius: var(--radius-1);
  background: var(--color-surface);
  font-size: var(--font-sm);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: rgba(0, 0, 0, 0.45);
}
.overlay[hidden] { display: none; }

.modal {
  display: flex;
  flex-direction: column;
  width: min(640px, 100%);
  max-height: min(92vh, 100%);
  background: var(--color-surface);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-md);
}
.modal-sm { width: min(420px, 100%); }
.modal-lg { width: min(920px, 100%); }
.modal-body pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: var(--font-xs);
}

.blocking {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
}
.blocking[hidden] { display: none; }
.blocking-chrome {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: var(--space-3);
  background: rgba(0, 0, 0, 0.45);
  color: var(--color-text-inverse);
}
.blocking.is-visible .blocking-chrome { display: flex; }
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: var(--color-text-inverse);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toasts {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(360px, calc(100% - var(--space-6)));
}
.toast {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-status-running);
  border-radius: var(--radius-1);
  box-shadow: var(--shadow-md);
  font-size: var(--font-sm);
}
.toast-success { border-left-color: var(--color-status-ok); }
.toast-error { border-left-color: var(--color-status-error); }
.toast p { margin: 0; flex: 1; }

.detail-scrim { display: none; }

@media (max-width: 1023px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "topbar"
      "toolbar"
      "main";
  }
  .brand { display: none; }
  .btn.menu-btn { display: inline-flex; }
  .topbar-brand { display: flex; }
  .module { display: none; }
  .sidebar {
    position: fixed;
    top: calc(var(--topbar-h) + var(--toolbar-h));
    bottom: 0;
    left: 0;
    width: var(--sidebar-w);
    z-index: var(--z-drawer);
    transform: translateX(-100%);
  }
  .sidebar.is-open { transform: translateX(0); }
  .detail-scrim:not([hidden]) {
    display: block;
    position: fixed;
    top: calc(var(--topbar-h) + var(--toolbar-h));
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: var(--z-scrim);
  }
  .detail {
    position: fixed;
    top: calc(var(--topbar-h) + var(--toolbar-h));
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    z-index: var(--z-drawer);
    border-radius: 0;
  }
}

@media (max-width: 767px) {
  .overlay { padding: 0; }
  .modal { width: 100%; height: 100%; max-height: none; border-radius: 0; }
  .user-naam { display: none; }
}
