/* Mesh Guide: project rules on top of muffin.css. Muffin owns tokens and shared components. */

/* Muffin's 68ch leaves doc pages looking narrow on wide screens (same as Dev Memory). */
:root { --layout-prose: 90ch; }

/* Muffin caps the header at layout-max, but the sidebar shell runs full width. */
.app-header__inner { max-width: none; }
.app-actions { margin-left: auto; gap: var(--space-1); }

.skip-link {
  position: absolute;
  left: var(--space-2);
  top: -48px;
  z-index: 10;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-accent);
  color: var(--color-on-accent);

  &:focus { top: var(--space-2); color: var(--color-on-accent); }
}

kbd {
  display: inline-block;
  font-size: 12px;
  line-height: 18px;
  padding: 0 6px;
  border: 1px solid var(--color-border-control);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
}

/* Theme toggle shows the icon for the theme you'd switch to. */
.theme-icon-sun, .theme-icon-moon { display: inline-flex; }
.theme-icon-sun { display: none; }
:root[data-theme="dark"] {
  & .theme-icon-sun { display: inline-flex; }
  & .theme-icon-moon { display: none; }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    & .theme-icon-sun { display: inline-flex; }
    & .theme-icon-moon { display: none; }
  }
}

/* Search. The MkDocs search plugin's main.js fills the results list. */
.site-search {
  position: relative;
  display: flex;
  align-items: center;
  width: 300px;
  color: var(--color-text-muted);

  & > .icon { position: absolute; left: var(--space-3); pointer-events: none; }
  & > kbd { position: absolute; right: var(--space-2); }

  & .input {
    width: 100%;
    padding-left: 34px;
    padding-right: 32px;

    &::-webkit-search-cancel-button { display: none; }
  }
}

.site-search__results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 10;
  width: min(440px, calc(100vw - 32px));
  max-height: min(70vh, 520px);
  overflow-y: auto;
  padding: var(--space-1);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);

  & article {
    padding: var(--space-2) 10px;
    border-radius: var(--radius-md);

    &:hover { background: var(--color-hover); }
  }

  & h3 { font-size: 14px; line-height: 20px; }
  & a { text-decoration: none; }

  & p {
    margin-top: 2px;
    font-size: 13px;
    line-height: 18px;
    color: var(--color-text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  & > p { padding: var(--space-2) 10px; margin: 0; }
}

@media (max-width: 720px) {
  .site-search {
    order: 3;
    flex-basis: 100%;
    width: auto;
    padding-bottom: var(--space-2);

    & > .icon { top: 10px; }
  }

  .site-search__results { left: 0; width: auto; }
}

/* Sidebar */

.side-nav__group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

@media (min-width: 721px) {
  .app-sidebar > .sidebar-toggle {
    position: sticky;
    top: var(--space-4);
  }
}

/* Page body: the article plus an "On this page" column on wide screens. */

/* The article and its TOC column are centered as one block beside the sidebar. */
.app-main {
  --doc-width: var(--layout-prose);
  --doc-block: calc(var(--doc-width) + var(--space-7) + 200px);

  &:has(.doc--home) { --doc-width: 1000px; }
}

.doc-layout {
  display: flex;
  gap: var(--space-7);
  align-items: flex-start;
  max-width: var(--doc-block);
  margin-inline: auto;
}

.doc {
  flex: 1;
  min-width: 0;

  max-width: var(--doc-width);
}

.doc-toc {
  flex: 0 0 200px;
  position: sticky;
  top: var(--space-5);
  max-height: calc(100vh - 2 * var(--space-5));
  overflow-y: auto;

  & .label { margin-bottom: 10px; }

  & ul {
    list-style: none;
    margin: 0;
    padding: 0;
    border-left: 1px solid var(--color-border);
  }

  & a {
    display: block;
    padding: var(--space-1) 0 var(--space-1) 14px;
    margin-left: -1px;
    border-left: 2px solid transparent;
    font-size: 13px;
    line-height: 18px;
    color: var(--color-text-muted);
    text-decoration: none;

    &:hover { color: var(--color-text); }

    &.is-active {
      color: var(--color-accent);
      border-left-color: var(--color-accent);
      font-weight: 700;
    }
  }

  & .doc-toc__sub { padding-left: 26px; }
}

.doc-toc-narrow {
  display: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);

  & summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 0 14px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    list-style: none;

    &::-webkit-details-marker { display: none; }
    &::after { content: "▾"; color: var(--color-text-muted); }
  }

  &[open] summary::after { content: "▴"; }

  & ul {
    list-style: none;
    margin: 0;
    padding: 0 14px 10px;
  }

  & a {
    display: block;
    padding: 6px 0;
    font-size: 14px;
    color: var(--color-text-soft);
    text-decoration: none;
  }
}

@media (max-width: 1180px) {
  .doc-toc { display: none; }
  .doc-toc-narrow { display: block; }
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2) var(--space-5);
  max-width: var(--doc-block);
  margin-inline: auto;
  margin-top: var(--space-7);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);

  & a { color: var(--color-text-muted); }

  /* Small text goes on the children: the footer's own font size sets the ch in --doc-block. */
  & > * { font-size: 13px; line-height: 18px; }
}

/* Prose. Muffin's .prose sets markdown headings a step below page headings, because
   apps render markdown under their own h1. Here the markdown h1 is the page title,
   so headings go back to the standard type scale. */

.prose.doc {
  & h1 { font-size: 26px; line-height: 32px; letter-spacing: -0.01em; }

  & h1 + p {
    font-size: 17px;
    line-height: 27px;
    color: var(--color-text-soft);
  }

  & h2 {
    font-size: 20px;
    line-height: 28px;
    margin-top: var(--space-7);
    padding-top: var(--space-5);
    border-top: 1px solid var(--color-border);
  }

  & h3 { font-size: 17px; line-height: 24px; }

  & h1 .headerlink { display: none; }

  & .headerlink {
    margin-left: var(--space-2);
    font-weight: 400;
    color: var(--color-text-faint);
    text-decoration: none;
    opacity: 0;

    &:focus-visible { opacity: 1; }
  }

  & :is(h2, h3, h4):hover .headerlink { opacity: 1; }
  & li::marker { color: var(--color-accent); }
}

.prose.doc--home h1 { font-size: 36px; line-height: 40px; }

/* Code blocks. app.js wraps each .highlight in .code-block and adds the header. */

.code-block {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface-sunken);
  overflow: hidden;

  & pre { margin: 0; border-radius: 0; }
}

.code-block__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 36px;
  padding: var(--space-1) var(--space-1) var(--space-1) 14px;
  border-bottom: 1px solid var(--color-border);

  & .btn.is-done { color: var(--color-ok-text); }
}

/* Pygments token classes */
.highlight {
  & :is(.k, .kc, .kd, .kn, .kp, .kr, .kt) { color: var(--color-accent-3); font-weight: 700; }
  & :is(.nb, .bp, .nf) { color: var(--color-accent); font-weight: 700; }
  & :is(.s, .s1, .s2, .sb, .sc, .sd, .se, .sh, .si, .sx, .sr, .ss) { color: var(--color-accent-2); }
  & :is(.m, .mb, .mf, .mh, .mi, .mo, .il, .nv, .vc, .vg, .vi) { color: var(--color-accent-3); }
  & :is(.c, .c1, .ch, .cm, .cp, .cs) { color: var(--color-text-muted); font-style: italic; }
  & :is(.o, .ow, .p) { color: var(--color-text-muted); }
  & .gp { color: var(--color-ok-text); font-weight: 700; }
  & .go { color: var(--color-text-soft); }
}

/* Tables. app.js adds Muffin's .table-wrap and .table; this undoes the plainer
   rules .prose applies to bare markdown tables so the Table component shows through. */
.prose .table-wrap {
  & table { display: table; }
  & :is(th, td) { border: 0; padding: var(--space-2) var(--space-3); }
  & td { border-top: 1px solid var(--color-border); vertical-align: top; }
  & tbody tr:hover { background: none; }
}

/* Admonitions */

.admonition {
  --adm-fg: var(--color-accent);
  --adm-bg: var(--color-accent-soft);
  --adm-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4'/%3E%3Cpath d='M12 8h.01'/%3E%3C/svg%3E");

  position: relative;
  padding: 14px var(--space-4) 14px 44px;
  border: 1px solid color-mix(in srgb, var(--adm-fg) 30%, transparent);
  border-radius: var(--radius-lg);
  background: var(--adm-bg);

  &::before {
    content: "";
    position: absolute;
    left: var(--space-4);
    top: 18px;
    width: 16px;
    height: 16px;
    background: var(--adm-fg);
    mask: var(--adm-icon) center / contain no-repeat;
  }

  & > * { margin: 0; }
  & > * + * { margin-top: var(--space-2); }

  & .admonition-title {
    font-weight: 700;
    color: var(--adm-fg);
  }

  & .admonition-title + * { margin-top: 2px; }

  & pre { background: var(--color-surface); }

  &:is(.tip, .hint, .success, .check, .done) {
    --adm-fg: var(--color-ok-text);
    --adm-bg: var(--color-ok-bg);
    --adm-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m9 12 2 2 4-4'/%3E%3C/svg%3E");
  }

  &:is(.warning, .caution, .attention) {
    --adm-fg: var(--color-warn-text);
    --adm-bg: var(--color-warn-bg);
    --adm-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3'/%3E%3Cpath d='M12 9v4'/%3E%3Cpath d='M12 17h.01'/%3E%3C/svg%3E");
  }

  &:is(.danger, .error, .failure, .fail, .bug) {
    --adm-fg: var(--color-error-text);
    --adm-bg: var(--color-error-bg);
    --adm-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7.86 2h8.28L22 7.86v8.28L16.14 22H7.86L2 16.14V7.86z'/%3E%3Cpath d='m15 9-6 6'/%3E%3Cpath d='m9 9 6 6'/%3E%3C/svg%3E");
  }

  &:is(.question, .example, .quote, .abstract) {
    --adm-fg: var(--color-accent-3);
    --adm-bg: var(--color-accent-3-soft);
  }
}

/* Definition lists. app.js turns "(shorthand: gw)" style asides in the term into badges.
   Muffin's KeyValue (dl.kv) keeps its own layout. */

.prose dl:not(.kv) {
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);

  & dt, & dd { padding: 14px var(--space-4); border-bottom: 1px solid var(--color-border); }

  & dt {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;

    & code {
      font-size: 14px;
      font-weight: 700;
      color: var(--color-accent);
      background: none;
      padding: 0;
    }
  }

  & dd {
    margin: 0;
    padding-left: 0;
    color: var(--color-text-soft);

    & > * + * { margin-top: var(--space-4); }
  }

  & > :nth-last-child(-n + 2) { border-bottom: 0; }

  @media (max-width: 600px) {
    grid-template-columns: minmax(0, 1fr);

    & dt { padding-bottom: var(--space-1); border-bottom: 0; }
    & dd { padding-left: var(--space-4); padding-top: 0; }
    & > dd:not(:last-child) { border-bottom: 1px solid var(--color-border); }
  }
}

/* Numbered steps: a markdown ordered list inside <div class="steps" markdown>,
   each item starting with a bold title. */
.steps ol {
  list-style: none;
  counter-reset: step;
  padding-left: 0;

  & > li {
    counter-increment: step;
    position: relative;
    padding-left: 44px;

    &::before {
      content: counter(step);
      position: absolute;
      left: 0;
      top: -2px;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 28px;
      height: 28px;
      border-radius: var(--radius-pill);
      background: var(--color-accent-soft);
      color: var(--color-accent);
      font-weight: 700;
      font-size: 14px;
    }

    & > strong:first-child { display: block; }
  }

  & > li + li { margin-top: var(--space-4); }
}

/* Content tabs. app.js rebuilds pymdownx.tabbed markup as Muffin Tabs. */
.tabbed > [role="tabpanel"] {
  padding-top: var(--space-3);

  & > * + * { margin-top: var(--space-4); }
}

/* Previous / next links */

.page-nav {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-7);

  & a.card {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  & .label { display: flex; align-items: center; gap: 6px; }

  & .page-nav__next {
    grid-column: 2;
    align-items: flex-end;
    text-align: right;
  }

  @media (max-width: 600px) {
    grid-template-columns: minmax(0, 1fr);

    & .page-nav__next { grid-column: 1; }
  }
}

.page-nav__title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-accent);
}

/* Card grids in pages. auto-fit so two or three cards fill the row instead of leaving an empty track. */
.prose .grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.prose .card {
  /* Logo and title share the first row; the last row stretches so the links line up across cards. */
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto auto 1fr;
  column-gap: var(--space-3);
  row-gap: var(--space-2);

  & > :not(.card-ic, h3) { grid-column: 1 / -1; }

  & h3 { margin: 0; align-self: center; }

  & p {
    margin: 0;
    font-size: 14px;
    line-height: 21px;
    color: var(--color-text-soft);
  }

  & .meta {
    font-size: 13px;
    line-height: 18px;
    color: var(--color-text-muted);
  }

  & ul {
    align-self: end;
    list-style: none;
    margin: 0;
    padding: 10px 0 0;
    border-top: 1px solid var(--color-border);
  }

  & li { margin: 0; }

  & li a {
    display: flex;
    align-items: center;
    min-height: 32px;
    font-size: 14px;
    text-decoration: none;

    &:hover { text-decoration: underline; }
  }
}

.card-ic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  background: var(--color-accent-soft);
  color: var(--color-accent);

  & .icon { width: 24px; height: 24px; }

  &.pink { background: var(--color-accent-2-soft); color: var(--color-accent-2); }
  &.lavender { background: var(--color-accent-3-soft); color: var(--color-accent-3); }
}

/* Platform logos on the home page cards keep their own brand colors: image tiles carry their
   own background, and Reticulum's black-on-white badge sits on a neutral tile. */
.card-ic--brand {
  background: var(--color-surface-sunken);
  color: var(--color-text);
}

.card-ic--image {
  overflow: hidden;

  & a { display: contents; }
  & img { width: 100%; height: 100%; }
}

.rns-logo {
  width: 42px;
  height: 42px;
}

.trademark-note {
  font-size: 13px;
  line-height: 18px;
  color: var(--color-text-muted);
}
