:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5b6573;
  --border: #d8dee5;
  --primary: #1f4e79;
  --primary-hover: #183d5f;
  --danger: #b42318;
  --success: #067647;
  --warning: #b54708;
  --focus: #f79009;
  --radius: 6px;

  --spot: #eef1f4;
  --spot-line: #7d8896;
  --visitor: #d1f5ee;
  --visitor-line: #0e9384;
  --share: #ebe4ff;
  --share-line: #7a5af8;
  --blocked: #d0d5dd;
  --blocked-line: #667085;
  --assigned: #fef0c7;
  --assigned-line: #b54708;
  --accessible: #d1e9ff;
  --accessible-line: #1570ef;
  --ev: #079455;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 0.25rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.75rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.5rem; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; }
.error { color: var(--danger); }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* --- Buttons and inputs --- */

button, .button {
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:disabled { opacity: 0.55; cursor: default; }
.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary:hover:not(:disabled) { background: var(--primary-hover); }
.secondary:hover:not(:disabled) { background: var(--bg); }
.danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.danger:hover:not(:disabled) { background: #fef3f2; }
.danger-text { color: var(--danger); }
.link { border: none; background: none; padding: 0; color: var(--primary); text-decoration: underline; }
.small { padding: 0.2rem 0.6rem; font-size: 0.85rem; }

input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
input:disabled, select:disabled, textarea:disabled { background: var(--bg); color: var(--muted); }
input[type="checkbox"], input[type="radio"] { width: auto; }

.field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.75rem; flex: 1; min-width: 0; }
.field-label { font-weight: 600; font-size: 0.9rem; }
.check { display: flex; align-items: center; gap: 0.4rem; margin: 0.25rem 0 0.75rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.row > .field { min-width: 160px; }
.row-tight { gap: 0.5rem; }
.row-tight > .field { min-width: 0; }
.actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.actions .danger { margin-right: auto; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 1rem; padding: 0.75rem 1rem; }
legend { font-weight: 600; padding: 0 0.25rem; }

.plate, .plate-input {
  font-family: "Kenteken", ui-monospace, "Cascadia Mono", Consolas, monospace;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.plate { background: #f5c400; border: 1px solid #1c2430; border-radius: 3px; padding: 0 0.35rem; font-weight: 700; }

/* --- Shell --- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.6rem 1.25rem;
  background: var(--primary);
  color: #fff;
  flex-wrap: wrap;
}
.topbar a, .topbar .link { color: #fff; }
.brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.nav { display: flex; gap: 0.25rem; }
.nav a { text-decoration: none; padding: 0.3rem 0.65rem; border-radius: var(--radius); opacity: 0.85; }
.nav a.active, .nav a:hover { background: rgba(255, 255, 255, 0.15); opacity: 1; }
.search { flex: 1; max-width: 340px; margin-left: auto; }
.search input { border-color: transparent; padding: 0.35rem 0.6rem; }
.me { display: flex; gap: 0.75rem; align-items: center; font-size: 0.9rem; }

.main { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.main-wide { max-width: none; padding: 0.75rem 1rem 1rem; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.crumbs { margin: 0 0 0.5rem; color: var(--muted); font-size: 0.9rem; }

.panel, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.panel { margin-top: 1.5rem; }
.panel > h1:first-child, .panel > h2:first-child { margin-top: 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.card h2, .card h3 { margin: 0.25rem 0; }
.card p { margin: 0.2rem 0; }
.card-link { color: inherit; text-decoration: none; display: block; }
.card-link:hover { border-color: var(--primary); box-shadow: 0 1px 4px rgba(16, 24, 40, 0.08); }
.floors { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }

.stats { list-style: none; padding: 0; margin: 0.5rem 0 0; display: flex; flex-wrap: wrap; gap: 0.25rem 0.9rem; font-size: 0.9rem; color: var(--muted); }
.stats strong { color: var(--text); }
.stats-big { font-size: 1rem; }

.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

.table-wrap { overflow-x: auto; padding: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.55rem 0.9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.table select { width: auto; }
.table tr.inactive td { color: var(--muted); }
.badge { display: inline-block; margin-left: 0.5rem; font-size: 0.75rem; padding: 0 0.4rem; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }

/* --- Templates --- */

.templates { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.template { position: relative; cursor: pointer; }
.template input { position: absolute; top: 0.6rem; left: 0.6rem; }
.template-body {
  display: flex; flex-direction: column; gap: 0.25rem; height: 100%;
  border: 2px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.75rem 0.75rem 2rem;
  font-size: 0.9rem;
}
.template input:checked + .template-body { border-color: var(--primary); background: #f0f5fa; }
.template-blank { display: flex; align-items: center; justify-content: center; height: 110px; font-size: 2rem; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }

/* --- Plans --- */

.plan { display: block; width: 100%; }
.plan-preview { height: 110px; margin-bottom: 0.4rem; }
.floor-card .plan-preview { height: 150px; }
.plan-editor { height: 100%; touch-action: none; user-select: none; cursor: grab; }
.plan-editor.mode-add { cursor: crosshair; }

.plan rect, .plan line { vector-effect: non-scaling-stroke; }
.floor-bg { fill: #fff; }
.floor-outline { fill: none; stroke: var(--text); stroke-width: 2px; }
.grid { stroke: #eef1f4; stroke-width: 1px; }
.grid-major { stroke: #dde2e8; }

.element rect { stroke-width: 1px; }
.element-label { fill: var(--muted); text-anchor: middle; dominant-baseline: central; pointer-events: none; font-family: system-ui, sans-serif; }
.el-rijbaan rect { fill: #f2f4f7; stroke: #c9d0d9; stroke-dasharray: 4 3; }
.el-hellingbaan rect { fill: #fdf0d5; stroke: #dc6803; }
.el-kolom rect { fill: #344054; stroke: #1d2939; }
.el-kern rect { fill: #cfd6e0; stroke: #475467; }
.el-in-uitrit rect { fill: #d3f8df; stroke: #099250; }
.el-obstakel rect { fill: #fee4e2; stroke: #d92d20; }
.plan-editor .element { cursor: pointer; }

.spot-body { fill: var(--spot); stroke: var(--spot-line); stroke-width: 1px; }
.spot-mouth { stroke: #fff; stroke-width: 2px; stroke-dasharray: 3 2; }
.kind-bezoekers .spot-body { fill: var(--visitor); stroke: var(--visitor-line); }
.kind-deelauto .spot-body { fill: var(--share); stroke: var(--share-line); }
.assigned .spot-body { fill: var(--assigned); stroke: var(--assigned-line); }
.accessible .spot-body { fill: var(--accessible); stroke: var(--accessible-line); }
.kind-geblokkeerd .spot-body { fill: var(--blocked); stroke: var(--blocked-line); }
.ev .spot-body { stroke: var(--ev); stroke-width: 2px; }
.spot text { text-anchor: middle; dominant-baseline: central; pointer-events: none; font-family: system-ui, sans-serif; }
.spot-code { fill: var(--text); font-weight: 600; }
.spot-icons { fill: var(--text); }
.spot-plate { fill: var(--assigned-line); font-weight: 700; font-family: ui-monospace, Consolas, monospace; }
.plan-editor .spot { cursor: move; }
.selected .spot-body, .selected rect { stroke: var(--focus) !important; stroke-width: 3px !important; }
.dragging { opacity: 0.75; }

/* --- Editor --- */

.editor-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.5rem; }
.editor-head .crumbs { margin: 0; }
.floor-switch { width: auto; }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 0.75rem; height: calc(100vh - 120px); min-height: 480px; }
.editor-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; padding: 0.5rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.tool-group { display: flex; gap: 0.35rem; align-items: center; }
.tool-group select { width: auto; padding: 0.35rem 0.5rem; }
.tool-right { margin-left: auto; }
.tool { padding: 0.35rem 0.7rem; }
.tool.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.canvas { flex: 1; min-height: 0; background: #e9edf1; border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }
.side { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; overflow-y: auto; }
.side h2 { margin-top: 0.25rem; }
.mini { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.mini th { text-align: left; font-weight: normal; color: var(--muted); padding: 0.15rem 0; }
.mini td { text-align: right; font-weight: 600; }
.legend { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem 0.5rem; font-size: 0.85rem; }
.legend li { display: flex; align-items: center; gap: 0.4rem; }
.legend-swatch { width: 18px; height: 18px; flex: none; }
.help ul { padding-left: 1rem; margin: 0; font-size: 0.85rem; color: var(--muted); }
kbd { font-family: inherit; font-size: 0.8rem; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 3px; padding: 0 0.3rem; background: var(--bg); color: var(--text); }

/* --- Toasts and dialogs --- */

.toasts { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 10; max-width: 420px; }
.toast { padding: 0.65rem 0.9rem; border-radius: var(--radius); background: var(--text); color: #fff; box-shadow: 0 4px 12px rgba(16, 24, 40, 0.18); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }

.dialog { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; max-width: 440px; }
.dialog::backdrop { background: rgba(16, 24, 40, 0.4); }
.dialog p { margin-top: 0; }

/* --- Login --- */

body.auth { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; }
.auth-card h1 { color: var(--primary); margin-bottom: 0.75rem; }
.auth-card label { display: block; font-weight: 600; margin: 1rem 0 0.3rem; }
.auth-card button.primary { width: 100%; justify-content: center; margin-top: 1rem; padding: 0.6rem; }

@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; height: auto; }
  .canvas { height: 60vh; }
  .search { max-width: none; order: 5; flex-basis: 100%; }
}
