:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  font-size: 16px;
  --page: #eef2f6;
  --surface: #f8fafc;
  --panel: #ffffff;
  --panel-muted: #f1f5f9;
  --border: #d8e0ea;
  --border-strong: #b8c4d2;
  --text: #172033;
  --muted: #617084;
  --muted-strong: #435064;
  --primary: #1769aa;
  --primary-strong: #0b4f86;
  --primary-soft: #e3f2fd;
  --success: #087f5b;
  --success-soft: #dff7ec;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --warning: #a15c07;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
}

[hidden] {
  display: none !important;
}

.surface {
  min-height: 100vh;
  padding: 0 0 2.5rem;
}

.top-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  width: 100%;
  min-height: 64px;
  padding: 0.75rem clamp(1rem, 4vw, 2.5rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(248, 250, 252, 0.94);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  font-weight: 700;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 34px;
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  letter-spacing: 0.04em;
  font-size: 0.86rem;
}

.brand-subtitle {
  color: var(--muted-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-id {
  margin: 0;
  max-width: 42vw;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hero,
.tabbar,
.layout {
  width: min(1280px, calc(100vw - 2rem));
  margin-left: auto;
  margin-right: auto;
}

.hero {
  margin-top: 1.25rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.45fr);
  gap: 1rem;
  align-items: stretch;
}

.hero-copy,
.hero-status,
.panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero-copy {
  padding: 1.25rem 1.35rem;
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(1.45rem, 2.6vw, 2.1rem);
  line-height: 1.1;
  letter-spacing: 0;
}

.hero-copy p {
  margin: 0.55rem 0 0;
  max-width: 72ch;
  color: var(--muted);
}

.hero-status {
  padding: 1rem;
  display: grid;
  align-content: center;
  gap: 0.55rem;
}

.vehicle-picker {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.vehicle-picker select {
  width: 100%;
  min-height: 40px;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  letter-spacing: normal;
  text-transform: none;
}

.status-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-chip {
  margin: 0;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid #b7ead7;
  background: var(--success-soft);
  color: var(--success);
  font-weight: 650;
  font-size: 0.9rem;
}

.status-chip::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  flex: 0 0 auto;
  border-radius: 50%;
  background: currentColor;
}

.status-chip.error {
  border-color: #f7b5ae;
  background: var(--danger-soft);
  color: var(--danger);
}

.tabbar {
  margin-top: 1rem;
  padding: 0.35rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-muted);
}

.tab-button {
  min-height: 42px;
  padding: 0.6rem 0.85rem;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-strong);
  box-shadow: none;
  font-weight: 700;
}

.tab-button:hover {
  background: #ffffff;
  box-shadow: none;
  transform: none;
}

.tab-button.active {
  border-color: var(--border);
  background: #ffffff;
  color: var(--primary-strong);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.layout {
  margin-top: 1rem;
  display: grid;
  gap: 1rem;
}

.panel {
  min-width: 0;
  padding: 1.1rem;
}

.panel-heading {
  margin-bottom: 1rem;
}

.panel-heading h2 {
  margin: 0;
  color: var(--text);
  font-size: 1.05rem;
  line-height: 1.2;
}

.panel-heading p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

form .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.85rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted-strong);
  font-size: 0.86rem;
  font-weight: 650;
}

label .form-note {
  margin-top: -0.1rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 500;
  line-height: 1.35;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 0.58rem 0.7rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-weight: 560;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input[type="checkbox"] {
  width: 1rem;
  min-height: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--primary);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 105, 170, 0.16);
}

.checkbox-label {
  min-height: 42px;
  padding: 0.6rem 0.7rem;
  display: grid;
  grid-template-columns: auto 1fr;
  align-content: start;
  column-gap: 0.55rem;
  row-gap: 0.2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.checkbox-label .form-note {
  grid-column: 2;
}

.form-actions {
  margin-top: 1rem;
  display: flex;
  justify-content: flex-end;
}

button {
  min-height: 42px;
  padding: 0.65rem 1.05rem;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: #ffffff;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

button:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
  box-shadow: 0 8px 18px rgba(23, 105, 170, 0.2);
  transform: translateY(-1px);
}

button:focus-visible {
  outline: 3px solid rgba(23, 105, 170, 0.22);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
  box-shadow: none;
}

.ghost-button {
  min-height: 36px;
  padding: 0.48rem 0.75rem;
  border-color: var(--border-strong);
  background: #ffffff;
  color: var(--muted-strong);
  font-size: 0.86rem;
}

.ghost-button:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.65rem;
}

.summary-grid p {
  margin: 0;
  min-height: 76px;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.summary-grid strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.control-chip {
  min-height: 34px;
  padding: 0.42rem 0.65rem;
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted-strong);
  font-size: 0.82rem;
  cursor: pointer;
}

.control-chip:hover {
  border-color: var(--primary);
  color: var(--primary-strong);
}

canvas {
  width: 100% !important;
  height: 360px !important;
  max-height: 48vh;
}

.panel-actions,
.exchange-actions {
  margin-bottom: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.log-output,
.exchange-preview {
  width: 100%;
  margin: 0;
  max-height: 260px;
  overflow: auto;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #111827;
  color: #d1d5db;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.55;
}

.exchange-count {
  color: var(--muted);
  font-size: 0.84rem;
}

.exchange-preview-wrapper {
  color: var(--muted-strong);
  font-size: 0.88rem;
}

.exchange-preview-wrapper > summary {
  margin-bottom: 0.55rem;
  cursor: pointer;
  font-weight: 700;
}

.log-output::-webkit-scrollbar,
.exchange-preview::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.log-output::-webkit-scrollbar-thumb,
.exchange-preview::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #4b5563;
}

footer {
  width: min(1280px, calc(100vw - 2rem));
  margin: 1.2rem auto 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

@media (min-width: 1000px) {
  .layout {
    grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.75fr);
    align-items: start;
  }

  .panel.telemetry,
  .panel.logs,
  .panel.exchange {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .top-nav {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .session-id {
    max-width: 100%;
  }

  .hero {
    grid-template-columns: minmax(0, 1fr);
  }

  .tabbar {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .hero,
  .tabbar,
  .layout,
  footer {
    width: min(100vw - 1rem, 1280px);
  }

  .hero-copy,
  .hero-status,
  .panel {
    padding: 0.9rem;
  }

  form .grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .form-actions {
    justify-content: stretch;
  }

  .form-actions button {
    width: 100%;
  }

  canvas {
    height: 300px !important;
  }
}
