:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #17202b;
  --text-2: #56606d;
  --text-3: #8a93a0;
  --border: #dde1e6;
  --border-2: #c7cdd5;
  --accent: #1f6feb;
  --accent-bg: #e6efff;
  --accent-text: #134aa3;
  --danger: #c62828;
  --danger-bg: #fdecec;
  --ok: #2e7d32;
  --warn: #b26a00;
  --todo: #6b7280;
  --doing: #1f6feb;
  --done: #2e7d32;
  --radius: 10px;
  --tabbar-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --plan-road: #9aa1aa;
  --plan-lot: #fbfbf8;
  --plan-grid: #e3e4dd;
  --plan-grid-5: #c9cbc0;
  --plan-bldg: #d9d6cc;
  --plan-text: #3b3f45;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e26;
    --surface-2: #202934;
    --text: #e8edf3;
    --text-2: #a6b0bc;
    --text-3: #707b88;
    --border: #2a3440;
    --border-2: #3a4552;
    --accent: #5b9bff;
    --accent-bg: #1a2c47;
    --accent-text: #a8c8ff;
    --danger: #ff6b6b;
    --danger-bg: #3a1b1b;
    --ok: #6fcf73;
    --warn: #f0b24a;
    --todo: #9aa3ae;
    --doing: #5b9bff;
    --done: #6fcf73;
    --plan-road: #4a515a;
    --plan-lot: #1b222b;
    --plan-grid: #26303b;
    --plan-grid-5: #36414d;
    --plan-bldg: #2f3640;
    --plan-text: #c9d1da;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { font-size: 16px; }
h1 { font-size: 22px; font-weight: 600; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 28px 0 10px; }
svg { display: block; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--border-2); background: var(--surface); cursor: pointer;
  font-weight: 500;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.block { width: 100%; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 14px; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px; display: grid; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; inset: 7px 6px; border: 2px solid #fff; border-radius: 2px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); font-weight: 500; }
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]), select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px; border-radius: var(--radius);
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form-error { color: var(--danger); font-size: 13px; margin: 0; min-height: 0; }
.form-error:empty { display: none; }

/* app shell */
.app { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--surface); border-bottom: 1px solid var(--border); flex: none; z-index: 20;
}
.topbar .brand { font-size: 16px; }
.tabs { display: flex; gap: 4px; margin-left: 16px; }
.tabs button {
  display: flex; align-items: center; gap: 6px; border: 0; background: transparent; cursor: pointer;
  padding: 8px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; position: relative;
}
.tabs button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.active { color: var(--accent); background: var(--accent-bg); }
.tabs .count { font-size: 11px; font-weight: 600; background: var(--accent); color: #fff; border-radius: 9px; padding: 0 5px; min-width: 18px; text-align: center; }
.tabs .count:empty { display: none; }
.presence { display: flex; margin-left: auto; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-size: 11px; font-weight: 600; color: #fff; border: 2px solid var(--surface);
}
.presence .avatar { margin-left: -6px; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); flex: none; }
.conn.live { background: var(--ok); }
main { flex: 1; min-height: 0; position: relative; }
.view { display: none; height: 100%; }
.view.active { display: flex; flex-direction: column; }
.page { width: 100%; max-width: 760px; margin: 0 auto; padding: 18px 16px 32px; overflow-y: auto; height: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

.tab-more { display: none !important; }
.plan-bar { flex: none; display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
.plan-bar .btn { white-space: nowrap; }
.plan-bar .count { font-size: 11px; font-weight: 600; background: var(--accent); color: #fff; border-radius: 9px; padding: 0 6px; }
.plan-bar .count:empty { display: none; }
#version-name { max-width: 52vw; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: bottom; }
.pin-mode #plan { cursor: crosshair; }
.pin-banner { position: absolute; left: 50%; transform: translateX(-50%); top: 10px; background: var(--accent); color: #fff; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 500; pointer-events: none; white-space: nowrap; }

/* mobile: tabs become a bottom bar */
@media (max-width: 760px) {
  .brand-text { font-size: 15px; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: 30;
    height: calc(var(--tabbar-h) + var(--safe-b)); padding: 4px 6px var(--safe-b);
    background: var(--surface); border-top: 1px solid var(--border); justify-content: space-around;
  }
  .tabs button { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; flex: 1; }
  .tabs .tab-extra { display: none; }
  .tabs .tab-more { display: flex !important; }
  .tabs button.active { background: transparent; }
  .tabs .count { position: absolute; top: 2px; left: 55%; }
  main { padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); }
}

/* plan */
.plan-wrap { flex: 1; min-height: 0; position: relative; background: var(--bg); overflow: hidden; }
#plan { width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
#plan.panning { cursor: grabbing; }
#plan .shape { cursor: move; }
#plan .handle { cursor: nwse-resize; }
#plan .rot-handle { cursor: grab; }
.plan-hud {
  position: absolute; left: 10px; top: 10px; font-size: 12px; color: var(--text-2);
  background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 6px; pointer-events: none;
}
.plan-hud:empty { display: none; }
.toolbar {
  flex: none; display: flex; gap: 4px; padding: 6px 8px; overflow-x: auto; scrollbar-width: none;
  background: var(--surface); border-top: 1px solid var(--border);
}
.toolbar::-webkit-scrollbar { display: none; }
.toolbar button {
  flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 62px;
  border: 1px solid transparent; background: transparent; border-radius: 8px; padding: 5px 6px; cursor: pointer;
  color: var(--text-2); font-size: 11px; font-weight: 500;
}
.toolbar button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toolbar button:active { background: var(--surface-2); }
.toolbar button.toggle.on { color: var(--accent); }
.tb-sep { width: 1px; background: var(--border); margin: 4px 2px; flex: none; }

/* shape panel */
.shape-panel {
  position: fixed; z-index: 25; background: var(--surface); border: 1px solid var(--border);
  left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-b));
  border-radius: 16px 16px 0 0; padding: 12px 14px 14px; max-height: 55dvh; overflow-y: auto;
  box-shadow: 0 -6px 24px rgba(0,0,0,.12);
}
@media (min-width: 761px) {
  .shape-panel { left: auto; right: 14px; top: 76px; bottom: auto; width: 320px; border-radius: 14px; max-height: calc(100dvh - 160px); }
}
.sp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.sp-head input { flex: 1; font-weight: 600; }
.sp-head .btn { font-size: 18px; min-width: 40px; }
.sp-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 8px; margin-bottom: 10px; }
.sp-row label input { min-height: 38px; padding: 6px 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 2px 0 12px; }
.swatches button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatches button.on { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }
.sp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.sp-more { display: none; }
.shape-panel.expanded .sp-more { display: block; }
.sp-tasks { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.sp-tasks h3 { font-size: 13px; margin: 0 0 6px; color: var(--text-2); font-weight: 600; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.item {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  display: flex; gap: 12px; align-items: flex-start; cursor: pointer;
}
.item:active { background: var(--surface-2); }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; overflow-wrap: anywhere; }
.item.done .item-title { text-decoration: line-through; color: var(--text-2); }
.meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--text-2); margin-top: 4px; align-items: center; }
.meta .overdue { color: var(--danger); font-weight: 600; }
.status-btn {
  flex: none; width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--todo);
  background: transparent; cursor: pointer; margin-top: 1px; position: relative; padding: 0;
}
.status-btn.doing { border-color: var(--doing); background: conic-gradient(var(--doing) 0 50%, transparent 50% 100%); }
.status-btn.done { border-color: var(--done); background: var(--done); }
.status-btn.done::after { content: ""; position: absolute; left: 7px; top: 3px; width: 6px; height: 11px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.pill.high { background: var(--danger-bg); color: var(--danger); }
.pill.shape-pill i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chips { display: flex; gap: 6px; overflow-x: auto; margin: 10px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button { flex: none; border: 1px solid var(--border-2); background: var(--surface); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 14px; }
.chips button.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.search { margin-top: 2px; }
.progress { font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 4px; display: flex; }
.bar i { display: block; height: 100%; }
.empty { text-align: center; color: var(--text-2); padding: 36px 12px; border: 1px dashed var(--border-2); border-radius: 12px; }
.feed .item { cursor: default; align-items: center; }
.feed .item.link { cursor: pointer; }
.feed time { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: grid; gap: 12px; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); display: inline-block; }

/* sheet (modal) */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
.sheet {
  position: fixed; z-index: 41; left: 0; right: 0; bottom: 0; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0; padding: 6px 16px calc(18px + var(--safe-b));
  animation: up .18s ease-out;
}
@media (min-width: 761px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: 560px; border-radius: 16px; max-height: 88dvh; animation: none; }
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border-2); margin: 4px auto 12px; }
.sheet-body { display: grid; gap: 14px; }
.sheet-body h2 { margin: 0; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border-2); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 9px 4px; cursor: pointer; font-weight: 500; font-size: 14px; }
.seg button + button { border-left: 1px solid var(--border-2); }
.seg button.on[data-v=todo] { background: var(--surface-2); }
.seg button.on[data-v=doing] { background: var(--accent-bg); color: var(--accent-text); }
.seg button.on[data-v=done] { background: color-mix(in srgb, var(--done) 18%, var(--surface)); color: var(--done); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-actions { display: flex; gap: 8px; justify-content: space-between; flex-wrap: wrap; }
.comments { display: grid; gap: 10px; }
.comment { display: flex; gap: 10px; }
.comment .body { background: var(--surface-2); border-radius: 12px; padding: 8px 12px; flex: 1; min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.comment .who { font-size: 12px; color: var(--text-2); margin-bottom: 2px; }
.comment-form { display: flex; gap: 8px; align-items: flex-end; }
.comment-form textarea { min-height: 42px; height: 42px; }
.muted { color: var(--text-2); font-size: 13px; }

/* toasts */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); top: calc(64px + env(safe-area-inset-top, 0px)); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 14px; animation: up .15s ease-out; }
.toast.error { background: var(--danger); color: #fff; }

/* agenda */
.day-head { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 18px 0 8px; text-transform: none; }
.day-head.today { color: var(--accent); }
.appt-time { flex: none; width: 54px; font-weight: 600; font-variant-numeric: tabular-nums; }
.appt-time small { display: block; font-weight: 400; color: var(--text-3); font-size: 12px; }
.item.cancelled .item-title { text-decoration: line-through; color: var(--text-3); }
.item.done-appt .item-title { color: var(--text-2); }
.pill.ok { background: color-mix(in srgb, var(--done) 18%, var(--surface)); color: var(--done); }
.contact-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.contact-actions a { text-decoration: none; color: inherit; }
.linkish { color: var(--accent); text-decoration: none; }

/* plan comments */
.pc { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.pc:last-child { border-bottom: 0; }
.pc.resolved { opacity: .6; }
.pc .body { flex: 1; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.pc .pc-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.pc.flash { background: var(--accent-bg); border-radius: 8px; }
.pin-num { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: #E24B4A; color: #fff; font-size: 11px; font-weight: 700; margin-right: 4px; }
.version-row { display: flex; gap: 10px; align-items: center; }
.version-row.current { border-color: var(--accent); }

/* surveys */
.tabs-inline { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 6px 0 16px; overflow-x: auto; }
.tabs-inline button { border: 0; background: transparent; padding: 10px 12px; cursor: pointer; font-weight: 500; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs-inline button.on { color: var(--accent); border-bottom-color: var(--accent); }
.qcard { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 10px; }
.qcard-head { display: flex; align-items: center; gap: 8px; }
.qnum { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 13px; font-weight: 600; }
.qcard-head select { width: auto; flex: 1; min-height: 36px; padding: 4px 8px; }
.icon-btn { flex: none; width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border-2); background: var(--surface); cursor: pointer; display: grid; place-items: center; font-size: 16px; }
.icon-btn:disabled { opacity: .35; }
.checkrow { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); font-weight: 400; }
.checkrow input { width: 18px; height: 18px; }
.cond { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; display: grid; gap: 6px; }
.add-q { display: flex; flex-wrap: wrap; gap: 6px; }
.sticky-save { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; display: flex; gap: 8px; justify-content: flex-end; align-items: center; z-index: 2; }
.res-q { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.res-q h3 { font-size: 15px; margin: 0 0 10px; }
.res-bar { display: grid; grid-template-columns: minmax(80px, 38%) 1fr 64px; gap: 8px; align-items: center; font-size: 14px; margin: 6px 0; }
.res-bar .track { height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.res-bar .track i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.res-bar .n { text-align: right; color: var(--text-2); font-variant-numeric: tabular-nums; }
.res-big { font-size: 28px; font-weight: 600; }
.res-text { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 280px; overflow-y: auto; }
.res-text li { background: var(--surface-2); border-radius: 8px; padding: 6px 10px; font-size: 14px; overflow-wrap: anywhere; }
.qr-box { background: #fff; border-radius: 12px; padding: 12px; width: min(260px, 70vw); border: 1px solid var(--border); }
.qr-box img { width: 100%; height: auto; display: block; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.stat .muted { font-size: 12px; }
.pill.open { background: color-mix(in srgb, var(--done) 18%, var(--surface)); color: var(--done); }
.pill.closed { background: var(--danger-bg); color: var(--danger); }
.seg button.on[data-v=planned] { background: var(--accent-bg); color: var(--accent-text); }
.seg button.on[data-v=cancelled] { background: var(--danger-bg); color: var(--danger); }
a.btn { text-decoration: none; color: inherit; }

/* draaiboek */
.now-card { border-color: var(--done); margin-bottom: 12px; gap: 8px; }
.run-item.now { border-color: var(--done); box-shadow: inset 4px 0 0 var(--done); }
.run-item.done .item-title { text-decoration: line-through; color: var(--text-2); }
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; color: #000; font: 12px/1.4 system-ui, sans-serif; }
  #print-area h1 { font-size: 20px; margin: 0 0 4px; }
  #print-area h2 { font-size: 15px; margin: 16px 0 6px; }
  #print-area table { width: 100%; border-collapse: collapse; }
  #print-area th, #print-area td { border: 1px solid #999; padding: 4px 6px; text-align: left; vertical-align: top; }
  #print-area th { background: #eee; }
  #print-area tr { break-inside: avoid; }
  @page { size: A4 landscape; margin: 12mm; }
}
