/*
 * KAI docs theme, layered on docsify's vue.css. Shared by the internal and
 * public sites (assemble.mjs copies it, and docs/theme/, to both).
 *
 * Colours mirror the KAI platform UI design system: ink and soft grey
 * surfaces, brand blue for links and emphasis, a navy palette in dark mode.
 * Everything is a variable below, so dark mode only redefines the palette.
 */

@font-face {
  font-family: "Basis Grotesque";
  src: url("./theme/fonts/basis-grotesque-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Basis Grotesque";
  src: url("./theme/fonts/basis-grotesque-bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  --kai-canvas: #ffffff;
  --kai-surface: #f9fafa;
  --kai-surface-2: #f4f4f4;
  --kai-line: #e8e9eb;
  --kai-ink: #1d1e20;
  --kai-ink-2: #4a4b50;
  --kai-muted: #6b6b70;
  --kai-brand: #0058ff;
  --kai-brand-hover: #0047d1;
  --kai-brand-soft: #e6eeff;
  --kai-title-from: #1d1e20;
  --kai-title-mid: #2c4f80;
  --kai-title-to: #4a90e8;
  --kai-warning-soft: #fef3c7;
  --kai-warning-accent: #f59e0b;
  --kai-danger: #b91c1c;
  --kai-danger-soft: #fee2e2;
  --kai-float-shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 8px 24px -6px rgb(16 24 40 / 0.1);

  /* Code highlighting (Prism). */
  --kai-code-comment: #6b6b70;
  --kai-code-keyword: #0047d1;
  --kai-code-string: #047857;
  --kai-code-number: #7e22ce;
  --kai-code-function: #1e2a78;
  --kai-code-punctuation: #4a4b50;

  --theme-color: var(--kai-brand);
  --kai-font: "Basis Grotesque", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --kai-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --kai-canvas: #0a0d24;
    --kai-surface: #111432;
    --kai-surface-2: #20254f;
    --kai-line: #262a55;
    --kai-ink: #f5f6fa;
    --kai-ink-2: #c9cbdd;
    --kai-muted: #8d90ae;
    --kai-brand: #5c95ff;
    --kai-brand-hover: #7aa9ff;
    --kai-brand-soft: rgb(0 88 255 / 0.15);
    --kai-title-from: #ffffff;
    --kai-title-mid: #bfd8ff;
    --kai-title-to: #5c95ff;
    --kai-warning-soft: rgb(245 158 11 / 0.15);
    --kai-warning-accent: #fbbf24;
    --kai-danger: #fca5a5;
    --kai-danger-soft: rgb(239 68 68 / 0.15);
    --kai-float-shadow: inset 0 0 0 1px #262a55;

    --kai-code-comment: #8d90ae;
    --kai-code-keyword: #7aa9ff;
    --kai-code-string: #6ee7b7;
    --kai-code-number: #d8b4fe;
    --kai-code-function: #aab3ff;
    --kai-code-punctuation: #c9cbdd;
  }
}

/* Base */

body {
  font-family: var(--kai-font);
  color: var(--kai-ink-2);
  background: var(--kai-canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Sidebar */

.sidebar {
  background: var(--kai-canvas);
  border-right: 1px solid var(--kai-line);
  color: var(--kai-ink-2);
}

.sidebar > h1 {
  margin: 1.5rem auto 1.25rem;
}

.sidebar > h1 .app-name-link img {
  height: 22px;
}

/* Group headings: plain text entries. Loose-list links are also wrapped in
   <p>, so only style a <p> that holds no link. */
.sidebar-nav > ul > li > p:not(:has(a)),
.sidebar-nav > ul > li > strong {
  margin-top: 1.25em;
  color: var(--kai-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-nav {
  padding-right: 0.75rem;
}

.sidebar ul li a {
  color: var(--kai-ink-2);
  font-size: 0.9rem;
  border-radius: 9999px;
  padding: 0.3em 0.9em;
  display: block;
  transition:
    background-color 150ms,
    color 150ms;
}

.sidebar ul li a:hover {
  color: var(--kai-ink);
  background: var(--kai-surface-2);
  text-decoration: none;
}

/* Active page: an ink pill, as in the platform UI's navigation. */
.sidebar ul li.active > a,
.sidebar ul li > p.active > a {
  color: var(--kai-canvas);
  background: var(--kai-ink);
  border-right: 0;
  font-weight: 700;
}

.sidebar ul li ul.app-sub-sidebar li a {
  font-size: 0.85rem;
}

.sidebar ul li ul.app-sub-sidebar li::before {
  content: none;
}

.sidebar-toggle {
  background: transparent;
}

.sidebar-toggle span {
  background-color: var(--kai-brand);
}

/* Search */

.search {
  border-bottom: 1px solid var(--kai-line);
}

.search .input-wrap {
  background: var(--kai-surface-2);
  border-radius: 9999px;
  padding: 0 0.5em;
}

.search input {
  font-family: var(--kai-font);
  color: var(--kai-ink);
  background: transparent;
}

.search .results-panel .matching-post {
  border-bottom-color: var(--kai-line);
}

.search .results-panel h2,
.search .results-panel p {
  color: var(--kai-ink-2);
}

.search .results-panel .search-keyword {
  color: var(--kai-brand);
}

/* Navbar */

.app-nav a {
  color: var(--kai-ink-2);
  border-radius: 9999px;
  padding: 0.35em 0.9em;
  margin: 0 0.1em;
}

.app-nav a:hover {
  color: var(--kai-ink);
  background: var(--kai-surface-2);
}

.app-nav a.active {
  color: var(--kai-canvas);
  background: var(--kai-ink);
  border-bottom: 0;
  font-weight: 700;
}

/* Content */

.markdown-section {
  max-width: 900px;
  color: var(--kai-ink-2);
}

.markdown-section h1,
.markdown-section h2,
.markdown-section h3,
.markdown-section h4,
.markdown-section h5,
.markdown-section strong,
.markdown-section :is(h1, h2, h3, h4, h5) a.anchor span {
  color: var(--kai-ink);
  font-weight: 700;
}

.markdown-section h1 {
  letter-spacing: -0.02em;
}

.markdown-section h2 {
  letter-spacing: -0.01em;
  margin-top: 2.25em;
}

/* Brand gradient on the page title, as in the platform UI. */
@supports (background-clip: text) or (-webkit-background-clip: text) {
  .markdown-section h1 a.anchor span {
    background-image: linear-gradient(
      90deg,
      var(--kai-title-from) 0%,
      var(--kai-title-mid) 55%,
      var(--kai-title-to) 100%
    );
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
  }
}

.markdown-section a {
  color: var(--kai-brand);
  font-weight: 400;
}

.markdown-section a:hover {
  color: var(--kai-brand-hover);
}

.markdown-section hr {
  border-bottom-color: var(--kai-line);
}

.markdown-section blockquote {
  color: var(--kai-ink-2);
  background: var(--kai-surface);
  border-left: 3px solid var(--kai-brand);
  border-radius: 0 12px 12px 0;
  padding: 0.25em 1.25em;
}

/* `?> note` and `!> important` callouts. */
.markdown-section p.warn {
  color: var(--kai-ink-2);
  background: var(--kai-brand-soft);
  border-radius: 12px;
  padding: 1em 1.25em;
}

.markdown-section p.tip {
  color: var(--kai-ink-2);
  background: var(--kai-danger-soft);
  border-left: 3px solid var(--kai-danger);
  border-radius: 0 12px 12px 0;
}

.markdown-section p.tip::before {
  background-color: var(--kai-danger);
  color: var(--kai-canvas);
}

.markdown-section p.tip code,
.markdown-section p.warn code {
  background: var(--kai-canvas);
}

.status-banner {
  color: var(--kai-ink-2);
  background: var(--kai-warning-soft);
  border-left: 3px solid var(--kai-warning-accent);
  border-radius: 0 12px 12px 0;
  padding: 0.75em 1.25em;
  margin: 1em 0;
}

/* Tables: a tinted card with small-caps headers and hairline rows. */
.markdown-section table {
  display: table;
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--kai-surface);
  border-radius: 16px;
  overflow: hidden;
}

.markdown-section th,
.markdown-section td {
  border: 0;
  border-bottom: 1px solid var(--kai-line);
  padding: 0.7em 1em;
  text-align: left;
}

.markdown-section th {
  color: var(--kai-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.markdown-section tr:last-child td {
  border-bottom: 0;
}

.markdown-section tr:nth-child(2n) {
  background: transparent;
}

/* Code */

.markdown-section code {
  font-family: var(--kai-mono);
  color: var(--kai-brand-hover);
  background: var(--kai-surface-2);
  border-radius: 6px;
}

.markdown-section pre {
  background: var(--kai-surface);
  border-radius: 16px;
}

.markdown-section pre > code {
  color: var(--kai-ink-2);
  background: transparent;
}

.markdown-section pre::after {
  color: var(--kai-muted);
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
  color: var(--kai-code-comment);
}

.token.keyword,
.token.selector,
.token.important,
.token.atrule,
.token.tag,
.token.builtin {
  color: var(--kai-code-keyword);
}

.token.string,
.token.char,
.token.attr-value,
.token.regex,
.token.inserted {
  color: var(--kai-code-string);
}

.token.number,
.token.boolean,
.token.constant,
.token.symbol {
  color: var(--kai-code-number);
}

.token.function,
.token.class-name,
.token.attr-name,
.token.property {
  color: var(--kai-code-function);
}

.token.punctuation,
.token.operator,
.token.entity,
.token.url,
.token.variable {
  color: var(--kai-code-punctuation);
}

.docsify-copy-code-button {
  font-family: var(--kai-font);
  background: var(--kai-ink);
  color: var(--kai-canvas);
  border-radius: 9999px;
}

/* Images and diagrams */

.markdown-section img {
  border-radius: 12px;
}

.markdown-section .mermaid {
  background: var(--kai-surface);
  border-radius: 16px;
  padding: 1.25em;
  text-align: center;
}

/* Pagination: two floating cards. */
.docsify-pagination-container {
  border-top: 0;
  gap: 1rem;
}

.pagination-item {
  flex: 1;
  margin-top: 1.5em;
  padding: 1em 1.25em;
  background: var(--kai-canvas);
  border-radius: 16px;
  box-shadow: var(--kai-float-shadow);
}

.pagination-item a,
.pagination-item-title {
  color: var(--kai-ink);
}

.pagination-item-label {
  color: var(--kai-muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pagination-item a:hover .pagination-item-title {
  color: var(--kai-brand);
  text-decoration: none;
}

/* Dark mode: the logo is drawn in ink, so lift it to white. */
@media (prefers-color-scheme: dark) {
  .sidebar > h1 .app-name-link img {
    filter: invert(1);
  }
}
