Skip to content

The OSINT investigator's workbench. One case, one folder, every tool. Local-first: your media and your investigations never leave your machine.

JavaScript
25.7 KB
Raw Blame
<script>
  import { onDestroy, untrack } from 'svelte';
  import {
    uiState,
    initSession,
    caseState,
    reloadCase,
    toast,
    updateState,
    updatesState,
    prefs,
    checkForUpdatesOnStart,
    toggleTheme,
    appInfo,
    keepOnboarding,
  } from './lib/state.svelte.js';
  import { api } from './lib/api.js';
  import { updateBadges } from './lib/staleness.js';
  import { startEvents, onEvent } from './lib/events.js';
  import {
    CASE_WORKSPACE,
    HOME_WORKSPACE,
    WORKSPACES,
    TOOL_LABELS,
    sidebarOpenForWorkspace,
    workspaceOf,
    toolFromHash,
  } from './lib/workspaces.js';
  import { readSolo, splitHash } from './lib/hash.js';
  import { caseShown, installBackButton, showTool } from './lib/backButton.js';
  import { landingFor } from './lib/guide.js';
  import { openGuide, openIssueReport } from './lib/navigate.js';
  import { listenToGuide } from './lib/guideWindow.js';
  import { openFindExample } from './lib/findExample.js';
  import { leaveFullscreen } from './lib/fullscreen.js';
  import { createToolLoader } from './lib/toolLoader.js';
  import { loadEntityTypes } from './lib/entityTypes.svelte.js';
  import Icon from './components/Icon.svelte';
  import Logo from './components/Logo.svelte';
  import Wordmark from './components/Wordmark.svelte';
  import CaseSwitcher from './components/CaseSwitcher.svelte';
  import CaseSidebar from './components/CaseSidebar.svelte';
  import Toasts from './components/Toasts.svelte';
  import UpdateModal from './components/UpdateModal.svelte';
  import DetectActivity from './components/DetectActivity.svelte';
  import PlateActivity from './components/PlateActivity.svelte';
  import { plateExport } from './lib/plate/exportRun.svelte.js';
  import WorkspaceStopped from './components/WorkspaceStopped.svelte';
  import NoteBar from './components/NoteBar.svelte';
  import MoveDialog from './components/MoveDialog.svelte';
  import CommandPalette from './components/CommandPalette.svelte';
  import GuideDialog from './components/GuideDialog.svelte';
  import Onboarding from './components/Onboarding.svelte';
  import { closedThisStart, onStart } from './lib/onboarding.js';
  import CaseChangeGuard from './components/CaseChangeGuard.svelte';
  import { isPaletteKey } from './lib/commandPalette.js';
  import { filedToast, workFolder } from './lib/folders.js';
  import { isNoteKey } from './lib/noteHere.svelte.js';
  import { readStatus, stoppedBecause } from './lib/workspace.js';
  import { analysisSearch, leaveAnalysisView } from './lib/analysisSearch.svelte.js';

  // The rail holds the pipeline workspaces (docs/UI.md §3); tools are tabs
  // inside them. Three workspaces sit in the topbar rather than the rail: home,
  // which is where the app opens and is not a stage either; the case, which is
  // what the stages file into; and Settings, which is app plumbing and not part
  // of the working flow at all.
  const TOOLS = [
    { id: 'overview', label: TOOL_LABELS.overview, load: () => import('./tools/Overview.svelte') },
    { id: 'board', label: TOOL_LABELS.board, load: () => import('./tools/Board.svelte') },
    { id: 'graph', label: TOOL_LABELS.graph, load: () => import('./tools/Graph.svelte') },
    { id: 'timeline', label: TOOL_LABELS.timeline, load: () => import('./tools/Timeline.svelte') },
    { id: 'sheet', label: TOOL_LABELS.sheet, load: () => import('./tools/Sheet.svelte') },
    { id: 'media', label: TOOL_LABELS.media, load: () => import('./tools/MediaLibrary.svelte') },
    { id: 'files', label: TOOL_LABELS.files, load: () => import('./tools/Files.svelte') },
    { id: 'reverse', label: TOOL_LABELS.reverse, load: () => import('./tools/ReverseSearch.svelte') },
    { id: 'inspect', label: TOOL_LABELS.inspect, load: () => import('./tools/Inspector.svelte') },
    { id: 'collage', label: TOOL_LABELS.collage, load: () => import('./tools/Collage.svelte') },
    { id: 'satellite', label: TOOL_LABELS.satellite, load: () => import('./tools/Satellite.svelte') },
    { id: 'compare', label: TOOL_LABELS.compare, load: () => import('./tools/Compare.svelte') },
    { id: 'detect', label: TOOL_LABELS.detect, load: () => import('./tools/Detect.svelte') },
    { id: 'horizon', label: TOOL_LABELS.horizon, load: () => import('./tools/Horizon.svelte') },
    { id: 'coordinates', label: TOOL_LABELS.coordinates, load: () => import('./tools/Coordinates.svelte') },
    { id: 'proof', label: TOOL_LABELS.proof, load: () => import('./tools/ProofComposer.svelte') },
    { id: 'post', label: TOOL_LABELS.post, load: () => import('./tools/PostComposer.svelte') },
    { id: 'plate', label: TOOL_LABELS.plate, load: () => import('./tools/MapPlate.svelte') },
    { id: 'notebook', label: TOOL_LABELS.notebook, load: () => import('./tools/Notebook.svelte') },
  ];
  const ALL_TOOLS = [
    ...TOOLS,
    { id: 'settings', label: TOOL_LABELS.settings, load: () => import('./tools/Settings.svelte') },
  ];
  // Settings is the only place anything can be updated from, and it sits out of
  // the working flow — so a dot on its icon is how the app mentions it at all.
  let badges = $derived(updateBadges(updatesState, prefs.updateDismissedVersion));

  const loader = createToolLoader(Object.fromEntries(ALL_TOOLS.map((tool) => [tool.id, tool.load])));
  let toolComponents = $state.raw({});
  let toolErrors = $state.raw({});
  const TOOL_IDS = ALL_TOOLS.map((t) => t.id);
  const toolLabel = (id) => ALL_TOOLS.find((t) => t.id === id)?.label ?? id;
  // Name the tab the `?` will answer about, so the press is not a leap into a document.
  const guideTitle = $derived(
    landingFor(uiState.tool).tool ? `Guide: ${toolLabel(uiState.tool)}` : 'Read the guide'
  );

  // deep links: tool ids (#media, #proof, …) plus workspace aliases
  // (#compose, #compose/post) — see lib/workspaces.js
  const fromHash = toolFromHash(location.hash, TOOL_IDS);
  if (fromHash) uiState.tool = fromHash;
  // The app owns the route; a tool may keep its own place in the query after it
  // (the map's view, the folder Files is in). Each switch of tool is an entry, so the
  // browser's Back and Forward walk the tools, and inside them the places the
  // analyst went to (lib/backButton.js).
  onDestroy(installBackButton(TOOL_IDS));
  // the guide in a tab of its own opens tools here, in the tab it was detached from
  onDestroy(
    listenToGuide({
      tools: TOOL_IDS,
      open: (id) => {
        uiState.guide = null;
        uiState.tool = id;
      },
      report: () => {
        uiState.guide = null;
        openIssueReport();
      },
      example: () => {
        uiState.guide = null;
        openFindExample();
      },
    })
  );
  let firstShow = true;
  $effect(() => {
    const tool = uiState.tool;
    untrack(() => showTool(tool, { first: firstShow, solo }));
    firstShow = false;
  });
  $effect(() => {
    caseState.current?.id;
    untrack(caseShown);
  });
  /**
   * A tab opened to hold one tool and nothing else (`lib/hash.js`).
   *
   * Read once, at load, because it describes the tab rather than a state the
   * app moves through: the way out of it is the address, which is the same way
   * in. Everything it takes away belongs to getting *somewhere else* — the
   * workspace rail, the case bar, the tab strip, the case sidebar — and a
   * second screen showing one map is already somewhere.
   */
  const solo = readSolo(splitHash(location.hash).params);
  /** The app's bars put away: in a tab of its own, or while a tool's focus gives its page the whole window. */
  const bare = $derived(solo || uiState.focusMode);
  // Map windows are numbered per window, and the one that opened the app is the
  // first: a window that was detached carries its own number in the address and
  // leaves the count alone (tools/Satellite.svelte).
  if (!splitHash(location.hash).params.has('w')) {
    try {
      localStorage.setItem('azimut:mapWindows', '1');
    } catch { /* a locked-down profile only loses the numbering */ }
  }

  // A frozen reading belongs to the surface that captured it. Carrying a Graph
  // snapshot into Board made the capture look like an incomplete second case and
  // could leave a hidden Details id waiting for the next live read. Changing tools
  // is therefore leaving the snapshot; live recipes still share their question.
  $effect(() => {
    for (const view of [analysisSearch.catalog.activeView, analysisSearch.timeline.activeView]) {
      if (view?.mode !== 'snapshot' || uiState.tool === view.surface) continue;
      leaveAnalysisView(caseState.current?.id, view.surface, { clear: true });
    }
  });

  // Workspace navigation: clicking a workspace returns to its last-used tab.
  const activeWs = $derived(workspaceOf(uiState.tool));
  const lastTool = $state({});
  const sidebarOpenByWorkspace = $state({});
  let previousTool = null;
  $effect(() => {
    const ws = workspaceOf(uiState.tool);
    if (ws) lastTool[ws.id] = uiState.tool;
  });
  $effect(() => {
    const nextTool = uiState.tool;
    const previousWs = workspaceOf(previousTool);
    const nextWs = workspaceOf(nextTool);
    if (nextWs && previousWs?.id !== nextWs.id) {
      uiState.sidebarOpen = sidebarOpenForWorkspace(nextWs.id, sidebarOpenByWorkspace);
    }
    previousTool = nextTool;
  });
  // A tool that holds the screen is left with it. Its host is hidden as soon as
  // another tool is picked, and a hidden fullscreen element blacks the screen
  // out with the new tool behind it. Every way across lands here: a toast's
  // action, Open in…, a candidate sent to Compare.
  $effect(() => {
    uiState.tool;
    leaveFullscreen();
  });
  function openWorkspace(ws) {
    uiState.tool = lastTool[ws.id] ?? ws.tools[0];
  }

  // ── Add event, from wherever the analyst is ──────────────────────────────────
  /** A frozen reading takes no new event, and says so rather than hiding the pencil:
   *  a control that is visible and unusable teaches something. */
  const noteFrozen = $derived(
    (['board', 'graph'].includes(uiState.tool) && Boolean(analysisSearch.catalog.snapshotId)) ||
      (uiState.tool === 'timeline' && Boolean(analysisSearch.timeline.snapshotId))
  );
  const noteTitle = $derived(
    noteFrozen ? 'A frozen snapshot takes no new event. Leave it to add one.' : 'Add event about what is on screen (Alt+N)'
  );
  function toggleNote() {
    if (!caseState.current || noteFrozen) return;
    // The Timeline already has its line under the axis: the pencil goes there.
    if (uiState.tool === 'timeline') {
      uiState.noting = false;
      uiState.timelineLineFocus += 1;
      return;
    }
    uiState.noting = !uiState.noting;
  }
  function onGlobalKey(event) {
    if (isPaletteKey(event)) {
      event.preventDefault();
      if (event.target?.closest?.('[role="alertdialog"]')) return;
      if (paletteOpen || !event.target?.closest?.('[role="dialog"]')) paletteOpen = !paletteOpen;
      return;
    }
    if (!isNoteKey(event)) return;
    event.preventDefault();
    toggleNote();
  }
  function toggleSidebar() {
    const open = !uiState.sidebarOpen;
    const ws = workspaceOf(uiState.tool);
    if (ws) sidebarOpenByWorkspace[ws.id] = open;
    uiState.sidebarOpen = open;
  }

  let paletteOpen = $state(false);

  // Tools mount lazily on first visit, then stay mounted (hidden via CSS) so
  // unsaved editor state — a half-composed proof, a collage in progress —
  // survives switching tabs to grab another capture or media.
  const visited = $state({ [uiState.tool]: true });
  async function ensureTool(id) {
    try {
      const component = await loader.load(id);
      toolComponents = { ...toolComponents, [id]: component };
      if (toolErrors[id]) toolErrors = { ...toolErrors, [id]: null };
    } catch (error) {
      toolErrors = { ...toolErrors, [id]: error?.message ?? 'Could not load this tool' };
    }
  }
  $effect(() => {
    const id = uiState.tool;
    visited[id] = true;
    void ensureTool(id);
  });

  // A workspace that can't be worked in replaces the app rather than letting
  // every tool fail one request at a time: a folder that is gone, or one
  // another Azimut holds. The backend refuses case work in both states and
  // touches neither folder, so what is left to do is explain and offer the way
  // out.
  // A newcomer opens on the welcome and the tour, someone who knows Azimut on what
  // their new version brings (lib/onboarding.js), once the case list says which they
  // are. A map window opened on its own is part of a session already under way, so it
  // never does.
  let guideButton = $state(null);
  function onboardOnStart() {
    if (solo || uiState.onboarding) return;
    const version = appInfo.version;
    uiState.onboarding = onStart({
      tour: prefs.tour,
      seen: prefs.whatsNewSeen,
      version,
      hasCases: caseState.list.length > 0,
      closed: closedThisStart(version),
    });
  }
  function onboarded({ guide = false, create = false } = {}) {
    uiState.onboarding = null;
    if (guide) openGuide(guide === true ? uiState.tool : guide);
    if (create) {
      // the front door's own field, where a first case is named
      uiState.tool = 'overview';
      requestAnimationFrame(() => document.getElementById('home-case-name')?.focus());
    }
  }

  let workspaceStopped = $state(null);
  readStatus()
    .then((status) => {
      workspaceStopped = stoppedBecause(status);
    })
    .catch(() => {});

  // The entity vocabulary: types, families, icons and the fields a form is built
  // from. It is code rather than case data, so it is fetched once here and shared —
  // and asking at startup is what keeps a row from painting under a fallback icon
  // before the first surface that needs the registry happens to ask for it.
  loadEntityTypes();

  // Load the case list and reopen the last-used case (survives reloads), then
  // — once preferences have landed — see what is behind: the app, the
  // downloaders, the capture extension. The check reads prefs.updateCheckOnStart
  // and the bundled extension version, so it must follow initSession, which
  // loads them.
  const startupCaseId = solo ? splitHash(location.hash).params.get('case') : null;
  initSession(startupCaseId)
    .catch((error) => {
      if (startupCaseId) {
        toast(`Could not open this map's case: ${error?.message ?? 'case not found'}`, 'danger', 8000);
      }
    })
    .finally(() => {
      onboardOnStart();
      checkForUpdatesOnStart();
    });

  // Live nudges from our own backend (SSE, same-origin — still local-first):
  // the capture extension files screenshots while this tab just sits here, and
  // they must show up without a reload. Refresh only what the nudge names.
  startEvents();
  // Filed from another window, so the toast is where the analyst hears which
  // folder it landed in, with Move when the work folder took it.
  async function filedFromExtension(ev, lead, fallback) {
    if (caseState.current?.id !== ev.case_id) return toast(fallback, 'ok', 5000);
    await reloadCase();
    let entity = null;
    if (workFolder()) {
      try {
        entity = ev.entity_id
          ? (await api.get(`/api/cases/${ev.case_id}/entities/${ev.entity_id}/chain`)).entity
          : (await api.get(`/api/cases/${ev.case_id}/entities/lookup?attr=path&value=${encodeURIComponent(ev.path)}`)).entity;
      } catch {
        /* the toast still says it was filed */
      }
    }
    filedToast(lead, [entity], { fallback, timeout: 5000 });
  }
  onEvent('capture', (ev) =>
    filedFromExtension(ev, `“${ev.title}” filed from ${ev.site}`, `Capture filed from ${ev.site}: ${ev.title}`)
  );
  onEvent('bookmark', (ev) => filedFromExtension(ev, `Bookmark “${ev.title}” saved`, `Bookmark saved: ${ev.title}`));
  onEvent('place', (ev) =>
    filedFromExtension(ev, `“${ev.title}” saved from ${ev.site}`, `Place saved from ${ev.site}: ${ev.title}`)
  );
  // The case's saved work, moved from another window onto it: a second app tab,
  // or the map panel the extension draws over someone else's map. Silent, unlike
  // the three above — the analyst did this themselves, just not here — and the
  // reload is what puts it on the map and in the Saved panel.
  onEvent('saved', (ev) => {
    if (caseState.current?.id === ev.case_id) reloadCase();
  });
</script>

<div class="shell">
  {#if !bare}
  <header class="topbar">
    <!-- The mark is the way home. It costs no rail seat and needs no label, which is
         the whole reason home lives here: the rail reads as a sequence of stages and
         an overview is not one of them, exactly as the case is not. -->
    <button
      class="brand"
      data-guide="start.home"
      class:topbar-active={activeWs?.id === HOME_WORKSPACE.id}
      title="Home"
      aria-label="Home"
      onclick={() => openWorkspace(HOME_WORKSPACE)}
    >
      <Logo size={27} />
      <span class="brand-name"><Wordmark height={13} /></span>
    </button>
    <div class="case-group" data-guide="start.case">
      <CaseSwitcher />
    </div>
    <div class="spacer"></div>
    <DetectActivity />
    <PlateActivity />
    <button class="btn btn-ghost btn-sm" title="Go to (Ctrl+K / ⌘K)" aria-label="Go to" data-guide="start.goto"
            aria-keyshortcuts="Control+k Meta+k" onclick={() => (paletteOpen = true)}>
      <Icon name="search" size={16} />
    </button>
    <!-- The one mark that answers "what is this tab I am standing in". It sits beside
         the gear rather than in each toolbar so there is one of it, and it opens the
         guide over the tool on that tool's page. -->
    <!-- The one way into Add event from every tool: quiet like the marks beside it,
         since amber is kept for the main action and the selection. -->
    {#if caseState.current && !solo}
      <button
        class="btn btn-ghost btn-sm note-btn"
        data-guide="start.event"
        class:on={uiState.noting}
        title={noteTitle}
        aria-label="Add an event"
        aria-pressed={uiState.noting}
        disabled={noteFrozen}
        onclick={toggleNote}
      >
        <Icon name="eventAdd" size={16} />
      </button>
    {/if}
    <button
      class="btn btn-ghost btn-sm"
      title={guideTitle}
      aria-label={guideTitle}
      bind:this={guideButton}
      onclick={() => openGuide(uiState.tool)}
    >
      <Icon name="help" size={16} />
    </button>
    <button
      class="btn btn-ghost btn-sm dotted"
      data-guide="start.settings"
      class:topbar-active={uiState.tool === 'settings'}
      title={badges.any ? 'Settings · something to install or update' : 'Settings'}
      onclick={() => (uiState.tool = 'settings')}
    >
      <Icon name="settings" size={16} />
      {#if badges.any}
        <span class="update-dot" aria-label="something to install or update"></span>
      {/if}
    </button>
    <button
      class="btn btn-ghost btn-sm"
      title="Toggle case sidebar"
      onclick={toggleSidebar}
    >
      <Icon name="panelRight" size={16} />
    </button>
  </header>
  {/if}

  <div class="main">
    {#if !bare}
    <nav class="rail">
      {#each WORKSPACES as ws (ws.id)}
        <button
          class="rail-btn"
          data-guide="start.stages"
          class:active={activeWs?.id === ws.id}
          onclick={() => openWorkspace(ws)}
          title={ws.label}
        >
          <Icon name={ws.icon} size={19} />
          <span>{ws.label}</span>
        </button>
      {/each}
      <!-- The case, under the four stages and apart from them: it is what every stage
           files into rather than one of them, and one press from any of them opens its
           Timeline, Board, Graph and Sheet. -->
      <span class="rail-rule" role="presentation"></span>
      <button
        class="rail-btn case-rail"
        data-guide="start.case-rail"
        class:active={activeWs?.id === CASE_WORKSPACE.id}
        onclick={() => openWorkspace(CASE_WORKSPACE)}
        title="The case: its Timeline, Board, Graph and Sheet"
      >
        <Icon name={CASE_WORKSPACE.icon} size={19} />
        <span>{CASE_WORKSPACE.label}</span>
      </button>
      <button
        class="rail-btn theme-toggle"
        onclick={toggleTheme}
        title={uiState.theme === 'light' ? 'Switch to dark theme' : 'Switch to light theme'}
      >
        <Icon name={uiState.theme === 'light' ? 'moon' : 'sun'} size={19} />
        <span>{uiState.theme === 'light' ? 'Dark' : 'Light'}</span>
      </button>
    </nav>
    {/if}

    <main class="canvas">
      {#if !bare && activeWs && activeWs.tools.length > 1}
        <div class="tabstrip">
          {#each activeWs.tools as toolId (toolId)}
            <button
              class="tab-btn"
              data-guide="start.tabs"
              class:active={uiState.tool === toolId}
              aria-current={uiState.tool === toolId ? 'page' : undefined}
              onclick={() => (uiState.tool = toolId)}
            >
              {toolLabel(toolId)}
            </button>
          {/each}
        </div>
      {/if}
      <div class="canvas-body">
        {#each ALL_TOOLS as tool (tool.id)}
          {#if visited[tool.id]}
            {@const ToolComponent = toolComponents[tool.id]}
            <!-- a plate exporting while another tool is open stays laid out, unseen: its maps draw the pictures -->
            <div class="tool-host" class:hidden={uiState.tool !== tool.id} class:working={tool.id === 'plate' && plateExport.running}>
              {#if ToolComponent}
                <ToolComponent />
              {:else if toolErrors[tool.id]}
                <div class="tool-loading">
                  <p>{toolErrors[tool.id]}</p>
                  <button class="btn btn-sm" onclick={() => ensureTool(tool.id)}>Retry</button>
                </div>
              {:else}
                <div class="tool-loading">Loading {tool.label}…</div>
              {/if}
            </div>
          {/if}
        {/each}
      </div>
    </main>

    {#if uiState.sidebarOpen && !bare}
      <CaseSidebar />
    {/if}
  </div>
</div>

<svelte:window onkeydown={onGlobalKey} />

<NoteBar />
<MoveDialog />
<CommandPalette bind:open={paletteOpen} tools={ALL_TOOLS} />
{#if uiState.guide}
  <GuideDialog at={uiState.guide.at} onclose={() => (uiState.guide = null)} />
{/if}
<CaseChangeGuard />
<Toasts />

{#if workspaceStopped}
  <WorkspaceStopped {...workspaceStopped} />
{/if}

{#if uiState.onboarding && !workspaceStopped}
  <Onboarding
    start={uiState.onboarding}
    version={appInfo.version}
    anchor={guideButton}
    hasCases={caseState.list.length > 0}
    onkeep={keepOnboarding}
    onclose={onboarded}
  />
{/if}

<!-- after the welcome or the tour, rather than over it -->
{#if updateState.show && !uiState.onboarding}
  <UpdateModal />
{/if}

<style>
  .shell {
    display: flex;
    flex-direction: column;
    height: 100%;
  }
  .topbar {
    height: var(--topbar-h);
    flex-shrink: 0;
    /* own stacking context above the tool canvas: a map's own layers and
       controls otherwise swallow the case switcher's dropdown */
    position: relative;
    z-index: 1200;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-1);
  }
  .brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 4px 8px 4px 4px;
    margin-left: -4px;
    border-radius: var(--r-sm);
    transition: background 0.15s var(--ease);
  }
  .brand:hover {
    background: var(--bg-2);
  }
  .brand-name {
    display: flex;
    align-items: center;
  }
  .spacer {
    flex: 1;
  }
  /* which case: the switcher alone, since the case itself opens from the rail */
  .case-group {
    display: flex;
    align-items: center;
  }
  .topbar-active {
    color: var(--text-1);
    background: var(--bg-2);
  }
  /* Add event sits with the other icon marks; amber only while its bar is open. */
  .note-btn.on {
    color: var(--accent);
    background: var(--accent-soft);
  }
  .main {
    flex: 1;
    display: flex;
    min-height: 0;
  }
  .rail {
    width: var(--rail-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 4px 0;
    border-right: 1px solid var(--border);
    background: var(--bg-1);
  }
  /* flat, full-bleed segments — active state is the edge bar, not a card */
  .rail-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 0 8px;
    border-left: 2px solid transparent;
    border-right: 2px solid transparent;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 500;
  }
  .rail-btn:hover {
    color: var(--text-1);
  }
  .rail-btn.active {
    color: var(--text-1);
    border-left-color: var(--accent);
  }
  /* The case under the four stages, a rule and some air between them. */
  .rail-rule {
    flex-shrink: 0;
    height: 1px;
    margin: 14px 14px 10px;
    background: var(--border-strong);
  }
  /* pinned to the foot of the rail, away from the workspace switches */
  .theme-toggle {
    margin-top: auto;
  }
  .canvas {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-0);
  }
  .tabstrip {
    flex-shrink: 0;
    display: flex;
    align-items: stretch;
    gap: 2px;
    padding: 0 10px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--border);
  }
  .tab-btn {
    padding: 7px 12px;
    font-size: var(--fs-sm);
    font-weight: 500;
    color: var(--text-3);
  }
  .tab-btn:hover {
    color: var(--text-1);
  }
  .tab-btn.active {
    color: var(--text-1);
    box-shadow: inset 0 -2px 0 var(--accent);
  }
  .canvas-body {
    flex: 1;
    min-height: 0;
  }
  .tool-host {
    width: 100%;
    height: 100%;
  }
  .tool-host.hidden {
    display: none;
  }
  .tool-host.hidden.working {
    display: block;
    position: fixed;
    inset: 0;
    visibility: hidden;
    pointer-events: none;
    z-index: -1;
  }
  .tool-loading {
    width: 100%;
    height: 100%;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 10px;
    color: var(--text-3);
    font-size: var(--fs-sm);
  }
</style>