/* The order-flow diagram: Pictos PoS, SalesPulse and the AI agent.
   Loaded after the main stylesheet and built on its tokens, by the Work page
   and by the Recently pages, where the Pictos PoS and SalesPulse thread shows
   the same diagram. Its markup lives in work.html; the build copies it into
   that thread, so the two cannot drift.

   The diagram tells one story in four stops: a till at a venue, Pictos PoS,
   SalesPulse, left to right, and under the last two the AI agent that audits
   what they recorded. Beside the agent sits the owner's phone: the agent is
   also the assistant the owner asks about the numbers. On a phone the stops
   stack top to bottom. An order travels the route as a small ticket; each stop
   shows what the order changed there. */

.flow {
  position: relative;
  margin: 28px 0 40px;
  /* The layout answers to the width of the reading column, not the window:
     the column is narrow on mid-size screens where the side rail is showing. */
  container-type: inline-size;
}

.flow-grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 0.7fr) minmax(0, 1.05fr) minmax(0, 1.25fr);
  align-items: center;
  gap: 48px 32px;
}

/* Connecting lines, drawn by the script between the centres of the stops and
   hidden where the stops cover them. The dashes drift toward SalesPulse, so
   the direction of travel is visible even between orders. */
.flow-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.flow-lines line {
  stroke: var(--border-secondary);
  stroke-width: 1;
  stroke-dasharray: 3 5;
  animation: flow-drift 1s linear infinite;
}
/* The line an order is on right now. */
.flow-lines line.is-live {
  stroke: var(--accent);
  stroke-width: 1.5;
}
@keyframes flow-drift {
  to { stroke-dashoffset: -8; }
}

.flow-venues,
.flow-node { position: relative; }

.docs-article .flow p { margin: 0; }

/* Small captions that say what each readout is. */
.docs-article .flow .flow-label {
  margin: 0 0 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-secondary);
}
.docs-article .flow .flow-label-gap { margin-top: 14px; }
.flow-venues .flow-label { background: var(--background-default); }

.flow-venues { display: grid; gap: 14px; }
.flow-venue { display: grid; gap: 6px; justify-items: start; }
.flow-venue-name {
  font-size: 13px;
  font-weight: 550;
  color: var(--text-primary);
  background: var(--background-default);
}

.flow-src {
  padding: 6px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--background-default);
  border: 1px solid var(--border-secondary);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.4s, color 0.4s, transform 0.1s;
}
.flow-src:hover { border-color: var(--text-primary); }
.flow-src:active { transform: scale(0.96); }
.flow-src:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* The till that just rang something up. */
.flow-src.is-hit {
  border-color: var(--accent);
  color: var(--accent);
  transition-duration: 0s;
}

.flow-node {
  padding: 16px;
  background: var(--background-default);
  border: 1px solid var(--border-primary);
  border-radius: 5px;
  transition: border-color 0.6s, box-shadow 0.6s;
}
/* A stop lights up for a moment when an order reaches it. */
.flow-node.is-hit {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  transition-duration: 0s;
}

.docs-article .flow .flow-node-name {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Pictos PoS: the receipt keeps the last three lines, newest on top. */
.docs-article .flow-receipt {
  display: grid;
  gap: 0;
  min-height: 84px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  align-content: start;
}
.docs-article .flow-receipt li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  padding: 5px 0;
  border-bottom: 1px dashed var(--border-secondary);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-secondary);
}
.docs-article .flow-receipt li:first-child { color: var(--text-primary); }
.docs-article .flow-receipt li.is-new { animation: flow-print 0.35s cubic-bezier(0.2, 0.7, 0.2, 1); }
.docs-article .flow-receipt .flow-receipt-empty { border-bottom-color: transparent; }
@keyframes flow-print {
  from { opacity: 0; transform: translateY(-8px); }
}

.flow-stat {
  font-size: 13px;
  color: var(--text-secondary);
}
.flow-num {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 300;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* Stock on hand: one tick per unit, emptied from the right. */
.flow-stock {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 2px;
  margin: 10px 0 6px;
}
.flow-stock i {
  height: 10px;
  background: var(--text-primary);
  transition: opacity 0.3s;
}
.flow-stock i.is-gone { opacity: 0.12; }
.docs-article .flow #flow-note { margin: 0; }

/* SalesPulse: one row per business, kept apart. */
.flow-lane {
  display: grid;
  grid-template-columns: 5.4em minmax(0, 1fr) 9ch;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px solid var(--border-primary);
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
}
.flow-bar {
  height: 10px;
  background: var(--secondary-main);
}
.flow-bar i {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.flow-count {
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* The dashboard in miniature: earlier hours are fixed, the current hour is
   the last bar and grows with every order. */
.flow-hours {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  align-items: end;
  gap: 4px;
  height: 46px;
  border-bottom: 1px solid var(--border-secondary);
}
.flow-hour {
  background: var(--border-secondary);
  transition: height 0.4s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.flow-hour-1 { height: 18%; }
.flow-hour-2 { height: 26%; }
.flow-hour-3 { height: 44%; }
.flow-hour-4 { height: 62%; }
.flow-hour-5 { height: 38%; }
.flow-hour-6 { height: 30%; }
.flow-hour-7 { height: 52%; }
.flow-hour-8 { height: 8%; background: var(--accent); }

.docs-article .flow .flow-journal {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-primary);
  white-space: pre; /* one line per side of the entry, amounts aligned */
}
.docs-article .flow .flow-journal.is-new { animation: flow-print 0.35s cubic-bezier(0.2, 0.7, 0.2, 1); }

/* The AI agent: a fourth stop under Pictos PoS and SalesPulse, because it
   reads from both. It has two jobs, and the role it is doing lights up: after
   every order it audits the sale, the journal entry and the raw materials,
   and when the owner asks something it answers from the same numbers. */
.flow-agent {
  grid-column: 2 / 4;
  grid-row: 2;
}
.flow-agent-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
}
.docs-article .flow .flow-roles {
  display: flex;
  gap: 6px;
}
.flow-role {
  padding: 1px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-secondary);
  border: 1px solid var(--border-secondary);
  border-radius: 999px;
  transition: color 0.3s, border-color 0.3s, background-color 0.3s;
}
.flow-role.is-on {
  color: var(--primary-contrastText);
  background: var(--accent);
  border-color: var(--accent);
  transition-duration: 0s;
}
.docs-article .flow .flow-agent-stat { margin-top: 12px; }

/* The owner's phone: a short chat with the agent, newest exchange only, and
   the questions that can be tapped. */
.flow-owner {
  grid-column: 1;
  grid-row: 2;
  align-self: center;
  padding: 14px;
}
.docs-article .flow .flow-owner .flow-node-name { margin-bottom: 10px; }
.flow-owner-mark { flex: none; color: var(--text-primary); }
.docs-article .flow-chat {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 92px;
  margin: 0 0 10px;
  padding: 0;
  list-style: none;
}
.docs-article .flow-chat li {
  margin: 0;
  padding: 5px 8px;
  font-size: 12px;
  line-height: 1.4;
  border-radius: 8px;
}
.docs-article .flow-chat .flow-chat-empty {
  padding: 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}
.docs-article .flow-chat .flow-msg-q {
  justify-self: end;
  max-width: 92%;
  color: var(--text-primary);
  background: var(--secondary-main);
  border-bottom-right-radius: 2px;
}
.docs-article .flow-chat .flow-msg-a {
  justify-self: start;
  max-width: 96%;
  color: var(--text-primary);
  border: 1px solid var(--accent);
  border-bottom-left-radius: 2px;
}
.docs-article .flow-chat .flow-msg-a.is-typing {
  color: var(--accent);
  letter-spacing: 0.2em;
}
.docs-article .flow-chat li.is-new { animation: flow-print 0.35s cubic-bezier(0.2, 0.7, 0.2, 1); }
.flow-asks {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.flow-ask {
  padding: 3px 9px;
  font: inherit;
  font-size: 12px;
  color: var(--text-primary);
  background: var(--background-default);
  border: 1px solid var(--border-secondary);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.4s, color 0.4s, transform 0.1s;
}
.flow-ask:hover { border-color: var(--text-primary); }
.flow-ask:active { transform: scale(0.96); }
.flow-ask:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.flow-ask.is-hit {
  border-color: var(--accent);
  color: var(--accent);
  transition-duration: 0s;
}
.docs-article .flow .flow-agent .flow-node-name { margin-bottom: 10px; }
.flow-agent-mark {
  flex: none;
  color: var(--text-primary);
}
.docs-article .flow-checks {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.docs-article .flow-check {
  display: grid;
  align-content: start;
  gap: 4px;
  margin: 0;
  padding: 8px 0 0;
  border-top: 2px solid var(--border-primary);
  font-size: 13px;
  line-height: 1.4;
  transition: border-color 0.3s;
}
.flow-check-name {
  font-weight: 550;
  color: var(--text-primary);
}
.flow-check-state {
  justify-self: start;
  padding: 1px 7px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-secondary);
  border: 1px solid var(--border-secondary);
  border-radius: 999px;
  transition: color 0.3s, border-color 0.3s, background-color 0.3s;
}
.flow-check-note {
  min-height: 2.8em;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}
.docs-article .flow-check.is-checking { border-top-color: var(--accent); }
.flow-check.is-checking .flow-check-state {
  color: var(--accent);
  border-color: var(--accent);
}
.flow-check.is-ok .flow-check-state {
  color: var(--primary-contrastText);
  background: var(--accent);
  border-color: var(--accent);
}
.flow-check.is-flag .flow-check-state {
  color: var(--background-default);
  background: var(--text-primary);
  border-color: var(--text-primary);
}
.flow-check.is-ok .flow-check-note,
.flow-check.is-flag .flow-check-note { color: var(--text-primary); }
.flow-check.is-new .flow-check-note { animation: flow-print 0.35s cubic-bezier(0.2, 0.7, 0.2, 1); }

/* What the agent is reading at this moment, in the stop it came from. */
.flow-node .is-audited {
  outline: 1px dashed var(--accent);
  outline-offset: 3px;
}

/* The order itself: a ticket carrying what was rung up. */
.flow-dot {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 2;
  padding: 3px 9px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.4;
  white-space: nowrap;
  color: var(--primary-contrastText);
  background: var(--accent);
  border-radius: 3px;
  pointer-events: none;
}

/* A question on its way to the agent, and the answer on its way back, travel
   as outlined tickets so they read apart from orders. */
.flow-dot.flow-dot-chat {
  color: var(--accent);
  background: var(--background-default);
  border: 1px solid var(--accent);
}

/* The four steps, in order. The one happening now is in full ink. */
.docs-article .flow-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 32px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  counter-reset: flow-step;
}
.docs-article .flow-steps li {
  margin: 0;
  padding-top: 8px;
  border-top: 2px solid var(--border-primary);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-secondary);
  counter-increment: flow-step;
  transition: color 0.3s, border-color 0.3s;
}
.docs-article .flow-steps li::before {
  content: counter(flow-step);
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
}
/* Set, not only counted: on a narrow column the steps not happening are
   hidden, and a hidden step does not count, so the one shown would read 1. */
.docs-article .flow-steps li:nth-child(2) { counter-set: flow-step 2; }
.docs-article .flow-steps li:nth-child(3) { counter-set: flow-step 3; }
.docs-article .flow-steps li:nth-child(4) { counter-set: flow-step 4; }
.docs-article .flow-steps li.is-on {
  color: var(--text-primary);
  border-top-color: var(--accent);
}


/* Narrow column: the stops stack, with room between them for the ticket to
   travel in the open. Each venue's tills sit in one row beside its name, the
   receipt keeps two lines instead of three, and only the step happening now
   is shown, so the diagram is shorter and less crowded. */
@container (max-width: 640px) {
  .flow-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 46px;
  }
  .flow-venues { gap: 10px; }
  .flow-venues .flow-label { margin: 0; }
  .flow-venue {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
  }
  .flow-venue-name { min-width: 5.6em; }

  .flow-node { padding: 14px; }
  .docs-article .flow .flow-node-name { margin-bottom: 10px; }
  .docs-article .flow-receipt { min-height: 56px; margin-bottom: 8px; }
  .docs-article .flow-receipt li:nth-child(n + 3) { display: none; }

  .flow-agent,
  .flow-owner { grid-column: auto; grid-row: auto; }
  .docs-article .flow-chat { min-height: 64px; }
  .docs-article .flow-checks { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .docs-article .flow-check {
    grid-template-columns: 7.5em auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 7px 0;
    border-top-width: 1px;
  }
  .flow-check-note { min-height: 0; text-align: right; }

  .docs-article .flow-steps {
    display: block;
    min-height: 4.6em;
    margin-top: 14px;
  }
  .docs-article .flow-steps li { display: none; }
  .docs-article .flow-steps li.is-on { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  .flow-lines line { animation: none; }
  .flow-bar i,
  .flow-hour,
  .flow-stock i,
  .flow-node,
  .flow-src,
  .flow-ask,
  .flow-role,
  .docs-article .flow-check,
  .flow-check-state,
  .docs-article .flow-steps li { transition: none; }
  .flow-check.is-new .flow-check-note,
  .docs-article .flow-chat li.is-new { animation: none; }
  .docs-article .flow-receipt li.is-new,
  .docs-article .flow .flow-journal.is-new { animation: none; }
}
