:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-hover: #334155;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent-dark: #059669;
  --gain: #34d399;
  --loss: #f87171;
  --live: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand .logo {
  font-size: 28px;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.badge-live {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  border: 1px solid var(--live);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  animation: pulseLive 1.6s infinite;
}

@keyframes pulseLive {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.auto-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  flex: 1;
  min-height: 0;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 61px);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  margin: 0;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.hike-list {
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hike-item {
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.hike-item:hover {
  background: var(--panel-hover);
}

.hike-item.active {
  border-color: var(--accent);
  background: rgba(16, 185, 129, 0.12);
}

.hike-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.hike-item-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hike-item-status {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 99px;
  font-weight: 700;
  flex-shrink: 0;
}

.hike-item-status.live {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.hike-item-status.done {
  background: rgba(148, 163, 184, 0.15);
  color: var(--muted);
}

.hike-item-meta {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}

.content {
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}

.hike-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.hike-title-wrap h2 {
  margin: 0 0 4px 0;
  font-size: 22px;
}

.hike-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn, .btn-icon {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover, .btn-icon:hover {
  background: var(--panel-hover);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #052e16;
}

.btn-primary:hover {
  background: var(--gain);
}

.btn-apk {
  background: rgba(16, 185, 129, 0.15);
  border-color: var(--accent);
  color: var(--gain);
}

.btn-danger {
  border-color: rgba(248, 113, 113, 0.4);
  color: var(--loss);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.stat-val {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat-card.gain .stat-val {
  color: var(--gain);
}

.stat-card.loss .stat-val {
  color: var(--loss);
}

.stat-sub {
  font-size: 12px;
  color: var(--muted);
}

.map-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  height: 440px;
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 18px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
}

.chart-header h3 {
  margin: 0;
  font-size: 15px;
}

.chart-container {
  height: 210px;
  position: relative;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 780px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    max-height: 240px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .map-card {
    height: 350px;
  }
}
