:root {
  /* ------------------------------------------------------------------
     Atlas Visual Language — single source of truth.
     Dark-Atlas is the dominant theme; light tokens redefine the same
     semantic names in the light @media block. Components consume only
     the semantic --bg/--fg/--accent/--err etc. — never the raw hex.
     If you tune tokens, tune all four CSS files in the same diff.
     ------------------------------------------------------------------ */
  --atlas-petrol:    #153937;
  --atlas-petrol-2:  #102b29;
  --atlas-teal:      #1F4E4A;
  --atlas-teal-2:    #29605B;
  --atlas-ochre:     #E6A24A;
  --atlas-ochre-2:   #C7873A;
  --atlas-sand:      #F2D6A2;
  --atlas-sand-mute: #C9B385;
  --atlas-sage:      #7FA39A;
  --atlas-sage-2:    #6A8C84;
  --atlas-coral:     #D97A5B;
  --atlas-terracotta:#A63D2F;
  --atlas-burnt:     #C65A2E;
  --atlas-clay:      #8C4A2F;

  --atlas-grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.05 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");

  --bg:           var(--atlas-petrol-2);
  --bg-elev:      var(--atlas-petrol);
  --bg-raised:   var(--atlas-teal);
  --bg-input:    var(--atlas-teal);
  --fg:          var(--atlas-sand);
  --fg-muted:    var(--atlas-sand-mute);
  --accent:      var(--atlas-ochre);
  --accent-hov:  var(--atlas-ochre-2);
  --accent-fade: rgba(230, 162, 74, 0.18);
  --user-bg:     var(--atlas-teal-2);
  --oji-bg:      rgba(31, 78, 74, 0.55);
  --border:      rgba(242, 214, 162, 0.10);
  --border-strong: rgba(242, 214, 162, 0.22);
  --warning:     var(--atlas-coral);
  --error:       var(--atlas-terracotta);
  --error-fg:    #F4C9B8;
  --at-cap:      var(--atlas-burnt);
  --focus-ring:  var(--atlas-ochre);

  --secondary:     var(--atlas-sage);
  --secondary-hov: var(--atlas-sage-2);
  --branch-glow:   rgba(230, 162, 74, 0.30);

  --font-ui: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Helvetica Neue", sans-serif;
  --font-headline: ui-serif, "Playfair Display", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 22px;

  --shadow-1: 0 1px 0 rgba(0, 0, 0, 0.25);
  --shadow-2: 0 6px 18px rgba(0, 0, 0, 0.35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg:           #F6EFE2;
    --bg-elev:      #FBF6EC;
    --bg-raised:    #F2D6A2;
    --bg-input:    #FEFCF8;
    --fg:          #153937;
    --fg-muted:    #4A6E69;
    --accent:      #C7873A;
    --accent-hov:  #A86A26;
    --accent-fade: rgba(199, 135, 58, 0.16);
    --user-bg:     #F2D6A2;
    --oji-bg:      #FBF6EC;
    --border:      rgba(21, 57, 55, 0.12);
    --border-strong: rgba(21, 57, 55, 0.25);
    --error-fg:    #6B1C12;
    --secondary:     #7FA39A;
    --secondary-hov: #6A8C84;
    --branch-glow:   rgba(230, 162, 74, 0.22);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: var(--atlas-grain);
  background-size: 160px 160px;
  pointer-events: none;
  z-index: 0;
  opacity: 0.9;
}

body { display: flex; flex-direction: column; }

header { position: relative; z-index: 10; }
main   { position: relative; z-index: 1; }

/* ------------------ Header ------------------ */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  min-height: 56px;
}

.brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-name {
  font-family: var(--font-headline);
  font-weight: 600;
  letter-spacing: 0.01em;
  font-size: 1.15rem;
  color: var(--fg);
}
.brand-sep { color: var(--fg-muted); }
.brand-sub {
  font-family: var(--font-headline);
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--fg-muted);
  letter-spacing: 0.02em;
}
.dot {
  width: 12px;
  height: 12px;
  background: var(--accent);
  display: inline-block;
  clip-path: polygon(50% 0%, 65% 35%, 100% 50%, 65% 65%, 50% 100%, 35% 65%, 0% 50%, 35% 35%);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}
.surface-nav {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex-wrap: wrap;
}
.surface-link {
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: color 120ms ease, background-color 120ms ease;
}
.surface-link:hover { color: var(--fg); background: var(--accent-fade); }
.surface-link:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.surface-link.is-current {
  color: var(--fg);
  background: var(--accent-fade);
  font-weight: 600;
}

.account-wrap { position: relative; }
.account-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-raised);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.25rem 0.6rem 0.25rem 0.3rem;
  font-size: 0.85rem;
  cursor: pointer;
  max-width: 240px;
  min-height: 36px;
}
.account-chip:hover { border-color: var(--accent); }
.account-chip:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.account-chip .avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--atlas-ochre);
  color: var(--atlas-petrol);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.account-chip .email-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-muted);
}
.account-chip .caret {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--fg-muted);
  margin-right: 2px;
}
.account-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  min-width: 220px;
  padding: 0.4rem;
  z-index: 20;
}
.account-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--fg);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  min-height: 36px;
}
.account-menu button:hover { background: var(--accent-fade); }
.account-menu button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: -2px; }
.account-menu .menu-section {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.account-menu hr { border: none; border-top: 1px solid var(--border); margin: 0.3rem 0; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ------------------ Sign-in / access denied ------------------ */
.signin-wrap {
  margin: auto;
  text-align: center;
  padding: 2rem 1.25rem;
  max-width: 460px;
  width: 100%;
}
.signin-medallion {
  width: 88px;
  height: 88px;
  margin: 0 auto 1.5rem;
  color: var(--accent);
  filter: drop-shadow(0 1px 0 rgba(0,0,0,0.2));
}
.signin-headline {
  font-family: var(--font-headline);
  font-size: 1.75rem;
  color: var(--fg);
  margin: 0 0 0.5rem;
  letter-spacing: 0.005em;
}
.signin-prose { color: var(--fg-muted); margin: 0 0 1.75rem; font-size: 0.95rem; }
.signin-prose strong { color: var(--fg); font-weight: 600; }
.signin-error {
  margin-top: 1.25rem;
  color: var(--error-fg);
  background: rgba(166, 61, 47, 0.18);
  border: 1px solid var(--error);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
}

.access-denied {
  margin: auto;
  text-align: center;
  padding: 2.5rem 1.5rem;
  max-width: 460px;
}
.access-denied .medallion {
  width: 72px;
  height: 72px;
  margin: 0 auto 1.25rem;
  color: var(--at-cap);
}
.access-denied h2 {
  font-family: var(--font-headline);
  color: var(--fg);
  margin: 0 0 0.5rem;
  font-size: 1.4rem;
}
.access-denied p { color: var(--fg-muted); margin: 0 0 1.5rem; }
.access-denied .email-shown {
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: 0.9rem;
}
.access-denied button {
  background: var(--accent);
  color: var(--atlas-petrol);
  border: none;
  border-radius: var(--radius-md);
  padding: 0.65rem 1.2rem;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}
.access-denied button:hover { background: var(--accent-hov); }
.access-denied button:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ------------------ Flow wrap ------------------ */
.flow-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2rem;
  opacity: 1;
}
.flow-wrap.fade-in { animation: oji-fade-in 220ms ease both; }
@keyframes oji-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

.flow-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.section-title {
  font-family: var(--font-headline);
  font-size: 1.35rem;
  color: var(--fg);
  margin: 0;
  letter-spacing: 0.005em;
}
.flow-count {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--fg-muted);
  transition: color 160ms ease, background-color 160ms ease;
}
.flow-wrap.has-live-active .flow-count {
  color: var(--atlas-petrol);
  background: var(--accent);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.poll-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-muted);
  opacity: 0.5;
  transition: background-color 200ms ease, opacity 200ms ease;
}
.poll-status.is-live { background: var(--secondary); opacity: 0.9; }
.poll-status.is-stale { background: var(--fg-muted); opacity: 0.4; }
.poll-status.is-error { background: var(--at-cap); opacity: 0.9; }

.flow-controls { margin-left: auto; display: flex; align-items: center; gap: 0.5rem; }
.flow-toggle {
  background: var(--bg-raised);
  color: var(--fg);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.flow-toggle::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--secondary);
}
.flow-toggle[aria-pressed="true"]::before { background: var(--accent); }
.flow-toggle:hover { border-color: var(--accent); }
.flow-toggle:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.resume-pill {
  background: var(--accent);
  color: var(--atlas-petrol);
  border: none;
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 32px;
}
.resume-pill:hover { background: var(--accent-hov); }
.resume-pill:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.error-strip {
  margin-top: 0.75rem;
  background: rgba(166, 61, 47, 0.16);
  border: 1px solid var(--error);
  color: var(--error-fg);
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
}

.thinking-strip {
  padding: 0 0.25rem;
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  opacity: 0;
  transition: height 180ms ease, opacity 180ms ease, padding 180ms ease;
}
.thinking-strip.is-active {
  height: 22px;
  padding: 0.5rem 0.25rem 0.25rem;
  opacity: 1;
}
.thinking-strip .shape {
  width: 8px;
  height: 8px;
  background: var(--accent);
  opacity: 0.3;
  animation: oji-thinking-pulse 1.4s ease-in-out infinite;
}
.thinking-strip .shape.s-triangle {
  background: transparent;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 9px solid var(--accent);
}
.thinking-strip .shape.s-diamond { transform: rotate(45deg); animation-delay: 0.18s; }
.thinking-strip .shape.s-circle { border-radius: 50%; animation-delay: 0.36s; }
@keyframes oji-thinking-pulse {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 1.0; }
}

/* ------------------ Live spotlight (projector legibility) ------------------ */
.flow-spotlight {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.85rem;
  padding: 1rem 1.15rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  box-shadow: var(--shadow-1);
  transition: border-color 220ms ease, background-color 220ms ease, box-shadow 220ms ease;
}
.flow-spotlight.is-idle {
  opacity: 0.82;
}
.flow-spotlight.is-live {
  border-color: var(--accent);
  background: linear-gradient(
    135deg,
    rgba(230, 162, 74, 0.22) 0%,
    var(--bg-elev) 55%,
    var(--bg-raised) 100%
  );
  box-shadow:
    0 0 0 1px rgba(230, 162, 74, 0.35),
    0 8px 28px rgba(230, 162, 74, 0.18);
  animation: flow-spotlight-breathe 2.8s ease-in-out infinite;
}
.flow-spotlight-mark {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  background: var(--fg-muted);
  clip-path: polygon(50% 0%, 65% 35%, 100% 50%, 65% 65%, 50% 100%, 35% 65%, 0% 50%, 35% 35%);
  opacity: 0.45;
  transition: background-color 220ms ease, opacity 220ms ease, transform 220ms ease;
}
.flow-spotlight.is-live .flow-spotlight-mark {
  background: var(--accent);
  opacity: 1;
  animation: flow-spotlight-pulse 1.6s ease-in-out infinite;
}
.flow-spotlight-copy { min-width: 0; flex: 1; }
.flow-spotlight-kicker {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 0.2rem;
}
.flow-spotlight.is-live .flow-spotlight-kicker {
  color: var(--accent);
}
.flow-spotlight-name {
  margin: 0;
  font-family: var(--font-headline);
  font-size: clamp(1.35rem, 3.2vw, 2.35rem);
  font-weight: 700;
  line-height: 1.15;
  color: var(--fg);
  letter-spacing: 0.02em;
  word-break: break-word;
}
.flow-spotlight.is-live .flow-spotlight-name {
  color: var(--atlas-sand);
  text-shadow: 0 1px 0 rgba(16, 43, 41, 0.45);
}
@keyframes flow-spotlight-breathe {
  0%, 100% { box-shadow: 0 0 0 1px rgba(230, 162, 74, 0.28), 0 8px 24px rgba(230, 162, 74, 0.14); }
  50%      { box-shadow: 0 0 0 2px rgba(230, 162, 74, 0.5), 0 12px 36px rgba(230, 162, 74, 0.26); }
}
@keyframes flow-spotlight-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.12); }
}

.flow-legend {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
  padding: 0.75rem 0.1rem 0.35rem;
  font-size: 0.82rem;
  color: var(--fg-muted);
  font-family: var(--font-mono);
}
.legend-item { display: inline-flex; align-items: center; gap: 0.45rem; }
.node-dot {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  display: inline-block;
  border: 1px solid var(--border-strong);
}
.node-dot.is-active { background: var(--accent); border-color: var(--accent); }
.node-dot.is-recent { background: var(--atlas-coral); border-color: var(--atlas-coral); }
.node-dot.is-idle { background: transparent; }

.flow-tree-shell {
  margin-top: 0.6rem;
  border: 1px solid rgba(21, 57, 55, 0.24);
  border-radius: var(--radius-xl);
  background: var(--atlas-ochre);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  min-height: 0;
  flex: 1;
  transition: box-shadow 280ms ease;
}
.flow-wrap.has-live-active .flow-tree-shell {
  box-shadow:
    0 0 0 2px rgba(230, 162, 74, 0.28),
    0 10px 32px rgba(16, 43, 41, 0.35);
}
.flow-tree {
  position: relative;
  min-height: 620px;
  width: 100%;
  background: var(--atlas-ochre);
}
.flow-tree-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.flow-tree-links line {
  stroke: var(--atlas-teal);
  stroke-width: 3;
  stroke-linecap: round;
  opacity: 0.7;
}

.soil-layer {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
}
.soil-layer-1 {
  bottom: 0;
  height: 28%;
  background: var(--atlas-petrol);
}
.soil-layer-2 {
  bottom: 3%;
  left: 4%;
  right: 4%;
  height: 19%;
  background: var(--atlas-clay);
  border-radius: 999px 999px 0 0;
}
.soil-layer-3 {
  bottom: 9%;
  left: 8%;
  right: 8%;
  height: 11%;
  background: var(--atlas-ochre);
  border-radius: 999px 999px 0 0;
  border: 1px solid rgba(21, 57, 55, 0.22);
}

.agent-node {
  --node-intensity: 0;
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  min-width: 126px;
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--fg);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 0 calc(20px * var(--node-intensity)) rgba(230, 162, 74, calc(0.55 * var(--node-intensity)));
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease, opacity 160ms ease;
}
.agent-node:hover { border-color: var(--accent); }
.agent-node:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

.agent-name {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  line-height: 1.2;
}
.agent-state {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.72rem;
  color: var(--fg-muted);
  line-height: 1.2;
}

.node-cortex {
  z-index: 3;
  min-width: 140px;
  border-radius: 999px;
  border-width: 2px;
}
.node-oji {
  z-index: 3;
  min-width: 150px;
  border-radius: 999px;
  background: rgba(16, 43, 41, 0.94);
}
.node-branch { z-index: 2; }

.agent-node.is-idle {
  opacity: 0.78;
  border-style: dashed;
}
.agent-node.is-idle .agent-state { color: var(--fg-muted); }

.agent-node.is-recent {
  opacity: calc(0.4 + (0.6 * var(--node-intensity)));
  border-style: solid;
  border-color: var(--secondary);
}
.agent-node.is-recent .agent-state { color: var(--secondary); }

.agent-node.is-active {
  border-style: solid;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(230, 162, 74, 0.25), 0 0 18px var(--branch-glow);
  animation: node-pulse 1.8s ease-in-out infinite;
}
.agent-node.is-active .agent-state { color: var(--accent); }

@keyframes node-pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(230, 162, 74, 0.22), 0 0 10px rgba(230, 162, 74, 0.2); }
  50% { box-shadow: 0 0 0 1px rgba(230, 162, 74, 0.4), 0 0 24px rgba(230, 162, 74, 0.34); }
}

/* ------------------ Detail drawer ------------------ */
.flow-detail-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 22, 21, 0.55);
  z-index: 90;
}
.flow-detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(480px, 92vw);
  background: var(--bg-elev);
  border-left: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2);
  z-index: 100;
  display: flex;
  flex-direction: column;
  animation: oji-drawer-in 200ms ease both;
}
@keyframes oji-drawer-in {
  from { transform: translateX(12px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
.flow-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.flow-detail-head h3 {
  font-family: var(--font-headline);
  font-size: 1.2rem;
  color: var(--fg);
  margin: 0;
}
.flow-detail-close {
  background: transparent;
  border: none;
  color: var(--fg-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
}
.flow-detail-close:hover { color: var(--fg); background: var(--accent-fade); }
.flow-detail-close:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.flow-detail-status {
  margin: 0.85rem 1.1rem 0;
  color: var(--error-fg);
  background: rgba(166, 61, 47, 0.18);
  border: 1px solid var(--error);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.8rem;
  font-size: 0.88rem;
}
.flow-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.detail-section { display: flex; flex-direction: column; gap: 0.4rem; }
.detail-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-muted);
}
.detail-query {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.8rem;
  color: var(--fg);
  font-size: 0.93rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.detail-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--fg-muted);
}
.detail-stage {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--oji-bg);
}
.detail-stage.is-fault { border-color: var(--at-cap); }
.detail-stage-head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.detail-stage-name {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  color: var(--fg);
}
.detail-stage-state {
  font-size: 0.7rem;
  color: var(--fg-muted);
  margin-left: auto;
}
.detail-stage-state.is-fired { color: var(--secondary); }
.detail-stage-state.is-fault { color: var(--error-fg); }
.detail-summary {
  font-size: 0.88rem;
  color: var(--fg-muted);
  line-height: 1.5;
}
.detail-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.detail-chip {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-raised);
  color: var(--fg-muted);
}
.detail-chip.is-fault { background: rgba(166, 61, 47, 0.2); color: var(--error-fg); border: 1px solid var(--error); }
.detail-list { margin: 0; padding-left: 1.1rem; color: var(--fg-muted); font-size: 0.88rem; line-height: 1.5; }
.detail-empty { color: var(--fg-muted); font-size: 0.85rem; opacity: 0.8; }

.hidden { display: none !important; }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------ Reduced motion ------------------ */
@media (prefers-reduced-motion: reduce) {
  .thinking-strip .shape,
  .thinking-strip .shape.s-diamond,
  .thinking-strip .shape.s-circle {
    animation: none;
    opacity: 0.7;
  }
  .flow-wrap.fade-in,
  .flow-detail-panel,
  .agent-node.is-active { animation: none; }
  .poll-status,
  .flow-toggle,
  .agent-node { transition: none; }
}

/* ------------------ Mobile ------------------ */
@media (max-width: 780px) {
  .flow-wrap { padding: 0.85rem 0.65rem 1.5rem; }
  .section-title { font-size: 1.15rem; }

  .flow-tree {
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
    padding: 0.9rem 0.7rem 1rem;
  }

  .flow-tree-links,
  .soil-band { display: none; }

  .agent-node {
    position: static;
    transform: none;
    width: 100%;
    min-width: 0;
  }
  .node-cortex,
  .node-oji { grid-column: 1 / -1; }

  .flow-detail-panel { width: 100vw; }
}

@media (max-width: 480px) {
  header {
    padding: 0.6rem 0.85rem;
    padding-top: calc(0.6rem + env(safe-area-inset-top, 0px));
  }
  .brand-name { font-size: 1.05rem; }
  .brand-sub { font-size: 0.85rem; }
  .account-chip { max-width: 120px; }
  .account-chip .email-text { font-size: 0.8rem; }
  .surface-link { font-size: 0.78rem; padding: 0.25rem 0.4rem; }
  .flow-tree { grid-template-columns: 1fr; }
}

/* =================================================================
   Tree SVG — Tier 1 brand-aware tree v2
   Real tree composition: layered soil, Deep Teal trunk, faceted leaf
   polygons on curved branches, Atlas medallion for Oji. Replaces the
   prior topology-with-rectangles approach.
   ================================================================= */
.flow-tree-svg {
  display: block;
  width: 100%;
  max-width: 1100px;
  height: auto;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  overflow: visible;
}

/* Atmosphere — Warm Ochre 60-70% dominance per AVL §4 */
.flow-tree-svg .canvas-bg {
  fill: var(--atlas-ochre);
}

/* Solar accent — Atlas-approved §6 symbolic motif. Faint, never focal. */
.flow-tree-svg .sun-mark {
  fill: var(--atlas-burnt);
  opacity: 0.09;
}

/* Soil layers — back to front, increasingly warmer */
.flow-tree-svg .soil-back  { fill: var(--atlas-petrol-2); opacity: 0.95; }
.flow-tree-svg .soil-mid   { fill: var(--atlas-clay); opacity: 0.92; } /* Clay Brown */
.flow-tree-svg .soil-front { fill: var(--atlas-ochre-2); opacity: 0.9; }

/* Trunk — Deep Teal, tapered polygon with subtle vertical grain */
.flow-tree-svg .trunk {
  fill: var(--atlas-teal);
  stroke: var(--atlas-petrol);
  stroke-width: 1.5;
  transition: fill 1000ms ease;
}
.flow-tree-svg .trunk-grain {
  stroke: var(--atlas-petrol);
  stroke-width: 2;
  opacity: 0.55;
}
.flow-tree-svg .trunk-label {
  fill: var(--atlas-sand);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.10em;
  text-transform: uppercase;
}
.flow-tree-svg .agent-cortex.is-active .trunk {
  fill: var(--atlas-teal-2);
  stroke: var(--atlas-ochre);
  stroke-width: 3;
  filter: url(#atlas-active-glow);
}
.flow-tree-svg .agent-cortex.is-active .trunk-label {
  font-size: 17px;
  font-weight: 800;
  fill: var(--atlas-ochre);
}
.flow-tree-svg .agent-cortex.is-recent .trunk { fill: var(--atlas-teal); }

/* Oji medallion — Atlas brand mark embedded at top of soil */
.flow-tree-svg .oji-medallion {
  fill: var(--atlas-teal);
  stroke: var(--atlas-sand);
  stroke-width: 1.5;
  transition: fill 1000ms ease, transform 1000ms ease;
  transform-origin: center;
  transform-box: fill-box;
}
.flow-tree-svg .oji-label {
  fill: var(--atlas-petrol-2);
  font-family: var(--font-headline);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.12em;
}
.flow-tree-svg .agent-oji.is-active .oji-medallion {
  fill: var(--atlas-ochre);
  stroke: var(--atlas-petrol);
  stroke-width: 3;
  filter: url(#atlas-active-glow);
}
.flow-tree-svg .agent-oji.is-active .oji-label {
  font-size: 28px;
  fill: var(--atlas-petrol-2);
  font-weight: 800;
}
.flow-tree-svg .agent-oji.is-recent .oji-medallion {
  fill: var(--atlas-coral);
}

/* Branches — Deep Teal curved paths from trunk to leaf */
.flow-tree-svg .branch {
  fill: none;
  stroke: var(--atlas-teal);
  stroke-width: 4;
  stroke-linecap: round;
  opacity: 0.92;
  transition: stroke 1000ms ease, stroke-width 1000ms ease;
}
.flow-tree-svg .agent.is-active .branch {
  stroke: var(--atlas-ochre);
  stroke-width: 7;
  opacity: 1;
  filter: url(#atlas-active-glow);
}

/* Leaves — faceted polygons, flat fills only (Atlas hard rule: no gradients) */
.flow-tree-svg .leaf-shape {
  fill: var(--atlas-sage);
  stroke: var(--atlas-petrol);
  stroke-width: 1.5;
  transition: fill 1200ms ease, transform 1200ms ease;
  transform-origin: center;
  transform-box: fill-box;
}
.flow-tree-svg .leaf-label {
  fill: var(--atlas-petrol-2);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  pointer-events: none;
}
.flow-tree-svg .agent.is-active .leaf-label {
  font-size: clamp(15px, 1.6vw, 20px);
  font-weight: 800;
  fill: var(--atlas-petrol-2);
  stroke: var(--atlas-sand);
  stroke-width: 0.35px;
  paint-order: stroke fill;
}

/* State colors per Atlas distribution rule */
.flow-tree-svg .agent.is-idle   .leaf-shape { fill: var(--atlas-sage); }
.flow-tree-svg .agent.is-recent .leaf-shape { fill: var(--atlas-coral); }
/* Sunlight pulse — ceremonial; amplified for projector legibility */
@keyframes sunlightPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.14); }
}
.flow-tree-svg .agent.is-active > .leaf {
  filter: url(#atlas-active-glow);
}
.flow-tree-svg .agent.is-active .leaf-shape {
  fill: var(--atlas-ochre);
  stroke: var(--atlas-petrol);
  stroke-width: 2.5;
  transform-origin: center;
  transform-box: fill-box;
  animation: sunlightPulse 2.6s ease-in-out infinite;
}

/* De-emphasise non-active nodes when something is live — room-scale focus */
.flow-tree-shell:has(.agent.is-active) .agent.is-idle {
  opacity: 0.34;
}
.flow-tree-shell:has(.agent.is-active) .agent.is-recent {
  opacity: 0.58;
}
.flow-tree-shell:has(.agent.is-active) .agent.is-active {
  opacity: 1;
}

/* Hover + focus — geometric not glossy */
.flow-tree-svg .agent { cursor: pointer; }
.flow-tree-svg .agent:hover .leaf-shape { stroke-width: 2.5; }
.flow-tree-svg .agent:focus { outline: none; }
.flow-tree-svg .agent:focus-visible .leaf-shape {
  stroke: var(--focus-ring);
  stroke-width: 3;
}
.flow-tree-svg .agent-cortex:focus-visible .trunk {
  stroke: var(--focus-ring);
  stroke-width: 3;
}
.flow-tree-svg .agent-oji:focus-visible .oji-medallion {
  stroke: var(--focus-ring);
  stroke-width: 2.5;
}

/* Projector / wide — extra legibility for conference screens */
@media (min-width: 900px) {
  .flow-spotlight-name { font-size: 2.5rem; }
  .flow-legend { font-size: 0.9rem; }
  .node-dot { width: 13px; height: 13px; }
  .flow-tree-svg .leaf-label { font-size: 14px; }
  .flow-tree-svg .agent.is-active .leaf-label { font-size: 22px; }
  .flow-tree-svg .trunk-label { font-size: 15px; }
  .flow-tree-svg .agent-cortex.is-active .trunk-label { font-size: 19px; }
  .flow-tree-svg .oji-label { font-size: 26px; }
  .flow-tree-svg .agent-oji.is-active .oji-label { font-size: 32px; }
}

/* Mobile — SVG handles via viewBox; bump labels for touch */
@media (max-width: 600px) {
  .flow-spotlight {
    padding: 0.85rem 0.9rem;
    gap: 0.75rem;
  }
  .flow-spotlight-name { font-size: 1.25rem; }
  .flow-tree-svg .leaf-label,
  .flow-tree-svg .trunk-label,
  .flow-tree-svg .oji-label {
    font-size: 14px;
  }
  .flow-tree-svg .agent.is-active .leaf-label { font-size: 16px; }
}

/* Reduced motion — honor user preference */
@media (prefers-reduced-motion: reduce) {
  .flow-spotlight.is-live,
  .flow-spotlight.is-live .flow-spotlight-mark { animation: none; }
  .flow-tree-svg .agent.is-active .leaf-shape { animation: none; }
  .flow-tree-svg * { transition: none !important; }
}
