:root {
  --green: #1f5f3f;
  --green-dark: #174a31;
  --green-light: #e7f2ec;
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1d2420;
  --muted: #66706a;
  --border: #e0e4e1;
  --input-border: #c6ccc8;
  --danger: #b3261e;
  --danger-bg: #fbe9e7;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --info: #1d4f91;
  --info-bg: #e8f0fb;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 1px 1px rgba(20, 40, 30, .03);
  --sidebar: 236px;
  --tabbar: 62px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--green); }
h1 { font-size: 1.55rem; margin: .2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: .75rem 0 .5rem; }
hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }

.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 8px; border: none; background: none; color: inherit; padding: 0; cursor: pointer; }
.icon-button:hover { background: rgba(255, 255, 255, .12); }

/* ---------- layout: sidebar (desktop) ---------- */
body.with-nav { padding-left: var(--sidebar); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); display: flex; flex-direction: column; gap: .75rem;
  background: var(--green); color: #fff; padding: 1rem .75rem; overflow-y: auto; z-index: 30; }
.sidebar a { color: #fff; text-decoration: none; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 .4rem; }
.brand { font-weight: 700; font-size: 1.05rem; line-height: 1.15; }
.brand small { display: block; font-weight: 400; opacity: .75; font-size: .8rem; }
.close-menu { display: none; }
.org-switch { display: flex; flex-direction: column; gap: .25rem; padding: 0 .4rem; }
.org-switch label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; opacity: .7; }
.org-switch select { width: 100%; padding: .4rem .5rem; border-radius: 8px; border: 1px solid rgba(255, 255, 255, .25); background: rgba(255, 255, 255, .1); color: #fff; font-size: .9rem; }
.org-switch select option { color: var(--text); }
.org-name { font-weight: 600; }
.sidebar a.sidebar-cta { display: flex; align-items: center; justify-content: center; gap: .4rem; background: #fff; color: var(--green); border-color: #fff; font-weight: 600; margin: 0 .25rem; }
.sidebar a.sidebar-cta:hover { background: var(--green-light); }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav a { display: flex; align-items: center; gap: .65rem; padding: .5rem .65rem; border-radius: 8px; opacity: .88; }
.side-nav a:hover { background: rgba(255, 255, 255, .1); opacity: 1; }
.side-nav a.active { background: rgba(255, 255, 255, .18); opacity: 1; font-weight: 600; }
.nav-section { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; opacity: .6; padding: .9rem .65rem .25rem; }
.sidebar-user { display: flex; align-items: center; justify-content: space-between; gap: .5rem; border-top: 1px solid rgba(255, 255, 255, .18); padding: .75rem .4rem 0; font-size: .9rem; }
.sidebar-user small { display: block; opacity: .75; }
.sidebar-user form { margin: 0; }

.mobilebar, .tabbar, .backdrop { display: none; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.25rem 1.5rem 3rem; }
body.no-nav .container { padding-top: 3rem; }

/* ---------- building blocks ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.25rem; margin-bottom: 1rem; overflow-x: auto; }
.card.narrow { max-width: 640px; }
.center { margin-left: auto; margin-right: auto; text-align: center; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); gap: 1rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .5rem; margin-bottom: .25rem; }
.row-between h1 { margin-bottom: .6rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.total td { font-weight: 700; border-top: 2px solid var(--border); }
table.kv th { width: 45%; text-transform: none; letter-spacing: 0; font-size: .88rem; }
.row-danger { background: var(--danger-bg); }
.row-warning { background: var(--warn-bg); }
.money { font-variant-numeric: tabular-nums; }
.money.neg { color: var(--danger); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.tile { display: flex; flex-direction: column; gap: .15rem; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: .85rem 1rem; text-decoration: none; color: var(--text); }
a.tile:hover { border-color: var(--green); }
.tile strong { font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: .88rem; }
.tile.attention { border-color: var(--green); background: var(--green-light); }
.tile.warning { border-color: var(--warn); background: var(--warn-bg); }
.tiles > .tile:last-child:nth-child(odd) { grid-column: auto; }

.flash { padding: .65rem .9rem; border-radius: 8px; margin-bottom: .75rem; border: 1px solid transparent; }
.flash-success { background: var(--green-light); border-color: #b8dcc6; }
.flash-error { background: var(--danger-bg); border-color: #f0b8b2; }
.flash-warning { background: var(--warn-bg); border-color: #f0d894; }
.flash-info { background: var(--info-bg); border-color: #bcd0ef; }

.badge { display: inline-block; padding: .08rem .55rem; border-radius: 999px; font-size: .76rem; font-weight: 600; background: #eceeed; color: var(--text); vertical-align: middle; white-space: nowrap; }
.badge-ingediend, .badge-open, .badge-onverwerkt { background: var(--warn-bg); color: var(--warn); }
.badge-goedgekeurd, .badge-in_batch { background: var(--info-bg); color: var(--info); }
.badge-uitbetaald, .badge-betaald, .badge-verwerkt { background: var(--green-light); color: var(--green); }
.badge-afgewezen, .badge-geannuleerd { background: var(--danger-bg); color: var(--danger); }

/* ---------- forms ---------- */
form.inline { display: inline; }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin: .5rem 0; }
.inline-form label { display: flex; flex-direction: column; gap: .15rem; font-size: .85rem; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: .8rem; text-align: left; }
.stack label { display: flex; flex-direction: column; gap: .25rem; font-weight: 600; font-size: .9rem; }
.stack small { font-weight: normal; }
.stack input, .stack select, .stack textarea { font-weight: normal; }
label.check { flex-direction: row !important; align-items: center; gap: .4rem; font-weight: normal; }
input, select, textarea { font: inherit; padding: .45rem .55rem; border: 1px solid var(--input-border); border-radius: 8px; background: #fff; color: var(--text); max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31, 95, 63, .35); outline-offset: 0; border-color: var(--green); }
input[type="checkbox"] { width: auto; accent-color: var(--green); }
input[type="file"] { padding: .35rem; background: #fafbfa; }
.buttons { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .75rem; }

button, .button { font: inherit; display: inline-flex; align-items: center; gap: .35rem; padding: .45rem .95rem; border-radius: 8px; border: 1px solid var(--input-border); background: #fff; color: var(--text); cursor: pointer; text-decoration: none; line-height: 1.3; }
button:hover, .button:hover { background: #f0f2f1; }
button.primary, .button.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
button.primary:hover, .button.primary:hover { background: var(--green-dark); }
button.danger { border-color: var(--danger); color: var(--danger); }
button.link { border: none; background: none; padding: 0; color: var(--green); text-decoration: underline; }
button.small, a.small { font-size: .8rem; padding: .22rem .55rem; }
.button .icon, button .icon { width: 18px; height: 18px; }

.filters { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.filters a { padding: .25rem .75rem; border-radius: 999px; border: 1px solid var(--border); background: #fff; text-decoration: none; font-size: .88rem; white-space: nowrap; }
.filters a.active { background: var(--green); color: #fff; border-color: var(--green); }
.filters .sep { color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; }
.hidden { display: none !important; }
ul.plain { list-style: none; padding: 0; }
.payee-block { border-top: 1px solid var(--border); padding-top: .75rem; margin-top: .75rem; }
.receipt { margin-bottom: 1rem; }
.receipt img { max-width: 100%; max-height: 420px; border: 1px solid var(--border); border-radius: 8px; }
code { background: #eef1ef; padding: .1rem .35rem; border-radius: 4px; }
code.copy { cursor: copy; font-size: 1.05rem; word-break: break-all; }
code.copy.copied { background: var(--green-light); }
.suggestion { color: var(--warn); }
meter { width: 110px; vertical-align: middle; }

/* ---------- budget builder ---------- */
.budget-items input, .budget-items select, .budget-groups input { padding: .28rem .4rem; font-size: .85rem; }
.budget-items td { vertical-align: middle; }
.w-xs { width: 5.5rem; }
.w-sm { width: 10rem; }
.w-md { width: 13rem; }
.nowrap { white-space: nowrap; }
label.tiny { display: inline-flex; align-items: center; gap: .2rem; font-size: .78rem; font-weight: normal; margin-right: .35rem; }
tr.new-row td { background: #f7faf8; }
.row-ok { background: var(--green-light); }
.budget-items tr.item-main td { border-bottom: none; padding-bottom: .1rem; }
.budget-items tr.item-detail td { padding-top: .1rem; padding-bottom: .6rem; }
.field-group { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .15rem; margin-right: .6rem; font-size: .78rem; }
.savebar { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem; margin: .5rem 0 1rem; }
.savebar:first-of-type { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: .5rem 0; }
.dirty-indicator { color: var(--warn); font-weight: 600; font-size: .9rem; }
.flash-inline { color: var(--danger); font-size: .9rem; }
.danger-text { color: var(--danger); }

/* ---------- tablet ---------- */
@media (max-width: 1100px) and (min-width: 801px) {
  :root { --sidebar: 200px; }
  .container { padding: 1rem 1.1rem 3rem; }
}

/* ---------- mobile ---------- */
@media (max-width: 800px) {
  body.with-nav { padding-left: 0; padding-bottom: calc(var(--tabbar) + env(safe-area-inset-bottom)); }
  body { font-size: 16px; }
  input, select, textarea { font-size: 16px; }   /* prevents iOS from zooming into fields */
  .container { padding: .85rem .85rem 2rem; }
  h1 { font-size: 1.35rem; }

  .mobilebar { display: flex; align-items: center; gap: .6rem; position: sticky; top: 0; z-index: 20;
    background: var(--green); color: #fff; padding: .35rem .5rem .35rem .9rem; padding-top: max(.35rem, env(safe-area-inset-top)); }
  .mobilebar a { color: #fff; text-decoration: none; }
  .mobilebar .brand { font-size: 1rem; }
  .mobilebar-org { flex: 1; min-width: 0; opacity: .85; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

  /* sidebar becomes a drawer, opened via #menu (works without JavaScript) */
  .sidebar { width: min(300px, 86vw); transform: translateX(-105%); transition: transform .2s ease; box-shadow: 0 0 30px rgba(0, 0, 0, .25); z-index: 50; }
  .sidebar:target { transform: none; }
  .sidebar:target ~ .backdrop { display: block; position: fixed; inset: 0; background: rgba(10, 25, 18, .45); z-index: 40; }
  .close-menu { display: inline-flex; }
  .side-nav a { padding: .7rem .7rem; }

  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: calc(var(--tabbar) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); background: #fff; border-top: 1px solid var(--border); box-shadow: 0 -2px 10px rgba(0, 0, 0, .05); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .7rem; }
  .tabbar a.active { color: var(--green); font-weight: 600; }
  .tabbar .icon { width: 22px; height: 22px; }
  .tabbar .tab-cta .icon { width: 26px; height: 26px; color: #fff; background: var(--green); border-radius: 50%; padding: 6px; box-sizing: content-box; margin-top: -14px; box-shadow: 0 2px 8px rgba(31, 95, 63, .4); stroke-width: 2.4; }
  .tabbar .tab-cta { color: var(--green); font-weight: 600; }

  .card { padding: .85rem; border-radius: 12px; }
  .card.narrow { max-width: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: .5rem; }
  .tile { padding: .7rem .8rem; }
  .tile strong { font-size: 1.35rem; }
  .tiles > .tile:last-child:nth-child(odd) { grid-column: span 2; }
  .tile span { font-size: .8rem; }
  .hide-mobile { display: none !important; }   /* e.g. "+ Nieuwe declaratie": the tab bar has "Declareren" */

  .filters { flex-wrap: nowrap; overflow-x: auto; margin: 0 -.85rem .75rem; padding: 0 .85rem .2rem; scrollbar-width: none; }
  .filters::-webkit-scrollbar { display: none; }

  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form label { width: 100%; }
  .inline-form input, .inline-form select { width: 100%; }
  .stack input, .stack select, .stack textarea { width: 100%; }
  .buttons { flex-direction: column; align-items: stretch; }
  .buttons button, .buttons .button { justify-content: center; padding: .7rem 1rem; }
  .buttons > a:not(.button) { text-align: center; padding: .4rem; }
  .savebar button.primary { flex: 1; justify-content: center; padding: .65rem 1rem; }
  .savebar:first-of-type { top: 50px; }

  /* tables: every row becomes a small card (labels come from the header row, set by app.js) */
  table.stackable, table.stackable tbody, table.stackable tr, table.stackable td { display: block; width: 100%; }
  table.stackable tr.head-row { display: none; }
  table.stackable tr { padding: .55rem 0; border-bottom: 1px solid var(--border); }
  table.stackable tr:last-child { border-bottom: none; }
  table.stackable td { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; border: none; padding: .12rem 0; text-align: right; }
  table.stackable td.num { white-space: normal; }
  table.stackable td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .82rem; text-align: left; flex: none; max-width: 45%; }
  table.stackable td:first-child { font-weight: 600; text-align: left; justify-content: flex-start; }
  table.stackable td:first-child::before { display: none; }
  table.stackable td:empty { display: none; }
  table.stackable td[colspan] { text-align: left; justify-content: flex-start; }
  table.stackable tr.total { border-top: 2px solid var(--border); }
  table.stackable tr.total td { border-top: none; }
  table.stackable tr.row-danger, table.stackable tr.row-warning, table.stackable tr.row-ok { padding-left: .55rem; padding-right: .55rem; border-radius: 8px; }
  table.stackable td:first-child input { max-width: none; width: 100%; flex: 1 1 auto; }
  table.stackable .inline-form, table.stackable form.inline { display: inline-flex; flex-direction: row; gap: .35rem; margin: 0; }
  table.stackable td input:not([type="checkbox"]), table.stackable td select { min-width: 0; flex: 1 1 auto; max-width: 62%; width: auto; }
  table.kv th { width: 50%; }

  /* budget items: the detail row is part of the same card */
  .budget-items.stackable tr.item-main { padding-bottom: 0; border-bottom: none; }
  .budget-items.stackable tr.item-detail td { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem .6rem; text-align: left; font-weight: normal; }
  .budget-items.stackable .field-group { grid-column: 1 / -1; gap: .3rem .6rem; font-size: .85rem; margin: 0; }
  .budget-items.stackable label.tiny { display: flex; flex-direction: column; align-items: stretch; gap: .1rem; font-size: .8rem; color: var(--muted); margin: 0; }
  .budget-items.stackable label.check.tiny { flex-direction: row; align-items: center; justify-content: flex-start; gap: .35rem; color: var(--text); }
  .budget-items.stackable label.check.tiny.danger-text { color: var(--danger); }
  .budget-items.stackable label.check.tiny input { flex: none; margin: 0; }
  .budget-items.stackable label.tiny input:not([type="checkbox"]) { max-width: none; width: 100%; }
  .budget-items.stackable .field-group > label.tiny:not(.check) { width: 100%; }
  .budget-items.stackable label.tiny:has(input[name$="_note"]) { grid-column: 1 / -1; }
  .w-sm, .w-md { width: 100%; }

  meter { width: 80px; }
}
