* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Courier New', monospace;
  background: #1a1a2e;
  color: #e0e0e0;
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: #16213e;
  border-bottom: 2px solid #0f3460;
}

header h1 {
  font-size: 18px;
  color: #e94560;
}

#connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.connected { background: #00ff88; }
.status-dot.disconnected { background: #ff4444; }

main {
  padding: 10px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 10px;
}

.panel {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 6px;
  padding: 12px;
  overflow: hidden;
}

.panel h2 {
  font-size: 14px;
  color: #e94560;
  margin-bottom: 10px;
  border-bottom: 1px solid #0f3460;
  padding-bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-toggle {
  background: transparent;
  border: 1px solid #0f3460;
  color: #a0a0c0;
  border-radius: 3px;
  width: 22px;
  height: 22px;
  line-height: 1;
  padding: 0;
  font-size: 14px;
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.panel-toggle:hover {
  background: #0f3460;
  color: #e0e0e0;
}

.panel.collapsed {
  padding-bottom: 8px;
  min-height: 0 !important;
}

.panel.collapsed > *:not(h2) {
  display: none !important;
}

.panel.collapsed h2 {
  margin-bottom: 0;
  border-bottom: none;
  padding-bottom: 0;
}

.panel h3 {
  font-size: 12px;
  color: #a0a0c0;
  margin: 8px 0 4px;
}

/* Light indicators above the top view — lamp states must be readable at a glance. */
.light-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.light-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  padding: 5px 10px;
  border: 1px solid #0f3460;
  border-radius: 3px;
  background: #0a0a1a;
  color: #6a6a8a;
}

.light-indicator .light-bulb {
  font-size: 18px;
  line-height: 1;
  filter: grayscale(1) brightness(0.5);
}

.light-indicator .light-name {
  font-size: 12px;
  font-weight: bold;
  letter-spacing: 0.4px;
}

.light-indicator .light-state {
  margin-left: auto;
  font-size: 12px;
  font-family: monospace;
}

.light-indicator.on {
  color: #ffdd77;
  border-color: #ffdd77;
  background: #2a2410;
  box-shadow: 0 0 8px rgba(255, 221, 119, 0.45);
}

.light-indicator.on .light-bulb {
  filter: none;
}

canvas {
  background: #0a0a1a;
  border: 1px solid #0f3460;
  border-radius: 3px;
  width: 100%;
  height: auto;
}

/* Control Panel */
.control-group {
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #0f3460;
}

.control-group:last-child {
  border-bottom: none;
}

button {
  background: #0f3460;
  color: #e0e0e0;
  border: 1px solid #1a4a80;
  border-radius: 3px;
  padding: 6px 12px;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  margin: 2px;
}

button:hover {
  background: #1a4a80;
}

button:active {
  background: #0a2540;
}

.btn-safety {
  background: #333;
  border-color: #555;
}

.btn-safety.active {
  background: #e94560;
  border-color: #ff5577;
  color: white;
}

.btn-small {
  padding: 2px 8px;
  font-size: 10px;
}

input[type="range"] {
  width: 100%;
  margin: 4px 0;
}

/* Axis table */
#axis-table {
  width: 100%;
  font-size: 11px;
  border-collapse: collapse;
}

#axis-table th, #axis-table td {
  padding: 3px 6px;
  text-align: left;
  border-bottom: 1px solid #0f3460;
}

#axis-table th {
  color: #a0a0c0;
}

/* Axis status (Axis.[N].status wire values, CamelCase) */
.status-Moving { color: #ffcc00; }
.status-Homing { color: #ff8800; }
.status-Hold { color: #00ff88; }
.status-Idle { color: #888; }
.status-Error { color: #ff4444; }
.status-Stop { color: #ff8888; }
.status-Off { color: #555; }
.status-Uninitialized { color: #666; }

/* Sensor values */
#sensor-values {
  font-size: 11px;
  line-height: 1.6;
}

.sensor-row {
  display: flex;
  justify-content: space-between;
}

.sensor-label { color: #a0a0c0; }
.sensor-value { color: #00ff88; }
.sensor-value.false { color: #ff4444; }

/* Message Log */
#log-panel {
  grid-column: 1 / -1;
}

.panel-h2-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#message-log {
  height: 300px;
  overflow-y: auto;
  font-size: 11px;
  line-height: 1.4;
  font-family: 'Courier New', monospace;
}

.log-arrow { margin-right: 4px; }
.log-msgid { color: #666; }

.log-params {
  white-space: pre-wrap;
  font-size: 10px;
  color: #888;
  padding: 2px 0 2px 20px;
  border-left: 2px solid #333;
  margin: 4px 0 0 4px;
}

.log-entry {
  padding: 2px 4px;
  border-bottom: 1px solid #0a0a1a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-entry:hover {
  white-space: normal;
  background: #1a1a3e;
}

.log-incoming { color: #4488ff; }
.log-outgoing.status-OK { color: #00ff88; }
.log-outgoing.status-PROCESSING { color: #ffcc00; }
.log-outgoing.status-ERROR { color: #ff4444; }
.log-notification { color: #cc88ff; }

.log-timestamp { color: #555; margin-right: 8px; }
.log-function { font-weight: bold; }
.log-status { margin-left: 8px; }

/* Side views */
.side-view-container {
  display: flex;
  gap: 10px;
}

.side-view-container > div {
  flex: 1;
}

.rack-nav {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}

#rack-indicator {
  font-size: 12px;
  color: #a0a0c0;
}

.parcel-edit-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #0f3460;
}

.parcel-edit-toggle label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #e0e0e0;
  cursor: pointer;
}

.parcel-edit-toggle input[type="checkbox"] {
  cursor: pointer;
}

.parcel-edit-hint {
  font-size: 10px;
  color: #666;
}

.parcel-edit-hint.active {
  color: #00ff88;
}

/* Command Tabs */
.cmd-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 10px;
}

.cmd-tab {
  flex: 1;
  padding: 6px 10px;
  background: #0a0a1a;
  border: 1px solid #0f3460;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  color: #666;
  font-size: 11px;
  cursor: pointer;
}

.cmd-tab.active {
  background: #16213e;
  color: #e0e0e0;
  border-color: #1a4a80;
}

.cmd-tab-content {
  display: none;
}

.cmd-tab-content.active {
  display: block;
}

.btn-mc {
  background: #4a2a0a;
  border-color: #6a4a2a;
}

.btn-mc:hover {
  background: #6a4a2a;
}

/* Command Executor */
#command-panel select,
#command-panel input[type="text"],
#command-panel input[type="number"] {
  width: 100%;
  background: #0a0a1a;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 3px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 11px;
  margin: 2px 0;
}

#command-panel select option {
  background: #0a0a1a;
}

#command-panel label {
  font-size: 11px;
  color: #a0a0c0;
  display: block;
  margin-bottom: 2px;
}

.cmd-param-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin: 3px 0;
}

.cmd-param-row label {
  min-width: 80px;
  text-align: right;
  font-size: 10px;
}

.cmd-param-row input,
.cmd-param-row select {
  flex: 1;
}

.btn-execute {
  background: #0a6e3a;
  border-color: #0a8e4a;
  font-weight: bold;
  width: 100%;
  padding: 8px;
}

.btn-execute:hover {
  background: #0a8e4a;
}

.cmd-response {
  background: #0a0a1a;
  border: 1px solid #0f3460;
  border-radius: 3px;
  padding: 8px;
  font-size: 10px;
  color: #00ff88;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 40px;
}

.cmd-response.error {
  color: #ff4444;
}

/* Grid: 3 columns for wider layout */
.grid {
  grid-template-columns: 1fr 1fr 1fr;
}

#top-view-panel {
  grid-column: 1 / 3;
}

#control-panel {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
  align-self: start;
}

.right-stack {
  grid-column: 2 / 4;
  grid-row: 2 / 3;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self: start;
  min-width: 0;
}

#client-panel {
  display: flex;
  flex-direction: column;
  min-height: 600px;
}

#client-panel iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: #0a0a1a;
  border-radius: 4px;
  min-height: 550px;
}

#tests-panel {
  display: flex;
  flex-direction: column;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: #0a0a1a;
}

::-webkit-scrollbar-thumb {
  background: #0f3460;
  border-radius: 3px;
}

/* ─── Test Runner ──────────────────────────────────────────────────────────── */

.test-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.test-filter {
  flex: 1;
  background: #0a0a1a;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 3px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 11px;
}

.test-btn-group {
  display: flex;
  gap: 4px;
}

.btn-test-run-all {
  background: #0a6e3a;
  border-color: #0a8e4a;
  font-weight: bold;
}

.btn-test-run-all:hover { background: #0a8e4a; }
.btn-test-run-all:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-test-stop {
  background: #8e2a0a;
  border-color: #ae4a2a;
}

.btn-test-stop:hover { background: #ae4a2a; }
.btn-test-stop:disabled { opacity: 0.3; cursor: not-allowed; }

.test-summary {
  font-size: 11px;
  padding: 4px 0;
  margin-bottom: 6px;
  color: #a0a0c0;
}

.test-pass-count { color: #00ff88; }
.test-fail-count { color: #ff4444; }
.test-precond-count { color: #ff8800; }

.test-list {
  max-height: 360px;
  overflow-y: auto;
}

.test-row {
  border: 1px solid #0f3460;
  border-radius: 3px;
  margin-bottom: 4px;
  background: #0d1a30;
}

.test-row.test-pass { border-left: 3px solid #00ff88; }
.test-row.test-fail { border-left: 3px solid #ff4444; }
.test-row.test-precondition { border-left: 3px solid #ff8800; }

.test-row-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 11px;
}

.test-row-header:hover {
  background: #1a2a4e;
}

.test-indicator {
  font-size: 13px;
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.indicator-pass { color: #00ff88; }
.indicator-fail { color: #ff4444; }
.indicator-precondition { color: #ff8800; }
.indicator-running { color: #ffcc00; }
.indicator-pending { color: #555; }

.test-name {
  flex: 1;
  color: #e0e0e0;
  font-weight: bold;
}

.test-tags {
  color: #555;
  font-size: 10px;
  flex-shrink: 0;
}

.btn-test-run {
  font-size: 10px;
  padding: 2px 8px;
  flex-shrink: 0;
}

.btn-test-run:disabled { opacity: 0.3; cursor: not-allowed; }

/* Step details */
.test-step-details {
  padding: 4px 8px 8px 28px;
  border-top: 1px solid #0f3460;
}

.test-step {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 0;
  font-size: 10px;
  color: #a0a0c0;
  flex-wrap: wrap;
}

.test-step.pass .step-icon { color: #00ff88; }
.test-step.fail .step-icon { color: #ff4444; }
.test-step.running .step-icon { color: #ffcc00; }

.step-label { flex: 1; }

.step-duration {
  color: #555;
  font-size: 9px;
  flex-shrink: 0;
}

.step-error {
  width: 100%;
  color: #ff6666;
  font-size: 9px;
  padding: 2px 0 0 20px;
}

/* ─── Parcel Add/Remove Dialog ────────────────────────────────────────────── */

#side-view-left,
#side-view-right,
#top-view {
  cursor: pointer;
}

.parcel-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.parcel-dialog.hidden {
  display: none;
}

.parcel-dialog-content {
  background: #16213e;
  border: 1px solid #1a4a80;
  border-radius: 6px;
  padding: 16px;
  min-width: 280px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.parcel-dialog-content h3 {
  color: #e94560;
  font-size: 13px;
  margin-bottom: 12px;
  border-bottom: 1px solid #0f3460;
  padding-bottom: 6px;
}

.parcel-field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
}

.parcel-field-row label {
  flex: 0 0 90px;
  color: #a0a0c0;
  font-size: 11px;
}

.parcel-field-row input {
  flex: 1;
  background: #0a0a1a;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 3px;
  padding: 4px 6px;
  font-family: inherit;
  font-size: 11px;
}

.notice-message {
  color: #e0e0e0;
  font-size: 12px;
  line-height: 1.4;
  margin: 8px 0 14px;
  white-space: pre-wrap;
}

.parcel-presets {
  display: flex;
  gap: 4px;
  margin: 10px 0;
}

.parcel-presets button {
  flex: 1;
}

.parcel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 10px;
}

.parcel-actions button {
  min-width: 80px;
}
