/* Right-rail CMS panel — shows the active project's pinned context
   inline on every page that loads /js/app-cms-rail.js.

   Tab on the right edge when collapsed; slides out to ~360px when open.
   State (open/closed + active project) persists in localStorage. */

.cms-rail {
  position: fixed;
  top: 38px;                    /* sit below the topnav */
  right: 0;
  bottom: 0;
  display: flex;
  z-index: 800;                 /* above page content, below modals (which use 5000+) */
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  font-size: 12.5px;
  color: #111;
}

/* Edge tab — visible when collapsed; click to open */
.cms-rail-tab {
  width: 28px;
  background: linear-gradient(180deg, #1f2937, #111827);
  color: #fde68a;
  border: 0;
  border-left: 1px solid #475569;
  cursor: pointer;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: inherit;
}
.cms-rail-tab:hover { background: linear-gradient(180deg, #334155, #1f2937); }
.cms-rail-tab .cms-rail-tab-icon { font-size: 16px; }
.cms-rail-tab .cms-rail-tab-label {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.cms-rail-tab .cms-rail-tab-bc {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9.5px;
  font-weight: 600;
  color: #94a3b8;
  letter-spacing: 0.04em;
}

/* The body of the rail — hidden until expanded */
.cms-rail-body {
  width: 0;
  background: #ffffff;
  border-left: 1px solid rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.18s ease;
  box-shadow: -4px 0 16px rgba(0,0,0,0.08);
}
.cms-rail.open .cms-rail-body { width: 360px; }
.cms-rail.open .cms-rail-tab .cms-rail-tab-label,
.cms-rail.open .cms-rail-tab .cms-rail-tab-bc { display: none; }

.cms-rail-head {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f9fafb;
  flex-shrink: 0;
}
.cms-rail-head .cms-rail-title {
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}
.cms-rail-head select {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  font: inherit;
  font-size: 11.5px;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 4px;
  background: white;
}
.cms-rail-head .cms-rail-btn {
  padding: 3px 7px;
  background: white;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 4px;
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  color: #666;
}
.cms-rail-head .cms-rail-btn:hover { color: #2563EB; border-color: #2563EB; }

.cms-rail-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 16px;
}

.cms-rail-empty {
  padding: 24px 12px;
  text-align: center;
  color: #666;
  font-size: 12px;
  line-height: 1.55;
}

.cms-rail-section {
  margin: 10px 0;
  border-radius: 6px;
  background: #fafafa;
  border: 1px solid rgba(0,0,0,0.04);
  overflow: hidden;
}
.cms-rail-section > summary {
  list-style: none;
  cursor: pointer;
  padding: 7px 10px;
  font-size: 11.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.cms-rail-section > summary::-webkit-details-marker { display: none; }
.cms-rail-section > summary:hover { background: rgba(0,0,0,0.03); }
.cms-rail-section > summary .cms-rail-count {
  margin-left: auto;
  background: #2563EB;
  color: white;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
}
.cms-rail-section > summary .cms-rail-count.zero {
  background: #e5e7eb;
  color: #6b7280;
}
.cms-rail-section .cms-rail-list { padding: 4px 10px 10px; }
.cms-rail-section .cms-rail-item {
  padding: 6px 0;
  border-top: 1px solid rgba(0,0,0,0.04);
  font-size: 11.5px;
  line-height: 1.45;
}
.cms-rail-section .cms-rail-item:first-child { border-top: 0; }
.cms-rail-section .cms-rail-item b { font-weight: 700; }
.cms-rail-section .cms-rail-item .cms-rail-meta {
  color: #666;
  font-size: 10.5px;
  margin-top: 2px;
  display: block;
}
.cms-rail-section .cms-rail-item code {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px;
  color: #2563EB;
}
.cms-rail-section .cms-rail-applies {
  background: rgba(37, 99, 235, 0.08);
  color: #2563EB;
  padding: 0 5px;
  border-radius: 8px;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-right: 4px;
}

.cms-rail-foot {
  padding: 8px 12px;
  border-top: 1px solid rgba(0,0,0,0.08);
  background: #f9fafb;
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  align-items: center;
}
.cms-rail-foot a {
  color: #2563EB;
  text-decoration: none;
  font-size: 11.5px;
  font-weight: 600;
}
.cms-rail-foot a:hover { text-decoration: underline; }
.cms-rail-foot .cms-rail-bc {
  margin-left: auto;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  color: #94a3b8;
}

/* Always overlay — no body shift. Earlier behavior pushed body content left
   by 360px when the rail opened; that broke fixed-height flex layouts (viewer)
   and constrained-grid layouts (filing_review). Overlay-everywhere is the
   safer default; the rail's box-shadow makes the boundary clear.

   Opt-in body shift (only on pages that use normal block layout) by adding
   the .cms-rail-shift class to <body>. */
body.cms-rail-shift.cms-rail-open { margin-right: 360px; transition: margin 0.18s ease; }

/* Mobile / narrow viewport — explicit no-shift even for opted-in pages */
@media (max-width: 900px) {
  body.cms-rail-shift.cms-rail-open { margin-right: 0; }
}

.cms-rail.open .cms-rail-body { box-shadow: -10px 0 30px rgba(0,0,0,0.25); }
