* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; color: #222; }
button { font: inherit; cursor: pointer; }
button.primary { background: #1f6feb; color: #fff; border: 0; padding: 0.5rem 1rem; border-radius: 6px; }
button.primary:hover { background: #1858c4; }
button:not(.primary) { background: #eee; border: 1px solid #ccc; padding: 0.35rem 0.75rem; border-radius: 6px; }
button:not(.primary):hover { background: #e0e0e0; }

/* Login */
.login-page { display: grid; place-items: center; background: #f4f6fa; min-height: 100vh; }
.login-card { background: #fff; padding: 2rem; border-radius: 10px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); width: 320px; }
.login-card h1 { margin: 0 0 1rem; text-align: center; }
.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.tab { flex: 1; background: #f0f0f0; border: 0; padding: 0.5rem; border-radius: 6px; }
.tab.active { background: #1f6feb; color: #fff; }
#auth-form { display: flex; flex-direction: column; gap: 0.75rem; }
#auth-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
#auth-form input { padding: 0.5rem; border: 1px solid #ccc; border-radius: 6px; font: inherit; }
.error { color: #c0392b; margin: 0; font-size: 0.9rem; }
.error.notice { color: #065f46; background: #d1fae5; border: 1px solid #a7f3d0; padding: 0.5rem 0.75rem; border-radius: 6px; }

/* App layout */
.topbar { display: flex; align-items: center; gap: 1rem; padding: 0.5rem 1rem; background: #1f2937; color: #fff; }
.topbar .title { flex: 1; text-align: center; margin: 0; font-size: 1.1rem; font-weight: 500; }
.topbar .user-area { display: flex; align-items: center; gap: 0.5rem; }
.topbar .user-area button { background: #374151; color: #fff; border: 1px solid #4b5563; }
.topbar .user-area button:hover { background: #4b5563; }

.layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 3rem); }
.sidebar { background: #f8f9fb; border-right: 1px solid #e5e7eb; overflow-y: auto; padding: 1rem; }
.sidebar .panel { margin-bottom: 1.5rem; }
.sidebar h2 { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; margin: 0 0 0.5rem; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.panel-header h2 { margin: 0; }
.select-all { font-size: 0.8rem; color: #6b7280; display: inline-flex; align-items: center; gap: 0.35rem; margin: 0 !important; padding: 0 !important; }
.sidebar label { display: flex; align-items: center; gap: 0.5rem; padding: 0.15rem 0; font-size: 0.92rem; cursor: pointer; }

.track-list { list-style: none; margin: 0; padding: 0; }
.track-item { background: #fff; border: 1px solid #e5e7eb; border-radius: 6px; padding: 0.4rem 0.5rem; margin-bottom: 0.4rem; }
.track-item.dragging { opacity: 0.45; }
.drag-handle {
  display: inline-flex; align-items: center;
  color: #9ca3af; font-size: 0.95rem; letter-spacing: -2px; line-height: 1;
  cursor: grab; user-select: none; padding: 0 0.15rem;
}
.drag-handle:active { cursor: grabbing; }
.track-row { display: flex; align-items: center; gap: 0.5rem; }
.track-row .name { flex: 1; outline: none; padding: 0.15rem 0.25rem; border-radius: 4px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.track-row .name:focus { background: #eef4ff; white-space: normal; }
.track-row .del { background: transparent; border: 0; color: #9ca3af; font-size: 1.2rem; line-height: 1; padding: 0 0.25rem; }
.track-row .del:hover { color: #c0392b; }
.track-meta { font-size: 0.72rem; color: #6b7280; margin-left: 2.1rem; margin-top: 0.1rem; line-height: 1.1; }
.empty-hint { font-size: 0.85rem; color: #6b7280; margin-top: 0.5rem; }
.overlay-list { list-style: none; margin: 0; padding: 0; }
.sidebar label.is-disabled { color: #9ca3af; cursor: not-allowed; }

.map-wrap { position: relative; width: 100%; height: 100%; }
.map { width: 100%; height: 100%; }

.distance-panel {
  position: absolute; left: 12px; bottom: 12px; z-index: 5;
  background: rgba(255,255,255,0.92); backdrop-filter: blur(4px);
  border: 1px solid #d0d5dd; border-radius: 8px;
  padding: 0.4rem 0.75rem; font-size: 0.9rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  display: flex; flex-direction: column; line-height: 1.2;
}
.distance-panel .label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; }
.distance-panel #distance-readout { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Admin page */
.topbar-link { color: #fff; text-decoration: none; padding: 0.35rem 0.75rem; border-radius: 6px; background: #374151; border: 1px solid #4b5563; font-size: 0.9rem; }
.topbar-link:hover { background: #4b5563; }
.admin-main { max-width: 960px; margin: 2rem auto; padding: 0 1.5rem; }
.admin-section { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1.5rem; }
.admin-section h2 { margin-top: 0; display: flex; align-items: center; gap: 0.5rem; }
.pill { background: #dc2626; color: #fff; border-radius: 999px; padding: 0.05rem 0.5rem; font-size: 0.75rem; font-weight: 700; }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th, .users-table td { text-align: left; padding: 0.5rem 0.5rem; border-bottom: 1px solid #eef0f3; vertical-align: middle; }
.users-table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: #6b7280; font-weight: 600; }
.users-table tr:last-child td { border-bottom: 0; }
.users-table .actions { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
.users-table button.danger { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.users-table button.danger:hover { background: #fecaca; }
.users-table button:disabled { opacity: 0.5; cursor: not-allowed; }
.tag { display: inline-block; background: #f3f4f6; color: #6b7280; border-radius: 4px; padding: 0.05rem 0.4rem; font-size: 0.72rem; font-weight: 600; margin-left: 0.35rem; }
.tag.tag-admin { background: #fef3c7; color: #92400e; margin: 0; }

.drop-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 1.25rem 0.75rem;
  border: 2px dashed #c0cada; border-radius: 8px; background: #fff;
  color: #6b7280; text-align: center; cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.drop-zone:hover, .drop-zone:focus-visible {
  border-color: #1f6feb; color: #1f6feb; outline: none;
}
.drop-zone.is-dragover {
  border-color: #1f6feb; background: #eef4ff; color: #1f6feb;
}
.drop-zone-text { font-weight: 600; font-size: 0.95rem; }
.drop-zone-sub { font-size: 0.8rem; margin-top: 0.15rem; }

.track-row .color-dot {
  width: 14px !important; height: 14px !important;
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(0,0,0,0.25);
  flex-shrink: 0;
}

.map-label-wrap {
  position: absolute;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.map-label-dot {
  position: absolute;
  left: 0; top: 0;
  transform: translate(-50%, -50%);
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--label-color, #333);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1.5px rgba(0,0,0,0.55), 0 2px 4px rgba(0,0,0,0.35);
}
.map-label {
  position: absolute;
  left: 0; bottom: 14px;
  transform: translateX(-50%);
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff;
  border: 2px solid var(--label-color, #333);
  color: #111;
  font-size: 13px; font-weight: 700;
  white-space: nowrap;
  line-height: 1.15;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.map-label::after {
  content: '';
  position: absolute;
  left: 50%; top: 100%;
  transform: translate(-50%, -5px) rotate(45deg);
  width: 7px; height: 7px;
  background: #fff;
  border-right: 2px solid var(--label-color, #333);
  border-bottom: 2px solid var(--label-color, #333);
}
