:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242736;
  --border: #2e3245;
  --text: #e2e4ed;
  --text-muted: #7b7f96;
  --accent: #4f8ef7;
  --accent-hover: #3a7af5;
  --danger: #e05c5c;
  --success: #4ecb71;
  --radius: 6px;
  --radius-lg: 12px;
  --gap: 16px;
  --topbar-h: 52px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, sans-serif; font-size: 14px; }

#app { height: 100%; }

/* ── screens ── */
.screen { height: 100%; }
.hidden { display: none !important; }

/* ── login ── */
#setup-screen,
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
.login-box h1 { font-size: 1.6rem; text-align: center; }
.login-box .tagline { text-align: center; color: var(--text-muted); font-size: 0.85rem; }
.login-box form { display: flex; flex-direction: column; gap: 10px; }
.login-box input, .login-box button { width: 100%; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-size: 1rem; }
.login-box button { background: var(--accent); border-color: var(--accent); cursor: pointer; font-weight: 600; }
.login-box button:hover { background: var(--accent-hover); }

/* ── topbar ── */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--gap);
  gap: var(--gap);
  z-index: 1000;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--accent); min-width: 0; }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 6px 14px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: color 0.15s, border-color 0.15s;
}
.nav-btn:hover, .nav-btn.active { color: var(--text); border-color: var(--border); }
.nav-btn.active { background: var(--surface-2); }
.nav-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
#topbar-user { color: var(--text-muted); font-size: 0.85rem; }
#upload-btn, #garmin-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: var(--radius);
  padding: 6px 14px;
  cursor: pointer;
  font-weight: 600;
}
#upload-btn:hover { background: var(--accent-hover); }
#strava-btn { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-weight: 400; border-radius: var(--radius); padding: 6px 14px; cursor: pointer; }
#strava-btn:hover { border-color: #fc4c02; color: #fc4c02; background: var(--surface-2); }
#logout-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 6px 14px;
  cursor: pointer;
}
#logout-btn:hover { color: var(--text); }

/* ── views ── */
.view { position: fixed; top: var(--topbar-h); left: 0; right: 0; bottom: 0; overflow-y: auto; }

/* ── map view ── */
#view-map { display: flex; overflow: hidden; }
#map { flex: 1; min-width: 0; height: 100%; }

/* ── map sidebar ── */
#map-sidebar {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow: hidden;
  z-index: 400;
}
#sidebar-list-view,
#sidebar-detail-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.sidebar-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
}
.sidebar-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.sidebar-back {
  background: transparent;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.88rem;
  padding: 0;
}
.sidebar-back:hover { text-decoration: underline; }
#sidebar-activity-list {
  flex: 1;
  overflow-y: auto;
}
.sidebar-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.sidebar-item:last-child { border-bottom: none; }
.sidebar-item:hover { background: var(--surface-2); }
.sidebar-item-title { font-weight: 600; font-size: 0.88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-item-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 0.76rem; color: var(--text-muted); }
.sidebar-type-badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 0.7rem;
  text-transform: capitalize;
  color: var(--text-muted);
  flex-shrink: 0;
}
.sidebar-empty {
  padding: 20px 14px;
  color: var(--text-muted);
  font-size: 0.83rem;
  line-height: 1.5;
}
/* detail view */
#sidebar-detail-content {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.detail-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}
.detail-type-badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  text-transform: capitalize;
  color: var(--text-muted);
  align-self: flex-start;
}
.detail-stats {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text-muted); font-size: 0.8rem; }
.stat-value { font-size: 0.85rem; font-weight: 600; text-align: right; }
.detail-description {
  font-size: 0.83rem;
  color: var(--text-muted);
  line-height: 1.5;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  white-space: pre-wrap;
}

/* ── activities list ── */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.view-header h2 { font-size: 1.1rem; }
.view-header button {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: var(--radius);
  padding: 6px 14px;
  cursor: pointer;
  font-weight: 600;
}
#activity-list { padding: var(--gap); display: flex; flex-direction: column; gap: 10px; }

.activity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--gap);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.activity-card:hover { border-color: var(--accent); }
.activity-card .title { font-weight: 600; }
.activity-card .meta { color: var(--text-muted); font-size: 0.82rem; display: flex; gap: 12px; flex-wrap: wrap; }
.activity-card .type-badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  text-transform: capitalize;
  align-self: start;
}
.activity-card .actions { display: flex; gap: 8px; align-items: center; }
.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
  border-radius: var(--radius);
}
.btn-icon:hover { color: var(--danger); }

/* ── user list ── */
#user-list { padding: var(--gap); display: flex; flex-direction: column; gap: 10px; }
.user-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--gap);
  display: flex;
  align-items: center;
  gap: var(--gap);
}
.user-card .info { flex: 1; }
.user-card .name { font-weight: 600; }
.user-card .email { color: var(--text-muted); font-size: 0.85rem; }
.badge-admin { background: var(--accent); color: #fff; border-radius: 4px; padding: 2px 8px; font-size: 0.75rem; }

/* ── modals ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 1.1rem; }
.modal-close { background: transparent; border: none; color: var(--text-muted); font-size: 1.4rem; cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-box form { display: flex; flex-direction: column; gap: 12px; }
.modal-box label { display: flex; flex-direction: column; gap: 4px; color: var(--text-muted); font-size: 0.85rem; }
.modal-box input, .modal-box select, .modal-box textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}
.modal-box textarea { resize: vertical; }
.checkbox-label { flex-direction: row; align-items: center; gap: 8px; }
.form-actions { display: flex; gap: 10px; }
.form-actions button { flex: 1; padding: 9px; border-radius: var(--radius); border: 1px solid var(--border); cursor: pointer; font-size: 0.95rem; }
.form-actions button[type="submit"] { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.form-actions button[type="submit"]:hover { background: var(--accent-hover); }
.form-actions button[type="button"] { background: transparent; color: var(--text-muted); }
.form-actions button[type="button"]:hover { color: var(--text); }

/* ── misc ── */
.error { color: var(--danger); font-size: 0.85rem; }

/* ── cluster icons ── */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background-color: rgba(79, 142, 247, 0.25) !important;
}
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background-color: rgba(79, 142, 247, 0.75) !important;
  color: #fff !important;
  font-weight: 700;
  font-size: 0.85rem;
}

/* ── cluster popup ── */
.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5) !important;
  padding: 0 !important;
  color: var(--text) !important;
}
.leaflet-popup-tip {
  background: var(--surface) !important;
}
.leaflet-popup-content {
  margin: 0 !important;
  width: auto !important;
}
.cluster-popup-header {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--border);
}
.cluster-popup-list {
  max-height: 280px;
  overflow-y: auto;
}
.cluster-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s;
}
.cluster-item:last-child { border-bottom: none; }
.cluster-item:hover { background: var(--surface-2); }
.cluster-item-title { font-weight: 600; font-size: 0.9rem; }
.cluster-item-meta { color: var(--text-muted); font-size: 0.78rem; margin-top: 2px; text-transform: capitalize; }

/* ── garmin modal ── */
.garmin-hint {
  color: var(--text-muted);
  font-size: 0.83rem;
  line-height: 1.5;
  margin-bottom: 4px;
}
/* ── strava modal ── */
.strava-hint { color: var(--text-muted); font-size: 0.83rem; line-height: 1.5; }
.strava-hint code { background: var(--bg); padding: 1px 5px; border-radius: 3px; font-family: monospace; font-size: 0.8rem; color: var(--accent); }
.strava-status-row { display: flex; align-items: center; justify-content: space-between; padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.strava-name-label { font-weight: 600; font-size: 0.9rem; }
.btn-danger-sm { background: transparent; border: 1px solid var(--danger); color: var(--danger); border-radius: var(--radius); padding: 4px 10px; cursor: pointer; font-size: 0.8rem; }
.btn-danger-sm:hover { background: var(--danger); color: #fff; }
.btn-sm { background: transparent; border: 1px solid var(--border); color: var(--text-muted); border-radius: var(--radius); padding: 4px 10px; cursor: pointer; font-size: 0.8rem; }
.btn-sm:hover { color: var(--text); border-color: var(--text-muted); }
.btn-accent-sm { background: var(--accent); border: none; color: #fff; border-radius: var(--radius); padding: 4px 12px; cursor: pointer; font-size: 0.8rem; font-weight: 600; }
.btn-accent-sm:hover { background: var(--accent-hover); }
.btn-accent-sm:disabled { opacity: 0.5; cursor: not-allowed; }
.strava-list-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; }
#strava-list-count { font-size: 0.82rem; color: var(--text-muted); }
.strava-list-actions { display: flex; gap: 6px; }
#strava-activity-list { max-height: 340px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.strava-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.12s; }
.strava-item:last-child { border-bottom: none; }
.strava-item:hover { background: var(--surface-2); }
.strava-item--done { opacity: 0.5; }
.strava-item input[type="checkbox"] { flex-shrink: 0; accent-color: var(--accent); width: 15px; height: 15px; }
.strava-item-title { font-size: 0.88rem; font-weight: 600; }
.strava-item-meta { font-size: 0.76rem; color: var(--text-muted); text-transform: capitalize; margin-top: 2px; }
.strava-badge-done { background: var(--success); color: #000; border-radius: 3px; padding: 1px 5px; font-size: 0.7rem; font-weight: 600; text-transform: none; }
.strava-loading, .strava-empty { padding: 16px; color: var(--text-muted); font-size: 0.85rem; text-align: center; }
.strava-result { font-size: 0.85rem; margin-top: 8px; }
.success-text { color: var(--success); }
