/* Global navigation ribbon — responsive mobile hamburger + desktop ribbon */

#global-nav-ribbon {
  height: 56px;
  min-height: 56px;
  max-height: 56px;
  position: relative;
  z-index: 80;
}

#global-nav-ribbon .nav-ribbon-inner {
  display: flex;
  height: 100%;
  max-width: 1600px;
  margin: 0 auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.5rem;
  min-width: 0;
}

#global-nav-ribbon .nav-brand-cluster {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  min-width: 0;
}

#global-nav-ribbon .nav-brand-link {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
}

#global-nav-ribbon .nav-brand-logo {
  height: 32px;
  width: auto;
  max-width: 7rem;
  object-fit: contain;
  object-position: left;
}

#global-nav-ribbon .nav-actions {
  display: flex;
  align-items: center;
  margin-left: auto;
  flex-shrink: 0;
  min-width: 0;
}

#global-nav-ribbon .nav-utility-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 0.15rem;
  flex-shrink: 0;
  min-width: 0;
}

.nav-hamburger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: 0.35rem;
  border: 1px solid rgb(51 65 85);
  background: rgb(15 23 42);
  color: rgb(226 232 240);
  cursor: pointer;
  flex-shrink: 0;
}

.nav-hamburger:hover,
.nav-hamburger:focus-visible {
  background: rgb(30 41 59);
  outline: none;
  border-color: rgb(14 165 233);
}

.nav-hamburger-icon {
  display: block;
  width: 1.05rem;
  height: 0.85rem;
  position: relative;
}

.nav-hamburger-icon span {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: 9999px;
  background: currentColor;
  transition: transform 0.18s ease, opacity 0.18s ease, top 0.18s ease;
}

.nav-hamburger-icon span:nth-child(1) { top: 0; }
.nav-hamburger-icon span:nth-child(2) { top: calc(50% - 1px); }
.nav-hamburger-icon span:nth-child(3) { bottom: 0; }

body.nav-drawer-open .nav-hamburger-icon span:nth-child(1) {
  top: calc(50% - 1px);
  transform: rotate(45deg);
}

body.nav-drawer-open .nav-hamburger-icon span:nth-child(2) {
  opacity: 0;
}

body.nav-drawer-open .nav-hamburger-icon span:nth-child(3) {
  bottom: auto;
  top: calc(50% - 1px);
  transform: rotate(-45deg);
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.15rem 0.32rem;
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: rgb(148 163 184);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  border-radius: 0.2rem 0.2rem 0 0;
  white-space: nowrap;
  line-height: 1.1;
}

.nav-tab-icon {
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-tab:hover {
  color: rgb(226 232 240);
  background: rgba(51, 65, 85, 0.35);
}

button.nav-tab {
  cursor: pointer;
  background: transparent;
  border-top: none;
  border-left: none;
  border-right: none;
}

.nav-tab-active {
  color: rgb(125 211 252) !important;
  border-bottom-color: rgb(14 165 233);
  background: rgba(14, 116, 144, 0.12);
}

.nav-primary {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  gap: 0.05rem;
  overflow-x: hidden;
}

.nav-divider {
  display: none;
  height: 1.25rem;
  width: 1px;
  flex-shrink: 0;
  background: rgb(30 41 59);
}

.nav-exit-cluster {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 0.1rem;
  flex-shrink: 0;
}

.nav-exit-btn {
  padding: 0.15rem 0.5rem;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: rgb(254 202 202);
  background: rgba(127, 29, 29, 0.35);
  border: 1px solid rgba(239, 68, 68, 0.45);
  border-radius: 0.25rem;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}

.nav-exit-btn:hover:not(:disabled) {
  background: rgba(153, 27, 27, 0.55);
}

.nav-exit-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.nav-exit-row {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* Operator panic stop. Sized to the Log Out button it sits beside; it carries a
   solid fill rather than extra bulk so it stays findable without reading. */
.nav-stop-btn {
  padding: 0.15rem 0.5rem;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: rgb(254 226 226);
  background: rgb(153 27 27);
  border: 1px solid rgb(248 113 113);
  border-radius: 0.25rem;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
}

.nav-stop-btn:hover:not(:disabled) {
  background: rgb(185 28 28);
}

.nav-stop-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* Halted: the ribbon should be impossible to mistake for a normal desk. */
.nav-stop-btn[data-halted="true"] {
  color: rgb(254 249 195);
  background: rgb(120 53 15);
  border-color: rgb(250 204 21);
  animation: nav-stop-pulse 1.6s ease-in-out infinite;
}

@keyframes nav-stop-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(250, 204, 21, 0.55); }
  50%      { box-shadow: 0 0 0 4px rgba(250, 204, 21, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .nav-stop-btn[data-halted="true"] { animation: none; }
}

/* Kill-switch banner. Hidden entirely at NORMAL — the ribbon should carry no
   chrome for a desk that is simply running. Distinct from the STOP ORDERS
   button beside it: that one halts transmission, this one also flattens. */
.nav-kill-banner {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgb(254 226 226);
  background: rgb(127 29 29);
  border: 1px solid rgb(248 113 113);
  border-radius: 0.25rem;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  animation: nav-kill-pulse 1.6s ease-in-out infinite;
}

.nav-kill-banner[hidden] {
  display: none;
}

.nav-kill-banner:hover {
  background: rgb(153 27 27);
}

/* Advisory states do not block entries — amber, and no pulse. */
.nav-kill-banner[data-blocking="false"] {
  color: rgb(254 243 199);
  background: rgba(120, 53, 15, 0.75);
  border-color: rgb(245 158 11);
  animation: none;
}

@keyframes nav-kill-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.6); }
  50%      { box-shadow: 0 0 0 4px rgba(248, 113, 113, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .nav-kill-banner { animation: none; }
}

.nav-page-index {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: rgb(71 85 105);
  line-height: 1;
  user-select: none;
}

.nav-page-index:empty {
  display: none;
}

.nav-env-status {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  max-width: 11.5rem;
  padding: 0.15rem 0.4rem;
  border-radius: 9999px;
  border: 1px solid rgb(51 65 85);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 7.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
  pointer-events: none;
  cursor: default;
}

.nav-env-status.env-sandbox {
  /* Bright yellow so SANDBOX pops against dark mode vs LIVE green */
  color: #FFD700;
  background: rgba(113, 63, 18, 0.55);
  border-color: rgba(234, 179, 8, 0.85);
  text-shadow: 0 0 8px rgba(234, 179, 8, 0.35);
}

.nav-env-status.env-live {
  color: rgb(110 231 183);
  background: rgba(6, 78, 59, 0.55);
  border-color: rgba(16, 185, 129, 0.65);
}

/* Mobile drawer — closed by default (never intercept touches) */
.nav-drawer-backdrop {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden;
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(2, 6, 23, 0.62);
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.nav-drawer {
  display: none !important;
  pointer-events: none;
  visibility: hidden;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 95;
  width: min(20rem, 88vw);
  height: 100dvh;
  max-height: 100vh;
  background: rgb(2 6 23);
  border-right: 1px solid rgb(30 41 59);
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
  transform: translateX(-105%);
  transition: transform 0.22s ease;
  padding: 0.75rem 0.65rem 1.25rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-drawer-backdrop[hidden],
.nav-drawer[hidden] {
  display: none !important;
  pointer-events: none !important;
  visibility: hidden !important;
}

.nav-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding: 0 0.25rem 0.65rem;
  border-bottom: 1px solid rgb(30 41 59);
}

.nav-drawer-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgb(148 163 184);
}

.nav-drawer-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.35rem;
  border: 1px solid rgb(51 65 85);
  background: rgb(15 23 42);
  color: rgb(226 232 240);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.nav-drawer-close:hover,
.nav-drawer-close:focus-visible {
  border-color: rgb(14 165 233);
  outline: none;
}

.nav-drawer-links {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-drawer-links .nav-tab {
  display: flex;
  width: 100%;
  min-height: 2.75rem;
  align-items: center;
  padding: 0.7rem 0.85rem;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: 0.45rem;
  border-bottom: none;
  border: 1px solid transparent;
  color: rgb(226 232 240);
  background: rgb(15 23 42 / 0.65);
}

.nav-drawer-links .nav-tab:hover {
  background: rgb(30 41 59);
}

.nav-drawer-links .nav-tab-active {
  color: rgb(125 211 252) !important;
  background: rgba(14, 116, 144, 0.22);
  border-color: rgba(14, 165, 233, 0.45);
}

body.nav-drawer-open {
  overflow: hidden;
}

/*
 * Breakpoint seam (no gap):
 *   ≤1023.98px → hamburger + drawer (phones, iPad Mini/Air portrait, narrow tablets)
 *   ≥1024px    → horizontal desktop ribbon
 */
@media (max-width: 1023.98px) {
  body.nav-drawer-open .nav-drawer-backdrop:not([hidden]) {
    display: block !important;
    pointer-events: auto !important;
    visibility: visible;
  }

  body.nav-drawer-open .nav-drawer:not([hidden]) {
    display: block !important;
    pointer-events: auto;
    visibility: visible;
    transform: translateX(0);
  }

  .nav-hamburger {
    display: inline-flex;
  }

  .nav-primary,
  .nav-divider {
    display: none !important;
  }

  #global-nav-ribbon .nav-ribbon-inner {
    gap: 0.4rem;
    padding: 0 0.45rem;
  }

  #global-nav-ribbon .nav-brand-logo {
    height: 28px;
    max-width: 5.75rem;
  }

  .nav-env-status {
    max-width: 5.5rem;
    padding: 0.18rem 0.45rem;
    font-size: 8px;
  }

  .nav-exit-btn,
  .nav-stop-btn,
  .nav-kill-banner {
    min-height: 1.75rem;
    padding: 0.25rem 0.55rem;
    font-size: 9px;
  }

  .nav-page-index {
    display: none;
  }

  .nav-exit-cluster {
    flex-direction: column;
    align-items: flex-end;
  }

  .nav-utility-stack {
    flex-direction: column;
    align-items: flex-end;
    gap: 0.15rem;
  }
}

/* Desktop / landscape tablet (≥1024px): horizontal ribbon — drawer/scrim never active */
@media (min-width: 1024px) {
  .nav-hamburger,
  .nav-drawer,
  .nav-drawer-backdrop {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }

  .nav-divider {
    display: block;
  }

  .nav-primary {
    display: flex;
    overflow-x: hidden;
    scrollbar-width: none;
  }

  .nav-primary::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  #global-nav-ribbon .nav-ribbon-inner {
    gap: 0.35rem;
    max-width: none;
    padding: 0 0.45rem;
  }

  #global-nav-ribbon {
    height: 62px;
    min-height: 62px;
    max-height: 62px;
  }

  /* Force-clear leftover open-drawer state after rotate/resize to desktop */
  body.nav-drawer-open {
    overflow: auto;
  }

  body.nav-drawer-open .nav-drawer-backdrop,
  body.nav-drawer-open .nav-drawer {
    display: none !important;
    pointer-events: none !important;
    visibility: hidden !important;
    transform: none;
  }
}

/* About modal — Epilego splash + live version */
.nav-about-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.nav-about-modal.open,
.nav-about-modal:not([hidden]) {
  display: flex;
}

.nav-about-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  background: rgb(2 6 23 / 0.88);
}

.nav-about-card {
  position: relative;
  z-index: 1;
  width: min(22rem, 100%);
  padding: 1.75rem 1.5rem 1.35rem;
  border-radius: 0.75rem;
  border: 1px solid rgb(51 65 85 / 0.9);
  background: linear-gradient(165deg, rgb(15 23 42) 0%, rgb(2 6 23) 100%);
  box-shadow: 0 24px 48px rgb(0 0 0 / 0.45);
  text-align: center;
}

.nav-about-logo {
  display: block;
  height: 4rem;
  width: auto;
  max-width: 12rem;
  margin: 0 auto 0.85rem;
  object-fit: contain;
}

.nav-about-logo-fallback {
  margin: 0 0 0.85rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: rgb(56 189 248);
}

.nav-about-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgb(226 232 240);
}

.nav-about-version {
  margin: 0.55rem 0 1.15rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: rgb(125 211 252);
}

.nav-about-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 5.5rem;
  padding: 0.45rem 1rem;
  border-radius: 0.4rem;
  border: 1px solid rgb(51 65 85);
  background: rgb(30 41 59);
  color: rgb(226 232 240);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.nav-about-close:hover,
.nav-about-close:focus-visible {
  border-color: rgb(14 165 233);
  outline: none;
  background: rgb(51 65 85);
}
