/* The right information rail on a Space page you manage (spec 88 §11; workbench 12/22
   item 8; architecture/contextual-navigation/01). It is the reader panel's markup
   (.kk-rpanel, .kk-rp-*) in kk-shell.css; this file only places it: a native popover
   sheet on phones, a strip docked at the window's right edge on desktop. Born
   tokens-only (shell_css_literal_ratchet). */

.kk-context-panel { --kk-context-strip: calc(var(--kk-s-7) + var(--kk-s-1)); }
.kk-context-panel .kk-rp-tab.is-greyed { color: var(--kk-faint); }
.kk-context-panel .kk-rp-tab.is-greyed.is-active { color: var(--kk-text-soft); }
.kk-context-rail-head { display: grid; gap: var(--kk-s-1); margin-bottom: var(--kk-s-4); }
.kk-context-rail-head .kk-rp-h, .kk-context-rail-head .kk-context-panel-title { margin: 0; }
.kk-context-rail-crumb { min-width: 0; color: var(--kk-text-soft); font-size: var(--kk-fs-meta); overflow-wrap: anywhere; }
.kk-context-rail-p { margin: 0 0 var(--kk-s-4); color: var(--kk-text); font-size: var(--kk-fs-body); line-height: var(--kk-lh-body); }
.kk-context-rail-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--kk-s-2); margin-bottom: var(--kk-s-4); }
.kk-context-rail-stats li { padding: var(--kk-s-2) var(--kk-s-1); }
.kk-context-rail-code { color: var(--kk-text); font: var(--kk-fs-meta) / var(--kk-lh-meta) var(--kk-font-mono); overflow-wrap: anywhere; }
.kk-context-panel .kk-rp-toc a, .kk-context-rail-greyed { display: flex; align-items: center; gap: var(--kk-s-2); padding: var(--kk-s-1) var(--kk-s-2); }
.kk-context-panel .kk-rp-toc a { align-items: flex-start; }
.kk-context-panel .kk-rp-toc a > svg { flex: none; margin-top: var(--kk-s-1); }
.kk-context-rail-row { display: grid; min-width: 0; gap: var(--kk-s-1); }
.kk-context-panel .kk-rp-toc + .kk-rp-h { margin-top: var(--kk-s-4); }
.kk-context-rail-greyed { color: var(--kk-faint); font-size: var(--kk-fs-body); cursor: default; }
.kk-context-rail-more { display: inline-block; margin-top: var(--kk-s-3); color: var(--kk-ink); font-size: var(--kk-fs-body); font-weight: 600; text-decoration: none; }
.kk-context-rail-more:hover { text-decoration: underline; }

/* Phones and tablets: the top bar's ⓘ opens a bottom sheet. Closed, the UA hides a
   popover; open, the active tab shows whatever the desktop open/closed state is. */
.kk-context-rail-sheethead {
  display: flex; align-items: center; justify-content: space-between;
  color: var(--kk-ink); font: 600 var(--kk-fs-heading) / var(--kk-lh-heading) var(--kk-font-display);
}
.kk-context-rail-sheethead .kk-rp-collapse { margin: 0; }
.kk-context-rail-toggle { display: none; }

@media (max-width: 899px) {
  .kk-rpanel.kk-context-panel:popover-open {
    position: fixed; inset: auto 0 0 0; width: 100%; max-width: none; max-height: 86dvh; margin: 0;
    display: flex; flex-direction: column; overflow: hidden;
    padding: var(--kk-s-3) 0 calc(var(--kk-s-5) + env(safe-area-inset-bottom));
    border: 0; border-radius: var(--kk-r-xl) var(--kk-r-xl) 0 0;
    background: var(--kk-bg); color: var(--kk-text); box-shadow: var(--kk-shadow-lg);
  }
  .kk-context-panel::backdrop { background: color-mix(in srgb, var(--kk-ink) 36%, transparent); }
  .kk-context-rail-sheethead { padding: 0 var(--kk-s-4); }
  .kk-context-panel .kk-rp-rail { margin: 0 var(--kk-s-4); border-bottom: 1px solid var(--kk-line); overflow-x: auto; }
  .kk-rpanel.kk-context-panel.is-collapsed .kk-rp-body { display: block; }
  /* The head and tabs stay put; only the tab's content scrolls. This outranks the
     reader's own phone sheet (kk-shell.css, max-width 560px), which shares .kk-rpanel. */
  .kk-rpanel.kk-context-panel .kk-rp-body { flex: 1; min-height: 0; max-height: none; overflow-y: auto; overscroll-behavior: contain; padding: var(--kk-s-4) var(--kk-s-4) 0; }
}

/* Desktop: the strip is docked at the window's edge under the top bar, so the ⓘ
   has nothing to open; a tab opens the 320px panel with the tabs across its top.
   These author rules outrank the UA's hidden-popover display. */
@media (min-width: 900px) {
  .kk-iconbtn.kk-context-rail-open, .kk-context-rail-sheethead { display: none; }
  .kk-context-rail-toggle { display: flex; }
  .kk-rpanel.kk-context-panel {
    position: fixed; inset: var(--kk-wtopbar-h) 0 0 auto; z-index: 20;
    width: var(--kk-context-strip); height: auto; max-height: none; margin: 0; padding: 0;
    display: flex; flex-direction: column; overflow: hidden;
    border: 0; border-left: 1px solid var(--kk-line); border-radius: 0;
    background: var(--kk-bg); color: var(--kk-text); box-shadow: none;
    transition: none; /* the page makes room at once, so the panel opens at once too */
  }
  .kk-rpanel.kk-context-panel:not(.is-collapsed) { width: 20rem; padding-left: 0; }
  .kk-context-panel .kk-rp-rail { flex-direction: column; gap: var(--kk-s-1); padding: var(--kk-s-3) 0; }
  .kk-context-panel:not(.is-collapsed) .kk-rp-rail { flex-direction: row; padding: var(--kk-s-2) var(--kk-s-3); border-bottom: 1px solid var(--kk-line); }
  .kk-context-panel .kk-context-rail-toggle { margin: auto 0 0; }
  .kk-context-panel:not(.is-collapsed) .kk-context-rail-toggle { margin: 0 0 0 auto; }
  .kk-context-panel.is-collapsed .kk-context-rail-shut,
  .kk-context-panel:not(.is-collapsed) .kk-context-rail-expand { display: none; }
  .kk-context-panel .kk-rp-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: var(--kk-s-4); }

  /* The page makes room for the strip, and for the panel when it is open. */
  .kk-main-inner:has(.kk-context-panel) { padding-right: calc(var(--kk-s-7) + var(--kk-s-1) + var(--kk-s-5)); }
  .kk-main-inner:has(.kk-context-panel:not(.is-collapsed)) { padding-right: calc(20rem + var(--kk-s-5)); }
}
