:root {
  --background: #ffffff;
  --surface: #ffffff;
  --foreground: #171717;
  --muted: #5f6368;
  --border: #d9dbdf;
  --accent: #171717;
  --accent-text: #ffffff;
  --danger: #c5221f;
  --danger-text: #ffffff;
  --danger-soft: rgba(197, 34, 31, 0.1);
  --amber: #b06000;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --success-soft: rgba(30, 142, 62, 0.12);
  --success: #1e8e3e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --background: #0a0a0a;
    --surface: #111214;
    --foreground: #ededed;
    --muted: #a1a5ab;
    --border: #2c2e33;
    --accent: #ededed;
    --accent-text: #0a0a0a;
    --danger: #ea4335;
    --danger-text: #ffffff;
    --amber: #fbbc04;
    --success: #5bb974;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { font-size: clamp(1rem, calc(0.40625rem + min(1.3vh, 0.8vw)), 1.5rem); }
body { margin: 0; background: var(--background); color: var(--foreground); font-family: Arial, Helvetica, sans-serif; line-height: 1.45; }
a { color: inherit; text-underline-offset: 4px; }
h1 { font-size: 1.6rem; margin: 0; font-weight: 600; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 0.9rem; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: 0.02em; }

.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-box { width: 100%; max-width: 24rem; display: flex; flex-direction: column; gap: 1.25rem; }
.auth-footer { display: flex; flex-direction: column; gap: 0.75rem; font-size: 0.9rem; color: var(--muted); }
.divider { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 0.85rem; }
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid var(--border); }

.account-page { max-width: 42rem; margin: 0 auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1.25rem; }

.field { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; }
.field input, .field select { font: inherit; font-size: 1rem; padding: 0.6rem 0.75rem; border: 1px solid var(--border); border-radius: 0.5rem; background: var(--surface); color: var(--foreground); width: 100%; }
.field input:focus, .field select:focus { outline: 2px solid var(--foreground); outline-offset: 1px; }

.button { font: inherit; font-size: 0.95rem; padding: 0.6rem 1rem; border-radius: 0.5rem; border: 1px solid var(--border); background: transparent; color: var(--foreground); cursor: pointer; }
.button:disabled { opacity: 0.55; cursor: default; }
.button-primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.button-danger { background: var(--danger); color: var(--danger-text); border-color: var(--danger); }
.button-wide { width: 100%; }

.alert { border-radius: 0.5rem; padding: 0.7rem 0.9rem; font-size: 0.92rem; border: 1px solid; }
.alert-error { background: var(--danger-soft); border-color: var(--danger); }
.alert-success { background: var(--success-soft); border-color: var(--success); }
.alert-amber { background: var(--amber-soft); border-color: var(--amber); }
.alert-info { border-color: var(--border); }

.card { border: 1px solid var(--border); border-radius: 0.75rem; background: var(--surface); padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.confirm-panel { border: 1px solid var(--danger); border-radius: 0.5rem; padding: 0.9rem; display: flex; flex-direction: column; gap: 0.75rem; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list > li { padding: 0.8rem 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.6rem; }
.list > li:first-child { border-top: 0; padding-top: 0; }
.tag { font-size: 0.75rem; border: 1px solid var(--border); border-radius: 999px; padding: 0.05rem 0.5rem; color: var(--muted); }
.language-choice { display: flex; gap: 0.5rem; }
.link-button { font: inherit; background: none; border: 0; padding: 0; color: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }
.link-button[aria-current='true'] { font-weight: 700; text-decoration: none; }

@media (pointer: coarse) {
  .button, .field input, .field select { min-height: 2.75rem; }
}

.button-link { display: block; text-align: center; text-decoration: none; }

/* ---- the Event Monitor: a dark presenter screen, like the Hiltermann monitor ---- */
body:has(.monitor-page) { background: #0b0e14; overflow: hidden; }
.monitor-page {
  --bg: #0b0e14; --panel: #111620; --panel-2: #161c28; --line: #243044; --line-strong: #34425a;
  --text: #eef1f6; --text-2: #b4bdcc; --dim: #7d889a; --blue: #5b8cff; --ok: #3fb950; --bad: #f0524d; --warn: #e3a21a;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace;
  color-scheme: dark; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: clamp(13px, 0.95vw, 20px); line-height: 1.35;
  display: grid; grid-template-rows: auto minmax(0, 1fr); height: 100vh;
}
.monitor-page button { font: inherit; color: inherit; }

.top { display: flex; align-items: center; gap: 2rem; padding: 0.7rem 1.4rem; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, #121827, var(--bg)); flex-wrap: wrap; }
.top-brand { display: flex; align-items: center; gap: 0.9rem; min-width: 0; flex: 1 1 24rem; }
.top-brand h1 { white-space: nowrap; }
.logo { width: 2.8rem; height: 2.8rem; flex: none; }
.top-brand h1 { font-size: 1.6rem; font-weight: 700; }
.top-brand p { color: var(--text-2); font-size: 0.9rem; }
.stats { display: flex; gap: 2.4rem; }
.stat { display: flex; flex-direction: column; align-items: flex-end; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-of { color: var(--dim); font-size: 1.3rem; font-weight: 600; }
.stat-label { color: var(--text-2); font-size: 0.8rem; }
.actions { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; }
.who { color: var(--text-2); font-size: 0.85rem; }
.actions .language-choice { font-size: 0.85rem; color: var(--text-2); }
.org-choice { display: flex; flex-direction: column; gap: 0.1rem; }
.org-manage { color: var(--blue); font-size: 0.75rem; text-decoration: none; }
.org-manage:hover { text-decoration: underline; }
.org-choice select { font: inherit; font-size: 0.9rem; padding: 0.3rem 0.5rem; border-radius: 0.5rem; border: 1px solid var(--line-strong); background: var(--panel-2); color: var(--text); }
.live-pill { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0.9rem; border-radius: 999px; font-weight: 700; font-size: 0.95rem; letter-spacing: 0.04em; text-transform: uppercase; border: 1px solid currentColor; }
.live-pill i { width: 0.7rem; height: 0.7rem; border-radius: 50%; background: currentColor; }
.live-pill.live { color: var(--ok); }
.live-pill.live i { animation: breathe 2s ease-in-out infinite; }
.live-pill.reconnecting { color: var(--warn); }
.dark-button { padding: 0.45rem 1rem; border-radius: 0.6rem; border: 1px solid var(--line-strong); background: var(--panel-2); font-weight: 600; font-size: 0.95rem; cursor: pointer; }
.dark-button:hover { border-color: var(--blue); }
.dark-button.icon { padding: 0.45rem 0.55rem; line-height: 0; }
.dark-button.icon svg { width: 1.1rem; height: 1.1rem; }

.monitor-main { display: grid; grid-template-columns: minmax(0, 1fr) clamp(22rem, 28vw, 34rem); min-height: 0; }
.stage-column { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage-wrap { position: relative; flex: 1; min-height: 0; }
.stage-wrap monitor-stage { display: block; height: 100%; }
.stage { display: block; width: 100%; height: 100%; }
.side { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--line); background: var(--panel); }
.side monitor-event-log { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.edge { stroke: #2a3548; stroke-width: 2.5; transition: stroke 0.3s, opacity 0.3s; }
.edge.offline { stroke-dasharray: 6 8; opacity: 0.5; }
.edge.dim { opacity: 0.2; }
.focus-arrows { pointer-events: none; }
.focus-line { stroke: currentColor; stroke-width: 4; }
.focus-line.dashed { stroke-dasharray: 10 8; }
.focus-head { fill: currentColor; }
.bus-body { stroke: var(--blue); stroke-width: 4; }
.bus-ring { fill: none; stroke: #3a5caa; stroke-width: 2; stroke-dasharray: 3 9; transform-box: fill-box; transform-origin: center; animation: spin 60s linear infinite; }
.bus-title { fill: var(--text); font-size: 30px; font-weight: 800; letter-spacing: 0.06em; }
.bus-sub { fill: var(--text-2); font-size: 18px; }
.bus-sub.small { fill: var(--dim); font-size: 16px; }
.node { transition: opacity 0.4s; }
.node .card { fill: var(--panel-2); stroke: var(--line-strong); stroke-width: 2; }
.node.offline { opacity: 0.42; }
.node.offline .card { stroke-dasharray: 8 7; fill: #10141c; }
.node.dim { opacity: 0.18; }
.status-dot { fill: var(--ok); }
.node.offline .status-dot { fill: none; stroke: var(--dim); stroke-width: 3; }
.node-name { fill: var(--text); font-size: 25px; font-weight: 700; }
.badge-box { fill: none; stroke: #4a5873; stroke-width: 1.5; }
.badge-text { fill: var(--text-2); font-size: 13px; font-weight: 700; letter-spacing: 0.1em; }
.node-state { fill: var(--ok); font-size: 16px; font-weight: 600; }
.node.offline .node-state { fill: var(--dim); }
.node-label, .node-none { fill: var(--dim); font-size: 16px; }
.pill.on { stroke: #fff; stroke-width: 3; }
.flight-label { font-size: 21px; font-weight: 700; paint-order: stroke; stroke: var(--bg); stroke-width: 7px; stroke-linejoin: round; }

.legend-wrap { padding: 0.5rem 1.2rem 0.8rem; border-top: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 0.5rem; margin: 0; padding: 0; list-style: none; }
.chip { display: inline-flex; align-items: center; gap: 0.45rem; padding: 0.25rem 0.75rem 0.25rem 0.55rem; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--panel); font-size: 0.9rem; font-weight: 600; cursor: pointer; }
.chip:hover { border-color: var(--type); }
.chip.on { border-color: var(--type); background: color-mix(in srgb, var(--type) 22%, var(--panel)); }
.swatch { display: inline-block; flex: none; width: 0.85rem; height: 0.85rem; border-radius: 50%; background: var(--type); }
.legend-caption { margin-top: 0.45rem; color: var(--text-2); font-size: 0.85rem; }
.legend-caption strong { color: var(--text); }

.log { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0.9rem 1.2rem 0.6rem; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 1.3rem; }
.count { color: var(--text-2); font-size: 0.9rem; }
.log-empty { padding: 2rem 1.4rem; color: var(--text-2); display: flex; flex-direction: column; gap: 0.5rem; }
.log-empty p:first-child { font-size: 1.2rem; color: var(--text); }
.link { align-self: flex-start; padding: 0; border: 0; background: none; color: var(--blue) !important; font-size: 0.9rem; text-decoration: underline; cursor: pointer; }
.log-list { flex: 1; margin: 0; padding: 0; list-style: none; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.log-row { border-bottom: 1px solid var(--line); border-left: 5px solid var(--type); }
.log-row > button { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: baseline; column-gap: 0.8rem; width: 100%; padding: 0.6rem 1rem 0.65rem 0.9rem; border: 0; background: none; text-align: left; cursor: pointer; }
.log-row > button:hover { background: #151b27; }
.log-row.selected > button { background: #18223a; }
.log-row.live { animation: row-in 2.6s ease-out; }
.row-body { display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.row-top { display: flex; align-items: center; gap: 0.7rem; }
.time { color: var(--text-2); font-family: var(--mono); font-size: 0.95rem; font-variant-numeric: tabular-nums; }
.type { display: inline-flex; align-items: center; gap: 0.45rem; font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.seq { margin-left: auto; color: var(--dim); font-family: var(--mono); font-size: 0.85rem; }
.from { color: var(--text-2); font-size: 0.85rem; overflow-wrap: anywhere; }
.row-detail { padding: 0 1rem 0.8rem 0.9rem; display: flex; flex-direction: column; gap: 0.4rem; }
.event-data { margin: 0; padding: 0.7rem; border: 1px solid var(--line); border-radius: 0.5rem; background: var(--bg); font-family: var(--mono); font-size: 0.8rem; overflow-x: auto; color: var(--text-2); }
.log-more { padding: 0.8rem 1rem; }

@keyframes breathe { 50% { opacity: 0.35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes row-in { from { background: color-mix(in srgb, var(--type) 30%, transparent); } }
@media (prefers-reduced-motion: reduce) { .live-pill.live i, .bus-ring, .log-row.live { animation: none; } }

/* On a phone: the stage on top, then the types, then the log; the page scrolls. */
@media (max-width: 900px) {
  body:has(.monitor-page) { overflow: auto; }
  .monitor-page { height: auto; min-height: 100vh; }
  .top { gap: 0.8rem; }
  .top-brand { flex: 1 1 100%; }
  .stats { gap: 1.6rem; }
  .stat { align-items: flex-start; }
  .monitor-main { grid-template-columns: minmax(0, 1fr); }
  .stage-wrap { height: 80vw; flex: none; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .log-list { overflow: visible; }
}
