:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1b1f24;
  --muted: #646d78;
  --border: #d9dee5;
  --primary: #1f5f8b;
  --primary-text: #ffffff;
  --accent: #f2b84b;
  --danger: #b3261e;
  --ok: #2e7d4f;
  --warn: #a35c00;
  --room: #e8f0f7;
  --room-stroke: #6d8aa3;
  --radius: 12px;
  --tap: 44px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121519;
    --surface: #1b2026;
    --surface-2: #242b33;
    --text: #e8ebef;
    --muted: #9aa4af;
    --border: #333c46;
    --primary: #5ea3d6;
    --primary-text: #0b1620;
    --danger: #ef6b62;
    --ok: #6cc28f;
    --warn: #f0a650;
    --room: #1f2c38;
    --room-stroke: #6f90ab;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body.no-scroll { overflow: hidden; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--primary); }
img { max-width: 100%; }

.page { max-width: 760px; margin: 0 auto; }
main { padding: 16px; }
.page.has-fab main { padding-bottom: 96px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.narrow { width: 5.5rem; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.warn { color: var(--warn); }
.pre { white-space: pre-wrap; }
.label { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin-bottom: 6px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.9rem; color: var(--muted); }
label.row { flex-direction: row; }

/* Kopbalk */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 8px 8px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar h1 { flex: 1; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn, .icon-spacer {
  width: var(--tap); height: var(--tap); flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.5rem; text-decoration: none; color: var(--text);
  background: none; border: 0; border-radius: 50%; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

.tabs { display: flex; gap: 6px; overflow-x: auto; }
.tabs a { padding: 8px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); text-decoration: none; color: var(--text); white-space: nowrap; font-size: 0.9rem; }

/* Knoppen en velden */
.btn {
  min-height: var(--tap); padding: 0 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; border-style: dashed; }
.btn.small { min-height: 36px; padding: 0 10px; font-size: 0.9rem; }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.input {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
}
textarea.input { resize: vertical; }
.input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 38px; padding: 0 12px; font: inherit; font-size: 0.92rem;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
}
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.chip.ghost { border-style: dashed; }
.chips.small .chip { min-height: 34px; font-size: 0.85rem; padding: 0 10px; }

.tag { display: inline-block; margin: 4px 4px 0 0; padding: 1px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.c-nieuw, .c-goed, .v-ongewijzigd { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.c-gebruikssporen, .v-slijtage { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.c-beschadigd, .c-defect, .v-schade { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.v-nieuw { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }

/* Kaarten en lijsten */
.list { display: flex; flex-direction: column; gap: 8px; }
.card {
  display: block; width: 100%; text-align: left; padding: 12px 14px;
  font: inherit; color: var(--text); text-decoration: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.card.selected { border-color: var(--primary); }
.card-title { font-weight: 600; margin: 4px 0 2px; }
.badge { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; padding: 2px 8px; border-radius: 6px; }
.badge.intrede { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.uittrede { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.empty { text-align: center; padding: 24px 12px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.panel { padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
section > h2 { margin-top: 6px; }

.progress { position: relative; height: 28px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--ok) 35%, transparent); }
.progress > span { position: relative; display: block; text-align: center; line-height: 28px; font-size: 0.85rem; font-weight: 600; }
.mini-progress { height: 4px; margin-top: 8px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.mini-progress > div { height: 100%; background: var(--ok); }

/* Grondplan */
.plan { display: block; width: 100%; max-height: 55vh; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); user-select: none; -webkit-user-select: none; }
.plan-edit { height: 55vh; touch-action: none; }
.plan .grid line { stroke: var(--border); stroke-width: 0.02; }
.plan .room-rect { fill: var(--room); stroke: var(--room-stroke); stroke-width: 0.06; }
.plan .room.selected .room-rect, .plan .room.highlight .room-rect { fill: color-mix(in srgb, var(--primary) 25%, var(--room)); stroke: var(--primary); stroke-width: 0.1; }
.plan .room-label { fill: var(--text); font-weight: 600; pointer-events: none; }
.plan .room-badge { fill: var(--muted); pointer-events: none; }
.plan .handle { fill: var(--primary); stroke: var(--surface); stroke-width: 0.06; cursor: nwse-resize; }
.plan .pin circle { fill: var(--accent); stroke: #fff; stroke-width: 0.05; }
.plan .pin.active circle { fill: var(--danger); }
.plan .pin text { fill: #111; font-weight: 700; pointer-events: none; }
.plan-view .room, .plan-pick { cursor: pointer; }

/* Ruimte */
.element { padding: 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; gap: 8px; }
.element.done { border-left: 4px solid var(--ok); }
.ref { padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-size: 0.92rem; }
.obs { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid var(--border); }
.obs-main { display: flex; gap: 10px; cursor: pointer; }
.thumbs { display: flex; gap: 4px; flex: none; }
.thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; }
.ai-box { padding: 10px 12px; border-radius: 10px; border: 1px solid color-mix(in srgb, var(--primary) 40%, transparent); background: color-mix(in srgb, var(--primary) 8%, var(--surface)); display: flex; flex-direction: column; gap: 6px; }
.ai-box ul { margin: 0; padding-left: 1.2rem; }
.error-box { padding: 12px; border-radius: 10px; border: 1px solid var(--danger); color: var(--danger); white-space: pre-wrap; }

/* Fotoknop */
.fab {
  position: fixed; z-index: 20; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  min-height: 60px; padding: 0 24px; border: 0; border-radius: 999px;
  font: inherit; font-size: 1.1rem; font-weight: 700;
  background: var(--primary); color: var(--primary-text); box-shadow: 0 6px 20px rgb(0 0 0 / 0.25); cursor: pointer;
}

/* Modals */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / 0.45); display: flex; align-items: flex-end; justify-content: center; }
.modal { width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px)); background: var(--bg); border-radius: 18px 18px 0 0; }
.modal.full { max-width: 760px; height: 100%; max-height: none; padding: 0; border-radius: 0; display: flex; flex-direction: column; }
@media (min-width: 700px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 18px; }
}
.capture { display: flex; flex-direction: column; height: 100%; }
.capture-body { flex: 1; overflow: auto; padding: 14px 16px; }
.actions { display: flex; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--border); }
.actions .btn { flex: 1; padding: 0 8px; }
.photo-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.loading { opacity: 0.5; }
.thumb { position: relative; flex: none; width: 92px; height: 92px; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.add { border: 2px dashed var(--border); font-size: 1.8rem; cursor: pointer; color: var(--text); }
.thumb-del { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border: 0; border-radius: 50%; background: rgb(0 0 0 / 0.6); color: #fff; font-size: 1.1rem; cursor: pointer; }
.photo-view { display: flex; justify-content: center; }
.photo-view img { max-height: 85vh; border-radius: 8px; }
.meter-photo { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; }

.toast { position: fixed; z-index: 100; left: 50%; bottom: 96px; transform: translateX(-50%); max-width: 90vw; padding: 10px 16px; border-radius: 10px; background: #222; color: #fff; box-shadow: 0 4px 14px rgb(0 0 0 / 0.3); }
.offline-bar { display: none; position: fixed; z-index: 30; left: 0; right: 0; top: 0; padding: calc(2px + env(safe-area-inset-top, 0px)) 8px 2px; text-align: center; font-size: 0.75rem; background: var(--warn); color: #fff; }
body.offline .offline-bar { display: block; }
.loading-screen { padding: 40px; text-align: center; color: var(--muted); }

/* Rapport */
.report { padding: 16px; background: var(--surface); color: var(--text); display: flex; flex-direction: column; gap: 14px; }
.report h1 { font-size: 1.4rem; }
.r-address { font-size: 1.1rem; font-weight: 600; }
.r-meta th { text-align: left; padding-right: 16px; color: var(--muted); font-weight: 500; }
.r-room { display: flex; flex-direction: column; gap: 8px; }
.r-room h2 { padding-bottom: 4px; border-bottom: 2px solid var(--primary); }
.r-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.r-table th, .r-table td { border: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
.r-table th { background: var(--surface-2); }
.ref-cell { color: var(--muted); }
.r-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.r-photos figure { margin: 0; break-inside: avoid; }
.r-photos img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; }
.r-photos figcaption { font-size: 0.8rem; }
.r-plan .plan { max-height: 40vh; }
.sig-box { display: flex; flex-direction: column; gap: 4px; }
.sig { width: 100%; aspect-ratio: 3 / 1; background: #fff; border: 1px solid var(--border); border-radius: 8px; touch-action: none; }

@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #f0f0f0; --text: #000; --muted: #555; --border: #bbb; --room: #f3f6f9; color-scheme: light; }
  .no-print, .offline-bar, .toast { display: none !important; }
  .report { padding: 0; }
  .r-table tr, .r-photos figure, .sig-box { break-inside: avoid; }
  .r-room h2 { break-after: avoid; }
  .r-photos { grid-template-columns: repeat(3, 1fr); }
  .sig { border-color: #999; }
}
