/* Global reset and base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: #0f1117;
  color: #e2e8f0;
  font-family: system-ui, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
}

#app {
  width: 100%;
  max-width: none;
  margin: 0;
  text-align: left;
  border: none;
  min-height: 100vh;
}

/* ── Connection banner ─────────────────────────────────────────────────── */

.connection-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #7f1d1d;
  color: #fca5a5;
  text-align: center;
  font-size: 0.8rem;
  padding: 0.3rem 1rem;
}

/* ── ViewMode ──────────────────────────────────────────────────────────── */

.view-mode {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  background: #0f1117;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  height: 44px;
  background: #1a1f2e;
  border-bottom: 1px solid #2d3748;
  flex-shrink: 0;
  gap: 1rem;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.toolbar-center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  justify-content: flex-end;
}

.app-name {
  font-size: 1rem;
  font-weight: 800;
  color: #60a5fa;
  letter-spacing: -0.5px;
}

.iface-name {
  font-size: 0.85rem;
  color: #94a3b8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.parse-error {
  font-size: 0.78rem;
  color: #f87171;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 4px;
  padding: 0.15rem 0.5rem;
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  background: #1e293b;
  color: #94a3b8;
  border: 1px solid #334155;
  text-transform: capitalize;
}

.status-chip.connected {
  background: #14532d;
  color: #86efac;
  border-color: #166534;
}

.status-chip.disconnected {
  background: #7f1d1d;
  color: #fca5a5;
  border-color: #991b1b;
}

.status-chip.connecting {
  background: #1e293b;
  color: #fbbf24;
  border-color: #92400e;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.btn-edit {
  background: #2d3748;
  border: none;
  color: #e2e8f0;
  font-size: 0.8rem;
  padding: 0.25rem 0.7rem;
  border-radius: 4px;
  cursor: pointer;
}

.btn-edit:hover {
  background: #374151;
}

.content {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── EditMode ──────────────────────────────────────────────────────────── */

.edit-mode {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100%;
  background: #0f1117;
  color: #475569;
  font-size: 1.1rem;
}

/* ── InterfaceList panel ───────────────────────────────────────────────── */

.panel {
  width: 260px;
  min-width: 260px;
  background: #1a1f2e;
  border-right: 1px solid #2d3748;
  display: flex;
  flex-direction: column;
  transition: width 0.2s ease, min-width 0.2s ease;
  overflow: hidden;
}

.panel.collapsed {
  width: 40px;
  min-width: 40px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.5rem 0.5rem 0.75rem;
  border-bottom: 1px solid #2d3748;
  min-height: 40px;
  flex-shrink: 0;
}

.panel.collapsed .panel-header {
  justify-content: center;
  padding: 0.5rem;
}

.panel-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.icon-btn {
  background: none;
  border: none;
  color: #64748b;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.2rem 0.4rem;
  border-radius: 3px;
  line-height: 1;
}

.icon-btn:hover {
  background: #2d3748;
  color: #e2e8f0;
}

.panel-actions {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid #2d3748;
  flex-shrink: 0;
}

.panel-btn {
  flex: 1;
  background: #2d3748;
  border: none;
  color: #e2e8f0;
  font-size: 0.78rem;
  padding: 0.3rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}

.panel-btn:hover {
  background: #374151;
}

.panel-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.hint {
  color: #475569;
  font-size: 0.8rem;
  padding: 0.75rem 0.75rem;
  line-height: 1.5;
}

.iface-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.iface-item {
  padding: 0.5rem 0.75rem;
  color: #cbd5e1;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 3px;
  margin: 1px 4px;
}

.iface-item:hover {
  background: #2d3748;
  color: #e2e8f0;
}

/* ── Canvas ────────────────────────────────────────────────────────────── */

.canvas-container {
  flex: 1;
  position: relative;
  overflow: auto;
  background: #0f1117;
  min-width: 0;
}

.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #475569;
  font-size: 0.95rem;
  text-align: center;
  padding: 2rem;
}

.canvas-area {
  position: relative;
  /* width/height set inline from interface dimensions */
}

/* ── TextLabel widget ──────────────────────────────────────────────────────── */

.textlabel {
  position: absolute;
  display: flex;
  align-items: center;
  overflow: hidden;
  box-sizing: border-box;
  font-size: 0.9rem;
  color: #e2e8f0;
  font-family: system-ui, sans-serif;
  white-space: nowrap;
}

/* ── Unknown widget ────────────────────────────────────────────────────────── */

.unknown-widget {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1e2535;
  border: 1px dashed #3d4f6e;
  border-radius: 4px;
  box-sizing: border-box;
}

.unknown-label {
  color: #475569;
  font-size: 0.75rem;
  font-family: ui-monospace, monospace;
}

/* ── Context Menu ──────────────────────────────────────────────────────── */

.ctx-menu {
  position: fixed;
  z-index: 9000;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  min-width: 180px;
  padding: 4px 0;
  font-family: system-ui, sans-serif;
}

.ctx-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: #cbd5e1;
  font-size: 0.85rem;
  padding: 0.4rem 0.9rem;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.ctx-item:hover {
  background: #2d3748;
  color: #e2e8f0;
}

.ctx-divider {
  height: 1px;
  background: #2d3748;
  margin: 4px 0;
}

.ctx-signal-info {
  padding: 0.3rem 0.9rem;
  font-size: 0.75rem;
  color: #475569;
  font-family: ui-monospace, monospace;
}

/* ── Widgets — shared ──────────────────────────────────────────────────── */

.quality-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ── TextView widget ───────────────────────────────────────────────────── */

.textview {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 0.4em;
  padding: 0 0.6em;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 4px;
  overflow: hidden;
  box-sizing: border-box;
  white-space: nowrap;
}

.textview .label {
  color: #94a3b8;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.textview .value {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.9rem;
  color: #e2e8f0;
  min-width: 4ch;
}

.textview .unit {
  color: #64748b;
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* ── Gauge widget ──────────────────────────────────────────────────────── */

.gauge {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 6px;
  box-sizing: border-box;
  overflow: hidden;
  font-family: system-ui, sans-serif;
  padding: 4px;
}

.gauge .quality-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.gauge-svg {
  width: 100%;
  flex: 1;
  overflow: visible;
}

.gauge-value {
  fill: #e2e8f0;
  font-size: 14px;
  font-family: ui-monospace, monospace;
}

.gauge-unit {
  fill: #64748b;
  font-size: 6px;
  font-family: system-ui, sans-serif;
}

.gauge-range {
  fill: #475569;
  font-size: 6px;
  font-family: system-ui, sans-serif;
}

.gauge-label {
  font-size: 0.75rem;
  color: #94a3b8;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  padding: 0 4px;
  box-sizing: border-box;
}

/* ── BarH widget ───────────────────────────────────────────────────────── */

.barh {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 3px;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 6px;
  box-sizing: border-box;
  padding: 6px 10px;
  font-family: system-ui, sans-serif;
  overflow: hidden;
}

.barh .quality-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.barh .bar-label {
  font-size: 0.75rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.barh .bar-track {
  width: 100%;
  height: 12px;
  background: #2d3748;
  border-radius: 3px;
  overflow: hidden;
}

.barh .bar-fill {
  height: 100%;
  background: #4a9eff;
  border-radius: 3px;
  transition: width 0.15s ease;
}

.barh .bar-value {
  display: flex;
  gap: 4px;
  align-items: baseline;
  justify-content: flex-end;
}

.barh .value {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  color: #e2e8f0;
}

.barh .unit {
  font-size: 0.7rem;
  color: #64748b;
}

/* ── BarV widget ───────────────────────────────────────────────────────── */

.barv {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 6px;
  box-sizing: border-box;
  padding: 6px 8px;
  font-family: system-ui, sans-serif;
  overflow: hidden;
}

.barv .quality-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.barv .bar-label {
  font-size: 0.75rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-align: center;
}

.barv .bar-value {
  display: flex;
  gap: 3px;
  align-items: baseline;
}

.barv .value {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  color: #e2e8f0;
}

.barv .unit {
  font-size: 0.7rem;
  color: #64748b;
}

.barv .bar-track {
  width: 24px;
  flex: 1;
  background: #2d3748;
  border-radius: 3px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.barv .bar-fill {
  width: 100%;
  background: #4a9eff;
  border-radius: 3px;
  transition: height 0.15s ease;
}

/* ── LED widget ────────────────────────────────────────────────────────── */

.led-widget {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 6px;
  box-sizing: border-box;
  padding: 4px;
  font-family: system-ui, sans-serif;
  overflow: hidden;
}

.led-circle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.2s;
}

.led-circle.blink {
  animation: blink-slow 1.8s ease-in-out infinite;
}

@keyframes blink-slow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.led-label {
  font-size: 0.75rem;
  color: #94a3b8;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

/* ── MultiLed widget ───────────────────────────────────────────────────── */

.multiled-widget {
  position: absolute;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 4px;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 6px;
  box-sizing: border-box;
  padding: 6px;
  font-family: system-ui, sans-serif;
  overflow: hidden;
}

.bit-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 20px;
}

.multiled-widget .led-circle {
  width: 14px;
  height: 14px;
}

.bit-label {
  font-size: 0.6rem;
  color: #64748b;
  text-align: center;
  white-space: nowrap;
}

/* ── SetValue widget ───────────────────────────────────────────────────── */

.setvalue {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 6px;
  box-sizing: border-box;
  overflow: hidden;
  font-family: system-ui, sans-serif;
  white-space: nowrap;
}

.setvalue .quality-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sv-label {
  color: #94a3b8;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.sv-input {
  width: 80px;
  background: #0f1117;
  border: 1px solid #3d4f6e;
  border-radius: 4px;
  color: #e2e8f0;
  font-size: 0.85rem;
  padding: 2px 5px;
  flex-shrink: 0;
  font-family: ui-monospace, monospace;
}

.sv-input:focus {
  outline: none;
  border-color: #4a9eff;
}

.sv-current {
  font-family: ui-monospace, monospace;
  font-size: 0.85rem;
  color: #e2e8f0;
  flex-shrink: 0;
}

.sv-unit {
  font-size: 0.7rem;
  color: #64748b;
  flex-shrink: 0;
}

.sv-btn {
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 3px 10px;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
  font-family: system-ui, sans-serif;
}

.sv-btn:hover {
  background: #1d4ed8;
}

.sv-btn:active {
  background: #1e40af;
}

/* ── Button widget ─────────────────────────────────────────────────────── */

.button-widget {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 4px;
}

.button-widget .btn {
  width: 100%;
  height: 100%;
  background: #1e3a5f;
  color: #e2e8f0;
  border: 1px solid #2d5a9e;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: system-ui, sans-serif;
  cursor: pointer;
  transition: background 0.15s;
}

.button-widget .btn:hover {
  background: #2563eb;
  border-color: #3b82f6;
}

.button-widget .btn:active {
  background: #1d4ed8;
  transform: scale(0.97);
}

/* ── ImageWidget ───────────────────────────────────────────────────────── */

.image-widget {
  position: absolute;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 4px;
  box-sizing: border-box;
  overflow: hidden;
}

.image-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  color: #475569;
  font-size: 0.8rem;
}

/* ── LinkWidget ────────────────────────────────────────────────────────── */

.link-widget {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.link-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 100%;
  background: #1e293b;
  color: #60a5fa;
  border: 1px solid #334155;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: system-ui, sans-serif;
  cursor: pointer;
  padding: 0 10px;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}

.link-btn:hover {
  background: #1e3a5f;
  border-color: #3b82f6;
  color: #93c5fd;
}

.link-icon { font-size: 1rem; flex-shrink: 0; }
.link-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── PlotWidget ────────────────────────────────────────────────────────── */

.plot-widget {
  position: absolute;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 6px;
  box-sizing: border-box;
  overflow: hidden;
  font-family: system-ui, sans-serif;
}

.chart-area {
  overflow: hidden;
}

/* uPlot dark overrides */
.chart-area .u-wrap { background: transparent; }
.chart-area .u-legend { color: #94a3b8; font-size: 0.75rem; }
.chart-area .u-value { color: #e2e8f0; }

/* ── Edit Mode layout ──────────────────────────────────────────────────── */

.edit-mode-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  background: #0f1117;
  outline: none;
}

.edit-badge {
  font-size: 0.7rem;
  font-weight: 700;
  background: #7c3aed;
  color: #e9d5ff;
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.iface-name-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid #3d4f6e;
  color: #e2e8f0;
  font-size: 0.9rem;
  padding: 0 4px;
  width: 200px;
  outline: none;
  font-family: system-ui, sans-serif;
}

.iface-name-input:focus {
  border-bottom-color: #60a5fa;
}

.dirty-dot {
  color: #f59e0b;
  font-size: 0.9rem;
  line-height: 1;
}

.toolbar-btn {
  background: #2d3748;
  border: none;
  color: #e2e8f0;
  font-size: 0.8rem;
  padding: 0.25rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  font-family: system-ui, sans-serif;
}

.toolbar-btn:hover { background: #374151; }

.toolbar-btn-primary {
  background: #2563eb;
  color: #fff;
}

.toolbar-btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.toolbar-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.toolbar-btn-active {
  background: #1e40af;
  color: #93c5fd;
  border: 1px solid #3b82f6;
}

/* time-nav styles are in the time-nav-bar section at the bottom of this file */

/* Overlay shown inside a plot widget while history is loading or unavailable */
.hist-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: #94a3b8;
  background: rgba(26, 31, 46, 0.75);
  pointer-events: none;
}
.hist-overlay-warn { color: #fbbf24; }

.edit-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Edit Canvas ────────────────────────────────────────────────────────── */

.edit-canvas-container {
  flex: 1;
  position: relative;
  overflow: auto;
  background: #0a0d14;
  background-image:
    linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 20px 20px;
  min-width: 0;
}

/* Widget overlays */
.widget-overlay {
  position: absolute;
  box-sizing: border-box;
  cursor: move;
  border: 1px solid transparent;
  transition: border-color 0.1s;
  z-index: 10;
}

.widget-overlay:hover {
  border-color: rgba(96, 165, 250, 0.4);
}

.widget-overlay.selected {
  border: 2px solid #60a5fa;
  border-radius: 2px;
}

.overlay-delete {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  border: none;
  font-size: 0.65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  z-index: 30;
  padding: 0;
}

.overlay-delete:hover { background: #dc2626; }

/* Resize handles */
.resize-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #60a5fa;
  border: 1px solid #1e40af;
  border-radius: 1px;
  z-index: 20;
}

.resize-n  { top: -4px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.resize-s  { bottom: -4px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.resize-e  { right: -4px; top: 50%; transform: translateY(-50%); cursor: e-resize; }
.resize-w  { left: -4px; top: 50%; transform: translateY(-50%); cursor: w-resize; }
.resize-ne { top: -4px; right: -4px; cursor: ne-resize; }
.resize-nw { top: -4px; left: -4px; cursor: nw-resize; }
.resize-se { bottom: -4px; right: -4px; cursor: se-resize; }
.resize-sw { bottom: -4px; left: -4px; cursor: sw-resize; }

/* ── Widget Type Picker ──────────────────────────────────────────────────── */

.widget-picker-backdrop {
  position: fixed;
  inset: 0;
  z-index: 8000;
}

.widget-picker {
  position: fixed;
  background: #1a1f2e;
  border: 1px solid #3d4f6e;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  min-width: 220px;
  max-height: 420px;
  overflow-y: auto;
  z-index: 8001;
}

.widget-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #94a3b8;
  border-bottom: 1px solid #2d3748;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.widget-picker-list { padding: 4px 0; }

.widget-picker-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  width: 100%;
  background: none;
  border: none;
  color: #e2e8f0;
  padding: 0.4rem 0.75rem;
  text-align: left;
  cursor: pointer;
  font-family: system-ui, sans-serif;
}

.widget-picker-item:hover { background: #2d3748; }

.wpt-label { font-size: 0.85rem; font-weight: 500; }
.wpt-desc  { font-size: 0.75rem; color: #64748b; }

/* ── Signal Tree ─────────────────────────────────────────────────────────── */

.signal-tree-panel {
  border-right: 1px solid #2d3748;
}

.signal-tree-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.signal-tree-search {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid #2d3748;
  flex-shrink: 0;
}

.signal-filter {
  width: 100%;
  background: #0f1117;
  border: 1px solid #2d3748;
  border-radius: 4px;
  color: #e2e8f0;
  font-size: 0.8rem;
  padding: 0.25rem 0.5rem;
  outline: none;
  font-family: system-ui, sans-serif;
}

.signal-filter:focus { border-color: #4a9eff; }

.signal-list { overflow-y: auto; flex: 1; }

.signal-group { margin-bottom: 2px; }

.signal-group-header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  color: #94a3b8;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  user-select: none;
}

.signal-group-header:hover { color: #cbd5e1; }

.signal-group-arrow { font-size: 0.7rem; flex-shrink: 0; }
.signal-group-name  { flex: 1; }
.signal-group-count {
  font-size: 0.7rem;
  background: #2d3748;
  border-radius: 10px;
  padding: 0 5px;
  color: #64748b;
}

.signal-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem 0.25rem 1.25rem;
  cursor: grab;
  border-radius: 3px;
  margin: 1px 4px;
  user-select: none;
}

.signal-item:hover { background: #1e2535; }
.signal-item:active { cursor: grabbing; }

.signal-name { font-size: 0.8rem; color: #cbd5e1; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signal-unit { font-size: 0.7rem; color: #64748b; flex-shrink: 0; }

/* Signal tree toolbar (+ Synthetic, CSV, Refresh) */
.signal-tree-toolbar {
  display: flex;
  gap: 0.25rem;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid #2d3748;
  flex-wrap: wrap;
}

/* Row containing filter input + CF search button */
.signal-search-row {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

/* "+" button inside group header */
.signal-add-btn {
  margin-left: auto;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.15s;
}
.signal-group-header:hover .signal-add-btn { opacity: 1; }

/* Inline add-signal row */
.signal-add-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem 0.2rem 1.5rem;
}
.signal-add-input {
  flex: 1;
  font-size: 0.8rem;
  background: #1a2236;
  border: 1px solid #4a5568;
  border-radius: 4px;
  color: #e2e8f0;
  padding: 0.15rem 0.4rem;
  outline: none;
}
.signal-add-input:focus { border-color: #63b3ed; }

/* Custom (manually added) signal items */
.signal-custom { opacity: 0.85; }
.signal-custom .signal-name { font-style: italic; }

/* Remove button on custom items */
.signal-remove-btn {
  margin-left: auto;
  font-size: 0.7rem;
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.signal-item:hover .signal-remove-btn { opacity: 1; }

/* ── Synthetic Wizard ─────────────────────────────────────────────────────── */

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

.wizard {
  background: #1e2535;
  border: 1px solid #2d3748;
  border-radius: 8px;
  width: 420px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.wizard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #2d3748;
  font-weight: 600;
  font-size: 0.95rem;
  color: #e2e8f0;
}

.wizard-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.wizard-footer {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  padding: 0.75rem 1rem;
  border-top: 1px solid #2d3748;
}

.wizard-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: #64748b;
  letter-spacing: 0.06em;
  margin-top: 0.5rem;
}

.wizard-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.wizard-field label {
  font-size: 0.75rem;
  color: #94a3b8;
}

/* Side-by-side fields */
.wizard-field-row {
  flex-direction: row;
  gap: 0.5rem;
}
.wizard-field-row > .wizard-field { flex: 1; }

.wizard-error {
  color: #fc8181;
  font-size: 0.8rem;
  background: rgba(252,129,129,0.1);
  border: 1px solid #fc8181;
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
}

/* ── Properties Pane ─────────────────────────────────────────────────────── */

.props-panel {
  width: 240px;
  min-width: 240px;
}

.props-body {
  overflow-y: auto;
  flex: 1;
  padding: 0.5rem 0;
}

.props-section {
  padding: 0 0 0.75rem;
  border-bottom: 1px solid #2d3748;
  margin-bottom: 0.5rem;
}

.props-section:last-child { border-bottom: none; }

.props-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.4rem 0.6rem 0.3rem;
}

.prop-field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem;
}

.prop-label {
  font-size: 0.75rem;
  color: #64748b;
  width: 60px;
  flex-shrink: 0;
}

.prop-input {
  flex: 1;
  background: #0f1117;
  border: 1px solid #2d3748;
  border-radius: 3px;
  color: #e2e8f0;
  font-size: 0.8rem;
  padding: 0.15rem 0.35rem;
  outline: none;
  font-family: system-ui, sans-serif;
  min-width: 0;
}

.prop-input:focus { border-color: #4a9eff; }

.prop-input-num { width: 70px; flex: none; }

.prop-select {
  flex: 1;
  background: #0f1117;
  border: 1px solid #2d3748;
  border-radius: 3px;
  color: #e2e8f0;
  font-size: 0.8rem;
  padding: 0.15rem 0.35rem;
  outline: none;
  font-family: system-ui, sans-serif;
}

.prop-sig {
  font-size: 0.75rem;
  color: #94a3b8;
  font-family: ui-monospace, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── InterfaceList item actions ─────────────────────────────────────────── */

.iface-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.iface-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.iface-item-actions {
  display: none;
  gap: 2px;
  flex-shrink: 0;
}

.iface-item:hover .iface-item-actions { display: flex; }

.iface-delete { color: #ef4444 !important; }
.iface-delete:hover { background: rgba(239, 68, 68, 0.15) !important; }

/* ── Phase 7 additions ───────────────────────────────────────────────────── */

/* Rubber-band selection rectangle */
.rubber-band {
  position: absolute;
  pointer-events: none;
  border: 1px solid #60a5fa;
  background: rgba(96, 165, 250, 0.08);
  z-index: 50;
  box-sizing: border-box;
}

/* Edit toolbar tools (center section) */
.edit-toolbar-tools {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  justify-content: center;
}

.toolbar-sep {
  width: 1px;
  height: 18px;
  background: #2d3748;
  margin: 0 0.1rem;
  flex-shrink: 0;
}

.toolbar-btn.icon-only {
  padding: 0.25rem 0.45rem;
  font-size: 0.75rem;
}

.toolbar-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Snap-to-grid toggle */
.snap-toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: #94a3b8;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.snap-toggle input { cursor: pointer; accent-color: #4a9eff; }

/* Insert dropdown */
.toolbar-dropdown {
  position: relative;
}

.toolbar-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 9000;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  min-width: 140px;
  padding: 4px 0;
}

/* Align toolbar */
.align-toolbar {
  display: flex;
  align-items: center;
  gap: 0.2rem;
}

/* ── Help Manual button (📖) in toolbar ─────────────────────────────────── */

.help-manual-btn {
  font-size: 1rem;
  line-height: 1;
  padding: 0.15rem 0.35rem;
  opacity: 0.8;
  transition: opacity 0.15s;
}
.help-manual-btn:hover { opacity: 1; }

/* ── Help Modal ──────────────────────────────────────────────────────────── */

.help-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.help-modal {
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 10px;
  width: min(960px, 96vw);
  height: min(720px, 94vh);
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid #2d3748;
  flex-shrink: 0;
}

.help-title {
  font-size: 1rem;
  font-weight: 700;
  color: #e2e8f0;
}

.help-close {
  font-size: 1rem;
  color: #64748b;
}
.help-close:hover { color: #e2e8f0; }

.help-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar navigation */
.help-sidebar {
  width: 188px;
  min-width: 188px;
  border-right: 1px solid #2d3748;
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0;
  overflow-y: auto;
  flex-shrink: 0;
}

.help-nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.55rem 1.1rem;
  font-size: 0.85rem;
  color: #94a3b8;
  background: none;
  border: none;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border-left: 3px solid transparent;
}
.help-nav-item:hover { background: #0f1117; color: #cbd5e1; }
.help-nav-item.active {
  color: #4a9eff;
  background: rgba(74, 158, 255, 0.08);
  border-left-color: #4a9eff;
  font-weight: 600;
}

/* Content area */
.help-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 2rem 2rem;
  font-size: 0.875rem;
  line-height: 1.65;
  color: #cbd5e1;
}

.help-h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #2d3748;
}

.help-h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: #e2e8f0;
  margin: 1.2rem 0 0.4rem;
}

.help-lead {
  color: #94a3b8;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.help-list {
  padding-left: 1.2rem;
  margin: 0.4rem 0 0.8rem;
}
.help-list li { margin-bottom: 0.3rem; }

/* SVG diagrams */
.help-diagram {
  display: block;
  width: 100%;
  max-width: 580px;
  height: auto;
  border-radius: 8px;
  margin: 1rem 0 0.25rem;
  border: 1px solid #2d3748;
}
.help-diagram-narrow {
  max-width: 280px;
}

.help-caption {
  font-size: 0.75rem;
  color: #64748b;
  margin-bottom: 1rem;
  font-style: italic;
}

/* Getting started cards */
.help-cards {
  display: flex;
  gap: 0.75rem;
  margin: 0.75rem 0 1rem;
  flex-wrap: wrap;
}

.help-card {
  flex: 1;
  min-width: 180px;
  background: #0f1117;
  border: 1px solid #2d3748;
  border-radius: 6px;
  padding: 0.75rem 1rem;
}

.help-card-title {
  font-weight: 600;
  color: #e2e8f0;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

/* Widget reference table */
.help-widget-table {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0.75rem 0;
  border: 1px solid #2d3748;
  border-radius: 6px;
  overflow: hidden;
}

.help-widget-row {
  display: flex;
  gap: 1rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid #1e2535;
}
.help-widget-row:last-child { border-bottom: none; }
.help-widget-row:nth-child(odd) { background: #0f1117; }

.help-widget-name {
  font-weight: 600;
  color: #4a9eff;
  min-width: 120px;
  font-size: 0.82rem;
}

.help-widget-desc {
  color: #94a3b8;
  font-size: 0.82rem;
}

/* Two-column layout for signals section */
.help-two-col {
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
}
.help-two-col > div:first-child { flex: 1; }

/* Shortcut table */
.help-shortcut-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
  font-size: 0.83rem;
}

.help-shortcut-table th {
  text-align: left;
  padding: 0.4rem 0.75rem;
  background: #0f1117;
  color: #64748b;
  font-weight: 600;
  border-bottom: 1px solid #2d3748;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.help-shortcut-table td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #1e2535;
  color: #cbd5e1;
}

.help-shortcut-table tr:last-child td { border-bottom: none; }
.help-shortcut-table tr:nth-child(odd) td { background: rgba(15, 17, 23, 0.5); }

.help-kbd {
  display: inline-block;
  background: #0f1117;
  border: 1px solid #2d3748;
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-family: monospace;
  font-size: 0.8rem;
  color: #e2e8f0;
  white-space: nowrap;
}

/* Inline code */
.help-content code {
  background: #0f1117;
  border: 1px solid #2d3748;
  border-radius: 3px;
  padding: 0.1rem 0.35rem;
  font-size: 0.82rem;
  font-family: monospace;
  color: #4a9eff;
}

/* Config block */
.help-pre {
  background: #0f1117;
  border: 1px solid #2d3748;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-family: monospace;
  font-size: 0.8rem;
  color: #94a3b8;
  white-space: pre-wrap;
  margin: 0.75rem 0;
  line-height: 1.6;
}

/* kbd element in content */
kbd {
  display: inline-block;
  background: #0f1117;
  border: 1px solid #2d3748;
  border-radius: 3px;
  padding: 0 0.35rem;
  font-size: 0.8rem;
  font-family: monospace;
  color: #e2e8f0;
}

/* ── Contextual Help ─────────────────────────────────────────────────────── */

.ctx-help {
  position: relative;
  display: flex;
  align-items: center;
}

.ctx-help-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid #4a5568;
  background: #1a2236;
  color: #94a3b8;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s;
  flex-shrink: 0;
  line-height: 1;
  padding: 0;
}
.ctx-help-btn:hover { border-color: #4a9eff; color: #4a9eff; }

.ctx-help-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 400;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  width: 280px;
  padding: 0.75rem;
}

.ctx-help-tip {
  display: flex;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: #cbd5e1;
  line-height: 1.5;
  margin-bottom: 0.6rem;
}

.ctx-help-icon {
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 0.05rem;
}

.ctx-help-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid #2d3748;
  padding-top: 0.5rem;
  gap: 0.5rem;
}

.ctx-help-nav {
  font-size: 0.75rem;
  color: #64748b;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.ctx-help-nav:hover { color: #94a3b8; }

.ctx-help-link {
  font-size: 0.75rem;
  color: #4a9eff;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.ctx-help-link:hover { text-decoration: underline; }


/* ── Historical time-nav bar (below main toolbar, hidden by default) ──────── */

.time-nav-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1rem;
  background: #161b27;
  border-bottom: 1px solid #2d3748;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.time-input {
  font-size: 0.75rem;
  background: #1a2236;
  border: 1px solid #2d3748;
  color: #e2e8f0;
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
  height: 28px;
  box-sizing: border-box;
}
.time-input:focus { outline: none; border-color: #63b3ed; }
.time-input::-webkit-calendar-picker-indicator { filter: invert(0.8); }

.time-sep {
  color: #475569;
  font-size: 0.8rem;
}

/* ── Fullscreen mode ──────────────────────────────────────────────────────── */

.fs-view {
  width: 100vw;
  height: 100vh;
  overflow: auto;
  background: #0f1117;
  display: flex;
}

.fs-error {
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f87171;
  font-size: 1rem;
}

/* ── Signal drop menu (drop onto existing widget) ─────────────────────────── */

.signal-drop-backdrop {
  position: absolute;
  inset: 0;
  z-index: 9500;
}

.signal-drop-menu {
  position: fixed;
  background: #1a1f2e;
  border: 1px solid #2d3748;
  border-radius: 6px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
  min-width: 220px;
  z-index: 9600;
  overflow: hidden;
  transform: translateY(4px);
}

.signal-drop-header {
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  color: #64748b;
  border-bottom: 1px solid #2d3748;
}

.signal-drop-header strong {
  color: #94a3b8;
}

.ctx-cancel {
  color: #6b7280;
  border-top: 1px solid #2d3748;
}

/* ── Button widget: pressed / mode hint ──────────────────────────────────── */

.btn-pressed {
  background: #1e40af !important;
  border-color: #3b82f6 !important;
  color: #93c5fd !important;
}

.btn-mode-hint {
  font-size: 0.65rem;
  opacity: 0.7;
  margin-left: 0.35rem;
}

/* ── PropertiesPane: signals list + hint text ─────────────────────────────── */

.prop-signals-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  width: 100%;
}

.prop-signal-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  justify-content: space-between;
}

.prop-sig-remove {
  font-size: 0.65rem;
  opacity: 0.6;
  flex-shrink: 0;
}
.prop-sig-remove:hover { opacity: 1; color: #f87171; }

.prop-hint {
  display: block;
  font-size: 0.65rem;
  color: #475569;
  margin-top: 0.15rem;
  line-height: 1.2;
}
