/* Terreinbouwer. Werkblad-idee: je bouwt op een groene snijmat, gele markeringen tonen wat actief is. */

@font-face { font-family: 'Barlow'; font-weight: 400; font-display: swap; src: url('../fonts/Barlow-Regular.woff') format('woff'); }
@font-face { font-family: 'Barlow'; font-weight: 500; font-display: swap; src: url('../fonts/Barlow-Medium.woff') format('woff'); }
@font-face { font-family: 'Barlow'; font-weight: 600; font-display: swap; src: url('../fonts/Barlow-SemiBold.woff') format('woff'); }
@font-face { font-family: 'Barlow Condensed'; font-weight: 600; font-display: swap; src: url('../fonts/BarlowCondensed-SemiBold.woff') format('woff'); }

:root {
  --mat: #23514a;
  --mat-deep: #173b35;
  --paper: #eef2ef;
  --paper-2: #e1e8e4;
  --ink: #14211e;
  --ink-2: #4c5c57;
  --rule: #cdd7d2;
  --mark: #f2c12e;
  --mark-ink: #14211e;
  --danger: #b8402c;
  --warn: #f07d1a;
  --warn-bg: #fbeadb;
  --danger-bg: #f8e1dc;
  --radius: 8px;
  --sans: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --cond: 'Barlow Condensed', 'Barlow', system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Indeling ------------------------------------------------------------------------- */
.app {
  display: grid;
  height: 100dvh;
  grid-template-columns: 236px minmax(0, 1fr) 300px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "mast stage bom" "tools stage bom";
}
.masthead { grid-area: mast; padding: 20px 20px 8px; }
.tools { grid-area: tools; overflow-y: auto; padding: 4px 12px 20px; }
.stage { grid-area: stage; position: relative; min-height: 0; background: var(--mat-deep); }
.bom { grid-area: bom; overflow-y: auto; }

.wordmark {
  margin: 0;
  font: 600 28px/1 var(--cond);
  letter-spacing: 0.01em;
}
.tagline { margin: 8px 0 0; color: var(--ink-2); font-size: 14px; line-height: 1.4; max-width: 30ch; }

/* ---- Gereedschap ---------------------------------------------------------------------- */
.tool-group { margin-top: 14px; }
.tool-group h3 { margin: 0 8px 4px; font: 500 13px/1.3 var(--sans); color: var(--ink-2); }
.tool {
  display: flex; align-items: center; gap: 10px;
  width: 100%; min-height: 40px; padding: 6px 8px;
  border: 0; border-radius: var(--radius); background: transparent;
  text-align: left; cursor: pointer; white-space: nowrap;
}
.tool:hover { background: var(--paper-2); }
.tool[aria-pressed="true"] { background: var(--mark); color: var(--mark-ink); font-weight: 600; }
.sw { flex: none; width: 18px; height: 18px; display: grid; place-items: center; }
.sw i { display: block; background: var(--c); }
.sw-board i { width: 18px; height: 18px; background: transparent; border: 3px solid var(--c); border-radius: 3px; }
.sw-tile i { width: 16px; height: 16px; border-radius: 3px; }
.sw-decor i { width: 16px; height: 18px; clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.sw-pillar i { width: 8px; height: 18px; border-radius: 2px; }
.sw-wall i { width: 18px; height: 6px; border-radius: 1px; }
.sw svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Speelveld ------------------------------------------------------------------------ */
.canvas-host { position: absolute; inset: 0; touch-action: none; }
.canvas-host canvas { display: block; }
.canvas-host.is-painting { cursor: crosshair; }

.hint {
  position: absolute; top: 14px; left: 14px; margin: 0;
  max-width: min(46ch, calc(100% - 230px));
  padding: 9px 12px; border-radius: var(--radius);
  background: rgba(14, 35, 31, 0.78); color: var(--paper);
  font-size: 14px; line-height: 1.4; pointer-events: none;
}
.hint small { display: block; margin-top: 4px; color: #b9c8c2; font-size: 13px; }
.hint .hint-warn {
  display: block; margin-top: 7px; padding: 5px 9px;
  border-left: 3px solid var(--warn); border-radius: 4px;
  background: rgba(240, 125, 26, 0.2); color: #ffd7b3;
}

.stage-actions { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper);
  cursor: pointer;
}
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover:not(:disabled) { background: #fff; }
.icon-btn:disabled { cursor: default; }
.icon-btn:disabled svg { opacity: 0.3; }

.total-chip {
  display: none; height: 40px; padding: 0 12px;
  border: 0; border-radius: var(--radius); background: var(--mark); color: var(--mark-ink);
  font: 600 18px/1 var(--cond); cursor: pointer;
}

.fill-btn {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  max-width: calc(100% - 28px); padding: 11px 16px;
  border: 0; border-radius: var(--radius); background: var(--mark); color: var(--mark-ink);
  font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28); cursor: pointer;
}
.fill-btn:hover { background: #f6cd4a; }
.rotate-btn { display: inline-flex; align-items: center; gap: 8px; }
.rotate-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.rotate-btn kbd {
  padding: 1px 6px; border: 1px solid rgba(20, 33, 30, 0.35); border-radius: 4px;
  font: 600 12px/1.3 var(--sans); background: rgba(255, 255, 255, 0.35);
}
@media (pointer: coarse) { .rotate-btn kbd { display: none; } }

.toast {
  position: absolute; left: 14px; bottom: 18px; display: flex; align-items: center; gap: 14px;
  padding: 10px 12px 10px 14px; border-radius: var(--radius);
  background: var(--ink); color: var(--paper); font-size: 14px;
}
.toast button { padding: 4px 2px; border: 0; background: none; color: var(--mark); font-weight: 600; text-decoration: underline; cursor: pointer; }
.toast[hidden], .fill-btn[hidden], .scrim[hidden], .status[hidden] { display: none; }
.has-fill .toast { bottom: 72px; }

.status { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: var(--paper); font-size: 15px; pointer-events: none; }
.status.is-error { padding: 24px; text-align: center; color: #ffd9d2; }

/* ---- Meldingen (botsingen, verdiepingen) ------------------------------------------------ */
.bom-alerts:empty { display: none; }
.alert {
  margin: 14px 0 0; padding: 10px 12px;
  border-left: 4px solid var(--warn); border-radius: 0 6px 6px 0; background: var(--warn-bg);
}
.alert + .alert { margin-top: 8px; }
.alert p { margin: 0; font-weight: 500; }
.alert .alert-advice { margin-top: 4px; font-weight: 400; color: var(--ink-2); font-size: 14px; }
.alert-error { border-left-color: var(--danger); background: var(--danger-bg); }
.alert-tip { border-left-color: var(--ink-2); background: var(--paper-2); }
.total-chip { position: relative; }
.total-chip.has-warning::after, .total-chip.has-error::after {
  content: ''; position: absolute; top: -4px; right: -4px; width: 12px; height: 12px;
  border: 2px solid var(--paper); border-radius: 50%; background: var(--warn);
}
.total-chip.has-error::after { background: var(--danger); }

/* ---- Verdiepingen: liftknoppen --------------------------------------------------------- */
.floors {
  position: absolute; top: 60px; right: 12px; display: flex; flex-direction: column; gap: 4px;
}
.floors[hidden] { display: none; }
.floor-btn {
  min-height: 36px; padding: 0 12px; text-align: left;
  border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper);
  font-weight: 500; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.floor-btn:hover { background: #fff; }
.floor-btn[aria-pressed="true"] { background: var(--mark); border-color: var(--mark); color: var(--mark-ink); font-weight: 600; }
.fl-short { display: none; }
.floor-all { margin-bottom: 6px; }
.fl-short svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; vertical-align: middle; }

/* ---- Stuklijst ------------------------------------------------------------------------ */
.bom { display: flex; flex-direction: column; padding: 20px 20px 16px; border-left: 1px solid var(--rule); background: var(--paper); }
.bom-head { display: flex; align-items: center; justify-content: space-between; }
.bom h2 { margin: 0; font: 600 24px/1.1 var(--cond); }
.bom-close { display: none; }
.bom-empty { margin: 16px 0 0; color: var(--ink-2); }
.bom-lines { list-style: none; margin: 14px 0 0; padding: 0; }
.bom-lines li {
  display: grid; grid-template-columns: 3.2ch minmax(0, 1fr) auto; gap: 2px 10px;
  padding: 9px 0; border-top: 1px solid var(--rule);
}
.bom-lines li:first-child { border-top: 0; }
.bom-qty { font-weight: 600; text-align: right; }
.bom-name { min-width: 0; }
.bom-unit { display: block; color: var(--ink-2); font-size: 13px; }
.bom-sub { text-align: right; white-space: nowrap; }
.bom-auto { margin-left: 6px; padding: 1px 6px; border-radius: 4px; background: var(--paper-2); color: var(--ink-2); font-size: 12px; }
.bom-total {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-top: 6px; padding-top: 10px; border-top: 2px solid var(--ink);
  font-weight: 500;
}
.bom-total strong { font: 600 34px/1 var(--cond); }
.bom-meta { margin: 4px 0 0; color: var(--ink-2); font-size: 13px; text-align: right; }
.bom-note { margin: 16px 0 0; color: var(--ink-2); font-size: 13px; }
.text-btn { align-self: flex-start; margin-top: auto; padding: 18px 0 0; border: 0; background: none; color: var(--ink-2); font-size: 14px; text-decoration: underline; cursor: pointer; }
.text-btn:hover { color: var(--danger); }

/* ---- Reserveren ----------------------------------------------------------------------- */
.primary-btn {
  padding: 12px 16px; border: 0; border-radius: var(--radius);
  background: var(--mark); color: var(--mark-ink); font-weight: 600; font-size: 16px; cursor: pointer;
}
.primary-btn:hover:not(:disabled) { background: #f6cd4a; }
.primary-btn:disabled { background: var(--paper-2); color: var(--ink-2); cursor: default; }
.reserve-btn { width: 100%; margin-top: 16px; }
.reserve-blocked { margin: 6px 0 0; color: var(--danger); font-size: 13px; }
.reserve-blocked[hidden] { display: none; }

dialog.reserve {
  width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0;
  border: 0; border-radius: 12px; background: var(--paper); color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
dialog.reserve::backdrop { background: rgba(10, 25, 22, 0.55); }
.reserve-inner { padding: 22px 22px 18px; }
.reserve h2 { margin: 0 0 8px; font: 600 26px/1.1 var(--cond); }
.reserve-intro { margin: 0 0 10px; color: var(--ink-2); }
.reserve-summary { margin: 0 0 14px; font-weight: 600; }
.reserve-test { margin: 0 0 14px; padding: 8px 10px; border-left: 4px solid var(--warn); background: var(--warn-bg); font-size: 14px; }
.reserve-test[hidden], .reserve-done[hidden], form[hidden] { display: none; }
.field { display: block; margin: 0 0 12px; }
.field span { display: block; margin-bottom: 4px; font-weight: 500; font-size: 14px; }
.field input, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #b9c5bf; border-radius: var(--radius);
  background: #fff; color: var(--ink); font: inherit;
}
.field input:focus-visible, .field textarea:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.field textarea { resize: vertical; min-height: 70px; }
.field-error, .form-error { margin: -6px 0 12px; color: var(--danger); font-size: 14px; }
.field-error[hidden], .form-error[hidden] { display: none; }
.botcheck { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.reserve-privacy { margin: 4px 0 14px; color: var(--ink-2); font-size: 13px; }
.reserve-privacy a { color: var(--ink); }
.reserve-actions { display: flex; justify-content: flex-end; align-items: center; gap: 16px; }
.reserve-actions .text-btn { margin: 0; padding: 0; }

/* ---- Telefoon ------------------------------------------------------------------------- */
@media (max-width: 820px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "mast" "stage" "tools";
  }
  .masthead { padding: 10px 16px; display: flex; align-items: baseline; }
  .wordmark { font-size: 22px; }
  .tagline { display: none; }

  .tools {
    display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--rule); scrollbar-width: none;
  }
  .tool-group { display: contents; }
  .tool-group h3 { display: none; }
  .tool { width: auto; flex: none; min-height: 44px; padding: 6px 12px; }

  .hint { top: auto; bottom: 12px; left: 12px; right: 12px; max-width: none; font-size: 13.5px; }
  .hint small { display: none; }
  .has-fill .hint { bottom: 64px; }
  .fill-btn { bottom: 12px; }
  .toast { left: 12px; right: 12px; bottom: 12px; }
  .has-fill .toast { bottom: 64px; }
  .total-chip { display: block; }
  .floors { top: 60px; }
  .floor-btn { width: 40px; padding: 0; text-align: center; }
  .fl-long { display: none; }
  .fl-short { display: inline; }

  .bom {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    max-height: 78dvh; border-left: 0; border-radius: 14px 14px 0 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.25);
    transform: translateY(105%); transition: transform 220ms ease;
    visibility: hidden;
  }
  .bom.is-open { transform: none; visibility: visible; }
  .bom-close { display: grid; }
  .scrim { position: fixed; inset: 0; z-index: 15; background: rgba(10, 25, 22, 0.45); }
}

@media (prefers-reduced-motion: reduce) {
  .bom { transition: none; }
}
