/* The messaging rail (rail.js, docs/CONSOLE-REDESIGN.md §4, step 11): a column of the frame between the sidebar and the
   content. Its head sits on --chrome-bg in the header's row; under it the rail is its own surface (tt-r4-rail): a card
   on --rail-bg with the content's corners (--rail-radius) and the same gap to the content and the window's foot
   (--content-inset), edged by a --rail-edge hairline, as the content card is by --chrome-line. No shadow: it is docked.
   Folded it is 64 px of faces (--rail-w); widened, 320 px of the Conversations
   list (--rail-w-open), which pushes the content as Keep open does. The width animates over 240 ms and the words fade in
   after the column has room; with reduced motion (tokens.css) it jumps. Flat: no rows boxed, no hairline between rows
   (the mockup's rail), a hairline before the machines. Tokens only; the frame's pairs are THEMES' (chromeFg on chromeBg,
   chromeHover, chromeActive). The sidebar's hover overlay (z 30) passes over the rail (z 20); a glimpse (faces.js, z 170)
   over both. Off a phone only: a phone has the strip of faces in Conversations (step 10). Loaded after frame.css. */

.mrail { display: none; }
.mrail[hidden] { display: none !important; }

@media (min-width: 781px) {
  /* sidebar | rail | header over content. Focus mode on a view (views.js) keeps its own two columns and no rail. */
  body:not(.chrome-compact):not(.chrome-hidden) .shell[data-msg="rail"] { grid-template-columns: var(--side-w) auto minmax(0, 1fr); }
  body:not(.chrome-compact):not(.chrome-hidden) .shell[data-msg="rail"][data-side="open"] { grid-template-columns: var(--side-w-open) auto minmax(0, 1fr); }
  body:not(.chrome-compact):not(.chrome-hidden) .shell[data-msg="rail"] .topbar,
  body:not(.chrome-compact):not(.chrome-hidden) .shell[data-msg="rail"] .main { grid-column: 3; }
  body:not(.chrome-compact):not(.chrome-hidden) .shell[data-msg="rail"] .mrail { display: flex; }
  /* The rail is the Conversations area: its sidebar item gives way to it (§4.1). */
  .shell[data-msg="rail"] .s-item[data-area="conversations"] { display: none; }
}

.mrail { grid-row: 1 / 3; grid-column: 2; position: relative; z-index: var(--z-rail); flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  width: calc(var(--rail-w) + var(--content-inset)); background: var(--chrome-bg); color: var(--chrome-fg-2); transition: width .24s ease; }
.mrail[data-w="full"] { width: calc(var(--rail-w-open) + var(--content-inset)); }
/* the surface: a sibling of the content card */
.mr-card { flex: 1; min-height: 0; display: flex; flex-direction: column; margin: 0 var(--content-inset) var(--content-inset) 0; overflow: hidden;
  background: var(--rail-bg); color: var(--chrome-fg-2); border-radius: var(--rail-radius, var(--content-radius)); box-shadow: 0 0 0 1px var(--rail-edge); }
.mr-foot { flex: none; display: flex; justify-content: center; padding: 6px 0 8px; }
.mrail[data-w="full"] .mr-foot { display: none; }
.mr-pin { color: var(--chrome-fg); }
.mrail.mr-drag { transition: none; user-select: none; }

/* ---------- its head: in the header's row, so the fold button shares the breadcrumb's centre line ---------- */
.mr-head { display: flex; align-items: center; gap: 2px; height: var(--header-h); padding: 0 22px 0 14px; flex: none; white-space: nowrap; }
.mr-fold, .mr-btn { width: 36px; height: 36px; display: grid; place-items: center; flex: none; padding: 0; border: 0; border-radius: 6px; background: none; color: var(--chrome-fg-2); cursor: pointer; }
.mr-fold:hover, .mr-btn:hover { color: var(--chrome-fg); background: var(--chrome-hover); }
.mr-fold[aria-expanded="true"] { color: var(--chrome-fg); background: var(--chrome-active); }
.mr-fold svg, .mr-btn svg { width: 18px; height: 18px; display: block; }
.mr-fold:focus-visible, .mr-btn:focus-visible { outline: var(--focus-w, 2px) solid var(--focus); outline-offset: -2px; }
.mr-title { margin: 0 0 0 8px; font-size: 14px; font-weight: 600; color: var(--chrome-fg); overflow: hidden; text-overflow: ellipsis; }
.mr-grow { flex: 1; min-width: 0; }
.mrail[data-w="faces"] .mr-title, .mrail[data-w="faces"] .mr-wide { display: none; }

/* ---------- the list on the frame ---------- */
.mr-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; overscroll-behavior: contain; }
.mr-body::-webkit-scrollbar { display: none; }
.mrail .cvl-search { padding: 0 12px 6px; }
.mrail .cvl-search input { background: var(--chrome-hover); color: var(--chrome-fg); border-color: var(--chrome-line); }
.mrail .cvl-bar { padding: 0 12px 10px; gap: 4px; border-bottom: 1px solid var(--chrome-line); }
.mrail .fchip { border-color: transparent; color: var(--chrome-fg-2); background: none; }
.mrail .fchip:hover { color: var(--chrome-fg); background: var(--chrome-hover); border-color: transparent; }
.mrail .fchip[aria-pressed="true"] { color: var(--chrome-fg); background: var(--chrome-active); border-color: transparent; box-shadow: none; }
.mrail .fchip .c { color: var(--chrome-fg-2); }
.mrail .fsel select { color: var(--chrome-fg-2); border-color: var(--chrome-line); }
.mrail .cvl-rows { padding: 4px 0 12px; }
.mrail .cvl-row { color: var(--chrome-fg); border-bottom: 0; }
.mrail .cvl-row:hover { color: var(--chrome-fg); background: var(--chrome-hover); }
.mrail .cvl-row[aria-current="true"] { color: var(--chrome-fg); background: var(--chrome-active); box-shadow: inset 2px 0 0 var(--canopy); }
.mrail .cvl-row[aria-expanded="true"] { color: var(--chrome-fg); background: var(--chrome-hover); }
.mrail .cvl-row:focus-visible { outline: var(--focus-w, 2px) solid var(--focus); outline-offset: -2px; }
.mrail .cvl-face { color: var(--chrome-fg); background: var(--chrome-active); }
.mrail .cvl-face.k-customer { color: var(--chrome-fg); background: var(--chrome-hover); box-shadow: inset 0 0 0 1px var(--chrome-line); }
.mrail .cvl-face.grp { color: var(--chrome-fg-2); }
.mrail .cvl-face.needs, .mrail .cvl[data-width="faces"] .cvl-face.needs { box-shadow: 0 0 0 2px var(--rail-bg), 0 0 0 4px var(--canopy); }
.mrail .cvl-live, .mrail .cvl-on { box-shadow: 0 0 0 2px var(--rail-bg); }
.mrail .cvl-on { background: var(--chrome-fg-2); }
.mrail .cvl-on.up { background: var(--ok); }
.mrail .cvl-on.warn { background: var(--warn); }
.mrail .cvl-l, .mrail .cvl-h, .mrail .cvl-t time, .mrail .cvl-w, .mrail .cvl-last i, .mrail .cvl-mute { color: var(--chrome-fg-2); }
.mrail .cvl-row.unread .cvl-l { color: var(--chrome-fg); }
.mrail .cvl-h.warn { color: var(--warn); }
.mrail .cvl-none, .mrail .cvl-err { color: var(--chrome-fg-2); }
/* One face column at both widths: 40 px faces whose left edge is 12 px in, so widening never moves a face. */
.mrail .cvl[data-width="full"] .cvl-row { padding: 9px 12px; gap: 12px; }
.mrail .cvl[data-width="full"] .cvl-face { width: 40px; height: 40px; }
.mrail .cvl[data-width="faces"] .cvl-row { padding: 6px 0; }
/* Machines come last (D12), after a short hairline. */
.mrail .cvl-row:not([data-kind="machine"]) + .cvl-row[data-kind="machine"] { margin-top: 9px; }
.mrail .cvl-row:not([data-kind="machine"]) + .cvl-row[data-kind="machine"]::before { content: ""; position: absolute; top: -5px; left: 20px; width: 24px; height: 1px; background: var(--chrome-line); }
.mrail .cvl[data-width="full"] .cvl-row:not([data-kind="machine"]) + .cvl-row[data-kind="machine"]::before { left: 12px; right: 12px; width: auto; }

/* ---------- widening and folding: the words come after the room (§4.1) ---------- */
.mrail .cvl-m, .mrail .cvl-bar, .mrail .cvl-search, .mrail .mr-title, .mrail .mr-wide { transition: opacity .12s ease; }
.mrail.mr-in .cvl-m, .mrail.mr-in .cvl-bar, .mrail.mr-in .cvl-search, .mrail.mr-in .mr-title, .mrail.mr-in .mr-wide { opacity: 0; }
.mrail.mr-out .cvl-m, .mrail.mr-out .cvl-bar, .mrail.mr-out .cvl-search { opacity: 0; transition-duration: .06s; }
.mrail.mr-out .cvl-row { gap: 0; }

/* ---------- the edge: drag to widen or fold ---------- */
.mr-edge { position: absolute; top: 0; right: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: var(--z-raise); touch-action: none; }
.mr-edge::after { content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 2px; background: transparent; transition: background .12s; }
.mr-edge:hover::after, .mrail.mr-drag .mr-edge::after { background: var(--chrome-line); }

/* ---------- the sidebar's switch ---------- */
.s-item.msgmode.on-rail { color: var(--chrome-fg); }

/* ---------- the rail's glimpse (faces.js with {modal: false}): a notch pointing back at the face ---------- */
.fc-glimpse.card.notch { overflow: visible; }
.fc-glimpse.card.notch::before { content: ""; position: absolute; top: calc(var(--notch-y, 28px) - 7px); left: -6px; width: 12px; height: 12px; transform: rotate(45deg);
  background: var(--pop-bg); border-radius: 2px; }
.fc-glimpse.card.notch[data-side="left"]::before { left: auto; right: -6px; }
.fc-glimpse.card.notch > .fc-gb, .fc-glimpse.card.notch > .fc-gf { border-radius: 0 0 var(--content-radius) var(--content-radius); }
/* a machine's state, load, slots and jobs */
.fc-kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; margin: 0 0 8px; font-size: 13px; }
.fc-kv dt { color: var(--text-3); }
.fc-kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- Conversations with the rail on: nothing chosen yet ---------- */
.cv-railpick { max-width: 52ch; padding-top: 24px; }
.cv-railpick p { margin: 0 0 10px; }

/* The page takes the focus when the rail is unpinned on a collapsed sidebar (rail.js unpin): no ring round the whole page. */
#main:focus { outline: none; }
