:root {
  --bg: #090e16;
  --panel: #0f1725;
  --panel-2: #131e2f;
  --line: #1f2c42;
  --text: #e8eef8;
  --muted: #8695ab;
  --accent: #c9ff4d;
  --live: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 18px 48px rgba(0, 0, 0, .38);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

code, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------------------------------------------------------------- Topbar */

.topbar {
  position: relative;
  z-index: 1000;
  height: 66px;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 22px;
  background: rgba(9, 14, 22, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -.4px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand em { font-style: normal; color: var(--accent); }
.brand-mark {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(201, 255, 77, .13), 0 0 18px rgba(201, 255, 77, .55);
}

.race {
  min-width: 0;
  flex: 1;
  border-left: 1px solid var(--line);
  padding-left: 22px;
}
.race-name {
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.race-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: rgba(255, 255, 255, .02);
}
.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}
.conn[data-state="live"] { color: var(--live); border-color: rgba(74, 222, 128, .3); }
.conn[data-state="live"] .conn-dot {
  background: var(--live);
  box-shadow: 0 0 0 4px rgba(74, 222, 128, .14);
  animation: pulse 2s infinite;
}
.conn[data-state="poll"] { color: #7dd3fc; border-color: rgba(125, 211, 252, .3); }
.conn[data-state="poll"] .conn-dot { background: #7dd3fc; }
.conn[data-state="reconnect"] { color: var(--warn); border-color: rgba(251, 191, 36, .3); }
.conn[data-state="reconnect"] .conn-dot { background: var(--warn); }

.lang-select {
  appearance: none;
  padding: 7px 26px 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 13px) 52% / 4px 4px no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 9px) 52% / 4px 4px no-repeat,
    rgba(255, 255, 255, .02);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}
.lang-select:hover, .lang-select:focus { color: var(--text); border-color: #304563; }
.lang-select option { background: var(--panel); color: var(--text); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .35; }
}

/* ---------------------------------------------------------------- Layout */

main {
  height: calc(100dvh - 66px);
  display: grid;
  grid-template-columns: 382px minmax(0, 1fr);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 12px;
}
.sidebar-head h1 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .9px;
  text-transform: uppercase;
  color: var(--muted);
}
.count {
  min-width: 26px;
  height: 24px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.runner-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: #2a3a55 transparent;
}
.runner-list::-webkit-scrollbar { width: 8px; }
.runner-list::-webkit-scrollbar-thumb { background: #2a3a55; border-radius: 8px; }

.runner {
  --c: var(--accent);
  position: relative;
  padding: 13px 14px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .18s;
}
.runner:hover {
  border-color: #2b3d59;
  background: #162236;
  transform: translateY(-1px);
}
.runner.selected {
  border-color: var(--c);
  background: #172235;
  box-shadow: inset 0 0 0 1px var(--c), 0 8px 28px rgba(0, 0, 0, .25);
}
.runner.waiting { opacity: .78; }

.r-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
}
.r-dot {
  width: 10px;
  height: 10px;
  flex: none;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 12px var(--c);
}
.r-name {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.r-badge {
  flex: none;
  padding: 3px 7px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(134, 149, 171, .12);
}
.r-badge[data-state="live"] { color: var(--live); background: rgba(74, 222, 128, .12); }
.r-badge[data-state="stale"] { color: var(--warn); background: rgba(251, 191, 36, .12); }
.r-badge[data-state="offline"] { color: #94a3b8; background: rgba(148, 163, 184, .1); }
.r-badge[data-state="waiting"] { color: #64748b; background: rgba(100, 116, 139, .1); }

.r-progress {
  height: 4px;
  border-radius: 4px;
  background: #223047;
  overflow: hidden;
  margin-bottom: 12px;
}
.r-progress i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: var(--c);
  box-shadow: 0 0 12px var(--c);
  transition: width .6s ease;
}

.r-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.r-stats div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.r-stats b {
  font-size: 16px;
  font-weight: 750;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.r-stats span {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.r-meta {
  font-size: 11.5px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 9px;
  font-variant-numeric: tabular-nums;
  min-height: 15px;
}
.r-meta .warn { color: var(--warn); }

.empty {
  margin: 8px 18px;
  padding: 26px 20px;
  border: 1px dashed #2a3a55;
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  line-height: 1.55;
}
.empty p { margin: 0 0 8px; }
.empty p:last-child { margin-bottom: 0; }
.empty strong { color: var(--text); }
.empty-icon { font-size: 26px; color: #3b4f70; margin-bottom: 6px; }
.empty[hidden] { display: none; }

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- Karte */

.map-wrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #0b1320; }

.leaflet-container { font-family: inherit; }
.leaflet-control-attribution {
  background: rgba(9, 14, 22, .78) !important;
  color: #75849a !important;
  font-size: 10px !important;
  padding: 2px 6px !important;
}
.leaflet-control-attribution a { color: #9fb0c8 !important; }
.leaflet-bar a {
  background: #121d2e !important;
  color: var(--text) !important;
  border-color: var(--line) !important;
}
.leaflet-bar a:hover { background: #1a2940 !important; }

.leaflet-tooltip {
  background: rgba(11, 18, 30, .94);
  border: 1px solid #2b3d59;
  color: var(--text);
  border-radius: 7px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  font-size: 12px;
  padding: 4px 8px;
}
.leaflet-tooltip-top:before { border-top-color: #2b3d59; }

.follow-chip {
  position: absolute;
  z-index: 800;
  left: 18px;
  bottom: 18px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid rgba(201, 255, 77, .3);
  background: rgba(13, 21, 34, .92);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.follow-chip[hidden] { display: none; }
.follow-chip b { color: var(--accent); }
.follow-x { color: var(--muted); margin-left: 2px; }
.follow-chip:hover .follow-x { color: var(--text); }
.pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(201, 255, 77, .45);
  animation: ring 2s infinite;
}
@keyframes ring {
  0% { box-shadow: 0 0 0 0 rgba(201, 255, 77, .45); }
  70% { box-shadow: 0 0 0 9px rgba(201, 255, 77, 0); }
  100% { box-shadow: 0 0 0 0 rgba(201, 255, 77, 0); }
}

.map-hint {
  position: absolute;
  z-index: 700;
  right: 14px;
  bottom: 28px;
  padding: 5px 9px;
  border-radius: 7px;
  background: rgba(9, 14, 22, .72);
  color: #8090a6;
  font-size: 10.5px;
  pointer-events: none;
  transition: opacity .4s;
}
.map-hint[hidden] { display: none; }

/* Marker */

.runner-icon { position: relative; }
.runner-dot {
  position: absolute;
  left: -9px;
  top: -9px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid #0a0f18;
  box-shadow: 0 0 0 2px currentColor, 0 0 20px currentColor;
}
.runner-label {
  position: absolute;
  left: 13px;
  top: -14px;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, .13);
  background: rgba(9, 14, 22, .9);
  color: var(--text);
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}

.endpoint { position: relative; }
.ep-dot {
  position: absolute;
  left: -5px;
  top: -5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #dfe7f2;
  border: 2px solid #0a0f18;
  box-shadow: 0 0 0 2px rgba(223, 231, 242, .5);
}
.ep-dot.finish { background: var(--accent); box-shadow: 0 0 0 2px rgba(201, 255, 77, .5); }
.ep-label {
  position: absolute;
  left: 10px;
  top: -11px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(9, 14, 22, .88);
  border: 1px solid #2b3d59;
  color: #cbd5e1;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- Admin */

.admin-body { overflow: auto; background: var(--bg); }

.admin-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(9, 14, 22, .93);
  backdrop-filter: blur(12px);
}
.admin-top .spacer { flex: 1; }
.admin-top a.back { color: var(--muted); font-size: 13px; }
.admin-top a.back:hover { color: var(--text); }

.notice {
  margin: 0;
  padding: 12px 16px;
  border: 1px solid rgba(251, 191, 36, .35);
  border-radius: var(--radius);
  background: rgba(251, 191, 36, .08);
  color: #fde68a;
  font-size: 13px;
  line-height: 1.55;
}
.notice[hidden] { display: none; }
.notice code {
  color: #fef3c7;
  background: rgba(0, 0, 0, .25);
  padding: 1px 5px;
  border-radius: 4px;
}

.admin-wrap {
  max-width: 1020px;
  margin: 0 auto;
  padding: 28px 22px 70px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 18px 20px 0;
}
.panel-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 750;
  letter-spacing: .7px;
  text-transform: uppercase;
}
.panel-head p { margin: 0; color: var(--muted); font-size: 12px; }
.panel-body { padding: 16px 20px 20px; }

.token-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.token-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #0b1320;
  outline: none;
}
.token-row input:focus { border-color: #3b5175; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #1a2940; border-color: #304563; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #101905;
}
.btn.primary:hover { background: #d8ff72; border-color: #d8ff72; }
.btn.danger { color: #fca5a5; border-color: rgba(248, 113, 113, .25); }
.btn.danger:hover { background: rgba(248, 113, 113, .1); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
}
.field input[type="text"], .field input[type="file"], .field input[type="color"] {
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #0b1320;
  outline: none;
  min-width: 0;
}
.field input[type="text"]:focus { border-color: #3b5175; }
.field input[type="color"] {
  width: 46px;
  height: 40px;
  padding: 4px;
  cursor: pointer;
}

.route-current {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  padding: 12px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0c1421;
  font-size: 13px;
}
.route-current .name { font-weight: 650; }
.route-current .meta { color: var(--muted); font-variant-numeric: tabular-nums; }

.runner-admin-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.runner-admin {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #0c1421;
}
.runner-admin .top { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.runner-admin .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.runner-admin .name { font-weight: 650; }
.runner-admin .sub { color: var(--muted); font-size: 11.5px; margin-left: auto; white-space: nowrap; }
.runner-admin .url-row { display: flex; align-items: center; gap: 7px; margin-top: 5px; }
.runner-admin code {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  color: #9fb0c8;
  background: #080e17;
  border: 1px solid #1c2a40;
  border-radius: 6px;
  padding: 4px 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.runner-admin .actions { display: flex; align-items: center; gap: 6px; }

.hint { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 10px 0 0; }
.hint code { color: #b9c7dc; background: #0b1320; padding: 1px 5px; border-radius: 4px; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  z-index: 100;
  padding: 11px 16px;
  border-radius: 10px;
  background: #142136;
  border: 1px solid #2b3d59;
  box-shadow: var(--shadow);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 30px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(248, 113, 113, .45); color: #fecaca; }
.toast.ok { border-color: rgba(74, 222, 128, .35); }

/* ---------------------------------------------------------------- Mobil */

@media (max-width: 900px) {
  body { overflow: auto; }
  .topbar {
    height: auto;
    min-height: 62px;
    flex-wrap: wrap;
    gap: 8px 14px;
    padding: 10px 14px;
  }
  .brand { font-size: 17px; }
  .race {
    order: 3;
    flex-basis: 100%;
    border-left: 0;
    padding-left: 0;
  }
  .race-meta { margin-top: 1px; }
  .conn { margin-left: auto; }
  .lang-select { padding-top: 6px; padding-bottom: 6px; }
  main {
    height: auto;
    grid-template-columns: 1fr;
    grid-template-rows: 54dvh auto;
  }
  .sidebar { order: 2; border-right: 0; border-top: 1px solid var(--line); }
  .runner-list { overflow: visible; }
  .map-wrap { order: 1; min-height: 54dvh; }
  .map-hint { display: none; }
  .follow-chip { bottom: 14px; left: 14px; }
  .sidebar-foot { position: sticky; bottom: 0; background: var(--panel); }
  .admin-top { flex-wrap: wrap; gap: 10px 14px; padding: 12px 14px; }
  .admin-top .spacer { display: none; }
  .admin-top a.back { margin-left: auto; }
  .admin-wrap { padding: 18px 14px 60px; }
  .form-grid { grid-template-columns: 1fr; }
  .runner-admin { grid-template-columns: 1fr; }
  .runner-admin .actions { justify-content: flex-end; }
}
