* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: #101216;
  color: #f5f7fb;
}

.mcr-header {
  min-height: 78px;
  padding: 14px 22px;
  background: #171a21;
  border-bottom: 1px solid rgba(255,255,255,.12);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: #ffffff;
  color: #111;
  display: grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: -.04em;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
}

.brand p {
  margin: 3px 0 0;
  color: #aeb6c4;
  font-size: 13px;
}

.page-tabs {
  display: flex;
  gap: 8px;
  padding: 6px;
  background: #101216;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
}

.page-tabs button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: transparent;
  color: #cbd3df;
  cursor: pointer;
  font-weight: 700;
}

.page-tabs button.active {
  background: #ffffff;
  color: #111;
}

.header-status {
  justify-self: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.header-status span {
  padding: 8px 10px;
  border-radius: 999px;
  background: #202532;
  border: 1px solid rgba(255,255,255,.1);
  color: #d9dde5;
  font-size: 12px;
}

.workspace {
  padding: 24px;
}

.panel {
  max-width: 1100px;
  margin: 0 auto;
  background: #171a21;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 22px;
  padding: 24px;
}

.panel h2 {
  margin: 0;
  font-size: 34px;
}

.muted {
  color: #aeb6c4;
}

.form {
  margin: 22px 0;
  display: grid;
  grid-template-columns: 1fr 120px 140px 1fr auto;
  gap: 10px;
}

.form input,
.form button {
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 12px;
  padding: 12px 14px;
  background: #101216;
  color: white;
}

.form button {
  background: white;
  color: #111;
  font-weight: 900;
  cursor: pointer;
}

.departure-list {
  display: grid;
  gap: 10px;
}

.departure-card {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  padding: 15px;
  border-radius: 16px;
  background: #202532;
  border: 1px solid rgba(255,255,255,.1);
}

.departure-card p,
.departure-card em {
  grid-column: 1 / -1;
  margin: 0;
}

.departure-card p {
  color: #cbd3df;
}

.departure-card em {
  color: #8f98a8;
  font-size: 12px;
}

@media (max-width: 900px) {
  .mcr-header {
    grid-template-columns: 1fr;
  }

  .header-status {
    justify-self: start;
  }

  .form {
    grid-template-columns: 1fr;
  }
}

.layout-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 24px;
}

.wing-panel {
  background: #101216;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  padding: 16px;
}

.wing-panel h3 {
  margin: 0 0 14px;
}

.door-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.door-tile {
  min-height: 96px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 14px;
  background: #171a21;
  padding: 10px;
  cursor: pointer;
}

.door-tile.occupied {
  background: #263247;
  border-color: rgba(255,255,255,.28);
}

.door-number {
  font-weight: 900;
  font-size: 14px;
  color: #ffffff;
}

.door-status {
  margin-top: 6px;
  font-size: 12px;
  color: #9fa8b8;
}

.door-destination {
  margin-top: 8px;
  font-weight: 800;
}

.door-time {
  color: #d9dde5;
  font-size: 13px;
}

.assign-hint {
  margin-top: 8px;
  font-size: 11px;
  color: #8f98a8;
}

@media (max-width: 1000px) {
  .layout-grid {
    grid-template-columns: 1fr;
  }

  .door-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.departure-card.selected {
  outline: 3px solid #ffffff;
  background: #2d3950;
}

.departure-card.selected {
  outline: 3px solid #ffffff;
  background: #2d3950;
}

/* MCR FIX: restore NHO wings side-by-side */
.wings-stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}

.wing-door-layout {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
}

@media (max-width: 1000px) {
  .wings-stage {
    grid-template-columns: 1fr;
  }
}

/* MCR Wing Engine refinement */
.nho-workspace {
  padding: 14px;
  max-width: none;
  overflow-x: auto;
}

.control-strip {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
  align-items: end;
  margin-bottom: 14px;
}

.quick-form {
  display: grid;
  grid-template-columns: 1fr 110px 130px 1fr auto;
  gap: 8px;
}

.quick-form input,
.quick-form button {
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 10px;
  padding: 10px 12px;
  background: #101216;
  color: white;
}

.quick-form button {
  background: #ffffff;
  color: #111;
  font-weight: 900;
  cursor: pointer;
}

.wings-stage {
  min-width: 1280px;
}

.wing {
  background: #171a21;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  padding: 12px;
}

.wing-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.wing-title h3 {
  margin: 0;
  font-size: 22px;
}

.wing-title span {
  color: #aeb6c4;
  font-size: 13px;
}

.wing-door-layout {
  grid-template-columns: repeat(6, minmax(98px, 1fr));
  gap: 8px;
}

.door-tile {
  min-height: 74px;
  padding: 8px;
  border-radius: 12px;
}

.door-number {
  font-size: 13px;
}

.door-status,
.assign-hint {
  font-size: 10px;
}

.door-destination {
  font-size: 13px;
  line-height: 1.05;
}

.door-time {
  font-size: 11px;
}

.unassigned-panel {
  margin-top: 16px;
  background: #171a21;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  padding: 14px;
}

@media (max-width: 1000px) {
  .control-strip,
  .quick-form {
    grid-template-columns: 1fr;
  }

  .wings-stage {
    min-width: 0;
  }
}

.selected-banner {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: #202532;
  border: 1px solid rgba(255,255,255,.12);
  color: #cbd3df;
  font-weight: 700;
}

.selected-banner.active {
  background: #ffffff;
  color: #111111;
}

.rails-stage {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 16px;
}

.rail-panel {
  background: #171a21;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  padding: 14px;
}

.rail-list {
  display: grid;
  gap: 8px;
}

.rail-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 12px;
  border-radius: 14px;
  background: #202532;
  border: 1px solid rgba(255,255,255,.1);
}

.rail-card strong {
  font-size: 16px;
}

.rail-card span {
  font-weight: 900;
}

.rail-card small {
  grid-column: 1 / -1;
  color: #aeb6c4;
}

.rail-empty {
  color: #8f98a8;
  font-size: 13px;
}

@media (max-width: 900px) {
  .rails-stage {
    grid-template-columns: 1fr;
  }
}

/* MCR Operations Layout: rails beside wings */
.operations-stage {
  display: grid;
  grid-template-columns: 280px minmax(900px, 1fr) 280px;
  gap: 14px;
  align-items: start;
  min-width: 1500px;
}

.operations-stage .wings-stage {
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.operations-stage .rail-panel {
  min-height: 520px;
  position: sticky;
  top: 96px;
}

.rail-left,
.rail-right {
  max-height: calc(100vh - 130px);
  overflow: auto;
}

@media (max-width: 1300px) {
  .operations-stage {
    grid-template-columns: 240px minmax(760px, 1fr) 240px;
    min-width: 1250px;
  }
}

/* MCR layout correction: skinny rails, full wings visible */
.operations-stage {
  grid-template-columns: 190px minmax(1040px, 1fr) 190px !important;
  gap: 10px !important;
  align-items: start;
}

.operations-stage .rail-panel {
  min-height: 0 !important;
  max-height: calc(100vh - 125px);
  padding: 10px !important;
  border-radius: 14px;
}

.operations-stage .wings-stage {
  width: 100%;
  min-width: 1040px;
  gap: 12px;
}

.wing-door-layout {
  grid-template-columns: repeat(5, minmax(86px, 1fr)) !important;
  gap: 7px !important;
}

.door-tile {
  min-height: 68px !important;
  padding: 7px !important;
}

.rail-card {
  grid-template-columns: 1fr !important;
  padding: 9px !important;
  gap: 3px !important;
}

.rail-card strong {
  font-size: 13px !important;
}

.rail-card span {
  font-size: 12px !important;
}

.rail-card small {
  font-size: 10px !important;
}

.rail-panel .wing-title h3 {
  font-size: 15px !important;
}

.rail-panel .wing-title span {
  font-size: 11px !important;
}

@media (max-width: 1400px) {
  .operations-stage {
    grid-template-columns: 170px minmax(980px, 1fr) 170px !important;
    min-width: 1320px !important;
  }

  .operations-stage .wings-stage {
    min-width: 980px;
  }
}

.zoom-controls {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.zoom-controls button {
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  background: #202532;
  color: white;
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 800;
}

.operations-stage {
  transform-origin: top left;
  transition: transform .18s ease;
}

.nho-workspace {
  overflow-x: auto;
  overflow-y: auto;
}

.mcr-footer {
  position: sticky;
  bottom: 0;
  z-index: 20;
  min-height: 42px;
  padding: 8px 18px;
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: 18px;
  align-items: center;
  background: #0b0d11;
  border-top: 1px solid rgba(255,255,255,.12);
  color: #aeb6c4;
  font-size: 12px;
}

#footerSelected {
  justify-self: center;
  min-width: 360px;
  text-align: center;
  padding: 8px 14px;
  border-radius: 10px;
  background: #101216;
  border: 1px solid rgba(255,255,255,.12);
  color: #ffffff;
}

@media (max-width: 900px) {
  .mcr-footer {
    grid-template-columns: 1fr;
  }

  #footerSelected {
    justify-self: stretch;
    min-width: 0;
  }
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 58px;
  z-index: 100;
  display: grid;
  gap: 10px;
  width: 320px;
  pointer-events: none;
}

.toast {
  padding: 12px 14px;
  border-radius: 14px;
  background: #202532;
  border: 1px solid rgba(255,255,255,.16);
  box-shadow: 0 12px 35px rgba(0,0,0,.35);
  color: #ffffff;
  animation: toastIn .18s ease-out;
}

.toast strong {
  display: block;
  margin-bottom: 4px;
}

.toast span {
  color: #aeb6c4;
  font-size: 12px;
}

@keyframes toastIn {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.mcr-dialog {
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 18px;
  background: #171a21;
  color: white;
  padding: 0;
  width: min(460px, calc(100vw - 28px));
  box-shadow: 0 24px 90px rgba(0,0,0,.55);
}

.mcr-dialog::backdrop {
  background: rgba(0,0,0,.62);
}

.mcr-dialog form {
  padding: 22px;
  display: grid;
  gap: 12px;
}

.mcr-dialog h3 {
  margin: 0 0 8px;
  font-size: 24px;
}

.mcr-dialog label {
  display: grid;
  gap: 6px;
  color: #aeb6c4;
  font-size: 13px;
}

.mcr-dialog input,
.mcr-dialog textarea {
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 12px;
  background: #101216;
  color: white;
  padding: 12px;
  font: inherit;
}

.mcr-dialog textarea {
  min-height: 90px;
  resize: vertical;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-actions button {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 900;
}

.dialog-actions button[type="button"] {
  background: #202532;
  color: white;
}

.dialog-actions button[type="submit"] {
  background: white;
  color: #111;
}

.dialog-actions {
  align-items: center;
}

.dialog-spacer {
  flex: 1;
}

.dialog-actions .danger {
  background: #6b1f28 !important;
  color: #ffffff !important;
}

.yard-panel {
  margin-top: 16px;
  background: #171a21;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  padding: 14px;
  min-width: 1480px;
}

.yard-grid {
  display: grid;
  grid-template-columns: repeat(20, minmax(54px, 1fr));
  gap: 6px;
}

.yard-tile {
  min-height: 54px;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 10px;
  background: #101216;
  color: white;
  padding: 6px;
  cursor: pointer;
  text-align: left;
}

.yard-tile.occupied {
  background: #263247;
  border-color: rgba(255,255,255,.28);
}

.yard-label {
  font-weight: 900;
  font-size: 11px;
}

.yard-destination {
  margin-top: 4px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1.05;
}

.yard-time {
  font-size: 10px;
  color: #cbd3df;
}

.role-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 999px;
  background: #202532;
  border: 1px solid rgba(255,255,255,.1);
  color: #d9dde5;
  font-size: 12px;
}

.role-switch select {
  border: 0;
  border-radius: 999px;
  padding: 4px 8px;
  background: #101216;
  color: white;
}

/* MCR Production Header v1 */
.mcr-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #0b0d11;
  border-bottom: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 12px 32px rgba(0,0,0,.28);
}

.topbar-row {
  display: grid;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
}

.topbar-main {
  grid-template-columns: 320px 1fr auto;
}

.topbar-sub {
  grid-template-columns: 1fr auto;
  border-top: 1px solid rgba(255,255,255,.08);
  background: #101216;
}

.brand-wide h1 {
  font-size: 20px;
}

.main-menu {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.main-menu button {
  border: 1px solid rgba(255,255,255,.14);
  background: #171a21;
  color: #f5f7fb;
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 800;
  cursor: pointer;
}

.main-menu button:hover {
  background: #202532;
}

.topbar-actions,
.sub-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.topbar-actions span,
.sub-status span {
  padding: 8px 10px;
  border-radius: 999px;
  background: #202532;
  border: 1px solid rgba(255,255,255,.1);
  color: #d9dde5;
  font-size: 12px;
}

.mcr-header {
  display: none !important;
}

@media (max-width: 1100px) {
  .topbar-main,
  .topbar-sub {
    grid-template-columns: 1fr;
  }

  .main-menu,
  .topbar-actions,
  .sub-status {
    justify-content: flex-start;
  }
}

.menu-wrap {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 210px;
  padding: 8px;
  border-radius: 16px;
  background: #171a21;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 18px 55px rgba(0,0,0,.42);
  display: none;
  z-index: 90;
}

.menu-wrap.open .dropdown-menu {
  display: grid;
  gap: 6px;
}

.dropdown-menu button {
  width: 100%;
  border-radius: 12px;
  text-align: left;
  background: #101216;
}

.side-drawer {
  position: fixed;
  top: 118px;
  bottom: 42px;
  width: 340px;
  z-index: 80;
  background: #171a21;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 18px 55px rgba(0,0,0,.45);
  padding: 14px;
  transition: transform .22s ease;
}

.side-drawer.left {
  left: 0;
  transform: translateX(calc(-100% - 8px));
  border-radius: 0 18px 18px 0;
}

.side-drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-head h3 {
  margin: 0;
  font-size: 24px;
}

.drawer-head button {
  border: 0;
  border-radius: 999px;
  background: #202532;
  color: white;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 22px;
}

.drawer-list {
  margin-top: 16px;
  display: grid;
  gap: 8px;
}

.drawer-list button {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  background: #101216;
  color: white;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.side-drawer {
  position: fixed;
  top: 118px;
  bottom: 42px;
  width: 340px;
  z-index: 80;
  background: #171a21;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 18px 55px rgba(0,0,0,.45);
  padding: 14px;
  transition: transform .22s ease;
}

.side-drawer.left {
  left: 0;
  transform: translateX(calc(-100% - 8px));
  border-radius: 0 18px 18px 0;
}

.side-drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-head h3 {
  margin: 0;
  font-size: 24px;
}

.drawer-head button {
  border: 0;
  border-radius: 999px;
  background: #202532;
  color: white;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 22px;
}

.drawer-list {
  margin-top: 16px;
  display: grid;
  gap: 8px;
}

.drawer-list button {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  background: #101216;
  color: white;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.side-drawer {
  position: fixed;
  top: 118px;
  bottom: 42px;
  width: 340px;
  z-index: 80;
  background: #171a21;
  border: 1px solid rgba(255,255,255,.14);
  box-shadow: 0 18px 55px rgba(0,0,0,.45);
  padding: 14px;
  transition: transform .22s ease;
}

.side-drawer.left {
  left: 0;
  transform: translateX(calc(-100% - 8px));
  border-radius: 0 18px 18px 0;
}

.side-drawer.open {
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-head h3 {
  margin: 0;
  font-size: 24px;
}

.drawer-head button {
  border: 0;
  border-radius: 999px;
  background: #202532;
  color: white;
  width: 34px;
  height: 34px;
  cursor: pointer;
  font-size: 22px;
}

.drawer-list {
  margin-top: 16px;
  display: grid;
  gap: 8px;
}

.drawer-list button {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  background: #101216;
  color: white;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.side-drawer.right {
  right: 0;
  transform: translateX(calc(100% + 8px));
  border-radius: 18px 0 0 18px;
}

.side-drawer.right.open {
  transform: translateX(0);
}

.drawer-search {
  width: 100%;
  margin-top: 14px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 12px;
  background: #101216;
  color: white;
  padding: 12px;
}

.drawer-backdrop {
  position: fixed;
  inset: 118px 0 42px 0;
  background: rgba(0,0,0,.38);
  z-index: 70;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.dialog-message {
  margin: 0;
  color: #cbd3df;
  line-height: 1.45;
}

.rail-card.next {
  border-left: 4px solid #4ade80;
}

.rail-card.pre-alert {
  border-left: 4px solid #facc15;
}

.rail-card.late {
  border-left: 4px solid #ef4444;
}

.rail-card.neutral {
  border-left: 4px solid #64748b;
}

.rail-card.next {
  border-left: 4px solid #4ade80;
}

.rail-card.pre-alert {
  border-left: 4px solid #facc15;
}

.rail-card.late {
  border-left: 4px solid #ef4444;
}

.rail-card.neutral {
  border-left: 4px solid #64748b;
}

.rail-countdown {
  grid-column: 1 / -1;
  margin-top: 4px;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: .02em;
}

.rail-card.pre-alert .rail-countdown {
  color: #facc15;
}

.rail-card.late .rail-countdown {
  color: #ef4444;
}

.rail-card.next .rail-countdown {
  color: #4ade80;
}

.rail-dup {
  justify-self: end;
  align-self: start;
  padding: 3px 8px;
  border-radius: 999px;
  background: #ffffff;
  color: #111111;
  font-size: 12px;
}

/* Rail V3 polish */
.rail-card.late {
  background: #33171b !important;
  border-color: rgba(239,68,68,.6) !important;
}

.rail-card.pre-alert {
  background: #302714 !important;
  border-color: rgba(250,204,21,.55) !important;
}

.rail-card.next {
  background: #13251b !important;
  border-color: rgba(74,222,128,.45) !important;
}

.rail-card small {
  font-weight: 800;
}

.rail-card.late .rail-countdown::after {
  content: " LATE";
  font-size: 11px;
  margin-left: 6px;
}

.rail-card.pre-alert .rail-countdown::after {
  content: " PRE ALERT";
  font-size: 11px;
  margin-left: 6px;
}
