/*
 * HPCXS app shell: left nav, top bar, content area, user menu, login.
 * Uses only tokens from hpcxs-tokens.css. Loaded after AdminLTE so it wins without !important
 * except where AdminLTE itself uses !important.
 */

/* ---------- Base ---------- */
.xs-body *,
.xs-body *::before,
.xs-body *::after {
  box-sizing: border-box;
}

html,
body.xs-body {
  background: var(--bg);
  color: var(--text);
}

body.xs-body {
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  margin: 0;
}

.xs-body :focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.xs-skip {
  position: absolute;
  inset-inline-start: var(--space-2);
  inset-block-start: -100px;
  z-index: 1100;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
}

.xs-skip:focus {
  inset-block-start: var(--space-2);
  color: var(--accent-contrast);
}

/* Visually hidden (Bootstrap's .sr-only is not loaded on the login page) */
.xs-body .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Wordmark ---------- */
.xs-wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  font-weight: var(--fw-semibold);
  font-size: var(--fs-16);
  letter-spacing: 0.08em;
  text-decoration: none;
  white-space: nowrap;
}

.xs-wordmark:hover {
  color: var(--text);
  text-decoration: none;
}

.xs-wordmark-mark {
  width: 28px;
  height: 28px;
  flex: none;
  color: var(--accent);
}

.xs-wordmark-x {
  color: var(--accent);
}

/* ---------- Shell grid ---------- */
.xs-shell {
  min-height: 100vh;
}

.xs-nav {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  z-index: 1040;
  width: var(--nav-w);
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border-inline-end: 1px solid var(--border);
  transition: width var(--dur-panel) var(--ease), transform var(--dur-panel) var(--ease);
}

.xs-frame {
  margin-inline-start: var(--nav-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin var(--dur-panel) var(--ease);
  min-width: 0;
}

/* ---------- Left nav ---------- */
.xs-nav-head {
  height: var(--topbar-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding-inline: var(--space-4) var(--space-2);
  border-block-end: 1px solid var(--border);
}

.xs-nav-head .xs-wordmark {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.xs-nav-scroll {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) var(--space-2);
}

.xs-nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.xs-nav-section {
  font-size: var(--fs-12);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--space-4) var(--space-3) var(--space-2);
  white-space: nowrap;
  overflow: hidden;
}

.xs-nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--hit);
  padding-inline: var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: var(--fw-medium);
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.xs-nav-link:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.xs-nav-link.is-active {
  background: var(--accent-soft);
  color: var(--text);
}

.xs-nav-link.is-active::before {
  content: '';
  position: absolute;
  inset-inline-start: calc(-1 * var(--space-2));
  inset-block: var(--space-2);
  width: 3px;
  border-radius: var(--radius-pill);
  background: var(--accent);
}

.xs-nav-link.is-active .xs-nav-icon {
  color: var(--accent);
}

.xs-nav-icon {
  width: 20px;
  flex: none;
  text-align: center;
  font-size: var(--fs-16);
}

.xs-nav-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Count badge on a nav item (AEC-1 phase 2: open efficiency alerts). */
.xs-nav-badge {
  margin-inline-start: auto;
  min-width: 20px;
  height: 20px;
  padding-inline: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--wait-soft);
  color: var(--wait);
  font-size: var(--fs-12);
  font-weight: var(--fw-semibold);
  font-feature-settings: "tnum";
}

.xs-nav-collapsed .xs-nav-badge {
  position: absolute;
  inset-block-start: 4px;
  inset-inline-end: 4px;
  min-width: 16px;
  height: 16px;
  padding-inline: 4px;
  font-size: 10px;
}

.xs-nav-foot {
  flex: none;
  padding: var(--space-2);
  border-block-start: 1px solid var(--border);
}

/* Collapsed (icons only) */
.xs-nav-collapsed .xs-nav {
  width: var(--nav-w-collapsed);
}

.xs-nav-collapsed .xs-frame {
  margin-inline-start: var(--nav-w-collapsed);
}

.xs-nav-collapsed .xs-nav-label,
.xs-nav-collapsed .xs-nav-head .xs-wordmark-text {
  display: none;
}

.xs-nav-collapsed .xs-nav-head {
  padding-inline: var(--space-2);
  justify-content: center;
}

.xs-nav-collapsed .xs-nav-head .xs-wordmark {
  display: none;
}

.xs-nav-collapsed .xs-nav-section {
  height: 1px;
  padding: 0;
  margin: var(--space-3) var(--space-2);
  background: var(--border);
  color: transparent;
}

.xs-nav-collapsed .xs-nav-link {
  justify-content: center;
  padding-inline: 0;
}

.xs-nav-collapsed #nav-collapse-btn .fa-angles-left,
.xs-nav-collapsed #nav-collapse-btn .fa-angle-double-left {
  transform: scaleX(-1);
}

/* ---------- Icon buttons ---------- */
.xs-icon-btn {
  width: var(--hit);
  height: var(--hit);
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.xs-icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* ---------- Top bar ---------- */
.xs-topbar {
  position: sticky;
  inset-block-start: 0;
  z-index: 1030;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-inline: var(--gutter);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-block-end: 1px solid var(--border);
}

.xs-topbar .xs-wordmark {
  display: none;
}

#nav-open-btn {
  display: none;
}

.xs-copilot {
  flex: 1;
  max-width: 560px;
  position: relative;
  display: flex;
  align-items: center;
  cursor: not-allowed;
}

.xs-copilot-icon {
  position: absolute;
  inset-inline-start: var(--space-3);
  color: var(--accent);
  pointer-events: none;
}

.xs-copilot input {
  width: 100%;
  height: var(--hit);
  padding-inline: calc(var(--space-3) + 24px) 112px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font: inherit;
  cursor: not-allowed;
  pointer-events: none;
}

.xs-copilot input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.xs-copilot-soon {
  position: absolute;
  inset-inline-end: var(--space-2);
  font-size: var(--fs-12);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px var(--space-2);
  pointer-events: none;
  white-space: nowrap;
}

.xs-topbar-spacer {
  flex: 1;
}

.xs-topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-inline-start: auto;
}

/* Chips and pills in the top bar */
.xs-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 32px;
  padding-inline: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-1);
  color: var(--text);
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  white-space: nowrap;
}

.xs-chip-muted {
  color: var(--text-muted);
  font-weight: var(--fw-regular);
}

.xs-dot {
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--idle);
}

.xs-dot[data-state="ok"] {
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.xs-dot[data-state="wait"] {
  background: var(--wait);
  box-shadow: 0 0 0 3px var(--wait-soft);
}

.xs-dot[data-state="fail"] {
  background: var(--fail);
  box-shadow: 0 0 0 3px var(--fail-soft);
}

.xs-dot.is-pulsing {
  animation: xs-pulse var(--dur-pulse) var(--ease) 1;
}

@keyframes xs-pulse {
  50% {
    transform: scale(1.15);
    opacity: 0.6;
  }
}

/* Page guide button (Driver.js anchor: #btn-start-tour) */
.xs-guide-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 32px;
  padding-inline: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.xs-guide-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.xs-guide-btn i {
  color: var(--accent);
}

/* ---------- User menu ---------- */
.xs-usermenu {
  position: relative;
}

.xs-user-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--hit);
  padding-inline: var(--space-1) var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease);
}

.xs-user-btn:hover,
.xs-user-btn[aria-expanded="true"] {
  background: var(--surface-2);
}

.xs-avatar {
  width: 32px;
  height: 32px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-13);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
}

.xs-user-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: var(--fw-medium);
}

.xs-role {
  font-size: var(--fs-12);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.06em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 2px var(--space-2);
}

.xs-menu {
  position: absolute;
  inset-inline-end: 0;
  inset-block-start: calc(100% + var(--space-2));
  min-width: 240px;
  padding: var(--space-2);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-overlay);
  z-index: 1060;
  opacity: 0;
  transform: translateY(-4px);
  visibility: hidden;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), visibility var(--dur-fast);
}

.xs-menu.is-open {
  opacity: 1;
  transform: none;
  visibility: visible;
  /* Visible at once on open, so keyboard opening can focus the first item (the fade still runs). */
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease), visibility 0s;
}

.xs-menu-head {
  padding: var(--space-2) var(--space-3) var(--space-3);
  border-block-end: 1px solid var(--border);
  margin-block-end: var(--space-2);
}

.xs-menu-head strong {
  display: block;
  font-weight: var(--fw-semibold);
  overflow: hidden;
  text-overflow: ellipsis;
}

.xs-menu-head span {
  color: var(--text-muted);
  font-size: var(--fs-13);
}

.xs-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--hit);
  padding-inline: var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}

.xs-menu-item:hover,
.xs-menu-item:focus-visible {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.xs-menu-item i {
  flex: none;
  width: 18px;
  text-align: center;
  color: var(--text-muted);
}

.xs-menu-item-meta {
  margin-inline-start: auto;
  color: var(--text-muted);
  font-size: var(--fs-12);
}

.xs-menu-item.is-danger,
.xs-menu-item.is-danger i {
  color: var(--fail);
}

.xs-menu-sep {
  height: 1px;
  margin: var(--space-2) 0;
  background: var(--border);
}

/* ---------- Content ---------- */
.xs-main {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--space-5) var(--gutter) var(--space-6);
  min-width: 0;
}

.xs-main > .container-fluid {
  padding-inline: 0;
}

/* Legacy pages that still wrap themselves in AdminLTE's .content-wrapper (xray.html): neutralize the
   offset AdminLTE computes for its own sidebar. */
.xs-main .content-wrapper {
  margin-inline-start: 0 !important;
  min-height: 0 !important;
  background: transparent !important;
  transition: none;
}

.xs-main .content-wrapper > .content-header,
.xs-main .content-wrapper > .content {
  padding-inline: 0;
}

.xs-main .content-wrapper .container-fluid {
  padding-inline: 0;
}

/* Flash messages */
.xs-flash {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin-block-end: var(--space-4);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--text);
}

.xs-flash i {
  margin-block-start: 2px;
  color: var(--accent);
}

.xs-flash[data-kind="danger"],
.xs-flash[data-kind="error"] {
  border-inline-start-color: var(--fail);
}

.xs-flash[data-kind="danger"] i,
.xs-flash[data-kind="error"] i {
  color: var(--fail);
}

.xs-flash[data-kind="warning"] {
  border-inline-start-color: var(--wait);
}

.xs-flash[data-kind="warning"] i {
  color: var(--wait);
}

.xs-flash[data-kind="success"] {
  border-inline-start-color: var(--ok);
}

.xs-flash[data-kind="success"] i {
  color: var(--ok);
}

/* Nav overlay (mobile drawer) */
.xs-scrim {
  position: fixed;
  inset: 0;
  z-index: 1035;
  background: var(--scrim);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-panel) var(--ease), visibility var(--dur-panel);
}

/* ---------- Responsive ---------- */
@media (max-width: 1279.98px) {
  .xs-cluster-meta {
    display: none;
  }
}

@media (max-width: 1023.98px) {
  .xs-user-name,
  .xs-guide-label {
    display: none;
  }
}

@media (max-width: 767.98px) {
  .xs-nav {
    width: var(--nav-w);
    transform: translateX(-100%);
    box-shadow: none;
  }

  .xs-frame,
  .xs-nav-collapsed .xs-frame {
    margin-inline-start: 0;
  }

  /* The drawer always shows labels, even if the desktop nav was collapsed */
  .xs-nav-collapsed .xs-nav {
    width: var(--nav-w);
  }

  .xs-nav-collapsed .xs-nav-label,
  .xs-nav-collapsed .xs-nav-head .xs-wordmark {
    display: revert;
  }

  .xs-nav-collapsed .xs-nav-head .xs-wordmark {
    display: inline-flex;
  }

  .xs-nav-collapsed .xs-nav-head .xs-wordmark-text {
    display: inline;
  }

  .xs-nav-collapsed .xs-nav-head {
    justify-content: flex-start;
    padding-inline: var(--space-4) var(--space-2);
  }

  .xs-nav-collapsed .xs-nav-link {
    justify-content: flex-start;
    padding-inline: var(--space-3);
  }

  .xs-nav-collapsed .xs-nav-section {
    height: auto;
    margin: 0;
    padding: var(--space-4) var(--space-3) var(--space-2);
    background: none;
    color: var(--text-muted);
  }

  #nav-collapse-btn {
    display: none;
  }

  .xs-nav-open .xs-nav {
    transform: none;
    box-shadow: var(--shadow-overlay);
  }

  .xs-nav-open .xs-scrim {
    opacity: 1;
    visibility: visible;
  }

  #nav-open-btn {
    display: inline-flex;
  }

  .xs-topbar {
    gap: var(--space-2);
  }

  .xs-topbar .xs-wordmark {
    display: inline-flex;
  }

  .xs-topbar .xs-wordmark-text {
    font-size: var(--fs-14);
  }

  .xs-copilot {
    display: none;
  }

  /* Keep the status text for screen readers; show only the dot. */
  .xs-cluster-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .xs-chip.xs-cluster {
    padding-inline: var(--space-3);
  }

  .xs-role,
  .xs-user-btn .fa-chevron-down {
    display: none;
  }

  .xs-main {
    padding-block-start: var(--space-4);
  }
}

@media (min-width: 768px) {
  .xs-topbar-spacer {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .xs-nav,
  .xs-frame,
  .xs-menu,
  .xs-scrim {
    transition: none;
  }

  .xs-dot.is-pulsing {
    animation: none;
  }
}

/* ---------- Driver.js theme ---------- */
.driver-popover.xs-tour,
.driver-popover {
  background-color: var(--surface-1);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-overlay);
  padding: var(--space-5);
  font-family: var(--font-sans);
}

.driver-popover-title {
  font-size: var(--fs-16);
  font-weight: var(--fw-semibold);
  color: var(--text);
  margin-bottom: var(--space-2);
}

.driver-popover-description {
  font-size: var(--fs-14);
  color: var(--text-muted);
  line-height: 1.5;
}

.driver-popover-progress-text {
  color: var(--text-muted);
  font-size: var(--fs-13);
}

.driver-popover-footer button {
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-4);
  font-weight: var(--fw-medium);
  text-shadow: none;
  font-family: var(--font-sans);
}

.driver-popover .driver-popover-prev-btn,
.driver-popover .driver-popover-prev-btn:hover,
.driver-popover .driver-popover-prev-btn:focus {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.driver-popover .driver-popover-next-btn,
.driver-popover .driver-popover-next-btn:hover,
.driver-popover .driver-popover-next-btn:focus {
  background: var(--accent);
  color: var(--accent-contrast);
  border: 1px solid var(--accent);
}

.driver-popover .driver-popover-footer button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.driver-popover-close-btn {
  color: var(--text-muted);
}

.driver-popover-close-btn:hover {
  color: var(--text);
}

.driver-popover-arrow {
  display: none;
}

/* ---------- Login ---------- */
.xs-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5) var(--space-4);
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.xs-login-bg {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
}

/* Soft dot grid that fades out toward the edges */
.xs-login-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(color-mix(in srgb, var(--text-muted) 22%, transparent) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 20%, transparent 70%);
  mask-image: radial-gradient(ellipse at center, #000 20%, transparent 70%);
}

/* Slow drifting accent glow */
.xs-login-bg::after {
  content: '';
  position: absolute;
  width: 720px;
  height: 720px;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  margin: -360px 0 0 -360px;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 16%, transparent) 0%, transparent 60%);
  animation: xs-drift 18s var(--ease) infinite alternate;
}

@keyframes xs-drift {
  from {
    transform: translate(-12%, -8%) scale(1);
  }

  to {
    transform: translate(12%, 8%) scale(1.1);
  }
}

.xs-login-nodes {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  color: var(--accent);
  opacity: 0.5;
}

.xs-login-nodes circle {
  fill: currentColor;
  animation: xs-blink 4s ease-in-out infinite;
}

.xs-login-nodes line {
  stroke: color-mix(in srgb, var(--accent) 35%, transparent);
  stroke-width: 1;
  stroke-dasharray: 4 6;
  animation: xs-flow 6s linear infinite;
}

/* Staggered so the nodes twinkle independently */
.xs-login-nodes circle:nth-child(1) {
  animation-delay: 0s;
}

.xs-login-nodes circle:nth-child(2) {
  animation-delay: 0.6s;
}

.xs-login-nodes circle:nth-child(3) {
  animation-delay: 1.4s;
}

.xs-login-nodes circle:nth-child(4) {
  animation-delay: 2.1s;
}

.xs-login-nodes circle:nth-child(5) {
  animation-delay: 0.9s;
}

.xs-login-nodes circle:nth-child(6) {
  animation-delay: 2.6s;
}

.xs-login-nodes circle:nth-child(7) {
  animation-delay: 1.1s;
}

.xs-login-nodes circle:nth-child(8) {
  animation-delay: 0.3s;
}

.xs-login-nodes circle:nth-child(9) {
  animation-delay: 1.8s;
}

.xs-login-nodes circle:nth-child(10) {
  animation-delay: 2.9s;
}

.xs-login-nodes circle:nth-child(11) {
  animation-delay: 0.5s;
}

@keyframes xs-blink {
  0%,
  100% {
    opacity: 0.25;
  }

  50% {
    opacity: 1;
  }
}

@keyframes xs-flow {
  to {
    stroke-dashoffset: -100;
  }
}

@media (prefers-reduced-motion: reduce) {
  .xs-login-bg::after,
  .xs-login-nodes circle,
  .xs-login-nodes line {
    animation: none;
  }
}

.xs-login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
  padding: var(--space-6);
}

.xs-login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin-block-end: var(--space-5);
  text-align: center;
}

.xs-login-brand .xs-wordmark {
  font-size: var(--fs-24);
  letter-spacing: 0.12em;
}

.xs-login-brand .xs-wordmark-mark {
  width: 36px;
  height: 36px;
}

.xs-login-brand p {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--fs-14);
}

.xs-login-title {
  font-size: var(--fs-20);
  font-weight: var(--fw-semibold);
  margin: 0 0 var(--space-1);
}

.xs-login-sub {
  margin: 0 0 var(--space-5);
  color: var(--text-muted);
}

/* IDEA-13: "Sign in to open the shared launch link" */
.xs-login-next {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  margin: calc(-1 * var(--space-3)) 0 var(--space-5);
  padding: var(--space-3);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--text);
  font-size: var(--fs-13);
  line-height: 1.5;
}
.xs-login-next > i { color: var(--accent); margin-block-start: 3px; }
[data-theme="light"] .xs-login-next > i { color: var(--text); }

.xs-field {
  margin-block-end: var(--space-4);
}

.xs-field + .xs-btn-primary {
  margin-block-start: var(--space-2);
}

.xs-field label {
  display: block;
  margin-block-end: var(--space-2);
  font-size: var(--fs-13);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
}

.xs-input-wrap {
  position: relative;
}

.xs-input {
  width: 100%;
  height: 44px;
  padding-inline: var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.xs-input-wrap .xs-input {
  padding-inline-end: calc(var(--hit) + var(--space-1));
}

.xs-input::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

.xs-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.xs-input-wrap .xs-icon-btn {
  position: absolute;
  inset-inline-end: 2px;
  inset-block-start: 2px;
}

.xs-btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  width: 100%;
  height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: filter var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.xs-btn-primary:hover {
  filter: brightness(1.08);
}

.xs-btn-primary:active {
  transform: scale(0.99);
}

.xs-btn-primary[disabled] {
  opacity: 0.7;
  cursor: progress;
}

.xs-alert-error {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  padding: var(--space-3);
  margin-block-end: var(--space-4);
  border: 1px solid color-mix(in srgb, var(--fail) 35%, transparent);
  border-radius: var(--radius-sm);
  background: var(--fail-soft);
  color: var(--text);
  font-size: var(--fs-13);
}

.xs-alert-error i {
  color: var(--fail);
  margin-block-start: 2px;
}

.xs-login-foot {
  margin-block-start: var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: var(--fs-12);
}

.xs-login-foot .xs-icon-btn {
  width: 32px;
  height: 32px;
}

@media (max-width: 479.98px) {
  .xs-login-card {
    padding: var(--space-5);
  }
}

/* ADM-2 white-label: the logo and name from Admin -> Server settings (templates/_brand.html). */
.xs-brand-logo { width: 28px; height: 28px; object-fit: contain; border-radius: 6px; flex: none; }
.xs-nav .xs-brand-name, .xs-topbar .xs-brand-name { max-width: 16ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* IT-1: "Sign in with <provider>" buttons and the directory note on the sign-in page. */
.xs-sso-list {
  display: grid;
  gap: var(--space-2);
}

.xs-sso-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 44px;
  padding-inline: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-weight: var(--fw-semibold);
  text-decoration: none;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.xs-sso-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.xs-sso-btn:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.xs-sso-btn i {
  width: 18px;
  text-align: center;
  color: var(--accent);
}

.xs-login-or {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-block: var(--space-4);
  color: var(--text-muted);
  font-size: var(--fs-12);
}

.xs-login-or::before,
.xs-login-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.xs-login-dir {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  margin: var(--space-3) 0 0;
  color: var(--text-muted);
  font-size: var(--fs-12);
}

.xs-login-dir i {
  margin-block-start: 2px;
}

/* IT-1: "account not enabled" page (access policy refused the sign-in). */
.xs-login-denied {
  display: grid;
  gap: var(--space-2);
  justify-items: start;
}

.xs-login-denied-icon {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--fail-soft);
  color: var(--fail);
  font-size: 18px;
}

.xs-login-denied .xs-btn-primary {
  text-decoration: none;
}

/* AEC-1 phase 3: idle-desktop banner (base_modern.html; warned or suspended desktop) */
.xs-aec-desk-banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin-block-end: var(--space-4);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--wait);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--text);
  font-size: var(--fs-13, 13px);
}
.xs-aec-desk-banner > i { color: var(--wait); }
.xs-aec-desk-banner[data-state="suspended"] { border-inline-start-color: var(--accent); }
.xs-aec-desk-banner[data-state="suspended"] > i { color: var(--accent); }
.xs-aec-desk-banner-text { flex: 1 1 320px; min-width: 0; }

/* MN-4: temporary desktop warning (portal shell and desktop page). Red in both themes: it must never look routine. */
.xs-temp-desk-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin-block-end: var(--space-4);
  border-radius: var(--radius-md, 8px);
  background: #b91c1c;
  color: #ffffff;
  border: 1px solid #fecaca;
}
.xs-temp-desk-bar > span { flex: 1 1 320px; }
.xs-temp-desk-bar strong { font-weight: 700; letter-spacing: .02em; }
.xs-temp-desk-bar .xs-btn { background: #ffffff; color: #991b1b; border-color: #ffffff; }
.xs-temp-desk-bar .xs-btn:hover, .xs-temp-desk-bar .xs-btn:focus-visible { background: #fee2e2; color: #7f1d1d; }
.xs-temp-desk-bar.is-back { background: var(--ok-soft, rgba(52, 211, 153, .14)); color: var(--text); border-color: var(--ok, #34d399); }
.xs-temp-desk-bar.is-back .xs-btn { background: var(--surface-2); color: var(--text); border-color: var(--border); }

/* ACC-1 "Desktop as an app": install help dialog (Safari) and the "installed" note (templates/_pwa_install.html). */
[data-pwa-install][hidden] { display: none !important; }
.xs-pwa-dialog {
  box-sizing: border-box;
  width: min(440px, calc(100% - 32px));
  max-width: calc(100% - 32px);
  margin: auto;
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-1);
  color: var(--text);
  box-shadow: var(--shadow-overlay);
}
.xs-pwa-dialog::backdrop { background: var(--scrim); }
.xs-pwa-dialog-head { display: flex; gap: var(--space-4); align-items: center; margin-block-end: var(--space-4); }
.xs-pwa-dialog-head img { flex: none; border-radius: var(--radius-md); }
.xs-pwa-dialog h2 { margin: 0 0 var(--space-1); font-size: var(--fs-16); font-weight: var(--fw-semibold); }
.xs-pwa-dialog-head p { margin: 0; font-size: var(--fs-13); color: var(--text-muted); }
.xs-pwa-steps { margin: 0 0 var(--space-5); padding-inline-start: var(--space-5); display: grid; gap: var(--space-2); font-size: var(--fs-14); }
.xs-pwa-steps[hidden] { display: none; }
.xs-pwa-steps i { color: var(--accent); }
.xs-pwa-dialog-actions { display: flex; justify-content: flex-end; }
.xs-pwa-installed {
  position: fixed;
  inset-block-end: var(--space-5);
  inset-inline-start: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: calc(100% - 32px);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--ok);
  border-radius: var(--radius-md);
  background: var(--surface-1);
  color: var(--text);
  box-shadow: var(--shadow-overlay);
  font-size: var(--fs-14);
}
.xs-pwa-installed[hidden] { display: none; }
.xs-pwa-installed i { color: var(--ok); }

/* ---------- Top bar collapse (UI-fix: no horizontal scroll from 320 to 1440 px) ----------
   Container queries on the bar's own content width, so an expanded or collapsed nav both work.
   Secondary items step down in this order as the bar narrows; whatever leaves the bar shows up in the
   user menu (#user-menu-overflow, .xs-menu-demo). The bell and the user menu always stay visible.
     < 1296  cluster chip detail ("· n nodes") hidden
     < 1132  Page guide becomes an icon button
     <  792  Demo chip -> flask icon (tooltip, sr-only label); user name hidden
     <  662  cluster chip -> dot only (label kept for screen readers)
     <  567  role tag and chevron hidden; Copilot input loses the Ctrl K hint
     <  448  Page guide -> menu "Page guide"           (phones: < 480 px viewport)
     <  388  Demo icon -> dot on the avatar + menu tag  (phones: < 420 px viewport)
     <  340  wordmark shows the mark only              (phones: < 372 px viewport) */
.xs-topbar {
  container: xs-topbar / inline-size;
}

.xs-copilot {
  min-width: 0;
}

.xs-topbar-actions {
  flex: none;
}

.xs-menu-overflow,
.xs-menu-guide,
.xs-menu-head .xs-menu-demo {
  display: none;
}

.xs-menu-head .xs-menu-demo {
  align-items: center;
  gap: var(--space-1);
  margin-block-start: var(--space-2);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--fs-12);
  font-style: normal;
  font-weight: var(--fw-semibold);
  width: fit-content;
}

.xs-menu-item-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.xs-menu-item-sub {
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  color: var(--text-muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Connect group (UI-connect): copy actions with a mono preview; "Copied" feedback via .is-copied. */
#user-menu {
  width: 296px;
  max-width: calc(100vw - 2 * var(--space-4));
}

.xs-menu-group-title {
  display: block;
  padding: var(--space-1) var(--space-3) var(--space-1);
  color: var(--text-muted);
  font-size: var(--fs-12);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.xs-menu-group .xs-menu-item {
  padding-block: var(--space-1);
}

.xs-menu-group .xs-menu-item-text {
  flex: 1 1 auto;
}

.xs-menu-group .xs-menu-item-sub {
  max-width: 100%;
}

.xs-menu-item-hint {
  font-size: var(--fs-12);
  color: var(--accent);
}

.xs-menu-copy.is-copied i,
.xs-menu-copy.is-copied .xs-menu-copy-label {
  color: var(--accent);
}

.xs-menu-copy.is-failed .xs-menu-copy-label {
  color: var(--fail);
}

.xs-menu-item-hint.is-muted {
  color: var(--text-muted);
}

/* UX-5 "Share my desktop (view only)": busy, done (the URL shows below the note), failed, and the in-menu confirm. */
.xs-menu-share.is-busy i { animation: xs-share-spin 1s linear infinite; }
@keyframes xs-share-spin { to { transform: rotate(360deg); } }
.xs-menu-share.is-copied i,
.xs-menu-share.is-copied .xs-menu-share-label { color: var(--accent); }
.xs-menu-share.is-failed i,
.xs-menu-share.is-failed .xs-menu-share-label,
.xs-menu-share.is-failed .xs-menu-item-hint { color: var(--fail); }
.xs-menu-share-url {
  font-family: var(--font-mono);
  font-size: var(--fs-12);
  color: var(--text);
  overflow-wrap: anywhere;
  user-select: all;
}
.xs-menu-confirm {
  margin: var(--space-1) var(--space-3) var(--space-2);
  padding: var(--space-3);
  border: 1px solid color-mix(in srgb, var(--wait) 45%, var(--border));
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--wait) 10%, var(--surface-1));
}
.xs-menu-confirm p {
  margin: 0 0 var(--space-3);
  font-size: var(--fs-13);
  color: var(--text);
}
.xs-menu-confirm p i { color: var(--wait); margin-inline-end: var(--space-1); }
.xs-menu-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}
.xs-menu-confirm-actions .xs-btn-sm { min-height: var(--hit); }
@media (prefers-reduced-motion: reduce) { .xs-menu-share.is-busy i { animation: none; } }

.xs-menu-row {
  display: flex;
  align-items: stretch;
  gap: var(--space-1);
}

.xs-menu-row > .xs-menu-copy {
  flex: 1 1 auto;
  min-width: 0;
}

.xs-menu-item.xs-menu-aux {
  flex: none;
  width: auto;
  padding-inline: var(--space-2);
  color: var(--accent);
  font-size: var(--fs-12);
  white-space: nowrap;
}

.xs-menu-item.xs-menu-aux:hover,
.xs-menu-item.xs-menu-aux:focus-visible {
  color: var(--accent);
  text-decoration: underline;
}

/* UX-7 Apps group: install / installed / fallback items swap via static/js/hpcxs-pwa.js ([hidden] must win over
   .xs-menu-item's display:flex). The menu scrolls inside itself when it is taller than the window (phones). */
[data-pwa-installed][hidden],
[data-pwa-fallback][hidden],
[data-pwa-when][hidden] {
  display: none !important;
}

.xs-menu-item i.xs-menu-ok {
  color: var(--ok);
}

#user-menu {
  max-height: calc(100vh - var(--topbar-h) - var(--space-4));
  max-height: calc(100dvh - var(--topbar-h) - var(--space-4));
  overflow-y: auto;
  overscroll-behavior: contain;
}

#user-menu .xs-menu-group + .xs-menu-group {
  margin-block-start: var(--space-2);
}

#user-menu-apps .xs-menu-item-hint {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Phones: the Apps items drop their muted second line so the menu stays short. */
@container xs-topbar (max-width: 566.98px) {
  #user-menu-apps .xs-menu-item-hint.is-muted {
    display: none;
  }
}

/* Dot on the avatar when the Demo chip has moved into the menu */
.xs-user-btn.has-demo .xs-avatar {
  position: relative;
}

@container xs-topbar (max-width: 1295.98px) {
  .xs-cluster-meta {
    display: none;
  }
}

@container xs-topbar (max-width: 1131.98px) {
  .xs-guide-label {
    display: none;
  }

  /* Icon-only Page guide: same 40 px borderless circle as the bell and the Copilot icon. */
  .xs-guide-btn {
    justify-content: center;
    width: var(--hit);
    height: var(--hit);
    padding: 0;
    border-color: transparent;
  }
}

@container xs-topbar (max-width: 791.98px) {
  .xs-demo-chip {
    justify-content: center;
    width: 32px;
    padding: 0;
    color: var(--accent);
  }

  .xs-demo-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .xs-user-name {
    display: none;
  }

  .xs-menu-head .xs-menu-demo {
    display: flex;
  }
}

@container xs-topbar (max-width: 661.98px) {
  .xs-cluster-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .xs-chip.xs-cluster {
    padding-inline: var(--space-3);
  }
}

@container xs-topbar (max-width: 566.98px) {
  .xs-role,
  .xs-user-btn .fa-chevron-down,
  .xs-copilot .xs-kbd {
    display: none;
  }

  .xs-topbar .xs-copilot.is-live input {
    padding-inline-end: calc(var(--space-2) * 3);
  }
}

@container xs-topbar (max-width: 447.98px) {
  #btn-start-tour {
    display: none;
  }

  .xs-menu-overflow {
    display: block;
  }

  .xs-menu-guide {
    display: flex;
  }
}

@container xs-topbar (max-width: 387.98px) {
  #demo-data-badge {
    display: none;
  }

  .xs-user-btn.has-demo .xs-avatar::after {
    content: "";
    position: absolute;
    inset-block-start: -1px;
    inset-inline-end: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--bg);
  }
}

@container xs-topbar (max-width: 339.98px) {
  .xs-topbar .xs-wordmark-text {
    display: none;
  }
}
