* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }

#map { position: absolute; inset: 0; }

#topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(6px);
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
}

#brand {
  font-weight: 700;
  font-size: 18px;
  color: #4A6FA1;
  white-space: nowrap;
}

#search-wrap {
  position: relative;
  flex: 1;
  max-width: 420px;
}

#search-input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
#search-input:focus { border-color: #4A6FA1; }

#search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  max-height: 320px;
  overflow-y: auto;
  display: none;
}
#search-results.open { display: block; }
.search-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
  font-size: 14px;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: #F3F3F3; }
.search-item .kind { color: #888; font-size: 12px; }
.search-item-region { color: #999; font-size: 12px; margin-top: 2px; }
.search-item-row { display: flex; align-items: flex-start; gap: 10px; }
.search-item-icon { color: #4A6FA1; flex-shrink: 0; margin-top: 1px; }
.search-item-text { flex: 1; min-width: 0; }
.search-empty { padding: 12px; color: #888; font-size: 14px; }

#account-area {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
  /* search-wrap растёт до max-width и дальше не тянется — без margin-left:
     auto оставшееся пустое место просто зависало бы между поиском и
     профилем, а не прижимало бы блок к правому краю. */
  margin-left: auto;
}
#profile-block {
  display: flex;
  align-items: center;
  gap: 8px;
}
#profile-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #4A6FA1;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  flex-shrink: 0;
}
#profile-avatar img { width: 100%; height: 100%; object-fit: cover; }
#profile-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  max-width: 160px;
}
#profile-name {
  font-size: 14px;
  font-weight: 600;
  color: #2E2E33;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#profile-vehicle {
  font-size: 12px;
  color: #4A4A50;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.icon-btn {
  background: #fff;
  color: #4A4A50;
  border: 1px solid #ddd;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
button.icon-btn svg { fill: currentColor; }
button.icon-btn:hover { background: #F3F3F3; color: #2E2E33; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 16px;
  padding: 9px 14px;
  font-size: 14px;
  background: #4A6FA1;
  color: #fff;
}
button:hover { background: #3D5C89; }
button.link-btn {
  background: none;
  color: #4A6FA1;
  padding: 4px;
  text-decoration: underline;
  font-size: 13px;
}
button.link-btn:hover { background: none; opacity: 0.7; }
button:disabled { opacity: 0.5; cursor: default; }

.hidden { display: none !important; }

#add-hint {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: #4A6FA1;
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

#auth-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  background: linear-gradient(135deg, #F3F3F3, #EDEDED);
  display: flex;
  align-items: center;
  justify-content: center;
}
#auth-overlay.hidden { display: none; }

#auth-box {
  background: #fff;
  padding: 32px 28px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  width: 320px;
}
#auth-box h1 { margin: 0 0 4px; color: #4A6FA1; font-size: 24px; }
.auth-sub { margin: 0 0 20px; color: #4A4A50; font-size: 13px; }

#auth-form input, #recovery-form input, #new-password-form input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 14px;
}

#auth-form button, #new-password-form button {
  width: 100%;
  margin-top: 6px;
  margin-bottom: 6px;
}

.error { color: #c62828; font-size: 13px; margin-bottom: 8px; }
.info { color: #4A6FA1; font-size: 13px; margin-bottom: 8px; }

.maplibregl-popup-content {
  font-size: 14px;
  border-radius: 10px;
}
.popup-title { font-weight: 700; margin-bottom: 4px; color: #2E2E33; }
.popup-sub { color: #4A4A50; font-size: 12px; }
.popup-coords {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  color: #4A4A50;
  font-size: 12px;
}
.copy-coords-btn {
  padding: 3px 8px;
  font-size: 11px;
  border-radius: 10px;
}

/* Крупнее стандартных 29px у MapLibre — весь стек кнопок внизу справа
   (зум, геолокация, грунтовки, спутник) одного увеличенного размера. */
.maplibregl-ctrl-group button {
  width: 40px !important;
  height: 40px !important;
}

.dirt-road-btn {
  background: #fff !important;
  border-radius: 0 !important;
  padding: 0 !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dirt-road-btn svg { fill: #2E2E33; }
.dirt-road-btn.active { background: #ba1a1a !important; }
.dirt-road-btn.active svg { fill: #fff; }

.satellite-btn {
  background: #fff !important;
  border-radius: 0 !important;
  padding: 0 !important;
  display: flex;
  align-items: center;
  justify-content: center;
}
.satellite-btn svg { fill: #2E2E33; }
.satellite-btn.active { background: #4A6FA1 !important; }
.satellite-btn.active svg { fill: #fff; }

button.danger-btn { background: #c62828; }
button.danger-btn:hover { background: #a02020; }

#draw-hint {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  background: #1565c0;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 90vw;
}
#draw-hint button {
  background: rgba(255,255,255,0.2);
  padding: 6px 12px;
  font-size: 13px;
}
#draw-hint button.link-btn { color: #fff; }

#admin-overlay, #track-edit-overlay, #profile-edit-overlay, #waypoints-overlay {
  position: absolute;
  inset: 0;
  z-index: 90;
  background: rgba(46,46,51,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}
#admin-overlay.hidden, #track-edit-overlay.hidden, #profile-edit-overlay.hidden, #waypoints-overlay.hidden { display: none; }

#admin-panel {
  background: #fff;
  border-radius: 16px;
  width: min(640px, 92vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
#admin-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: 1px solid #eee;
}
#admin-panel-header h2 { margin: 0; font-size: 18px; color: #2E2E33; }
#admin-track-list { overflow-y: auto; padding: 8px 12px 16px; }

.admin-track-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 8px;
  border-bottom: 1px solid #f2f2f2;
  cursor: pointer;
}
.admin-track-item:hover { background: #f7f7f7; }
.admin-track-item .title { font-weight: 600; color: #2E2E33; font-size: 14px; }
.admin-track-item .sub { color: #4A4A50; font-size: 12px; margin-top: 2px; }

#waypoints-panel {
  background: #fff;
  border-radius: 16px;
  width: min(640px, 92vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
#waypoints-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: 1px solid #eee;
}
#waypoints-panel-header h2 { margin: 0; font-size: 18px; color: #2E2E33; }
#waypoints-list { overflow-y: auto; padding: 8px 12px 16px; }
.waypoints-region-header {
  font-weight: 700;
  font-size: 13px;
  color: #4A6FA1;
  padding: 12px 8px 4px;
}

#track-edit-box {
  background: #fff;
  border-radius: 16px;
  width: min(420px, 92vw);
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
#track-edit-box h2 { margin: 0 0 16px; font-size: 18px; color: #2E2E33; }
#track-edit-box input, #track-edit-box textarea {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.track-edit-meta { color: #4A4A50; font-size: 12px; margin-bottom: 10px; }
#track-edit-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

#profile-edit-box {
  background: #fff;
  border-radius: 16px;
  width: min(380px, 92vw);
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
#profile-edit-box h2 { margin: 0 0 16px; font-size: 18px; color: #2E2E33; }
#profile-edit-box input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
#profile-edit-avatar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
#profile-edit-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #4A6FA1;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  overflow: hidden;
  flex-shrink: 0;
}
#profile-edit-avatar img { width: 100%; height: 100%; object-fit: cover; }
#profile-edit-avatar-btn {
  color: #4A6FA1;
  text-decoration: underline;
  font-size: 13px;
  cursor: pointer;
}
#profile-edit-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
