/* The portal on @stack-ui tokens (vendor/stack-ui/tokens.css).
   Scoped to pages that mount the portal (#app): this portal and the artifact
   portal in AppBoundry.wasm (packages/appboundry/scripts/portal-page.mjs
   inlines this file after the vendored release), not the marketing pages,
   which have marketing-theme.css. The tokens follow the
   operating system's colour scheme unless Settings → Appearance sets
   data-stack-theme. AppBoundry's cyan stays in the logo only: it is a product
   mark, not a UI colour (stack-ui docs/design-system-contract.md §3). */
:root:has(#app){
  --bg:var(--stack-color-bg-canvas);
  --panel:var(--stack-color-bg-surface);
  --line:var(--stack-color-border-default);
  --text:var(--stack-color-text-default);
  --muted:var(--stack-color-text-muted);
  --cyan:var(--stack-color-text-link);
  --blue:var(--stack-color-text-link);
  --amber:var(--stack-color-status-attention-fg);
  --red:var(--stack-color-status-critical-fg);
}
/* A chosen theme sets color-scheme through tokens.css; this is only the default. */
:root:has(#app):not([data-stack-theme]){color-scheme:light dark}
body:has(#app){background:var(--bg);color:var(--text);font-family:var(--stack-font-family-sans)}
body:has(#app):before{background-image:linear-gradient(var(--text) 1px,transparent 1px),linear-gradient(90deg,var(--text) 1px,transparent 1px);opacity:.025}

/* Logo: white on dark, black on light, following the same theme as the tokens. */
#app .logo-on-light{display:none}
@media (prefers-color-scheme:light){
  :root:not([data-stack-theme="dark"]) #app .logo-on-light{display:inline}
  :root:not([data-stack-theme="dark"]) #app .logo-on-dark{display:none}
}
:root[data-stack-theme="light"] #app .logo-on-light{display:inline}
:root[data-stack-theme="light"] #app .logo-on-dark{display:none}
#app .brand img{max-width:100%}
#app .auth-card img{max-width:240px;margin:0 auto}

/* Surfaces and text that styles.css and portal.css colour by hand. */
#app aside{background:var(--stack-color-bg-surface)}
#app nav a{color:var(--muted)}
#app nav a:hover,#app nav a.active{color:var(--text);background:var(--stack-color-bg-sunken)}
#app .panel,#app .card{background:var(--panel);box-shadow:none}
#app .metric strong{color:var(--text)}
#app .node{border-color:var(--line)}
#app .tr.head{background:var(--stack-color-bg-sunken)}
#app .notice{border-color:var(--line);background:var(--stack-color-bg-sunken);color:var(--text)}
#app .search,#app input,#app .connection-methods select,#app .connection-methods textarea,#app select:not([class*="stack-"]){background:var(--stack-color-bg-surface);color:var(--text);border-color:var(--stack-color-border-strong)}
#app .context-panel,#app .code-step{background:var(--stack-color-bg-sunken)}
#app .code-step pre{color:var(--text)}
/* The integration guide's and implementation sources' grid tracks grew to its widest code block (433px past a
   phone's width); the code scrolls inside its own step instead. */
#app .integration-guide,#app .implementation-sources{grid-template-columns:minmax(0,1fr)}
#app .integration-guide>*,#app .implementation-sources>*,#app .code-step{min-width:0}
#app .connection-record>div:first-child{flex-wrap:wrap}
#app .connection-record h2{overflow-wrap:anywhere;min-width:0}
#app .source-row{grid-template-columns:minmax(0,1fr) auto}
@media (max-width:620px){#app .source-row{grid-template-columns:minmax(0,1fr)}}
#app button:not([class*="stack-"]),#app .fatal .button{background:var(--stack-color-action-primary-bg);border-color:var(--stack-color-action-primary-bg);color:var(--stack-color-action-primary-fg)}
#app .language-tabs button{background:transparent;color:var(--text);border-color:var(--line)}
#app .language-tabs button.active{background:var(--stack-color-action-primary-bg);border-color:var(--stack-color-action-primary-bg);color:var(--stack-color-action-primary-fg)}
#app button.secondary{background:transparent;color:var(--stack-color-text-link);border-color:var(--stack-color-action-primary-bg)}
#app button.danger{background:var(--stack-color-action-danger-bg);border-color:var(--stack-color-action-danger-bg);color:var(--stack-color-action-danger-fg)}
#app .sidebar-toggle{color:var(--stack-color-action-primary-fg)}
#app .check{color:var(--stack-color-status-positive-glyph)}
#app .gone{color:var(--stack-color-status-critical-glyph)}

/* A plain label (organization, role, event kind). It carries no state: states
   are stack-status elements. */
#app .badge,#app .badge.ok,#app .badge.warn{color:var(--muted);border-color:var(--line);background:transparent}

/* States from @stack-ui/core inside the portal's dense rows and cards. The
   portal sizes and spaces the containers it owns; the states themselves look
   as they do in every Boundry product (AGENTS.md: no .stack-* restyling). */
#app .state-pair{display:inline-flex;flex-wrap:wrap;gap:var(--stack-space-1);align-items:center;justify-content:flex-end;font-size:var(--stack-text-xs-size);line-height:var(--stack-text-xs-line);letter-spacing:normal}
#app .connection-verification{margin:0 0 var(--stack-space-3)}
#app .implementation-row{padding-left:var(--stack-space-4)}
#app .health-check{display:flex;gap:var(--stack-space-2);align-items:baseline;border-top:1px solid var(--line);padding:11px 0;margin:0}
#app .health-check small{color:var(--muted)}
#app .facts{margin:0 0 var(--stack-space-3);padding-left:var(--stack-space-5);color:var(--text);font-size:12px;line-height:1.8}
#app .theme-control{display:flex;gap:var(--stack-space-2);align-items:center}
/* The evidence summary in a card keeps the foundation's own layout: styles.css
   lays out only the portal's own lists (dl without a stack- class). */
#app .card-evidence{margin-top:var(--stack-space-2);min-width:0}
/* The evidence needs the row's width: in a third of it the foundation's claim
   grid leaves no room for values. The card spans the row instead. */
#app .cards>.trust-card{grid-column:1/-1}

/* The authority line in the sidebar. Collapsed, the box it sits in is one glyph
   wide, so only the glyph shows; the label is clipped, not removed, and stays
   for screen readers. Below 1000px the sidebar is never collapsed. */
#app .source{flex-direction:column;align-items:flex-start;gap:4px}
#app .source small{font-size:10px}
@media (min-width:1001px){
  #app.sidebar-collapsed .source-state{width:1.1em;overflow:hidden;white-space:nowrap}
}

/* Keyboard focus was invisible: nothing in the portal styled :focus. */
#app :focus-visible{outline:var(--stack-focus-ring-width) solid var(--stack-focus-ring-color);outline-offset:var(--stack-focus-ring-offset)}
#app .stack-table:focus-visible{outline-offset:0}

/* The Boundry family: every Boundry product surface links to the company. */
#app .boundry-family{display:block;margin:10px 13px 0;color:var(--muted);font-size:12px;text-decoration:none}
#app .boundry-family:hover{color:var(--text);text-decoration:underline}
#app .boundry-family:focus-visible{outline:var(--stack-focus-ring-width) solid var(--stack-focus-ring-color);outline-offset:var(--stack-focus-ring-offset)}
.sidebar-collapsed .boundry-family span{display:none}

/* In a short window the fixed sidebar's content is taller than the sidebar: flex
   shrank the logo to nothing and the Boundry link ran under the source box. It
   scrolls on its own instead (both this portal and the artifact portal). */
#app aside{overflow-y:auto}
#app aside>*{flex-shrink:0}

/* At phone width the navigation's three columns cut off the longer labels
   (Deployments, Relationships), the header's identity ran into its buttons,
   and the connect page's code widened the one grid column, and the page, by 453px. */
@media (max-width:620px){
  #app,#app.sidebar-collapsed{grid-template-columns:minmax(0,1fr)}
  #app nav{grid-template-columns:repeat(2,minmax(0,1fr))}
  #app nav a{white-space:normal;overflow-wrap:anywhere}
  #app main>header{height:auto;min-height:72px;flex-wrap:wrap;gap:var(--stack-space-2);padding:var(--stack-space-3) 0}
}

/* A failed sign-in (StackUI.ErrorPanel) sits in the sign-in card's column. */
#app .auth-problem{max-width:420px;margin:var(--stack-space-3) auto;text-align:left}

/* The page header's actions end with the shared theme control, on every page
   (an app carries its theme control in its frame, contract §10). The sign-in
   card carries the family link and the theme control too. */
#app main>header .header-actions{display:flex;flex-wrap:wrap;gap:var(--stack-space-2);align-items:center;justify-content:flex-end}
#app .auth-family{display:flex;flex-wrap:wrap;gap:var(--stack-space-3);align-items:center;justify-content:center;margin-top:var(--stack-space-5)}
#app .auth-family .boundry-family{margin:0}
