/* side.css: an app's side panel and the frame that puts it under the
 * bar, beside <main>. Mapa's, copied (its level-up spec, §3.2); Contra is
 * the second app to use it. Tokens only, so Calma and light/dark apply.
 * Calma: only icons carry colour.
 *
 * Breakpoints are estilo's: 800px, where the bar stacks and the side
 * appears, and 80rem, from which the side is open unless folded.
 *
 * Markup: <div estilo-side-frame="open|rail|"> holds <nav estilo-side>
 * (the estilo-side template) and <main>. An empty value lets the width
 * decide.
 */

[estilo-side-frame] {
  --estilo-side-inline-size: 224px;        /* PUBLIC: the side's width now, rail included */
  --estilo-side-rail-inline-size: 56px;    /* PUBLIC */
  display: grid;
  grid-template-columns: var(--estilo-side-inline-size) minmax(0, 1fr);
  min-block-size: calc(100dvh - var(--estilo-bar-block-size, 56px));
}
/* The rail: by state, or by width when there is none (open from 80rem,
   the rail below). */
[estilo-side-frame~="rail"] { --estilo-side-inline-size: var(--estilo-side-rail-inline-size); }
@media (max-width: 79.99rem) {
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) {
    --estilo-side-inline-size: var(--estilo-side-rail-inline-size);
  }
}
[estilo-side-frame] > main { min-inline-size: 0; }

/* The places are the side's from 800px; estilo's Menu sheet carries them
   below it. */
@media (min-width: 800px) {
  :root:has([estilo-side-frame]) [estilo-bar-nav] { display: none; }
}

/* ── The side: one grid per row, a 16px icon column and the label,
   centred on one axis. ── */
[estilo-side] {
  box-sizing: border-box;
  position: sticky;
  inset-block-start: var(--estilo-bar-block-size, 56px);
  block-size: calc(100dvh - var(--estilo-bar-block-size, 56px));
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: auto;
  padding: 10px 8px 12px;
  background: light-dark(#f8f9fb, #191b21);
  border-inline-end: 1px solid var(--rst-line);
  font-size: 13px;
}
[estilo-side-item] {
  box-sizing: border-box;
  position: relative;
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 10px;
  inline-size: 100%;
  min-block-size: 30px;
  padding: 0 8px 0 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--rst-text-muted);
  font: inherit;
  line-height: 18px;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}
[estilo-side-item] > svg { inline-size: 16px; block-size: 16px; }
[estilo-side-label] { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[estilo-side-item]:hover { background: var(--rst-surface-2); color: var(--rst-text); }
[estilo-side-item]:focus-visible { outline: 2px solid var(--rst-accent); outline-offset: -2px; }
[estilo-side-item][aria-current] { background: var(--rst-accent-soft); color: var(--rst-text); font-weight: 600; }
[estilo-side-item][aria-current] > svg { color: var(--rst-accent); }
/* One full highlight: a place holding a page that has its own row is
   drawn twice, and the open side shows the unlit one; the rail, which
   hides the page rows, shows the lit one. The lit copy carries [hidden]
   for a page read with no CSS; the rail's display: grid below outranks
   the browser's own [hidden] rule. */
[estilo-side-holds="rail"] { display: none; }
/* A locked row (Mapa: a private note of your own): a lock at its end. */
[estilo-side-lock] { display: inline-flex; color: var(--rst-text-muted); }
[estilo-side-lock] > svg { inline-size: 12px; block-size: 12px; }
[estilo-side-head] {
  margin: 14px 0 2px;
  padding: 0 8px 0 10px;
  color: var(--rst-text-faint, var(--rst-text-muted));
  font-size: 11.5px;
  font-weight: 600;
  line-height: 22px;
}
[estilo-side-foot] { margin-block-start: auto; padding-block-start: 10px; display: grid; gap: 1px; }
[estilo-side-foot] form { display: contents; }
kbd[estilo-side-key] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: 1.4em;
  padding: 0 5px;
  border: 1px solid var(--rst-line);
  border-block-end-width: 2px;
  border-radius: 5px;
  background: var(--rst-surface);
  color: var(--rst-text-muted);
  font: 500 10.5px/14px var(--rst-font);
}

/* The fold: one button per state, shown by what is on screen. */
[estilo-side-fold-to="open"] { display: none; }
[estilo-side-frame~="rail"] [estilo-side-fold-to="rail"] { display: none; }
[estilo-side-frame~="rail"] [estilo-side-fold-to="open"] { display: grid; }
@media (max-width: 79.99rem) {
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-fold-to="rail"] { display: none; }
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-fold-to="open"] { display: grid; }
}

/* ── The rail: the same rows, icons only, on one axis. The label stays
   in the accessibility tree and is the tooltip. The tooltip is fixed
   where its row puts it (its static position, insets left auto), then
   moved out beside the 40px row: a fixed box escapes the side's
   scrolling, which clipped an absolute one. The tooltip is part of its
   row, so the row stays hovered while the pointer is on it, and a
   bridge (its ::before) spans the 10px gap so the pointer can cross to
   it. side.js dismisses it on Escape (data-estilo-side-tip="off") until
   the next hover or focus. ── */
@media (min-width: 800px) {
  [estilo-side-frame~="rail"] [estilo-side] { padding-inline: 8px; align-items: center; }
  [estilo-side-frame~="rail"] [estilo-side-item] {
    grid-template-columns: 18px;
    justify-content: center;
    inline-size: 40px;
    min-block-size: 38px;
    padding: 0;
    border-radius: 10px;
  }
  [estilo-side-frame~="rail"] [estilo-side-item] > svg { inline-size: 18px; block-size: 18px; }
  [estilo-side-frame~="rail"] [estilo-side-item] > kbd,
  [estilo-side-frame~="rail"] [estilo-side-head],
  [estilo-side-frame~="rail"] [estilo-side-page] { display: none; }
  [estilo-side-frame~="rail"] [estilo-side-item][aria-current] { background: none; }
  [estilo-side-frame~="rail"] [estilo-side-holds="open"] { display: none; }
  [estilo-side-frame~="rail"] [estilo-side-holds="rail"] { display: grid; }
  [estilo-side-frame~="rail"] [estilo-side-item][aria-current]::before {
    content: "";
    position: absolute;
    inset-inline-start: -8px;
    inset-block-start: 10px;
    inline-size: 3px;
    block-size: 18px;
    border-radius: 0 3px 3px 0;
    background: var(--rst-accent);
  }
  [estilo-side-frame~="rail"] [estilo-side-label] {
    position: fixed;
    margin-inline-start: 50px;
    margin-block-start: 19px;
    translate: 0 -50%;
    z-index: 30;
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--rst-text);
    color: var(--rst-surface);
    font-size: 12px;
    font-weight: 500;
    overflow: visible;
    pointer-events: none;
    opacity: 0;
    clip-path: inset(50%);
  }
  [estilo-side-frame~="rail"] [estilo-side-label]::before {
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-end: 100%;
    inline-size: 12px;
  }
  [estilo-side-frame~="rail"] [estilo-side-item]:not([data-estilo-side-tip="off"]):hover [estilo-side-label],
  [estilo-side-frame~="rail"] [estilo-side-item]:not([data-estilo-side-tip="off"]):focus-visible [estilo-side-label] {
    opacity: 1;
    clip-path: none;
    pointer-events: auto;
  }
}
@media (min-width: 800px) and (max-width: 79.99rem) {
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side] { padding-inline: 8px; align-items: center; }
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-item] {
    grid-template-columns: 18px;
    justify-content: center;
    inline-size: 40px;
    min-block-size: 38px;
    padding: 0;
    border-radius: 10px;
  }
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-item] > svg { inline-size: 18px; block-size: 18px; }
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-item] > kbd,
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-head],
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-page] { display: none; }
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-item][aria-current] { background: none; }
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-holds="open"] { display: none; }
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-holds="rail"] { display: grid; }
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-item][aria-current]::before {
    content: "";
    position: absolute;
    inset-inline-start: -8px;
    inset-block-start: 10px;
    inline-size: 3px;
    block-size: 18px;
    border-radius: 0 3px 3px 0;
    background: var(--rst-accent);
  }
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-label] {
    position: fixed;
    margin-inline-start: 50px;
    margin-block-start: 19px;
    translate: 0 -50%;
    z-index: 30;
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--rst-text);
    color: var(--rst-surface);
    font-size: 12px;
    font-weight: 500;
    overflow: visible;
    pointer-events: none;
    opacity: 0;
    clip-path: inset(50%);
  }
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-label]::before {
    content: "";
    position: absolute;
    inset-block: 0;
    inset-inline-end: 100%;
    inline-size: 12px;
  }
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-item]:not([data-estilo-side-tip="off"]):hover [estilo-side-label],
  [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-item]:not([data-estilo-side-tip="off"]):focus-visible [estilo-side-label] {
    opacity: 1;
    clip-path: none;
    pointer-events: auto;
  }
}

/* Where the engine anchors, each tooltip is tied to its own row
   (anchor-scope keeps the name to that row), so it follows the rail as
   it scrolls; a static position is fixed where layout put it. An app
   anchoring something else to a row (Mapa's New team page popover)
   names both: anchor-name: --its-own, --estilo-side-item. */
@supports (anchor-name: --estilo-side-item) {
  @media (min-width: 800px) {
    [estilo-side-item] { anchor-name: --estilo-side-item; anchor-scope: --estilo-side-item; }
    [estilo-side-frame~="rail"] [estilo-side-label] {
      position-anchor: --estilo-side-item;
      inset-block-start: anchor(center);
      inset-inline-start: calc(anchor(end) + 10px);
      margin: 0;
    }
  }
  @media (min-width: 800px) and (max-width: 79.99rem) {
    [estilo-side-frame]:not([estilo-side-frame~="open"], [estilo-side-frame~="rail"]) [estilo-side-label] {
      position-anchor: --estilo-side-item;
      inset-block-start: anchor(center);
      inset-inline-start: calc(anchor(end) + 10px);
      margin: 0;
    }
  }
}

/* Below 800px there is no side: its places are rows in estilo's Menu
   sheet. Last, so it wins over [estilo-side]'s own display. */
@media (max-width: 799.98px) {
  [estilo-side-frame] { grid-template-columns: minmax(0, 1fr); }
  [estilo-side] { display: none; }
}
