:root {
  --bg: #090b0d;
  --panel: rgba(12, 14, 17, 0.84);
  --panel-strong: rgba(14, 16, 19, 0.96);
  --border: rgba(255, 245, 230, 0.1);
  --text: #f4ede2;
  --muted: #b1a79a;
  --accent: #ef5b24;
  --accent-soft: rgba(239, 91, 36, 0.16);
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.38);
  --radius: 18px;
  --sidebar-width: 360px;
  --chart-height: 300px;
  --grid: rgba(255, 245, 230, 0.08);
  --surface: rgba(255, 255, 255, 0.04);
  --font-display: "Iowan Old Style", "Palatino Linotype", "URW Palladio L", serif;
  --font-body: "Avenir Next", "Helvetica Neue", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color-scheme: dark;
  background:
    radial-gradient(ellipse at 0% 18%, rgba(62, 116, 201, 0.28), transparent 20%),
    radial-gradient(ellipse at 10% 16%, rgba(109, 166, 255, 0.14), transparent 13%),
    linear-gradient(90deg, #17345d 0%, #0c1830 24%, #090b0d 52%, #090b0d 100%);
  color: var(--text);
  font-family: var(--font-body);
}

body {
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, var(--sidebar-width)) minmax(0, 1fr);
  gap: 12px;
  min-height: 100vh;
  padding: 22px;
  position: relative;
  transition: grid-template-columns 180ms ease, gap 180ms ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
  gap: 0;
}

.sidebar,
.workspace {
  min-width: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 9px;
  transition: opacity 180ms ease, transform 180ms ease;
}

.app-shell.sidebar-collapsed .sidebar {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-16px);
  overflow: hidden;
}

.brand,
.panel,
.workspace {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand {
  padding: 24px;
  background:
    linear-gradient(145deg, rgba(62, 116, 201, 0.2), transparent 54%),
    radial-gradient(circle at top right, rgba(109, 166, 255, 0.12), transparent 32%),
    var(--panel-strong);
}

.brand h1,
.workspace-header h2,
.empty-message h3 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.03em;
}

.brand h1 {
  font-size: 2.05rem;
  line-height: 0.94;
}

.lede {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel {
  padding: 18px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-header h2 {
  margin-bottom: 0;
}

.panel-note {
  font-size: 0.78rem;
}

.legal-panel .panel-note {
  margin: 0 0 10px;
}

.legal-links {
  display: grid;
  gap: 8px;
}

.legal-links a {
  color: var(--text);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 8px;
}

.legal-links a:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.legal-links a:hover {
  color: var(--accent);
}

.file-picker,
.stacked-label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-picker span,
.stacked-label span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.file-picker input,
.stacked-label input,
.stacked-label select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 12px 14px;
}

.file-picker input::placeholder,
.stacked-label input::placeholder {
  color: rgba(244, 237, 226, 0.42);
}

.secondary-button,
.primary-button,
.text-button,
.channel-button,
.chip-button,
.remove-button {
  border: 0;
  cursor: pointer;
}

.secondary-button,
.primary-button,
.chip-button {
  min-height: 42px;
  border-radius: 999px;
  padding: 0 16px;
  font-weight: 700;
}

.chip-button {
  min-height: 32px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.chip-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.secondary-button {
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.primary-button {
  background: var(--accent);
  color: white;
}

.text-button {
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}

.secondary-button:hover,
.primary-button:hover,
.text-button:hover,
.chip-button:hover:not(:disabled) {
  filter: brightness(1.08);
}

.muted {
  color: var(--muted);
}

.status-line {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.92rem;
}

.status-line.idle {
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

.status-line.loading {
  background: rgba(239, 91, 36, 0.14);
  color: var(--accent);
}

.status-line.ready {
  background: rgba(63, 166, 112, 0.16);
  color: #81d8a4;
}

.status-line.error {
  background: rgba(201, 67, 67, 0.18);
  color: #ff9999;
}

.metadata-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.metadata-list div {
  display: grid;
  gap: 2px;
}

.metadata-list dt {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metadata-list dd {
  margin: 0;
  line-height: 1.35;
}

.track-dock {
  position: fixed;
  left: 22px;
  bottom: 22px;
  z-index: 9;
  width: min(var(--sidebar-width), calc(100vw - 44px));
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(12, 14, 17, 0.94);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(16px);
}

.track-dock.hidden {
  display: none;
}

.track-dock.collapsed {
  width: 52px;
  height: 52px;
  padding: 0;
  place-items: center;
}

.track-dock-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.track-dock-header h2 {
  margin: 0;
  font-size: 0.96rem;
}

.track-dock-header-info {
  display: grid;
  gap: 4px;
}

.track-dock-toggle {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  font-size: 0.95rem;
  line-height: 1;
}

.track-dock.collapsed .track-dock-header {
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
}

.track-dock.collapsed .track-dock-header-info,
.track-dock.collapsed .track-map,
.track-dock.collapsed .track-dock-lap-select {
  display: none;
}

.track-map {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  border-radius: 18px;
  border: 1px solid var(--border);
  background:
    radial-gradient(circle at top, rgba(239, 91, 36, 0.08), transparent 48%),
    rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.track-dock-lap-select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 10px 12px;
}

.track-map-svg {
  width: 100%;
  height: 100%;
}

.track-map-path {
  fill: none;
  stroke: rgba(244, 237, 226, 0.72);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.track-map-start {
  fill: #35b8c8;
}

.track-map-marker {
  fill: var(--accent);
  stroke: rgba(9, 11, 13, 0.92);
  stroke-width: 2;
}

.channel-results {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 38vh;
  overflow: auto;
}

.channel-results.empty {
  border: 1px dashed var(--border);
  border-radius: 14px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.03);
}

.channel-button {
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.channel-button:hover {
  border-color: rgba(239, 91, 36, 0.32);
  background: rgba(255, 255, 255, 0.07);
}

.channel-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.channel-button strong {
  font-size: 1.4rem;
}

.channel-button span {
  color: var(--muted);
  font-size: 0.82rem;
}

.workspace {
  display: flex;
  flex-direction: column;
  padding: 14px 8px 10px;
  overflow: hidden;
}

.workspace-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.workspace-header h2 {
  font-size: 2rem;
}

.workspace-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 8px;
}

.zoom-dock {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 9;
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(12, 14, 17, 0.94);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(16px);
}

.zoom-dock.hidden {
  display: none;
}

.zoom-dock-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.zoom-dock-title {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.zoom-dock-toggle {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  font-size: 0.9rem;
  line-height: 1;
}

.zoom-dock-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-chip {
  min-width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 1.25rem;
}

.zoom-reset-chip {
  min-height: 38px;
  padding: 0 14px;
  font-size: 0.92rem;
}

.zoom-dock.collapsed {
  width: 48px;
  height: 48px;
  padding: 0;
  place-items: center;
}

.zoom-dock.collapsed .zoom-dock-title,
.zoom-dock.collapsed .zoom-dock-controls {
  display: none;
}

.zoom-dock.collapsed .zoom-dock-header {
  width: 100%;
  height: 100%;
  justify-content: center;
}

.workspace-meta-label {
  color: var(--muted);
}

.workspace-meta-value {
  display: inline-block;
  min-width: 6.8ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.sidebar-toggle-button {
  position: absolute;
  top: 46px;
  left: calc(22px + var(--sidebar-width) - 25px);
  z-index: 5;
  border: 1px solid rgba(255, 245, 230, 0.12);
  border-radius: 999px;
  background: rgba(17, 19, 23, 0.98);
  color: var(--text);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(14px);
  width: 48px;
  height: 48px;
  padding: 0;
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.08em;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    left 180ms ease,
    right 180ms ease,
    background 180ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
}

.sidebar-toggle-button:hover {
  background: rgba(24, 27, 32, 1);
  transform: scale(1.06);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.42);
}

.app-shell.sidebar-collapsed .sidebar-toggle-button {
  left: 22px;
  background: rgba(20, 23, 27, 0.98);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.42);
}

.chart-stack {
  display: grid;
  gap: 8px;
  min-height: 320px;
  padding-top: 10px;
  overflow: auto;
}

.chart-stack.empty-state {
  place-items: center;
}

.empty-message {
  width: min(520px, 100%);
  padding: 26px;
  border-radius: 22px;
  border: 1px dashed var(--border);
  background: rgba(255, 255, 255, 0.03);
  text-align: center;
}

.empty-message p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.chart-card {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(11, 13, 16, 0.84);
  overflow: hidden;
}

.chart-title-block {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.chart-title-block h3 {
  margin: 0;
  font-size: 0.96rem;
}

.chart-title-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.chart-unit,
.chart-meta-detail {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.chart-meta-detail::before {
  content: "\2022";
  margin-right: 8px;
  color: rgba(255, 245, 230, 0.28);
}

.chart-card-controls {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.chart-order-button,
.remove-button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  line-height: 1;
}

.chart-order-button {
  font-size: 0.86rem;
  font-weight: 800;
}

.remove-button {
  font-size: 1.1rem;
}

.chart-order-button:disabled {
  opacity: 0.32;
  cursor: default;
}

.chart-order-button:not(:disabled):hover,
.remove-button:hover {
  background: rgba(255, 255, 255, 0.14);
}

.remove-button,
.chart-order-button {
  line-height: 1;
}

.chart-card-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(178px, 16vw, 196px);
  gap: 0;
  min-height: var(--chart-height);
  align-items: stretch;
}

.chart-frame {
  position: relative;
  min-width: 0;
  min-height: var(--chart-height);
  height: 100%;
  padding: 2px 0 0 1px;
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.chart-side-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border-left: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(239, 91, 36, 0.06), transparent 18%),
    rgba(255, 255, 255, 0.025);
}

.pinned-marker {
  position: absolute;
  width: 0;
  border-left: 1px dashed rgba(128, 198, 255, 0.78);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}

.pinned-marker.visible {
  opacity: 1;
}

.chart-values {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-height: 0;
}

.value-chip {
  appearance: none;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.07);
  width: 100%;
  text-align: left;
  color: inherit;
  font: inherit;
}

button.value-chip {
  cursor: pointer;
}

button.value-chip:hover {
  background: rgba(255, 255, 255, 0.065);
}

button.value-chip.series-hidden {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.05);
}

.value-chip.series-hidden .value-chip-label {
  color: #8a8d92;
}

.value-chip-label {
  color: var(--muted);
  font-size: 0.84rem;
}

.value-chip-number {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: right;
}

.uplot {
  font-family: var(--font-body);
}

.u-title,
.u-legend {
  display: none;
}

.uplot .u-axis {
  color: #d6cec2;
}

.uplot text {
  fill: #d6cec2;
}

.uplot .u-grid line {
  stroke: var(--grid);
}

.uplot .u-axis line,
.uplot .u-series path {
  stroke-opacity: 1;
}

.uplot .u-select {
  background: rgba(239, 91, 36, 0.12);
  border: 1px solid rgba(239, 91, 36, 0.35);
}

.uplot .u-over {
  cursor: crosshair;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    order: 2;
  }

  .workspace {
    order: 1;
  }

  .app-shell.sidebar-collapsed .sidebar {
    max-height: 0;
    margin: 0;
    gap: 0;
    opacity: 0;
    transform: translateY(0);
  }

  .sidebar-toggle-button {
    top: 18px;
    left: auto;
    right: 18px;
  }

  .app-shell.sidebar-collapsed .sidebar-toggle-button {
    left: auto;
    right: 18px;
  }

  .track-dock {
    left: 18px;
    bottom: 18px;
    width: 216px;
  }

  .zoom-dock {
    right: 18px;
    bottom: 18px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px;
    gap: 14px;
  }

  .workspace-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .workspace-meta {
    width: 100%;
    justify-content: space-between;
  }

  .chart-card-body {
    grid-template-columns: 1fr;
  }

  .chart-values {
    border-left: 0;
    border-top: 1px solid var(--border);
  }

  .track-dock {
    left: 14px;
    bottom: 14px;
    width: 172px;
  }

  .zoom-dock {
    right: 14px;
    bottom: 14px;
  }
}
