:root {
  --bg: #0b0d10;
  --panel: #12151a;
  --panel-2: #0f1318;
  --line: #1c222b;
  --line-soft: #232a34;
  --text: #f2f5f7;
  --muted: #9aa4ae;
  --accent: #3fd0ff;
  --good: #7ed957;
  --warn: #f4c430;
  --error: #e14b4b;
  --radius: 14px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4 {
  margin: 0;
}

h4 {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: var(--space-1);
}

.subtle {
  color: var(--muted);
  margin: 4px 0 0;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) 22px;
  border-bottom: 1px solid var(--line-soft);
  background: #0f1318;
}

.app-header h1 {
  font-size: 20px;
  letter-spacing: 0.01em;
}

.toggle-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: var(--space-1);
  padding: 10px 22px;
  border-bottom: 1px solid var(--line-soft);
}

.tab-button {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  font-weight: 600;
}

.tab-button.active {
  background: rgba(63, 208, 255, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

main {
  padding: var(--space-4) 22px 28px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.panel-header.compact {
  margin-bottom: var(--space-1);
}

.controls-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.controls-row label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

select,
input {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
}

.small-btn {
  background: rgba(63, 208, 255, 0.12);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 600;
}

.small-btn:hover,
.tab-button:hover {
  border-color: var(--accent);
}

input:focus-visible,
select:focus-visible,
.small-btn:focus-visible,
.tab-button:focus-visible {
  outline: 2px solid rgba(63, 208, 255, 0.5);
  outline-offset: 2px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(180px, 1fr));
  gap: var(--space-2);
}

.device-card,
.chart-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.device-card {
  cursor: pointer;
  transition: border-color 120ms ease;
}

.device-card.active {
  border-color: var(--accent);
  background: #0f1318;
}

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-1);
  margin-bottom: 6px;
}

.title-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.title-main h3 {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #5a657b;
  border: 1px solid #7f8dab;
}

.status-dot.connected {
  background: var(--good);
  border-color: #b0f18d;
}

.metric-large {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  margin: 4px 0 8px;
}

.metric-rows,
.mini-metrics {
  display: grid;
  gap: 4px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.metric-row .k {
  color: var(--muted);
}

.metric-row .v {
  text-align: right;
  overflow-wrap: anywhere;
  max-width: 68%;
}

.mini-metrics {
  margin-top: 8px;
  border-top: 1px solid var(--line-soft);
  padding-top: 8px;
}

.badge-row {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  border: 1px solid var(--line);
  color: #cde0ff;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  line-height: 1.2;
}

.badge.warn {
  border-color: #8b6a17;
  color: #ffd985;
}

.badge.error {
  border-color: #934343;
  color: #ffb3b3;
}

.live-bottom {
  margin-top: var(--space-2);
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
}

.live-map-panel {
  margin-top: var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-height: 75vh;
}

.live-map-controls {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.live-map-controls .subtle {
  margin: 0;
}

.map-shell {
  position: relative;
  flex: 1 1 auto;
}

.live-map {
  min-height: 75vh;
}

.live-driver-overlay {
  position: absolute;
  left: 14px;
  bottom: 14px;
  width: min(380px, calc(100% - 28px));
  background: rgba(12, 16, 22, 0.9);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.overlay-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}

.overlay-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.overlay-item {
  display: grid;
  gap: 2px;
}

.overlay-item .k {
  color: var(--muted);
  font-size: 11px;
}

.overlay-item .v {
  font-size: 13px;
  font-weight: 600;
}

.live-tools {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.live-tools summary {
  cursor: pointer;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text);
  list-style: none;
}

.live-tools summary::-webkit-details-marker {
  display: none;
}

.live-tools[open] summary {
  border-bottom: 1px solid var(--line-soft);
}

.live-tools .operator-panel {
  padding: 10px;
}

.chart-stack {
  display: grid;
  gap: 8px;
}

.chart-block {
  display: grid;
  gap: 4px;
}

.live-map {
  width: 100%;
  height: 100%;
  min-height: 75vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #0f1318;
}

.map-driver-marker {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid #0f1318;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(63, 208, 255, 0.25);
  cursor: pointer;
}

.map-driver-marker.active {
  background: var(--good);
  box-shadow: 0 0 0 3px rgba(126, 217, 87, 0.3);
}

.map-driver-marker.disconnected {
  background: #7a8394;
  box-shadow: 0 0 0 2px rgba(122, 131, 148, 0.24);
}

canvas {
  width: 100%;
  background: #0f1318;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
}

.operator-panel,
.inspect-main {
  display: grid;
  gap: var(--space-2);
  align-content: start;
}

.dense {
  padding: 10px;
}

.settings-json,
.timeline {
  margin: 8px 0 0;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 10px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 12px;
}

.url-grid,
.settings-tools {
  display: grid;
  gap: 8px;
}

.url-row {
  display: grid;
  gap: 6px;
}

.url-row label,
.stack-label {
  font-size: 12px;
  color: var(--muted);
}

.url-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.inspect-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: var(--space-2);
}

.inspect-sidebar {
  align-self: start;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: auto;
  background: var(--panel);
}

.session-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 740px;
}

.session-table th,
.session-table td {
  border-bottom: 1px solid var(--line-soft);
  padding: 9px 10px;
  text-align: left;
  font-size: 12px;
}

.session-table th {
  color: var(--muted);
  font-weight: 600;
  background: #0f1318;
}

.session-table tr:last-child td {
  border-bottom: 0;
}

.status-pill {
  display: inline-block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  color: var(--muted);
}

a {
  color: var(--accent);
}

@media (max-width: 1600px) {
  .card-grid {
    grid-template-columns: repeat(4, minmax(180px, 1fr));
  }
}

@media (max-width: 1280px) {
  .card-grid {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
  }

  .inspect-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 920px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .card-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  main {
    padding-inline: 14px;
  }

  .tabs {
    padding-inline: 14px;
  }
}

@media (max-width: 640px) {
  .card-grid {
    grid-template-columns: 1fr;
  }

  .overlay-grid {
    grid-template-columns: 1fr 1fr;
  }
}