/*
 * Stravica brand kit v1.0: ink, paper and cobalt.
 * Canonical values supplied from stravica.ai public/brand/theme/tokens.css.
 * Dependency-free typography, flat prose surfaces and separate status colours.
 *
 * Workspace aliases retain their historical selector contract. The --sv-*
 * layer follows the OS when unset; explicit light/dark choices take precedence.
 * Legacy private names remain aliases for compatibility, with no retired values.
 * Chart extensions use fixed L .44 (light) / .80 (dark), C .10 and link-relative
 * hues. Offsets +30 / -15 / +150 give violet, blue-cyan and warm orange while
 * keeping both themes in sRGB. Ratios use unrounded sRGB and WCAG luminance.
 */

:root, [data-theme="dark"] {
  --bg: var(--sv-canvas);
  --bg-surface: var(--sv-surface);
  --bg-highlight: var(--sv-raised);
  --bg-inset: var(--sv-code);
  --border: var(--sv-border);
  --rule: var(--sv-border);
  --text: var(--sv-ink);
  --text-dim: var(--sv-muted);
  --text-bright: var(--sv-ink);
  --accent: var(--sv-link);
  --accent-hover: var(--sv-hover);
  --accent-ink: var(--sv-onbutton);
  --emphasis: var(--sv-link);
  --signal: var(--sv-link);
  --focus: var(--sv-focus);
  --green: var(--sv-success);
  --yellow: var(--sv-warning);
  --red: var(--sv-danger);
  --purple: oklch(from var(--sv-link) 0.80 0.10 calc(h + 30)); /* Link hue +30, C .10; AA target >=4.5:1; light bg/surface 7.60:1 / 8.08:1; dark bg/surface 9.81:1 / 9.17:1. */
  --cyan: oklch(from var(--sv-link) 0.80 0.10 calc(h - 15)); /* Link hue -15, C .10; AA target >=4.5:1; light bg/surface 7.30:1 / 7.76:1; dark bg/surface 10.12:1 / 9.46:1. */
  --orange: oklch(from var(--sv-link) 0.80 0.10 calc(h + 150)); /* Link hue +150, C .10; AA target >=4.5:1; light bg/surface 7.56:1 / 8.03:1; dark bg/surface 9.93:1 / 9.28:1. */
  --font-display: var(--sv-font);
  --font-body: var(--sv-font);
  --font-mono: var(--sv-mono);
  --font-editorial: var(--sv-font);
}

[data-theme="light"] {
  --bg: var(--sv-canvas);
  --bg-surface: var(--sv-surface);
  --bg-highlight: var(--sv-raised);
  --bg-inset: var(--sv-code);
  --border: var(--sv-border);
  --rule: var(--sv-border);
  --text: var(--sv-ink);
  --text-dim: var(--sv-muted);
  --text-bright: var(--sv-ink);
  --accent: var(--sv-link);
  --accent-hover: var(--sv-hover);
  --accent-ink: var(--sv-onbutton);
  --emphasis: var(--sv-link);
  --signal: var(--sv-link);
  --focus: var(--sv-focus);
  --green: var(--sv-success);
  --yellow: var(--sv-warning);
  --red: var(--sv-danger);
  --purple: oklch(from var(--sv-link) 0.44 0.10 calc(h + 30)); /* Link hue +30, C .10; AA target >=4.5:1; light bg/surface 7.60:1 / 8.08:1; dark bg/surface 9.81:1 / 9.17:1. */
  --cyan: oklch(from var(--sv-link) 0.44 0.10 calc(h - 15)); /* Link hue -15, C .10; AA target >=4.5:1; light bg/surface 7.30:1 / 7.76:1; dark bg/surface 10.12:1 / 9.46:1. */
  --orange: oklch(from var(--sv-link) 0.44 0.10 calc(h + 150)); /* Link hue +150, C .10; AA target >=4.5:1; light bg/surface 7.56:1 / 8.03:1; dark bg/surface 9.93:1 / 9.28:1. */
  --font-display: var(--sv-font);
  --font-body: var(--sv-font);
  --font-mono: var(--sv-mono);
  --font-editorial: var(--sv-font);
}

/* Canonical light palette and shared, dependency-free type stacks. */
:root, :root[data-theme="light"] {
  --sv-canvas: #F6F8FC;
  --sv-surface: #FFFFFF;
  --sv-raised: #EEF2F8;
  --sv-ink: #111927;
  --sv-muted: #536176;
  --sv-border: #D8DFEA;
  --sv-control: #738198;
  --sv-link: #2447EB;
  --sv-hover: #1737C7;
  --sv-active: #E9EEFF;
  --sv-button: #2447EB;
  --sv-onbutton: #FFFFFF;
  --sv-code: #EEF2F8;
  --sv-success: #116B4D;
  --sv-successbg: #E7F4ED;
  --sv-warning: #895000;
  --sv-warningbg: #FFF3DC;
  --sv-danger: #B4233B;
  --sv-dangerbg: #FDECF0;
  --sv-focus: #2447EB;
  --sv-font: Arial, Helvetica, sans-serif;
  --sv-mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

/* Compatibility names resolve exclusively to the current kit. */
:root {
  --stravica-paper: var(--sv-canvas);
  --stravica-ink: var(--sv-ink);
  --stravica-mute: var(--sv-muted);
  --stravica-rule: var(--sv-border);
  --stravica-signal: var(--sv-link);
  --stravica-signal-2: var(--sv-hover);
  --stravica-surface-nav: var(--sv-surface);
  --stravica-surface-sidebar: var(--sv-surface);
  --stravica-font-display: var(--sv-font);
  --stravica-font-body: var(--sv-font);
  --stravica-font-mono: var(--sv-mono);
  --stravica-font-editorial: var(--sv-font);
}

/* Unset theme uses light chart ink until the OS dark query applies. */
:root:not([data-theme]) {
  --purple: oklch(from var(--sv-link) 0.44 0.10 calc(h + 30)); /* Link hue +30, C .10; AA target >=4.5:1; light bg/surface 7.60:1 / 8.08:1; dark bg/surface 9.81:1 / 9.17:1. */
  --cyan: oklch(from var(--sv-link) 0.44 0.10 calc(h - 15)); /* Link hue -15, C .10; AA target >=4.5:1; light bg/surface 7.30:1 / 7.76:1; dark bg/surface 10.12:1 / 9.46:1. */
  --orange: oklch(from var(--sv-link) 0.44 0.10 calc(h + 150)); /* Link hue +150, C .10; AA target >=4.5:1; light bg/surface 7.56:1 / 8.03:1; dark bg/surface 9.93:1 / 9.28:1. */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --sv-canvas: #0B111B;
    --sv-surface: #101925;
    --sv-raised: #182334;
    --sv-ink: #EDF2FA;
    --sv-muted: #AAB7CA;
    --sv-border: #2C3A4F;
    --sv-control: #75859D;
    --sv-link: #A3B5FF;
    --sv-hover: #C0CDFF;
    --sv-active: #1D2C50;
    --sv-button: #A3B5FF;
    --sv-onbutton: #0B111B;
    --sv-code: #0D1521;
    --sv-success: #80D9B1;
    --sv-successbg: #102D24;
    --sv-warning: #F1CA7A;
    --sv-warningbg: #322712;
    --sv-danger: #FFA3B3;
    --sv-dangerbg: #361C28;
    --sv-focus: #A3B5FF;
    --purple: oklch(from var(--sv-link) 0.80 0.10 calc(h + 30)); /* Link hue +30, C .10; AA target >=4.5:1; light bg/surface 7.60:1 / 8.08:1; dark bg/surface 9.81:1 / 9.17:1. */
    --cyan: oklch(from var(--sv-link) 0.80 0.10 calc(h - 15)); /* Link hue -15, C .10; AA target >=4.5:1; light bg/surface 7.30:1 / 7.76:1; dark bg/surface 10.12:1 / 9.46:1. */
    --orange: oklch(from var(--sv-link) 0.80 0.10 calc(h + 150)); /* Link hue +150, C .10; AA target >=4.5:1; light bg/surface 7.56:1 / 8.03:1; dark bg/surface 9.93:1 / 9.28:1. */
  }
}

:root[data-theme="dark"] {
  --sv-canvas: #0B111B;
  --sv-surface: #101925;
  --sv-raised: #182334;
  --sv-ink: #EDF2FA;
  --sv-muted: #AAB7CA;
  --sv-border: #2C3A4F;
  --sv-control: #75859D;
  --sv-link: #A3B5FF;
  --sv-hover: #C0CDFF;
  --sv-active: #1D2C50;
  --sv-button: #A3B5FF;
  --sv-onbutton: #0B111B;
  --sv-code: #0D1521;
  --sv-success: #80D9B1;
  --sv-successbg: #102D24;
  --sv-warning: #F1CA7A;
  --sv-warningbg: #322712;
  --sv-danger: #FFA3B3;
  --sv-dangerbg: #361C28;
  --sv-focus: #A3B5FF;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
}

/* The body prefix outranks later page-local prose rules, including the
 * viewer.html .content surface and markdownPage() .md-body output. */
body .content,
body .md-body {
  font-family: var(--font-body);
  color: var(--text);
  font-size: 1.125rem;
  line-height: 1.65;
}

body :is(.content, .md-body) :is(h1, h2, h3, h4) {
  font-family: var(--font-display);
  font-weight: 700;
  text-wrap: balance;
  color: var(--text-bright);
}

body :is(.content, .md-body) h1 {
  letter-spacing: -0.025em;
}

body :is(.content, .md-body) h2 {
  letter-spacing: -0.015em;
}

/* Emphasis AA vs --bg: light 6.22:1; dark 9.56:1 (target >=4.5:1). */
body :is(.content, .md-body) strong {
  color: var(--emphasis);
  font-weight: 700;
}

body :is(.content, .md-body) :is(code, pre),
body :is(.content, .md-body) .plain-text {
  font-family: var(--font-mono);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 4px;
}

body :is(.content, .md-body) code {
  font-size: 0.875em;
  color: var(--text);
  padding: 0.15rem 0.35rem;
  border-radius: 2px;
}

body :is(.content, .md-body) pre {
  font-size: inherit;
  padding: 1rem;
  overflow-x: auto;
}

body :is(.content, .md-body) pre code {
  font-size: 0.875em;
  font-family: var(--font-mono);
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}

body :is(.content, .md-body) blockquote {
  border-left: 2px solid var(--signal);
  color: var(--text-dim);
  background: transparent;
  padding: 0.4rem 0 0.4rem 1rem;
  border-radius: 0;
}

body :is(.content, .md-body) blockquote em {
  color: inherit;
}

/* Banner incident re-renders retain the separate theme chrome and button. */
/* Global banner chrome: one slim bar carrying the Stravica lockup on the
 * left and the three-state appearance control on the right; incident rows
 * added by banner.js stack under this row. Height picks the smaller of the
 * kit's 4.5rem header (the workspace is a denser surface than the site).
 * A hairline rule below separates it from page content. */
#global-banner [data-theme-chrome] {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-height: 46px;
  padding: 4px 12px;
  box-sizing: border-box;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--rule);
}

#global-banner .ws-brand {
  display: inline-flex;
  align-items: center;
  gap: 0;
  margin-right: auto;
  padding: 2px 0;
  border-radius: 4px;
  outline: none;
}
#global-banner .ws-brand:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
#global-banner .ws-brand-logo {
  height: 30px;
  width: auto;
  display: block;
}
#global-banner .ws-brand-logo--dark { display: none; }
:root[data-theme="dark"] #global-banner .ws-brand-logo--light { display: none; }
:root[data-theme="dark"] #global-banner .ws-brand-logo--dark { display: block; }
#global-banner .ws-brand-mark { display: none; height: 30px; width: auto; }

/* Narrow fallback: swap the full lockup for the mark alone below 480px. */
@media (max-width: 480px) {
  #global-banner .ws-brand-logo { display: none; }
  #global-banner .ws-brand-mark { display: block; }
}

#global-banner [data-theme-control] {
  position: relative;
  display: inline-flex;
  align-items: center;
}

#global-banner [data-theme-menu-trigger] {
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 4px;
  min-width: 32px;
  height: 30px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1;
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}
#global-banner [data-theme-menu-trigger]:hover {
  border-color: var(--accent);
  color: var(--text-bright);
  background: var(--bg-highlight);
}
#global-banner [data-theme-menu-trigger]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
#global-banner [data-theme-menu-trigger] [data-theme-trigger-glyph] {
  font-size: 14px;
  display: inline-flex;
}

#global-banner [data-theme-menu] {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 140px;
  padding: 4px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 100;
}
#global-banner [data-theme-menu][hidden] { display: none; }
#global-banner [role="menuitemradio"] {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 6px 10px;
  text-align: left;
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
#global-banner [role="menuitemradio"]:hover {
  background: var(--bg-highlight);
}
#global-banner [role="menuitemradio"][aria-checked="true"] {
  color: var(--accent);
  font-weight: 600;
}
#global-banner [role="menuitemradio"]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
