/* ─── LiveFabric Hub — IBM Carbon Design System (g10 / g90) ───────────── */

/* g10 — Light */
:root, [data-carbon-theme="g10"] {
  --cds-field: #ffffff;
  --cds-layer-01: #f4f4f4;
  --cds-layer-02: #e0e0e0;
  --cds-layer-accent-01: #c6c6c6;
  --cds-background: #ffffff;
  --cds-text-primary: #161616;
  --cds-text-secondary: #525252;
  --cds-text-helper: #6f6f6f;
  --cds-text-placeholder: #a8a8a8;
  --cds-interactive: #0f62fe;
  --cds-text-on-color: #ffffff;
  --cds-support-success: #24a148;
  --cds-support-error: #da1e28;
  --cds-support-warning: #f1c21b;
  --cds-support-info: #4589ff;
  --cds-border-strong: #8d8d8d;
  --cds-border-subtle: #e0e0e0;
  --cds-header-bg: #161616;
  --cds-header-text: #f4f4f4;
  --cds-status-online: #24a148;
  --cds-status-offline: #da1e28;
  --cds-shadow-sm: 0 1px 2px rgba(0,0,0,.08);
  --cds-shadow-md: 0 2px 6px rgba(0,0,0,.12);
}

/* g90 — Dark */
[data-carbon-theme="g90"] {
  --cds-field: #262626;
  --cds-layer-01: #353535;
  --cds-layer-02: #474747;
  --cds-layer-accent-01: #525252;
  --cds-background: #262626;
  --cds-text-primary: #f4f4f4;
  --cds-text-secondary: #c6c6c6;
  --cds-text-helper: #8d8d8d;
  --cds-text-placeholder: #6f6f6f;
  --cds-interactive: #78a9ff;
  --cds-text-on-color: #161616;
  --cds-support-success: #42be65;
  --cds-support-error: #ff8389;
  --cds-support-warning: #f1c21b;
  --cds-support-info: #78a9ff;
  --cds-border-strong: #6f6f6f;
  --cds-border-subtle: #474747;
  --cds-header-bg: #161616;
  --cds-header-text: #f4f4f4;
  --cds-status-online: #42be65;
  --cds-status-offline: #ff8389;
  --cds-shadow-sm: 0 1px 2px rgba(0,0,0,.25);
  --cds-shadow-md: 0 2px 6px rgba(0,0,0,.35);
}

/* ─── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  color: var(--cds-text-primary);
  background: var(--cds-background);
}

.mono { font-family: 'IBM Plex Mono', monospace; }

/* ─── Header ────────────────────────────────────────────────────────────── */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 48px;
  background: var(--cds-header-bg);
  color: var(--cds-header-text);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  z-index: 9000;
}

.header-logo {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0.16px;
  white-space: nowrap;
}
.header-logo .accent { font-weight: 600; }

.header-status {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.header-meta {
  font-size: 12px;
  color: var(--cds-text-secondary);
}

.status-badge {
  font-size: 12px;
  padding: 2px 8px;
  font-weight: 500;
}
.status-badge.online { color: var(--cds-status-online); }
.status-badge.offline { color: var(--cds-status-offline); }

.header-actions {
  display: flex;
  align-items: center;
}

.theme-toggle {
  width: 32px; height: 32px;
  border: none;
  background: transparent;
  color: var(--cds-header-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease;
}
.theme-toggle:hover { background: rgba(255,255,255,0.08); }

/* ─── Layout ────────────────────────────────────────────────────────────── */
.hub-layout {
  display: flex;
  margin-top: 48px;
  height: calc(100vh - 48px);
}

/* ─── Sidebar ───────────────────────────────────────────────────────────── */
.node-sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--cds-layer-01);
  border-right: 1px solid var(--cds-border-subtle);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.32px;
  color: var(--cds-text-secondary);
  border-bottom: 1px solid var(--cds-border-subtle);
}

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

.node-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--cds-border-subtle);
  transition: background-color 0.15s ease;
}
.node-item:hover { background: var(--cds-layer-02); }
.node-item.selected {
  background: var(--cds-interactive);
  color: var(--cds-text-on-color);
}
.node-item.selected .node-item-id,
.node-item.selected .node-item-caps {
  color: var(--cds-text-on-color);
  opacity: 0.8;
}

.node-status-dot {
  width: 8px; height: 8px;
  flex-shrink: 0;
}
.node-status-dot.online { background: var(--cds-status-online); }
.node-status-dot.offline { background: var(--cds-status-offline); }

.node-item-info { flex: 1; min-width: 0; }
.node-item-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.node-item-id {
  font-size: 11px;
  color: var(--cds-text-secondary);
  font-family: 'IBM Plex Mono', monospace;
}
.node-item-caps {
  font-size: 10px;
  color: var(--cds-text-secondary);
  margin-top: 2px;
}

/* ─── Main Content ──────────────────────────────────────────────────────── */
.hub-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--cds-text-secondary);
  gap: 16px;
}
.empty-state p { font-size: 16px; }

/* ─── Node Detail ───────────────────────────────────────────────────────── */
.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.detail-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.detail-title h2 {
  font-size: 20px;
  font-weight: 600;
}
.detail-node-id {
  font-size: 12px;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--cds-text-secondary);
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 32px;
  padding: 0 16px;
  font-size: 14px;
  font-family: inherit;
  font-weight: 400;
  border: none;
  cursor: pointer;
  transition: background-color 0.15s ease;
  white-space: nowrap;
}
.btn-ghost {
  background: transparent;
  color: var(--cds-interactive);
  border: 1px solid var(--cds-interactive);
}
.btn-ghost:hover {
  background: var(--cds-interactive);
  color: var(--cds-text-on-color);
}
.btn-danger {
  background: var(--cds-support-error);
  color: #fff;
}
.btn-danger:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Card Grid ─────────────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

/* ─── Card ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--cds-field);
  border: 1px solid var(--cds-border-subtle);
  padding: 16px;
  box-shadow: var(--cds-shadow-sm);
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.32px;
  color: var(--cds-text-secondary);
  margin-bottom: 8px;
}

/* ─── Data Grid ─────────────────────────────────────────────────────────── */
.data-grid {
  display: flex;
  flex-direction: column;
}

.data-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px solid var(--cds-border-subtle);
}
.data-row:last-child { border-bottom: none; }

.data-label {
  font-size: 12px;
  color: var(--cds-text-secondary);
}
.data-value {
  font-size: 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 500;
  text-align: right;
}

.data-value.online { color: var(--cds-status-online); }
.data-value.offline { color: var(--cds-status-offline); }

/* ─── Signal Display ────────────────────────────────────────────────────── */
.signal-display {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 8px;
}

.signal-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 28px;
}
.signal-bars .bar {
  width: 8px;
  background: var(--cds-border-subtle);
  transition: background-color 0.3s ease;
}
.signal-bars .bar:nth-child(1) { height: 6px; }
.signal-bars .bar:nth-child(2) { height: 11px; }
.signal-bars .bar:nth-child(3) { height: 16px; }
.signal-bars .bar:nth-child(4) { height: 21px; }
.signal-bars .bar:nth-child(5) { height: 28px; }
.signal-bars .bar.active { background: var(--cds-status-online); }

.signal-label {
  font-size: 18px;
  font-weight: 600;
  line-height: 1;
}

/* ─── Connection Dot ────────────────────────────────────────────────────── */
.conn-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex-shrink: 0;
}
.conn-dot.online { background: var(--cds-status-online); }
.conn-dot.offline { background: var(--cds-status-offline); }

/* ─── IMU Hero ──────────────────────────────────────────────────────────── */
.imu-hero {
  background: var(--cds-field);
  border: 1px solid var(--cds-border-subtle);
  padding: 16px;
  box-shadow: var(--cds-shadow-sm);
}

.imu-hero-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.imu-hero-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-size: 12px;
  color: var(--cds-text-secondary);
}

.imu-instruments {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  min-height: 200px;
}

/* ─── IMU Bar Panels (Lin. Accel / Gravity) ─────────────────────────────── */
.imu-bar-panel { min-width: 72px; }
.imu-gyro-panel { min-width: 60px; }

.imu-bars-wrap {
  width: 72px;
  height: 180px;
}

.imu-bars {
  width: 100%;
  height: 100%;
}

.imu-bar-axis {
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
  fill: var(--cds-text-secondary);
}

.imu-bar-val {
  font-size: 10px;
  font-family: 'IBM Plex Mono', monospace;
  fill: var(--cds-text-secondary);
}

/* ─── IMU Gyro Arcs ─────────────────────────────────────────────────────── */
.imu-gyro-arcs {
  width: 60px;
  height: 180px;
}

.imu-gyro-svg {
  width: 100%;
  height: 100%;
}

/* ─── IMU Instrument (Compass / Attitude) ───────────────────────────────── */
.imu-instrument {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.imu-instrument-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.32px;
  color: var(--cds-text-secondary);
  margin-bottom: 4px;
  text-align: center;
}

.imu-instrument-value {
  font-size: 16px;
  font-weight: 600;
  margin-top: 2px;
}

/* ─── Compass ───────────────────────────────────────────────────────────── */
.imu-compass-wrap {
  width: 180px;
  height: 180px;
}

.imu-compass {
  width: 100%;
  height: 100%;
}

.compass-cardinal {
  font-size: 14px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  fill: var(--cds-text-secondary);
}
.compass-n { fill: var(--cds-support-error); }

.compass-degree-text {
  font-size: 10px;
  font-family: 'IBM Plex Mono', monospace;
  text-anchor: middle;
  dominant-baseline: central;
  fill: var(--cds-text-secondary);
}

/* ─── Attitude Indicator ────────────────────────────────────────────────── */
.imu-attitude-wrap {
  width: 180px;
  height: 180px;
}

.imu-attitude {
  width: 100%;
  height: 100%;
}

.imu-attitude-readouts {
  display: flex;
  gap: 16px;
  margin-top: 4px;
}

.imu-att-readout {
  display: flex;
  gap: 6px;
  align-items: baseline;
  font-size: 13px;
}

/* ─── Calibration Rings ─────────────────────────────────────────────────── */
.imu-status-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 32px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.imu-calib-grid {
  display: flex;
  gap: 12px;
}

.imu-calib-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.imu-calib-ring {
  position: relative;
  width: 36px;
  height: 36px;
}
.imu-calib-ring svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.imu-cal-arc {
  transition: stroke-dasharray 0.3s ease, stroke 0.3s ease;
}

.imu-cal-num {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
}

.imu-calib-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.32px;
  color: var(--cds-text-secondary);
}

/* ─── IMU Sensor Strip ──────────────────────────────────────────────────── */
.imu-sensor-strip {
  display: flex;
  gap: 16px;
}

.imu-sensor-strip .data-row {
  gap: 8px;
  padding: 4px 0;
  border-bottom: none;
}

/* ─── Toast ─────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 10px 16px;
  font-size: 14px;
  color: var(--cds-text-on-color);
  box-shadow: var(--cds-shadow-md);
  animation: toast-in 0.2s ease;
}
.toast.info { background: var(--cds-support-info); }
.toast.success { background: var(--cds-support-success); }
.toast.error { background: var(--cds-support-error); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .node-sidebar { width: 180px; min-width: 180px; }
  .card-grid { grid-template-columns: 1fr; }
  .detail-header { flex-direction: column; align-items: flex-start; }
  .imu-instruments { gap: 16px; }
}

@media (max-width: 480px) {
  .hub-layout { flex-direction: column; }
  .node-sidebar {
    width: 100%;
    min-width: unset;
    max-height: 30vh;
    border-right: none;
    border-bottom: 1px solid var(--cds-border-subtle);
  }
  .imu-instruments { gap: 12px; }
  .imu-compass-wrap,
  .imu-attitude-wrap { width: 140px; height: 140px; }
  .imu-status-row { gap: 16px; }
}
