:root {
  --bg-1: #07111f;
  --bg-2: #10263f;
  --bg-3: #173a5f;
  --panel: rgba(9, 22, 38, 0.86);
  --panel-border: rgba(180, 225, 255, 0.14);
  --text: #eff8ff;
  --muted: #95afc8;
  --brand: #22d3ee;
  --brand-2: #f59e0b;
  --ok: #10b981;
  --stale: #94a3b8;
  --danger: #ef4444;
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font-family: "Manrope", "Space Grotesk", sans-serif;
  background: radial-gradient(circle at 10% 20%, var(--bg-3) 0%, var(--bg-1) 45%, #020712 100%);
}

code {
  font-family: "Space Grotesk", monospace;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 6px;
}

.app-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 85% 15%, rgba(34, 211, 238, 0.18), transparent 25%),
    radial-gradient(circle at 8% 80%, rgba(245, 158, 11, 0.17), transparent 35%);
}

.hidden {
  display: none !important;
}

.eyebrow {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  letter-spacing: 0.15em;
  font-size: 0.72rem;
  color: var(--brand);
  text-transform: uppercase;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(520px, 100%);
  background: linear-gradient(160deg, rgba(7, 25, 43, 0.93), rgba(6, 15, 26, 0.93));
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 28px;
  backdrop-filter: blur(10px);
  box-shadow: 0 25px 55px rgba(0, 0, 0, 0.45);
}

.login-card h1 {
  margin: 12px 0 22px;
  font-family: "Space Grotesk", sans-serif;
}

.stack {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.86rem;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.17);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 11px;
  font: inherit;
}

textarea {
  resize: vertical;
}

.password-input-wrap {
  position: relative;
}

.password-input-wrap input {
  padding-right: 42px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 8px;
  color: #c5dff7;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.password-toggle:hover {
  background: rgba(255, 255, 255, 0.12);
}

.password-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.22);
}

.password-toggle svg {
  width: 18px;
  height: 18px;
}

.password-toggle .icon-eye-off {
  display: none;
}

.password-toggle.is-visible .icon-eye {
  display: none;
}

.password-toggle.is-visible .icon-eye-off {
  display: block;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.2);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font: 700 0.88rem "Space Grotesk", sans-serif;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  color: #031926;
  background: linear-gradient(95deg, var(--brand), #67e8f9);
}

.btn-secondary {
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.2);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.5);
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 14px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px 1fr;
}

.sidebar {
  border-right: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(9, 24, 42, 0.95), rgba(3, 9, 18, 0.92));
  padding: 22px 16px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
}

.brand h2 {
  margin: 3px 0 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.65rem;
}

.nav {
  display: grid;
  gap: 8px;
  align-content: start;
  grid-auto-rows: min-content;
}

.nav-item {
  text-align: left;
  color: var(--text);
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 12px;
  padding: 9px 11px;
  font: 600 0.9rem "Manrope", sans-serif;
  line-height: 1.2;
  cursor: pointer;
}

.nav-item.active {
  border-color: rgba(34, 211, 238, 0.42);
  background: rgba(34, 211, 238, 0.14);
}

.session-box {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.session-box p {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.84rem;
}

.content {
  padding: 16px 18px 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.topbar h1 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.42rem;
}

.topbar-right {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.78rem;
  color: var(--muted);
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
}

.badge-ok {
  color: #bbf7d0;
  border-color: rgba(16, 185, 129, 0.6);
  background: rgba(16, 185, 129, 0.15);
}

.badge-error {
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.6);
  background: rgba(239, 68, 68, 0.14);
}

.section {
  display: none;
  gap: 14px;
}

.section.active {
  display: grid;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.25);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.panel-head h3 {
  margin: 0;
  font-size: 1rem;
  font-family: "Space Grotesk", sans-serif;
}

.panel-note {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.84rem;
}

.inline-controls {
  display: flex;
  gap: 8px;
  align-items: end;
}

.inline-controls.wrap {
  flex-wrap: wrap;
}

.inline-controls label {
  min-width: 135px;
}

.live-controls {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) minmax(90px, 110px) minmax(170px, 0.9fr) minmax(240px, 1.2fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.live-controls label {
  min-width: 0;
}

.live-control {
  display: grid;
  gap: 6px;
}

.live-stale-field {
  width: 100%;
  max-width: 110px;
}

.live-stale-field input {
  width: 100%;
  min-width: 0;
}

.live-control-title {
  color: var(--muted);
  font-size: 0.86rem;
}

.live-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  grid-column: span 2;
}

.live-actions {
  display: flex;
  justify-content: flex-end;
}

.live-route-users {
  grid-column: 1 / -1;
}

.live-route-users-list {
  min-height: 54px;
  max-height: 188px;
  overflow: auto;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  padding: 7px;
  display: grid;
  gap: 6px;
}

.live-route-users-list.is-disabled {
  opacity: 0.62;
}

.live-route-user-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9px;
  padding: 6px 8px;
  background: rgba(255, 255, 255, 0.03);
}

.live-route-user-row.is-selected {
  border-color: rgba(34, 211, 238, 0.45);
  background: rgba(34, 211, 238, 0.12);
}

.live-route-user-row input[type="checkbox"] {
  width: auto;
}

.live-route-user-main {
  min-width: 0;
}

.live-route-user-name {
  margin: 0;
  color: #e3f3ff;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-route-user-meta {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-route-focus {
  padding: 6px 9px;
  font-size: 0.74rem;
}

.live-route-users-empty {
  color: var(--muted);
  font-size: 0.82rem;
  padding: 8px;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox input {
  width: auto;
}

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

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.chart-card {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  padding: 10px;
  min-height: 260px;
}

.chart-title {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.82rem;
}

.chart-card canvas {
  width: 100% !important;
  height: 220px !important;
}

.metric-card {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.metric-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: 1.38rem;
  font-family: "Space Grotesk", sans-serif;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding: 9px 7px;
  text-align: left;
  font-size: 0.84rem;
}

th {
  color: #b8d7f0;
  font-family: "Space Grotesk", sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.73rem;
}

tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

#workoutsTbody tr {
  cursor: pointer;
}

#workoutsTbody tr button {
  cursor: pointer;
}

.muted {
  color: var(--muted);
  font-size: 0.83rem;
}

.map {
  height: 420px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
}

.map-small {
  margin-top: 10px;
  height: 320px;
}

.map-shell {
  position: relative;
}

.map-fullscreen-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1100;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  color: #f8fcff;
  background: rgba(3, 13, 25, 0.86);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(7px);
}

.map-fullscreen-btn:hover {
  border-color: rgba(34, 211, 238, 0.9);
  background: rgba(8, 28, 48, 0.94);
}

.map-fullscreen-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.4), 0 8px 22px rgba(0, 0, 0, 0.42);
}

.map-fullscreen-btn svg {
  width: 18px;
  height: 18px;
}

.map-fullscreen-btn .icon-exit {
  display: none;
}

.map-fullscreen-btn.is-open .icon-enter {
  display: none;
}

.map-fullscreen-btn.is-open .icon-exit {
  display: block;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.map-shell:fullscreen {
  background: #031120;
  padding: 8px;
}

.map-shell:fullscreen .map {
  width: 100%;
  height: calc(100vh - 16px) !important;
  border-radius: 8px;
}

.map-shell:-webkit-full-screen {
  background: #031120;
  padding: 8px;
}

.map-shell:-webkit-full-screen .map {
  width: 100%;
  height: calc(100vh - 16px) !important;
  border-radius: 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.chips span {
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.78rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.03);
}

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.config-col {
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 10px;
}

.config-col h4 {
  margin: 0 0 10px;
  font-family: "Space Grotesk", sans-serif;
}

.full-row {
  grid-column: 1 / -1;
}

.status-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

.status-active {
  color: #bbf7d0;
  background: rgba(16, 185, 129, 0.2);
}

.status-stale {
  color: #e2e8f0;
  background: rgba(148, 163, 184, 0.22);
}

.toast {
  position: fixed;
  right: 14px;
  bottom: 14px;
  max-width: 420px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(3, 17, 31, 0.96);
  border: 1px solid var(--panel-border);
  color: var(--text);
  z-index: 1200;
}

.mono-cell {
  font-family: "Space Grotesk", monospace;
  font-size: 0.74rem;
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar-cell {
  width: 54px;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  background: rgba(255, 255, 255, 0.06);
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.user-avatar-fallback {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.7rem;
  color: #d7edff;
  background: linear-gradient(145deg, #224f7e, #19314f);
}

@media (max-width: 1040px) {
  .live-controls {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
  }

  .live-toggles {
    grid-column: span 2;
  }

  .live-actions {
    justify-content: flex-start;
  }

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

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--panel-border);
  }

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

@media (max-width: 760px) {
  .content {
    padding: 12px;
  }

  .panel {
    padding: 11px;
  }

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

  .nav {
    grid-template-columns: 1fr;
  }

  .live-controls {
    grid-template-columns: 1fr;
  }

  .live-toggles {
    grid-column: auto;
  }

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

  .live-actions .btn {
    width: 100%;
  }
}
