/* Swiss / International Typographic Style foundation shared by all demos.
   Black on white, one red accent, Helvetica stack, hard rules, no decoration. */

:root {
  --ink: #111111;
  --paper: #ffffff;
  --rule: #111111;
  --hairline: #d9d9d9;
  --red: #e30613;
  --muted: #6b6b6b;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  line-height: 1.4;
}

h1, h2, h3 {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

h1 { font-size: clamp(2.5rem, 6vw, 4.5rem); }
h2 { font-size: 1.5rem; }

a { color: inherit; }

.micro-label {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--red);
}

.meta { color: var(--muted); margin: 0.5rem 0 0; font-size: 0.85rem; }

.site-nav {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 2px solid var(--rule);
}

.site-nav .wordmark {
  font-weight: 700;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-decoration: none;
}

.site-nav .micro-label { color: var(--muted); }

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 3rem 1.5rem 4rem;
}

.page-header { margin-bottom: 2rem; }
.page-header h1 { margin-top: 0.25rem; }

/* Sync-state badges shared by all demos */
.badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.15rem 0.45rem;
  border: 1px solid var(--ink);
}

.badge-pending  { border-color: var(--red); color: var(--red); }
.badge-synced   { border-color: var(--hairline); color: var(--muted); }
.badge-rejected { background: var(--red); border-color: var(--red); color: var(--paper); }

/* Form controls: flat, ruled, no rounding */
input[type="text"], textarea {
  font-family: var(--font);
  font-size: 1rem;
  padding: 0.6rem 0.75rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
}

input[type="text"]:focus, textarea:focus {
  outline: 2px solid var(--red);
  outline-offset: -2px;
  border-color: var(--red);
}

input[type="submit"], button {
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0.6rem 1rem;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
}

input[type="submit"]:hover, button:hover { background: var(--red); border-color: var(--red); }

/* Shown when a new build takes over the service worker. Asking beats an
   unannounced reload, which would discard anything half-typed — so it sits at
   the top, clear of the composer it is protecting. */
#new-version {
  position: fixed;
  top: 4rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--paper);
  border: 2px solid var(--ink);
}

#new-version[hidden] { display: none; }

/* --- Sync inspector --------------------------------------------------------
   Fixed and out of flow, so opening it never reflows what it is describing —
   the page is only shifted over by the body padding below. */

#inspector {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  width: 24rem;
  max-width: 100vw;
  background: var(--ink);
  color: var(--paper);
  border-left: 2px solid var(--red);
  font-size: 0.7rem;
}

/* Make room instead of covering the page. Fixed positioning is viewport-based,
   so the panel itself is unaffected by this padding. */
body { padding-right: 24rem; }

@media (max-width: 60rem) {
  body { padding-right: 0; }
  #inspector { display: none; }
}

/* Sits in the same band as the site nav across the page: 46px tall, the same
   2px rule, and its label on the same baseline — hence the asymmetric padding
   (16 + 16px label + 12 + 2px border), which mirrors what baseline alignment
   does to the nav's own smaller label. */
#inspector header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.5rem 0.75rem;
  border-bottom: 2px solid rgba(255, 255, 255, 0.85);
}

.inspector-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.inspector-controls label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.inspector-controls button {
  margin-left: auto;
  padding: 0.3rem 0.6rem;
  font-size: 0.6rem;
  background: transparent;
  color: var(--paper);
  border-color: rgba(255, 255, 255, 0.4);
}

/* Newest first, so the freshest event is always in view without scrolling. */
.inspector-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.inspector-log li {
  display: grid;
  grid-template-columns: 3.6rem 1fr auto;
  gap: 0.5rem;
  padding: 0.4rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.inspector-kind { text-transform: uppercase; color: var(--red); }
.inspector-log li[data-kind="local"] .inspector-kind,
.inspector-log li[data-kind="assets"] .inspector-kind { color: #6ea8ff; }
.inspector-log li[data-kind="sync-pass"] .inspector-kind { color: #8f8f8f; }
.inspector-log li[data-kind="change"] .inspector-kind { color: #4ec9a0; }
.inspector-log li[data-kind="stream"] .inspector-kind { color: #c678dd; }

.inspector-path { overflow-wrap: anywhere; }
.inspector-meta { color: rgba(255, 255, 255, 0.55); white-space: nowrap; }
.inspector-log li[data-status="bad"] .inspector-meta { color: var(--red); }
.inspector-log li[data-status="warn"] .inspector-meta { color: #e5c07b; }

/* --- Inspector flow map ----------------------------------------------------
   Boxes and wires light up as the log records traffic on them. Everything is
   driven by data-active, set by inspector_controller.js. */

#inspector-flow {
  flex: 0 0 auto;
  width: 100%;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  font-family: var(--font);
}

.flow-zone rect {
  fill: none;
  stroke: rgba(255, 255, 255, 0.25);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.flow-zone-label {
  fill: rgba(255, 255, 255, 0.5);
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.flow-node rect {
  fill: none;
  stroke: rgba(255, 255, 255, 0.55);
  stroke-width: 1.5;
  transition: fill 240ms ease-out, stroke 240ms ease-out;
}

.flow-node text {
  fill: var(--paper);
  font-size: 9px;
  letter-spacing: 0.04em;
  text-anchor: middle;
}

/* A box doing work fills with the accent; it fades back on its own. */
.flow-node[data-active] rect {
  fill: var(--red);
  stroke: var(--red);
}

.flow-edge {
  fill: none;
  stroke: rgba(255, 255, 255, 0.4);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.flow-edge-label {
  fill: rgba(255, 255, 255, 0.5);
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* Active wire: the dashes march in the direction of travel, so up and down are
   distinguishable at a glance rather than by reading the label. */
.flow-edge[data-active] {
  stroke: var(--red);
  stroke-width: 2.5;
  animation: flow-march 600ms linear;
}

.flow-edge[data-active="down"] { animation-direction: reverse; }

/* A wire the simulated network has broken. */
.flow-edge[data-broken] {
  stroke: rgba(227, 6, 19, 0.45);
  stroke-dasharray: 2 6;
  animation: none;
}

@keyframes flow-march {
  from { stroke-dashoffset: 24; }
  to { stroke-dashoffset: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .flow-edge[data-active] { animation: none; }
}

/* Markers don't inherit the referencing path's stroke, so the arrowhead is
   coloured on its own and simply stays neutral while a wire pulses. */
#inspector-flow marker path { fill: rgba(255, 255, 255, 0.45); }

/* A stream that is held open, even while nothing crosses it — the difference
   between SSE and polling, made visible. */
.flow-edge[data-connected] {
  stroke: #4ec9a0;
  stroke-dasharray: none;
}

/* An active pulse still wins over the connected state. */
.flow-edge[data-active] {
  stroke: var(--red);
  stroke-dasharray: 4 4;
}
