:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface2: #faf8f3;
  --text: #1f1d1a;
  --text2: #77716a;
  --text3: #a8a199;
  --border: #e5dfd3;
  --border-strong: #cfc7b8;
  --green: #1f6b4a;
  --green-dark: #173f2f;
  --green-mid: #225a42;
  --green-pale: #e3efe8;
  --gold: #b8923a;
  --gold-text: #7d5f1c;
  --gold-pale: #f6ecd6;
  --red: #a63c3c;
  --red-pale: #f6e3e3;
  --blue: #2c5d8f;
  --blue-pale: #e3ecf6;
  --sans: 'DM Sans', system-ui, -apple-system, sans-serif;
  --mono: 'DM Mono', ui-monospace, monospace;
  --r: 8px;
  --shadow: 0 1px 2px rgba(31, 29, 26, 0.04), 0 4px 16px rgba(31, 29, 26, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.mono { font-family: var(--mono); }
.muted { color: var(--text2); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- Schil: zijmenu op desktop, balk op mobiel ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--green-dark); color: #dfe9e3;
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.logo { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; margin: 4px 8px 22px; }
.logo i { color: #d9b95a; font-size: 24px; }
.logo .word { font-weight: 600; font-size: 17px; line-height: 1.1; }
.logo .tag { display: block; font-size: 11px; color: #9fb5a9; font-weight: 400; }
.nav a { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: var(--r); color: #c9d8cf; text-decoration: none; }
.nav a i { font-size: 18px; }
.nav a.on { background: var(--green-mid); color: #fff; }
.nav a:hover { color: #fff; }
.sidebar .me { margin-top: auto; font-size: 12px; color: #9fb5a9; padding: 12px 12px 0; border-top: 1px solid #23503e; }
.sidebar .me b { display: block; color: #dfe9e3; font-weight: 500; }
.sidebar .actions { display: flex; gap: 6px; padding: 8px 12px 0; }
.sidebar .actions button { background: transparent; border: 1px solid #2f6a51; color: #c9d8cf; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.sidebar .actions button:hover { border-color: #6f9c86; color: #fff; }

main { flex: 1; min-width: 0; padding: 28px 36px 80px; max-width: 1140px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }

@media (max-width: 800px) {
  .shell { display: block; }
  .sidebar { width: auto; height: auto; position: sticky; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 4px; padding: 10px 12px; }
  .logo { margin: 0 8px 0 0; }
  .logo .tag { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { padding: 8px 10px; font-size: 13px; }
  .nav a span { display: none; }
  .sidebar .me { display: none; }
  .sidebar .actions { margin-left: auto; padding: 0; }
  main { padding: 14px 12px 80px; }
  .page-head h1 { font-size: 19px; }
}

/* ---------- Kaarten, knoppen, velden ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 14px;
}
.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.card h2 i { color: var(--green); font-size: 18px; }
.card h2 .by { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--text2); text-align: right; }
.card .intro { color: var(--text2); font-size: 13px; margin: -6px 0 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 14px;
  border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text); font-weight: 500;
}
.btn:hover { border-color: var(--text3); background: var(--surface2); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-mid); }
.btn.danger { color: var(--red); }
.btn.link { border: none; background: none; min-height: auto; padding: 4px 0; color: var(--green); font-weight: 500; }
.btn.link:hover { text-decoration: underline; background: none; }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: progress; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--text2); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=search], input[type=number], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 11px;
  border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface);
}
input:focus, select:focus, textarea:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px var(--green-pale); }
textarea { min-height: 96px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.grid4 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 14px; }
@media (min-width: 640px) { .grid4 { grid-template-columns: repeat(4, 1fr); } }
.field-error { color: var(--red); font-size: 13px; margin-top: 4px; }
.has-error input, .has-error select, .has-error textarea, .has-error .seg { border-color: var(--red); }
.inline-btn { display: flex; gap: 8px; align-items: flex-end; }
.inline-btn .field { flex: 1; margin-bottom: 14px; }
.inline-btn .btn { margin-bottom: 14px; white-space: nowrap; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  min-height: 40px; padding: 8px 12px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface);
}
.seg button:hover { border-color: var(--text3); }
.seg button[aria-pressed=true] { background: var(--text); border-color: var(--text); color: #fff; }
.seg button.bad[aria-pressed=true] { background: var(--red); border-color: var(--red); }
.seg button.good[aria-pressed=true] { background: var(--green); border-color: var(--green); }

.check-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.check-row:last-child { border-bottom: none; }
.check-row .label { flex: 1; }

/* ---------- Chips, meldingen ---------- */
.chip { display: inline-block; font-size: 12px; font-weight: 500; padding: 3px 9px; border-radius: 999px; background: var(--surface2); white-space: nowrap; border: 1px solid var(--border); }
.chip.registered { background: var(--blue-pale); color: var(--blue); border-color: transparent; }
.chip.received { background: var(--gold-pale); color: var(--gold-text); border-color: transparent; }
.chip.done { background: var(--green-pale); color: var(--green); border-color: transparent; }
.chip.cancelled { background: #eeebe4; color: var(--text2); border-color: transparent; }
.chip.admin { background: var(--gold-pale); color: var(--gold-text); border-color: transparent; }
.chip.cs, .chip.warehouse { background: var(--green-pale); color: var(--green); border-color: transparent; }

.av { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; background: var(--green-pale); color: var(--green); font-size: 11px; font-weight: 600; align-items: center; justify-content: center; margin-right: 6px; vertical-align: middle; }
.av.customer { background: #eeebe4; color: var(--text2); }

.alert { display: flex; gap: 8px; align-items: flex-start; padding: 10px 12px; border-radius: var(--r); margin-bottom: 8px; font-size: 14px; }
.alert i { font-size: 18px; line-height: 1.2; flex-shrink: 0; }
.alert.danger { background: var(--red-pale); color: var(--red); }
.alert.warning { background: var(--gold-pale); color: var(--gold-text); }
.alert.info { background: var(--blue-pale); color: var(--blue); }
.alert.success { background: var(--green-pale); color: var(--green); }

/* ---------- Overzicht ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 12px 14px; cursor: pointer; text-align: left; box-shadow: var(--shadow); font: inherit; color: inherit;
}
.tile:hover { border-color: var(--border-strong); }
.tile.on { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-pale); }
.tile .n { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.tile .l { font-size: 12px; color: var(--text2); margin-top: 2px; }
.tile.alarm .n { color: var(--red); }
.tile.quiet { background: var(--surface2); box-shadow: none; }
.tiles-title { font-size: 12px; color: var(--text2); margin: 10px 0 6px; }

.list-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.list-head input[type=search] { flex: 1; min-width: 200px; }
.page-head input[type=search] { width: 300px; }
@media (max-width: 800px) { .page-head input[type=search] { width: 100%; } }
.tabs { display: flex; gap: 16px; border-bottom: 1px solid var(--border); margin-bottom: 12px; overflow-x: auto; }
.tabs button { border: none; background: none; padding: 8px 2px; cursor: pointer; color: var(--text2); border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tabs button[aria-pressed=true] { color: var(--text); border-bottom-color: var(--green); font-weight: 500; }
.filter-bar { display: flex; gap: 10px; align-items: center; font-size: 13px; color: var(--text2); margin-bottom: 10px; }

.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.table th { text-align: left; font-weight: 500; color: var(--text2); font-size: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface2); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr.row { cursor: pointer; }
.table tr.row:hover td { background: var(--surface2); }
.table .num { color: var(--text2); font-size: 12px; font-family: var(--mono); white-space: nowrap; }
.table td.c-owner { white-space: nowrap; }
.table .name { font-weight: 500; }
.table .sub { color: var(--text2); font-size: 12px; }
.table .flag { font-size: 12px; display: flex; gap: 5px; align-items: center; }
.table .flag.danger { color: var(--red); }
.table .flag.warning { color: var(--gold-text); }
.table tr.urgent td:first-child { box-shadow: inset 3px 0 0 var(--red); }
.empty { padding: 32px 16px; text-align: center; color: var(--text2); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); }

/* Op mobiel wordt de tabel een lijst van kaarten */
@media (max-width: 800px) {
  .table, .table tbody, .table tr, .table td { display: block; }
  .table thead { display: none; }
  .table tr { padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .table td { padding: 2px 0; border: none; }
  .table td.c-status { position: absolute; right: 12px; margin-top: -2px; }
  .table tr { position: relative; }
  .table tr.urgent td:first-child { box-shadow: none; }
  .table tr.urgent { box-shadow: inset 3px 0 0 var(--red); }
  .table td.c-owner { color: var(--text2); font-size: 12px; }
  .table td.c-owner .av { display: none; }
}

/* ---------- Retourpagina ---------- */
.case-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin: 4px 0 12px; }
.case-head h1 { font-size: 22px; margin: 0; font-weight: 600; }
.case-head .num { font-family: var(--mono); color: var(--text2); font-size: 13px; }

.nextstep {
  display: flex; gap: 14px; align-items: center;
  background: var(--green-dark); color: #fff; border-radius: var(--r);
  padding: 14px 18px; margin-bottom: 12px;
}
.nextstep i { font-size: 26px; color: #d9b95a; }
.nextstep .who { font-size: 12px; color: #9fb5a9; }
.nextstep .what { font-size: 17px; font-weight: 500; }
.nextstep.closed { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.nextstep.closed i { color: var(--green); }
.nextstep.closed .who { color: var(--text2); }

.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 12px; }
.steps div { text-align: center; font-size: 13px; padding: 6px 4px; background: var(--surface); border-radius: var(--r); color: var(--text2); border: 1px solid var(--border); }
.steps div.done { background: var(--green-pale); color: var(--green); border-color: transparent; }
.steps div.current { background: var(--green); color: #fff; border-color: var(--green); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--text2); }
dl.kv dd { margin: 0; overflow-wrap: anywhere; }
.complaint { white-space: pre-wrap; background: var(--surface2); border: 1px solid var(--border); padding: 10px 12px; border-radius: var(--r); margin: 12px 0 0; }

.money { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font-size: 14px; }
.money .total { font-weight: 600; border-top: 1px solid var(--border); padding-top: 6px; }
.money .big { font-size: 22px; font-weight: 600; color: var(--green); }
.money .line { color: var(--text2); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; margin-bottom: 10px; }
.photos a { display: block; aspect-ratio: 1; background: var(--surface2); border-radius: var(--r); overflow: hidden; border: 1px solid var(--border); }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .heic { display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--text2); height: 100%; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.timeline li { padding: 6px 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 112px 1fr; gap: 8px; }
.timeline li:last-child { border-bottom: none; }
.timeline .when { color: var(--text2); font-family: var(--mono); font-size: 12px; }
.timeline .note { white-space: pre-wrap; }

/* ---------- Wachtwoord-oogje ---------- */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 42px; }
.pw-eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 34px; height: 32px; border: none; background: none; color: var(--text2); cursor: pointer; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.pw-eye:hover { background: var(--surface2); color: var(--text); }

/* ---------- Gebruikers ---------- */
.user-row td .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.user-row.inactive td { color: var(--text3); }
.pw-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 6px; }
.pw-form .field { flex: 1; margin: 0; }

/* ---------- Login ---------- */
.login { max-width: 380px; margin: 10vh auto 0; padding: 0 16px; }
.login .logo { color: var(--text); margin: 0 0 16px; }
.login .logo i { color: var(--green); }
.login .logo .tag { color: var(--text2); }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: var(--r);
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50;
  max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; }
#toast.error { background: var(--red); }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
