/* One sidebar design for Studio and Docs. Only these three colors vary by theme;
   every rail tint, rule, and muted label is mixed from them. */
:root {
  --ts-sidebar-page: #fff9ec;
  --ts-sidebar-ink: #1c1810;
  --ts-sidebar-accent: #b5391b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ts-sidebar-page: #141210;
    --ts-sidebar-ink: #efe9dc;
    --ts-sidebar-accent: #ff5a3c;
  }
}
:root[data-theme="dark"] {
  --ts-sidebar-page: #141210;
  --ts-sidebar-ink: #efe9dc;
  --ts-sidebar-accent: #ff5a3c;
}

:is(.jr-rail, .rail, .wiki-sidebar) {
  --ts-sidebar-rule: color-mix(in srgb, var(--ts-sidebar-ink) 18%, var(--ts-sidebar-page));
  --ts-sidebar-muted: color-mix(in srgb, var(--ts-sidebar-ink) 73%, var(--ts-sidebar-page));
  --ts-sidebar-hover: color-mix(in srgb, var(--ts-sidebar-ink) 6%, var(--ts-sidebar-page));
  --ts-sidebar-active: color-mix(in srgb, var(--ts-sidebar-ink) 9%, var(--ts-sidebar-page));
  background: var(--ts-sidebar-page);
  border-right: 1px solid var(--ts-sidebar-rule);
  color: var(--ts-sidebar-ink);
}

/* Docs' light paper sits closer to its header while Studio keeps its rail. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .wiki-sidebar {
    background: color-mix(in srgb, var(--ts-sidebar-page) 96%, var(--ts-sidebar-ink));
  }
}
:root[data-theme="light"] .wiki-sidebar {
  background: color-mix(in srgb, var(--ts-sidebar-page) 96%, var(--ts-sidebar-ink));
}

.jr-rail {
  position: fixed;
  top: 62px;
  bottom: 0;
  left: 0;
  z-index: 25;
  width: 245px;
  overflow: auto;
  padding: 22px 11px;
  display: flex;
  flex-direction: column;
}
.rail {
  grid-area: rail;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 22px 11px;
}
.wiki-sidebar { min-width: 0; }
.wiki-sidebar-inner {
  position: sticky;
  top: var(--docs-header-height);
  max-height: calc(100dvh - var(--docs-header-height));
  overflow-y: auto;
  padding: 22px 11px 34px;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
}

:is(.jr-rail > a, .rail > .navlink, .wiki-sidebar .ts-sidebar-row) {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 0;
  color: var(--ts-sidebar-muted);
  font: 650 17px/1.5 Inter, system-ui, sans-serif;
  letter-spacing: 0;
  text-decoration: none;
  text-transform: none;
  cursor: pointer;
  transition: color .12s ease, background-color .12s ease;
}
:is(.jr-rail > a, .rail > .navlink, .wiki-sidebar .ts-sidebar-row):hover {
  border-color: var(--ts-sidebar-rule);
  background: var(--ts-sidebar-hover);
  color: var(--ts-sidebar-ink);
  text-decoration: none;
}
:is(.jr-rail > a, .rail > .navlink, .wiki-sidebar .ts-sidebar-row, .wiki-group-title, .wiki-group-links a):focus-visible {
  outline: 2px solid var(--ts-sidebar-accent);
  outline-offset: -2px;
}
:is(.jr-rail > a, .rail > .navlink, .wiki-sidebar .ts-sidebar-row)[aria-current="page"] {
  border-color: var(--ts-sidebar-rule);
  border-left: 3px solid var(--ts-sidebar-accent);
  background: var(--ts-sidebar-active);
  color: var(--ts-sidebar-ink);
}

:is(.jr-rail > a > span[aria-hidden], .rail > .navlink > .nav-glyph, .wiki-sidebar .ts-sidebar-icon) {
  flex: 0 0 20px;
  width: 20px;
  text-align: center;
  color: var(--ts-sidebar-accent);
}
/* Docs draws the Attacks mark instead of typing it. `display: block` takes the
   svg off the text baseline so it centres on the same line as the glyphs beside
   it. Inert in Studio, whose rail icons are all glyphs. */
.ts-sidebar-icon > svg {
  display: block;
  width: 20px;
  height: 20px;
}

.wiki-attack-tree { min-width: 0; }
.wiki-attack-tree > summary, .wiki-group > summary { list-style: none; }
.wiki-attack-tree > summary::-webkit-details-marker,
.wiki-group > summary::-webkit-details-marker { display: none; }
.wiki-link-label { min-width: 0; }
.ts-sidebar-count, .wiki-group-count {
  margin-left: auto;
  color: var(--ts-sidebar-muted);
  font: 500 13px/1.2 PlexMono, Consolas, ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}
.ts-sidebar-chevron {
  flex: 0 0 7px;
  width: 7px;
  height: 7px;
  margin-left: 2px;
  border-right: 1.5px solid var(--ts-sidebar-muted);
  border-bottom: 1.5px solid var(--ts-sidebar-muted);
  transform: rotate(-45deg);
  transition: transform .16s ease;
}
.wiki-attack-tree[open] > summary .ts-sidebar-chevron { transform: rotate(45deg); }
.wiki-tree-body {
  margin: 6px 0 8px 20px;
  padding-left: 13px;
  border-left: 1px solid var(--ts-sidebar-rule);
}
.wiki-group { margin-top: 4px; }
.wiki-group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 5px;
  color: var(--ts-sidebar-muted);
  font: 600 12px/1.35 PlexMono, Consolas, ui-monospace, monospace;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
}
.wiki-group-title:hover { color: var(--ts-sidebar-ink); }
.wiki-group-label { min-width: 0; }
.wiki-group-title::after {
  content: "";
  flex: 0 0 6px;
  width: 6px;
  height: 6px;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  transform: rotate(-45deg);
}
.wiki-group[open] > .wiki-group-title::after { transform: rotate(45deg); }
.wiki-group-links { display: grid; gap: 1px; margin: 0 0 6px; }
.wiki-group-links a {
  display: block;
  padding: 5px 6px;
  color: var(--ts-sidebar-muted);
  font: 400 14px/1.45 Inter, system-ui, sans-serif;
  overflow-wrap: anywhere;
  text-decoration: none;
}
.wiki-group-links a:hover, .wiki-group-links a[aria-current="page"] {
  color: var(--ts-sidebar-accent);
  text-decoration: none;
}
@media (prefers-reduced-motion: reduce) {
  .ts-sidebar-chevron { transition: none; }
}

@media (max-width: 840px) {
  .wiki-sidebar {
    position: fixed;
    top: var(--docs-header-height);
    bottom: 0;
    left: 0;
    z-index: 50;
    width: min(300px, 84vw);
    box-shadow: 8px 10px 26px color-mix(in srgb, var(--ts-sidebar-ink) 18%, transparent);
    transform: translateX(-104%);
    transition: transform .22s ease, visibility .22s ease;
    visibility: hidden;
  }
  .wiki-sidebar.is-mobile-open { transform: translateX(0); visibility: visible; }
  .wiki-sidebar-inner { position: static; height: 100%; max-height: none; overflow-y: auto; }
}
@media (max-width: 800px) {
  .jr-rail, .rail { display: none; width: min(280px, 82vw); box-shadow: 8px 10px 26px color-mix(in srgb, var(--ts-sidebar-ink) 18%, transparent); }
  .jr-rail.open, .rail.open { display: flex; }
  .rail { position: fixed; top: 56px; bottom: 0; left: 0; z-index: 40; }
}
@media (max-width: 600px) { .jr-rail { top: 56px; } }
