/* Tokens, type and shared controls. The palette follows the workspace in view: you always see which world you are in. */
@property --ground { syntax: '<color>'; inherits: true; initial-value: #14142B; }
@property --surface { syntax: '<color>'; inherits: true; initial-value: #1E1E3D; }
@property --line { syntax: '<color>'; inherits: true; initial-value: #36365F; }
@property --ink { syntax: '<color>'; inherits: true; initial-value: #F2F1FF; }
@property --dim { syntax: '<color>'; inherits: true; initial-value: #A9A8CC; }
@property --glow { syntax: '<color>'; inherits: true; initial-value: #CFCAFF; }
@property --second { syntax: '<color>'; inherits: true; initial-value: #8FA8FF; }

:root {
  --ground: #14142B; --surface: #1E1E3D; --line: #36365F; --ink: #F2F1FF; --dim: #A9A8CC; --glow: #CFCAFF; --second: #8FA8FF;
  --attention: #FFE14D;
  --error: #FF5A5F;
  --arc: var(--glow);
  --font: "Bricolage Grotesque", ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
  --mono: "Spline Sans Mono", ui-monospace, "Cascadia Mono", Consolas, "SF Mono", monospace;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  transition: --ground .6s ease, --surface .6s ease, --line .6s ease, --ink .6s ease, --dim .6s ease, --glow .6s ease, --second .6s ease;
  color-scheme: dark;
}
:root[data-ws="prive"] {
  --ground: #1A0F2E; --surface: #251640; --line: #3B2760; --ink: #F6EFFF; --dim: #A794C9; --glow: #FFB14A; --second: #FF6B9A;
}
:root[data-ws="zakelijk"] {
  --ground: #04232A; --surface: #0A323B; --line: #17505B; --ink: #EAFBF8; --dim: #86B5B8; --glow: #6FF2CF; --second: #6DB6FF;
}
/* An item keeps the colour of its own world, also when both are in view. */
[data-ws-item="prive"] { --arc: #FFB14A; }
[data-ws-item="zakelijk"] { --arc: #6FF2CF; }
[data-ws-item="alles"] { --arc: #CFCAFF; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--ground);
  color: var(--ink);
  font: 400 16px/1.45 var(--font);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}
h1, h2, h3, p, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--glow); text-underline-offset: 3px; }
.mono { font-family: var(--mono); font-size: .875em; }
.dim { color: var(--dim); }
.ico { flex: none; display: block; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
::selection { background: var(--glow); color: var(--ground); }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }

/* ---- top bar ---- */
.top {
  display: flex; align-items: center; gap: 20px;
  padding: calc(10px + var(--safe-t)) calc(20px + var(--safe-r)) 10px calc(20px + var(--safe-l));
  min-height: 60px;
}
.wordmark { font-size: 24px; font-weight: 800; font-stretch: 75%; letter-spacing: -.01em; color: var(--glow); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.ws-switch { display: flex; padding: 3px; border-radius: 999px; background: var(--surface); }
.ws-switch button {
  border: 0; background: none; cursor: pointer; min-height: 38px; padding: 0 16px; border-radius: 999px;
  font-weight: 600; color: var(--dim);
}
.ws-switch button[aria-checked="true"] { background: var(--arc); color: #14101F; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--dim); }
.conn i { width: 9px; height: 9px; border-radius: 50%; background: var(--error); }
.conn[data-on="true"] i { background: var(--glow); }
.conn[data-on="false"] { color: var(--ink); }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 999px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--dim); }
.btn.primary { background: var(--glow); border-color: var(--glow); color: var(--ground); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.quiet { background: none; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 14px; }
.btn.danger, .btn.deny { background: none; border-color: var(--error); color: var(--error); }
.btn.danger { background: var(--error); color: #23070A; }
.btn.allow { background: var(--attention); border-color: var(--attention); color: #231D00; }
.btn.danger-text { color: var(--error); border-color: transparent; margin-right: auto; }
.btn[aria-pressed="true"] { background: var(--glow); border-color: var(--glow); color: var(--ground); }
.btn:disabled, .icon-btn:disabled { opacity: .4; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: 50%;
  border: 0; background: none; color: var(--dim); cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 10%, transparent); color: var(--ink); }
.icon-btn.solid { background: var(--glow); color: var(--ground); }
.icon-btn.solid:hover:not(:disabled) { background: var(--glow); color: var(--ground); filter: brightness(1.08); }
.icon-btn.tiny { width: 28px; height: 28px; }

/* ---- fields ---- */
input[type="text"], input[type="password"], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: var(--ground); color: var(--ink);
}
textarea { resize: vertical; line-height: 1.4; }
::placeholder { color: var(--dim); opacity: 1; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--glow); outline-offset: 0; border-color: transparent; }

/* ---- dialogs ---- */
.dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; overflow: auto;
  border: 1.5px solid var(--line); border-radius: 28px; background: var(--surface); color: var(--ink);
}
.dialog::backdrop { background: color-mix(in srgb, var(--ground) 78%, transparent); backdrop-filter: blur(6px); }
.dialog form { display: grid; gap: 16px; padding: 24px; }
.dialog header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog h2 { font-size: 28px; font-weight: 700; font-stretch: 85%; line-height: 1.1; }
.dialog h3 { font-size: 16px; font-weight: 700; margin-top: 8px; }
.dialog .intro { color: var(--dim); max-width: 60ch; }
.dialog .path { word-break: break-all; }
.dialog .warn { color: var(--attention); }
.dialog footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: 15px; }
.field small, .check + small { color: var(--dim); font-size: 14px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: var(--glow); }
.run-list { display: grid; gap: 4px; }
.run-row { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.run-main { flex: 1; min-width: 0; display: grid; }
.run-main small { color: var(--dim); font-size: 14px; }
.run-dot, .run { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
[data-run="ok"] > .run-dot, .run[data-run="ok"] { background: var(--glow); }
[data-run="fail"] > .run-dot, .run[data-run="fail"] { background: var(--error); }
[data-run="busy"] > .run-dot, .run[data-run="busy"] { background: var(--attention); }

/* ---- toasts ---- */
.toasts {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); top: calc(68px + var(--safe-t));
  display: grid; gap: 8px; width: min(560px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; padding: 12px 10px 12px 16px;
  border-radius: 18px; background: var(--surface); border: 1.5px solid var(--line); box-shadow: 0 12px 40px rgb(0 0 0 / .45);
}
.toast span { flex: 1; }
.toast.error { border-color: var(--error); }

.offer {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 0 20px 8px; padding: 12px 16px;
  border-radius: 20px; background: var(--surface); border: 1.5px solid var(--glow);
}
.offer p { flex: 1; min-width: 240px; font-size: 18px; }

/* ---- pincode screen: the same ring, quiet, with the field in its centre ---- */
.login {
  position: fixed; inset: 0; z-index: 100; background: var(--ground);
  display: grid; place-items: center; padding: 16px;
}
.login-ring { position: relative; width: min(92vw, 78vh, 460px); aspect-ratio: 1; }
.login-ring svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.login-ring circle { fill: none; stroke: var(--line); stroke-width: 10; }
.login-ring .login-sweep { stroke: var(--glow); stroke-linecap: round; stroke-dasharray: 22 78; animation: sweep 9s linear infinite; }
.login-core {
  position: absolute; inset: 15%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; text-align: center;
}
.login-core h1 { font-size: clamp(28px, 8vw, 40px); font-weight: 800; font-stretch: 75%; color: var(--glow); line-height: 1; }
.login-core label { color: var(--dim); }
.login-core input { max-width: 220px; text-align: center; font-size: 26px; letter-spacing: .3em; border-radius: 999px; }
.login-core .btn { min-width: 160px; }
.login-error { min-height: 2.9em; max-width: 26ch; font-size: 14px; color: var(--error); }
.login-ring.shake { animation: shake .3s; }

@keyframes sweep { to { stroke-dashoffset: -100; } }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }

@media (prefers-reduced-motion: reduce) {
  :root { transition: none; }
  .login-ring .login-sweep, .login-ring.shake { animation: none; }
}
