/**
 * rmc-cp-copilot-grid-lock.css — terminal copilot rail placement (control plane)
 *
 * Loaded last in control_plane_skeleton head so the operator 3-column bind wins
 * over any late shell overrides. Without an explicit grid-area pin, auto-placement
 * parks .rmc-app-shell__copilot on a full-width implicit row (bottom band).
 */

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell[data-rmc-app-shell-copilot="1"] {
  display: grid !important;
  grid-template-columns: var(--rmc-app-shell-sidebar-w, clamp(240px, 18vw, 320px)) minmax(0, 1fr) var(--rmc-app-shell-copilot-w, var(--rmc-operator-copilot-collapsed-w, 44px)) !important;
  grid-template-areas:
    "rmc-shell-h rmc-shell-h rmc-shell-h"
    "rmc-shell-sb rmc-shell-cv rmc-shell-cp"
    "rmc-shell-f rmc-shell-f rmc-shell-f" !important;
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell[data-rmc-app-shell-copilot="1"][data-copilot="expanded"] {
  --rmc-app-shell-copilot-w: var(--rmc-copilot-expanded-w, 360px);
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .rmc-app-shell__header {
  grid-area: rmc-shell-h;
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .rmc-app-shell__sidebar {
  grid-area: rmc-shell-sb;
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .rmc-app-shell__canvas {
  grid-area: rmc-shell-cv;
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .rmc-app-shell__copilot {
  grid-area: rmc-shell-cp !important;
  grid-row: 2 !important;
  grid-column: 3 !important;
  width: var(--rmc-app-shell-copilot-w, var(--rmc-operator-copilot-collapsed-w, 44px)) !important;
  max-width: var(--rmc-app-shell-copilot-w, var(--rmc-operator-copilot-collapsed-w, 44px)) !important;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  justify-self: stretch;
  align-self: stretch;
  position: relative !important;
  inset: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  top: auto !important;
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell[data-rmc-app-shell-copilot="1"] > dialog.rmc-sheet:not([open]),
html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell[data-rmc-app-shell-copilot="1"] > [data-rmc-operator-notebook],
html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .lx-notebook {
  position: fixed !important;
  grid-column: 1 !important;
  grid-row: 1 !important;
  width: auto !important;
  height: auto !important;
  margin: 0 !important;
  pointer-events: auto;
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .rmc-app-shell__footer {
  grid-area: rmc-shell-f;
}

@media (max-width: 1199.98px) {
  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell[data-rmc-app-shell-copilot="1"] {
    grid-template-columns: var(--rmc-app-shell-sidebar-w, clamp(240px, 18vw, 320px)) minmax(0, 1fr);
    grid-template-areas:
      "rmc-shell-h rmc-shell-h"
      "rmc-shell-sb rmc-shell-cv"
      "rmc-shell-f rmc-shell-f";
  }

  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .rmc-app-shell__copilot {
    display: block !important;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1080;
    width: 100% !important;
    max-width: none !important;
    height: min(78vh, 640px);
    transform: translateY(100%);
    transition: transform var(--motion-normal, 240ms) var(--ease-out, ease-out);
    box-shadow: var(--elev-3, 0 -12px 40px rgba(0, 0, 0, 0.28));
    border-radius: var(--radius-xl, 16px) var(--radius-xl, 16px) 0 0;
    overflow: hidden;
  }

  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell[data-rmc-app-shell-copilot="1"]
    > .rmc-app-shell__copilot
    .lx-copilot,
  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell[data-rmc-app-shell-copilot="1"]
    > .rmc-app-shell__copilot
    .lx-copilot__expanded {
    min-height: 0;
    max-height: 100%;
    height: 100%;
    overflow: hidden;
  }

  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell:has(> .rmc-app-shell__copilot)
    > .rmc-app-shell__copilot
    .lx-copilot,
  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell:has(> .rmc-app-shell__copilot)
    > .rmc-app-shell__copilot
    .lx-copilot__expanded {
    min-height: 0;
    max-height: 100%;
    height: 100%;
    overflow: hidden;
  }

  .rmc-copilot-mobile-fab {
    display: none;
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1075;
    width: 3rem;
    height: 3rem;
    border-radius: 999px;
    border: 1px solid var(--hairline);
    background: var(--brand-primary, #6366f1);
    color: #fff; /* off-token-allow: copilot-fab-on-brand */
    font-size: 1.25rem;
    line-height: 1;
    align-items: center;
    justify-content: center;
    box-shadow: var(--elev-2);
    cursor: pointer;
  }

  .rmc-copilot-mobile-fab:not([hidden]) {
    display: inline-flex;
  }

  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell[data-rmc-copilot-mobile-open="1"]
    .rmc-app-shell[data-rmc-app-shell-copilot="1"]
    > .rmc-app-shell__copilot {
    transform: translateY(0);
  }
}

@media (max-width: 991.98px) {
  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell[data-rmc-app-shell-copilot="1"] {
    grid-template-columns: 1fr;
    grid-template-areas:
      "rmc-shell-h"
      "rmc-shell-cv"
      "rmc-shell-f";
  }

  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .rmc-app-shell__sidebar {
    display: none;
  }

  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .rmc-app-shell__canvas {
    grid-area: rmc-shell-cv;
  }
}

/* ---------------------------------------------------------------------------
 * Belt-and-suspenders (2026-06-10): self-activating right-dock via :has().
 *
 * Every rule above keys on the `data-rmc-app-shell-copilot="1"` attribute. If
 * that attribute is ever absent while the copilot <aside> still renders — e.g.
 * the `cockpit.ai_copilot_rail.enabled` flag is read inconsistently between the
 * shell attribute and the partial, or a stale deploy ships one without the
 * other — NONE of the attribute-keyed rules match and CSS grid auto-placement
 * parks `.rmc-app-shell__copilot` on a full-width implicit row (the bottom-band
 * "stretched" bug). These rules re-pin the rail on the PRESENCE of the copilot
 * aside alone, so the right-dock cannot silently regress. Modern-browser
 * `:has()` only; older browsers still get the attribute-keyed rules above.
 * ------------------------------------------------------------------------- */
html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell:has(> .rmc-app-shell__copilot) {
  display: grid !important;
  grid-template-columns: var(--rmc-app-shell-sidebar-w, clamp(240px, 18vw, 320px)) minmax(0, 1fr) var(--rmc-app-shell-copilot-w, var(--rmc-operator-copilot-collapsed-w, 44px)) !important;
  grid-template-areas:
    "rmc-shell-h rmc-shell-h rmc-shell-h"
    "rmc-shell-sb rmc-shell-cv rmc-shell-cp"
    "rmc-shell-f rmc-shell-f rmc-shell-f" !important;
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell[data-copilot="expanded"]:has(> .rmc-app-shell__copilot) {
  --rmc-app-shell-copilot-w: var(--rmc-copilot-expanded-w, 360px);
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell:has(> .rmc-app-shell__copilot) > .rmc-app-shell__header {
  grid-area: rmc-shell-h;
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell:has(> .rmc-app-shell__copilot) > .rmc-app-shell__sidebar {
  grid-area: rmc-shell-sb;
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell:has(> .rmc-app-shell__copilot) > .rmc-app-shell__canvas {
  grid-area: rmc-shell-cv;
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell:has(> .rmc-app-shell__copilot) > .rmc-app-shell__copilot {
  grid-area: rmc-shell-cp !important;
  grid-row: 2 !important;
  grid-column: 3 !important;
  width: var(--rmc-app-shell-copilot-w, var(--rmc-operator-copilot-collapsed-w, 44px)) !important;
  max-width: var(--rmc-app-shell-copilot-w, var(--rmc-operator-copilot-collapsed-w, 44px)) !important;
  min-width: 0;
  position: relative !important;
  inset: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  top: auto !important;
}

html[data-rmc-isomorphic-template="operator-control-plane"]
  body.control-plane-shell
  .rmc-app-shell:has(> .rmc-app-shell__copilot) > .rmc-app-shell__footer {
  grid-area: rmc-shell-f;
}

@media (max-width: 1199.98px) {
  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell:has(> .rmc-app-shell__copilot) {
    grid-template-columns: var(--rmc-app-shell-sidebar-w, clamp(240px, 18vw, 320px)) minmax(0, 1fr);
    grid-template-areas:
      "rmc-shell-h rmc-shell-h"
      "rmc-shell-sb rmc-shell-cv"
      "rmc-shell-f rmc-shell-f";
  }

  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell:has(> .rmc-app-shell__copilot) > .rmc-app-shell__copilot {
    display: block !important;
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1080;
    width: 100% !important;
    max-width: none !important;
    height: min(78vh, 640px);
    transform: translateY(100%);
    transition: transform var(--motion-normal, 240ms) var(--ease-out, ease-out);
    box-shadow: var(--elev-3, 0 -12px 40px rgba(0, 0, 0, 0.28));
    border-radius: var(--radius-xl, 16px) var(--radius-xl, 16px) 0 0;
    overflow: hidden;
  }

  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell[data-rmc-copilot-mobile-open="1"]
    .rmc-app-shell:has(> .rmc-app-shell__copilot)
    > .rmc-app-shell__copilot {
    transform: translateY(0);
  }

  .rmc-copilot-mobile-fab {
    display: none;
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1075;
    width: 3rem;
    height: 3rem;
    border-radius: 999px;
    border: 1px solid var(--hairline);
    background: var(--brand-primary, #6366f1);
    color: #fff; /* off-token-allow: copilot-fab-on-brand */
    font-size: 1.25rem;
    line-height: 1;
    align-items: center;
    justify-content: center;
    box-shadow: var(--elev-2);
    cursor: pointer;
  }

  .rmc-copilot-mobile-fab:not([hidden]) {
    display: inline-flex;
  }
}

/* Approved responsive contract: at 1024px and below the operator workspace is
   one full-width column. Keep this terminal so both the attribute-keyed rule
   and the later :has() safety net cannot restore the desktop sidebar column. */
@media (max-width: 1024px) {
  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell[data-rmc-app-shell-copilot="1"],
  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell:has(> .rmc-app-shell__copilot) {
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-areas:
      "rmc-shell-h"
      "rmc-shell-cv"
      "rmc-shell-f" !important;
  }

  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .rmc-app-shell__sidebar,
  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell:has(> .rmc-app-shell__copilot) > .rmc-app-shell__sidebar,
  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .rmc-app-shell__copilot,
  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell:has(> .rmc-app-shell__copilot) > .rmc-app-shell__copilot {
    display: none !important;
  }

  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell[data-rmc-app-shell-copilot="1"] > .rmc-app-shell__canvas,
  html[data-rmc-isomorphic-template="operator-control-plane"]
    body.control-plane-shell
    .rmc-app-shell:has(> .rmc-app-shell__copilot) > .rmc-app-shell__canvas {
    grid-area: rmc-shell-cv !important;
    grid-column: 1 / -1 !important;
    width: 100% !important;
    max-width: none !important;
    margin-inline: 0 !important;
  }
}
