/* Live dashboard */

.live-dashboard {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.dashboard-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.dashboard-controls > * {
  flex-shrink: 0;
}

.dashboard-controls .btn {
  min-height: 2.25rem;
  padding: 0.4rem 0.85rem;
  font-size: 0.8rem;
}

/* On wide screens the overflow wrapper is transparent: its children flow
   inline as normal toolbar items. The ⋯ button and the overflow-only text
   label only appear on phones (see the max-width: 768px block). */
.dashboard-controls-overflow {
  display: contents;
}

/* With display:contents the wrapper's children are the real flex items, so
   carry over the no-shrink behaviour the direct children used to get. */
.dashboard-controls-overflow > * {
  flex-shrink: 0;
}

.dash-more-toggle,
.dash-overflow-text {
  display: none;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.25rem;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--apex-border);
  font-size: 0.8rem;
  line-height: 1.15;
  color: var(--apex-muted);
}

.connection-status .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: rgba(157, 181, 168, 0.5);
  transition: background 0.3s ease;
}

.connection-status.connected .status-dot {
  background: var(--apex-success);
  box-shadow: 0 0 8px rgba(var(--apex-success-rgb), 0.5);
}

.connection-status.connected {
  color: var(--apex-success);
  border-color: rgba(var(--apex-success-rgb), 0.3);
}

/* REAL | toggle | SIM segmented control for the live data source. */
.source-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  min-height: 2.25rem;
  padding: 0.3rem 0.55rem;
  border: 1px solid var(--apex-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  line-height: 1.15;
  user-select: none;
}

.source-switch-side {
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--apex-muted);
  cursor: pointer;
  transition: color 0.15s ease;
}

.source-switch-side:disabled {
  cursor: default;
}

.source-switch-real.is-active {
  color: var(--apex-success);
}

.source-switch-sim.is-active {
  color: #f59e0b;
}

.source-switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--apex-border);
  border-radius: 999px;
  background: rgba(var(--apex-success-rgb), 0.18);
  cursor: pointer;
  transition: background 0.15s ease;
}

.source-switch.is-simulation .source-switch-track {
  background: rgba(245, 158, 11, 0.22);
}

.source-switch-track:disabled {
  cursor: default;
  opacity: 0.6;
}

.source-switch-track:focus-visible {
  outline: 2px solid var(--apex-accent, #3b82f6);
  outline-offset: 2px;
}

.source-switch-knob {
  position: absolute;
  top: 50%;
  left: 2px;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--apex-success);
  transition: left 0.15s ease, background 0.15s ease;
}

.source-switch.is-simulation .source-switch-knob {
  left: calc(100% - 18px);
  background: #f59e0b;
}

.recording-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.25rem;
  padding: 0.25rem 0.3rem;
  border: 1px solid var(--apex-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--apex-muted);
  line-height: 1.15;
}

.recording-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  min-height: 1.75rem;
  min-width: 68px;
  padding: 0.24rem 0.6rem;
  border: 1px solid rgba(248, 113, 113, 0.34);
  border-radius: 999px;
  color: #fca5a5;
  background: rgba(248, 113, 113, 0.08);
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.recording-action:hover,
.recording-action:focus {
  color: #fee2e2;
  border-color: rgba(248, 113, 113, 0.55);
  background: rgba(248, 113, 113, 0.14);
  outline: none;
}

.recording-action:disabled {
  cursor: wait;
  opacity: 0.68;
}

.recording-dot {
  width: 0.48rem;
  height: 0.48rem;
  flex: 0 0 0.48rem;
  border-radius: 999px;
  background: #f87171;
  box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.12);
}

.recording-status {
  display: inline-flex;
  align-items: center;
  padding: 0 0.1rem;
  color: var(--apex-muted);
  font-size: 0.8rem;
  line-height: 1.15;
  white-space: nowrap;
}

.recording-status:empty {
  display: none;
}

.recording-controls.is-recording {
  border-color: rgba(248, 113, 113, 0.3);
  background: rgba(248, 113, 113, 0.07);
}

.recording-controls.is-recording .recording-status {
  color: #fecdd3;
}

.recording-controls.is-recording .recording-action {
  color: #fee2e2;
  border-color: rgba(248, 113, 113, 0.5);
  background: rgba(239, 68, 68, 0.2);
}

.recording-controls.is-recording .recording-dot {
  animation: recordingPulse 1.2s ease-in-out infinite;
}

.recording-controls.is-busy {
  opacity: 0.78;
}

/* ── Live radio (WebRTC) controls ── */
.radio-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.25rem;
  padding: 0.25rem 0.3rem;
  border: 1px solid var(--apex-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--apex-muted);
  line-height: 1.15;
}

.radio-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42rem;
  min-height: 1.75rem;
  min-width: 68px;
  padding: 0.24rem 0.6rem;
  border: 1px solid rgba(52, 214, 160, 0.34);
  border-radius: 999px;
  color: #7FE6C6;
  background: rgba(52, 214, 160, 0.08);
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.radio-action:hover,
.radio-action:focus {
  color: #D6F5E9;
  border-color: rgba(52, 214, 160, 0.55);
  background: rgba(52, 214, 160, 0.14);
  outline: none;
}

.radio-action .radio-icon {
  flex: 0 0 auto;
}

.radio-controls[data-state="connecting"] .radio-icon {
  animation: recordingPulse 1.2s ease-in-out infinite;
}

.radio-action.is-active {
  color: #D6F5E9;
  border-color: rgba(52, 214, 160, 0.6);
  background: rgba(52, 214, 160, 0.2);
}

.radio-status {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  color: var(--apex-muted);
  font-size: 0.8rem;
  line-height: 1.15;
  white-space: nowrap;
}

.radio-status:empty {
  display: none;
}

.radio-controls[data-state="error"] .radio-status {
  color: #fca5a5;
}

.recording-downloads {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding-left: 0.4rem;
  border-left: 1px solid rgba(157, 181, 168, 0.22);
}

.recording-downloads.d-none {
  display: none !important;
}

.recording-download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.65rem;
  padding: 0.22rem 0.45rem;
  border: 1px solid transparent;
  border-radius: 999px;
  color: #B9CDBF;
  background: transparent;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.recording-download-link:hover,
.recording-download-link:focus {
  border-color: rgba(52, 214, 160, 0.26);
  color: #E6F0EA;
  background: rgba(52, 214, 160, 0.09);
  outline: none;
}

@keyframes recordingPulse {
  0%, 100% {
    box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.12);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.28);
  }
}

.modal-kicker {
  color: var(--apex-success);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  line-height: 1.2;
}

.toolbar-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--apex-success);
  box-shadow: 0 0 0 3px rgba(var(--apex-success-rgb), 0.14), 0 0 9px rgba(var(--apex-success-rgb), 0.35);
}

.status-lights-section {
  display: grid;
  gap: 0.42rem;
}

.status-lights-heading {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  color: var(--apex-muted);
}

.status-lights-heading > span {
  color: var(--apex-text);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.status-lights-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.status-lights-bar.status-lights-bar--empty {
  display: none;
}

.status-light {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(157, 181, 168, 0.24);
  background: linear-gradient(135deg, #111713, #18211C);
  min-height: 28px;
}

.status-light[draggable="true"] {
  cursor: grab;
}

.status-light[draggable="true"]:active {
  cursor: grabbing;
}

.status-light.dragging {
  opacity: 0.42;
}

.status-light.drop-before {
  box-shadow: -4px 0 0 var(--apex-success);
}

.status-light-bus {
  display: none;
  padding: 0.12rem 0.25rem;
  border-radius: 4px;
  color: var(--apex-success-strong);
  background: rgba(var(--apex-success-rgb), 0.1);
  font-size: 0.52rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.status-light[data-bus="can2"] .status-light-bus {
  color: #7dd3fc;
  background: rgba(56, 189, 248, 0.12);
}

body.edit-mode .status-light-bus {
  display: inline-flex;
}

.status-light-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: rgba(157, 181, 168, 0.7);
  box-shadow: 0 0 0 3px rgba(157, 181, 168, 0.16);
  flex: 0 0 auto;
}

.status-light-label {
  color: #B9CDBF;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.status-light-state {
  color: var(--apex-muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.status-light-edit-controls {
  display: none;
  gap: 0.2rem;
  margin-left: 0.15rem;
}

.status-light-drag-handle {
  display: inline-flex;
  align-items: center;
  padding: 0 0.1rem;
  color: var(--apex-muted);
  cursor: grab;
  font-size: 0.72rem;
  letter-spacing: -0.16em;
}

body.edit-mode .status-light-edit-controls {
  display: inline-flex;
}

.status-light-edit-controls .widget-btn {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  font-size: 0.72rem;
}

.status-light.is-on {
  border-color: rgba(var(--apex-success-rgb), 0.38);
  background: linear-gradient(135deg, #0B3022, #153721);
}

.status-light.is-on .status-light-dot {
  background: var(--apex-success);
  box-shadow: 0 0 0 3px rgba(var(--apex-success-rgb), 0.2), 0 0 10px rgba(var(--apex-success-rgb), 0.45);
}

.status-light.is-on .status-light-state {
  color: var(--apex-success-strong);
}

.status-light.is-warn {
  border-color: rgba(250, 204, 21, 0.45);
  background: linear-gradient(135deg, #39270B, #302810);
}

.status-light.is-warn .status-light-dot {
  background: #facc15;
  box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.2), 0 0 10px rgba(250, 204, 21, 0.42);
}

.status-light.is-warn .status-light-state {
  color: #fde68a;
}

.status-light.is-off {
  border-color: rgba(248, 113, 113, 0.35);
  background: linear-gradient(135deg, #391719, #2D1919);
}

.status-light.is-off .status-light-dot {
  background: #ef4444;
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.2), 0 0 10px rgba(248, 113, 113, 0.35);
}

.status-light.is-off .status-light-state {
  color: #fca5a5;
}

.status-light.is-stale {
  border-color: rgba(157, 181, 168, 0.3);
  background: linear-gradient(135deg, #151A17, #1C221E);
}

.status-light.is-stale .status-light-dot {
  background: #7E968A;
  box-shadow: 0 0 0 3px rgba(126, 150, 138, 0.18);
}

.status-light.is-stale .status-light-state {
  color: #9DB5A8;
}

.status-light--hidden {
  display: none;
}

#edit-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.2s ease;
}

#edit-mode-toggle.active {
  background: var(--apex-success-deep);
  border-color: var(--apex-success-deep);
  color: #fff;
}
