@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:ital,wght@0,300;0,400;0,600;0,700;1,400&display=swap');

:root {
  --bg: #7f8388;
  --panel: #afb3b8;             /* Classic German SpDrS60 industrial grey */
  --panel-inner: #9ea2a7;       /* Slightly darker for inset slots */
  --border-color: #5c6064;      /* Shadow edge of 3D frames */
  --border-color-light: #ffffff;/* Highlight edge of 3D frames */
  
  --muted: #494e54;
  --text: #111417;              /* Dark text for grey physical console labels */
  --text-bright: #050505;       /* Crisp black text */
  
  /* Interlocking Color Standards (German SpDrS60 Console Style) */
  --track: #000000;             /* Thick black base track */
  --route: #ffe000;             /* Locked route yellow LED */
  --free: #10d024;              /* Free / Signal Go green LED */
  --halt: #ff1a1a;              /* Occupied track / Signal Stop red LED */
  --block: #1f6feb;
  --blue: #2c52bf;
  --warn: #ff9000;
  --select: #00bcd4;            /* Selection outline cyan glow */
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Mono", "Consolas", monospace;
  overflow-x: hidden;
}

.estw-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 56px 1fr 180px;
  background: var(--panel);
}

/* ==========================================
   PHYSICAL METAL CONSOLE HEADER
   ========================================== */
.hud-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 4px solid var(--border-color);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
  z-index: 10;
  position: relative;
}

.hud-bar::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--border-color-light);
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.hud-badge {
  padding: 2px 8px;
  border: 2px inset var(--border-color);
  background: var(--panel-inner);
  color: var(--text-bright);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: 2px;
}

.hud-title {
  display: flex;
  flex-direction: column;
}

.hud-title strong {
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-bright);
}

.hud-title span {
  color: var(--blue);
  font-weight: bold;
  font-size: 11px;
}

/* Glowing 7-segment digital clock panel */
.hud-center {
  display: flex;
  justify-content: center;
}

.clock-panel {
  background: #000000 !important;
  padding: 4px 14px;
  border: 2px inset var(--border-color);
  border-radius: 4px;
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.9);
}

.hud-clock {
  color: #ff2222 !important; /* Retro red glowing digits */
  font-size: 20px;
  font-weight: bold;
  letter-spacing: 0.08em;
  text-shadow: 0 0 5px #ff2222;
}

.hud-right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.hud-chip {
  background: var(--panel-inner);
  border: 2px outset var(--border-color-light);
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-bright);
  border-radius: 2px;
  letter-spacing: 0.02em;
  box-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}

.hud-chip.live {
  background: #188a30;
  color: #ffffff;
  border-color: #55c455 #0b4f1b #0b4f1b #55c455;
}

#tokenStateLabel.live {
  background: #d89f0e;
  color: #000000;
  border-color: #ffe155 #8c6508 #8c6508 #ffe155;
}

/* ==========================================
   MAIN CONTENT AREA
   ========================================== */
.estw-main {
  display: grid;
  grid-template-columns: 1fr 400px;
  min-height: 0;
  background: var(--panel);
}

/* ==========================================
   TRACK SCREEN (SPDRS60 GREY TILES & LAYOUT OVERLAY)
   ========================================== */
.track-stage {
  position: relative;
  padding: 0;
  background: var(--panel);
  border-right: 4px solid var(--border-color);
  box-shadow: inset 3px 3px 6px rgba(0,0,0,0.3);
  overflow: hidden;
}

#layout {
  width: 100%;
  height: 100%;
  display: block;
  background: var(--panel); /* app.js will draw grid rect over this */
}

/* ==========================================
   SPDRS60 GROUP BUTTONS BAR
   ========================================== */
.group-buttons-container {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
}

.group-button-panel {
  pointer-events: auto;
  background: var(--panel);
  border: 3px solid #7c8085;
  border-top-color: #ffffff;
  border-left-color: #ffffff;
  border-bottom-color: #4a4e52;
  border-right-color: #4a4e52;
  border-radius: 4px;
  padding: 10px 24px;
  position: relative;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.group-button-label {
  font-size: 10px;
  font-weight: bold;
  text-transform: uppercase;
  color: var(--text-bright);
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.group-button-row {
  display: flex;
  gap: 14px;
  align-items: center;
}

/* Physical Screw Heads */
.panel-screw {
  position: absolute;
  width: 8px;
  height: 8px;
  background: radial-gradient(circle at 35% 35%, #ffffff, #7a7e84);
  border-radius: 50%;
  border: 1px solid #4a4e52;
}
.panel-screw.top-left { top: 4px; left: 4px; }
.panel-screw.top-right { top: 4px; right: 4px; }
.panel-screw.bottom-left { bottom: 4px; left: 4px; }
.panel-screw.bottom-right { bottom: 4px; right: 4px; }

.panel-screw::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 1px;
  width: 5px;
  height: 1px;
  background: #333;
  transform: rotate(35deg);
}

/* Tactile 3D Buttons (Physical Keycaps) */
.spdr-btn-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

/* Small Indicator LED Above Button */
.led {
  width: 7px;
  height: 7px;
  background: #404448;
  border-radius: 50%;
  border: 1px solid #202428;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.5);
  transition: all 0.15s ease;
}

.led.led-red.active { background: #ff2222; box-shadow: 0 0 6px #ff2222, inset 0 1px #fff; }
.led.led-green.active { background: #22ff22; box-shadow: 0 0 6px #22ff22, inset 0 1px #fff; }
.led.led-yellow.active { background: #ffff22; box-shadow: 0 0 6px #ffff22, inset 0 1px #fff; }
.led.led-blue.active { background: #22aaff; box-shadow: 0 0 6px #22aaff, inset 0 1px #fff; }
.led.led-white.active { background: #ffffff; box-shadow: 0 0 6px #ffffff, inset 0 1px #fff; }

.spdr-btn, .panel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "IBM Plex Mono", monospace;
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  color: #000000;
  cursor: pointer;
  user-select: none;
  border: 3px solid;
  border-radius: 3px;
  box-shadow: 0 3px 5px rgba(0,0,0,0.3);
  position: relative;
  transition: transform 0.05s ease, box-shadow 0.05s ease;
}

.spdr-btn {
  width: 44px;
  height: 38px;
}

.spdr-btn:active, .panel-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

/* Button Color Variants (Beveled plastic 3D look) */
.spdr-blue {
  background: #3a6bf0;
  border-color: #7fa2ff #1b3db3 #1b3db3 #7fa2ff;
  color: #ffffff;
}
.spdr-green {
  background: #1b8c2c;
  border-color: #59cc6c #0c4d16 #0c4d16 #59cc6c;
  color: #ffffff;
}
.spdr-green-white {
  background: linear-gradient(135deg, #1b8c2c 50%, #f0f4f8 50%);
  border-color: #59cc6c #0c4d16 #0c4d16 #59cc6c;
  color: #000000;
}
.spdr-red {
  background: #b81d1d;
  border-color: #ff6868 #630c0c #630c0c #ff6868;
  color: #ffffff;
}
.btn-white {
  background: #eaeef3;
  border-color: #ffffff #9da2a8 #9da2a8 #ffffff;
  color: #000000;
}
.btn-grey {
  background: #808488;
  border-color: #afb3b8 #4c5054 #4c5054 #afb3b8;
  color: #ffffff;
}
.btn-yellow {
  background: #d4a30b;
  border-color: #ffe07b #775c06 #775c06 #ffe07b;
  color: #000000;
}
.btn-red {
  background: #b81d1d;
  border-color: #ff6868 #630c0c #630c0c #ff6868;
  color: #ffffff;
}

.panel-btn.active {
  border-color: #00bcd4 !important;
  box-shadow: 0 0 6px #00bcd4;
}

/* ==========================================
   OPERATOR PANEL (Tactile grey metal plate cards)
   ========================================== */
.operator-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 12px;
  background: var(--panel);
  border-left: 4px solid var(--border-color);
  box-shadow: inset 1px 0 2px rgba(255,255,255,0.4);
}

.panel-card {
  border: 3px solid #7c8085;
  border-top-color: #ffffff;
  border-left-color: #ffffff;
  border-bottom-color: #4a4e52;
  border-right-color: #4a4e52;
  background: var(--panel);
  padding: 12px;
  border-radius: 4px;
  position: relative;
  box-shadow: 0 3px 6px rgba(0,0,0,0.2);
}

/* Render screws on the panel card corners */
.panel-card::before, .panel-card::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  background: radial-gradient(circle at 35% 35%, #ffffff, #7a7e84);
  border-radius: 50%;
  border: 1px solid #4a4e52;
  z-index: 2;
}
.panel-card::before { top: 4px; left: 4px; }
.panel-card::after { top: 4px; right: 4px; }

.card-title {
  margin-top: -2px;
  margin-bottom: 10px;
  padding-bottom: 4px;
  color: var(--text-bright);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border-color);
}

/* Inset inputs */
input,
select {
  width: 100%;
  font: inherit;
  margin-bottom: 10px;
  padding: 8px 12px;
  background: var(--panel-inner);
  color: var(--text-bright);
  border: 2px inset var(--border-color);
  border-radius: 3px;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--select);
  box-shadow: 0 0 4px var(--select);
}

.button-row {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.button-row.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Selection Data Display (Flat inset labels) */
.selection-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.selection-grid > div {
  background: var(--panel-inner);
  border: 2px inset var(--border-color);
  padding: 6px 8px;
  border-radius: 3px;
}

.selection-label {
  display: block;
  margin-bottom: 2px;
  color: #313539;
  font-size: 9px;
  text-transform: uppercase;
  font-weight: 700;
}

.selection-grid strong {
  font-size: 12px;
  color: var(--text-bright);
}

/* ==========================================
   GLOWING CRT PREVIEW WINDOW
   ========================================== */
.command-preview {
  min-height: 72px;
  margin-bottom: 10px;
  padding: 10px;
  border: 2px inset var(--border-color);
  background: #000000;
  color: #22ff22;
  border-radius: 3px;
  font-size: 11px;
  line-height: 1.4;
  position: relative;
  overflow: hidden;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.9);
  text-shadow: 0 0 3px #22ff22;
}

.command-preview::after {
  content: " █";
  color: #22ff22;
  animation: blink 1s step-end infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.mini-note {
  margin-top: 8px;
  color: #313539;
  font-weight: bold;
  font-size: 10px;
  line-height: 1.4;
}

/* Glowing segment indicators for count rows */
.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px dotted var(--border-color);
  font-size: 11px;
}

.summary-row strong {
  background: #000000 !important;
  color: #ff2222 !important;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: bold;
  padding: 1px 6px;
  border-radius: 2px;
  border: 1px inset #4a0000;
  text-shadow: 0 0 3px #ff2222;
}

/* ==========================================
   CONSOLE PRINTER LOG STRIP
   ========================================== */
.message-strip {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
  padding: 10px 20px;
  border-top: 4px solid var(--border-color);
  background: var(--panel);
  box-shadow: inset 0 2px 2px rgba(255,255,255,0.4);
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-bright);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

#pointerHint {
  color: var(--muted);
  font-weight: bold;
  text-transform: none;
}

/* Retro print-log paper look */
#log {
  max-height: 110px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-size: 11px;
  line-height: 1.5;
  color: #1a1e22;
  padding: 8px;
  background: #faf6eb;
  border: 2px inset var(--border-color);
  border-radius: 2px;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
}

#log div, #log .log-line {
  border-bottom: 1px dashed rgba(0, 0, 0, 0.08);
  padding: 2px 0;
}

#log .log-line {
  display: flex;
  flex-wrap: wrap;
}

#log .log-time {
  color: #6a6e74;
  margin-right: 6px;
}

#log .log-level {
  font-weight: 700;
  margin-right: 6px;
}

#log .log-level-info {
  color: #0b5c15;
}

#log .log-level-warn {
  color: #9c6f05;
}

#log .log-level-fehler {
  color: #a31212;
}

.clickable-link {
  color: #2c52bf;
  text-decoration: underline;
  cursor: pointer;
  font-weight: 700;
}

.clickable-link:hover {
  color: #10d024;
}

.clickable-action {
  color: #0d4ab5;
  cursor: pointer;
  font-weight: 700;
  margin-left: 8px;
  text-decoration: underline;
  background: rgba(44, 82, 191, 0.1);
  padding: 0px 6px;
  border-radius: 3px;
  border: 1px solid rgba(44, 82, 191, 0.2);
}

.clickable-action:hover {
  color: #10d024;
  background: rgba(16, 208, 36, 0.1);
  border-color: rgba(16, 208, 36, 0.2);
}

/* Custom scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--panel-inner);
}
::-webkit-scrollbar-thumb {
  background: #7a7e84;
  border: 2px solid var(--panel-inner);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #5c6064;
}

/* ==========================================
   SVG TILED TRACK SYSTEM (SPDRS60 DOUBLE-LINE)
   ========================================== */
.track-rail-bg {
  fill: none;
  stroke: #000000;              /* Thick black underlay body */
  stroke-width: 14;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.track-rail-fg {
  fill: none;
  stroke: #ffffff;              /* Inner dashed LED display */
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 2, 7;       /* Small dots inside track */
}

/* Route indicators & Track Blocks */
.line-block {
  fill: none;
  stroke: #ffffff;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 2, 7;
}

.line-block.occupied,
.line-block.failed-occupied {
  stroke: var(--halt) !important;
  stroke-dasharray: 6, 4;       /* Solid red dash */
  filter: url(#glow-red);
}

.line-block.reserved {
  stroke: var(--route) !important;
  stroke-dasharray: 6, 4;       /* Solid yellow dash */
  filter: url(#glow-yellow);
}

.line-block.failed-free {
  stroke: var(--warn) !important;
  stroke-dasharray: 6, 4;
}

.active-route {
  fill: none;
  stroke: var(--route);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 6, 4;
  filter: url(#glow-yellow);
}

/* Switches (Tiled segments) */
.switch-geometry {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.switch-geometry-bg {
  fill: none;
  stroke: #000000;              /* Thick black underlay for switch legs */
  stroke-width: 14;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.switch-geometry-fg {
  fill: none;
  stroke: #ffffff;
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 2, 7;
}

.switch-geometry-fg.locked {
  stroke: var(--route);
  stroke-dasharray: 6, 4;
  filter: url(#glow-yellow);
}

.switch-geometry-fg.occupied {
  stroke: var(--halt);
  stroke-dasharray: 6, 4;
  filter: url(#glow-red);
}

.switch-geometry-fg.inactive {
  stroke: #404448 !important;   /* Muted center line for unaligned leg */
  stroke-dasharray: 1, 8;
  opacity: 0.5;
  filter: none !important;
}

/* Layout Labels */
.switch-label,
.signal-label,
.signal-label-text,
.target-label,
.route-node-label,
.block-label,
.station-title,
.legend-text {
  font-family: "IBM Plex Mono", monospace;
  font-weight: 700;
  paint-order: stroke;
  stroke: #afb3b8;              /* Mask label outline with console grey background */
  stroke-width: 4px;
  stroke-linejoin: round;
}

.switch-label {
  fill: #0d4ab5;
  font-size: 15px;
}

.signal-label {
  fill: #a61c1c;
  font-size: 15px;
}

.signal-label.block {
  fill: var(--blue);
}

.target-label {
  fill: #0d4ab5;
  font-size: 14px;
}

.route-node-label {
  fill: #705404;
  font-size: 12px;
}

.block-label {
  fill: var(--muted);
  font-size: 11px;
}

.station-title {
  fill: var(--text-bright);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  opacity: 0.9;
}

.legend-text {
  fill: var(--text);
  font-size: 11px;
}

/* Interactive elements */
.click-hit {
  cursor: pointer;
  fill: transparent;
  stroke: none;
}

.click-hit:hover {
  fill: rgba(255, 255, 255, 0.12);
}

.click-hit.selected {
  stroke: var(--select);
  stroke-width: 3;
  fill: rgba(0, 188, 212, 0.12);
  filter: url(#glow-blue);
}

/* SVG Signal Symbols */
.signal-mast-line {
  stroke: #000000;
  stroke-width: 4;
  stroke-linecap: square;
}

.signal-head-plate {
  fill: #000000;
  stroke: #404448;
  stroke-width: 1;
}

.signal-optic {
  stroke: #202428;
  stroke-width: 0.6;
}

.route-node {
  fill: var(--panel);
  stroke: #775c06;
  stroke-width: 2.5;
}

.route-node.selected {
  fill: var(--route);
  filter: url(#glow-yellow);
}

.route-node.pending {
  fill: var(--free);
  stroke: #0c4d16;
  filter: url(#glow-green);
}

.target-glyph {
  fill: none;
  stroke: #2c52bf;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.legend-panel {
  fill: var(--panel);
  stroke: var(--border-color);
  stroke-width: 2;
}

/* Error banner */
.error-banner {
  position: absolute;
  z-index: 10;
  top: 12px;
  left: 12px;
  right: 12px;
  padding: 10px 14px;
  border: 2px solid var(--halt);
  background: #fdf2f2;
  color: #a31212;
  border-radius: 4px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}

.hidden {
  display: none;
}

/* ==========================================
   RESPONSIVE DESIGN
   ========================================== */
@media (max-width: 1450px) {
  .estw-main {
    grid-template-columns: 1fr;
  }

  .operator-panel {
    border-left: none;
    border-top: 4px solid var(--border-color);
  }

  .estw-shell {
    grid-template-rows: 56px minmax(800px, 1fr) 210px;
  }
}
